OperatorStateFn¶
- class OperatorStateFn(primitive=None, coeff=1.0, is_measurement=False)[source]¶
A class for state functions and measurements which are defined by a density Operator, stored using an
OperatorBase
.- Parameters
primitive (
Optional
[OperatorBase
]) – TheOperatorBase
which defines the behavior of the underlying State function.coeff (
Union
[int
,float
,complex
,ParameterExpression
]) – A coefficient by which to multiply the state functionis_measurement (
bool
) – Whether the StateFn is a measurement operator
Attributes
A coefficient by which the state function is multiplied.
Whether the StateFn object is a measurement Operator.
The number of qubits over which the Operator is defined.
The primitive which defines the behavior of the underlying State function.
Methods
OperatorStateFn.__mul__
(other)Overload
*
for Operator scalar multiplication.OperatorStateFn.add
(other)Return Operator addition of self and other, overloaded by
+
.Return a new Operator equal to the Operator’s adjoint (conjugate transpose), overloaded by
~
.OperatorStateFn.assign_parameters
(param_dict)Binds scalar values to any Terra
Parameters
in the coefficients or primitives of the Operator, or substitutes oneParameter
for another.OperatorStateFn.bind_parameters
(param_dict)Same as assign_parameters, but maintained for consistency with QuantumCircuit in Terra (which has both assign_parameters and bind_parameters).
OperatorStateFn.compose
(other)Composition (Linear algebra-style: A@B(x) = A(B(x))) is not well defined for states in the binary function model, but is well defined for measurements.
OperatorStateFn.equals
(other)Evaluate Equality between Operators, overloaded by
==
.OperatorStateFn.eval
([front])Evaluate the Operator’s underlying function, either on a binary string or another Operator.
OperatorStateFn.mul
(scalar)Returns the scalar multiplication of the Operator, overloaded by
*
, including support for Terra’sParameters
, which can be bound to values later (viabind_parameters
).Return the Operator’s negation, effectively just multiplying by -1.0, overloaded by
-
.OperatorStateFn.power
(exponent)Compose with Self Multiple Times, undefined for StateFns.
Return a set of strings describing the primitives contained in the Operator.
Try collapsing the Operator structure, usually after some type of conversion, e.g.
OperatorStateFn.sample
([shots, massive, …])Sample the state function as a normalized probability distribution.
OperatorStateFn.tensor
(other)Return tensor product between self and other, overloaded by
^
.OperatorStateFn.tensorpower
(other)Return tensor product with self multiple times, overloaded by
^
.Return
StateFnCircuit
corresponding to this StateFn.OperatorStateFn.to_density_matrix
([massive])Return numpy matrix of density operator, warn if more than 16 qubits to force the user to set massive=True if they want such a large matrix.
OperatorStateFn.to_legacy_op
([massive])Attempt to return the Legacy Operator representation of the Operator.
OperatorStateFn.to_matrix
([massive])Note: this does not return a density matrix, it returns a classical matrix containing the quantum or classical vector representing the evaluation of the state function on each binary basis state.
OperatorStateFn.to_matrix_op
([massive])Return a MatrixOp for this operator.
OperatorStateFn.traverse
(convert_fn[, coeff])Apply the convert_fn to the internal primitive if the primitive is an Operator (as in the case of
OperatorStateFn
).OperatorStateFn.__mul__
(other)Overload
*
for Operator scalar multiplication.