# DictStateFn¶

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

Bases: qiskit.aqua.operators.state_fns.state_fn.StateFn

A class for state functions and measurements which are defined by a lookup table, stored in a dict.

Parameters
• primitive (Union[str, dict, Result, None]) – The dict, single bitstring (if defining a basis sate), or Qiskit Result, which defines the behavior of the underlying function.

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

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

Raises

TypeError – invalid parameters.

Methods

 add Return Operator addition of self and other, overloaded by +. adjoint Return a new Operator equal to the Operator’s adjoint (conjugate transpose), overloaded by ~. assign_parameters Binds scalar values to any Terra Parameters in the coefficients or primitives of the Operator, or substitutes one Parameter for another. bind_parameters Same as assign_parameters, but maintained for consistency with QuantumCircuit in Terra (which has both assign_parameters and bind_parameters). compose 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. equals Evaluate Equality between Operators, overloaded by ==. eval Evaluate the Operator’s underlying function, either on a binary string or another Operator. mul 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). neg Return the Operator’s negation, effectively just multiplying by -1.0, overloaded by -. permute Permute the qubits of the state function. power Compose with Self Multiple Times, undefined for StateFns. primitive_strings Return a set of strings describing the primitives contained in the Operator. reduce Try collapsing the Operator structure, usually after some type of conversion, e.g. sample Sample the state function as a normalized probability distribution. tensor Return tensor product between self and other, overloaded by ^. tensorpower Return tensor product with self multiple times, overloaded by ^. to_circuit_op Return StateFnCircuit corresponding to this StateFn. to_density_matrix Return matrix representing product of StateFn evaluated on pairs of basis states. to_legacy_op Attempt to return the Legacy Operator representation of the Operator. to_matrix Return NumPy representation of the Operator. to_matrix_op Return a VectorStateFn for this StateFn. to_spmatrix Same as to_matrix, but returns csr sparse matrix. traverse Apply the convert_fn to the internal primitive if the primitive is an Operator (as in the case of OperatorStateFn).

Attributes

ENABLE_DEPRECATION = True
INDENTATION = ' '
coeff

A coefficient by which the state function is multiplied.

Return type

Union[int, float, complex, ParameterExpression]

is_measurement

Whether the StateFn object is a measurement Operator.

Return type

bool

num_qubits
Return type

int

parameters
primitive

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