Improved stabilizer decomposition strategies#77
Merged
Conversation
- 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.
Contributor
☂️ Python Coverage
Overall Coverage
New FilesNo new covered files... Modified Files
|
Contributor
|
Contributor
There was a problem hiding this comment.
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
strategythroughCircuit.compile_*→ sampler classes → compilation pipeline → stabilizer-rank decomposition (find_stab*). - Update integration tests to run under each decomposition strategy.
- Pin
pyzx-paramto a specific git revision viauvsources / 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_stabdocstring 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.
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
…faelha/magic5_decomp
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.
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

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

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: