class QuantumCircuit(num_qubits=0, num_clbits=0, name=None)[source]#

This class describes quantum circuits. Many of the attribute and method names are oriented at the Qiskit QuantumCircuit class in order to provide a high degree of compatibility.

QuantumCircuits can be visualized by calling print on them.

Qrisp QuantumCircuits can be quickly generated out of existing Qiskit QuantumCircuits with the from_qiskit method.

num_qubitsinteger, optional

The amount of qubits, this QuantumCircuit is initialized with. The default is 0.

num_clbitsinteger, optional

The amount of classical bits. The default is 0.

namestring, optional

A name for the QuantumCircuit. The default will generated a generic name.


We create a QuantumCircuit containing a so-called fan-out gate:

>>> from qrisp import QuantumCircuit
>>> qc_0 = QuantumCircuit(4, name = "fan out")
>>> qc_0.cx(0, range(1,4))
>>> print(qc_0)
qb_0: ──■────■────■──
      ┌─┴─┐  │    │
qb_1: ┤ X ├──┼────┼──
      └───┘┌─┴─┐  │
qb_2: ─────┤ X ├──┼──
qb_3: ──────────┤ X ├

Note that the cx gate appending method (like all other gate appending methods) can be called with integers, Qubit objects, lists of integers or lists of Qubit objects.

We now turn this QuantumCircuit into a gate and append to another QuantumCircuit to generate a GHZ state:

>>> qc_1 = QuantumCircuit(4)
>>> qc_1.h(0)
>>> qc_1.append(qc_0.to_gate(), qc_1.qubits)
>>> print(qc_1)
qb_4: ┤ H ├┤0         ├
      └───┘│          │
qb_5: ─────┤1         ├
           │  fan out │
qb_6: ─────┤2         ├
           │          │
qb_7: ─────┤3         ├

Finally, we add a measurement and evaluate the circuit:

>>> qc_1.measure(qc_1.qubits)
>>> print(qc_1)
qb_4: ┤ H ├┤0         ├┤M├─────────
      └───┘│          │└╥┘┌─┐
qb_5: ─────┤1         ├─╫─┤M├──────
           │  fan out │ ║ └╥┘┌─┐
qb_6: ─────┤2         ├─╫──╫─┤M├───
           │          │ ║  ║ └╥┘┌─┐
qb_7: ─────┤3         ├─╫──╫──╫─┤M├
           └──────────┘ ║  ║  ║ └╥┘
cb_0: ══════════════════╩══╬══╬══╬═
                           ║  ║  ║
cb_1: ═════════════════════╩══╬══╬═
                              ║  ║
cb_2: ════════════════════════╩══╬═
cb_3: ═══════════════════════════╩═
>>> qc_1.run(shots = 1000)
{'0000': 500, '1111': 500}

Converting from Qiskit

We construct the very same fan out QuantumCircuit in Qiskit:

>>> from qiskit import QuantumCircuit as QiskitQuantumCircuit
>>> qc_2 = QiskitQuantumCircuit(4)
>>> qc_2.cx(0, range(1,4))
>>> print(qc_2)
q_0: ──■────■────■──
     ┌─┴─┐  │    │
q_1: ┤ X ├──┼────┼──
     └───┘┌─┴─┐  │
q_2: ─────┤ X ├──┼──
q_3: ──────────┤ X ├

To acquire the Qrisp QuantumCircuit we call the from_qiskit method. Note that we don’t need to create a QuantumCircuit object first as this is a class method.

>>> qrisp_qc_2 = QuantumCircuit.from_qiskit(qc_2)
>>> print(qrisp_qc_2)
 qb_8: ──■────■────■──
       ┌─┴─┐  │    │
 qb_9: ┤ X ├──┼────┼──
       └───┘┌─┴─┐  │
qb_10: ─────┤ X ├──┼──
qb_11: ──────────┤ X ├

Abstract Parameters

Abstract parameters are represented by Sympy symbols in Qrisp.

We create a QuantumCircuit with some abstract parameters and bind them subsequently.

>>> from qrisp import QuantumCircuit
>>> from sympy import symbols
>>> qc = QuantumCircuit(3)

Create some Sympy symbols and use them as abstract parameters for phase gates:

>>> abstract_parameters = symbols("a b c")
>>> for i in range(3): qc.p(abstract_parameters[i], i)

Create the substitution dictionary and bind the parameters:

>>> subs_dic = {abstract_parameters[i] : i for i in range(3)}
>>> bound_qc = qc.bind_parameters(subs_dic)
>>> print(bound_qc)
qb_0: ┤ P(0) ├
qb_1: ┤ P(1) ├
qb_2: ┤ P(2) ├


Constructing QuantumCircuits#


Method for appending Operation or Instruction objects to the QuantumCircuit.


Method to return an Operation object generated out of this QuantumCircuit.


Similar to to_op but raises an exception if self contains classical bits (like the Qiskit equivalent).


Adds a Qubit to the QuantumCircuit.


Adds a classical bit to the QuantumCircuit.


Returns a copy of the given QuantumCircuit.


Returns a copy of the given QuantumCircuit but without any data (i.e.


Returns the inverse/daggered QuantumCircuit.

QuantumCircuit.extend(other[, translation_dic])

Extends self in-place by another QuantumCircuit.


Returns a QuantumCircuit where the abstract parameters in subs_dic are bound to their specified values.


Transpiles the QuantumCircuit in the sense that there are no longer any synthesized gate objects.

Evaluating QuantumCircuits#

QuantumCircuit.run([shots, backend])

Runs a QuantumCircuit on a given backend.


Performs a simulation of the statevector of self and returns a numpy array of complex numbers.

QuantumCircuit.depth([depth_indicator, ...])

Returns the depth of the QuantumCircuit.


Estimates the T-depth of self.


This function returns the CNOT-depth of an self.


Returns the amount of qubits.


Counts the amount of operations of each kind.


Acquires the unitary matrix of the given QuantumCircuit as a Numpy array.

QuantumCircuit.compare_unitary(other[, ...])

Compares the unitaries of two QuantumCircuits.


Deploys the Qiskit circuit drawer to generate LaTeX output.

QuantumCircuit.qasm([formatted, filename, ...])

Returns the OpenQASM string of self.



Class method to create QuantumCircuits from Qiskit QuantumCircuits.


Method to convert the given QuantumCircuit to a Qiskit QuantumCircuit.


Method to convert the given QuantumCircuit to a Pennylane Circuit.


Method to convert the given QuantumCircuit to a PyTket Circuit.


Loads a QuantumCircuit from a QASM String.


Loads a QuantumCircuit from a QASM file.

Operation application methods#


Each Qubit and Clbit parameter in these methods can be replaced by an integer, a list of integers or a list of Qubit/Clbit objects.

>>> from qrisp import QuantumCircuit
>>> qc = QuantumCircuit(5)
>>> qc.cx(qc.qubits[1:], qc.qubits[0])
>>> qc.x([0,1,2,3])
>>> print(qc)
      ┌───┐┌───┐     ┌───┐┌───┐┌───┐
qb_0: ┤ X ├┤ X ├─────┤ X ├┤ X ├┤ X ├
qb_1: ──■────┼──┤ X ├──┼────┼───────
             │  ├───┤  │    │
qb_2: ───────■──┤ X ├──┼────┼───────
                └───┘  │    │  ┌───┐
qb_3: ─────────────────■────┼──┤ X ├
                            │  └───┘
qb_4: ──────────────────────■───────

QuantumCircuit.measure(qubits[, clbits])

Instructs a measurement.

QuantumCircuit.cx(qubits_0, qubits_1)

Instruct a CX-gate.

QuantumCircuit.cy(qubits_0, qubits_1)

Instruct a CY-gate.

QuantumCircuit.cz(qubits_0, qubits_1)

Instruct a CZ-gate.


Instruct a Hadamard-gate.


Instruct a Pauli-X-gate.


Instruct a Pauli-Y-gate.


Instruct a Pauli-Z-gate.

QuantumCircuit.mcx(control_qubits, target_qubits)

Instruct a multi-controlled X-gate.

QuantumCircuit.ccx(ctrl_qubit_0, ...[, method])

Instruct a Toffoli-gate.

QuantumCircuit.rx(phi, qubits)

Instruct a parametrized RX-gate.

QuantumCircuit.ry(phi, qubits)

Instruct a parametrized RY-gate.

QuantumCircuit.rz(phi, qubits)

Instruct a parametrized RZ-gate.

QuantumCircuit.p(phi, qubits)

Instruct a phase-gate.

QuantumCircuit.cp(phi, qubits_0, qubits_1)

Instruct a controlled phase-gate.

QuantumCircuit.u3(theta, phi, lam, qubits)

Instruct a U3-gate from given Euler angles.

QuantumCircuit.swap(qubits_0, qubits_1)

Instruct a SWAP-gate.


Instruct a T-gate.


Instruct a dagger T-gate.


Instruct an S-gate.


Instruct a daggered S-gate.


Instruct a SX-gate.


Instruct a daggered SX-gate.

QuantumCircuit.rxx(phi, qubits_0, qubits_1)

Instruct an RXX-gate.

QuantumCircuit.rzz(phi, qubits_0, qubits_1)

Instruct an RZZ-gate.

QuantumCircuit.xxyy(phi, beta, qubits_0, ...)

Instruct an XXYY-gate.


Instruct a reset.

QuantumCircuit.unitary(unitary_array, qubits)

Instruct a U3-gate from a given U3 matrix.

QuantumCircuit.gphase(phi, qubits)

Instruct a global phase.


Instruct an identity gate.