Repository navigation
[P8-01] Optimize CPU and Metal CLI execution while preserving final-state views - #569
Merged
Merged
Conversation
This was referenced Oct 13, 2026
ruslan-splynx
marked this pull request as ready for review
November 1, 2026 21:06
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.
CPU FP64/FP32 and Metal CLI state-vector runs previously used raw execution even when benchmarks/Python exercised fusion. CLI now selects a backend-appropriate optimized executor independently of formatting;
--rawretains the reference driver and--execution-statsexposes actual retained IR kinds/planning cost.Closes #551. The previously deferred Mac validation is now complete (2026-11-01), after integrating main
4e72028. Integration preserves noise-budget/CUDA execution APIs and benchmark diagnostics. Review and green CI are required on this integrated head.Final-state pipelines omit measurement-seeded DCE so preparation on unmeasured qubits, collapsed-final-state sampling, amplitudes and expectations survive partial measurements. Relabelling is restored before views. CPU retains small precomputed diagonal gates; a phase-polynomial pilot made FP64 QFT 54% slower despite a smaller IR plan. Metal uses its supported GPU final-state wrapper. FP32 supports dense/diagonal fusion and correct tiled replay. Stabilizer/MPS/noise/CUDA drivers and the legacy bench subcommand are unchanged; the original Rust run_circuit API remains available.
Actual public CPU CLI A/B on i5-13500 Linux, release, RAYON_NUM_THREADS=1, 32 shots/seed 7, three interleaved fresh processes per mode:
Public-process Criterion (10 samples, 1 s warmup, 2 s requested measurement, committed n=15 fixtures): FP64 brickwall 25.605 → 22.854 ms; FP32 QFT 37.224 → 19.194 ms; FP32 brickwall 40.369 → 24.355 ms. FP64 QFT median confidence intervals overlap, so no speedup is claimed. Tiny inputs expose added planning overhead. Comparisons use the same binary's raw/optimized modes, not historical binaries or kernel-only timers.
Fusion can change FP rounding/alias bins and hence a seed's exact histogram. Each mode is reproducible. Full n=20 brickwall verification found optimized FP32 max amplitude error 2.85e-9 and probability L1 error 5.52e-7 versus raw FP64 (raw FP32 L1 1.69e-6). CLI seed help documents the mode-dependent mapping.
Validation: 35 CLI unit tests, 40 existing command tests, GPU-init regression, three new public optimizer tests; final-state amplitude oracles for CPU FP64/FP32 including relabelling, external controls, partial measurements, phases/barriers and 64 generated circuits; existing optimized-driver oracles; three public CPU Python/CLI equivalence fixtures. Real Metal CLI raw/optimized oracle executed successfully. CUDA CLI compilation, workspace/Metal all-target clippy, formatting and diff checks pass. Raw data, Criterion samples, planning counts/costs, limitations and pending work: docs/perf/p8-01-optimized-cli.md.
Deferred Metal validation completed (2026-11-01)
Apple M5 MacBook Air, 10 CPU/10 GPU cores, 32 GiB unified memory. Release public CLI, FP32 Metal, same binary raw vs optimized, 32 shots/seed 7, RAYON_NUM_THREADS=1. One untimed process per mode, then four ABBA blocks (8 observations per mode), with diagnostics and host telemetry. Whole-process timings include planning/startup/output. No programs/services stopped; shared desktop, CPU idle median 74.68% (range 57.11–94.36%), GPU/thermals not isolated.
Bell n=2 has no consistent gain: 28.861 → 27.552 ms in the first series; 32.747 → 32.793 ms in the second. Public-process Criterion without diagnostics (10 samples, 1 s warmup/2 s requested measurement) gives median estimates: Bell n=2 26.699 → 27.358 ms; QFT n=15 33.196 → 28.375 ms; brickwall n=15 d=20 33.298 → 34.138 ms. Small Bell/brickwall remain no-gain cases; large-n gains are not universal.
Integrated validation: 81 release CLI tests with actual Metal explicitly enabled; 5 final-state oracle tests (1 existing ignored offline case); 4 optimized-driver oracle tests; 4 Metal oracle tests plus 1 property test. Three focused public optimizer tests passed again with Metal structural assertions. New n=16 real-Metal oracle verifies all 65,536 amplitudes against raw CPU FP64 after permutation restoration and partial measurement/unmeasured preparation. Workspace all-target Clippy, Metal CLI/backend all-target Clippy, formatting, Python syntax and changed documentation/checksums passed. Manual integration review found no blocking findings.
Raw samples, confidence intervals, logs, host telemetry, source/binary fingerprints and commands:
docs/perf/data/p8-01-metal/. Report:docs/perf/p8-01-optimized-cli.md. Same-mode seed reproducibility passed; cross-mode histogram equality is not required because floating-point fusion can alter alias bins.