quri_parts.circuit.circuit module

class ImmutableQuantumCircuit

Bases: object

cbit_count
combine()
depth
draw()
freeze()
gates
get_mutable_copy()
inverse()
qubit_count
sample(shot_count)
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

NonParametricQuantumCircuit

Deprecated: use quri_parts.circuit.ImmutableQuantumCircuit instead

class QuantumCircuit(qubit_count, cbit_count=None, gates=Ellipsis)

Bases: ImmutableQuantumCircuit

add_CNOT_gate(control_index, target_index)
add_CZ_gate(control_index, target_index)
add_H_gate(qubit_index)
add_Identity_gate(qubit_index)
add_PauliRotation_gate(target_qubits, pauli_id_list, angle)
add_Pauli_gate(target_indices, pauli_ids)
add_RX_gate(qubit_index, angle)
add_RY_gate(qubit_index, angle)
add_RZ_gate(qubit_index, angle)
add_SWAP_gate(target_index1, target_index2)
add_S_gate(qubit_index)
add_Sdag_gate(qubit_index)
add_SingleQubitUnitaryMatrix_gate(target_index, unitary_matrix)
add_SqrtX_gate(qubit_index)
add_SqrtXdag_gate(qubit_index)
add_SqrtY_gate(qubit_index)
add_SqrtYdag_gate(qubit_index)
add_TOFFOLI_gate(control_index1, control_index2, target_index)
add_T_gate(qubit_index)
add_Tdag_gate(qubit_index)
add_TwoQubitUnitaryMatrix_gate(target_index1, target_index2, unitary_matrix)
add_U1_gate(qubit_index, lmd)
add_U2_gate(qubit_index, phi, lmd)
add_U3_gate(qubit_index, theta, phi, lmd)
add_UnitaryMatrix_gate(target_indices, unitary_matrix)
add_X_gate(qubit_index)
add_Y_gate(qubit_index)
add_Z_gate(qubit_index)
add_gate()
extend()
measure(qubit_indices, classical_indices)
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.