Skip to content

[STIM] Support Generalized Pauli Product Gates - #3556

Open
João Boechat (joao-boechat) wants to merge 10 commits into
mainfrom
joaoboechat/support-generalized-pauli-product-gates
Open

[STIM] Support Generalized Pauli Product Gates#3556
João Boechat (joao-boechat) wants to merge 10 commits into
mainfrom
joaoboechat/support-generalized-pauli-product-gates

Conversation

@joao-boechat

@joao-boechat João Boechat (joao-boechat) commented Aug 7, 2026

Copy link
Copy Markdown
Contributor

This PR adds QIR compiler support for Stim's generalized Pauli-product gates: MPP, SPP, and SPP_DAG. For more info on how they work, I recommend the official stim docs.

High-level changes

  • Lexer: Starts treating Pauli targets (e.g. X1, Y1, Z1) and loss targets (e.g. L1) as separate tokens, rather than the general "instruction_name".
  • Parser: Groups *-connected Pauli targets into a single PauliProduct AST node. It combines factor negations with XOR and represents each term as a PauliFactor.
  • Compiler: Adds shared validation, canonicalization, and emission for generalized Pauli products.

Canonicalization

Before emission, the compiler canonicalizes each product by sorting factors by qubit, multiplying repeated same-qubit Paulis, and tracking the resulting phase i^k. Odd phases are rejected because they produce an anti-Hermitian product. A -1 phase negates the canonical product, while factors reducing to identity are removed.

Decomposition

To emit the product, the compiler:

  1. Rotates each Pauli factor into the Z basis.
  2. Accumulates the product parity onto one focus qubit using CNOTs.
  3. Performs the central operation:
    • MPP: measure the focus qubit.
    • SPP: apply S.
    • SPP_DAG: apply S_DAG.
  4. Reverses the CNOTs and basis rotations.

Inversion logic

For MPP, negation flips the measurement result. For phase gates, negation reverses the phase direction:

let adjoint = (instruction.name == "SPP_DAG") ^ negated;

Identity products

An MPP target whose factors all cancel measures the identity, which is deterministic but still has to append a result to the measurement record. We don't have an instruction that appends to the measurement record without acting on a qubit, so these targets are rejected for now. Once that instruction exists, MPP will be able to support them.

SPP and SPP_DAG don't have this limitation: phasing the identity is a global phase, so those targets are emitted as no-ops.

@joao-boechat João Boechat (joao-boechat) changed the title Joaoboechat/support generalized pauli product gates [STIM] Support Generalized Pauli Product Gates Aug 7, 2026
Comment thread source/compiler/stim_compiler/src/qir.rs Dismissed
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.

2 participants