quri_parts.circuit.circuit module#

quri_parts.circuit.circuit.is_gate_sequence(gates: QuantumCircuitProtocol | NonParametricQuantumCircuit | Sequence[QuantumGate]) typing_extensions.TypeGuard[NonParametricQuantumCircuit | Sequence[QuantumGate]]#
class quri_parts.circuit.circuit.QuantumCircuitProtocol(*args, **kwargs)#

Bases: Protocol

Interface protocol for a quantum circuit.

This interface covers all quantum circuit classes, including:

  • Non-parametric circuit, parametric circuit and linearly mapped parametric circuit

  • Mutable and immutable circuit classes

abstract property qubit_count: int#

Number of qubits involved in the circuit.

abstract property cbit_count: int#

Number of classical bits involved in the circuit.

abstract property depth: int#

Returns circuit depth.

class quri_parts.circuit.circuit.MutableQuantumCircuitProtocol(*args, **kwargs)#

Bases: QuantumCircuitProtocol, Protocol

Interface protocol for a mutable quantum circuit.

This interface represents quantum circuits that can be modified by adding QuantumGates (non-parametric gates).

Some methods (add_???_gate) have implementations using an abstract method add_gate().

abstract add_gate(gate: QuantumGate, gate_index: int | None = None) None#

Add a (non-parametric) quantum gate to the circuit.

abstract extend(gates: NonParametricQuantumCircuit | Sequence[QuantumGate]) None#

Extend the circuit with given gate sequence.

add_Identity_gate(qubit_index: int) None#

Add an Identity gate to the circuit.

add_X_gate(qubit_index: int) None#

Add an X gate to the circuit.

add_Y_gate(qubit_index: int) None#

Add a Y gate to the circuit.

add_Z_gate(qubit_index: int) None#

Add a Z gate to the circuit.

add_H_gate(qubit_index: int) None#

Add an H gate to the circuit.

add_S_gate(index: int) None#

Add a S gate to the circuit.

add_Sdag_gate(index: int) None#

Add a Sdag gate to the circuit.

add_SqrtX_gate(index: int) None#

Add a SqrtX gate to the circuit.

add_SqrtXdag_gate(index: int) None#

Add a SqrtXdag gate to the circuit.

add_SqrtY_gate(index: int) None#

Add a SqrtY gate to the circuit.

add_SqrtYdag_gate(index: int) None#

Add a SqrtYdag gate to the circuit.

add_T_gate(index: int) None#

Add a T gate to the circuit.

add_Tdag_gate(index: int) None#

Add a Tdag gate to the circuit.

add_U1_gate(index: int, lmd: float) None#

Add an U1 gate to the circuit.

add_U2_gate(index: int, phi: float, lmd: float) None#

Add an U2 gate to the circuit.

add_U3_gate(index: int, theta: float, phi: float, lmd: float) None#

Add an U3 gate to the circuit.

add_RX_gate(index: int, angle: float) None#

Add a RX gate to the circuit.

add_RY_gate(index: int, angle: float) None#

Add a RY gate to the circuit.

add_RZ_gate(index: int, angle: float) None#

Add a RZ gate to the circuit.

add_CNOT_gate(control_index: int, target_index: int) None#

Add a CNOT gate to the circuit.

add_CZ_gate(control_qubit_index: int, target_qubit_index: int) None#

Add a Control-Z gate to the circuit.

add_SWAP_gate(target_index1: int, target_index2: int) None#

Add a SWAP gate to the circuit.

add_TOFFOLI_gate(control_index1: int, control_index2: int, target_index: int) None#

Add a TOFFOLI gate to the circuit.

add_UnitaryMatrix_gate(target_indices: Sequence[int], unitary_matrix: Sequence[Sequence[complex]]) None#

Add a UnitaryMatrix gate to the circuit.

add_SingleQubitUnitaryMatrix_gate(target_index: int, unitary_matrix: Sequence[Sequence[complex]]) None#

Add a single qubit UnitaryMatrix gate to the circuit.

add_TwoQubitUnitaryMatrix_gate(target_index1: int, target_index2: int, unitary_matrix: Sequence[Sequence[complex]]) None#

Add a two qubit UnitaryMatrix gate to the circuit.

add_Pauli_gate(target_indices: Sequence[int], pauli_ids: Sequence[int]) None#

Add a Pauli gate to the circuit.

add_PauliRotation_gate(target_qubits: Sequence[int], pauli_id_list: Sequence[int], angle: float) None#

Add a Pauli rotation gate to the circuit.

measure(qubit_indices: int | Sequence[int], classical_indices: int | Sequence[int]) None#

Adds measurement gate at selected qubits.

class quri_parts.circuit.circuit.NonParametricQuantumCircuit(*args, **kwargs)#

Bases: QuantumCircuitProtocol, ABC

A base class for quantum circuits having only non-parametric gates.

This class support + operator with GateSequence.

abstract property gates: Sequence[QuantumGate]#

Returns the gate sequence of the circuit.

property depth: int#

Returns circuit depth.

combine(gates: NonParametricQuantumCircuit | Sequence[QuantumGate]) QuantumCircuit#

Create a new circuit with itself and the given gates combined.

abstract freeze() ImmutableQuantumCircuit#

Returns a “freezed” version of itself.

The “freezed” version is an immutable object and can be reused safely without copying.

abstract get_mutable_copy() QuantumCircuit#

Returns a copy of itself that can be modified.

Use this method when you want to get a new circuit based on an existing circuit but don’t want to modify it.

class quri_parts.circuit.circuit.QuantumCircuit(qubit_count: int, cbit_count: int = 0, gates: Sequence[QuantumGate] = [])#

Bases: NonParametricQuantumCircuit, MutableQuantumCircuitProtocol

A mutable quantum circuit having only non-parametric gates.

property qubit_count: int#

Number of qubits involved in the circuit.

property cbit_count: int#

Number of classical bits involved in the circuit.

property gates: Sequence[QuantumGate]#

Returns the gate sequence of the circuit.

freeze() ImmutableQuantumCircuit#

Returns a “freezed” version of itself.

The “freezed” version is an immutable object and can be reused safely without copying.

get_mutable_copy() QuantumCircuit#

Returns a copy of itself that can be modified.

Use this method when you want to get a new circuit based on an existing circuit but don’t want to modify it.

add_gate(gate: QuantumGate, gate_index: int | None = None) None#

Add a (non-parametric) quantum gate to the circuit.

extend(gates: NonParametricQuantumCircuit | Sequence[QuantumGate]) None#

Extend the circuit with given gate sequence.

class quri_parts.circuit.circuit.ImmutableQuantumCircuit(circuit: NonParametricQuantumCircuit)#

Bases: NonParametricQuantumCircuit

An immutable quantum circuit having only non-parametric gates.

property qubit_count: int#

Number of qubits involved in the circuit.

property cbit_count: int#

Number of classical bits involved in the circuit.

property gates: Sequence[QuantumGate]#

Returns the gate sequence of the circuit.

freeze() ImmutableQuantumCircuit#

Returns a “freezed” version of itself.

The “freezed” version is an immutable object and can be reused safely without copying.

get_mutable_copy() QuantumCircuit#

Returns a copy of itself that can be modified.

Use this method when you want to get a new circuit based on an existing circuit but don’t want to modify it.