Skip to content

Improved stabilizer decomposition strategies#77

Open
rafaelha wants to merge 2 commits intomainfrom
rafaelha/magic5_decomp
Open

Improved stabilizer decomposition strategies#77
rafaelha wants to merge 2 commits intomainfrom
rafaelha/magic5_decomp

Conversation

@rafaelha
Copy link
Collaborator

Addresses #9 and #10

The main change is in the param-pyzx repo, where the decompositions are implemented.

Here, we now use the magic cat 5 decomposition
image

This decomposition reduces to the following equation from https://arxiv.org/pdf/2202.09202 when theta=pi/4:
image

Additionally, now the cutting decomposition is used. This simply corresponds to decomposing a single spider with the |0> and |1> state -- this case was previously handled already when only a single non-Clifford state remained.

The following three strategies are now supported:

  • cat5 (default)
  • bss
  • cutting

- Added a `strategy` parameter to `compile_sampler` and `compile_detector_sampler` methods in `src/tsim/circuit.py` to allow selection of stabilizer rank decomposition strategies ("cat5", "bss", "cutting").
- Updated corresponding classes in `src/tsim/sampler.py` and `src/tsim/compile/pipeline.py` to utilize the new strategy parameter.
- Modified integration tests in `test/integration/test_sampler.py` to validate behavior with different strategies.
- Updated `pyproject.toml` and `uv.lock` to include the `pyzx-param` package from a specific Git repository version.
@github-actions
Copy link
Contributor

github-actions bot commented Mar 25, 2026

☂️ Python Coverage

current status: ✅

Overall Coverage

Lines Covered Coverage Threshold Status
1969 1914 97% 0% 🟢

New Files

No new covered files...

Modified Files

File Coverage Status
src/tsim/circuit.py 100% 🟢
src/tsim/compile/pipeline.py 100% 🟢
src/tsim/compile/stabrank.py 100% 🟢
src/tsim/sampler.py 97% 🟢
TOTAL 99% 🟢

updated for commit: abf4f0f by action🐍

@github-actions
Copy link
Contributor

github-actions bot commented Mar 25, 2026

PR Preview Action v1.8.1

QR code for preview link

🚀 View preview at
https://queracomputing.github.io/tsim/pr-preview/pr-77/

Built to branch gh-pages at 2026-03-25 20:58 UTC.
Preview will be ready when the GitHub Pages deployment is complete.

Copy link

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

Adds a decomposition-strategy parameter to the sampling/compilation pipeline so callers can choose between different stabilizer-rank decompositions (cat5/bss/cutting), and expands integration coverage to exercise all supported strategies.

Changes:

  • Thread strategy through Circuit.compile_* → sampler classes → compilation pipeline → stabilizer-rank decomposition (find_stab*).
  • Update integration tests to run under each decomposition strategy.
  • Pin pyzx-param to a specific git revision via uv sources / lockfile to pick up the new decomposition implementations.

Reviewed changes

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

Show a summary per file
File Description
src/tsim/circuit.py Exposes strategy on public sampler compilation methods and forwards it to samplers.
src/tsim/sampler.py Stores/threads strategy into compile_program for both sampling and probability estimation.
src/tsim/compile/pipeline.py Accepts strategy and passes it into stabilizer-rank decomposition during component compilation.
src/tsim/compile/stabrank.py Passes strategy into pyzx_param.simulate.replace_* decomposition hooks.
test/integration/test_sampler.py Parametrizes key integration tests over cat5, bss, and cutting.
pyproject.toml Adds [tool.uv.sources] override for pyzx-param to a git revision.
uv.lock Locks pyzx-param to the git revision; also changes resolution details for doc deps.
Comments suppressed due to low confidence (1)

src/tsim/compile/stabrank.py:63

  • The find_stab docstring still says it "decomposes T gates via BSS decompositions", but decomposition is now strategy-dependent (cat5/bss/cutting). Please update this description so it doesn’t imply BSS is always used.
    This is the main entry point for stabilizer rank decomposition. It first removes
    U3 phases, then decomposes T gates via BSS decompositions, producing a sum of
    scalar graphs.

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

Comment on lines +97 to +99
[tool.uv.sources]
pyzx-param = { git = "https://github.com/rafaelha/pyzx", rev = "f4d440c299b71f576ccc369886ba319fb51dd2e2" }

Copy link

Copilot AI Mar 25, 2026

Choose a reason for hiding this comment

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

The project code now imports DecompositionStrategy and passes strategy=... into pyzx_param.simulate.replace_* APIs. However, [project.dependencies] still allows pyzx-param>=0.9.2 from PyPI, while only uv users will pick up the git revision via [tool.uv.sources]. To avoid broken installs for pip/packaging users, either (a) bump the minimum released pyzx-param version that contains these APIs, or (b) switch the main dependency to a direct URL reference (PEP 508) matching this git rev.

Copilot uses AI. Check for mistakes.
@rafaelha rafaelha changed the title Enhance circuit sampling: Introduce decomposition strategy parameter Improved stabilizer decomposition strategies Mar 25, 2026
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
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