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), or three elements (OperatorTerm
, coefficient and duality). If the second or third element is not given, they will be set to the default values (coefficient=1
,duality=False
).
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: Tuple[OperatorTerm, Optional[Union[numbers.Number, Tuple]], Optional[bool]]) None [source]¶
Initialize an operator representing a collection of
OperatorTerm
objects.
- __mul__(scalar) Operator [source]¶
Return a new
Operator
equal to thisOperator
multiplied by a scalar 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, Callable[[numbers.Number, Sequence], numbers.Number]] = 1.0, duality: bool = False) 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
).
- compute_action(t: float, params: list[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.
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: Sequence[float], state: State) 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.
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, partial 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