Skip to article frontmatterSkip to article content

Sample Test

Quantum Tokyo

This is a sample test provided in the official page of “IBM Certified Quantum Computation using Qiskit v2.X Developer - Associate”.

Section 1: Perform quantum operations

1. Which one of the following code fragments will generate the given output?

[[ 1.+0.j 0.+0.j 0.+0.j 0.+0.j]
[ 0.+0.j -1.+0.j 0.+0.j 0.+0.j]
[ 0.+0.j 0.+0.j 1.+0.j 0.+0.j]
[ 0.+0.j 0.+0.j 0.+0.j -1.+0.j]]

a. p = Pauli('IZ') print(p.to_matrix())
b. p = Pauli('-II') print(p.to_matrix())
c. p = Pauli('-ZI') print(p.to_matrix())
d. p = Pauli('ZZ') print(p.to_matrix())

Answer

The answer is a.

Pauli('IZ') corresponds to IZI \otimes Z. Since Z=diag(1,1)Z=\mathrm{diag}(1,-1) and I=diag(1,1)I=\mathrm{diag}(1,1), we get

IZ=diag(1,1,1,1),I\otimes Z=\mathrm{diag}(1,-1,1,-1),

which matches the given matrix.

b:'-II'II=diag(1,1,1,1)-I\otimes I=\mathrm{diag}(-1,-1,-1,-1)
c:'-ZI'ZI=diag(1,1,1,1)-Z\otimes I=\mathrm{diag}(-1,-1,1,1)
d: 'ZZ'ZZ=diag(1,1,1,1)Z\otimes Z=\mathrm{diag}(1,-1,-1,1)

2. Applying the Qiskit TGate to a qubit in state |1> introduces which global phase?

a. π/2 phase
b. -π/2 phase
c. -π/4 phase
d. π/4 phase

Answer

The answer is d.
T gate induces a π/4 phase.

T=[100eiπ/4]T = \begin{bmatrix} 1 & 0 \\ 0 & e^{i\pi/4} \end{bmatrix}

3. Given the following code fragment, what is the approximate probability that a measurement would result in a bit value of 1?

from qiskit import QuantumCircuit
import numpy as np

qc = QuantumCircuit(1)
qc.reset(0)
qc.ry(np.pi / 2, 0)
qc.measure_all()

a. 0.8536
b. 1.0
c. 0.1464
d. 0.5

Answer

The answer is d.

On the Bloch sphere, the state 0|0\rangle is at the north pole.
The operation Ry(π/2)R_y(\pi/2) rotates the state vector by 90° around the y-axis.
This moves the vector from the north pole to a point on the equator of the Bloch sphere.

On the equator, the probabilities of measuring 0|0\rangle and 1|1\rangle are equal.
Thus, the probability of getting 1|1\rangle is:

P(1)=12P(1) = \tfrac{1}{2}

Section 2: Visualize quantum circuits, measurements, and states

4. Which one of the following images is the output from the code below:

from qiskit import *
qubits = QuantumRegister(2)
clbits = ClassicalRegister(2)
circuit = QuantumCircuit(qubits, clbits)
(q0, q1) = qubits
(c0, c1) = clbits

circuit.h(q0)
circuit.measure(q0, c0)
with circuit.if_test((c0, 1)) as else_:
circuit.h(q1)
with else_:
circuit.x(q1)
circuit.measure(q1, c1)

circuit.draw(output="mpl")
Answer

The answer is a.

5. Given the code fragment below, which image is the expected output?

from qiskit.quantum_info import Statevector
from qiskit.visualization import plot_histogram
state = Statevector([0.+0.j, 0.+0.j, 0.70710678+0.j, 0.+0.j,
                    0.+0.j, -0.70710678+0.j, 0.+0.j, 0.+0.j])
counts = state.sample_counts(shots=1024)
plot_histogram(counts)
Answer

The answer is c.

What is a Statevector?

In Qiskit, a Statevector represents the quantum state of an nn-qubit system as a complex vector of length 2n2^n. Each entry corresponds to the amplitude of one computational basis state (e.g., 000,001,,111|000\rangle, |001\rangle, …, |111\rangle). The squared magnitude of each amplitude gives the probability of measuring that basis state.

Ordering of the List

The list follows lexicographic ordering of basis states, where the index of the list corresponds to the integer value of the basis bitstring:

  • Index ii → basis state i|i\rangle, written in binary.
  • Qubit 0 is the least significant bit (rightmost), and qubit n1n-1 is the most significant bit (leftmost).

Thus, for 3 qubits:

  • index 0 → 000|000\rangle
  • index 1 → 001|001\rangle
  • index 7 → 111|111\rangle.

6. Which one of the following code fragments will generate the given qsphere representation visualization? Note: the circles on the qsphere are the same color.

a.

qc = QuantumCircuit(2)
qc.h(0)
qc.z(0)
qc.cx(0, 1)
state = Statevector(qc)
plot_state_qsphere(state)

b.

qc = QuantumCircuit(2)
qc.h(0)
qc.z(0)
qc.x(1)
qc.cx(0, 1)
state = Statevector(qc)
plot_state_qsphere(state)

c.

qc = QuantumCircuit(2)
qc.x(1)
qc.h(0)
qc.cx(0, 1)
state = Statevector(qc)
plot_state_qsphere(state)

d.

qc = QuantumCircuit(2)
qc.h(0)
qc.cx(0, 1)
state = Statevector(qc)
plot_state_qsphere(state)
Answer

The answer is d.

Section 3: Create quantum circuits

7. Given the code fragment below, which of the following code fragments creates a rotation gate with an angle with an initially undefined value?

from qiskit.circuit import QuantumCircuit, Parameter,
ParameterExpression
qc = QuantumCircuit(1)

a.

theta = 3.14
qc.rx(3.14, 0)

b.

theta = Parameter('theta')
qc.rx(theta, 0)

c.

qc.rx('theta', 0)

d.

qc.rx(ParameterExpression('theta'), 0)
Answer

The answer is b.

Parameter('theta') creates a symbolic parameter, which represents an angle with an initially undefined value that can be assigned later when executing the circuit.

8. Which one of the following types of register stores the result of a measured circuit?

a. Ancillary register
b. Quantum register
c. Classical register
d. Circuit register

Answer

The answer is c.

  • a. Ancillary register → Used as extra helper qubits, not for storing measurement results.
  • b. Quantum register → Holds qubits, which collapse after measurement, so results are not stored here.
  • c. Classical register → Stores the outcomes of measurements as classical bits.
  • d. Circuit register → Not an actual register type in Qiskit.

9. Given the code fragment below, which one of the following images could be produced?

from qiskit import QuantumCircuit
from qiskit import generate_preset_pass_manager

qc = QuantumCircuit(2)
qc.h(0)
qc.cx(0,1)

pass_manager = generate_preset_pass_manager(
 optimization_level=3,
 coupling_map=[[0, 1], [1, 2]] ,
 basis_gates=['h', 'swap', 'cx'],
 initial_layout=[0, 2]
)
tqc = pass_manager.run(qc)
tqc.draw(output="mpl")
Answer

The answer is a.

Here are concise descriptions of the parameters in qiskit.transpiler.generate_preset_pass_manager

ParameterWhat it is / PurposeValid options / behavior
optimization_levelDetermines how much optimization/transformation effort is applied when transpiling a circuit. Higher levels produce more optimized circuits but take more time.Integer: 0, 1, 2, or 3.
• 0 = no optimization
• 1 = light optimization
• 2 = heavy optimization (default)
• 3 = even heavier optimization
coupling_mapThe connectivity constraints of the quantum processor: which qubits can directly interact (two-qubit gates). The transpiler uses this to route gates correctly.Can be a CouplingMap object, or a list of edges. For example: [[0,1], [0,3], [1,2], …]. Directed (or undirected) depending on backend.
basis_gatesThe set of primitive gates that gates must be decomposed into (“unrolled” to) so they match the backend’s capabilities.A list of gate names, e.g. ['u1','u2','u3','cx']. If not provided, backend or target may set a default.
initial_layoutHow virtual (logical) qubits are mapped initially onto physical qubits before any routing/swaps. Useful to reduce routing overhead.Can be a Layout object or a simple list of integers. The list should map logical qubits to physical qubit indices. If not provided, layout method (like ‘trivial’, ‘dense’, ‘sabre’) will choose.

Section 4: Run quantum circuits

10. Which three of the following are job execution modes in Qiskit Runtime?

a. classical
b. session
c. parallel
d. quantum
e. batch
f. single job

Answer

The answer is b, e, f.

There are three execution modes: job, session, and batch.

Job mode

A single primitive request of the estimator or the sampler made without a context manager. Circuits and inputs are packaged as primitive unified blocs (PUBs) and submitted as an execution task on the quantum computer.

Batch mode

A multi-job manager for efficiently running experiments comprising multi-job workloads. These workloads are made up of independently executable jobs that have no conditional relationship with each other. With batch mode, users submit their jobs all at once. The system parallelizes or threads the pre-processing step of each primitive job to more tightly package quantum execution across jobs, and then runs the quantum execution of each job in quick succession to deliver the most efficient results.

Session mode

A dedicated window for running a multi-job workload. During this window, the user has exclusive access of the system and no other jobs can run - including calibration jobs. This allows users to experiment with variational algorithms in a more predictable way and even run multiple experiments simultaneously, taking advantage of parallelism in the stack. Using sessions helps avoid delays caused by queuing each job separately, which can be particularly useful for iterative tasks that require frequent communication between classical and quantum resources.

Workloads on the Open Plan can run only in job mode or batch mode.

11. Which code fragment is the correct way to open a session?

a.

from qiskit_ibm_runtime import Session
session = Session(system='ibm_foo')

b.

from qiskit_ibm_runtime import execute, QiskitRuntimeService
service = QiskitRuntimeService()
session = execute(service=service)

c.

from qiskit_ibm_runtime import Session, QiskitRuntimeService
service = QiskitRuntimeService()
session = Session(service.least_busy())

d.

from qiskit import QuantumCircuit
session = QuantumCircuit(2).open_session()
Answer

The answer is c.

See the document “Run jobs in a session”

12. Which one of the following patterns, expressed in terms of array broadcasting primitives, is represented by the given image?

a. Standard multidimensional array generalization
b. All-to-all
c. Extended dimensional variation
d. Best effort broadcasting

Answer

The answer is a.

An array broadcasting primitive is a fundamental operation that allows arrays of different shapes to participate in element-wise operations by automatically expanding dimensions without copying data.

  • It aligns array shapes according to broadcasting rules (match or size-1).
  • It enables efficient, memory-safe, multidimensional computations.
  • In Qiskit, this is used to combine parameter sweeps with observables into expectation value arrays.

a. Standard multidimensional array generalization ✅

  • This exactly matches the NumPy-style broadcasting rule: expand size-1 dimensions to align arrays.
  • The example (3,6) + (2,3,1)(2,3,6) is a textbook case.

b. All-to-all ❌

  • Would imply computing every combination in a Cartesian product sense.
  • Not the case here: dimensions are aligned, not cross-multiplied.

c. Extended dimensional variation ❌

  • Sounds like adding extra dimensions, but it’s not the standard term.
  • The process shown is standard broadcasting, not a special variation.

d. Best effort broadcasting ❌

  • Suggests a heuristic or partial match when rules fail.
  • Here, broadcasting succeeds cleanly under standard rules, no “best effort” needed.

Section 5: Use the sampler primitive

13. Given the following code fragment, which one of the following describes the SamplerOptions parameter options.default_shots?

...
from qiskit_ibm_runtime import Sampler
sampler = Sampler(mode=backend)
sampler.options.default_shots = ...

a. The sum of the number of measurements in each qubit
b. The number of randomizations we apply to the circuit
c. The number of times that we run the circuit
d. The number of sequences in dynamical decoupling

Answer

The answer is c.

Here is the documentation of SamplerOptions.

The default number of shots to use if none are specified in the PUBs or in the run method.

14. Given the code snippet, which one of the following is a valid way to invoke the run method on an instance of SamplerV2?

from qiskit_ibm_runtime import SamplerV2
...
sampler = SamplerV2(...)

a. sampler.run([isa_circuit])
b. sampler.run(distribution, isa_circuit)
c. sampler.run(isa_circuit, distribution='gauss')
d. sampler.run([isa_circuit1, isa_circuit2], runs=1024)

Answer

The answer is a.

Here is the documentation of SamplerV2.

Parameters

  • pubs (Iterable[SamplerPubLike]) – An iterable of pub-like objects. For example, a list of circuits or tuples (circuit, parameter_values).
  • shots (int | None) – The total number of shots to sample for each sampler pub that does not specify its own shots. If None, the primitive’s default shots value will be used, which can vary by implementation.

Section 6: Use the estimator primitive

15. Which one of the following describes the expected behavior of the number of shots if the value for the parameter precision were changed from 0.015625 to 0.03125?

a. It increases the number of shots quadratically
b. It increases the number of shots exponentially
c. It has no effect on the number of shots
d. It decreases the number of shots

Answer

The answer is d.

The required number of shots is inversely proportional to the square of the precision:

N1ϵ2N \sim \frac{1}{\epsilon^2}

When the precision parameter increases from 0.015625 (1/64) to 0.03125 (1/32), the allowed error becomes larger. This means fewer shots are needed. In fact, doubling the precision reduces the required shots by a factor of 4.

16. Which error mitigation technique can be applied using resilience options?

a. Pauli twirling
b. Dynamical decoupling
c. Zero Noise Extrapolation
d. Full quantum error correction

Answer

The answer is c.

a. Pauli twirling → A noise tailoring technique, not a resilience option.
b. Dynamical decoupling → A circuit scheduling technique, not in resilience options.
c. Zero Noise Extrapolation → ✅ This is directly available as a resilience option.
d. Full quantum error correction → Not yet practical and not part of resilience options.

17. Which format should a primitive unified bloc (PUB) tuple follow for the Estimator primitive?

a. pub = (circuit, observable, parameter_values, backend)
b. pub = (circuit, observable, parameter_values, precision)
c. pub = (circuit, observable, shots, optimization_level)
d. pub = (circuit, observable, resilience_level, noise_model)

Answer

The answer is b.

This page gives an overview of the inputs and outputs of the Qiskit Runtime primitives that execute workloads on IBM Quantum® compute resources. These primitives provide you with the ability to efficiently define vectorized workloads by using a data structure known as a Primitive Unified Bloc (PUB). These PUBs are the fundamental unit of work a QPU needs to execute these workloads. They are used as inputs to the run() method for the Sampler and Estimator primitives, which execute the defined workload as a job. Then, after the job has completed, the results are returned in a format that is dependent on both the PUBs used as well as the runtime options specified from the Sampler or Estimator primitives.

Estimator PUB

For the Estimator primitive, the format of the PUB should contain at most four values:

  • A single QuantumCircuit, which may contain one or more Parameter objects
  • A list of one or more observables, which specify the expectation values to estimate, arranged into an array (for example, a single observable represented as a 0-d array, a list of observables as a 1-d array, and so on). The data can be in any one of the ObservablesArrayLike format such as Pauli, SparsePauliOp, PauliList, or str.
  • A collection of parameter values to bind the circuit against. This can be specified as a single array-like object where the last index is over circuit Parameter objects, or omitted (or equivalently, set to None) if the circuit has no Parameter objects.
  • (Optionally) a target precision for expectation values to estimate

Sampler PUB

For the Sampler primitive, the format of the PUB tuple contains at most three values:

  • A single QuantumCircuit, which may contain one or more Parameter objects
  • A collection of parameter values to bind the circuit against θk\theta_k (only needed if any Parameter objects are used that must be bound at runtime)
  • (Optionally) a number of shots to measure the circuit with

Section 7: Retrieve and analyze the results of quantum circuits

18. Which statement describes the purpose of a Qiskit Runtime session?

a. Automatically generate quantum algorithms based on user input
b. Visualise the results of quantum experiments in real time
c. Group a collection of calls to the quantum computer
d. Compile and optimise quantum circuits for different backends

Answer

The answer is c.

a. some kind of AI-driven or template-based algorithm generation
b. Qiskit Visualization
c. Qiskit Runtime session
d. Qiskit transpiler

19. Which two of the following pieces of information are part of the dictionary returned by session.details(), assuming that session is an instance of qiskit_ibm_runtime.Session?

a. Quantum circuit depth
b. Timestamp of the last job in the session that completed
c. Session state
d. Primitive options
e. Primitive unified blocs (PUBs) in each job

Answer

The answer is b, c.

session.details() method returns a dictionary with the sessions details.

  • id: id of the session.
  • backend_name: backend used for the session.
  • interactive_timeout: The maximum idle time (in seconds) between jobs that is allowed to occur before the session is deactivated.
  • max_time: Maximum allowed time (in seconds) for the session, subject to plan limits.
  • active_timeout: The maximum time (in seconds) a session can stay active.
  • state: State of the session - open, active, inactive, or closed.
  • accepting_jobs: Whether or not the session is accepting jobs.
  • last_job_started: Timestamp of when the last job in the session started.
  • last_job_completed: Timestamp of when the last job in the session completed.
  • started_at: Timestamp of when the session was started.
  • closed_at: Timestamp of when the session was closed.
  • activated_at: Timestamp of when the session state was changed to active.
  • mode: Execution mode of the session.
  • usage_time: The usage time, in seconds, of this Session or Batch. Usage is defined as the time a quantum system is committed to complete a job.

Section 8: Operate with OpenQASM

20. Which one of the following is a classical data type supported by OpenQASM 3?

a. complex
b. class
c. char
d. enum

Answer

The answer is a.

OpenQASM 3 supports several classical types, including:

  • int (signed integers)
  • uint (unsigned integers)
  • bool (boolean values)
  • bit (classical bit register)
  • float (floating-point numbers)
  • angle (special type for representing angles)
  • complex (complex numbers, added in OpenQASM 3)
  • array, struct, enum (for composite data structures)

21. Which method should be used to export a Qiskit circuit named qc to OpenQASM 3 and store it into a file stream named qasmprogram?

a. qc.to_openqasm3(qasmprogram)
b. qiskit.qasm3.dump(qc, qasmprogram)
c. qasmprogram.export_to_qasm3(qc)
d. qiskit.qasm3.export(qc, qasmprogram)

Answer

The answer is b.

The high-level functions are simply dump() and dumps(), which respectively export to a file (given as a filename) and to a Python string.

  • dump(): Serialize a QuantumCircuit object as an OpenQASM 3 stream to file-like object.
  • dumps(): Serialize a QuantumCircuit object in an OpenQASM 3 string.