cuquantum.densitymat.Operator¶
- class cuquantum.densitymat.Operator(hilbert_space_dims, *terms)[source]¶
Operator representing a collection of
OperatorTerm
objects.The action of an
Operator
maps aState
to anotherState
. AnOperator
acts on an instance ofState
through itscompute
method after itsprepare
method is called on the same instance ofState
.- Parameters
hilbert_space_dims – Hilbert space dimensions of the physical system.
terms – A sequence of tuples specifying each term. Each tuple can consist of a single element (
OperatorTerm
), two elements (OperatorTerm
and coefficient), three elements (OperatorTerm
, coefficient and duality) or four elements (OperatorTerm
, coefficient, duality and batch size). If less than four elements are given, the remaining ones will be set to their default values (coefficient=1
,duality=False
,batch_size=1
).
Methods
- __add__(other: Operator) Operator [source]¶
Return a new
Operator
equal to the sum of thisOperator
with anotherOperator
.
- __iadd__(other: Union[Operator, OperatorTerm]) None [source]¶
Inplace add another
Operator
orOperatorTerm
into thisOperator
.
- __init__(hilbert_space_dims: Sequence[int], *terms: Union[Tuple[OperatorTerm], Tuple[OperatorTerm, Union[numbers.Number, numpy.ndarray, cupy.ndarray, Callback, Tuple[Union[numpy.ndarray, cupy.ndarray], Callback]]], Tuple[OperatorTerm, Union[numbers.Number, numpy.ndarray, cupy.ndarray, Callback, Tuple[Union[numpy.ndarray, cupy.ndarray], Callback]], bool], Tuple[OperatorTerm, Union[numbers.Number, numpy.ndarray, cupy.ndarray, Callback, Tuple[Union[numpy.ndarray, cupy.ndarray], Callback]], bool, int]]) None [source]¶
Initialize an operator representing a collection of
OperatorTerm
objects.
- __mul__(factor: Union[numbers.Number, numpy.ndarray, cupy.ndarray, Callback, Tuple[Union[numpy.ndarray, cupy.ndarray], Callback]]) Operator [source]¶
Return a new
Operator
equal to thisOperator
multiplied by a scalar or a batch of scalars on the left.
- __rmul__(scalar) Operator [source]¶
Return a new
Operator
equal to thisOperator
multiplied by a scalar on the right.
- __sub__(other: Operator) Operator [source]¶
Return the difference of this
Operator
with anotherOperator
.
- append(term: OperatorTerm, coeff: Union[numbers.Number, numpy.ndarray, cupy.ndarray, Callback, Tuple[Union[numpy.ndarray, cupy.ndarray], Callback]] = 1.0, duality: bool = False, batch_size: Optional[int] = 1) None [source]¶
Append an
OperatorTerm
to thisOperator
.- Parameters
term – The
OperatorTerm
to be appended.coeff – The coefficient associated with this
OperatorTerm
.duality – Whether the elementary operators in
term
are applied on ket modes (False
) or bra modes (True
).batch_size – Batch size associated with the operator term.
- compute_action(t: float, params: Optional[Union[numpy.ndarray, cupy.ndarray, Sequence[float]]], state_in: State, state_out: State) None [source]¶
Compute the action of this
Operator
on an input state and accumulate into the output state.- Parameters
t – Time argument to be passed to all callback functions.
params – Additional arguments to be passed to all callback functions. The element type is required to be float (i.e “float64” for arrays). If batched operators or coefficients are used, they need to be passed as 2-dimensional the last dimension of which is the batch size. To avoid copy of the argument array, it can be passed as a fortran-contiguous cp.ndarray.
state – The input quantum state to which the
Operator
is to be applied.state_out – The output quantum state to which the action is to be accumulated. Defaults to
state
.
- compute_expectation(t: float, params: Optional[Union[numpy.ndarray, cupy.ndarray, Sequence[float]]], state: State, out: Optional[cupy.ndarray] = None) cupy.ndarray [source]¶
Compute the expectation value of this
Operator
on a state.- Parameters
t – Time argument to be passed to all callback functions.
params – Additional arguments to be passed to all callback functions. The element type is required to be float (i.e “float64” for arrays). If batched operators or coefficients are used, they need to be passed as 2-dimensional the last dimension of which is the batch size. To avoid copy of the argument array, it can be passed as a fortran-contiguous cp.ndarray.
state – The quantum state on which the expectation value is evaluated.
- Returns
The computed expectation value wrapped in a
cupy.ndarray
.
Note
Currently, this method executes in blocking manner, returning the expectation value only after the computation is finished.
- dual() Operator [source]¶
Return a shallow copy of this
Operator
with flipped duality for each term.
- prepare_action(ctx: WorkStream, state: State, state_out: Optional[State] = None, compute_type: Optional[str] = None) None [source]¶
Prepare the action of this
Operator
on an input state and accumulate into the output state.- Parameters
ctx – Library context, which contains workspace, stream and other configuration information.
state – The input quantum state to which the
Operator
is to be applied.state_out – The output quantum state to which the action is to be accumulated. Defaults to
state
.compute_type – The CUDA compute type to be used by the computation.
Attention
The
compute_type
argument is currently not used and will default to the data type.
- prepare_expectation(ctx: WorkStream, state: State, compute_type: Optional[str] = None) None [source]¶
Prepare the computation of an expectation value of this
Operator
on a state.- Parameters
ctx – Library context, which contains workspace, stream and other configuration information.
state – The quantum state on which the expectation value is evaluated.
compute_type – The CUDA compute type to be used by the computation.
Attention
The
compute_type
argument is currently not used and will default to the data type.
Attributes