QuantumLab — Handbook and guided course

Officina Turini · Educational freeware · C++14 / Qt5 · v0.16.0

Italiano

Contents

All 21 lessons, explained

Start here: what is quantum computation?

A classical computer manipulates bits. A quantum processor controls physical states described by complex amplitudes. QuantumLab is not a quantum processor: your PC simulates those amplitudes, so you can pause an experiment and inspect information that cannot be directly read from real hardware.

The laboratory rule: predict first, change a gate, inspect amplitudes and probabilities. Use equations afterwards to explain what you saw.

Your first experiment in five moves

  1. Choose 01 — The quantum coin.
  2. Read the required qubits: 1, hence 2 basis states.
  3. Stop at initial |0⟩; select H and press Next step.
  4. Observe amplitudes +0.7071: probabilities 50% and 50%.
  5. Run 1000 shots. Return to the circuit and try the second Hadamard.

Recommended path

Lessons 01–04: observe. 05–14: build and check. 15–21: discover algorithms. Afterwards use the parametric lab to change oracles, secrets and iteration counts.

↑ Back to contents

What exactly is a qubit?

For one ideal qubit we write |ψ⟩ = α|0⟩ + β|1⟩. The amplitudes α and β may be complex; the probabilities are |α|² and |β|² and sum to one.

|ψ⟩ = α|0⟩ + β|1⟩ |α|² + |β|² = 1 P(0) = |α|² P(1) = |β|²

With n qubits the computational basis has 2n states. The simulator holds 2n complex amplitudes; this does not allow you to read 2n answers in one measurement.

Bit order

QuantumLab numbers q0 as the least significant bit on the right. In two qubits, |10⟩ means q1=1 and q0=0. X(q0) applied to |00⟩ gives |01⟩; X(q1) gives |10⟩.

Global versus relative phase

Multiplying the entire state by eiφ changes no observable predictions. Changing just one amplitude’s sign can change later interference. Challenges therefore use fidelity, invariant under global phase but sensitive to relative phase.

Measurement

Measurement draws an outcome and collapses the simulated state. Repeated preparations (10, 100, 1000 or 10000) instead draw independent samples from the same preparation; they are not consecutive measurements of one already-collapsed qubit. A single shot does not validate a probabilistic algorithm.

↑ Back to contents

The five quantum gates

GateEffectTry it
XSwaps |0⟩ and |1⟩ (computational-basis NOT).X·X = identity.
HMixes amplitudes: H|0⟩=(|0⟩+|1⟩)/√2.H·H = identity.
ZNegates the |1⟩ amplitude; does not instantly change probabilities.H–Z–H acts as X.
P(θ)Multiplies the |1⟩ amplitude by eiθ.P(180°)=Z; input is degrees.
CNOTFlips target if the control qubit is 1.H(q0), CNOT(q0→q1): Bell.

Before measurement these operations are unitary and reversible. Circuit gates act in time order; CNOT has two distinct qubits, control and target.

Attention: the editor takes P angles in degrees, while internal C++ calculations use radians.

↑ Back to contents

Using QuantumLab without getting lost

Four left-hand tabs

Lesson: question, hints, challenge checking. Algorithms: oracle parameters and checkpoints. Editor: gates and qubits. Measurements: prediction, sampling, validation and report.

Three right-hand panes

The circuit viewer supports zoom and step selection; the amplitude/probability table and the Laboratory Notebook sit below. Splitters adjust pane sizes. QSettings remembers the layout.

Three different operations

Advance a gate changes the simulated state. Jump to checkpoint reconstructs an intermediate state without a physical measurement. Measure samples and collapses. The 1000 shots sample many independent preparations.

Editor and files

To modify a prepared lesson create a working copy. Insert or replace gates; old shots are invalidated. Save the circuit as .qlab.json; export predictions, counts and outcomes as a separate JSON result. Unsaved changes are indicated in the title and protected at exit.

IT / EN

The selector switches labels, tooltips, explanations and manual. QSettings under Officina Turini / QuantumLab remembers language and window geometry.

↑ Back to contents

Learning by predicting, trying and explaining

For every exercise: (1) predict an outcome, (2) build or explore, (3) inspect amplitudes, (4) sample repeatedly, (5) explain. A surprising result is useful if you can trace its cause.

Example: H produces 50/50; Z keeps 50/50; a second H produces 100% on |1⟩. Only looking at intermediate probabilities hides the information that makes this work.

Challenges 05–14 start blank. They are graded against the final state, plus teaching constraints when needed (required gates, minimum length). They are not graded on lucky measurements.

↑ Back to contents

Oracles: what are we counting?

An oracle is a reversible circuit exposing a function. In the query model one complete use of Uf counts as one query even if built from many X, H, P and CNOT gates. Always separate queries, elementary gates, RAM and elapsed time.

Deutsch

The one-bit function is promised constant or balanced. A deterministic classical algorithm may need two queries for certainty; Deutsch needs one. Read only data qubit q0: 0=constant, 1=balanced. The ancilla is not the answer.

Bernstein–Vazirani

The oracle returns f(x)=s·x mod 2. For s=101, three classical basis-vector queries recover the three bits; the quantum circuit uses one logical call. Read q2q1q0; q3 is an ancilla and may measure randomly.

Grover

Unstructured search has one marked state. The oracle flips its phase, and diffusion converts that phase into increased amplitude. Optimal query complexity scales as O(√N), rather than O(N). The gate cost of constructing oracle and diffusion must be counted separately.

3 qubits, target |101⟩Ideal probability
Uniform preparation12.5%
1 iteration78.125%
2 iterations94.53125%
3 iterations33.0078125%
4 iterations1.220703125%
Query count does not predict runtime on the PC or real quantum hardware. Comparisons involving success probability below 100% do not automatically hold reliability constant.

↑ Back to contents

Where the simulator ends and real hardware begins

QuantumLab is an ideal state-vector simulator. It stores one complex amplitude per computational basis state. At two double values per amplitude, the state alone needs about 16·2n bytes.

QubitsState-vector RAM (complex double)
84 KiB
2016 MiB
3016 GiB
3264 GiB

The present editor is deliberately limited to 1–8 qubits; the parametric Grover lab uses 2–3 qubits. Support for 30 qubits is a possible future development, not a current feature.

This software does not fully simulate gate noise, decoherence, actual processor connectivity, error correction or energy costs. Displayed amplitudes are internal information from the numerical model, not quantities directly readable from hardware in one measurement.

↑ Back to contents

Can we trust the results?

The v0.11 scientific suite checks analytical vectors, an independent matrix-based reference, norm conservation, circuit replay and algorithms. The Measurements tab shows PASS/FAIL and exports a JSON report.

A successful test suite does not prove there are no bugs; compilation on another PC still requires verification. When something looks wrong, reduce to a few gates and compare amplitudes, probabilities and checkpoints.

For two normalized pure states |ψ⟩ and |φ⟩, fidelity is F = |⟨φ|ψ⟩|². It remains 1 when the states differ only by global phase. Challenges may also impose required gate types or lengths.

↑ Back to contents

Questions and troubleshooting

Why do 1000 shots not give exactly 500/500?

Sampling is random. Theoretical probability does not enforce a fixed quota per experiment.

Why does Z not change the histogram?

Z changes relative phase. Add a later H to observe the effect.

Why does challenge grading reject correct-looking probabilities?

It compares the quantum state (including relative phase) and some lesson constraints. Try lessons 11 and 13.

Why does Bernstein–Vazirani show two final basis outcomes?

The ancilla remains in superposition; the answer lives in the data qubits only.

Why does Grover get worse after three or four iterations?

It is a rotation; pushing beyond the optimum decreases success probability.

Is the program faster than a classical computer?

No: the program is a classical computer simulating a quantum circuit. The discussion concerns abstract queries, not CPU simulation time.

Where are my files?

Circuits save as .qlab.json; shot data export separately. Remembering language or window layout does not automatically save a modified circuit.

Help is missing?

The internal manual is compiled into the application as a resource. If building from source, check that Help/QuantumLabHelp.qrc is processed by Qt RCC.

↑ Back to contents

Essential glossary

TermOperational meaning
AmplitudeComplex number whose squared magnitude is a probability.
Computational basisStates indexed by binary strings.
AncillaService qubit that need not be part of the answer.
InterferenceCombination and cancellation of complex amplitudes.
Relative phaseDifference in phase between amplitudes that can affect measurements.
Global phaseOverall phase factor with no observable effect.
EntanglementComposite state not factorable into independent subsystem states.
FidelitySquared overlap of two pure quantum states.
OracleReversible implementation of a function used by an algorithm.
ShotOne preparation followed by one measurement.
CheckpointReconstructed intermediate state for inspection, not a physical measurement.

↑ Back to contents

Mathematical appendix, step by step

This material is not a prerequisite: it explains what you have already observed.

Vectors and gates

|0⟩ = (1, 0)ᵀ |1⟩ = (0, 1)ᵀ X = [[0, 1], [1, 0]] Z = [[1, 0], [0,-1]] H = (1/√2) [[1, 1], [1,-1]] P(θ) = [[1, 0], [0, exp(iθ)]]

H applied to |0⟩ gives (1/√2,1/√2); Z negates the second component; another H gives (0,1). That is the complete calculation behind lesson 04.

Tensor products and CNOT

Independent qubits form tensor products. The ordered basis is |00⟩, |01⟩, |10⟩, |11⟩; q0 is on the right. CNOT is a four-dimensional unitary.

Sampling statistics

P(x) = |aₓ|² Σₓ P(x) = 1 σ(p̂) ≈ √[p(1−p)/M] (M independent shots)

For p=1/2 and M=1000, the frequency standard deviation is about 1.58 percentage points. Observing 515/485 does not contradict a 50/50 model.

Fidelity

F(|ψ⟩,|φ⟩) = |Σₓ conj(φₓ)·ψₓ|²

Global phase disappears after taking the squared magnitude. But (|0⟩+|1⟩)/√2 and (|0⟩−|1⟩)/√2 have zero fidelity although both yield 50/50.

Grover as a rotation

sin θ = 1/√N P_success(k) = sin²((2k+1)θ)

For a single marked state, uniform preparation and k ideal iterations. It explains the peak and over-rotation in lessons 20–21.

↑ Back to contents

For teachers: ready-to-use lesson plans

Each group should formulate a testable hypothesis before pressing Run. The goal is experimental intuition, not memorized gate names.

45-minute class

  1. 5′: classical coin and H; predict frequencies.
  2. 10′: H and H; interference.
  3. 10′: H–Z–H; why does Z leave probabilities unchanged?
  4. 10′: Bell; observed correlation versus entanglement certification.
  5. 10′: challenge 13; explain why H alone fails.

90-minute class

Add Deutsch, two-qubit Grover, then three qubits with one and two iterations. Each group reports queries, gate count and success probability separately.

Ask instead of telling

Do not equate lower query complexity with automatic runtime superiority. A 00/11 histogram alone does not certify entanglement.

↑ Back to contents

Learning lab 0.16

Start the learning path

Learning lab opens a non-modal window with four tabs. Beginner view in the main window hides numerical details and advanced tabs; turn it off to explore further. Both views share the same simulated state.

Prediction and reasoning

Choose activities 1, 2 and 3 (lessons 01, 02 and 04). Before applying gates, choose a distribution: always state 0, always state 1, all outcomes equally likely, or I do not know yet. For multiple qubits the displayed bits refer to the whole register. Write a reason and press Record prediction. After the final gate the program compares it with theory, independently of one random draw. Restarting or editing invalidates the recorded prediction.

A/B comparisons

Load H/H-Z, H-H/H-Z-H, or Grover with 1/2 or 2/3 iterations; alternatively copy the current circuit to A and B. Copies are independent. Step A and Step B reconstruct unitary circuit prefixes, without intermediate measurements. Gate strings appear above the table; hover over long strings to read them in full. Append H to both is available for two single-qubit circuits.

Arrows show phase direction and amplitude magnitude; numerical phases are in degrees. Zero amplitude has undefined phase. A global phase does not identify a different physical state.

Statistics and challenges

In the main Measurements tab choose 10, 100, 1000 or 10000 preparations. The table separates theoretical probability, count and observed frequency. The notebook records the trial count. A finite series need not split exactly 50/50. Challenges use the stated minimum gate constraints: longer equivalent solutions are accepted unless they use forbidden gates. Feedback detects matching probabilities with different relative phase.

Undo edits

File → Undo circuit edit (Ctrl+Z) and Redo circuit edit (Ctrl+Y) handle insertion, replacement, deletion, movement and qubit count. History retains up to 100 edits, resets on document/session changes, and is distinct from circuit step navigation. An edit invalidates previous circuit measurements and predictions.

Save a session

Worksheet and session holds the question, reasoning, observations and conclusion. Save session (Ctrl+Alt+S) writes a .session.json containing circuit, lesson, step, measurement, counts, prediction and A/B copies. The random generator is preserved for resuming in the same runtime environment; identical sequences across different C++ libraries are not promised. Window preferences remain separate in QSettings.

Saves are atomic. Loading validates data before replacing the active work. Limits: 1 MiB per session and 32768 characters per text field. Unsaved session changes require Save/Discard/Cancel before closing or replacing the document. Saving only the circuit does not save notes. The .qlab.json circuit format remains compatible.

Print a worksheet

Export HTML worksheet creates a standalone browser-printable document with question, prediction, reasoning, notes, conclusion, gates, amplitudes, probabilities and frequencies. Its embedded circuit JSON allows reconstruction. Use the session to resume the complete activity. Results JSON export now uses version 2 and includes the circuit and pre-measurement amplitudes.

Bell and classical mixture

The fourth tab compares Bell+ with a 50/50 ensemble of 00 and 11. Z/Z probabilities agree; in X/X Bell+ gives 00 and 11 at 50%, while the mixture gives four outcomes at 25%. Bases are ordered q1/q0. Switching to X uses H before readout. The mixture adds branch probabilities, never branch amplitudes. This distinguishes two known preparations, is not a universal entanglement certificate, and does not model noise.

↑ Back to contents

All 21 lessons, explained

01 — The quantum coin

DemonstrationQubits: 1

The question: Start in |0⟩ and apply H(q0). Predict 0 or 1 before measuring.

Try it in the program: Select H, inspect the amplitudes, then run 1000 independent shots without collapsing the displayed state.

Expected observation: P(0)=P(1)=50%. With 1000 shots the counts are close, not necessarily equal.

Why it works: H does not hide an ordinary classical coin: it prepares +1/√2 amplitudes, each with probability 1/2.

Watch out: Do not confuse a single measurement with the full distribution.

↑ Back to contents

02 — The second Hadamard

DemonstrationQubits: 1

The question: Apply H twice. Does uncertainty double or disappear?

Try it in the program: Pause after the first and second H; inspect amplitudes, not only measurement.

Expected observation: The final state is |0⟩ with 100% probability.

Why it works: H·H=I: the second mixing interferes constructively for |0⟩ and destructively for |1⟩.

Watch out: "More gates" does not necessarily mean "more randomness".

↑ Back to contents

03 — The twin coins

DemonstrationQubits: 2

The question: From |00⟩ produce perfectly matching outcomes, 00 and 11.

Try it in the program: Apply H(q0), then CNOT with control q0 and target q1.

Expected observation: 00 and 11 each have 50%; 01 and 10 never occur.

Why it works: The state (|00⟩+|11⟩)/√2 is entangled and cannot be factored into two single-qubit states.

Watch out: The 00/11 histogram alone does not certify entanglement; measurements in other bases are needed.

↑ Back to contents

04 — An invisible sign

DemonstrationQubits: 1

The question: Can a phase change a later outcome while leaving intermediate probabilities unchanged?

Try it in the program: Compare H–H with H–Z–H, inspecting the table just after Z.

Expected observation: After Z it is still 50/50; after the final H, |1⟩ is certain.

Why it works: Z introduces a relative phase of π: the second H converts phase difference into probability.

Watch out: Phase is not negative probability.

↑ Back to contents

05 — Turn the qubit on

ChallengeQubits: 1

The question: Build |1⟩ from |0⟩ using at least one X gate.

Try it in the program: In the Editor tab select X on q0 and insert it into the empty circuit.

Expected observation: The checker should return PASS: amplitude 1 on |1⟩.

Why it works: X acts like a NOT on computational basis states.

Watch out: H produces a superposition, not a certain |1⟩.

↑ Back to contents

06 — NOT twice

ChallengeQubits: 1

The question: Return to |0⟩ using exactly two X gates.

Try it in the program: Insert X(q0), then a second X(q0).

Expected observation: The checker accepts X–X because X²=I.

Why it works: Unitary quantum transformations are reversible.

Watch out: An empty circuit has the same state but does NOT meet the two-X learning constraint.

↑ Back to contents

07 — Build a quantum coin

ChallengeQubits: 1

The question: Prepare (|0⟩+|1⟩)/√2 using at least one H.

Try it in the program: Insert H(q0); compare amplitudes and probabilities.

Expected observation: The amplitudes are both +1/√2; probabilities are 50/50.

Why it works: The distribution alone does not define the state: relative sign matters.

Watch out: Do not confuse this with challenge 13, which requires a different phase.

↑ Back to contents

08 — Which qubit?

ChallengeQubits: 2

The question: Start from |00⟩ and prepare exactly |01⟩.

Try it in the program: The rightmost bit is q0: apply X(q0).

Expected observation: P(01)=100% and all others are zero.

Why it works: QuantumLab uses q0 as the least significant bit in the binary index.

Watch out: X(q1) would prepare |10⟩, not |01⟩.

↑ Back to contents

09 — Four possibilities

ChallengeQubits: 2

The question: Produce four equal, positive amplitudes.

Try it in the program: Apply H(q0) and H(q1). The order of these two H gates does not matter.

Expected observation: All four amplitudes are +1/2; each outcome has probability 25%.

Why it works: Two qubits have 2²=4 basis states, but one measurement returns just one state.

Watch out: Four amplitudes do not mean four simultaneously readable answers.

↑ Back to contents

10 — Build a Bell pair

ChallengeQubits: 2

The question: Prepare (|00⟩+|11⟩)/√2.

Try it in the program: Insert H(q0), then CNOT(q0→q1).

Expected observation: The checker accepts a coherent superposition of 00 and 11.

Why it works: CNOT can create entanglement if the control is in superposition.

Watch out: A classical 50/50 mixture of 00 and 11 would have the same histogram in this basis.

↑ Back to contents

11 — Turn phase into outcome

ChallengeQubits: 1

The question: Reach |1⟩ without X, using at least two H and one Z.

Try it in the program: Try H(q0)–Z(q0)–H(q0).

Expected observation: The checker accepts H–Z–H and also checks the gate constraint.

Why it works: HZH=X: the same action can be implemented very differently.

Watch out: A single X gives the final state but violates the challenge objective.

↑ Back to contents

12 — Alternative Bell state

ChallengeQubits: 2

The question: Prepare (|01⟩+|10⟩)/√2.

Try it in the program: Start with a standard Bell state, then apply X(q0).

Expected observation: Nonzero amplitudes belong to 01 and 10, both +1/√2.

Why it works: A local gate can transform one Bell state into another.

Watch out: Correct probabilities alone are not enough: relative phase must match.

↑ Back to contents

13 — Probabilities can mislead

ChallengeQubits: 1

The question: Prepare (|0⟩−|1⟩)/√2 with negative relative sign.

Try it in the program: Use H(q0) followed by Z(q0).

Expected observation: The checker accepts H–Z but rejects H alone, although both show 50/50.

Why it works: State fidelity detects the relative phase difference.

Watch out: Global phase is not observable; relative phase is.

↑ Back to contents

14 — Three qubits in lockstep

ChallengeQubits: 3

The question: Prepare GHZ=(|000⟩+|111⟩)/√2.

Try it in the program: Apply H(q0), CNOT(q0→q1), CNOT(q1→q2).

Expected observation: Only 000 and 111 have 50% probability, with correct phases.

Why it works: GHZ extends coherent entanglement from two to three qubits.

Watch out: Three classical correlations alone do not certify entanglement.

↑ Back to contents

15 — Deutsch: constant function

AlgorithmQubits: 2

The question: Is the function constant or balanced? Here f(0)=f(1)=1.

Try it in the program: Inspect ancilla preparation, the oracle X(q1), and the final H on q0.

Expected observation: The data qubit q0 measures 0 with certainty; q1 does not encode the answer.

Why it works: One query to the reversible oracle identifies the function class.

Watch out: One logical query is not necessarily one physical gate.

↑ Back to contents

16 — Deutsch: balanced function

AlgorithmQubits: 2

The question: Repeat Deutsch with f(x)=x.

Try it in the program: The oracle is CNOT(q0→q1): observe how information reaches the phase.

Expected observation: q0=1 with certainty; the function is balanced.

Why it works: Preparing the ancilla in |−⟩ enables phase kickback.

Watch out: Do not read q1 to classify the function.

↑ Back to contents

17 — Deutsch: different oracle

AlgorithmQubits: 2

The question: Same question, now f(x)=1−x. Does the classification change?

Try it in the program: Compare the oracle gate sequence with lesson 16.

Expected observation: q0 is still 1: this function is also balanced.

Why it works: The output captures a property of the function, not its full truth table.

Watch out: Do not infer that the circuit recovered f(0) and f(1) separately.

↑ Back to contents

18 — Bernstein–Vazirani: 101

AlgorithmQubits: 4

The question: An oracle hides s=101: recover it with one logical call.

Try it in the program: Data qubits are q2,q1,q0; q3 is an ancilla in |−⟩. Inspect the oracle CNOT gates.

Expected observation: The data bits are q2q1q0=101 with 100% probability; q3 may be 0 or 1.

Why it works: Interference extracts the s·x mod 2 parity encoded in phase.

Watch out: Do not expect one unique four-qubit result: the ancilla remains random.

↑ Back to contents

19 — Grover: four possibilities

AlgorithmQubits: 2

The question: Find |10⟩ among four candidates.

Try it in the program: Inspect uniform preparation, phase marking and diffusion.

Expected observation: After one complete iteration P(10)=100% in the ideal case.

Why it works: Diffusion amplifies the marked answer amplitude through interference.

Watch out: Marking alone changes sign, not probability.

↑ Back to contents

20 — Grover: eight, one iteration

AlgorithmQubits: 3

The question: Search for |101⟩ among eight possibilities using one iteration.

Try it in the program: Visit checkpoints: preparation, oracle, diffusion.

Expected observation: P(101) rises from the initial 12.5% to 78.125% after diffusion.

Why it works: High probability is not certainty yet.

Watch out: One ideal query does not guarantee a correct answer on each measurement.

↑ Back to contents

21 — Grover: second iteration

AlgorithmQubits: 3

The question: Repeat oracle+diffusion for the same target |101⟩.

Try it in the program: Compare checkpoints, then use the parametric lab with three iterations.

Expected observation: After two iterations P(101)=94.53125%; after three it falls to about 33.01%.

Why it works: Grover rotates amplitudes: continuing past the optimum causes over-rotation.

Watch out: More iterations do not always mean a higher success probability.

↑ Back to contents

Finished the course?

Now pick an algorithm, change one parameter, and predict the difference before reading the output. If a measurement surprises you, inspect the Notebook and reconstruct the checkpoints.

QuantumLab · Officina Turini · v0.16.0 · EN · UTF-8 · offline