feat(qiskit): add calibration-ranked initial_layout for packed jobs#18
Open
MatthewPeng57 wants to merge 2 commits into
Open
feat(qiskit): add calibration-ranked initial_layout for packed jobs#18MatthewPeng57 wants to merge 2 commits into
MatthewPeng57 wants to merge 2 commits into
Conversation
Modern IBM devices have large per-qubit calibration variance: on a
FakeSherbrooke snapshot, readout error ranges from 1.1% (q0) to 25.7%
(q6), a 23x spread. Packed single-qubit QKAN circuits submitted via
parallel_qubits=N implicitly map onto physical qubits 0..N-1, which
often includes several poorly-calibrated qubits. Because per-edge noise
dominates the fast-programmer's output and rel MSE scales as sigma^2,
a 6x higher mean noise across the selected set compounds to ~36x higher
aggregate error.
This patch:
- Adds `best_qubits(backend, n)` helper that scores each physical qubit
by `readout_error + sx_err + 1e-4/T2` and returns the n lowest.
- Adds `initial_layout` config key to qiskit_solver:
* None (default) - transpiler chooses (unchanged behaviour).
* "auto" - call best_qubits(backend, parallel_qubits).
* list[int] - user-supplied physical qubit indices.
- Threads `initial_layout` into both the serial and
`_qiskit_run_parallel` transpiler calls via
`generate_preset_pass_manager(initial_layout=...)`.
- Documents the feature in docs/solver_guide.rst with an empirical
impact table.
Empirical impact (FakeSherbrooke, 200 single-qubit edges,
parallel_qubits=20, shots=1024):
Layout rel MSE vs noiseless
--------------------------------------------------
parallel_qubits=1 (qubit 0) 0.134%
naive packed (0..19) 5.218%
best_qubits(backend, 20) 0.127%
The smart layout at parallel_qubits=20 recovers parallel_qubits=1
fidelity (a ~40x improvement over naive) at identical QPU cost.
A reproducer script is linked from the PR body (hosted as a gist to
keep this diff focused on the core change).
Backwards compatible: existing callers that do not pass `initial_layout`
see no change in behaviour. `best_qubits` returns [] when the backend
has no properties(), so `"auto"` cleanly falls back to transpiler
default in that case.
The previous CI run failed during `pip install -r requirements-dev.txt` with `SSL: DECRYPTION_FAILED_OR_BAD_RECORD_MAC` while downloading transformers-4.57.1.whl — a known intermittent PyPI/CDN issue, not a problem with this PR. `make lint` (ruff check, ruff format --diff, mypy) passes locally against this branch with no new findings relative to master. This empty commit exists only to retrigger CI.
Author
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Closes #17
Summary
Adds a
best_qubits(backend, n)helper and a newinitial_layoutoption (supportingNone,"auto", orlist[int]) toqiskit_solver.solver_kwargs. Pinning the packed N-qubit circuit to the top-N best-calibrated qubits recoversparallel_qubits=1fidelity at identical QPU cost.Motivation
On real and fake IBM backends, per-qubit readout error varies by up to ~23× across the chip. The transpiler's default layout for packed
parallel_qubits=Njobs uses physical qubits0..N-1, which picks up several poorly-calibrated qubits. Because rel MSE ∝ σ², a 6× higher mean noise compounds to ~36× higher aggregate error.Approach
best_qubits(backend, n)scores each qubit and returns thenlowest:sx_errbreaks ties between comparably-calibrated qubitsThe new
initial_layoutkwarg is threaded throughgenerate_preset_pass_manager(initial_layout=...)in both the serial and_qiskit_run_parallelpaths.Backwards compatibility
Fully back-compat:
initial_layout=Nonereproduces prior transpiler behaviour exactly.best_qubitsreturns[]whenbackend.properties()is unavailable, so"auto"falls back to the default cleanly.Empirical validation
200 independent single-qubit pz-encoding circuits,
parallel_qubits=20,shots=1024, FakeSherbrooke:parallel_qubits=1(qubit 0)0..19)best_qubits(backend, 20)Reproducer: stand-alone script hosted as a [gist](https://gist.github.com/MatthewPeng57/4c09a4fd39244ff62c8306fe6a6f96ed) to keep this PR focused on the library change.
Files changed
src/qkan/solver/qiskit_solver.pybest_qubits+initial_layoutplumbing through the config and both transpiler pathssrc/qkan/solver/__init__.pybest_qubitsdocs/solver_guide.rstTesting
The repo has no existing test suite, so validation is via:
ast.parse+import qkan.solver.best_qubitspass locally.initial_layout={None, "auto", [...]}paths on FakeSherbrooke via a trained QKAN forecasting model (rel MSE numbers above).