Level 6 · Practitioner’s Corner

Reading a Quantum Circuit Diagram

About 5,237 words · roughly 24 minute read · sources checked December 2, 2026

Quantum circuit diagrams are the main way algorithms are written down in papers, textbooks and documentation. They look simple, but small conventions trip up beginners: which way time runs, which qubit is on top, what a vertical line means, and why two diagrams that look different can describe the same computation. Once you can read them fluently, most algorithm descriptions become easy to follow.

This lesson teaches reading as a skill. We go through the parts of a diagram, read four small circuits step by step, compare conventions between Qiskit and textbooks, and learn to count gates and depth, which later decide whether a circuit can run on real hardware. Each circuit is verified numerically, by building its matrix and checking what it does to the basis states.

You need the gates lesson and a first look at entanglement. If you have done the first Qiskit lesson, the Bell circuit will already be familiar.

What you will learn

  • What the horizontal wires, boxes, dots, crosses and meters mean.
  • That time runs left to right, and what that implies about operation order.
  • How to read controls, targets, swaps and multi-control gates.
  • How measurement and classical wires appear, and what barriers do.
  • How Qiskit’s qubit order compares with the convention in many textbooks.
  • How to count gates and circuit depth, and why two-qubit gates matter most.
  • How to turn a diagram into a matrix or a truth table to check your reading.

Helpful first: Quantum Gates, Entanglement, Your First Qiskit Circuit.

The parts of a diagram

A circuit diagram is a picture of a program. Four ingredients appear in almost every diagram.

  • Wires. Each horizontal line is one qubit. The label at the left, such as q0, names the qubit, and sometimes the starting state is written there too, usually |0⟩.
  • Gates. A box with a letter, such as H, X or Rz, is an operation on the wire it sits on. Gates that act on two or more qubits join several wires with a vertical line.
  • Measurements. A box with a small meter symbol turns a qubit into a classical bit. The result goes to a classical wire, usually drawn as a double line.
  • Time. Time runs from left to right. The first operation is the leftmost one on a wire. The wires themselves do not move or carry anything; they are a time axis.
q0q1cHgatecontrol • targetmeasuretime runs left to right
A labelled circuit: a Hadamard, a CNOT, then two measurements into a classical register at the bottom.

It is worth stressing the last point. A wire does not represent a physical wire carrying the qubit. The picture says, for this qubit, apply these operations in this order. The horizontal position of a gate shows when it happens relative to other gates on the same wire, and gates in different wires at the same horizontal position can happen at the same time.

The symbols you will meet

HXCNOTCZSWAPToffoliHXDots are controls. A circled plus is the NOT target. CZ and SWAP are symmetric.
Six common symbols. A dot marks a control, and a circled plus marks the target of a NOT.
SymbolNameWhat it doesWhich wire is special
Box HHadamardMaps |0⟩ to |+⟩ and |1⟩ to |−⟩Single wire
Box XPauli X, the quantum NOTSwaps |0⟩ and |1⟩Single wire
Dot and circled plusCNOT, also CXFlips the target if the control is |1⟩Dot is the control, plus is the target
Two dots joinedCZAdds a minus sign when both qubits are |1⟩Neither: it is symmetric
Two crosses joinedSWAPExchanges the states of two qubitsNeither
Two dots and a circled plusToffoli, also CCXFlips the target if both controls are |1⟩Plus is the target

Common gate symbols. Names and effects are standard.

Symmetry is not obvious

CZ looks as if it has a control and a target, but it does not: the gate is the same if you swap the two qubits. I checked that its matrix is symmetric. CNOT is the opposite: swapping control and target gives a different gate. Always check which end carries the plus.

Measurement and classical wires

A measurement turns a qubit into a classical bit. After the meter, the wire for that qubit either ends or continues carrying a classical value, and a dashed or double line connects the meter to a classical register. In Qiskit, the method measure_all adds a measurement to every qubit and a classical register to store the results, as the first lesson in this level showed.

Barriers

A barrier, drawn as a vertical dashed line across wires, is not an operation. It separates parts of the circuit so that tools do not rearrange gates across the line, which helps with readability and with some optimisation settings. Qiskit’s measure_all places one before the measurements. Reading a circuit, you can ignore barriers.

Classical control

Some circuits use a measurement result to decide whether to apply a later gate. In a diagram, a classical wire runs to the gate, which is drawn with a condition. Quantum teleportation is the classic example: two measured bits decide which Pauli corrections are applied to the third qubit. Qiskit’s older c_if method for this was removed in version 2.0 and replaced by if_test blocks, as the IBM release notes say.

Reading four circuits step by step

The best way to learn is to read circuits and then verify the readings. For each circuit below, the method is the same: go left to right, track what each gate does to the state, and check the final state by building the matrix.

Circuit 1: the Bell circuit

     ┌───┐     
q_0: ┤ H ├──■──
     └───┘┌─┴─┐
q_1: ─────┤ X ├
          └───┘
The Bell circuit as Qiskit’s text drawer prints it. The characters may differ slightly in your version.

Worked example

Reading it

  1. Time runs left to right. Step 1 is an H on q_0. Step 2 is a CNOT: the dot is on q_0 and the circled plus (drawn here as an X in a box) is on q_1, so q_0 is the control.
  2. Start |00⟩. After H: qubit 0 is in |+⟩. After CNOT: (|00⟩ + |11⟩)/√2.
  3. Gate count: 2 (one single-qubit, one two-qubit). Depth: 2, since the second gate must wait for the first on qubit 0.
  4. Verified numerically: the measurement probabilities are 0.5 for 00 and 0.5 for 11.

Circuit 2: GHZ in two shapes

Two diagrams can look different and give the same state. A GHZ state on four qubits can be built by a chain of CNOTs or by a branching pattern.

Worked example

Chain versus branch

  1. Chain: H on q0, then CNOT(0,1), CNOT(1,2), CNOT(2,3), one after the other. Each CNOT needs the qubit that the previous one just changed. Depth 4.
  2. Branch: H on q0, then CNOT(0,1), then CNOT(0,2) and CNOT(1,3) at the same time, since they act on different pairs of qubits. Depth 3.
  3. Both give (|0000⟩ + |1111⟩)/√2. I built both state vectors and checked that they agree exactly, with only the keys 0000 and 1111 present.
  4. Both use three CNOTs, so the gate count is the same, but the second finishes in fewer steps. On a real device with a limited coherence time, fewer layers is better, and in a larger circuit the difference grows: a chain needs n steps for n qubits, while a branching pattern needs about log₂ n steps.

Circuit 3: three CNOTs make a SWAP

q0: ──●────⊕────●──
      │    │    │
q1: ──⊕────●────⊕──
Three CNOTs in a row, in a simplified text drawing: ● is a control and ⊕ is a target. Read left to right.

Worked example

Reading it

  1. Gate 1: control q0, target q1. Gate 2: control q1, target q0 (the dot and the plus swapped sides). Gate 3: control q0, target q1 again.
  2. Test with the input |01⟩, meaning q0 = 1 and q1 = 0. Gate 1 flips q1 since q0 = 1, giving q0 = 1, q1 = 1. Gate 2 flips q0 since q1 = 1, giving q0 = 0, q1 = 1. Gate 3 does nothing since q0 = 0. Final: q0 = 0, q1 = 1, which is the string '10'.
  3. The input had its 1 on qubit 0, and the output has its 1 on qubit 1. The qubits were exchanged. I verified that the product of the three CNOT matrices equals the SWAP matrix.
  4. This is why SWAP costs three two-qubit gates on hardware that has no direct SWAP, and why routing on real devices is expensive: the transpiler lesson in this level uses this fact.

Circuit 4: a Toffoli gate

Worked example

Reading it

  1. A Toffoli has two dots on the control wires and a circled plus on the target. It flips the target only if both controls are 1.
  2. On three qubits with controls q0 and q1 and target q2, the gate changes only two of the eight basis states: '011' (q0 = 1, q1 = 1, q2 = 0) becomes '111', and '111' becomes '011'. I computed all eight and found no other change.
  3. So the Toffoli is a reversible AND: with the target starting at 0, it writes (q0 AND q1) into the target.
  4. Gate count: one three-qubit gate. Real devices usually have only one- and two-qubit gates, so it must be rewritten, and a standard textbook decomposition uses six CNOTs together with single-qubit gates. I give that figure from general knowledge, not a source opened in this session.

A longer circuit: two-qubit Grover search

Diagrams of real algorithms are longer but built of the same parts. Here is the smallest Grover search, on two qubits, looking for the item 11. Read it in three blocks, as papers usually draw it: a Hadamard layer, an oracle, and a diffusion step.

q0: ─ H ─────●───── H ─ Z ───────●───── H ─ M
             │                   │
q1: ─ H ─────●───── H ─ Z ───────●───── H ─ M
     └ start ┘└ oracle (CZ) ┘└──── diffusion ────┘
The two-qubit Grover circuit in simplified text. The oracle is a CZ, which marks |11⟩. The diffusion step is H, Z, CZ, H on both wires. This is a schematic, not the exact output of a drawing tool.

Worked example

Reading it block by block

  1. Block 1: H on both wires. Start |00⟩ and get the uniform state, amplitudes (0.5, 0.5, 0.5, 0.5) on 00, 01, 10, 11.
  2. Block 2: the CZ flips the sign of |11⟩ only, so the amplitudes become (0.5, 0.5, 0.5, −0.5). Nothing about the probabilities has changed yet, which is the point of an oracle: it marks the answer by a sign.
  3. Block 3, the diffusion step: H on both wires, then a Z on each, then a CZ, then H on both wires again. I computed each stage. After the middle Z and CZ the amplitudes are (0.5, −0.5, −0.5, 0.5), and the final Hadamards give (0, 0, 0, 1).
  4. Measured, the output is 11 with probability 1. For four items, one round of Grover is exact, a special property of N = 4 that was discussed in the Grover lesson.
  5. I also checked that the diffusion block equals, up to a global sign, the operator 2|s⟩⟨s| − I, where |s⟩ is the uniform state. That is the ‘reflection about the mean’ that papers describe in words.

The lesson from reading it in blocks is that long diagrams are repeated patterns. Once you recognise ‘uniform superposition, mark, reflect’, a larger Grover circuit is the same picture with more wires and a repeated middle part.

A circuit with classical control: teleportation

Teleportation is the standard example of a circuit that uses measurement results to steer later gates. It uses three qubits. Qubit 0 holds the state to send, and qubits 1 and 2 will share an entangled pair. Read it in four stages.

  1. Make a Bell pair on qubits 1 and 2: H on qubit 1, then CNOT from qubit 1 to qubit 2.
  2. Entangle the state with its half: CNOT from qubit 0 to qubit 1, then H on qubit 0.
  3. Measure qubits 0 and 1. These two results are classical bits.
  4. Apply corrections to qubit 2, controlled by the classical bits: an X if the result from qubit 1 is 1, and a Z if the result from qubit 0 is 1.

Worked example

Checking the reading with numbers

  1. Send the state 0.6|0⟩ + 0.8i|1⟩, which is normalised since 0.36 + 0.64 = 1.
  2. I simulated all four possible measurement outcomes. Each occurs with probability 0.25. After applying the matching corrections, qubit 2 is in the state (0.6, 0.8i) in all four cases, identical to the original.
  3. Before the corrections, qubit 2’s state differed between outcomes by an X, a Z, or both, which is exactly what the two classical bits tell you.
  4. In the diagram, the classical bits travel along the double lines to the correction gates. Without them, qubit 2 would be a random-looking mixture, and the transfer would not work.

What to notice in the diagram

The double lines carry only classical information. The circuit sends no quantum state along them. This is how the picture makes it visible that teleportation needs a classical channel.

In a modern Qiskit program, this classical control is written with if_test blocks, which replaced the old c_if method that was removed in version 2.0 according to the release notes I opened. Level 7 builds and runs this circuit in full.

Boxes with angles: rotation gates

Many diagrams contain boxes such as Rz(π/2) or Ry(θ). These are rotations of the qubit’s Bloch vector about an axis by the stated angle. Their matrices are cos(θ/2) I − i sin(θ/2) P, where P is X, Y or Z for the axis. Angles are in radians. A rotation by 2π brings the Bloch vector back, but multiplies the state by −1, a global phase that cannot be measured.

BoxEffect on |0⟩Relation to a named gate (up to a global phase)
Rx(π)−i|1⟩The X gate
Rx(π/2)(|0⟩ − i|1⟩)/√2, equal probabilitiesThe square-root-of-X gate, usually called SX; SX applied twice gives X
Ry(π/2)(|0⟩ + |1⟩)/√2, which is |+⟩Half of a Hadamard: H equals Ry(π/2) applied after Z
Rz(π)|0⟩ with a phase on |1⟩ relative to |0⟩The Z gate
Rz(π/2)A relative phase of i between |1⟩ and |0⟩The S gate
Rz(π/4)A relative phase of e^{iπ/4}The T gate

Rotation gates and their named equivalents. Each relationship was checked with matrices.

Worked example

Why diagrams from hardware look different

  1. A device’s native gate set is small. Circuits you draw with H and CNOT are rewritten before they run, which is what the transpiler does. The IBM optimization page, for example, shows circuits made of ECR two-qubit gates.
  2. A Hadamard itself can be built from the native single-qubit gates. I checked that H equals Rz(π/2) followed by SX followed by Rz(π/2), up to a global phase of 0.707 + 0.707i, which is e^{iπ/4}. Many hardware-ready circuits therefore show triplets of rotations where you drew a single H.
  3. Because rotations about the same axis add their angles (Rz(0.7) followed by Rz(0.5) equals Rz(1.2), which I confirmed), neighbouring Rz gates are merged by the optimiser.
  4. If you print a transpiled circuit and cannot recognise it, this is the reason. The logic is the same, and the gates are expressed in the device’s own vocabulary.

Reading a rotation: look at the axis (the letter), then the angle. An angle of π is a flip, π/2 is a quarter turn that turns a basis state into an equal superposition, and small angles are small tilts that algorithms use for tuning.

Unusual boxes

  • A box labelled U, or a labelled block such as ‘oracle’, hides a more complex operation. Look for a caption, a legend, or a definition in the text.
  • A box with several wires, such as a QFT block, stands for a whole sub-circuit. Papers often draw it that way to keep a diagram short.
  • Open circles instead of filled dots on a control, in some drawings, mean the gate acts when that qubit is 0, not 1. I did not open a source for how Qiskit draws this, so check the legend when you see it.
  • Gates drawn with a dashed outline or a parameter name such as θ are placeholders to be filled in, as in the parameter sweep of the first lesson.

Reading practice: four circuits to decode

Try each of these before reading the answer. For each one, name what the circuit does in one sentence. All answers were checked with matrices.

Worked example

Circuit A: H, X, H on one qubit

  1. Read it left to right. Hadamard, then X, then Hadamard.
  2. Answer: the whole circuit equals the Z gate. A Hadamard on each side of an X turns it into a Z. I checked that H·X·H = Z exactly.
  3. Consequence: a Z gate is the same as ‘change to the X basis, flip, change back’. This is the basis-change idea again.

Worked example

Circuit B: an X on the control before and after a CNOT

  1. Put an X gate on qubit 0, then CNOT(0 → 1), then an X on qubit 0 again.
  2. Answer: this is a CNOT that fires when qubit 0 is 0, a ‘control on zero’. The first X turns a 0 into a 1 so the CNOT fires, and the second X puts it back. I computed the truth table: ‘00’ becomes ‘10’ (qubit 1 flipped), ‘10’ becomes ‘00’, while ‘01’ and ‘11’ are unchanged.
  3. Some drawings show this as an open circle on the control instead of the three separate gates. If you meet an open circle, read it as control on zero.

Worked example

Circuit C: a Toffoli with X gates on both controls

  1. Put X on qubits 0 and 1, then a Toffoli with controls 0 and 1 and target 2, then X on qubits 0 and 1 again.
  2. Answer: a gate that flips the target when both controls are 0. I computed all eight inputs and only two change: '000' becomes '100' and '100' becomes '000'.
  3. In classical logic terms the target gets NOR of the two controls when it starts at 0. This pattern of X, gate, X is a standard way to change what a control means.

Worked example

Circuit D: phase kickback

  1. Qubit 1 gets X then H, which makes it |−⟩. Qubit 0 gets H. Then CNOT(0 → 1). Then H on qubit 0. Measure both.
  2. Answer: qubit 0 is measured as 1 with certainty, and qubit 1 is a fair coin. I computed the keys: '01' and '11', each with probability 0.5. Qubit 1 (the left character) is random, and qubit 0 (the right character) is always 1.
  3. The reason: when the target is in |−⟩, a CNOT does not change the target. It gives the control a minus sign when the control is 1, so the control’s |+⟩ becomes |−⟩ and the final Hadamard turns that into |1⟩. The phase has ‘kicked back’ onto the control.
  4. This effect is the heart of several algorithms, including phase estimation and Deutsch–Jozsa. Recognising it in a diagram, a target prepared in |−⟩ and a control that changes, is a valuable reading skill.

Pattern spotting

Experienced readers do not trace every gate. They notice patterns: gate–X–gate sandwiches, control-flip pairs, a target in |−⟩, Hadamards on both sides of something. Each of the four circuits above is such a pattern.

Which qubit is on top?

There are two common conventions, and mixing them up is the most frequent source of wrong results when moving between a textbook and Qiskit.

  • Qiskit draws qubit 0 at the top. Its bitstrings are written with qubit 0 at the right, so the printed key lists the highest-numbered qubit first. IBM calls this little-endian ordering and says it can cause confusion when interpreting a string of bits.
  • Many textbooks draw the first qubit at the top and also write it first, leftmost, in a ket such as |q₁q₂⟩. The first qubit in the picture is then the first (leftmost) label in the state.

So the same picture, read in the two conventions, can describe the same circuit with a differently labelled state. The physics is unchanged. What changes is how you write down the basis states and which matrix you build.

Worked example

The same circuit in two conventions

  1. Take the circuit with an X on the top wire only.
  2. Textbook convention: the top wire is the leftmost label. The result is |10⟩.
  3. Qiskit: the top wire is qubit 0, which is the rightmost character. The result is the key '01'.
  4. Both describe a circuit where only the top wire was flipped. They differ only in how the state is written, which is why you should always check which character of an output belongs to which wire.
  5. For gates, the same applies to matrices: Qiskit’s matrix for an operation on qubit 0 of two qubits is I ⊗ G, with the identity on the left, and the textbook matrix is G ⊗ I.

What to do about it

When comparing a Qiskit result with a paper, convert one into the other’s convention before comparing. The simplest test is the one from the first lesson: apply a single X to one named qubit and see which character of the result changes. IBM’s page also notes that draw(reverse_bits=True) flips the drawing only, without changing the circuit, so it is a way to get a textbook-style picture.

Counting: gates, depth and what matters

Two numbers summarise the cost of a circuit, and they are easy to read from a diagram.

  • Gate count: how many operations there are, usually split into single-qubit and two-qubit gates.
  • Depth: the number of layers when you pack gates that can run at the same time into the same layer. Equivalently, the length of the longest chain of gates that each depend on the previous one.

On real hardware, two-qubit gates are usually the slowest and least accurate operations, so the number of two-qubit gates is often the most important figure. IBM’s page on the optimization levels says that the higher levels of transpilation aim to reduce depth and gate count, and gives an example where a circuit went from six two-qubit ECR gates to three. Reading a diagram, count the vertical lines first.

CircuitSingle-qubit gatesTwo-qubit gatesDepth
Bell pair112
4-qubit GHZ, chain134
4-qubit GHZ, branch133
SWAP from CNOTs033
Toffoli (one gate)00 (it has three qubits)1

Counts read from the diagrams in this lesson, excluding measurements. Depth is counted in layers of gates that can run together.

Worked example

The depth of a GHZ state as the system grows

  1. A chain builds an n-qubit GHZ state in depth n: one Hadamard layer and n − 1 CNOTs one after another.
  2. A branching pattern doubles the number of qubits that carry the choice at every layer, so after the Hadamard it needs ⌈log₂ n⌉ layers. Total depth is 1 + ⌈log₂ n⌉.
  3. For n = 4: 3 against 4. For n = 8: 4 against 8. For n = 64: 7 against 64. For n = 100: 8 against 100.
  4. The branch needs qubits 0 and 2 to be allowed to interact, then qubits 1 and 3, which is not always possible. On a device where qubits are only connected to neighbours on a line, the branch requires SWAPs, and its advantage shrinks or vanishes. Reading depth from a diagram without the device’s connectivity gives only an idealised number.

Different pictures, same circuit

You will often see circuits redrawn using equivalent gate identities. Recognising them lets you simplify a diagram or check that two papers describe the same thing. All of the identities below were verified with matrices.

IdentityIn wordsWhy it is useful
H · CZ · H on the target = CNOTA CNOT is a CZ with Hadamards on the target wire before and afterSome devices have CZ as the native gate, so CNOTs are built this way
(H⊗H) · CNOT(0→1) · (H⊗H) = CNOT(1→0)Surrounding a CNOT by Hadamards on both wires reverses control and targetLets a device with one preferred direction run both directions
H · Z · H = XConjugating Z by a Hadamard gives XExplains why measuring in the X basis means adding a Hadamard before a Z measurement
CNOT · CNOT = identityDoing the same CNOT twice does nothingThe basis of cancellations in optimisers
CZ is symmetricSwapping the two wires changes nothingOrientation does not matter for CZ

Gate identities. I checked each numerically using Qiskit’s ordering.

Worked example

A mystery circuit

  1. Circuit: H on q0, H on q1, then CZ between them, then H on q1. What does it do?
  2. The last three gates, CZ followed by H on q1 with an H on q1 before it, are the identity H · CZ · H, which equals a CNOT with control q0 and target q1.
  3. So the circuit is H on q0 followed by a CNOT, which is the Bell circuit. I computed the state of the original four-gate version and got (|00⟩ + |11⟩)/√2, with amplitudes 0.707 on 00 and 11 and zero elsewhere.
  4. This is a typical use of identities: a longer circuit turns out to be a familiar one.

A method for checking your reading

When a diagram is not obvious, follow these steps.

  1. Write down the starting state, normally all zeros, and which wire is which qubit.
  2. Go left to right. For each gate, identify the wires involved and which is control and which is target.
  3. Track a single basis state through the circuit, as we did with the SWAP, to understand what each gate does.
  4. If superposition is involved, track the amplitudes of each basis state or use a table of the four (or eight) basis states.
  5. Check the answer in a limiting case, such as all-zero input.
  6. Only then read off the output, taking care with the bit order.

For circuits on up to three or four qubits, a truth table for the computational-basis inputs often settles the question, as with the Toffoli. For circuits with Hadamards, tracking amplitudes is needed. For anything bigger, use a simulator to confirm.

Do not trust a vertical line to touch only its endpoints

A vertical line between two qubits that crosses another wire does not act on the wire in between. In the diagram of a CNOT between q0 and q2, the line passes over q1 without touching it. A filled dot or a gate symbol is where the action happens.

Read it first, then run it

The skill this lesson teaches is predicting what a circuit does by reading it. The best practice is to read first, write your prediction down, and only then run. Below are five circuits from this site's collection. For each, read the diagram from left to right, track the state in your head or on paper, and then compare with the widget. The strings use Qiskit's convention, with qubit 0 as the rightmost bit.

Circuit 1: two gates, one correlated pair

Run this circuit

Bell pair: H then CNOT

q0q1H

Bit order: q0 is the rightmost digit of each result, as in Qiskit. All qubits start in |0⟩ unless marked. This is an ideal simulator with no hardware noise.

Predict first: H puts qubit 0 in superposition; CNOT copies its value onto qubit 1 as an XOR. Which of 00, 01, 10, 11 can appear?

Press Run to simulate. Results appear here with a short explanation.

Circuit 2: a chain of CNOT gates

Run this circuit

GHZ state across three qubits

q0q1q2H

Bit order: q0 is the rightmost digit of each result, as in Qiskit. All qubits start in |0⟩ unless marked. This is an ideal simulator with no hardware noise.

Predict first: Extend the Bell circuit with one more CNOT. Which strings appear now?

Press Run to simulate. Results appear here with a short explanation.

Circuit 3: a controlled-Z between two Hadamards

Run this circuit

CZ sandwiched by H equals CNOT

q0q1XHH

Bit order: q0 is the rightmost digit of each result, as in Qiskit. All qubits start in |0⟩ unless marked. This is an ideal simulator with no hardware noise.

Predict first: Qubit 0 is set to 1. Wrapping CZ in Hadamards on the target should behave like a CNOT. What is the final string?

Press Run to simulate. Results appear here with a short explanation.

Circuit 4: a Toffoli with both controls set

Run this circuit

Toffoli (CCX) with both controls set

q0q1q2XX

Bit order: q0 is the rightmost digit of each result, as in Qiskit. All qubits start in |0⟩ unless marked. This is an ideal simulator with no hardware noise.

Predict first: X on qubits 0 and 1 sets both controls to 1. What does the Toffoli do to qubit 2?

Press Run to simulate. Results appear here with a short explanation.

Circuit 5: the kickback circuit

Run this circuit

Phase kickback

q0q1XHHHH

Bit order: q0 is the rightmost digit of each result, as in Qiskit. All qubits start in |0⟩ unless marked. This is an ideal simulator with no hardware noise.

Predict first: Qubit 1 is prepared in |−⟩ and used as the target of a CNOT. The target is untouched by a CNOT on |−⟩ (it only gets a sign). Which qubit changes?

Press Run to simulate. Results appear here with a short explanation.

If you got all five right, you can read circuits. If you missed one, work out why: usually the culprit is the order of gates, the role of a control, or the bit order of the answer. Then change one gate in your head, predict the new answer, and check it by editing the circuit on this site's circuit builder.

A reading routine you can reuse

  1. Write the starting state of every qubit, usually all zeros.
  2. Go column by column. For each column, note which qubits are touched and what each gate does to a basis state.
  3. For superposition gates, keep a list of the basis states with non-zero amplitude, and apply controlled gates to each term separately.
  4. At the end, square the amplitudes to get probabilities and write the bitstrings in the same order the tool uses.
  5. Check the total probability is 1.

The routine is slow for large circuits and fast for the small ones that appear in examples, which is exactly where you need it.

Common reading mistakes

MistakeCorrection
Reading right to leftTime runs left to right in the picture. The matrix product is written right to left, which is a separate fact.
Treating the top wire as the leftmost character in Qiskit outputIn Qiskit the top wire is qubit 0, which is the rightmost character of the key.
Mixing up control and targetThe dot is the control. The circled plus is the target. Swapping them gives a different gate.
Assuming CZ has a directionCZ is symmetric. Either dot can be called the control.
Believing a barrier is a gateA barrier is only a separator. It changes nothing in the state.
Judging cost by the number of boxesTwo-qubit gates and depth usually matter more than single-qubit gates.
Thinking two different diagrams must be different circuitsGate identities can make different pictures equal. Check with a matrix.

Reading mistakes and fixes.

Practice problems

Check yourself

In Qiskit, a circuit applies X only to q2 of a three-qubit register and measures all. What is the counts key?

'100'.

What does the circuit CNOT(0→1), CNOT(1→0), CNOT(0→1) do?

It swaps the states of qubits 0 and 1.

How many basis states does a Toffoli gate change, out of eight?

Two: '011' and '111' exchange.

What is the depth of the 8-qubit GHZ state built by a chain, and by a branching pattern?

Chain: 8. Branch: 1 + ⌈log₂ 8⌉ = 4.

What does a Hadamard on both wires before and after a CNOT do?

It reverses the roles of control and target.

A circuit has an H on q0 followed by CNOT(0→1) followed by CNOT(0→1) again. What is the final state?

The two CNOTs cancel, so the state is (|0⟩+|1⟩)/√2 on qubit 0 and |0⟩ on qubit 1: keys '00' and '01'.

Why can two circuits with the same gate count differ in usefulness on hardware?

Depth and which qubits must interact, and the connectivity of the device, change how long they take and how many extra SWAPs are needed.

What does a barrier do to the quantum state?

Nothing. It only prevents tools from rearranging gates across it.

Which of CNOT and CZ is symmetric in its two qubits?

CZ.

In a two-qubit Qiskit circuit, what is the matrix for a Hadamard on qubit 0, in terms of Kronecker products?

I ⊗ H, with the identity for qubit 1 on the left.

References and further reading

I opened IBM’s bit-ordering page (the convention that qubit 0 is drawn at the top and is the rightmost character of a bitstring, and the draw(reverse_bits=True) option), IBM’s page on the optimization levels, and Google’s Cirq introduction (qubits, gates, operations, moments and circuits). All circuit readings, truth tables and equivalences on this page were checked with my own NumPy matrices. The standard textbook convention, the six-CNOT cost of a Toffoli gate and the drawings produced by Qiskit’s text drawer are background knowledge that I did not look up in this session, so the exact characters your Qiskit version prints may differ from what I show.

  1. Bit ordering (IBM Quantum documentation) Opened. Qubit 0 as the least significant bit, rightmost character of a bitstring, draw(reverse_bits=True) only changes the drawing, (control, target) ordering.
  2. Set optimization (IBM Quantum documentation) Opened. Optimization levels and the example in which level 3 reduced six ECR gates to three.
  3. Introduction to Cirq (Google Quantum AI) Opened. Qubits, gates and operations, moments as time slices, circuits as ordered sequences of moments, text diagrams with time moving left to right.
  4. Qiskit SDK 2.0 release notes (IBM Quantum documentation) Opened (first part). Removal of c_if in favour of if_test blocks.

Key terms in the dictionary