Quantum Circuits

A quantum circuit is a sequence of quantum gates applied to qubits. It is the program of a quantum computer. Just as a classical program is a list of instructions executed in order, a quantum circuit is a sequence of operations that transform the qubit states from input to output.

Anatomy of a Quantum Circuit

Every quantum circuit has the same basic structure:

  • Qubit lines (wires): Horizontal lines, one per qubit. Time flows left to right.
  • Gate boxes: Symbols on the wires that represent operations applied to qubits.
  • Measurement symbols: A meter icon at the end of a wire, converting the qubit to a classical bit.
  • Classical wires: Double lines that carry the classical measurement results.
Example: Bell State Circuit (Creates Entanglement)
q_0: |0> ---[H]---@---[M]---c_0
q_1: |0> -------X---[M]---c_1

Step 1: Both qubits start at |0>

Step 2: H gate puts q_0 into superposition (|0>+|1>)/sqrt(2)

Step 3: CNOT entangles q_0 and q_1 in (|00>+|11>)/sqrt(2)

Step 4: Measure both - they always agree (both 0 or both 1)

Key Rules of Quantum Circuits

Time flows left to right

Unlike classical circuits (which are spatial), quantum circuits are temporal. Each column of gates represents a moment in time. Gates in the same column happen simultaneously; gates in different columns happen in sequence.

Qubits always start at |0>

Every qubit in a quantum circuit begins in the |0> state (unless otherwise initialized). This is the reset state after cooling the quantum processor.

Circuits are reversible (except measurement)

Because all quantum gates are reversible (unitary), you can run any quantum circuit backwards. The exception is measurement. Once you measure, you cannot unmeasure. Measurement is always at the end.

Circuit depth matters for hardware

On real quantum hardware, qubits decohere over time. Circuit depth - the number of gate layers - determines how long the computation runs. Deeper circuits have more errors. Optimizing circuits to be as shallow as possible is a major engineering challenge.

Your First Quantum Circuit in Qiskit

Here is the Bell state circuit written in Qiskit (IBM's quantum Python library):

Python - Qiskit
from qiskit import QuantumCircuit

# Create a circuit with 2 qubits and 2 classical bits
qc = QuantumCircuit(2, 2)

# Apply Hadamard to qubit 0
qc.h(0)

# Apply CNOT with qubit 0 as control, qubit 1 as target
qc.cx(0, 1)

# Measure both qubits
qc.measure([0, 1], [0, 1])

# Draw the circuit
print(qc.draw())

# Run on a simulator
from qiskit_aer import AerSimulator
sim = AerSimulator()
result = sim.run(qc, shots=1000).result()
counts = result.get_counts()
print(counts)
Try it free: You can run this code on IBM Quantum at quantum.ibm.com with no special hardware required.

Common Quantum Circuit Patterns

Superposition preparation

H gates on all qubits to create a uniform superposition of all 2n states.

Bell state creation

H gate plus CNOT creates entanglement between two qubits.

Phase kickback

A controlled-U gate where the phase of an eigenvalue kicks back to the control qubit.

Quantum teleportation

Transfer a qubit state to another using entanglement plus 2 classical bits.

Frequently Asked Questions

Are quantum circuits the same as classical logic circuits?

They share the concept of gates and wires, but differ fundamentally. Classical circuits are spatial while quantum circuits are temporal. Quantum circuits also use superposition and entanglement.

How do I run a quantum circuit on real hardware?

IBM Quantum offers free cloud access to real quantum hardware via Qiskit. You write your circuit in Python, submit it to the cloud, and the result comes back when the hardware runs it.

What is circuit transpilation?

Circuits must be transpiled before running on real hardware. This rewrites the circuit to use only the gates the hardware supports. Qiskit handles this automatically.

Frequently Asked Questions

What will I learn here?

This page covers the core concepts and techniques you need to understand the topic and progress confidently to the next lesson.

How should I use this page?

Start with the overview, then follow the section links to deepen your understanding. Use the table of contents on the right to jump to specific sections.

What should I read next?

Use the navigation below to continue to the next lesson or explore related topics.