OperatorTerm#

class cuquantum.densitymat.OperatorTerm(dtype: str | None = None)[source]#

Operator term consisting of tensor products of elementary operators.

An OperatorTerm containing a tensor product of elementary operators can be obtained from the free function tensor_product(). Sums of more than a single product are obtained by in-place (+=) or out-of-place addition (+) of OperatorTerm objects.

Parameters:

dtype – Numeric data type of the underlying elementary operators’ data. Defaults to None and will be inferred from the appended tensor products of elementary operators.

Note

  • Scalar operators, for which no product is appended, require specification of dtype at construction.

Methods

__add__(
other: OperatorTerm,
) OperatorTerm[source]#

Return a new OperatorTerm equal to the sum of this OperatorTerm and another OperatorTerm.

__iadd__(
other: OperatorTerm,
) OperatorTerm[source]#

Inplace add another OperatorTerm into this OperatorTerm.

__init__(dtype: str | None = None)[source]#

Initialize an operator term consisting of tensor products of elementary operators.

__mul__(
other: Number | ndarray | ndarray | Callback | Tuple[Number, Callback] | Tuple[ndarray | ndarray, Callback] | OperatorTerm,
) OperatorTerm[source]#

Multiply this OperatorTerm with another OperatorTerm or with a coefficient. Note that multiplication by a Callable that outputs a batched coefficient vector requires all static coefficients to have the the same batch_size as the output of the callable.

__rmul__(
other: Number | ndarray | ndarray | Callback | Tuple[Number, Callback] | Tuple[ndarray | ndarray, Callback] | OperatorTerm,
) OperatorTerm[source]#

Multiply this OperatorTerm with a number, callable or another OperatorTerm on the right.

append_elementary_product(
elem_ops: Iterable[ElementaryOperator],
modes: Iterable[Sequence[int]],
duals: Iterable[Sequence[bool]],
coeff: Number | ndarray | ndarray | Callback | Tuple[Number, Callback] | Tuple[ndarray | ndarray, Callback] = 1 + 0j,
batch_size: int = 1,
) None[source]#

Append a product of elementary operators to this operator term.

Parameters:
  • elem_ops – An iterable of elementary operators.

  • modes – An iterable of the mode indices of the elementary operators.

  • duals – Dualities of the elementary operators.

  • coeff – Coefficient associated with this tensor product of elementary operators.

  • batch_size – Batch size associated with this product of elementary operators.

Note

The relation among operators in elem_ops is matrix multiplication/tensor contraction, which is equivalent to tensor product when there are no overlapping modes.

append_matrix_product(
matrix_ops: Iterable[MatrixOperator],
conjugations: Iterable[bool],
duals: Iterable[bool],
coeff: Number | ndarray | ndarray | Callback | Tuple[Number, Callback] | Tuple[ndarray | ndarray, Callback] = 1 + 0j,
batch_size: int = 1,
) None[source]#

Append a product of matrix operators to this operator term.

Parameters:
  • matrix_ops – An iterable of matrix operators.

  • conjugations – An iterable of whether each matrix operator is conjugated.

  • duals – Dualities of the matrix operators.

  • coeff – Coefficient associated with this tensor product of matrix operators.

  • batch_size – Batch size associated with this product of matrix operators.

Note

The relation among operators in matrix_ops is matrix multiplication.

append_mpo_product(
mpo_ops: Iterable[MatrixProductOperator],
modes: Iterable[Sequence[int]],
conjugations: Iterable[bool],
duals: Iterable[Sequence[bool]],
coeff: Number | ndarray | ndarray | Callback | Tuple[Number, Callback] | Tuple[ndarray | ndarray, Callback] = 1 + 0j,
batch_size: int = 1,
) None[source]#

Append a product of matrix product operators (MPOs) to this operator term.

Parameters:
  • mpo_ops – An iterable of matrix product operators.

  • modes – An iterable of mode index sequences, one per MPO, specifying which state modes each MPO acts on. The length of each sequence must equal the number of sites in the corresponding MPO.

  • conjugations – An iterable of whether each MPO is conjugated.

  • duals – An iterable of mode duality sequences, one per MPO. Each inner sequence specifies whether the action on each mode applies to a ket mode (False) or a bra mode (True).

  • coeff – Coefficient associated with this product of MPOs.

  • batch_size – Batch size associated with this product of MPOs.

dag() OperatorTerm[source]#

Return a new OperatorTerm equal to the complex conjugate of this OperatorTerm.

Warning

A error will be raised if the OperatorTerm contains tensor products of elementary operators acting on both bra and ket modes at the same time.

dual() OperatorTerm[source]#

Return a new OperatorTerm with duality reversed.

Attributes

dtype#

Data type of this OperatorTerm.

hilbert_space_dims#

Hilbert space dimensions of this OperatorTerm.