Class EvalExpr

Inheritance Relationships

Derived Types

Class Documentation

class EvalExpr

The EvalExpr is a building block of binary trees used to evaluate expressions.

The EvalExpr class itself is not a proper node of the binary tree. It is rather a data that a node should hold.

Subclassed by sequant::ExportExpr, sequant::eval::dryrun::EvalExprDryRun

Public Types

using index_vector = Index::index_vector

Public Functions

explicit EvalExpr(Tensor const &tnsr)

Construct an EvalExpr object from a tensor.

explicit EvalExpr(Constant const &c)

Construct an EvalExpr object from a Constant.

explicit EvalExpr(Variable const &v)

Construct an EvalExpr object from a Variable.

explicit EvalExpr(Power const &p)

Construct an EvalExpr object from a Power.

EvalExpr(EvalOp op, ResultType res, ExprPtr const &expr, index_vector ixs, std::int8_t phase, size_t hash, std::shared_ptr<bliss::Graph> connectivity)
Parameters:
  • op – Evaluation operation resulting to this object.

  • res – Evaluation result type that will be produced.

  • expr – A SeQuant expression corresponding to res.

  • ixs – Canonical indices used for annotating the result’s modes if res is tensor type. Possibly empty for non-tensor res type.

  • phase – Phase that was part of the tensor network canonicalization. Considered for reusing sub-expressions.

  • hash – A hash value that is equal for two EvalExpr objects that produce the same evaluated result modulo the phase.

  • connectivity – The graph representing the connectivity. May be null to indicate that no graph is present/necessary.

const std::optional<EvalOp> &op_type() const noexcept
Returns:

Operation type of this expression, or null if this is a primary expression.

ResultType result_type() const noexcept
Returns:

The ResultType of the evaluation performed on this node.

size_t hash_value() const noexcept

Compute the hash value of this EvalExpr object.

The hash value is computed during construction of the object by also looking at the hash values of the EvalExpr objects if passed.

Returns:

The hash value of this EvalExpr object.

ExprPtr expr() const noexcept
Returns:

The ExprPtr object that this EvalExpr object holds.

bool tot() const noexcept
Returns:

True if this EvalExpr object contains a SeQuant tensor with proto-indices, false otherwise.

std::wstring to_latex() const noexcept
Returns:

Returns the result of calling to_latex() on the ExprPtr object contained by this object.

Expr::type_id_type type_id() const noexcept
Returns:

The type id of the Expr held by this object.

bool is_tensor() const noexcept
Returns:

True if the ExprPtr held by this object is Tensor and equivalently the result of evaluation is tensor.

bool is_scalar() const noexcept
Returns:

True if the ExprPtr held by this object is scalar (Constant, Variable, or Power) and equivalently the result of evaluation is scalar.

bool is_constant() const noexcept
Returns:

True if ExprPtr held by this object is Constant.

bool is_variable() const noexcept
Returns:

True if ExprPtr held by this object is Variable.

bool is_power() const noexcept
Returns:

True if ExprPtr held by this object is Power.

bool is_primary() const noexcept
Returns:

True if this is a primary expression (i.e. a leaf on expression tree)

bool is_product() const noexcept
Returns:

True if this expression is a product.

bool is_sum() const noexcept
Returns:

True if this expression is a sum.

bool is_adjoint() const noexcept
Returns:

True if this expression is an adjoint (unary) node.

Tensor const &as_tensor() const

Calls to<Tensor>() on ExprPtr held by this object.

Returns:

Tensor const&

Constant const &as_constant() const

Calls to<Constant>() on ExprPtr held by this object.

Returns:

Constant const&.

Variable const &as_variable() const

Calls to<Variable>() on ExprPtr held by this object.

Returns:

Variable const&

Power const &as_power() const

Calls to<Power>() on ExprPtr held by this object.

Returns:

Power const&

std::string label() const noexcept

Get the label for this object useful for logging.

std::string indices_annot() const noexcept
Returns:

A string usable as TiledArray annotation if is_tensor() true, empty string otherwise.

index_vector const &canon_indices() const noexcept
Returns:

Canonically ordered indices &#8212; non-empty if this object represents a tensor result.

std::int8_t canon_phase() const noexcept
Returns:

The canonicalization phase (+1 or -1).

bool has_connectivity_graph() const noexcept

Returns:

Whether this expression has a connectivity graph

const bliss::Graph &connectivity_graph() const noexcept

Note

If has_connectivity_graph returns false, this function must not be called

Returns:

The graph representing the connectivity of two factors in a product

std::shared_ptr<bliss::Graph> copy_connectivity_graph() const noexcept
Returns:

A copy of the graph representing the connectivity of two factors in a product

inline container::svector<std::pair<Index, BatchModeType>> const &node_slice_mask() const noexcept

Batchable indices the single-term optimizer chose to slice at this node (its DP aprime), each tagged with its BatchModeType. Empty unless set by binarize from BinarizationOptions::node_batch_axes (itself populated from OptimizeOptions::term_batch_axes by the optimizer). The runtime batched evaluator slices exactly these indices at this node.

inline void set_node_slice_mask(container::svector<std::pair<Index, BatchModeType>> modes) noexcept

Sets the batch modes for this node; see node_slice_mask.

inline container::svector<std::pair<Index, BatchModeType>> const &batch_loops_opened_here() const noexcept

Batch loops opened at this node: the subset of node_slice_mask() for which this node is the loop-open site (the outermost node introducing the physical batch loop), as opposed to a deeper node that only carries the sliced mode. Empty unless set by binarize from NodeBatchAnnotation::opened_here. Unlike node_slice_mask() &#8212; which the runtime consults per node to slice that node’s operands, and which the DP stamps on every carrying node &#8212; this names each physical loop exactly once, so a consumer reconstructing the enclosing-loop nest (e.g. peak_profile's OccurrenceRec::ectx) does not multi-count one loop as one-per-carrying-node.

inline void set_batch_loops_opened_here(container::svector<std::pair<Index, BatchModeType>> modes) noexcept

Sets the loop-open modes for this node; see batch_loops_opened_here.

inline container::svector<Index> const &sliced_modes() const noexcept

Canonical batch modes that slice this node in every occurrence (the cross-occurrence meet; see stamp_lifetime_masks). Empty => all-full (block-agnostic, run-scope). Proto-aware: a composite slot contributes its proto indices. Set by stamp_lifetime_masks; empty by default (off path).

inline void set_sliced_modes(container::svector<Index> m) noexcept

Sets the cross-occurrence sliced-mode mask; see sliced_modes.

inline bool mask_all_full() const noexcept

Whether this node’s sliced-mode mask is empty (all modes full / block-agnostic). Equivalent to sliced_modes().empty().

inline container::svector<Index> const &occurrence_home() const noexcept

The batch modes that slice this occurrence of the node: the loops opened at or above it that live on its own result slots. The value’s home in the table-driven engine (explicit-cells design section 11, home_scope / value_key_of), stamped per occurrence by stamp_occurrence_homes &#8212; not the cross-occurrence meet (sliced_modes), which folds occurrences by node identity and by label and serves the forest-descent path’s residency. Empty = whole.

inline void set_occurrence_home(container::svector<Index> m) noexcept

Sets this occurrence’s home; see occurrence_home.

inline std::size_t value_key() const noexcept

This occurrence’s value key (explicit-cells design section 11): node id + (position, loop slot) of every home-sliced position + the operands’ keys, stamped by compute_dag_boulevard once loop instances are numbered; 0 = not stamped (value_key_of then falls back to the structural key).

inline void set_value_key(std::size_t k) noexcept

Sets this occurrence’s value key; see value_key.

inline bool accumulate_in_place() const noexcept

Whether this Sum node’s result should be accumulated in place into its left operand rather than materialized as a fresh value. Set by binarize on the accumulation-chain Sum nodes produced when an N-ary Sum is folded into binary Sum nodes: for a chain (((t1+t2)+t3)+t4), every binary Sum's left operand is the running accumulator (the chain seed or a prior chain Sum), so every chain Sum is marked true. Never set based on the right operand. Default false (off path, behavior-neutral).

inline void set_accumulate_in_place(bool v) noexcept

Sets the in-place accumulation flag; see accumulate_in_place.

inline std::size_t batch_effective_count() const noexcept

Emitted effective use count of this contraction node: the number of times its value is (re)referenced across the enclosing batch loops it does not carry. 1 (the default and the order-blind / off-path value) means the node is used once (no across-loop reuse). See NodeBatchAnnotation::effective_count.

inline bool batch_order_aware() const noexcept

Whether the order-aware cost model emitted this node &#8212; the per-level placement order-aware gate. false (default, off path) means the node is never hoisted. See NodeBatchAnnotation::order_aware.

inline void set_batch_order_aware(bool v) noexcept

Sets the order-aware placement gate; see batch_order_aware.

inline void set_batch_effective_count(std::size_t count) noexcept

Sets the effective use count; see batch_effective_count.

Protected Attributes

std::optional<EvalOp> op_type_ = std::nullopt
ResultType result_type_
ExprPtr expr_
index_vector canon_indices_
std::int8_t canon_phase_ = {1}
size_t hash_value_
std::shared_ptr<bliss::Graph> connectivity_
container::svector<std::pair<Index, BatchModeType>> node_slice_mask_ = {}

See node_slice_mask.

container::svector<std::pair<Index, BatchModeType>> batch_loops_opened_here_ = {}

See batch_loops_opened_here.

container::svector<Index> sliced_modes_ = {}

See sliced_modes.

container::svector<Index> occurrence_home_ = {}
std::size_t value_key_ = 0
bool batch_order_aware_ = false

See batch_order_aware.

std::size_t batch_effective_count_ = 1

See batch_effective_count.

bool accumulate_in_place_ = false

See accumulate_in_place.

Friends

friend struct EvalOpSetter