Level 7 · Capstone Topics

Quantum Circuit Simulator Problems: 30 Worked Exercises With Computed Answers

About 5,024 words · roughly 23 minute read · sources checked December 2026

A simulator is the first quantum computer most people use, and it is also where most confusion starts. A circuit that looks right produces a bitstring that looks reversed. A result that should be exactly 50-50 comes back as 487 and 537. A program that works with 20 qubits runs out of memory at 35. None of these is a bug in the physics. They are things you can predict, and this lesson trains you to predict them.

The problems are grouped into six sets: reading outputs and bit order, phases and interference, small algorithms, statistics from finite shots, the cost of simulation, and a final mixed set on entanglement protocols and error budgets. For each one, try to answer before you open the solution. Every numerical answer was computed with a small state-vector simulator I wrote in Python with NumPy for this project; the simulator uses little-endian bit order, like Qiskit, so qubit 0 is the rightmost character of a printed bitstring.

Qiskit itself is not installed in the environment where I prepared the lessons, so none of the Qiskit code in this lesson was run. The numbers come from my own simulation and from standard formulas. Where a number is an assumption (for example a processing speed), the text says so.

What you will learn

  • How to read a simulator's output bitstring and its bit order without guessing
  • How phases change measurement results through interference
  • What the correct outputs are for Deutsch-Jozsa, Bernstein-Vazirani, Grover and the QFT on small cases
  • How to tell ordinary shot noise from a real bug
  • How memory and time for state-vector simulation grow with the number of qubits

Helpful first: Your First Qiskit Circuit, Reading a Quantum Circuit Diagram, Quantum Algorithms.

How to use this set, and the simulator conventions

A state-vector simulator stores the amplitudes of every possible bitstring. For n qubits there are 2^n amplitudes, each a complex number. Applying a gate multiplies this vector by a matrix, and measuring a bitstring has probability equal to the squared magnitude of its amplitude. That is all a simulator does, and the first four sets of problems below are exercises in predicting what it will print.

The one convention that trips almost everybody is bit order. The simulator I used, like Qiskit, numbers qubits from 0 and prints the bitstring with qubit 0 on the right. So if three qubits are named q2, q1, q0, the string ‘110’ means q2 = 1, q1 = 1, q0 = 0, and its position in the state vector is the binary number 110, which is index 6. Many textbooks write the leftmost qubit first, and the two conventions give different strings for the same state. Before comparing any answer with a book, check which convention each uses.

Convention itemWhat this lesson uses
Qubit numberingq0 is the first qubit (the one you add first)
Printed bitstringq(n-1) ... q1 q0, so q0 is on the right
State-vector indexThe bitstring read as a binary number; for three qubits ‘110’ is index 6
Gate X, Z, HStandard matrices; H = (1/√2)[[1, 1], [1, −1]]
CNOT(c, t)Flips target t when control c is 1
MeasurementProbabilities are |amplitude|²; results are random in a real run

Conventions used for all answers in this lesson.

The reference code

The listing below shows how you would check the first problem in Qiskit. I did not run it, because Qiskit is not installed in my environment. It uses the Statevector class, which computes exact probabilities without sampling, so it is the right tool for checking an ideal circuit.

from qiskit import QuantumCircuit
from qiskit.quantum_info import Statevector

qc = QuantumCircuit(2)
qc.h(0)
qc.cx(0, 1)
print(Statevector(qc).probabilities_dict())
# expected: {'00': 0.5, '11': 0.5}
A Bell-state check in Qiskit (not run). The expected output is from my own simulation.

Work in three passes

First predict the answer on paper. Then compute it with exact probabilities (state vector). Only then run with shots. If the exact probabilities differ from your prediction, you misunderstood the circuit. If the shots differ from the exact probabilities, you are seeing sampling noise, which Set D explains.

Set A: reading outputs and bit order

Check yourself

A1. Apply H to qubit 0, then CNOT with control 0 and target 1. What are the exact outcome probabilities?

The result is the Bell state: ‘00’ with probability 0.5 and ‘11’ with probability 0.5. The Hadamard puts q0 in an equal superposition and the CNOT copies its value onto q1, so the two qubits always agree. ‘01’ and ‘10’ have probability exactly 0 in an ideal simulation. If you see them in a simulator without noise, the circuit is not what you think.

A2. Build a three-qubit GHZ state: H on q0, then CNOT(0,1), then CNOT(1,2). What does the simulator print?

‘000’ with probability 0.5 and ‘111’ with probability 0.5. Each CNOT passes the value of the previous qubit along the chain. All six other bitstrings have probability 0. Note that the string is symmetric, so bit order does not matter for this particular answer.

A3. On three qubits, apply X only to qubit 0. What bitstring is printed? What if X is applied only to qubit 2?

X on q0 prints ‘001’ (q0 is the rightmost character). X on q2 prints ‘100’. With the little-endian convention, the qubit you flipped is the position counted from the right, starting at 0. A very common mistake is to expect ‘100’ for the first case, which is the order used by many textbooks.

A4. Two qubits. Apply X to q1, then CNOT with control q1 and target q0. Then, in a second experiment, apply X to q1 and CNOT with control q0 and target q1. What do the two experiments print?

First experiment: X sets q1 = 1, the CNOT sees control = 1 and flips q0, so the result is ‘11’ with probability 1. Second experiment: q1 = 1 but the control q0 is 0, so nothing happens and the result is ‘10’ with probability 1. The two circuits differ only in which qubit controls which, and the outputs differ accordingly.

A5. Start with q0 = 1 (apply X), then apply CNOT(0,1), CNOT(1,0), CNOT(0,1). What is the final bitstring, and what did the three gates do?

The final bitstring is ‘10’, meaning q1 = 1 and q0 = 0. Three CNOTs in this alternating pattern make a SWAP gate: the value 1 moved from q0 to q1. This is how SWAP is built from CNOTs on hardware that has no native SWAP, which is also a reminder that moving information between distant qubits costs gates and therefore errors.

A6. A three-qubit state vector has amplitude 1 at index 6 and 0 elsewhere. Which bitstring is it, and which qubits are 1?

Index 6 in binary is 110, so the printed string is ‘110’ and q2 = 1, q1 = 1, q0 = 0. To convert, write the index in binary with n digits; the leftmost digit belongs to the highest-numbered qubit. This conversion is useful whenever you print a raw state vector and need to know which entry is which.

Set B: phases and interference

Probabilities depend only on the magnitudes of amplitudes, but phases decide how amplitudes add up when paths recombine. These problems show phases changing outcomes even though no single gate seems to ‘do’ anything to probabilities.

Check yourself

B1. Start with |0⟩. Apply H, then Z, then H. What is the measurement result?

The result is ‘1’ with probability 1. H makes (|0⟩ + |1⟩)/√2. Z flips the sign of the |1⟩ amplitude, giving (|0⟩ − |1⟩)/√2. The second H maps that to |1⟩. This is the identity H Z H = X, and it shows that a phase flip, which does not change probabilities by itself, becomes a bit flip after a change of basis.

B2. Start with |0⟩. Apply H, then T (a phase of e^(iπ/4) on |1⟩), then H. What are P(0) and P(1)?

P(0) = 0.8536 and P(1) = 0.1464. These equal cos²(π/8) and sin²(π/8). The reason: the two paths to outcome 0 add as (1 + e^(iπ/4))/2, whose magnitude is cos(π/8) ≈ 0.9239, and squaring gives 0.8536. A small phase of 45 degrees makes the interference only partly constructive. Compare with Z (a 180 degree phase), which makes the interference fully destructive for outcome 0 as in B1.

B3. Two qubits. Put q0 in |+⟩ (apply H), put q1 in |−⟩ (apply X then H), apply CNOT(0,1), then apply H to both qubits. What is printed?

‘11’ with probability 1. When the target of a CNOT is in |−⟩, the CNOT does not change the target but adds a phase of −1 to the control when it is 1. So the control goes from |+⟩ to |−⟩. This is called phase kickback, and it is the mechanism behind Deutsch-Jozsa, Bernstein-Vazirani and phase estimation. Applying H to |−⟩ gives |1⟩ on both qubits.

B4. Start with |0⟩ and apply X, Z, X, Z in that order. What state results and what does the simulator print?

Step by step: X gives |1⟩, Z gives −|1⟩, X gives −|0⟩, Z gives −|0⟩. The final state is −|0⟩, and the simulator prints ‘0’ with probability 1. The overall minus sign is a global phase, which has no observable effect. This is why two states that differ only by a global factor are considered the same state.

B5. Apply Ry(θ) to |0⟩, giving cos(θ/2)|0⟩ + sin(θ/2)|1⟩. For θ = π/3, what are P(1) and the expectation value ⟨Z⟩?

P(1) = sin²(π/6) = 0.25. The expectation ⟨Z⟩ = P(0) − P(1) = 0.75 − 0.25 = 0.5, which equals cos(θ) = cos(π/3) = 0.5. In general ⟨Z⟩ = cos θ for this state. This identity is the basis of variational algorithms, where a parameter θ is tuned to move an expectation value.

θP(1) = sin²(θ/2)⟨Z⟩ = cos θ
001
π/30.250.5
π/20.50
π1−1

Ry(θ) on |0⟩, computed in the simulator. These values will reappear in the variational algorithm lessons.

Set C: small algorithms with known answers

These problems give you reference outputs for small versions of famous algorithms. If your own implementation does not reproduce them exactly, there is a bug in the circuit, the oracle or the bit order.

Check yourself

C1. Deutsch-Jozsa with n = 3 input qubits (q0, q1, q2) and an ancilla q3 prepared in |−⟩. The oracle computes f(x) = x0 XOR x1 using CNOT(0, 3) and CNOT(1, 3). What is the output of the three input qubits?

The input register prints ‘011’ with probability 1, never ‘000’. The function is balanced, so the all-zero outcome has probability exactly 0. The nonzero result ‘011’ (q1 = 1, q0 = 1) in fact shows which inputs the function depends on. If the function were constant, the register would print ‘000’ with probability 1. This single-run certainty is the algorithm's advantage over a classical test, which may need more than half of the inputs to be sure.

C2. Bernstein-Vazirani with a hidden string s = 101 (q2 = 1, q1 = 0, q0 = 1). The oracle uses CNOT(0, 3) and CNOT(2, 3) onto the ancilla in |−⟩. What does the three-qubit register print?

‘101’ with probability 1. The oracle adds a phase (−1)^(s·x), and the final Hadamards turn that phase pattern directly into the string s. A classical algorithm needs 3 queries for a 3-bit string; the quantum one needs 1. Note again the bit order: CNOT from q0 and q2 gives ‘101’, which is symmetric, so choose s = 110 in your own test to check that your bit order is right.

C3. Grover search over N = 8 items (3 qubits) with the marked item 5 (bitstring ‘101’). What is the probability of measuring the marked item after 0, 1, 2, 3 and 4 iterations?

After 0 iterations 0.125, after 1 iteration 0.78125 (printed as 0.7812 or 0.7813 depending on rounding), after 2 iterations 0.9453, after 3 iterations 0.3301, after 4 iterations 0.0122. These match sin²((2k + 1)θ) with sin θ = 1/√8, θ ≈ 0.3614 radians. The probability rises, peaks at two iterations and falls again, which is the signature of Grover's algorithm: running it for too long makes the answer worse.

C4. How many Grover iterations should you use for N = 8, and how do you compute it?

The best number is the integer closest to π/(4θ) − 1/2, where θ = arcsin(1/√8) ≈ 0.3614. That is 2.173 − 0.5 = 1.67, which rounds to 2. Two iterations give 0.9453, which the table in C3 confirms is the best of the five values. For large N the formula gives about (π/4)√N iterations.

C5. The 3-qubit QFT is applied to the basis state |5⟩. What are the measurement probabilities, and what are the phases of the output amplitudes in units of π?

Every output has probability 1/8 = 0.125, because the QFT of a basis state spreads equally over all outputs. The amplitudes are e^(2πi·5k/8)/√8 for k = 0 to 7, so the phases in units of π are 0, −0.75, 0.5, −0.25, 1, 0.25, −0.5, 0.75 (taking angles between −π and π). The information about 5 is in the phases, not in the probabilities, which is why a measurement right after a QFT shows nothing and why phase estimation needs the inverse QFT.

Iterations kP(marked item) from the simulatorFormula sin²((2k+1)θ)
00.12500.1250
10.78120.7812
20.94530.9453
30.33010.3301
40.01220.0122

Grover on N = 8, marked item 5. The simulator and the formula agree to four decimals.

Set D: shots, noise and statistics

A real device, and a simulator that samples, returns a finite number of measurement results called shots. Each shot is a random draw from the exact probabilities, so the observed fractions fluctuate. For an outcome with probability p, the standard deviation of the observed fraction after N shots is √(p(1 − p)/N). These problems teach you to recognise ordinary fluctuation.

Check yourself

D1. The exact probability of ‘00’ is 0.5. What is the standard error of the observed fraction with 100, 1,024 and 10,000 shots?

The standard error is √(0.25/N): 0.05 for 100 shots, 0.0156 for 1,024 shots and 0.005 for 10,000 shots. So with 1,024 shots the observed fraction typically lies within about 1.6 percentage points of 0.5. Quadrupling the number of shots only halves the error, because the error scales as 1 divided by the square root of N.

D2. How many shots do you need to estimate a probability near 0.5 to within ±0.01 with about 95 percent confidence?

Use N = (1.96 × 0.5 / 0.01)² = 98² = 9,604 shots. The 1.96 is the usual factor for 95 percent confidence, a standard statistical value. This is the reason why estimating probabilities to two decimals needs thousands of shots, and why variational algorithms that need many expectation values are costly on real devices.

D3. In a noiseless simulation with 1,024 shots of a Bell state you get ‘00’: 487 and ‘11’: 537. Is that a bug?

No. The expected count is 512 for each, with standard deviation √(1024 × 0.25) = 16. The count 487 is (487 − 512)/16 ≈ −1.56 standard deviations from the mean, and 537 is +1.56. Differences of that size are ordinary. Also, ‘00’ and ‘11’ together sum to 1,024, so no shot landed on ‘01’ or ‘10’, which is the property that matters.

D4. The same Bell-state circuit on a real device gives ‘01’ and ‘10’ a few percent of the time. A noiseless simulator gives them zero times. Which is the bug?

Neither. The simulator is ideal, so ‘01’ and ‘10’ must be exactly zero. The device has gate errors and readout errors, so a few percent of results in the forbidden outcomes is the expected signature of noise. The size of that leakage is a quick measure of device quality, and it is why the lesson on moving from simulator to hardware stresses comparing the two instead of trusting either one alone.

Shots NStandard error at p = 0.5Standard error at p = 0.1
1000.05000.0300
1,0240.01560.0094
10,0000.00500.0030

Standard error of an observed probability, √(p(1−p)/N). The error is largest for p = 0.5 and smaller for outcomes that are rarer or more common.

Set E: the cost of simulation

A state vector of n qubits has 2^n complex amplitudes. Storing each as two 64-bit floating-point numbers takes 16 bytes, so the memory is 2^n × 16 bytes. This is the reason classical simulation hits a wall, and it is also the reason that quantum computers might eventually do something classical machines cannot.

Check yourself

E1. How much memory does a state vector need for 20, 30, 40 and 50 qubits at 16 bytes per amplitude?

20 qubits: 2^20 × 16 bytes = 16 MiB (about 0.0156 GiB). 30 qubits: 16 GiB. 40 qubits: 16,384 GiB, which is 16 TiB. 50 qubits: 16,777,216 GiB, which is 16 PiB. Each added qubit doubles the memory. At 30 qubits an ordinary laptop with 16 GiB is already full, and 40 qubits needs a large cluster.

E2. What is the largest number of qubits that fits in a machine with 64 GiB of memory, ignoring everything else?

The state vector needs 2^n × 16 bytes. For 64 GiB = 2^36 bytes, 2^n × 2^4 ≤ 2^36 gives n ≤ 32. So 32 qubits is the limit, and in practice a few qubits fewer, since the program and a copy of the vector for gate application need space. Doubling the memory to 128 GiB gains only one more qubit.

E3. Applying one single-qubit gate touches every amplitude, about 2^n operations. Assume, as an illustration only, a rate of 10^9 amplitude updates per second. How long does a 1,000-gate circuit take on 30 qubits?

At 30 qubits, 2^30 ≈ 1.07 × 10^9 updates per gate, so 1,000 gates need about 1.07 × 10^12 updates, which takes about 1,070 seconds, roughly 18 minutes at the assumed speed. The assumed rate is my illustration, not a measurement; real speeds depend on hardware and code. Adding 10 more qubits multiplies the time by 1,024.

E4. A friend says their simulator ran a 100-qubit circuit in seconds. Is that impossible?

Not necessarily. A full state-vector simulation of 100 qubits is impossible, since 2^100 amplitudes cannot be stored. But specialised simulators exploit structure: a circuit built only from certain gates (called Clifford gates) can be simulated efficiently, a known result that I am stating from general knowledge and did not verify in this project, and circuits with little entanglement can be simulated with compressed representations. The right questions are what gates the circuit uses and how entangled the state gets.

QubitsAmplitudes 2^nMemory at 16 bytes each
101,02416 KiB
201,048,57616 MiB
301,073,741,82416 GiB
40about 1.1 × 10^1216 TiB
50about 1.1 × 10^1516 PiB

Memory for a full state vector. Binary prefixes: 1 GiB = 2^30 bytes. Computed by my own arithmetic.

Set F: mixed problems on entanglement and error budgets

The last set mixes the earlier ideas. These are closer to what you meet in real projects: protocols that use entanglement, an inequality that tests it, and a rough estimate of how errors add up.

Check yourself

F1. Teleportation. Prepare an unknown state on q0 with P(1) = sin²(0.35) ≈ 0.1176 (apply Ry(0.7) to |0⟩). Make a Bell pair on q1 and q2, then CNOT(0,1), H(0), and measure q0 and q1. What are the probabilities of the four measurement results, and what is the state of q2 in each case?

Each of the four results (00, 01, 10, 11 for the pair q1 q0) has probability exactly 0.25, whatever the unknown state is. The state of q2 depends on the result: if q1 measured 0 it has P(1) = 0.1176 (the original value), and if q1 measured 1 it has P(1) = 0.8824, the X-flipped value. Whether q0 measured 0 or 1 does not change P(1), because that case differs only by a Z phase, which is invisible to a computational-basis measurement. The sender must send two classical bits, the receiver applies X if q1 was 1 and Z if q0 was 1, and then q2 holds the original state. Nothing travels faster than the classical message.

F2. Superdense coding. Alice and Bob share a Bell pair (q0 is Alice's, q1 is Bob's). Alice applies one of I, X, Z or X then Z to her qubit; then Bob applies CNOT(0,1) and H(0) and measures both. What does the simulator print for each of Alice's four choices?

In my simulation, I gives ‘00’, X gives ‘10’, Z gives ‘01’ and Z then X gives ‘11’ (all with probability 1). Notice the little-endian printing: Alice's X shows up as a 1 in the left position, because the printed string lists q1 first. One qubit sent from Alice carries two classical bits, using the entanglement she shared earlier. A quick check of your own code is to confirm that the four results are all different.

F3. CHSH test. For the Bell state (|00⟩ + |11⟩)/√2, the correlation between measurements along angles a and b in the x-z plane is E(a, b) = cos(a − b). Take a = 0, a′ = π/2, b = π/4, b′ = −π/4 and compute S = E(a,b) + E(a,b′) + E(a′,b) − E(a′,b′). What does the result mean?

S = 0.7071 + 0.7071 + 0.7071 − (−0.7071) = 2.8284, which is 2√2. My direct matrix calculation gave 2.82843, the same. Any theory in which the outcomes are fixed in advance by local hidden variables must give |S| ≤ 2, so a value of 2.83 is a violation and is the standard test of entanglement. A noisy device gives a smaller value; if your measured S is below 2, the entanglement is too weak to show, even if the Bell-state counts look good.

F4. Apply H, T, H to a qubit and then apply H, T† (phase e^(−iπ/4) on |1⟩), H. What does the simulator print?

‘0’ with probability 1. The second block is the inverse of the first: the product H T† H · H T H = H T† T H = H H = I. After the first block, P(0) was 0.8536 as in B2, but the amplitudes are not lost; the second block undoes them exactly. This is the basis of uncomputation in algorithms and of mirror-circuit tests on hardware, where running a circuit and then its inverse should return the start state and any other answer measures the noise.

F5. On a real device, a Bell circuit run with 1,024 shots gives ‘00’: 480, ‘11’: 500, ‘01’: 24, ‘10’: 20. Estimate how often the qubits disagree, and give a simple summary of quality.

Disagreements total 24 + 20 = 44 out of 1,024, which is 0.0430 or about 4.3 percent, so the qubits agree in about 95.7 percent of shots. That is a crude quality number, since it counts only errors that break the parity and ignores errors that preserve it (for example a phase error, which this measurement cannot see). A full estimate of Bell-state fidelity also needs measurements in other bases.

F6. A circuit has 20 two-qubit gates, each with a 0.5 percent chance of failing independently. What is the probability that none fails? Roughly how many such gates can you run before the success chance falls below 50 percent?

0.995^20 = 0.9046, so about 90 percent. The number n for which 0.995^n = 0.5 is n = ln(0.5)/ln(0.995) = 138.3, so about 138 gates. This is a rough model that treats errors as independent and fatal, but it gives the right order of magnitude and shows that a 0.5 percent error rate limits circuits to roughly a hundred gates without error correction.

Write a 15-line simulator and see the control bug yourself

The best way to understand a simulator is to write one. A state vector is a NumPy array, a gate is a matrix, and applying a gate is a matrix-vector product. For two qubits the basis order is |q1 q0⟩, that is 00, 01, 10, 11, with q0 the rightmost bit. A gate on q0 alone is the Kronecker product I ⊗ G, because the first factor belongs to q1 and the second to q0. The program below is real code that I ran with NumPy in this project; it builds the Bell state twice, once with the CNOT controlled by q1 and once with the CNOT controlled by q0.

import numpy as np

H = np.array([[1, 1], [1, -1]]) / np.sqrt(2)
I = np.eye(2)

# Basis order is |q1 q0>: 00, 01, 10, 11  (q0 is the rightmost bit).
CNOT_c1_t0 = np.array([[1,0,0,0],[0,1,0,0],[0,0,0,1],[0,0,1,0]])  # control q1, target q0
CNOT_c0_t1 = np.array([[1,0,0,0],[0,0,0,1],[0,0,1,0],[0,1,0,0]])  # control q0, target q1

def run(cnot):
    state = np.array([1, 0, 0, 0], dtype=float)   # |00>
    state = np.kron(I, H) @ state                 # H on q0
    state = cnot @ state
    return {format(i, '02b'): round(float(abs(a) ** 2), 4) for i, a in enumerate(state)}

print('control q1:', run(CNOT_c1_t0))
print('control q0:', run(CNOT_c0_t1))
A two-qubit simulator in NumPy. This program was run.
control q1: {'00': 0.5, '01': 0.5, '10': 0.0, '11': 0.0}
control q0: {'00': 0.5, '01': 0.0, '10': 0.0, '11': 0.5}
Output of the program above.

The first line is the wrong answer for a Bell state. H is applied to q0, but the CNOT is controlled by q1, which is still 0, so the CNOT does nothing and the state is just a superposition of 00 and 01. The qubits are not entangled. The second line is correct: the control is q0, so the 1 branch flips q1 and the result is the Bell state with 00 and 11. Everything about the two circuits is the same except which qubit controls. This is precisely the bug in problem A4, and writing the matrices makes it visible: the two CNOT matrices differ only in which pairs of basis states they swap.

What to look at in the matrices

In the control-q0 matrix, the second and fourth rows swap, which means the basis states 01 and 11 exchange. Those are the two states in which q0 = 1, and the exchange flips q1, so q0 is the control. In the control-q1 matrix, the third and fourth rows swap, which exchanges 10 and 11, the states with q1 = 1; the exchange flips q0, so q1 is the control. Reading a gate matrix in this way, as a list of which basis states it swaps, is a useful skill when a circuit gives a surprising answer.

You can extend the program to three qubits with np.kron(I, np.kron(I, H)) for H on q0, and you can reproduce several answers in this lesson. For larger systems the matrices become too large, which is why real simulators apply gates by reshaping the state vector instead of building a full matrix; the memory problem of Set E applies to the vector, and a full matrix would need the square of that.

A debugging checklist for simulator results

When a result looks wrong, work through the list below in order. It is arranged from the most common cause to the least common. Most wrong-looking results are explained by one of the first four items.

  1. Bit order. Is the string printed with qubit 0 on the right or on the left? Rerun the single-X test from problem A3 on your tool. If X on q0 prints ‘001’ you have the little-endian convention used here.
  2. Control and target. In CNOT(c, t), which argument is the control? Rerun problem A4. A swapped control and target is the most common circuit bug.
  3. Measurement placement. Did you measure before the last gate? Gates after a measurement do not affect that outcome, and some tools silently allow it.
  4. Shot noise. Is the deviation within a few standard errors, as in problem D3? If yes, nothing is wrong.
  5. Missing normalisation or a wrong oracle. For Deutsch-Jozsa and Bernstein-Vazirani, check that the ancilla was put in |−⟩ (X then H); with the ancilla in |0⟩ the oracle does not produce a phase and the output is wrong.
  6. Wrong number of iterations. For Grover, compute the optimal count with the formula in problem C4. Too many iterations lowers the success probability, as the table in C3 shows.
  7. Noise model. If you added noise, the forbidden outcomes will appear, as in problem D4. Remove the noise to check the ideal circuit first.
  8. Library version. Quantum libraries change their interfaces quickly. Check the version of the library against the code example you copied.

The exact-then-sampled habit

Always compute the exact probabilities first (a state-vector calculation), and only then compare with sampled counts. If the exact probabilities are right, any remaining difference is sampling noise or hardware noise, and you know where to look.

A reference table of the expected outputs

The table below collects the key outputs, so you can use them as a regression test for your own code. Run each circuit in your own tool, using the exact-probability mode, and compare. The values are from my own simulation.

CircuitExpected exact output (qubit 0 on the right)
H(0), CNOT(0,1)00: 0.5, 11: 0.5
H(0), CNOT(0,1), CNOT(1,2)000: 0.5, 111: 0.5
X(0) on 3 qubits001: 1
X(2) on 3 qubits100: 1
X(1), CNOT(1,0)11: 1
X(0), CNOT(0,1), CNOT(1,0), CNOT(0,1)10: 1
H, Z, H on one qubit1: 1
H, T, H on one qubit0: 0.8536, 1: 0.1464
|+⟩ and |−⟩, CNOT(0,1), then H on both11: 1
Deutsch-Jozsa, f = x0 XOR x1, three inputsInput register 011: 1
Bernstein-Vazirani, s = 101Input register 101: 1
Grover, N = 8, marked 5, 2 iterations101: 0.9453
QFT on |5⟩, three qubitsEach outcome 0.125

Regression values for small circuits, computed with a NumPy state-vector simulator for this project. They are exact to the digits shown.

Turning the problems into a test suite

A good habit is to keep these circuits as automated tests. Each test builds the circuit, computes the exact probabilities and checks that they match the table to a tolerance of about 10^-9. When you change your code, or upgrade a library, the suite tells you at once whether a gate convention changed. Because the answers are exact, there are no random failures, which is not true of tests that depend on sampled counts. If you do need a sampled test, set the tolerance from the standard error: with 10,000 shots and p = 0.5, three standard errors is 0.015, so a tolerance of 0.02 is reasonable.

Where to go next

If these problems felt easy, move to the algorithms practice set and then to circuits on real hardware, where the noise questions of Set D become central. If they felt hard, return to the lesson on reading circuit diagrams and the beginner mistakes lesson, then retry the problems you missed without looking at the solutions. The aim is not to memorise the numbers, but to be able to predict them.

References and further reading

All numerical answers were computed in this project with a NumPy state-vector simulator, or from standard formulas stated in the text. Qiskit code shown is not run.