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
, typenameFL
>
structblock2
::
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
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.
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.
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).
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).
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 loadbalanced, the multithread 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 multithread 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.
Tensor product multiplication operation (multiroot case): vmats = expr x cmats. Both cmats and vmats are wavefunctions with multitarget 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 (multitarget wavefunction).
vmats – Output “vector” result (multitarget 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.
Tensor product multiplication operation (singleroot 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.
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.
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).
Rotation (renormalization) of a leftblock 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).
Rotation (renormalization) of a rightblock 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).
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 leftblocking or rightblocking.
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.
Tensor product operation in left blocking: c = a x b.
 Parameters
a – Operator a (left block tensor).
b – Operator b (dot block singlesite 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 threetensor operations later.
Tensor product operation in right blocking: c = b x a.
 Parameters
a – Operator a (right block tensor).
b – Operator b (dot block singlesite 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 threetensor operations later.