Self-Assessment Quiz: OpenQASM

Twenty questions on the format, the API, and what serialization costs you. Aim for 16 or more.


Question 1

OpenQASM's closest classical analogue is: - A. Python source code - B. an intermediate representation such as LLVM IR, or assembly - C. a binary executable - D. a configuration file

Question 2

The main structural reason a shared IR exists is: - A. it is faster - B. it turns an $N \times M$ problem (every framework × every device) into $N + M$ - C. it uses less memory - D. hardware vendors require it legally

Question 3

Which line declares two qubits in OpenQASM 3? - A. qreg q[2]; - B. qubit[2] q; - C. qubits q = 2; - D. register q(2);

Question 4

Measurement in OpenQASM 3 is written: - A. measure q[0] -> c[0]; - B. c[0] = measure q[0]; - C. read q[0] into c[0]; - D. c[0] <- q[0];

Question 5

Which function replaced qc.qasm() for OpenQASM 3? - A. qc.to_qasm3() - B. qasm3.dumps(qc) - C. qc.export("qasm3") - D. qasm3.serialize(qc)

Question 6

qasm3.load() expects: - A. an open file object - B. a filename or path - C. a string containing QASM - D. a QuantumCircuit

Question 7

In transpiled QASM, $0 means: - A. a classical bit - B. a physical qubit on the device - C. a parameter placeholder - D. a comment

Question 8

A gate ecr a, b { ... } block appearing at the top of transpiled QASM is there because: - A. the circuit uses a custom user gate - B. ecr is not in stdgates.inc, so the exporter defines it in standard terms - C. it is a compiler error - D. all gates must be redefined

Question 9

In the transpiled Bell circuit, seven rz gates appear. Their cost on superconducting hardware is: - A. the largest contribution to the circuit's error - B. zero — rz is virtual, implemented as a phase-reference shift - C. about the same as an sx - D. unknown without calibration data

Question 10

Which of these can OpenQASM 2 not represent? - A. a Bell state - B. a circuit with unbound free parameters - C. a measurement - D. a three-qubit register

Question 11

Which can OpenQASM 2 not represent? - A. a Hadamard gate - B. general classical control flow such as if (c[0]) { x q[1]; } - C. a CNOT - D. a classical register

Question 12

A QASM 3 round trip silently discards: - A. the gate sequence - B. the global phase - C. the qubit count - D. measurements

Question 13

That loss matters most when the circuit is later: - A. simulated - B. used as a controlled operation - C. drawn - D. measured

Question 14

Operator(a).equiv(Operator(b)) after a phase-losing round trip returns: - A. False, correctly flagging the problem - B. True, because equiv compares up to global phase by design - C. an error - D. None

Question 15

A ParameterVector named theta exports its first element as: - A. theta[0] - B. _theta_0_ - C. theta0 - D. param0

Question 16

That renaming happens because: - A. Qiskit prefers underscores - B. [ and ] are not legal characters in an OpenQASM identifier - C. QASM 3 does not support parameters - D. it is a bug

Question 17

The recommended way to match original parameter names to mangled ones is: - A. reproduce the exporter's mangling rule exactly - B. normalize both sides by stripping non-alphanumeric characters and compare - C. match by position in the file - D. it cannot be done

Question 18

Compared with QASM, Qiskit's QPY format is: - A. cross-framework and human-readable - B. Qiskit-specific and version-sensitive, but preserves every detail - C. slower but otherwise identical - D. deprecated

Question 19

For maximum cross-framework compatibility you should generally export: - A. QASM 2, unless you need a QASM 3 feature - B. QASM 3 always - C. QPY - D. a pickled circuit

Question 20

Diffing the QASM of a circuit transpiled at two optimization levels gives you: - A. nothing useful - B. a precise record of every decision the optimizer made - C. the device's error rates - D. the measurement outcomes


Answers

# Answer Why
1 B An intermediate representation with a specification. §6.1
2 B The same argument that produced LLVM IR. §6.1
3 B QASM 3 uses qubit[n] name; qreg is QASM 2. §6.2
4 B An assignment — which is what makes classical control possible. §6.2
5 B qc.qasm() was removed in Qiskit 1.0. §6.3
6 B And dump takes a stream — the asymmetry catches everyone. §6.3 pitfall
7 B The transpiler's layout decision, written down. §6.5
8 B A hardware-native gate in a vocabulary you know. §6.5
9 B Four sx and one ecr are the real cost; the rest is bookkeeping. §6.5
10 B QASM2ExportError — decisive for variational work. §6.4
11 B QASM 2 supports register-equality conditions only. §6.4
12 B Silently, with no warning. §6.6
13 B Global becomes relative under control — phase kickback. §6.6
14 B Which is why an equiv-based round-trip test cannot catch it. §6.6
15 B Verified in §6.6.
16 B Brackets are illegal in an identifier. §6.6
17 B The exact mangling rule is an implementation detail that changes. §6.6 pitfall
18 B Use QASM to communicate; QPY to checkpoint. §6.6
19 A Uniform support beats newest syntax. §6.8
20 B A technique Chapter 10 uses constantly. §6.5

Topic Map

Questions Topic Section If you missed these
1, 2 Why an IR exists §6.1 The $N\times M \to N+M$ argument is the whole justification
3, 4 QASM 3 syntax §6.2 Write the GHZ state by hand — Exercise 6.7
5, 6 The API §6.3 The dump/load asymmetry will catch you once; make it now
7, 8, 9, 20 Reading transpiled QASM §6.5 The payoff of the chapter. Do Exercises 6.9 and 6.10
10, 11 QASM 2's limits §6.4, §6.7 Parameters and control flow decide the format
12, 13, 14 The global-phase loss §6.6 Do Exercise 6.15 — seeing the answer invert is worth more than reading it
15, 16, 17 Parameter mangling §6.6 Normalize; do not reproduce the mangling rule
18, 19 QASM vs. QPY, interchange §6.6, §6.8 Save both. Storage is free; an unreconstructable circuit is not

Score 16+: Part I is done. Go to Chapter 7.

Score 12–15: if you lost points on 7–9 or 20, reread §6.5 and run code/example-02-reading-transpiled-qasm.py against your own circuits — that skill is used from Chapter 10 onward. The serialization-loss cluster (12–17) can wait until you archive something.

Score under 12: the syntax details are reference. The two things to carry into Part II are: QASM is where you see what the transpiler actually did, and a round trip is lossy in two specific ways.