quri_parts.core.state package#

class 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 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)#

Returns a new state with the gates applied.

The original state is not changed.

Parameters:

gates (circuit.circuit.GateSequence) –

Return type:

CircuitQuantumState

class GeneralCircuitQuantumState(n_qubits, circuit=None)#

Bases: CircuitQuantumStateMixin, CircuitQuantumState

GeneralCircuitQuantumState represents a state given as a result of applying a circuit to |00…0> state.

Parameters:
property qubit_count: int#

Returns the qubit count of the state.

with_gates_applied(gates)#

Returns a new state with the gates applied.

The original state is not changed.

Parameters:

gates (circuit.circuit.GateSequence) –

Return type:

GeneralCircuitQuantumState

class ParametricCircuitQuantumState(n_qubits, circuit)#

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.

Parameters:
property qubit_count: int#

Returns the qubit count of the state.

with_primitive_circuit()#

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.

Return type:

ParametricCircuitQuantumState

with_gates_applied(gates)#

Returns a new state with the gates applied.

The original state is not changed.

Parameters:

gates (circuit.circuit.GateSequence) –

Return type:

ParametricCircuitQuantumState

bind_parameters(params)#

Returns a new state with the circuit parameters assigned concrete values.

This method does not modify self but returns a newly created state.

Parameters:

params (Sequence[float]) –

Return type:

GeneralCircuitQuantumState

class ComputationalBasisState(n_qubits, *, bits=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 (int) – The number of qubits.

  • bits (int) – 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)#

Apply a Pauli gate to the quantum state.

Parameters:

gate (QuantumGate) –

Return type:

ComputationalBasisState

with_gates_applied(gates)#

Returns a new state with the gates applied.

The original state is not changed.

Parameters:

gates (circuit.circuit.GateSequence) –

Return type:

ComputationalBasisState | GeneralCircuitQuantumState

property bits: int#

An integer representing a bit string of the computational basis state.

property phase: float#

The phase of the state.

comp_basis_superposition(state_a, state_b, theta, phi)#

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.

Parameters:
Return type:

GeneralCircuitQuantumState

ComputationalBasisSuperposition#

ComputationalBasisSuperposition represents a state that is formed as a linear combination of quri_parts.core.state.ComputationalBasisStates. Note that the state expressed in this form is not necessarily normalized.

StateVectorType = 'npt.NDArray[np.cfloat]'#

A type alias representing a numerical state vector, equivalent to np.ndarray of complex floats.

class QuantumStateVector(n_qubits, vector=None, circuit=None)#

Bases: QuantumStateVectorMixin, CircuitQuantumStateMixin, QuantumState

QuantumStateVector represents a state defined by a state vector with an optional circuit to be applied.

Parameters:
  • n_qubits (int) –

  • vector (Optional[Union[StateVectorType, 'npt.ArrayLike']]) –

  • circuit (Optional[NonParametricQuantumCircuit]) –

property qubit_count: int#

Returns the qubit count of the state.

with_gates_applied(gates)#

Returns a new state with the gates applied.

The original state is not changed.

Parameters:

gates (circuit.circuit.GateSequence) –

Return type:

QuantumStateVector

class ParametricQuantumStateVector(n_qubits, circuit, vector=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.

Parameters:
property qubit_count: int#

Returns the qubit count of the state.

with_primitive_circuit()#

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.

Return type:

ParametricQuantumStateVector

with_gates_applied(gates)#

Returns a new state with the gates applied.

The original state is not changed.

Parameters:

gates (circuit.circuit.GateSequence) –

Return type:

ParametricQuantumStateVector

bind_parameters(params)#

Returns a new state with the circuit parameters assigned concrete values.

This method does not modify self but returns a newly created state.

Parameters:

params (Sequence[float]) –

Return type:

QuantumStateVector

class 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 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)

quantum_state(n_qubits, *, vector=None, bits=0, circuit=None)#

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.

Parameters:
Return type:

QuantumState

apply_circuit(circuit, state)#

Returns a new state with the circuit applied.

The original state is not changed.

Parameters:
Return type:

QuantumState

Submodules#