State objects

class quantumflow.State(tensor: TensorLike, qubits: Qubits = None, memory: Dict[quantumflow.cbits.Addr, Any] = None)

The quantum state of a collection of qubits.

Note that memory usage grows exponentially with the number of qubits. (16*2^N bytes for N qubits)

asdensity() → qf.Density

Convert a pure state to a density matrix

expectation(diag_hermitian: Any, trials: int = None) → BKTensor

Return the expectation of a measurement. Since we can only measure our computer in the computational basis, we only require the diagonal of the Hermitian in that basis.

If the number of trials is specified, we sample the given number of times. Else we return the exact expectation (as if we’d performed an infinite number of trials. )

measure() → numpy.ndarray

Measure the state in the computational basis.

Returns:A [2]*bits array of qubit states, either 0 or 1
norm() → BKTensor

Return the state vector norm

normalize() → qf.State

Normalize the state

permute(qubits: Qubits) → qf.State

Return a copy of this state with qubit labels permuted

probabilities() → BKTensor
Returns:The state probabilities

Return the total number of qubits


Return qubit labels of this state

relabel(qubits: Qubits) → qf.State

Return a copy of this state with new qubits

sample(trials: int) → numpy.ndarray

Measure the state in the computational basis the the given number of trials, and return the counts of each output configuration.


Returns the tensor representation of state vector

Standard states

quantumflow.zero_state(qubits: Union[int, Qubits]) → qf.State

Return the all-zero state on N qubits

quantumflow.w_state(qubits: Union[int, Qubits]) → qf.State

Return a W state on N qubits

quantumflow.ghz_state(qubits: Union[int, Qubits]) → qf.State

Return a GHZ state on N qubits

quantumflow.random_state(qubits: Union[int, Qubits]) → qf.State

Return a random state from the space of N qubits

Actions on states

quantumflow.join_states(*states) → qf.State

Join two state vectors into a larger qubit state

quantumflow.print_state(state: qf.State, file: TextIO = None) → None

Print a state vector

quantumflow.print_probabilities(state: qf.State, ndigits: int = 4, file: TextIO = None) → None

Pretty print state probabilities.

  • state
  • ndigits – Number of digits of accuracy
  • file – Output stream (Defaults to stdout)