state¶
Interfaces for classical or quantum states.
This module contains the interfaces State, BasisState, QuantumState,
BasisStateProbabilities, and BasisStateCounts. Specific implementations of the interfaces in
the Pauli bases can be found in the module parityos.states.pauli_state.
- class parityos.states.state.State¶
Bases:
HasFrozenQubits[QubitT_co],ABCInterface for all types of states defined on a set of qubits.
- abstractmethod flip_qubits(qubits: QubitT_co | Iterable[QubitT_co] | None = None) Self¶
Flip the state on every qubit in
qubits.For each qubit in
qubitsthe state on this qubit is flipped (0 <-> 1). Qubits inqubitsthat are not in this state are ignored.Note
If
qubitsisNone(default), all qubits are flipped.- Parameters:
qubits – Qubits to flip. If
None, all qubits are flipped. Defaults toNone.- Returns:
Copy of
selfwith state on all qubits inqubitsflipped
- class parityos.states.state.StateT_contra¶
A contravariant
TypeVarrepresenting aState.alias of TypeVar(‘StateT_contra’, bound=
State, contravariant=True)
- class parityos.states.state.BasisState¶
Bases:
State[QubitT_co],HasFrozenQubits[QubitT_co],ABCInterface for basis states of quantum states.
Basis states are assumed to be product states with an associated mapping
qubit_to_valuefrom each qubit to its boolean bit value representing the qubits state.- property qubit_to_value: MappingProxyType¶
A mapping from each qubit to its boolean value.
Example
A product state \(|0101\rangle\) on qubits
q_0, q_1, q_2, q_3would return a mapping equivalent to{q_0: False, q_1: True, q_2: False, q_3: True}.- Returns:
A mapping from each qubit to its boolean value, indicating the product state.
- get_bit_value(qubit: QubitT_co) bool¶
Get boolean bit assignment for
qubitof thisBasisState.- Parameters:
qubit – Qubit for which to get its assigned boolean bit value.
- Returns:
Boolean bit value of
qubitin this basis state.- Raises:
ParityOSException – If
qubitis not contained in this basis state.
- class parityos.states.state.BasisStateProbabilities¶
Bases:
State[QubitT_co],Generic[QubitT_co,BasisStateT_co],ABCInterface for states with probabilities assigned to
BasisStateinstances.BasisStateProbabilitiesare defined by a mapping from product states (BasisStateinstances) to the probability of observing thisBasisState.- property state_to_probability: MappingProxyType¶
A mapping from
BasisStateinstances to their probabilities.Example
A state with probability 1/2 of measuring the basis states \(|01\rangle\) and \(|10\rangle\) would return a mapping equivalent to \(\{|01\rangle: 0.5, |10\rangle: 0.5\}\).
- class parityos.states.state.QuantumState¶
Bases:
BasisStateProbabilities[QubitT_co,BasisStateT_co],ABCInterface for quantum states.
Quantum states are defined by a mapping from product states (
BasisStateinstances) to their corresponding amplitudes. Amplitudes can be complex numbers orSymboliccoefficients.- property state_to_amplitude: MappingProxyType¶
A mapping from
BasisStateinstances to their amplitudes.Amplitudes can be complex numbers or
Symboliccoefficients.Example
The Bell state \(1/\sqrt{2}\left(|00\rangle + |11\rangle\right)\) would return a mapping equivalent to \(\{|00\rangle: 1/\sqrt{2}, |11\rangle: 1/\sqrt{2}\}\).
- abstractmethod to_normalized() Self¶
Rescale all amplitudes such that their squared absolute values sum to 1, i.e. the quantum state is properly normalized.
- Returns:
A normalized copy of this state.
- property norm_squared: Symbolic | float¶
Squared norm of the quantum state \(\langle\Psi|\Psi\rangle\).
- property norm: Symbolic | float¶
Norm of the quantum state \(\lVert|\Psi\rangle\rVert = \sqrt{\langle\Psi|\Psi\rangle}\).
- property state_to_probability: MappingProxyType¶
A mapping from
BasisStateinstances to their probabilities.Example
A state with probability 1/2 of measuring the basis states \(|01\rangle\) and \(|10\rangle\) would return a mapping equivalent to \(\{|01\rangle: 0.5, |10\rangle: 0.5\}\).
- class parityos.states.state.BasisStateCounts¶
Bases:
BasisStateProbabilities[QubitT_co,BasisStateT_co],ABCInterface for an ensemble of measured basis states with corresponding measurement counts.
BasisStateCountsare defined by a mapping from product states (BasisStateinstances) to their corresponding measurement counts (integer). They are typically obtained from measurements on QPUs where measurement counts of basis states are recorded, i.e. how often they have been observed.- property total_count: int¶
Sum of all measurement counts.
This corresponds to the total number of measurements performed, and is useful for normalization and obtaining empirical probabilities of measuring individual basis states.
- Returns:
The total sum of all measurement counts.
- property state_to_count: MappingProxyType¶
A mapping from
BasisStateinstances to their measurement counts.
- property state_to_probability: MappingProxyType¶
A mapping from
BasisStateinstances to their probabilities.Example
A state with probability 1/2 of measuring the basis states \(|01\rangle\) and \(|10\rangle\) would return a mapping equivalent to \(\{|01\rangle: 0.5, |10\rangle: 0.5\}\).