Skip to content

Faster weight calculation - #126

Merged
david-pl merged 9 commits into
mainfrom
david/fix-weight-calc
Jun 19, 2026
Merged

Faster weight calculation#126
david-pl merged 9 commits into
mainfrom
david/fix-weight-calc

Conversation

@david-pl

Copy link
Copy Markdown
Collaborator

Benchmarking trotter including a MaxPauliWeight truncation strategy showed a major regression. This PR uses bytemuck to bypass the bitvec methods and directly computes the weight from the total &[u8] slices of bits.

CopilotAI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Improves ppvm-runtime truncation performance by speeding up Pauli “weight” computation (hot in MaxPauliWeight/MaxLossWeight truncation) and by skipping retain passes entirely when the truncation is effectively disabled via a sentinel. Adds Rust/Python/Julia benchmarks to reproduce/track the regression described in the PR.

Changes:

  • Optimized PauliWordTrait::weight() (and lossy variants) to popcount directly over raw storage bytes using bytemuck.
  • Avoided unnecessary retain() passes when MaxPauliWeight(usize::MAX) / MaxLossWeight(usize::MAX) is used to opt out of those truncations.
  • Added benchmarking coverage (Criterion bench + pytest-benchmark + Julia mirrors) and wired pytest-benchmark into the Python dev environment.

Reviewed changes

Copilot reviewed 16 out of 18 changed files in this pull request and generated 2 comments.

Show a summary per file
FileDescription
crates/ppvm-runtime/src/word/data.rsFast popcount-based Pauli weight computation over raw storage bytes.
crates/ppvm-runtime/src/loss/data.rsSame optimization for lossy words (weight + loss_weight).
crates/ppvm-runtime/src/strategy.rsEarly-return optimization when max-weight truncation is disabled via usize::MAX.
crates/ppvm-runtime/src/traits/coefficient.rsAdds #[inline] hints to cutoff methods used during truncation retains.
crates/ppvm-runtime/benches/trotter.rsUpdates trotter benchmark strategy to match Python binding configuration and thread settings.
crates/ppvm-runtime/benches/truncation-weight.rsNew Criterion micro-benchmark focusing on truncation strategy costs.
crates/ppvm-runtime/Cargo.tomlRegisters the new truncation-weight benchmark target.
ppvm-python/pyproject.tomlAdds pytest-benchmark to the dev group and disables benchmarking by default via pytest addopts.
ppvm-python/uv.lockLockfile update for pytest-benchmark (and its dependency py-cpuinfo).
ppvm-python/test/benchmarks/test_trotter.pyNew pytest-benchmark mirror of the Rust trotter bench for Python bindings.
ppvm-python/demo/trotter_ladder.pyNew pedagogical/demo script showing a truncation-controlled ladder Trotter example.
ppvm-python/demo/stim_demo.pyNew demo script for running/sampling Stim programs via Python bindings.
julia-benchmarks/benches/truncation-weight.jlJulia-side mirror of the new Rust truncation-weight benchmark.
julia-benchmarks/benches/trotter.jlAdjusts gate order to better align with Heisenberg vs Schrödinger ordering assumptions.
julia-benchmarks/benches/random-circuit.jlAligns circuit construction/benchmark semantics with the Rust benchmark (no truncation).
julia-benchmarks/benches/gates.jlMinor adjustments to which qubits are targeted by rotation benchmarks.
julia-benchmarks/xy_ladder_msd.jlNew Julia script for MSD XY-ladder benchmark comparison vs ppvm.
julia-benchmarks/Manifest.tomlLarge lockfile update to support the Julia benchmark additions/updates.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment threadppvm-python/test/benchmarks/test_trotter.py Outdated
Comment threadcrates/ppvm-runtime/benches/trotter.rs Outdated
@github-actions

github-actionsBot commented Jun 17, 2026

Copy link
Copy Markdown
PR Preview Action v1.8.1
Preview removed because the pull request was closed.
2026-06-19 08:13 UTC

AlexSchuckert added a commit that referenced this pull request Jun 17, 2026
…shim
Brings the bytemuck-based weight() speedup + early-return for uncapped
MaxPauliWeight (and the rest of #126) into the Lindblad branch.
Conflicts resolved: keep stim_demo.py (byte-identical to lindblad-shim's
stim_msd.py rename); regenerate uv.lock against the merged pyproject.
Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
AlexSchuckert added a commit that referenced this pull request Jun 17, 2026
…merging
Brings the bytemuck-based weight() speedup + early-return for uncapped
MaxPauliWeight (and the rest of #126) into the symmetry-merging branch.
Conflicts resolved: keep stim_demo.py (byte-identical to the stim_msd.py
rename); regenerate uv.lock against the merged pyproject.
Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
AlexSchuckert added a commit that referenced this pull request Jun 17, 2026
The expm serial/parallel SpMV parity test built `ExpmOpts { tol,
parallel_threshold }` without the `max_krylov_m` field, so `cargo test`
failed to compile the ppvm-lindblad test target (pre-existing on
lindblad-shim, surfaced when running the full suite after merging #126).
The whole Rust workspace test suite now passes.
Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
Co-authored-by: Copilot Autofix powered by AI <175728472+Copilot@users.noreply.github.com>
CopilotAI review requested due to automatic review settings June 17, 2026 14:45

CopilotAI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Copilot reviewed 16 out of 18 changed files in this pull request and generated no new comments.

@david-pl
david-pl enabled auto-merge (squash) June 19, 2026 08:09
@david-pl
david-pl merged commit 299d340 into mainJun 19, 2026
6 of 7 checks passed
@david-pl
david-pl deleted the david/fix-weight-calc branch June 19, 2026 08:13
Sign up for freeto join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants

@david-pl