Quiz: Microsoft Q
Answers with explanations at the end.
1. What is the current import for Q# from Python, and why is neither import qsharp nor
import qdk alone correct?
2. State three differences between a Q# function and an operation.
3. function F() : Unit { use q = Qubit(); H(q); } is rejected. What is the diagnostic, and why is
this restriction useful in a hybrid quantum program?
4. M(q) returns a Result, not a Bool or Int. What class of bug does that prevent?
5. What does use (a, b) = (Qubit(), Qubit()) do, and what obligation does it create?
6. An operation ends with a qubit in $|1\rangle$. What happens, and at what stage — compile time or run time?
7. Why does a dirty qubit returned to the pool produce an especially bad kind of bug?
8. Q# accepts an operation that measures a qubit, skips the reset, applies H, measures again, and
resets only at the end. Explain why the release discipline does not catch this, and state the general
principle.
9. What does is Adj + Ctl declare, and what does the compiler do with it?
10. Write the identity that makes automatic adjoint generation possible.
11. Declaring is Adj on an operation containing a measurement is rejected. Is this a design
limitation or a mathematical necessity? Explain.
12. Why can the compiler's generated inverse never drift out of sync with the operation, while a hand-written one can?
13. A two-qubit circuit with H, CNOT, and three T gates requires 12,642 physical qubits, of
which 882 run the algorithm. What are the other 11,760 doing?
14. Zero T gates costs 450 physical qubits; one T gate costs 2,882. Explain the jump in terms
of how the two gate classes are implemented under error correction.
15. Connect the answer to question 14 to Chapter 11's Gottesman–Knill theorem in one sentence.
16. At 30 and 100 T gates the physical qubit count is identical (98,658) while runtime grows from
111.6 μs to 363.6 μs. What is the estimator doing?
17. The same circuit needs 4,882 physical qubits at a $10^{-3}$ error rate and 180 at $10^{-4}$. Explain the factor of 27, and state the practical implication for hardware roadmaps.
18. Case Study 1 found T factories were 93% of a small circuit's machine but only 3% of RSA-2048's. Both are correct. Explain, and state the general lesson.
19. RSA-2048 needs 6,189 logical qubits and roughly 25 million physical ones. Which number do people usually quote, and why does the confusion matter?
20. Case Study 2 scored twelve of this book's real bugs against the Q# compiler: three caught, one made impossible, eight missed. What do the eight missed bugs have in common?
Answers
1. from qdk import qsharp. The standalone qsharp package is deprecated (it warns on
import), and the top-level qdk module does not re-export eval, run, or estimate — those
live in the qdk.qsharp submodule. qdk is an umbrella package that also carries qdk.qiskit,
qdk.cirq, and qdk.azure.
2. A function cannot allocate qubits, cannot call quantum operations, and is
deterministic. An operation can do all three and is not. The purpose is that a hybrid program's
classical and quantum halves become distinguishable by declaration.
3. Qdk.Qsc.CallableLimits.QubitAlloc — functions cannot allocate qubits. It is useful because a
hybrid quantum program is mostly classical code, and being able to see at a glance which parts can
possibly have quantum side effects makes the whole program easier to reason about — Chapter 24's
variational loop is exactly this shape.
4. Arithmetic on measurement outcomes. In Python a measurement result is an int or a string, so
adding, summing, or indexing with it is silently legal; in Q# Result is a distinct type with values
Zero and One, and you must convert explicitly.
5. It allocates two qubits for the enclosing scope, borrowed from a shared pool. The obligation is that they must be back in $|0\rangle$ when the scope ends.
6. A runtime error — Qubit0 released while not in |0⟩ state,
Qdk.Qsc.Eval.ReleasedQubitNotZero, with a call stack. Not compile time: the compiler cannot in
general know the state a qubit will be in.
7. Because the failure appears in a different part of the program from its cause. The next operation to allocate that qubit is entitled to assume $|0\rangle$; it gets something else and produces a wrong answer, with nothing in its own code responsible.
8. The release discipline checks the state at scope exit, and the qubit is reset before the block ends — so the contract is satisfied while the algorithm is still wrong. The general principle: a guarantee is only as broad as its statement. Read what a checker actually promises rather than what it seems to imply.
9. It declares that the operation has an adjoint and a controlled variant and that the compiler
may generate them. The compiler then does generate Adjoint Op, Controlled Op, and
Adjoint Controlled Op from the body — and verifies the body is actually reversible.
10. $(U_1 U_2 \cdots U_n)^\dagger = U_n^\dagger \cdots U_2^\dagger U_1^\dagger$ — reverse the sequence and adjoint each element. Since every primitive knows its own inverse, the transformation is mechanical.
11. A mathematical necessity. Measurement is irreversible — it destroys information — so an
operation containing one has no adjoint to generate. Q# rejects it
(Qdk.Qsc.LogicSeparation.OpCallForbidden), which means is Adj functions as a proof obligation
the compiler discharges, not merely an annotation.
12. Because it is derived from the definition at compile time. Change the operation and the inverse is regenerated automatically. A hand-written inverse is a second piece of code that must be updated in parallel, and nothing enforces that it was.
13. Manufacturing magic states. They are T factories — the distillation hardware that consumes
many noisy states to produce the clean $|T\rangle$ states each T gate consumes. 93% of that machine
is not running the algorithm.
14. Clifford gates can be applied transversally — directly on the encoded logical qubits, with
no extra machinery. T gates cannot, and require magic state distillation, which means building
at least one factory. The first T gate pays the entire cost of standing up that infrastructure.
15. Gottesman–Knill says Clifford circuits are classically simulable in polynomial time — so they give no quantum advantage — and the resource estimator shows the same boundary from the hardware side: the gates that make a quantum computer worth building are exactly the gates that make it enormous.
16. Trading time for space. It has stopped buying additional factories at 15 and started reusing them serially, running the same distillation hardware repeatedly instead of building more. Which side of the trade you want depends on whether you are constrained by qubit count or by coherence.
17. To reach a target logical error rate you need a code distance $d$ that grows as the physical error rate approaches the threshold, and a surface-code patch costs $O(d^2)$ qubits — so the qubit count depends quadratically on the distance. Practical implication: improving fidelity beats adding qubits. A roadmap promising a million qubits at $10^{-3}$ is a worse road to useful computation than one promising a hundred thousand at $10^{-5}$.
18. A T factory is a fixed-size piece of hardware producing magic states at some rate. For a small circuit (882 physical qubits of algorithm) even one factory at 2,000 qubits dominates. For RSA-2048 (~24 million qubits of algorithm, running a day and a half) a modest number of factories, continuously reused, keeps up. Long runtimes amortize factories; large registers dwarf them. General lesson: a measurement taken at one scale is evidence about that scale.
19. People usually quote the logical count (~6,000, often rounded to "about 4,000 qubits"), and hear it as a hardware requirement. The physical count is about four thousand times larger. The confusion matters because it makes the milestone sound imminent when the actual gap to today's ~1,000-physical-qubit devices is four to five orders of magnitude.
20. Every one is a well-typed program that does the wrong thing — an error of correspondence rather than of form. A dead qubit is type-correct; an endianness mistranslation is well-typed on both sides; a DD pass that inserts four gates where no idle time exists returns a perfectly valid circuit. Type systems constrain what you can write and say nothing about whether what you wrote matches reality, because they have no access to reality.