Tensor Functions

Tensor functions are drivers for performing operations for operator tensors. For operator tensors with different internal data representations or distribed parallelization schemes, a few different implementations of the tensor function drivers are defined. They all have the same interface.

Archived Tensor Functions

template<typename S, typename FL>
struct block2::ArchivedTensorFunctions : public block2::TensorFunctions<S, FL>

Operations for operator tensors with internal data stored in disk file.

tparam S

Quantum label type.

tparam FL

float point type.

Public Functions

inline ArchivedTensorFunctions(const shared_ptr<OperatorFunctions<S, FL>> &opf)

Constructor.

Parameters

opf – Sparse matrix algebra driver.

inline virtual TensorFunctionsTypes get_type() const override

Get the type of this driver for tensor functions.

Returns

Type of this driver for tensor functions.

inline void archive_tensor(const shared_ptr<OperatorTensor<S, FL>> &a) const

Save the content of an operator tensor into disk, transforming its internal representation to sparse matrices with internal data stored in disk file, and deallocating its memory data.

Parameters

a – Operator tensor with ordinary memory storage.

inline virtual void left_assign(const shared_ptr<OperatorTensor<S, FL>> &a, shared_ptr<OperatorTensor<S, FL>> &c) const override

Left assignment (copy) operation: c = a. This is the edge case for the left blocking step. Left assignment means that the operator tensor is a row vector of symbols.

Parameters
  • a – Operator a (input).

  • c – Operator c (output).

inline virtual void right_assign(const shared_ptr<OperatorTensor<S, FL>> &a, shared_ptr<OperatorTensor<S, FL>> &c) const override

Right assignment (copy) operation: c = a. This is the edge case for the right blocking step. Right assignment means that the operator tensor is a column vector of symbols.

Parameters
  • a – Operator a (input).

  • c – Operator c (output).

inline virtual void tensor_product_partial_multiply(const shared_ptr<OpExpr<S>> &expr, const shared_ptr<OperatorTensor<S, FL>> &lopt, const shared_ptr<OperatorTensor<S, FL>> &ropt, bool trace_right, const shared_ptr<SparseMatrix<S, FL>> &cmat, const vector<pair<uint8_t, S>> &psubsl, const vector<vector<shared_ptr<typename SparseMatrixInfo<S>::ConnectionInfo>>> &cinfos, const vector<S> &vdqs, const shared_ptr<SparseMatrixGroup<S, FL>> &vmats, int &vidx, int tvidx, bool do_reduce) const override

Partial tensor product multiplication operation: vmat = expr[L part | R part] x cmat. This is used only for perturbative noise, where only left or right block part of the Hamiltonian expression is multiplied by the wavefunction cmat, to get a perurbed wavefunction vmat.

Parameters
  • expr – Symbolic expression in form of sum of tensor products.

  • lopt – Symbol lookup table for left operands in the tensor products.

  • ropt – Symbol lookup table for right operands in the tensor products.

  • trace_right – If true, the left operands in the tensor products are used. The right operands are treated as identity. Otherwise, the right operands in the tensor products are used.

  • cmat – Input “vector” operand (wavefunction).

  • psubsl – Vector of transpose pattern and delta quantum of the “matrix” operand (in the same order as cinfos).

  • cinfos – Vector of sparse matrix connection info (in the same order as cinfos).

  • vdqs – Vector of quantum number of each vmat (for lookup).

  • vmats – Vector of output “vectors” (perurbed wavefunctions).

  • vidx – If -1, there is only one perurbed wavefunction for each target quantum number (used in NoiseTypes::ReducedPerturbative). Otherwise, one vmat is created for each tensor product (used in NoiseTypes::Perturbative), and vidx is used as an incremental index in vmats.

  • tvidx – If -1, vmats is copied to every thread, which is the high memory mode but may be more load-balanced, the multi-thread parallelization is over different terms in expr for this case. If -2, every thread works on a single vmat, which is the low memory mode (used in NoiseTypes:: NoiseTypes::LowMem), the multi-thread parallelization is over different vmats for this case. Otherwise, if >= 0, only the specified vmat is handled, which is used only internally.

  • do_reduce – If true, the output vmats are accumulated to the root processor in the distributed parallel case.

inline virtual void tensor_product_multi_multiply(const shared_ptr<OpExpr<S>> &expr, const shared_ptr<OperatorTensor<S, FL>> &lopt, const shared_ptr<OperatorTensor<S, FL>> &ropt, const shared_ptr<SparseMatrixGroup<S, FL>> &cmats, const shared_ptr<SparseMatrixGroup<S, FL>> &vmats, const unordered_map<S, shared_ptr<typename SparseMatrixInfo<S>::ConnectionInfo>> &cinfos, S opdq, FL factor, bool all_reduce) const override

Tensor product multiplication operation (multi-root case): vmats = expr x cmats. Both cmats and vmats are wavefunctions with multi-target components.

Parameters
  • expr – Symbolic expression in form of sum of tensor products.

  • lopt – Symbol lookup table for left operands in the tensor products.

  • ropt – Symbol lookup table for right operands in the tensor products.

  • cmats – Input “vector” operand (multi-target wavefunction).

  • vmats – Output “vector” result (multi-target wavefunction).

  • cinfos – Lookup table of sparse matrix connection info, where the key is the combined quantum number of the vmat and cmat.

  • opdq – The delta quantum number of expr.

  • factor – Sacling factor applied to the results.

  • all_reduce – If true, the output result is accumulated and broadcast to all processors.

inline virtual void tensor_product_multiply(const shared_ptr<OpExpr<S>> &expr, const shared_ptr<OperatorTensor<S, FL>> &lopt, const shared_ptr<OperatorTensor<S, FL>> &ropt, const shared_ptr<SparseMatrix<S, FL>> &cmat, const shared_ptr<SparseMatrix<S, FL>> &vmat, S opdq, bool all_reduce) const override

Tensor product multiplication operation (single-root case): vmat = expr x cmat.

Parameters
  • expr – Symbolic expression in form of sum of tensor products.

  • lopt – Symbol lookup table for left operands in the tensor products.

  • ropt – Symbol lookup table for right operands in the tensor products.

  • cmat – Input “vector” operand (wavefunction), assuming the cinfo is already attached.

  • vmat – Output “vector” result (wavefunction).

  • opdq – The delta quantum number of expr.

  • all_reduce – If true, the output result is accumulated and broadcast to all processors.

inline virtual void tensor_product_diagonal(const shared_ptr<OpExpr<S>> &expr, const shared_ptr<OperatorTensor<S, FL>> &lopt, const shared_ptr<OperatorTensor<S, FL>> &ropt, const shared_ptr<SparseMatrix<S, FL>> &mat, S opdq) const override

Extraction of diagonal of a tensor product expression: mat = diag(expr).

Parameters
  • expr – Symbolic expression in form of sum of tensor products.

  • lopt – Symbol lookup table for left operands in the tensor products.

  • ropt – Symbol lookup table for right operands in the tensor products.

  • mat – Output “vector” result (diagonal part).

  • opdq – The delta quantum number of expr.

inline virtual void tensor_product(const shared_ptr<OpExpr<S>> &expr, const unordered_map<shared_ptr<OpExpr<S>>, shared_ptr<SparseMatrix<S, FL>>> &lop, const unordered_map<shared_ptr<OpExpr<S>>, shared_ptr<SparseMatrix<S, FL>>> &rop, shared_ptr<SparseMatrix<S, FL>> &mat) const override

Direct evaluation of a tensor product expression: mat = eval(expr).

Parameters
  • expr – Symbolic expression in form of sum of tensor products.

  • lop – Symbol lookup table for left operands in the tensor products.

  • rop – Symbol lookup table for right operands in the tensor products.

  • mat – Output “vector” result (the sparse matrix value of the expression).

inline virtual void left_rotate(const shared_ptr<OperatorTensor<S, FL>> &a, const shared_ptr<SparseMatrix<S, FL>> &mpst_bra, const shared_ptr<SparseMatrix<S, FL>> &mpst_ket, shared_ptr<OperatorTensor<S, FL>> &c) const override

Rotation (renormalization) of a left-block operator tensor: c = mpst_bra.T x a x mpst_ket. In the above expression, [x] means multiplication. Note that the row and column of mpst_bra and mpst_ket are for system and environment indices, respectively. Left rotation means that system indices are contracted.

Parameters
  • a – Input operator tensor a (as a row vector of symbols).

  • mpst_bra – Rotation matrix (bra MPS tensor) for row of sparse matrices in a.

  • mpst_ket – Rotation matrix (ket MPS tensor) for column of sparse matrices in a.

  • c – Output operator tensor c (as a row vector of symbols).

inline virtual void right_rotate(const shared_ptr<OperatorTensor<S, FL>> &a, const shared_ptr<SparseMatrix<S, FL>> &mpst_bra, const shared_ptr<SparseMatrix<S, FL>> &mpst_ket, shared_ptr<OperatorTensor<S, FL>> &c) const override

Rotation (renormalization) of a right-block operator tensor: c = mpst_bra x a x mpst_ket.T. In the above expression, [x] means multiplication. Note that the row and column of mpst_bra and mpst_ket are for system and environment indices, respectively. Right rotation means that environment indices are contracted.

Parameters
  • a – Input operator tensor a (as a column vector of symbols).

  • mpst_bra – Rotation matrix (bra MPS tensor) for row of sparse matrices in a.

  • mpst_ket – Rotation matrix (ket MPS tensor) for column of sparse matrices in a.

  • c – Output operator tensor c (as a column vector of symbols).

inline virtual void intermediates(const shared_ptr<Symbolic<S>> &names, const shared_ptr<Symbolic<S>> &exprs, const shared_ptr<OperatorTensor<S, FL>> &a, bool left) const override

Compute the intermediates to speed up the tensor product operations in the next blocking step. Intermediates are formed by collecting terms sharing the same left or right operands during the MPO simplification step.

Parameters
  • names – Operator names (symbols, only used in distributed parallelization).

  • exprs – Tensor product expressions (expressions of symbols).

  • a – Symbol lookup table for symbols in the tensor product expressions (updated).

  • left – Whether this is for left-blocking or right-blocking.

inline virtual void numerical_transform(const shared_ptr<OperatorTensor<S, FL>> &a, const shared_ptr<Symbolic<S>> &names, const shared_ptr<Symbolic<S>> &exprs) const override

Numerical transform from normal operators to complementary operators near the middle site.

Parameters
  • a – Symbol lookup table for symbols in the tensor product expressions (updated).

  • names – List of complementary operator names (symbols).

  • exprs – List of symbolic expression of complementary operators as linear combination of normal operators.

inline virtual void left_contract(const shared_ptr<OperatorTensor<S, FL>> &a, const shared_ptr<OperatorTensor<S, FL>> &b, shared_ptr<OperatorTensor<S, FL>> &c, const shared_ptr<Symbolic<S>> &cexprs = nullptr, OpNamesSet delayed = OpNamesSet()) const override

Tensor product operation in left blocking: c = a x b.

Parameters
  • a – Operator a (left block tensor).

  • b – Operator b (dot block single-site tensor).

  • c – Operator c (enlarged left block tensor).

  • cexprs – Symbolic expression for the tensor product operation. If nullptr, this is automatically contructed from expressions in a and b.

  • delayed – The set of operator names for which the tensor product operation should be delayed. The delayed tensor product will not be performed here. Instead, it will be evaluated as three-tensor operations later.

inline virtual void right_contract(const shared_ptr<OperatorTensor<S, FL>> &a, const shared_ptr<OperatorTensor<S, FL>> &b, shared_ptr<OperatorTensor<S, FL>> &c, const shared_ptr<Symbolic<S>> &cexprs = nullptr, OpNamesSet delayed = OpNamesSet()) const override

Tensor product operation in right blocking: c = b x a.

Parameters
  • a – Operator a (right block tensor).

  • b – Operator b (dot block single-site tensor).

  • c – Operator c (enlarged right block tensor).

  • cexprs – Symbolic expression for the tensor product operation. If nullptr, this is automatically contructed from expressions in b and a.

  • delayed – The set of operator names for which the tensor product operation should be delayed. The delayed tensor product will not be performed here. Instead, it will be evaluated as three-tensor operations later.

Public Members

string filename = ""

The name of the associated disk file.

mutable int64_t offset = 0

Byte offset in the file (where to read/write the content).