States
QuantumFlow representations of pure quantum states and actions on states.
class quantumflow.states. State ( tensor : ArrayLike , qubits : Sequence [ Qubit ] | None = None , memory : Mapping | None = 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 ( qubits : Sequence [ Qubit ] | None = None ) → Density
Convert a pure state to a density matrix.
Parameters:
qubits – The qubit subspace. If not given return the density
matrix for all the qubits (which can take a lot of memory!)
expectation ( diag_hermitian : ArrayLike , trials : int | None = None ) → ndarray
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 ( ) → ndarray
Measure the state in the computational basis.
Returns:
A [2]*bits array of qubit states, either 0 or 1
normalize ( ) → State
Normalize the state
probabilities ( ) → ndarray
Returns:
The state probabilities
sample ( trials : int ) → ndarray
Measure the state in the computational basis the the given number
of trials, and return the counts of each output configuration.
quantumflow.states. zero_state ( qubits : int | Sequence [ Qubit ] ) → State
Return the all-zero state on N qubits
quantumflow.states. w_state ( qubits : int | Sequence [ Qubit ] ) → State
Return a W state on N qubits
quantumflow.states. ghz_state ( qubits : int | Sequence [ Qubit ] ) → State
Return a GHZ state on N qubits
quantumflow.states. random_state ( qubits : int | Sequence [ Qubit ] ) → State
Return a random state from the space of N qubits
quantumflow.states. join_states ( ket0 : State , ket1 : State ) → State
Join two mixed states into a larger qubit state
quantumflow.states. print_state ( state : State , file : TextIO | None = None ) → None
Print a state vector
quantumflow.states. print_probabilities ( state : State , ndigits : int = 4 , file : TextIO | None = None ) → None
Pretty print state probabilities.
Parameters: