Written and maintained by CASRAI Editorial Board
Last updated
A quantum circuit is an ordered list of operations on qubits, ending in measurements. This guide is for researchers and students who need to build one in code, draw it, and read the diagram correctly. It uses two documented frameworks, Qiskit and PennyLane, and covers a trap that catches many beginners: the two frameworks treat measurement differently.
What a quantum circuit is used for in research
Qiskit’s documentation defines it plainly: “A simple quantum circuit is a collection of qubits and a list of instructions that act on those qubits.” Researchers write circuits to state an algorithm, simulate it, and, where access exists, run it on hardware (see the IBM Quantum Platform access guide). In PennyLane, a circuit is a Python “quantum function” that applies gates to wires and returns a measurement; a QNode binds that function to a device, and the docs say “A quantum node is used to declare the quantum circuit.”
Not to be confused with: Quantum Circuits, Inc. (a company name), or classical electrical circuits. This page concerns the computational model.
Install or access (official sources only)
- Qiskit: the official install page gives
pip install qiskitand recommends a virtual environment (python3 -m venv .venv, thensource .venv/bin/activateon macOS/Linux; on Windowspython -m venv .venvand activate with.venvScriptsActivate.ps1in PowerShell). Supported Python versions are listed on the Qiskit PyPI page. The circuit-construction page lists its requirement asqiskit[all]~=2.6.1or newer. - PennyLane: follow the options on the official PennyLane install page.
Step-by-step: build and draw a circuit
In Qiskit
- Create a circuit with two qubits:
qc = QuantumCircuit(2). - Add an instruction, here an X gate on qubit 0:
qc.x(0). - Draw it:
qc.draw("mpl"). The docs say “The easiest way to view this information is through the draw method.” - Add measurements. Qiskit offers
measure,measure_allandmeasure_active; for exampleqc2 = QuantumCircuit(2),qc2.measure_all(),qc2.draw("mpl", cregbundle=False).
In PennyLane
- Import the library as the docs do:
import pennylane as qp. - Create a device:
dev = qp.device('default.qubit', wires=2). - Decorate a function with
@qp.qnode(dev)that applies gates and returns a measurement:@qp.qnode(dev) def circuit(x): qp.RZ(x, wires=0) qp.CNOT(wires=[0,1]) qp.RY(x, wires=1) return qp.expval(qp.PauliZ(1)) - Run it by calling
circuit(0.543), and draw it withimport numpy as np; print(qp.draw(circuit)(np.pi/4)).
Output and how to read a circuit diagram
For this circuit, called with np.pi/4, qp.draw prints a text diagram of the following form (wire labels 0 and 1, one row per wire; exact spacing can differ between PennyLane versions):
0: ──RZ(0.79)─╭●────────┤
1: ───────────╰X─RY(0.79)─┤ <Z>
- Each row is one wire (qubit).
- Gates read left to right in time order.
- A filled dot marks a control; an X joined to it by a vertical line is the target of a CNOT.
- Gate parameters appear in the label, for example RZ(0.79) for an angle of π/4.
- A symbol such as <Z> at the end of a wire is an expectation-value measurement.
Qiskit’s draw method renders the same idea (qubits as rows, instructions in sequence); the "mpl" option draws it as a figure.
Troubleshooting: the measurement difference
Qiskit states that “if you are submitting circuits to a Sampler primitive, measurements are required.” A Qiskit circuit therefore needs explicit measure instructions before sampling. In PennyLane the measurement is part of the function’s return statement, such as qp.expval(...), so a circuit function that returns nothing measurable is incomplete. If a result is missing or an error appears, check this first.
Also note that current PennyLane documentation uses the alias qp in its examples; code copied from older material may use a different alias, so match the alias to the version you installed.
Qiskit and PennyLane compared
| Question | Qiskit | PennyLane |
|---|---|---|
| What is the circuit object? | A QuantumCircuit: qubits plus a list of instructions |
A Python function applying gates to wires, wrapped as a QNode on a device |
| How do you draw it? | qc.draw("mpl") |
qp.draw(circuit)(args) |
| How is measurement specified? | Explicit instructions such as measure_all; required for the Sampler primitive |
The function’s return value, for example qp.expval |
| Where are the install instructions? | Qiskit install page (pip install qiskit) |
pennylane.ai/install |
Reproducibility for papers
Quantum circuit code changes between releases, so record the framework name and exact version with your results, and cite the software. See reproducible research practices, the CITATION.cff format and the FAIR4RS software citation principles.
FAQ
What is a quantum circuit?
A collection of qubits and a list of instructions acting on them, usually ending in measurements (Qiskit documentation).
How do I draw a quantum circuit in Python?
In Qiskit call draw on the circuit, for example qc.draw("mpl"); in PennyLane use qp.draw(circuit).
Do I need measurements?
For Qiskit’s Sampler primitive, yes. In PennyLane the returned measurement defines the circuit’s output.
Sources
- Qiskit documentation, Construct circuits: quantum.cloud.ibm.com/docs/en/guides/construct-circuits (read 2026-11-07)
- Qiskit documentation, Install Qiskit: quantum.cloud.ibm.com/docs/en/guides/install-qiskit (read 2026-11-07)
- PennyLane documentation, Quantum circuits: docs.pennylane.ai/en/stable/introduction/circuits.html (read 2026-11-07)







