Skip to content

Add SPP and SPP_DAG instructions#97

Merged
rafaelha merged 15 commits intomainfrom
rafaelha/spp_instruction
Apr 7, 2026
Merged

Add SPP and SPP_DAG instructions#97
rafaelha merged 15 commits intomainfrom
rafaelha/spp_instruction

Conversation

@rafaelha
Copy link
Copy Markdown
Collaborator

@rafaelha rafaelha commented Apr 7, 2026

Summary

  • Implement SPP and SPP_DAG (generalized S gate) that phase the -1 eigenspace of Pauli product observables by i or -i
  • Reuses the MPP auxiliary qubit pattern: entangle with Pauli product, apply S/S_DAG, then uncompute
  • Extracted shared _apply_pauli_controls helper from MPP
  • Supports inverted targets (!) which toggle between SPP and SPP_DAG behavior
  • Supports multi-qubit Pauli products (e.g., SPP X0*Y1*Z2) and multiple products per instruction

Closes #74

Test plan

  • Unit tests: parsing single/multi-qubit products, SPP_DAG, multiple products
  • Integration tests verifying equivalence to known gates:
    • SPP Z0 = S, SPP_DAG Z0 = S_DAG
    • SPP X0 = SQRT_X, SPP !X0 = SQRT_X_DAG
    • SPP X0*X1 = SQRT_XX, SPP Y0*Y1 = SQRT_YY, SPP Z0*Z1 = SQRT_ZZ

🤖 Generated with Claude Code

rafaelha and others added 5 commits April 6, 2026 21:09
Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
@github-actions
Copy link
Copy Markdown
Contributor

github-actions bot commented Apr 7, 2026

PR Preview Action v1.8.1
Preview removed because the pull request was closed.
2026-04-07 03:03 UTC

@github-actions
Copy link
Copy Markdown
Contributor

github-actions bot commented Apr 7, 2026

☂️ Python Coverage

current status: ✅

Overall Coverage

Lines Covered Coverage Threshold Status
2201 2128 97% 0% 🟢

New Files

No new covered files...

Modified Files

File Coverage Status
src/tsim/circuit.py 94% 🟢
src/tsim/core/instructions.py 98% 🟢
src/tsim/core/parse.py 94% 🟢
src/tsim/utils/diagram.py 94% 🟢
TOTAL 95% 🟢

updated for commit: d50c1ee by action🐍

Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

Implements support for Stim’s SPP / SPP_DAG instructions in tsim by translating them into an auxiliary-qubit gadget, plus associated parsing, documentation, and tests.

Changes:

  • Added spp core instruction (and extracted _apply_pauli_controls shared with mpp).
  • Extended the Stim circuit parser to recognize and expand SPP / SPP_DAG (including !-inverted targets and multi-product instructions).
  • Added unit/integration tests and updated the overview demo notebook with the new instructions.

Reviewed changes

Copilot reviewed 5 out of 5 changed files in this pull request and generated 6 comments.

Show a summary per file
File Description
src/tsim/core/instructions.py Adds spp gadget implementation and extracts shared _apply_pauli_controls.
src/tsim/core/parse.py Parses SPP / SPP_DAG targets into Pauli products and dispatches to spp.
test/unit/core/test_parse.py Adds basic parsing tests ensuring SPP/SPP_DAG don’t create measurement records.
test/integration/test_sampler_circuits.py Adds probability-based equivalence tests for SPP/SPP_DAG vs known gates.
docs/demos/overview.ipynb Documents SPP / SPP_DAG semantics and shows a diagram example.

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

Comment on lines +263 to +288
class TestParseSPP:
"""Tests for parsing SPP and SPP_DAG instructions."""

def test_spp_single_pauli(self):
"""SPP Z0 should parse without adding measurement records."""
circuit = stim.Circuit("SPP Z0")
b = parse_stim_circuit(circuit)
assert len(b.rec) == 0

def test_spp_product(self):
"""SPP X0*Z1 should parse without adding measurement records."""
circuit = stim.Circuit("SPP X0*Z1")
b = parse_stim_circuit(circuit)
assert len(b.rec) == 0

def test_spp_dag_single_pauli(self):
"""SPP_DAG Z0 should parse without adding measurement records."""
circuit = stim.Circuit("SPP_DAG Z0")
b = parse_stim_circuit(circuit)
assert len(b.rec) == 0

def test_spp_multiple_products(self):
"""SPP with multiple products should parse correctly."""
circuit = stim.Circuit("SPP X0 Y1*Z2")
b = parse_stim_circuit(circuit)
assert len(b.rec) == 0
Copy link

Copilot AI Apr 7, 2026

Choose a reason for hiding this comment

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

These new parsing tests assume the installed stim supports SPP/SPP_DAG. The project metadata currently allows stim>=1.0.0, which may permit versions that can't parse these instructions, causing test/runtime failures in downstream environments. Consider bumping the minimum supported stim version (or conditionally skipping these tests when the gate is unavailable).

Copilot uses AI. Check for mistakes.
rafaelha added 3 commits April 6, 2026 22:39
…per function `_iter_pauli_products` to streamline the extraction of Pauli products and their inversion status from circuit instructions.
…e a few new-ish Stim instructions that are not yet supported.
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

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 7 out of 7 changed files in this pull request and generated 4 comments.


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

rafaelha and others added 2 commits April 6, 2026 22:51
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
@rafaelha rafaelha merged commit 2fad404 into main Apr 7, 2026
10 checks passed
@rafaelha rafaelha deleted the rafaelha/spp_instruction branch April 7, 2026 03:01
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.

Add 'SPP' and 'SPP_DAG' Instruction

2 participants