quri_parts.circuit.circuit module#

is_gate_sequence(gates)#
Parameters:

gates (QuantumCircuitProtocol | circuit.circuit.GateSequence) –

Return type:

typing_extensions.TypeGuard[circuit.circuit.GateSequence]

class 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 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, gate_index=None)#

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

Parameters:
Return type:

None

abstract extend(gates)#

Extend the circuit with given gate sequence.

Parameters:

gates (circuit.circuit.GateSequence) –

Return type:

None

add_Identity_gate(qubit_index)#

Add an Identity gate to the circuit.

Parameters:

qubit_index (int) –

Return type:

None

add_X_gate(qubit_index)#

Add an X gate to the circuit.

Parameters:

qubit_index (int) –

Return type:

None

add_Y_gate(qubit_index)#

Add a Y gate to the circuit.

Parameters:

qubit_index (int) –

Return type:

None

add_Z_gate(qubit_index)#

Add a Z gate to the circuit.

Parameters:

qubit_index (int) –

Return type:

None

add_H_gate(qubit_index)#

Add an H gate to the circuit.

Parameters:

qubit_index (int) –

Return type:

None

add_S_gate(index)#

Add a S gate to the circuit.

Parameters:

index (int) –

Return type:

None

add_Sdag_gate(index)#

Add a Sdag gate to the circuit.

Parameters:

index (int) –

Return type:

None

add_SqrtX_gate(index)#

Add a SqrtX gate to the circuit.

Parameters:

index (int) –

Return type:

None

add_SqrtXdag_gate(index)#

Add a SqrtXdag gate to the circuit.

Parameters:

index (int) –

Return type:

None

add_SqrtY_gate(index)#

Add a SqrtY gate to the circuit.

Parameters:

index (int) –

Return type:

None

add_SqrtYdag_gate(index)#

Add a SqrtYdag gate to the circuit.

Parameters:

index (int) –

Return type:

None

add_T_gate(index)#

Add a T gate to the circuit.

Parameters:

index (int) –

Return type:

None

add_Tdag_gate(index)#

Add a Tdag gate to the circuit.

Parameters:

index (int) –

Return type:

None

add_U1_gate(index, lmd)#

Add an U1 gate to the circuit.

Parameters:
  • index (int) –

  • lmd (float) –

Return type:

None

add_U2_gate(index, phi, lmd)#

Add an U2 gate to the circuit.

Parameters:
  • index (int) –

  • phi (float) –

  • lmd (float) –

Return type:

None

add_U3_gate(index, theta, phi, lmd)#

Add an U3 gate to the circuit.

Parameters:
  • index (int) –

  • theta (float) –

  • phi (float) –

  • lmd (float) –

Return type:

None

add_RX_gate(index, angle)#

Add a RX gate to the circuit.

Parameters:
  • index (int) –

  • angle (float) –

Return type:

None

add_RY_gate(index, angle)#

Add a RY gate to the circuit.

Parameters:
  • index (int) –

  • angle (float) –

Return type:

None

add_RZ_gate(index, angle)#

Add a RZ gate to the circuit.

Parameters:
  • index (int) –

  • angle (float) –

Return type:

None

add_CNOT_gate(control_index, target_index)#

Add a CNOT gate to the circuit.

Parameters:
  • control_index (int) –

  • target_index (int) –

Return type:

None

add_CZ_gate(control_qubit_index, target_qubit_index)#

Add a Control-Z gate to the circuit.

Parameters:
  • control_qubit_index (int) –

  • target_qubit_index (int) –

Return type:

None

add_SWAP_gate(target_index1, target_index2)#

Add a SWAP gate to the circuit.

Parameters:
  • target_index1 (int) –

  • target_index2 (int) –

Return type:

None

add_TOFFOLI_gate(control_index1, control_index2, target_index)#

Add a TOFFOLI gate to the circuit.

Parameters:
  • control_index1 (int) –

  • control_index2 (int) –

  • target_index (int) –

Return type:

None

add_UnitaryMatrix_gate(target_indices, unitary_matrix)#

Add a UnitaryMatrix gate to the circuit.

Parameters:
  • target_indices (Sequence[int]) –

  • unitary_matrix (Sequence[Sequence[complex]]) –

Return type:

None

add_SingleQubitUnitaryMatrix_gate(target_index, unitary_matrix)#

Add a single qubit UnitaryMatrix gate to the circuit.

Parameters:
  • target_index (int) –

  • unitary_matrix (Sequence[Sequence[complex]]) –

Return type:

None

add_TwoQubitUnitaryMatrix_gate(target_index1, target_index2, unitary_matrix)#

Add a two qubit UnitaryMatrix gate to the circuit.

Parameters:
  • target_index1 (int) –

  • target_index2 (int) –

  • unitary_matrix (Sequence[Sequence[complex]]) –

Return type:

None

add_Pauli_gate(target_indices, pauli_ids)#

Add a Pauli gate to the circuit.

Parameters:
  • target_indices (Sequence[int]) –

  • pauli_ids (Sequence[int]) –

Return type:

None

add_PauliRotation_gate(target_qubits, pauli_id_list, angle)#

Add a Pauli rotation gate to the circuit.

Parameters:
  • target_qubits (Sequence[int]) –

  • pauli_id_list (Sequence[int]) –

  • angle (float) –

Return type:

None

measure(qubit_indices, classical_indices)#

Adds measurement gate at selected qubits.

Parameters:
  • qubit_indices (int | Sequence[int]) –

  • classical_indices (int | Sequence[int]) –

Return type:

None

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

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

Parameters:

gates (circuit.circuit.GateSequence) –

Return type:

QuantumCircuit

abstract freeze()#

Returns a “freezed” version of itself.

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

Return type:

ImmutableQuantumCircuit

abstract get_mutable_copy()#

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.

Return type:

QuantumCircuit

class QuantumCircuit(qubit_count, cbit_count=0, gates=[])#

Bases: NonParametricQuantumCircuit, MutableQuantumCircuitProtocol

A mutable quantum circuit having only non-parametric gates.

Parameters:
  • qubit_count (int) –

  • cbit_count (int) –

  • gates (Sequence[QuantumGate]) –

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

Returns a “freezed” version of itself.

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

Return type:

ImmutableQuantumCircuit

get_mutable_copy()#

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.

Return type:

QuantumCircuit

add_gate(gate, gate_index=None)#

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

Parameters:
Return type:

None

extend(gates)#

Extend the circuit with given gate sequence.

Parameters:

gates (circuit.circuit.GateSequence) –

Return type:

None

class ImmutableQuantumCircuit(circuit)#

Bases: NonParametricQuantumCircuit

An immutable quantum circuit having only non-parametric gates.

Parameters:

circuit (NonParametricQuantumCircuit) –

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

Returns a “freezed” version of itself.

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

Return type:

ImmutableQuantumCircuit

get_mutable_copy()#

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.

Return type:

QuantumCircuit