Qiskit Runtime & the Primitives — SamplerV2 and EstimatorV2 in 2026

When we first seeded Quantum Genesis, we ran circuits the old way: build a circuit, call execute() or backend.run(), and wait for a Result object with raw counts. It worked, but every run felt like negotiating with the machine directly. Since then the Qiskit SDK has moved to a model built around the primitives — first Sampler/Estimator (V1), now SamplerV2/EstimatorV2 on Qiskit Runtime. This post is the mental model I wish I'd had, with code you can run today.

If you've been following old tutorials and finding that qiskit.execute no longer exists, or that IBMQ.save_account is gone, this is the update you need. The days of submitting circuits one at a time to backend.run() and parsing raw result objects are over. Modern Qiskit wants you to think in terms of what you want to compute, not how to shuffle bits from the QPU.

Quantum Genesis NFT #29 — run through modern primitives

Why the primitives exist

The old flow forced you to become an expert in the transport layer: pick a backend, submit a job, poll for status, parse a counts dictionary, handle retries. Every experiment re-implemented the same plumbing. The primitives abstract that away and give you two verbs:

  • Sampler — given one or more circuits, return the probability (or the raw counts) of the measurement outcomes. This is your "run the circuit and give me the distribution" tool.
  • Estimator — given circuits plus operator expressions (like a Hamiltonian), return the expectation value. This is your "give me an energy / give me " tool for algorithms like VQE.

The V2 versions tighten this contract. EstimatorV2 accepts circuits with support for parameters and returns richer metadata. SamplerV2 lets you control the number of shots per circuit independently and exposes the results in a way that's easier to consume with qiskit_aer and runtime backends alike.

Installing what you need

pip install qiskit qiskit-ibm-runtime qiskit-aer

qiskit brings the circuit library and transpiler. qiskit-ibm-runtime is the package that talks to IBM's cloud backends through the primitives. qiskit-aer gives you a fast local simulator with the same primitive interface, which is perfect for iterating before you spend real quantum time.

The SamplerV2 workflow, step by step

The key difference from the old API: you pass a list of PUBs (Primitive Unified Blocs — a circuit plus its parameter values and, for the Estimator, the observables) rather than a single job, and you get back a structured result rather than a raw counts.

from qiskit import QuantumCircuit
from qiskit_aer.primitives import SamplerV2

# A circuit that produces a simple superposition
qc = QuantumCircuit(1, 1)
qc.h(0)      # Hadamard -> equal superposition of |0> and |1>
qc.measure(0, 0)

# Build the primitive interface
sampler = SamplerV2()

# Run and inspect
result = sampler.run([qc], shots=1000).result()
counts = result[0].data.c.get_counts()
print(counts)
# {'0': 496, '1': 504}   -- roughly 50/50, as superposition predicts

Notice a few things that changed from the old days:

  1. sampler.run([qc]) — you pass a list of circuits.
  2. result[0] — the result is indexed by pub, in the order you provided them.
  3. result[0].data.c — results are grouped by classical register name. QuantumCircuit(1, 1) creates a register called c; measure_all() creates one called meas.

For a circuit with a parameter, you pass the values inside the PUB, as a (circuit, parameter_values) tuple:

from qiskit.circuit import Parameter

theta = Parameter("theta")
qc = QuantumCircuit(1, 1)
qc.ry(theta, 0)
qc.measure(0, 0)

from qiskit_aer.primitives import SamplerV2

sampler = SamplerV2()
result = sampler.run(
    [(qc, [[0.0], [3.14159]])],   # one row per parameter set
    shots=1000,
).result()
print(result[0].data.c.get_counts(0))   # theta = 0  -> {'0': 1000}
print(result[0].data.c.get_counts(1))   # theta = pi -> {'1': 1000}

Each row is one parameter set, and the result keeps that shape, so get_counts(0) and get_counts(1) return the counts for each value. This is the "vectorized" batch mode that replaced the old parameter_binds loops.

EstimatorV2: getting an expectation value

Where the Estimator shines is when you want ⟨ψ|H|ψ⟩, the expectation value — the quantity every hybrid quantum algorithm needs.

from qiskit import QuantumCircuit
from qiskit.quantum_info import SparsePauliOp
from qiskit_aer.primitives import EstimatorV2

# Prepare a simple state
qc = QuantumCircuit(2)
qc.h([0, 1])

# A toy Hamiltonian: Z on both qubits
H = SparsePauliOp(["ZZ"])

estimator = EstimatorV2()
job = estimator.run([(qc, H)])
result = job.result()
print(result[0].data.evs)

The pub interface here is (circuit, operator) — you pass the circuit and the observable you want measured. With EstimatorV2 the default variance/overlap metadata is richer than V1, so it's straightforward to extract the expectation value as a float.

Jumping to real IBM hardware

The local Aer simulators share the primitive API with the real thing, so the only change to go to the cloud is the backend you attach to.

from qiskit_ibm_runtime import QiskitRuntimeService, SamplerV2 as RuntimeSampler
from qiskit.transpiler.preset_passmanagers import generate_preset_pass_manager

service = QiskitRuntimeService(channel="ibm_quantum_platform", token="YOUR_API_TOKEN")
backend = service.backend("ibm_fez")  # or whatever is available today

# Real hardware only accepts circuits in its native gates and qubit layout (ISA circuits)
pm = generate_preset_pass_manager(backend=backend, optimization_level=1)
isa_qc = pm.run(qc)   # qc: the Hadamard circuit from the first example

sampler = RuntimeSampler(mode=backend)
result = sampler.run([isa_qc], shots=1024).result()

There is one step the simulator lets you skip but real hardware does not: transpilation. Qiskit Runtime only accepts circuits already expressed in the processor's native gates and qubit layout (ISA circuits) and rejects anything else, so run them through generate_preset_pass_manager first. The channel name changed too: it is now "ibm_quantum_platform"; the old "ibm_quantum" no longer authenticates.

Sessions: keeping state across calls

For iterative algorithms like VQE, repeatedly spinning up jobs is wasteful. Sessions give you a shared context where multiple primitive calls reuse the same runtime slot:

from qiskit_ibm_runtime import Session, EstimatorV2 as RuntimeEstimator

isa_qc = pm.run(qc)                     # qc, H: from the EstimatorV2 example
isa_H = H.apply_layout(isa_qc.layout)   # map the observable onto the physical qubits

with Session(backend=backend) as session:
    estimator = RuntimeEstimator(mode=session)
    e1 = estimator.run([(isa_qc, isa_H)]).result()
    # ... iterate ...
    e2 = estimator.run([(isa_qc, isa_H)]).result()

Sessions matter for any loop that talks to the backend more than once — the scheduling overhead and latency of cold-starts vanish after the first call. This is the change that quietly made hybrid loops practical on real hardware. Note that sessions need a paid plan; on the free Open plan, group jobs with Batch instead.

Error mitigation: improving noisy results

The real hardware is noisy, and the primitives make error mitigation a one-line option rather than a research project.

from qiskit_ibm_runtime import EstimatorV2 as RuntimeEstimator

estimator = RuntimeEstimator(mode=backend)
estimator.options.resilience_level = 1      # readout-error mitigation (TREX)
# resilience_level = 2 adds zero-noise extrapolation (more shots, more time)
result = estimator.run([(isa_qc, isa_H)]).result()

# SamplerV2 has no resilience levels; it offers suppression instead:
sampler = RuntimeSampler(mode=backend)
sampler.options.dynamical_decoupling.enable = True
sampler.options.twirling.enable_gates = True

The two primitives differ here. EstimatorV2 has resilience levels: level 1 applies readout-error mitigation (TREX), and level 2 adds zero-noise extrapolation. SamplerV2 does not correct readout errors in your counts. It offers dynamical decoupling and Pauli twirling, and for corrected counts you need a package like mthree (see the measurement error mitigation post). Either way, more mitigation means more shots and more classical post-processing time.

Migrating old code to the primitives

The single biggest trap in upgrading is reaching for functions that no longer exist. Quick map that covers 95% of real code:

Old (deprecated/removed)New
qiskit.execute(circ)SamplerV2 (or EstimatorV2)
backend.run(circ)a runtime primitive bound to that backend
transpile(circ, backend) before rungenerate_preset_pass_manager(...).run(circ) — still required for real hardware
IBMQ.save_account() / IBMQ.load_account()QiskitRuntimeService(..., token=...)
result.get_counts(circ)result[n].data.<register>.get_counts() (e.g. .c or .meas)
parameter_bindsparameter_values in the pub interface
assemble(...)gone — runtime builds it for you

If a tutorial references qiskit.execute, IBMQ.get_provider, or backend.run with a manually assembled Qobj, it's for a version that has been superseded. The primitives are the present and the near future.

What this means for reproducible art

Back when Quantum Genesis still ran the old way, each of our 82 IBM seeds went through backend.run(). The pipeline worked, but it was brittle: if the backend name changed or the SDK bumped, the whole run script needed surgery. If we were building that same collection today, I'd wrap the seed generation in a SamplerV2 bound to a runtime backend, put a pass manager in front for transpilation, and let the primitive handle job management and the counts parsing. The art code would only ever touch a clean interface: "give me 4096 shots of this circuit."

Quantum Genesis NFT #57 — Seeded the modern way, on Qiskit Runtime primitives

The primitives are less about new physics and more about a sane engineering boundary between your code and the hardware. Once you're on that boundary, switching between a laptop simulator and a real quantum processor is a one-line change — which is exactly the flexibility a generative-art pipeline wants when it's iterating on tens of circuits at a time.

Comments

Popular posts from this blog

Quantum Key Distribution for Developers — BB84 with Qiskit

Post-Quantum Cryptography in 2026 — What Developers Actually Need to Know