Run Quantum Circuits – Execution Modes, Primitives V2 & PUBs

📋 20 Questions ⏱ ~20 min 🎯 Pass threshold: 70% 📖 Flashcards included
0 / 20 answered
— / 20
Your score  | 

Review highlighted answers and explanations below.

📖 Flashcard Study Guide: Run Quantum Circuits

Flashcard Set: Qiskit Runtime Execution Modes

Front (Question / Concept) Back (Answer / Definition)
What is Job Mode (Standard)? The default mode where each job is treated independently. Every job submitted enters the regular fair-share queue, incurring full queuing overhead for every execution.
Define Session Mode. An execution mode that allows for iterative workloads. Once the first job starts, the session stays active for a set time (TTL), giving subsequent jobs priority access to the backend.
Define Batch Mode. A mode designed for independent jobs submitted simultaneously. It allows multiple jobs to be grouped to reduce queuing overhead, but unlike Sessions, there is no interactivity between the user and the QPU.
What is the primary benefit of Session Mode? Reduced Latency. By keeping the connection "warm," it minimizes the time spent waiting in the queue between iterations of an algorithm like VQE or QAOA.
What is the "First-in, First-out" (FIFO) behavior in a Session? Within a single session, jobs are executed in the order they are submitted. However, the session itself has priority over other non-session jobs in the general queue.
What does "Max Time" or "TTL" (Time-to-Live) refer to? The maximum duration a Session or Batch remains active. If no new jobs are submitted within a specific idle window, the session closes to free up hardware for others.
When should you use Batch mode instead of Session mode? Use Batch when you have multiple circuits that do not depend on each other's results. Use Session when the next circuit's parameters depend on the results of the previous job.
How do you initialize a Session in Qiskit v2.x? Using a context manager: with Session(service=service, backend=backend) as session:
Does Batch mode support interactive feedback? No. Batch mode is "fire and forget." You submit all jobs at once; you cannot use the result of Job A to modify Job B within the same Batch context.
What is "Dedicated" or "Priority" access in the context of Sessions? It refers to the "reservation" of a spot at the front of the queue for the duration of the session, ensuring that your iterative algorithm isn't interrupted by other users' jobs.

Flashcard Set: Primitives V2 & Hardware Execution

Front (Concept / Question) Back (Answer / Definition)
What are the two main Primitives in Qiskit Runtime V2? SamplerV2 (returns bitstrings/counts) and EstimatorV2 (returns expectation values of observables).
What does PUB stand for? Primitive Unified Bloc. It is the standardized format used to submit circuits and data to V2 primitives.
Structure of a SamplerV2 PUB? (circuit, parameter_values, shots) — Note: parameter_values and shots are optional.
Structure of an EstimatorV2 PUB? (circuit, observables, parameter_values, precision) — Note: parameter_values and precision are optional.
What is the purpose of "Broadcasting" in a PUB? It allows you to pair a single circuit with multiple parameter sets or observables without repeating the circuit object, reducing data transfer and overhead.
How do you filter for a real hardware backend? Using service.least_busy(simulator=False, operational=True).
Where do you specify the number of shots in SamplerV2? Shots can be specified globally in the Options or locally per PUB as the third element of the tuple.
What is the return type of SamplerV2.run().result()? A PrimitiveResult containing DataBins (e.g., pub_result.data.meas.get_counts()).
What happens if you provide 1 circuit and 5 sets of parameters in one PUB? Broadcasting occurs: the circuit is executed 5 times, once for each set of parameters, and 5 results are returned.
How is 'precision' used in EstimatorV2? It defines the target standard error for the expectation value. The primitive will automatically determine the number of shots needed to reach that precision.

Deep Dive: Visualizing Broadcasting Rules

Broadcasting follows NumPy-like rules. If a PUB contains a singleton (length 1) and an array (length N), the singleton is "stretched" to match the array.

Circuit Observables Parameters Resulting Executions
1 1 10 10 — 1 circuit, 1 observable, 10 different params
1 5 1 5 — 1 circuit, 5 different observables, 1 param
1 5 5 5 — 1 circuit, Obs A with Param A, Obs B with Param B, etc.
5 5 5 5 — Circuit A with Obs A and Param A, etc.

Code Syntax Flashcards (Practical)

How do you run two different circuits in a single SamplerV2 call?
Pass a list of two PUBs:
# Pass a list of two PUBs
sampler = SamplerV2(mode=backend)
job = sampler.run([(qc1,), (qc2,)])
How do you retrieve results from the first PUB in a V2 job?
Access the PUB result by index, then navigate the data bin:
result = job.result()
pub_result = result[0]  # Access the first PUB result
counts = pub_result.data.meas.get_counts()
How do you define a PUB for EstimatorV2 with a specific precision?
Precision is the optional fourth element of the tuple:
# (circuit, observables, parameter_values, precision)
pub = (my_circuit, my_obs, my_params, 0.01)
job = estimator.run([pub])