Skip to content

[codex] Specialize ppvm-runtime depolarizing noise fast paths - #54

Merged
Roger-luo merged 2 commits into
mainfrom
codex/runtime-micro-overall-pr
Apr 12, 2026
Merged

Roger-luo merged 2 commits into
mainfrom
codex/runtime-micro-overall-pr

Conversation

@Roger-luo

Copy link
Copy Markdown
Collaborator

Summary

  • specialize ppvm-runtime single-qubit noise scaling to use bit-based Pauli classification with precomputed factors
  • replace depolarize2's generic 15-entry probability expansion with the closed-form uniform two-qubit depolarizing factor
  • record the kept and discarded autotune iterations under docs/autotune/runtime-micro-overall/

Why

The ppvm-runtime microbenchmark suite showed the noise group as a meaningful opportunity for end-to-end improvement. The kept change removes avoidable branching and coefficient setup from the depolarizing paths while preserving the existing generic two-qubit Pauli-error implementation.

Benchmark Notes

Fresh cargo bench -p ppvm-runtime --bench micro -- --noplot on a clean branch based on origin/main produced these representative medians:

  • noise/pauli_error: 279.81 ns -> 187.02 ns
  • noise/depolarize: 272.73 ns -> 187.85 ns
  • noise/depolarize2: 509.21 ns -> 242.33 ns
  • noise/two_qubit_pauli_error: 523.07 ns -> 447.96 ns
  • noise/amplitude_damping: 524.70 ns -> 473.04 ns

Validation

  • cargo test -p ppvm-runtime
  • cargo bench -p ppvm-runtime --bench micro -- --noplot

@github-actions

github-actions Bot commented Apr 12, 2026 •

Copy link
Copy Markdown
PR Preview Action v1.8.1
Preview removed because the pull request was closed.
2026-04-12 18:36 UTC

@Roger-luo
Roger-luo marked this pull request as ready for review April 12, 2026 18:05
Copilot AI review requested due to automatic review settings April 12, 2026 18:05

Copilot AI 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

This PR optimizes ppvm-runtime depolarizing/noise hot paths to reduce per-term branching and setup overhead, and records the autotuning results used to select the kept optimization.

Changes:

  • Specialized single-qubit pauli_error/depolarize scaling via bit-based Pauli classification with precomputed factors.
  • Replaced depolarize2’s 15-entry probability expansion with the closed-form two-qubit depolarizing scaling factor.
  • Added autotune logs/metrics documenting kept vs. discarded iterations.

Reviewed changes

Copilot reviewed 3 out of 3 changed files in this pull request and generated 1 comment.

File Description
docs/autotune/runtime-micro-overall/metric.toml Captures baseline and iteration medians for the overall runtime microbenchmarks.
docs/autotune/runtime-micro-overall/log.md Documents hypotheses, outcomes, and the rationale for keeping the noise specialization.
crates/ppvm-runtime/src/sum/noise.rs Implements faster single-/two-qubit depolarizing paths using bit-based Pauli checks and closed-form scaling.

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

Comment on lines 19 to +22
fn pauli_error(&mut self, addr0: usize, p: [<T as Config>::Coeff; 3]) {
self.scale(|k, v| {
match k.get(addr0) {
Pauli::I => {}
Pauli::X => {
*v *= 1.0f64 - 2.0f64 * p[1].clone() - 2.0f64 * p[2].clone();
}
Pauli::Y => {
*v *= 1.0f64 - 2.0f64 * p[0].clone() - 2.0f64 * p[2].clone();
}
Pauli::Z => {
*v *= 1.0f64 - 2.0f64 * p[0].clone() - 2.0f64 * p[1].clone();
}
Pauli::L => {}
};
let x_factor = 1.0f64 - 2.0f64 * p[1].clone() - 2.0f64 * p[2].clone();
let z_factor = 1.0f64 - 2.0f64 * p[0].clone() - 2.0f64 * p[1].clone();
let y_factor = 1.0f64 - 2.0f64 * p[0].clone() - 2.0f64 * p[2].clone();

Copilot AI Apr 12, 2026

Copy link

Choose a reason for hiding this comment

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

pauli_error behavior was refactored to rely on bit-based Pauli classification (pauli_code + get_lbit), but there is no unit test that directly exercises PauliError::pauli_error (unlike depolarize / depolarize2). Adding a regression test that checks the scaling for I/X/Y/Z (and that L is unchanged) would help catch any future mismatches between the bit encoding and the Pauli enum mapping.

Copilot uses AI. Check for mistakes.

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

@copilot apply changes based on this feedback

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Added a regression test test_pauli_error in crates/ppvm-runtime/tests/noise.rs (commit 050cb02) that verifies the coefficient scaling for each Pauli at the target qubit:

  • I: coefficient unchanged
  • X: scales by 1 - 2*py - 2*pz
  • Y: scales by 1 - 2*px - 2*pz
  • Z: scales by 1 - 2*px - 2*py
  • L: coefficient unchanged (lost qubit is skipped via the get_lbit guard)

@Roger-luo
Roger-luo enabled auto-merge (squash) April 12, 2026 18:31
@Roger-luo
Roger-luo merged commit 6a5dbc8 into main Apr 12, 2026
7 checks passed
@Roger-luo
Roger-luo deleted the codex/runtime-micro-overall-pr branch April 12, 2026 18:35
Sign up for free to 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.

3 participants