Repository navigation
feat(ppvm-pauli-kernels): shared Clifford rules and Pauli row product - #297
Merged
Merged
Conversation
Contributor
|
david-pl
force-pushed
the
david/ppvm-pauli-kernels
branch
from
November 17, 2026 13:05
4ff4a26 to
9d4a644
Compare
david-pl
marked this pull request as ready for review
November 17, 2026 13:05
rafaelha
self-requested a review
November 17, 2026 19:49
rafaelha
approved these changes
Nov 17, 2026
david-pl
force-pushed
the
david/ppvm-pauli-kernels
branch
from
November 18, 2026 07:45
9d4a644 to
76738ec
Compare
david-pl
force-pushed
the
david/ppvm-pauli-kernels
branch
from
November 19, 2026 10:05
76738ec to
3224d54
Compare
A dependency-free crate with the bit-level kernels that Pauli containers share: - `Bits`: the bitwise operators plus `popcount`, for `bool` and the unsigned integers. An integer holds one independent Pauli per bit. - `heisenberg`: one fused rule per Clifford gate (X, Y, Z, H, S, S†, √X, √X†, √Y, √Y†, CX, CZ, CY) for `P ↦ G† P G`, returning the new X/Z bits and a sign-flip mask. - `row_product` / `row_product_phase`: the packed Pauli-word product and the exponent of its iᵏ phase. Rows up to 8 words use an iterator loop and longer rows an indexed one, which benchmarked fastest on each side (arm64). The formulas are proved in a new core-Lean project (`lean/`, no Mathlib) against exact Gaussian-integer gate matrices: each rule equals G† P G, every gate is unitary, and the product phase matches the matrix product per site, on two sites, and as a popcount sum for any length. The Rust tests check the code against tables generated from that matrix model (`mise run lean-tables`) plus algebraic invariants. `lean/README.md` lists what the proofs do not cover. `mise.toml` gains elan and the `lean-build` / `lean-tables` tasks. Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
A Pauli container now gets `Clifford` by implementing `ApplyGateRule`: `apply1` and `apply2` run a whole gate rule over its bits in one pass, and `apply_sign1` (defaulting to `apply1`) lets sign-only gates skip the bit writes. The blanket impl maps each of the 13 gates to its rule in `ppvm_pauli_kernels::heisenberg`, so the formulas exist once and the existing Heisenberg convention is kept. The step is additive: nothing implements `ApplyGateRule` yet, and the hand-written `Clifford` impls in the word crates compile unchanged next to the blanket impl. `CliffordBatch` is not blanket-implemented, so containers can still provide fused batch methods. `Bits` is re-exported so containers need not depend on the kernel crate directly. Tests check gate identities through `Clifford` (S² = Z, √X = HSH, CY = (I⊗S)·CX·(I⊗S†), ...) on every signed two-qubit Pauli, and that a bit-sliced u64 container matches 64 single words on random circuits. Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
`PauliWord` now gets `Clifford` from the `ApplyGateRule` blanket impl instead of 13 hand-written gate methods; each gate's bits come from `ppvm_pauli_kernels::heisenberg`. `apply1`/`apply2` XOR in only the bits that change, drop the sign flip, and keep the existing panics on out-of-range or repeated qubits before any mutation. X, Y and Z stay no-ops via `apply_sign1`. Gates that change no bit skip the hash refresh when the storage is larger than one word; for a single word the branch cost more than the hash, so it always rehashes (measured on arm64). `key_mul_assign` loops over the new per-word kernel `ppvm_pauli_kernels::word_product` instead of carrying its own masks. It keeps the loop local rather than calling `row_product`: behind the call, the hash refresh that follows was ~4 ns slower at 1024 qubits. `row_product` shares the mask formula with `word_product`. `PauliStorage` now also requires `Bits` of its word type, which every storage word already satisfies. Against the previous commit (arm64): mixed gate sequences are unchanged at 64 qubits and 24-34% faster at 256 and 1024; single h/s/cnot at 64 qubits are 10-15% slower in isolation; the product is within ~3%. New tests: the cached hash stays structural after random circuits, one- and four-word storage agree on random circuits (this catches a broken skip condition), and `word_product` matches the matrix-model site table. Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
On main the lossy word implemented only the SymplecticColumns/PhaseTrack primitives, whose blanket Clifford impl never landed, so a bare lossy word had no Clifford; it took part only through Phased<LossyPauliWord>. It now implements ApplyGateRule: - a gate touching any lost site does nothing (as the primitives do); - out-of-range qubits panic via check_qubit, like its bit accessors; - the sign flip is dropped, and X/Y/Z only check bounds; - only changed bits are written, XORed into the raw storage words, and the lazy X/Z hash is invalidated branch-free when something changed. To share that write path, PauliWord's xor_bits2 is now public (doc-hidden) and re-exported from ppvm-pauli-word-2. Writing all four bits through bitvec made cnot 5.2 ns at 64 qubits; with the raw XOR writes the lossy word matches PauliWord (cnot ~2.4 ns, mixed ~2.6 ns/gate, arm64). Tests: a loss-free lossy word matches PauliWord on random circuits, every gate on a lost site is a no-op while gates elsewhere match a plain word, and the cached hash stays structural with lost sites present. Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
`Phased<W>` now gets `Clifford` from the `ApplyGateRule` blanket impl instead of 13 hand-written gates. `apply1`/`apply2` hand the rule to the word's own `ApplyGateRule`, wrapped to record its sign flip, so each word type keeps its tuned write path; `Phased` only updates its ℤ₄ phase. A word that skips a gate (a lost site) never calls the rule, so no flip is recorded. Sign-only gates (X/Y/Z) compute the flip in `Phased`, since `PauliWord` skips those rules entirely; they keep the lost-site check, which is redundant today because lost sites always hold zero X/Z bits. `W` must now also implement `ApplyGateRule`; both word types do. The flip is applied branch-free (`exponent + 2·flip`): on random Paulis it is a coin toss, and the branch mispredicted (~1 ns per gate, arm64). Against the previous commit, mixed gate sequences are 4-19% faster (Phased<PauliWord> 64q 3.18 -> 3.04, 256q 4.58 -> 4.27 ns/gate; Phased<LossyPauliWord> 64q 3.29 -> 3.01, 256q 3.52 -> 2.84). Some single gates repeated in isolation are slower (e.g. h at 64 qubits), others faster. New test: Phased<PauliWord> and a loss-free Phased<LossyPauliWord> agree on random circuits, phase included. Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
They were the building blocks of a blanket Clifford impl that never landed on main, and since the ApplyGateRule ports nothing calls them: every word type now gets Clifford from ApplyGateRule, with the gate formulas in ppvm-pauli-kernels. Drops both traits from ppvm-traits-2 and their impls from PauliWord and LossyPauliWord. The bounds-check tests no longer list the primitives (they still cover all 13 gates), and the lossy word's three primitive tests now drive the corresponding gates (H, S, CNOT, CZ) with the same expected results. Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
… mise config to lean/ Phased reads the sign flip from the rule call, so state that words must call the rule exactly once per applied gate and never on skipped ones. Move elan, its PATH entry and the lean-* tasks into lean/mise.toml so contributors who don't touch lean/ no longer install elan. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
david-pl
force-pushed
the
david/ppvm-pauli-kernels
branch
from
November 19, 2026 13:06
3224d54 to
03455a0
Compare
david-pl
enabled stacked auto-merge (squash)
November 19, 2026 13:06
david-pl
added a commit
that referenced
this pull request
Nov 19, 2026
…leau (#298) > Stacked on #297 (`ppvm-pauli-kernels`). Review that first; this PR's diff is against its branch. Adds `ppvm-tableau-2`, a hybrid stabilizer simulator: `|ψ⟩ = C |χ⟩`, an inverse tableau for the Clifford `C` plus the state `|χ⟩` of the virtual qubits, kept in a representation that can be swapped out. The crate is `publish = false` for now. ## What's in it - **`InverseTableau`** - Physical gates fused into one pass over the rows. - Changes of basis on virtual qubits. - Measurement and reset. - Batched `measure_many`, which runs on a column-major copy when there are many random outcomes. - **`VirtualState` trait**, with `ActiveDormant<DenseState>` as its implementation. It keeps amplitudes only for the active virtual qubits: non-Clifford gates activate them and measurements retire them. - **`GeneralizedTableau<V>`** - Clifford gates, `T`, Pauli rotations, `U3`, and Pauli noise. - Measurement with active qubits. - Loss, leakage and leakage reduction, correlated loss, and asymmetric loss with its survival back-action. - `fork` and `Display`. - **Hot path for pure stabilizer states.** With no active qubits, `measure` and `measure_many` run on the tableau alone. - **`ppvm-traits-2`**: adds the leakage channel traits. ## Testing `tests/dense_matrix.rs` checks the simulator against exact dense matrices and state vectors, sharing no Pauli code with the tableau: - tableau rows match `C† X_q C` and `C† Z_q C`; - measurement probabilities and the post-measurement state match a state vector, including after rotations; - asymmetric loss matches its Kraus operators. ## Benchmarks (noise-free Stim memory circuits, µs per shot, arm64) Harnesses live in `benches/stim-compare`. Stim is a native `-march=native` build of its `TableauSimulator`. | circuit | Stim | `InverseTableau` | `GeneralizedTableau` | |---|---|---|---| | surface d7 | 38.5 | 39.6 | 41.3 | | surface d15 | 691 | 782 | 777 | | surface d31 | 20463 | 14294 | 14716 | | repetition d75 | 170 | 186 | 198 | | color d25 | 2460 | 2025 | 2040 | On the clifft-bench workloads (noise included), `GeneralizedTableau` is 0.13–0.45× the time of the current `ppvm-tableau` on `main`. Known gap: on the repetition code every outcome is deterministic, and `InverseTableau::measure_many` reads each target's row once more just to decide whether to batch. 🤖 Generated with [Claude Code](https://claude.com/claude-code) --------- Co-authored-by: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
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.
This adds a new crate,
ppvm-pauli-kernels, which holds the bit update rules for Pauli conjugation. These are the actual Lean-proven kernels and can be re-used by all consumers via theApplyGateRuletrait, which is used to implementClifford.AI output below.
Adds
ppvm-pauli-kernels, a dependency-free crate with the bit-level Pauli formulas that every PPVM container shares, and ports the-2word types onto it.What's in it
ppvm-pauli-kernelsheisenberg: one Boolean update rule per Clifford gate (P ↦ G† P G), generic overBits, so the same formula updates one Pauli (bool) or 64 at once (u64).row_product/row_product_phase: the packed Pauli-word product and itsiᵏphase.ppvm-traits-2ApplyGateRuleand a blanketCliffordimpl on top of it.SymplecticColumns/PhaseTrackprimitive traits; nothing calls them after the ports.Word types ported to
ApplyGateRule:PauliWord(and it uses the shared product kernel),LossyPauliWord(which gainsCliffordon its own),Phased<W>.Lean proofs (
lean/, core Lean only, no Mathlib). They are checked against exact Gaussian-integer matrices:G† P Gfor its gate (13 gates);The Rust tests compare against tables generated from that model.
lean/README.mdlists what the proofs don't cover.Performance
Mixed gate sequences on
Phased<W>are 4–19% faster than before the port. Details are in thePhased<W>commit message.Stack
This is the base of a stack;
ppvm-tableau-2is stacked on top of it.🤖 Generated with Claude Code