Standardize how tutorials use local simulators
I maintainer di solito rispondono entro 1 giorno
Nessuno ha ancora preso questa issue.
Valutazione
- Difficoltà
- 5/5
- Tempo stimato
- Più di una settimana
- Idoneità per principianti
- 45/100
- Tipo di issue
- Refactoring
- Chiarezza
- Specificata chiaramente
- Stato di attività
- Attiva
- Stack tecnologico
- jupyter-notebook, python
- Ambito
- documentation
Direzione di ricerca
Start with the affected notebooks under docs/tutorials/ and compare them with docs/guides/local-testing-mode and docs/guides/local-simulators. Apply the proposed Tier 1 or Tier 2 choice to each listed tutorial, preserving the explicitly out-of-scope tensor-network methods; done means simulator setup, transpile targets, naming, noise rationale, and exact-reference usage are consistent across the audit.
Scritto dal modello di indicizzazione a partire dal testo della issue.
Descrizione
Summary
About 33 of the 60 tutorials in docs/tutorials/ run a local simulation somewhere, usually as a small-scale example before the hardware run. They do it in at least six different ways, with different primitives, noise choices, transpile targets, and variable names. A reader who goes through several tutorials sees a different simulator pattern almost every time, and many of the patterns don't match what the guides teach.
This issue lists what each tutorial currently does, the inconsistencies, and a proposed standard that aligns with the Local testing mode and Migrate to local simulators guides.
Current state
A. Qiskit reference primitives (StatevectorSampler / StatevectorEstimator)
| Tutorial | What it does |
|---|---|
grovers-algorithm |
StatevectorSampler() for the small-scale run |
krylov-quantum-diagonalization |
Transpiles against FakeMarrakesh, then runs the untranspiled circuits on StatevectorEstimator() |
loop-string-hadron-dynamics |
StatevectorEstimator() |
operator-back-propagation |
StatevectorEstimator(seed=rng) for exact reference values |
quantum-kernel-training |
StatevectorSampler() |
sample-based-krylov-quantum-diagonalization |
Transpiles against GenericBackendV2, runs on StatevectorSampler() |
sample-based-quantum-diagonalization |
Transpiles against a custom GenericBackendV2 (LUCJ basis gates), runs on StatevectorSampler(seed=rng) |
warm-start-qaoa |
StatevectorEstimator() and StatevectorSampler() |
simulate-neutron-scattering |
StatevectorEstimator(), alongside Quimb tensor-network simulation |
B. Runtime primitive + noiseless AerSimulator() (local testing mode)
| Tutorial | What it does |
|---|---|
edc-cut-bell-pair-benchmarking |
aer_backend = AerSimulator(); Sampler(mode=aer_backend) |
long-range-entanglement |
aer_backend = AerSimulator(); Sampler(mode=aer_backend) |
multi-product-formula |
aer_sim = AerSimulator(); Estimator(mode=aer_sim) |
wire-cutting |
SamplerV2(mode=AerSimulator()) |
dc-hex-ising |
aer_sim = AerSimulator(); Sampler inside Batch(backend=aer_sim) |
qedma-2d-ising-with-qesem |
simulator = AerSimulator(); Estimator(simulator) (positional, no mode=) |
C. Runtime primitive + AerSimulator.from_backend(real_backend) (device noise model)
| Tutorial | What it does |
|---|---|
chsh-inequality |
aer_sim = AerSimulator.from_backend(backend); Estimator(mode=aer_sim); transpiles to aer_sim.target |
nishimori-phase-transition |
aer_backend = AerSimulator.from_backend(backend), passed to GemExperiment |
pauli-correlation-encoding-for-qaoa |
backend = AerSimulator.from_backend(real_backend), which reuses the name backend for the simulator |
D. Runtime primitive + AerSimulator with a hand-built noise model
| Tutorial | What it does |
|---|---|
ai-transpiler-introduction |
Depolarizing NoiseModel; aer_sim = AerSimulator(noise_model=...); SamplerV2(mode=aer_sim) |
compilation-methods-for-hamiltonian-simulation-circuits |
Same pattern as ai-transpiler-introduction |
E. Qiskit Aer primitives (qiskit_aer.primitives)
| Tutorial | What it does |
|---|---|
fractional-gates |
AerSampler.from_backend(backend_f) and AerSampler.from_backend(backend_c) |
transpilation-optimizations-with-sabre |
AerEstimator.from_backend(backend) |
dc-hex-ising |
Aer_Sampler.from_backend(AerSimulator(method="matrix_product_state", ...)) for the MPS run |
F. AerSimulator.run() directly (no primitives)
| Tutorial | What it does |
|---|---|
sqdrift |
simulator = AerSimulator(); transpile(...); simulator.run(...) |
transverse-field-ising-model |
backend_sim = AerSimulator(method="matrix_product_state"); .run(...) |
quantum-phase-estimation-qctrl |
aer_simulator = AerSimulator(method="matrix_product_state"); .run(...) |
spacetime-codes |
noisy_sim = AerSimulator(method="stabilizer", noise_model=...); .run(..., seed_simulator=...) per circuit |
G. Other (not circuit-execution simulators)
| Tutorial | What it does |
|---|---|
approximate-quantum-compilation-for-time-evolution |
Quimb MPS via qiskit-addon-aqc-tensor; FakeKyiv used only as a transpile target |
simulate-neutron-scattering, simulate-neutron-scattering-with-a-serverless-workflow |
Quimb MPS via QuimbSimulator |
multi-product-formula |
tenpy MPS/TEBD via qiskit-addon-mpf |
depth-reduction-with-circuit-cutting, probabilistic-error-cancellation-with-logical-noise-models, multi-product-formula |
qiskit.quantum_info.Statevector for exact reference values |
Leftovers found during the audit
depth-reduction-with-circuit-cutting: comment says "For a fake backend, this will use a local simulator," but the tutorial only uses a real backend.readout-error-mitigation-sampler: commented-outFakeMelbourneV2.
Inconsistencies
- Four ways to run the simulation. The tutorials use Qiskit reference primitives, Runtime primitives in local testing mode,
qiskit_aer.primitives, and rawAerSimulator.run(). The raw.run()calls (group F) bypass primitives entirely, even though every hardware section uses them. - No stated noise choice. Some examples are noiseless, some copy a device's noise with
from_backend, and some use a hand-built depolarizing model. Tutorials rarely explain why they chose one. - Different transpile targets. These include
GenericBackendV2,FakeKyivorFakeMarrakesh,AerSimulator(),aer_sim.target, and inkrylov-quantum-diagonalization, a target that the simulated circuit isn't even transpiled for. - API style. Most tutorials pass
mode=aer_sim;qedma-2d-ising-with-qesempasses the simulator positionally. - Variable names. The simulator is called
aer_sim,aer_backend,simulator,backend_sim,aer_simulator,noisy_sim, orbackend. - Problems in individual tutorials. These are the
krylov-quantum-diagonalizationtranspile mismatch, thebackendreuse inpauli-correlation-encoding-for-qaoa, and the leftovers listed above.
Proposed standard
The standard has two tiers, because one simulator path can't cover every tutorial (see "Why two tiers").
Tier 1: Simulate the hardware workflow (default)
Use local testing mode: the same qiskit_ibm_runtime SamplerV2/EstimatorV2 used for the hardware run, with an AerSimulator as the mode. Transpile against that same simulator object.
from qiskit_aer import AerSimulator
from qiskit.transpiler import generate_preset_pass_manager
from qiskit_ibm_runtime import SamplerV2 as Sampler
# Pick ONE and say why in the markdown:
aer_sim = AerSimulator() # noiseless
# aer_sim = AerSimulator.from_backend(backend) # noise model from a real QPU
# aer_sim = AerSimulator(noise_model=noise_model) # custom noise model
# aer_sim = AerSimulator(method="matrix_product_state") # larger, low-entanglement circuits
# aer_sim = AerSimulator(method="stabilizer") # Clifford circuits
pm = generate_preset_pass_manager(backend=aer_sim, optimization_level=1)
isa_circuits = pm.run(circuits)
sampler = Sampler(mode=aer_sim)
result = sampler.run(isa_circuits).result()
Rules:
- Always pass the simulator with
mode=, not positionally. - Name it
aer_sim. Never reusebackend, which stays the real QPU. - Transpile against the object passed to
mode, not a separate fake or generic backend. - State the noise choice (noiseless, device noise, or custom) and the reason in the markdown.
- For reproducible output, set
sampler.options.simulator.seed_simulator(supported in local testing mode). SessionandBatchare accepted but ignored in local testing mode. They're fine when they mirror the hardware code, but not required.
When the hardware section switches from simulator to QPU, only the mode argument (and the transpile target) should change. This is the main selling point of local testing mode in the guides.
Tier 2: Exact reference values
When the tutorial needs an exact value (for example, a ground-truth expectation value to compare against, or an exact kernel entry), use the Qiskit reference primitives StatevectorEstimator / StatevectorSampler on the logical (untranspiled) circuit, and label it as the exact reference. Use qiskit.quantum_info.Statevector directly only when the tutorial needs the state itself rather than a primitive result.
Out of scope
Tensor-network methods that are part of the algorithm itself (Quimb in AQC and neutron scattering, tenpy in MPF) are not simulator choices and stay as they are.
Why two tiers
I verified this locally (qiskit-ibm-runtime 0.46.1, qiskit-aer 0.17.2). Local testing mode wraps the simulator in Qiskit's shot-based BackendEstimatorV2, so:
Estimator(mode=AerSimulator())returned 0.9507 for an observable whose exact value is 0.9553.default_precision=0is rejected ("must be >0").
So local testing mode can't produce exact values, and tutorials that need them must keep a statevector path. The standard makes that an explicit, labeled choice instead of an accident.
What changes per tutorial
| Tutorial | Change |
|---|---|
edc-cut-bell-pair-benchmarking, long-range-entanglement |
Rename aer_backend → aer_sim |
multi-product-formula, dc-hex-ising (noiseless part) |
Already compliant |
wire-cutting |
Assign aer_sim = AerSimulator() instead of constructing it inline in SamplerV2(mode=AerSimulator()) |
qedma-2d-ising-with-qesem |
Estimator(mode=aer_sim); rename simulator → aer_sim |
chsh-inequality, ai-transpiler-introduction, compilation-methods-for-hamiltonian-simulation-circuits |
Already compliant |
nishimori-phase-transition |
Rename aer_backend → aer_sim. GemExperiment takes a backend, so the primitive isn't under our control; keep AerSimulator.from_backend |
pauli-correlation-encoding-for-qaoa |
Rename so backend is the QPU and aer_sim is the simulator |
fractional-gates |
AerSampler.from_backend(backend_f) → Sampler(mode=AerSimulator.from_backend(backend_f)); confirm that Aer handles the fractional-gate target |
transpilation-optimizations-with-sabre |
AerEstimator.from_backend(backend) → Estimator(mode=AerSimulator.from_backend(backend)); expect small numerical changes because results become shot-based |
dc-hex-ising (MPS part) |
Aer_Sampler.from_backend(mps_backend) → Sampler(mode=AerSimulator(method="matrix_product_state", ...)) |
sqdrift |
simulator.run(...) → Sampler(mode=aer_sim); read counts from result[0].data.<creg>.get_counts() |
transverse-field-ising-model, quantum-phase-estimation-qctrl |
.run(...) → Sampler(mode=AerSimulator(method="matrix_product_state")) |
spacetime-codes |
.run(...) → Sampler(mode=AerSimulator(method="stabilizer", noise_model=...)) with options.simulator.seed_simulator. The postselection logic reads combined counts, so use result[0].join_data().get_counts() |
grovers-algorithm, quantum-kernel-training, sample-based-krylov-quantum-diagonalization, sample-based-quantum-diagonalization |
Decide per tutorial: if the example demonstrates the hardware workflow → Tier 1; if it needs exact output → Tier 2, labeled as such. sample-based-quantum-diagonalization needs a custom LUCJ basis-gate GenericBackendV2 for ffsim's pass manager; keep it and add a sentence explaining why |
krylov-quantum-diagonalization |
Either run the transpiled circuits in Tier 1, or drop the FakeMarrakesh transpile from the simulator section and use Tier 2 on the logical circuits. Don't transpile for one target and run another |
operator-back-propagation, loop-string-hadron-dynamics, warm-start-qaoa, simulate-neutron-scattering |
Tier 2 (exact values); add a label that these are exact references |
approximate-quantum-compilation-for-time-evolution |
Out of scope (Quimb); FakeKyiv transpile-only use is fine |
depth-reduction-with-circuit-cutting |
Remove the stale fake-backend comment |
readout-error-mitigation-sampler |
Remove the commented-out FakeMelbourneV2 |
Alignment with the guides
- Local testing mode and Migrate to local simulators teach exactly Tier 1:
Sampler(mode=aer_sim)withAerSimulator(),AerSimulator.from_backend(real_backend), orAerSimulator(method="stabilizer"), transpiled withgenerate_preset_pass_manager(backend=aer_sim, ...). The guide also says "For most users,AerSimulatoris a good choice," and uses the nameaer_sim. - Quickstart and Exact simulation with Qiskit SDK primitives teach
StatevectorSampler/StatevectorEstimatorfor exact, small simulations, which matches Tier 2. - Run your first circuit on hardware offers a fake backend in local testing mode as its simulator alternative. That is the same mechanism with a fake backend instead of Aer. Tier 1 prefers
AerSimulatorto match the "most users" recommendation, but fake backends remain valid when a tutorial specifically targets a device snapshot. - One mismatch: Exact and noisy simulation with Qiskit Aer primitives teaches
qiskit_aer.primitives(group E). The proposal moves tutorials away from that pattern. The guide can stay as a reference for Aer's own primitives, but tutorials should use local testing mode so the simulator code matches the hardware code. - Nothing in the guides teaches raw
AerSimulator.run(), so group F is the clearest case for migration.
Open questions
- Should the tutorial template/guidelines codify this (for example, a "Small-scale simulator example" section with the Tier 1 snippet)?
- Should
simulate-with-qiskit-aerget a note pointing to local testing mode as the default for workflows that end on hardware?
- Lingua principale
- Jupyter Notebook
- Stelle
- 111
- Fork
- 247
- Merge medio
- 1g 1h
- PR unite (30g)
- 96
Preparare l'ambiente
- Nessun Dockerfile né file Docker Compose
- Ha un modello di pull request
- Leggi la guida per i contributori
Come iniziare
- Leggi tutta la issue e poi la guida ai contributi del progetto.
- Commenta sulla issue per dire che te ne occupi tu — evita che due persone facciano lo stesso lavoro.
- Fai un fork del repository e lavora su un branch.
- Apri una pull request che faccia riferimento al numero della issue.
Altre issue di Qiskit/documentation
-
Difficoltà 2/5 1-3 ore Idoneità per principianti 82/100
Qiskit/documentation#6052 · 2 commenti ·
I maintainer di solito rispondono entro 1 giorno
-
content 📄
Difficoltà 1/5 Meno di un'ora Idoneità per principianti 82/100
Qiskit/documentation#6036 · 2 commenti ·
I maintainer di solito rispondono entro 1 giorno
-
content 📄
Difficoltà 1/5 Meno di un'ora Idoneità per principianti 82/100
Qiskit/documentation#6033 ·
I maintainer di solito rispondono entro 1 giorno
-
content 📄
Difficoltà 2/5 1-3 ore Idoneità per principianti 67/100
Qiskit/documentation#5967 ·
I maintainer di solito rispondono entro 1 giorno
-
Document that shot order is execution order in the samplerForse già presa @Ashiq1w l’ha presa 9 giorni fa. Apertacontent 📄
Difficoltà 1/5 1-3 ore Idoneità per principianti 68/100
Qiskit/documentation#5808 · 2 commenti · 1 assegnatario ·
I maintainer di solito rispondono entro 1 giorno
Tutte le issue di Qiskit/documentation
Issue simili
-
Difficoltà 1/5 Meno di un'ora Idoneità per principianti 85/100
facebookresearch/atlas-lean#20426 ·
I maintainer di solito rispondono entro 1 giorno
-
docs(contributing): the two things that silently block a PRForse già presa Una pull request collegata a questa issue è aperta o già unita. Apertaavailable documentation good first issue
Difficoltà 1/5 1-3 ore Idoneità per principianti 95/100
Nixitov/Riptide-Native#944 ·
I maintainer di solito rispondono entro 1 giorno
-
area: ai-assistants documentation help wanted
Difficoltà 2/5 1-3 ore Idoneità per principianti 78/100
BetaBots-LLC/latticegate#17 ·
-
enhancement good first issue
Difficoltà 2/5 1-3 ore Idoneità per principianti 88/100
I maintainer di solito rispondono entro 1 giorno
-
Difficoltà 2/5 1-3 ore Idoneità per principianti 78/100
juspay/agent-distro#203 ·
I maintainer di solito rispondono entro 1 giorno