PrimitiveOp¶
- class PrimitiveOp(primitive=None, coeff=1.0)[source]¶
A class for representing basic Operators, backed by Operator primitives from Terra. This class (and inheritors) primarily serves to allow the underlying primitives to “flow” - i.e. interoperability and adherence to the Operator formalism - while the core computational logic mostly remains in the underlying primitives. For example, we would not produce an interface in Terra in which
QuantumCircuit1 + QuantumCircuit2
equaled the Operator sum of the circuit unitaries, rather than simply appending the circuits. However, within the Operator flow summing the unitaries is the expected behavior.Note that all mathematical methods are not in-place, meaning that they return a new object, but the underlying primitives are not copied.
- Parameters
(Instruction (primitive) – MatrixOperator, Pauli): The operator primitive being wrapped.
QuantumCircuit – MatrixOperator, Pauli): The operator primitive being wrapped.
list – MatrixOperator, Pauli): The operator primitive being wrapped.
np.ndarray – MatrixOperator, Pauli): The operator primitive being wrapped.
spmatrix – MatrixOperator, Pauli): The operator primitive being wrapped.
:param : MatrixOperator, Pauli): The operator primitive being wrapped. :type coeff:
Union
[int
,float
,complex
,ParameterExpression
,None
] :param coeff: A coefficient multiplyingthe primitive.
Attributes
The scalar coefficient multiplying the Operator.
The number of qubits over which the Operator is defined.
The primitive defining the underlying function of the Operator.
Methods
PrimitiveOp.__mul__
(other)Overload
*
for Operator scalar multiplication.PrimitiveOp.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
~
.PrimitiveOp.assign_parameters
(param_dict)Binds scalar values to any Terra
Parameters
in the coefficients or primitives of the Operator, or substitutes oneParameter
for another.PrimitiveOp.bind_parameters
(param_dict)Same as assign_parameters, but maintained for consistency with QuantumCircuit in Terra (which has both assign_parameters and bind_parameters).
PrimitiveOp.compose
(other)Return Operator Composition between self and other (linear algebra-style: A@B(x) = A(B(x))), overloaded by
@
.PrimitiveOp.equals
(other)Evaluate Equality between Operators, overloaded by
==
.PrimitiveOp.eval
([front])Evaluate the Operator’s underlying function, either on a binary string or another Operator.
Return Operator exponentiation, equaling e^(-i * op)
PrimitiveOp.log_i
([massive])Return a
MatrixOp
equivalent to log(H)/-i for this operator H.PrimitiveOp.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
-
.PrimitiveOp.power
(exponent)Return Operator composed with self multiple times, overloaded by
**
.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.
PrimitiveOp.tensor
(other)Return tensor product between self and other, overloaded by
^
.PrimitiveOp.tensorpower
(other)Return tensor product with self multiple times, overloaded by
^
.Returns a
QuantumCircuit
equivalent to this Operator.Returns a
CircuitOp
equivalent to this Operator.Returns an
Instruction
equivalent to this Operator.PrimitiveOp.to_legacy_op
([massive])Attempt to return the Legacy Operator representation of the Operator.
PrimitiveOp.to_matrix
([massive])Return NumPy representation of the Operator.
PrimitiveOp.to_matrix_op
([massive])Returns a
MatrixOp
equivalent to this Operator.PrimitiveOp.to_pauli_op
([massive])Returns a sum of
PauliOp
s equivalent to this Operator.PrimitiveOp.__mul__
(other)Overload
*
for Operator scalar multiplication.