StateFn

class StateFn(primitive=None, coeff=1.0, is_measurement=False)[source]

A class for representing state functions and measurements.

State functions are defined to be complex functions over a single binary string (as compared to an operator, which is defined as a function over two binary strings, or a function taking a binary function to another binary function). This function may be called by the eval() method.

Measurements are defined to be functionals over StateFns, taking them to real values. Generally, this real value is interpreted to represent the probability of some classical state (binary string) being observed from a probabilistic or quantum system represented by a StateFn. This leads to the equivalent definition, which is that a measurement m is a function over binary strings producing StateFns, such that the probability of measuring a given binary string b from a system with StateFn f is equal to the inner product between f and m(b).

NOTE: State functions here are not restricted to wave functions, as there is no requirement of normalization.

Parameters
  • primitive (Union[str, dict, Result, list, ndarray, Statevector, QuantumCircuit, Instruction, OperatorBase, None]) – The primitive which defines the behavior of the underlying State function.

  • coeff (Union[int, float, complex, ParameterExpression]) – A coefficient by which the state function is multiplied.

  • is_measurement (bool) – Whether the StateFn is a measurement operator

Attributes

StateFn.coeff

A coefficient by which the state function is multiplied.

StateFn.is_measurement

Whether the StateFn object is a measurement Operator.

StateFn.num_qubits

The number of qubits over which the Operator is defined.

StateFn.primitive

The primitive which defines the behavior of the underlying State function.

Methods

StateFn.__mul__(other)

Overload * for Operator scalar multiplication.

StateFn.add(other)

Return Operator addition of self and other, overloaded by +.

StateFn.adjoint()

Return a new Operator equal to the Operator’s adjoint (conjugate transpose), overloaded by ~.

StateFn.assign_parameters(param_dict)

Binds scalar values to any Terra Parameters in the coefficients or primitives of the Operator, or substitutes one Parameter for another.

StateFn.bind_parameters(param_dict)

Same as assign_parameters, but maintained for consistency with QuantumCircuit in Terra (which has both assign_parameters and bind_parameters).

StateFn.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.

StateFn.equals(other)

Evaluate Equality between Operators, overloaded by ==.

StateFn.eval([front])

Evaluate the Operator’s underlying function, either on a binary string or another Operator.

StateFn.mul(scalar)

Returns the scalar multiplication of the Operator, overloaded by *, including support for Terra’s Parameters, which can be bound to values later (via bind_parameters).

StateFn.neg()

Return the Operator’s negation, effectively just multiplying by -1.0, overloaded by -.

StateFn.power(exponent)

Compose with Self Multiple Times, undefined for StateFns.

StateFn.primitive_strings()

Return a set of strings describing the primitives contained in the Operator.

StateFn.reduce()

Try collapsing the Operator structure, usually after some type of conversion, e.g.

StateFn.sample([shots, massive, …])

Sample the state function as a normalized probability distribution.

StateFn.tensor(other)

Return tensor product between self and other, overloaded by ^.

StateFn.tensorpower(other)

Return tensor product with self multiple times, overloaded by ^.

StateFn.to_density_matrix([massive])

Return matrix representing product of StateFn evaluated on pairs of basis states.

StateFn.to_legacy_op([massive])

Attempt to return the Legacy Operator representation of the Operator.

StateFn.to_matrix([massive])

Return NumPy representation of the Operator.

StateFn.to_matrix_op([massive])

Return a VectorStateFn for this StateFn.

StateFn.traverse(convert_fn[, coeff])

Apply the convert_fn to the internal primitive if the primitive is an Operator (as in the case of OperatorStateFn).

StateFn.__mul__(other)

Overload * for Operator scalar multiplication.