cuquantum.densitymat.Operator¶
- class cuquantum.densitymat.Operator(hilbert_space_dims, *terms)[source]¶
Operator representing a collection of
OperatorTermobjects.The action of an
Operatormaps aStateto anotherState. AnOperatoracts on an instance ofStatethrough itscomputemethod after itspreparemethod 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 (OperatorTermand 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
Operatorequal to the sum of thisOperatorwith anotherOperator.
- __iadd__(other: Union[Operator, OperatorTerm]) None[source]¶
Inplace add another
OperatororOperatorTerminto 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
OperatorTermobjects.
- __mul__(factor: Union[numbers.Number, numpy.ndarray, cupy.ndarray, Callback, Tuple[Union[numpy.ndarray, cupy.ndarray], Callback]]) Operator[source]¶
Return a new
Operatorequal to thisOperatormultiplied by a scalar or a batch of scalars on the left.
- __rmul__(scalar) Operator[source]¶
Return a new
Operatorequal to thisOperatormultiplied by a scalar on the right.
- __sub__(other: Operator) Operator[source]¶
Return the difference of this
Operatorwith 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
OperatorTermto thisOperator.- Parameters
term – The
OperatorTermto be appended.coeff – The coefficient associated with this
OperatorTerm.duality – Whether the elementary operators in
termare 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
Operatoron 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
Operatoris 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
Operatoron 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.
- prepare_action(ctx: WorkStream, state: State, state_out: Optional[State] = None, compute_type: Optional[str] = None) None[source]¶
Prepare the action of this
Operatoron 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
Operatoris 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_typeargument 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
Operatoron 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_typeargument is currently not used and will default to the data type.
Attributes