Skip to content
Kartikey Purohit
← Course overview

Sample Papers

Paper 5

Fundamentals of Quantum Computing Using Qiskit v2.X Developer Flavor: primitives-heavy — PUB shapes, broadcasting, options paths, result access.

Questions 34 (half-length paper; real exam is 68)
Time limit 45 minutes (~79 seconds/question)
Passing target 24 / 34 ≈ 69% (mirrors the real 47/68 threshold)
Answer format Single best answer A–D unless a question says "Choose TWO"

Instructions

  1. Assume qiskit 2.x, qiskit-ibm-runtime (V2 primitives), and qiskit-aer are installed; all imports shown are the only ones needed.
  2. Qiskit's little-endian convention applies everywhere: qubit 0 is the rightmost character in bitstrings, Pauli strings, and statevector labels.
  3. Numerical outputs are exact up to floating-point rounding; pick the closest option.
  4. No notes, no interpreter. Time yourself. Answers are in paper-05-answers.md.

Section 1 — Create Quantum Circuits (Q1–Q6)

Q1. What does this code print?

from qiskit import QuantumCircuit
from qiskit.circuit import Parameter
 
a = Parameter('a')
b = Parameter('b')
qc = QuantumCircuit(1)
qc.rx(b, 0)
qc.ry(a, 0)
print([p.name for p in qc.parameters])
  • A. ['b', 'a']
  • B. ['rx', 'ry']
  • C. ['a', 'b']
  • D. It raises an error because two different parameters are bound to the same qubit

Q2. What does this code print?

from qiskit import QuantumCircuit
 
qc1 = QuantumCircuit(2)
qc1.h(0)
qc2 = QuantumCircuit(2)
qc2.cx(0, 1)
qc3 = qc1.compose(qc2)
print(qc3.size(), qc1.size())
  • A. 2 1
  • B. 2 2
  • C. 1 2
  • D. It raises an error because compose requires inplace=True

Q3. Which snippet prepares the 3-qubit GHZ state (|000⟩ + |111⟩)/√2 on a fresh QuantumCircuit(3)?

  • A. qc.h(0); qc.h(1); qc.h(2)
  • B. qc.h(0); qc.cx(0, 1); qc.cx(1, 2)
  • C. qc.h(0); qc.cx(0, 1); qc.cx(0, 1)
  • D. qc.x(0); qc.cx(0, 1); qc.cx(1, 2)

Q4. What counts does this dynamic circuit produce?

from qiskit import QuantumCircuit
from qiskit_aer import AerSimulator
 
qc = QuantumCircuit(2, 2)
qc.x(0)
qc.measure(0, 0)
with qc.if_test((qc.clbits[0], 1)):
    qc.x(1)
qc.measure(1, 1)
counts = AerSimulator().run(qc, shots=1000).result().get_counts()
print(counts)
  • A. {'01': 1000}
  • B. {'10': 1000}
  • C. {'11': 1000}
  • D. Roughly {'01': 500, '11': 500}

Q5. During transpilation with generate_preset_pass_manager(optimization_level=1, backend=backend), which stage is responsible for inserting SWAP gates so that two-qubit gates only act on physically connected qubits?

  • A. Layout
  • B. Routing
  • C. Translation
  • D. Scheduling

Q6. What does this code print?

from qiskit import QuantumCircuit
 
qc = QuantumCircuit(2)
qc.h(0)
qc.cx(0, 1)
inv = qc.inverse()
print([inst.operation.name for inst in inv.data])
  • A. ['h', 'cx']
  • B. ['cx', 'h']
  • C. ['cxdg', 'hdg']
  • D. It raises an error because CX has no inverse method

Section 2 — Perform Quantum Operations (Q7–Q12)

Q7. What does this code print?

from qiskit.quantum_info import Pauli, Statevector
 
sv = Statevector.from_label('01')
print(sv.expectation_value(Pauli('IZ')))
  • A. -1.0
  • B. 1.0
  • C. 0.0
  • D. -1j

Q8. What does this code print?

from qiskit.quantum_info import SparsePauliOp
 
op = SparsePauliOp.from_sparse_list([("ZX", [3, 1], 2.0)], num_qubits=4)
print(op.paulis)
  • A. ['ZXII']
  • B. ['IXIZ']
  • C. ['IZIX']
  • D. ['ZIXI']

Q9. What does this code print?

from qiskit import QuantumCircuit
from qiskit.quantum_info import Operator, Pauli
 
qc = QuantumCircuit(1)
qc.h(0)
qc.x(0)
qc.h(0)
print(Operator(qc).equiv(Operator(Pauli('Z'))))
  • A. True
  • B. False
  • C. Z
  • D. It raises an error because a Pauli cannot be converted to an Operator

Q10. You need the observable H = 2·(Z on qubit 1)⊗(Z on qubit 0) + 1·(X on qubit 1) for a 2-qubit Estimator run. Which construction is correct?

  • A. SparsePauliOp.from_list([("ZZ", 2.0), ("IX", 1.0)])
  • B. Pauli("2ZZ + XI")
  • C. SparsePauliOp.from_list([("ZZ", 2.0), ("XI", 1.0)])
  • D. SparsePauliOp(["ZZ", "XI"], coeffs=[1.0, 2.0])

Q11. In the Pauli string Pauli('XYZ'), which qubit does the Z operator act on?

  • A. Qubit 0
  • B. Qubit 2
  • C. Qubit 1
  • D. All three qubits, because a Pauli string is a tensor product

Q12. What does this code print?

from qiskit import QuantumCircuit
from qiskit.quantum_info import Statevector
 
qc = QuantumCircuit(2)
qc.h(0)
qc.cx(0, 1)
qc.x(1)
print(Statevector.from_instruction(qc).probabilities_dict())
  • A. {'00': 0.5, '11': 0.5}
  • B. {'11': 1.0}
  • C. {'00': 0.25, '01': 0.25, '10': 0.25, '11': 0.25}
  • D. {'01': 0.5, '10': 0.5}

Section 3 — Run Quantum Circuits (Q13–Q17)

Q13. You are running a VQE-style algorithm where each Estimator job's parameters depend on the result of the previous job, and you want to avoid re-queuing between iterations. Which execution mode fits best?

  • A. Job mode — each request queues independently
  • B. Session mode — a dedicated access window for iterative workloads
  • C. Batch mode — parallel scheduling of independent jobs
  • D. Local mode — hardware iteration is only possible on simulators

Q14. Which snippet correctly creates a Sampler inside a session?

  • A. ```python with Session(backend=backend) as session: sampler = SamplerV2(mode=session)
  • B. ```python session = Session(backend=backend) sampler = SamplerV2(session.run())
  • C. ```python sampler = SamplerV2(backend=backend, session=True)
  • D. ```python with Session(backend=backend) as session: sampler = session.sampler(resilience_level=1)

Q15. A user builds a circuit with h and cx gates and submits it directly to EstimatorV2(mode=backend) on real IBM hardware without transpiling. What happens?

  • A. The service transpiles it automatically before running
  • B. It runs, but with a warning about degraded fidelity
  • C. The job is rejected with an error — V2 primitives require ISA circuits
  • D. It runs only if optimization_level=0 is set in the options

Q16. What does this code print?

from qiskit import QuantumCircuit
from qiskit.primitives import StatevectorSampler
 
qc = QuantumCircuit(2, 2)
qc.x(1)
qc.measure([0, 1], [0, 1])
job = StatevectorSampler().run([(qc, None, 200)])
print(job.result()[0].data.c.get_counts())
  • A. {'01': 200}
  • B. {'10': 200}
  • C. {'1': 200}
  • D. Roughly {'00': 100, '10': 100}

Q17. Which call returns the least busy real (non-simulator) operational backend from service = QiskitRuntimeService()?

  • A. service.backend(busy=False)
  • B. service.backends(sort='queue')[0]
  • C. least_busy(service.backends())
  • D. service.least_busy(operational=True, simulator=False)

Section 4 — Use the Sampler Primitive (Q18–Q21)

Q18. What does this code print?

from qiskit import QuantumCircuit
from qiskit.primitives import StatevectorSampler
 
qc = QuantumCircuit(3)
qc.x(0)
qc.measure_all()
result = StatevectorSampler().run([qc], shots=100).result()
data = result[0].data.meas
print(data.num_shots, data.num_bits, data.get_counts())
  • A. 100 3 {'001': 100}
  • B. 100 3 {'100': 100}
  • C. 3 100 {'001': 100}
  • D. 100 1 {'1': 100}

Q19. A circuit qc has two parameters, and you want the Sampler to run it for three different parameter sets in a single PUB. Which PUB is correctly shaped?

  • A. (qc, [0.1, 0.2, 0.3])
  • B. [(qc, [0.1, 0.2]), (qc, [0.3, 0.4]), (qc, [0.5, 0.6])] passed as one PUB
  • C. (qc, [[0.1, 0.2], [0.3, 0.4], [0.5, 0.6]])
  • D. (qc, {0: [0.1, 0.2, 0.3], 1: [0.4, 0.5, 0.6]})

Q20. (Choose TWO.) Which of these are valid option settings on a SamplerV2 from qiskit_ibm_runtime?

  • A. sampler.options.dynamical_decoupling.enable = True
  • B. sampler.options.resilience_level = 2
  • C. sampler.options.default_shots = 4096
  • D. sampler.options.resilience.zne_mitigation = True

Q21. What does this code print?

from qiskit import QuantumCircuit, QuantumRegister, ClassicalRegister
from qiskit.primitives import StatevectorSampler
 
q = QuantumRegister(2)
c1 = ClassicalRegister(1, 'alpha')
c2 = ClassicalRegister(1, 'beta')
qc = QuantumCircuit(q, c1, c2)
qc.x(0)
qc.measure(0, c1[0])
qc.measure(1, c2[0])
r = StatevectorSampler().run([qc], shots=50).result()[0]
print(r.data.alpha.get_counts(), r.data.beta.get_counts())
  • A. {'01': 50} — the registers are merged into one field
  • B. {'1': 50} {'0': 50}
  • C. {'0': 50} {'1': 50}
  • D. It raises an error — Sampler results only expose .data.meas

Section 5 — Use the Estimator Primitive (Q22–Q25)

Q22. What does this code print?

from qiskit import QuantumCircuit
from qiskit.primitives import StatevectorEstimator
from qiskit.quantum_info import SparsePauliOp
 
qc = QuantumCircuit(2)
qc.h(0)
qc.cx(0, 1)
obs = [SparsePauliOp('ZZ'), SparsePauliOp('XX'), SparsePauliOp('IZ')]
result = StatevectorEstimator().run([(qc, obs)]).result()
print(result[0].data.evs)
  • A. [1. 1. 0.]
  • B. [0. 0. 1.]
  • C. [1. 0. 0.]
  • D. It raises an error — one PUB may contain only one observable

Q23. What does this code print?

import numpy as np
from qiskit import QuantumCircuit
from qiskit.circuit import Parameter
from qiskit.primitives import StatevectorEstimator
from qiskit.quantum_info import SparsePauliOp
 
theta = Parameter('t')
qc = QuantumCircuit(1)
qc.ry(theta, 0)
obs = SparsePauliOp('Z')
result = StatevectorEstimator().run([(qc, obs, [[0.0], [np.pi]])]).result()
print(result[0].data.evs)
  • A. [-1. 1.]
  • B. [ 1. -1.]
  • C. 1.0 — only the first parameter set is used
  • D. It raises an error — two parameter sets require two separate PUBs

Q24. You transpile qc to isa_qc = pm.run(qc) for a 127-qubit backend. Your observable obs was built for the original 2-qubit circuit. What is the correct way to run the Estimator?

  • A. estimator.run([(qc, obs)]) — use the untranspiled circuit so the qubit counts match
  • B. estimator.run([(isa_qc, obs)]) — the Estimator expands observables automatically
  • C. estimator.run([(isa_qc, obs.apply_layout(isa_qc.layout))])
  • D. estimator.run([(isa_qc.apply_layout(obs), obs)])

Q25. With qiskit_ibm_runtime's EstimatorV2, setting options.resilience_level = 2 enables which technique on top of the level-1 defaults?

  • A. Dynamical decoupling
  • B. Zero-noise extrapolation (ZNE)
  • C. Probabilistic error cancellation (PEC)
  • D. Measurement twirling

Section 6 — Visualize Circuits, Measurements, and States (Q26–Q29)

Q26. Which text drawing does this code produce?

from qiskit import QuantumCircuit
 
qc = QuantumCircuit(2)
qc.h(0)
qc.z(0)
qc.cx(0, 1)
print(qc.draw('text'))
  • A. ```text ┌───┐┌───┐┌───┐ q_0: ┤ H ├┤ Z ├┤ X ├ └───┘└───┘└─┬─┘ q_1: ────────────■──
  • B. ```text ┌───┐┌───┐
    q_0: ┤ H ├┤ Z ├──■── └───┘└───┘┌─┴─┐ q_1: ──────────┤ X ├ └───┘
  • C. ```text ┌───┐ q_0: ──────────┤ X ├ ┌───┐┌───┐└─┬─┘ q_1: ┤ H ├┤ Z ├──■── └───┘└───┘
  • D. ```text ┌───┐┌───┐
    q_0: ┤ Z ├┤ H ├──■── └───┘└───┘┌─┴─┐ q_1: ──────────┤ X ├ └───┘

Q27. You call plot_bloch_multivector(Statevector.from_instruction(bell)) where bell is the standard H+CX Bell circuit. What do the two Bloch spheres show?

  • A. q0 pointing +X and q1 pointing +Z
  • B. Both qubits pointing +X
  • C. Both vectors with zero length (at the center of each sphere)
  • D. Both qubits pointing −Z

Q28. On a plot_state_qsphere diagram, what does the color of a blob encode?

  • A. The magnitude of the amplitude
  • B. The probability of that basis state
  • C. The number of 1-bits in the basis state label
  • D. The phase of the amplitude

Q29. plot_histogram(counts, number_to_keep=2) is called with counts over five distinct bitstrings. What is displayed?

  • A. The 2 most frequent bitstrings, with everything else aggregated into a "rest" bar
  • B. Only the first 2 bitstrings in alphabetical order; the others are dropped
  • C. An error — number_to_keep must be at least the number of keys
  • D. All 5 bars, but only 2 are labeled

Section 7 — Retrieve and Analyze Results (Q30–Q32)

Q30. You submitted a Runtime job yesterday and saved its job ID. Which snippet retrieves its result in a new Python session?

  • A. job = SamplerV2.load(job_id); job.result()
  • B. result = QiskitRuntimeService.result(job_id)
  • C. service = QiskitRuntimeService(); job = service.job(job_id); result = job.result()
  • D. job = Session.retrieve(job_id); result = job.result()

Q31. A single-qubit circuit measured in the computational basis returns {'0': 600, '1': 400} over 1000 shots. What is the estimate of ⟨Z⟩ computed from these counts?

  • A. 0.6
  • B. 0.2
  • C. −0.2
  • D. 0.4

Q32. An Estimator run at 4096 shots gives a standard error of 0.02 on an expectation value. Approximately how many shots are needed to reduce the standard error to 0.01?

  • A. 8192 — double the shots
  • B. 6144 — 1.5× the shots
  • C. 2048 — precision improves as shots decrease
  • D. 16384 — four times the shots

Section 8 — Operate with OpenQASM (Q33–Q34)

Q33. You receive a program string that begins with OPENQASM 3.0;. Which function turns it into a QuantumCircuit?

  • A. QuantumCircuit.from_qasm_str(program)
  • B. qiskit.qasm3.loads(program)
  • C. qiskit.qasm3.load(program)
  • D. qiskit.qasm2.loads(program)

Q34. qasm3.dumps(qc) is called on a 2-qubit Bell circuit with qc.measure([0, 1], [0, 1]) into a default 2-bit classical register. Which lines appear in the output?

  • A. qreg q[2]; creg c[2]; ... measure q -> c;
  • B. qubit[2] q; bit[2] c; ... measure q[0] -> c[0];
  • C. bit[2] c; qubit[2] q; ... c[0] = measure q[0];
  • D. input bit[2] c; qubit[2] q; ... c = sample q;

End of Paper 05. Check your work against paper-05-answers.md.