Skip to content

feat(qiskit): add calibration-ranked initial_layout for packed jobs#18

Open
MatthewPeng57 wants to merge 2 commits into
Jim137:masterfrom
MatthewPeng57:feat/qiskit-initial-layout-smart-qubits
Open

feat(qiskit): add calibration-ranked initial_layout for packed jobs#18
MatthewPeng57 wants to merge 2 commits into
Jim137:masterfrom
MatthewPeng57:feat/qiskit-initial-layout-smart-qubits

Conversation

@MatthewPeng57
Copy link
Copy Markdown

@MatthewPeng57 MatthewPeng57 commented Apr 19, 2026

Closes #17

Summary

Adds a best_qubits(backend, n) helper and a new initial_layout option (supporting None, "auto", or list[int]) to qiskit_solver.solver_kwargs. Pinning the packed N-qubit circuit to the top-N best-calibrated qubits recovers parallel_qubits=1 fidelity at identical QPU cost.

Diff: 3 files · +215 / −3

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=N jobs uses physical qubits 0..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 the n lowest:

score(q) = readout_error(q) + sx_err(q) + 1e-4 / max(T2_μs(q), 1)
  • Readout error dominates the score
  • sx_err breaks ties between comparably-calibrated qubits
  • Short T2 adds a small penalty

The new initial_layout kwarg is threaded through generate_preset_pass_manager(initial_layout=...) in both the serial and _qiskit_run_parallel paths.

Backwards compatibility

Fully back-compat:

  • The default initial_layout=None reproduces prior transpiler behaviour exactly.
  • best_qubits returns [] when backend.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:

Layout rel MSE vs. noiseless
parallel_qubits=1 (qubit 0) 0.134 %
naive packed (0..19) 5.218 %
best_qubits(backend, 20) 0.127 %

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

File Change
src/qkan/solver/qiskit_solver.py best_qubits + initial_layout plumbing through the config and both transpiler paths
src/qkan/solver/__init__.py Export best_qubits
docs/solver_guide.rst New "Qubit-calibration layout" section with the empirical table and usage examples

Testing

The repo has no existing test suite, so validation is via:

  1. Reproducer gist (linked above) — run locally on FakeSherbrooke to reproduce the empirical table.
  2. Smoke checksast.parse + import qkan.solver.best_qubits pass locally.
  3. Manual exercise of initial_layout={None, "auto", [...]} paths on FakeSherbrooke via a trained QKAN forecasting model (rel MSE numbers above).

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.
@MatthewPeng57 MatthewPeng57 changed the title feat(qiskit): calibration-ranked initial_layout for packed jobs feat(qiskit): add calibration-ranked initial_layout for packed jobs Apr 19, 2026
@Jim137 Jim137 added enhancement New feature or request good first issue Good for newcomers labels Apr 20, 2026
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.
@MatthewPeng57
Copy link
Copy Markdown
Author

@codex

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

enhancement New feature or request good first issue Good for newcomers

Projects

None yet

Development

Successfully merging this pull request may close these issues.

feat(qiskit): add calibration-ranked initial_layout for packed jobs

2 participants