Repository navigation
perf(sampler): compile stabilizer-rank components of one shape once - #302
Conversation
output_indices is a static field of CompiledComponent and so part of the jit cache key: every component compiled on its own, and the ones with a single output were run eagerly to avoid that. Sampling does not read the field. Without it components of the same shape share one compilation, and a 20-qubit Clifford circuit with cat5 samples in 6.6 ms instead of 55 ms. Seeded samples are unchanged.
|
👋 Thanks for opening your first pull request against Tsim! A quick note on contribution terms: by submitting this PR you A few things that will speed up review:
We'll get to your PR as soon as we can. Thanks for contributing! |
Codex Review Summary: ✅ CompletedThis comment shows the latest Codex review activity on this pull request.
ℹ️ About Codex in GitHubYour team has set up Codex to review pull requests in this repo. Reviews are triggered when you
Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings. |
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: dd0d1602d1
ℹ️ About Codex in GitHub
Codex has been enabled to automatically review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
When you sign up for Codex through ChatGPT, Codex can also answer questions or update the PR, like "@codex address that feedback".
Codecov Report✅ All modified and coverable lines are covered by tests. 📢 Thoughts on this report? Let us know! |
|
Thanks for the contribution and improvement. I'll go ahead and merge this. Yes - I am wondering if the stabilizer backend is really useful still or used in practice. I personally have not seen any cases practical cases where it performs better than the active statevector backend (from Clifft/SymFT). Do you have any usecases or opinion on whether the stabilizer rank backend is still needed? On the other hand, I have been having some discussions on adding an approximate stabilizer decomposition backend, which could be promising for circuits with lots of small angle rotations. |
|
Thanks for merging, and for the quick review 🙏 Honest answer: i don't have a case where it wins either. But i should say what that's based on, because it's less than it sounds. Everything i ran is bloqade-tsim 0.1.5, so What i can say is that on random Clifford+T circuits (20 to 100 qubits, up to 24 T gates, CPU) the stabilizer-rank path in 0.1.5 was slower than Clifft and SymFT at every T count i tried, and the gap grows quickly with the T count. Beyond 24 T gates i stopped running it. That's a narrow set tho (few qubits active at once, T gates only, no GPU run of cat5), so i wouldn't read it as "never". My guess is it could still matter where many qubits are non-Clifford-active at the same time with few T gates in total, so a dense vector over the active qubits doesn't fit. Only a guess, i have no such circuit and no use of my own that needs it. If it helps i can run main with |
With
strategy="cat5"a pure Clifford circuit samples slower than the same circuit with 8 T gates: 55 ms against 14 ms at 20 qubits and 1000 shots. I ran into this while benchmarking and it took me a while to see why.Without T gates the circuit falls apart into one component per measured qubit, each with one output, and
sample_componentruns those without jit, about 2.8 ms a piece.My first try was to jit them anyway. That made it worse: the first
sample(1000)went from 1.8 s to 6.9 s. Turns outoutput_indicesis a static field ofCompiledComponent, so it ends up in the jit cache key and every component compiles on its own, even though they all have the same shape. Sampling never reads that field.So this hands the component to
_sample_component_jitwithout it and drops the one-output special case. Components of the same shape then share one compilation. It is four lines insample_component.1000 shots, 16 cores of a Xeon Platinum 8468, every number from a fresh process:
The last two rows have one big component and don't move beyond noise. For the 1-qubit circuit the first call on this branch took 2.2 s in one run and 1.0 s in the repeat; main took 1.6 s both times. Peak RSS for the circuits in the table moves by 22 MB at most. Across all my runs the biggest change was 173 MB less, at 100000 shots.
With a fixed seed I get the same samples as on main in every case I ran: the circuits above, a Clifford block next to a T block, a detector sampler, and batch sizes 1, 1000 and 100000.
I also tried sampling all one-output components in one jitted call. A bit faster per sample (4.4 ms at 20 qubits), but the compile grows with the number of components: 10.7 s for the first call at 80 qubits. Dropped.
What I ran:
coverage run -m pytest testpasses. There is one new test; it fails on main (6 calls of_sample_componentfor 2 shapes) and passes here, and it checks the samples against the eager path.isort,black,ruff,pyright src test dev,deptry: clean.What I didn't:
cat5.bssandcuttinggo through the same function and the existing tests pass for them.tsim-dev bench: it times the default strategy, which doesn't go through this function.I saw in AGENTS.md that the stabilizer-rank strategies are provisional. If they're on the way out and this isn't worth carrying, just close it, no hard feelings.