Skip to content

Support Stim tags and export Stim non-Clifford gates#688

Open
ChenZhao44 wants to merge 17 commits intomainfrom
chen/stim-non-clifford
Open

Support Stim tags and export Stim non-Clifford gates#688
ChenZhao44 wants to merge 17 commits intomainfrom
chen/stim-non-clifford

Conversation

@ChenZhao44
Copy link
Contributor

@ChenZhao44 ChenZhao44 commented Jan 28, 2026

This PR includes changes to support stim tags for Stim circuit analysis. It also exports the non-Clifford gates explicitly in the dialect, allowing users to run potential simulations with Tsim.

To support the Stim tag, I introduced a base class for all Stim native statements, including gate, noise, collapse, and annotation. Those instructions are inherent from the StimStatement base class that includes the tag.

One thing I would like to mention is that the tag now is typed as tag: str = info.attribute(types.String, default=None) instead of str | None. I couldn't figure out how to make the types.UnionType work for attributes. Probably it is a bug of the UnionType. Therefore, the current type will result in an error when the user explicitly sets tag=None. For example,

from bloqade import stim

@stim.main
def stim_kernel():
    stim.x(tag=None, targets=(0, 1))

will not pass the compilation.

ChenZhao44 and others added 15 commits January 26, 2026 16:42
Add tests for tag attribute on collapse dialect statements:
- test_measurement_with_tag (MZ)
- test_reset_with_tag (RZ)
- test_ppmeasurement_with_tag (MPP)

These tests will fail until StimStatement base class is implemented.

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
- Create StimStatement base class with tag attribute
- Update Measurement, Reset, PPMeasurement to inherit from StimStatement
- Update emit methods to include tag in output
- Fix test expectations for float formatting

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
Add tests for tag attribute on noise dialect statements:
- test_depolarize_with_tag (Depolarize1)
- test_pauli_channel_with_tag (PauliChannel1)

These tests will fail until noise statements inherit from StimStatement.

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
Update all noise statements (Depolarize1, Depolarize2, PauliChannel1,
PauliChannel2, XError, YError, ZError, TrivialError, QubitLoss, etc.)
to inherit from StimStatement base class, which provides the tag attribute.

Update emit methods to format instructions with optional tag annotations.

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
Add tests for TICK, DETECTOR, OBSERVABLE_INCLUDE, and QUBIT_COORDS
instructions with tag annotations. Tests fail because the tag attribute
doesn't exist on these statements yet.

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
Update Tick, Detector, ObservableInclude, and QubitCoordinates
statements to inherit from StimStatement base class, which provides
the tag attribute.

Update emit methods to format instructions with optional tag annotations.
Fix test API usage for detector, observable_include, and qubit_coordinates.

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
Update all wrapper functions to expose the tag parameter for:
- Gate dialect (x, y, z, h, s, t, cx, cy, cz, swap, spp, etc.)
- Collapse dialect (mz, my, mx, mzz, myy, mxx, mpp, rz, ry, rx)
- Noise dialect (depolarize1, depolarize2, pauli_channel1, etc.)
- Auxiliary dialect (tick, detector, observable_include, qubit_coords)

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
Refactor Gate and SPP to inherit from StimStatement instead of
ir.Statement, removing duplicate tag attribute definitions. This
centralizes the tag functionality in the StimStatement base class.

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
@ChenZhao44 ChenZhao44 requested a review from rafaelha January 28, 2026 02:07
@github-actions
Copy link
Contributor

github-actions bot commented Jan 28, 2026

☂️ Python Coverage

current status: ✅

Overall Coverage

Lines Covered Coverage Threshold Status
10838 9571 88% 0% 🟢

New Files

File Coverage Status
src/bloqade/stim/dialects/stim_statement.py 100% 🟢
TOTAL 100% 🟢

Modified Files

File Coverage Status
src/bloqade/stim/_init_.py 100% 🟢
src/bloqade/stim/_wrappers.py 100% 🟢
src/bloqade/stim/dialects/auxiliary/emit.py 100% 🟢
src/bloqade/stim/dialects/auxiliary/stmts/annotate.py 100% 🟢
src/bloqade/stim/dialects/collapse/emit_str.py 100% 🟢
src/bloqade/stim/dialects/collapse/stmts/measure.py 100% 🟢
src/bloqade/stim/dialects/collapse/stmts/pp_measure.py 100% 🟢
src/bloqade/stim/dialects/collapse/stmts/reset.py 100% 🟢
src/bloqade/stim/dialects/gate/emit.py 100% 🟢
src/bloqade/stim/dialects/gate/stmts/base.py 100% 🟢
src/bloqade/stim/dialects/gate/stmts/non_clifford.py 100% 🟢
src/bloqade/stim/dialects/gate/stmts/pp.py 100% 🟢
src/bloqade/stim/dialects/noise/emit.py 100% 🟢
src/bloqade/stim/dialects/noise/stmts.py 100% 🟢
TOTAL 100% 🟢

updated for commit: dc49446 by action🐍

@codecov
Copy link

codecov bot commented Jan 28, 2026

Codecov Report

✅ All modified and coverable lines are covered by tests.

📢 Thoughts on this report? Let us know!

- Sort imports alphabetically in src/bloqade/stim/__init__.py
- Fix import order in collapse/stmts/pp_measure.py
- Format long line in test_stim_tag.py per black requirements

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
@rafaelha rafaelha requested a review from kaihsin January 28, 2026 14:57
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.

1 participant