Skip to main content
v2026.11,858 entries · CC-BY 4.0

Quantum Circuit: Build, Draw and Read One in Qiskit and PennyLane

How to build, draw and read a quantum circuit in Qiskit and PennyLane, including how each framework handles measurement.

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 qiskit and recommends a virtual environment (python3 -m venv .venv, then source .venv/bin/activate on macOS/Linux; on Windows python -m venv .venv and activate with .venvScriptsActivate.ps1 in PowerShell). Supported Python versions are listed on the Qiskit PyPI page. The circuit-construction page lists its requirement as qiskit[all]~=2.6.1 or newer.
  • PennyLane: follow the options on the official PennyLane install page.

Step-by-step: build and draw a circuit

In Qiskit

  1. Create a circuit with two qubits: qc = QuantumCircuit(2).
  2. Add an instruction, here an X gate on qubit 0: qc.x(0).
  3. Draw it: qc.draw("mpl"). The docs say “The easiest way to view this information is through the draw method.”
  4. Add measurements. Qiskit offers measure, measure_all and measure_active; for example qc2 = QuantumCircuit(2), qc2.measure_all(), qc2.draw("mpl", cregbundle=False).

In PennyLane

  1. Import the library as the docs do: import pennylane as qp.
  2. Create a device: dev = qp.device('default.qubit', wires=2).
  3. 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))
  4. Run it by calling circuit(0.543), and draw it with import 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

Follow CASRAI

Research-administration guidance, standards updates and independent tool reviews.

Ask CASRAI · free to try

Ask about Quantum Circuit: Build, Draw and Read One in Qiskit and PennyLane

Ask your first 2 questions free below. Subscribers get 150 a day for $29 a month.

An AI assistant specialized in research administration. It cites the sources behind every answer, labels web answers and says when it can't answer.

Answers draw on CASRAI's guides and dictionary plus the federal and funder documents we index: Federal Register, Grants.gov, Regulations.gov and UKRI.

Works on this site and inside Claude, Cursor and the AI tools you already use.

Everything CASRAI publishes — this page, the dictionary, the guides and the news — stays free to read, with no account and no card.

Referenced across the research world

University of Cambridge logoColumbia University logoCrossref logoUniversity of Edinburgh logoHarvard University logoUniversity of Oxford logoPrinceton University logoStanford School of Medicine logoUniversity College London logoORCID logoUniversity of Cambridge logoColumbia University logoCrossref logoUniversity of Edinburgh logoHarvard University logoUniversity of Oxford logoPrinceton University logoStanford School of Medicine logoUniversity College London logoORCID logo
  • University of Cambridge logo
  • Columbia University logo
  • Crossref logo
  • University of Edinburgh logo
  • Harvard University logo
  • University of Oxford logo
  • Princeton University logo
  • Stanford School of Medicine logo
  • University College London logo
  • ORCID logo

View CASRAI adoption →