quri_parts.core.state package#
Interfaces and classes representing quantum states.
- class quri_parts.core.state.QuantumState(*args, **kwargs)#
Bases:
Protocol
QuantumState is an interface for classes representing a quantum state.
Since this interface is defined with Protocol, explicit inheritance of this class is not necessary when implementing a concrete class with this interface. (You can inherit it to indicate the interface if you want.)
- abstract property qubit_count: int#
Returns the qubit count of the state.
- class quri_parts.core.state.CircuitQuantumState(*args, **kwargs)#
Bases:
QuantumState
CircuitQuantumState is an interface for classes representing a quantum state generated by applying a circuit to |00…0> state.
- abstract property circuit: ImmutableQuantumCircuit#
Circuit to build the quantum state.
- abstract with_gates_applied(gates: NonParametricQuantumCircuit | Sequence[QuantumGate]) CircuitQuantumState #
Returns a new state with the gates applied.
The original state is not changed.
- class quri_parts.core.state.GeneralCircuitQuantumState(n_qubits: int, circuit: NonParametricQuantumCircuit | None = None)#
Bases:
CircuitQuantumStateMixin
,CircuitQuantumState
GeneralCircuitQuantumState represents a state given as a result of applying a circuit to |00…0> state.
- property qubit_count: int#
Returns the qubit count of the state.
- with_gates_applied(gates: NonParametricQuantumCircuit | Sequence[QuantumGate]) GeneralCircuitQuantumState #
Returns a new state with the gates applied.
The original state is not changed.
- class quri_parts.core.state.ParametricCircuitQuantumState(n_qubits: int, circuit: UnboundParametricQuantumCircuitProtocol)#
Bases:
ParametricCircuitQuantumStateMixin
,QuantumState
ParametricCircuitQuantumState represents a quantum state generated by applying a parametric circuit to |00…0> state.
This class holds an unbound parametric circuit, thus circuit parameters are not bound to concrete values. Use
bind_parameters()
when you need to bind concrete parameter values.- property qubit_count: int#
Returns the qubit count of the state.
- with_primitive_circuit() ParametricCircuitQuantumState #
Returns a new ParametricCircuitQuantumState whose circuit is replaced with the corresponding primitive circuit.
The original state is not changed. For details about the primitive circuit, please refer to .primitive_circuit() in
UnboundParametricQuantumCircuitProtocol
.
- with_gates_applied(gates: NonParametricQuantumCircuit | Sequence[QuantumGate]) ParametricCircuitQuantumState #
Returns a new state with the gates applied.
The original state is not changed.
- bind_parameters(params: Sequence[float]) GeneralCircuitQuantumState #
Returns a new state with the circuit parameters assigned concrete values.
This method does not modify self but returns a newly created state.
- class quri_parts.core.state.ComputationalBasisState(n_qubits: int, *, bits: int = 0)#
Bases:
CircuitQuantumState
ComputationalBasisState represents a computational basis state. A computational basis state can also be considered as a state given as a result of applying Pauli gates to |00…0> state. It internally holds a phase factor resulted from the applications of Pauli gates.
- Parameters:
n_qubits – The number of qubits.
bits – An integer representing a bit string of the computational basis state.
- property qubit_count: int#
Returns the qubit count of the state.
- property circuit: ImmutableQuantumCircuit#
Circuit to build the quantum state.
- with_pauli_gate_applied(gate: QuantumGate) ComputationalBasisState #
Apply a Pauli gate to the quantum state.
- with_gates_applied(gates: NonParametricQuantumCircuit | Sequence[QuantumGate]) ComputationalBasisState | GeneralCircuitQuantumState #
Returns a new state with the gates applied.
The original state is not changed.
- property bits: int#
An integer representing a bit string of the computational basis state.
- property phase: float#
The phase of the state.
- quri_parts.core.state.comp_basis_superposition(state_a: ComputationalBasisState, state_b: ComputationalBasisState, theta: float, phi: float) GeneralCircuitQuantumState #
Return a superposition state (as GeneralCircuitQuantumState) composed of two ComputationalBasisState.
\[\cos \theta | state_a \rangle + e^{i \phi} \sin \theta | state_b \rangle\]Raises ValueError if the qubit counts of the two states are different.
- quri_parts.core.state.ComputationalBasisSuperposition#
ComputationalBasisSuperposition represents a state that is formed as a linear combination of
quri_parts.core.state.ComputationalBasisState
s. Note that the state expressed in this form is not necessarily normalized.
- quri_parts.core.state.StateVectorType = 'npt.NDArray[np.cfloat]'#
A type alias representing a numerical state vector, equivalent to np.ndarray of complex floats.
- class quri_parts.core.state.QuantumStateVector(n_qubits: int, vector: npt.NDArray[np.cfloat] | npt.ArrayLike | None = None, circuit: NonParametricQuantumCircuit | None = None)#
Bases:
QuantumStateVectorMixin
,CircuitQuantumStateMixin
,QuantumState
QuantumStateVector represents a state defined by a state vector with an optional circuit to be applied.
- property qubit_count: int#
Returns the qubit count of the state.
- with_gates_applied(gates: NonParametricQuantumCircuit | Sequence[QuantumGate]) QuantumStateVector #
Returns a new state with the gates applied.
The original state is not changed.
- class quri_parts.core.state.ParametricQuantumStateVector(n_qubits: int, circuit: UnboundParametricQuantumCircuitProtocol, vector: npt.NDArray[np.cfloat] | npt.ArrayLike | None = None)#
Bases:
QuantumStateVectorMixin
,ParametricCircuitQuantumStateMixin
,QuantumState
ParametricQuantumStateVector represents a state defined by a state vector with a parametric circuit applied.
This class holds an unbound parametric circuit, thus circuit parameters are not bound to concrete values. Use
bind_parameters()
when you need to bind concrete parameter values.- property qubit_count: int#
Returns the qubit count of the state.
- with_primitive_circuit() ParametricQuantumStateVector #
Returns a new ParametricQuantumStateVector whose circuit is replaced with the corresponding primitive circuit.
The original state is not changed. For details about the primitive circuit, please refer to .primitive_circuit() in
UnboundParametricQuantumCircuitProtocol
.
- with_gates_applied(gates: NonParametricQuantumCircuit | Sequence[QuantumGate]) ParametricQuantumStateVector #
Returns a new state with the gates applied.
The original state is not changed.
- bind_parameters(params: Sequence[float]) QuantumStateVector #
Returns a new state with the circuit parameters assigned concrete values.
This method does not modify self but returns a newly created state.
- class quri_parts.core.state.QuantumStateT#
A type variable representing either one of non-parametric quantum state classes. You can use it as a type parameter for generic classes or functions which can be used with any non-parametric quantum state (i.e. not depending on whether the state is a state vector or not).
alias of TypeVar(‘QuantumStateT’, ~quri_parts.core.state.state.CircuitQuantumState, ~quri_parts.core.state.state_vector.QuantumStateVector)
- class quri_parts.core.state.ParametricQuantumStateT#
A type variable representing either one of parametric quantum state classes. You can use it as a type parameter for generic classes or functions which can be used with any parametric quantum state (i.e. not depending on whether the state is a state vector or not).
alias of TypeVar(‘ParametricQuantumStateT’, ~quri_parts.core.state.state_parametric.ParametricCircuitQuantumState, ~quri_parts.core.state.state_vector_parametric.ParametricQuantumStateVector)
- quri_parts.core.state.quantum_state(n_qubits: int, vector: npt.NDArray[np.cfloat] | npt.ArrayLike | None = None, bits: int = 0, circuit: NonParametricQuantumCircuit | UnboundParametricQuantumCircuitProtocol | None = None) QuantumState #
Returns a quantum state generated by a given vector, bits, and a circuit.
Raises ValueError if both a vector and bits input at the same time.
- quri_parts.core.state.apply_circuit(circuit: NonParametricQuantumCircuit | UnboundParametricQuantumCircuitProtocol, state: QuantumState) QuantumState #
Returns a new state with the circuit applied.
The original state is not changed.
Submodules#
- quri_parts.core.state.comp_basis module
- quri_parts.core.state.state module
- quri_parts.core.state.state_helper module
- quri_parts.core.state.state_parametric module
- quri_parts.core.state.state_vector module
- quri_parts.core.state.state_vector_parametric module