pauliverse: speed up random-outcome measurements by choosing a cheaper pivot
Maintainers usually reply within 1 day
Assessment
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Newbie friendliness
- 48/100
- Issue type
- Feature
- Clarity
- Clearly specified
- Activity status
- Active
- Tech stack
- rust
- Domain
- performance
Research direction
Start with the four measure implementations named in the issue and trace how each chooses a pivot; read the existing measure_equivalence_test.rs and simulation_benchmark.rs for their current expectations and benchmark setup. Implementing the rule spans simulator state and tests, and the issue calls for a new Criterion benchmark. Done means all four simulators use the rule, random circuit outcomes still match the current behavior, and benchmark results report before and after measurements.
Written by the indexing model from the issue text.
Description
Is your feature request related to a problem? Please describe.
In a downstream simulator running Clifford circuits on over 1,000 qubits (S, √X and CZ gates, with frequent single-qubit Z measurements and resets), measurements with a random outcome were about 3% of operations but about 83% of the time spent in pauliverse.
Most of that time goes to the update after the pivot is chosen. The pivot is a position where the observable's preimage has an X or Y. update_encoder_for_random_outcome then updates every stored row that has an X or Y at that position. In this workload, that was about 160 rows per measurement on average.
Any candidate position gives the same outcomes, but the number of rows to update can differ a lot between candidates. All four simulators currently take the first candidate, using x_bits().support().next() (OutcomeSpecificSimulation, OutcomeFreeSimulation, OutcomeCompleteSimulation, PhasedOutcomeCompleteSimulation). So there is room to speed up these measurements by choosing the pivot differently.
Describe the solution you'd like
Among the candidates, choose the position that was the pivot most recently. If none of them has been a pivot yet, choose the first one, as today.
Pseudocode:
last_pivot[i] = when position i was last chosen as the pivot (0 if never)
clock = number of pivots chosen so far
candidates = positions where preimage(O) has an X or Y
k = the candidate with the largest last_pivot (all 0: the first candidate)
clock += 1
last_pivot[k] = clock
Why it helps: the rows to update are those with an X or Y at the pivot. Right after a position serves as the pivot, few rows have one there; after a single-qubit Z measurement, only one does. Later gates spread X and Y to more rows over time. The first candidate may not have been a pivot for a long time, or ever, so many rows may have an X or Y there. The most recent pivot has usually had the least time for that to happen.
The pivot changes only how the state is written down, not the state. So which measurements are random, their outcomes, and the random bits they use all stay the same. state_encoder() still encodes the current state, as documented, but its rows can differ from today's, since a state has many valid encoders.
Added cost: one counter per qubit, and visiting every candidate instead of stopping at the first. Both are small compared with the row updates.
I'd like to work on this in one pauliverse PR that:
- uses the rule in all four
measurefunctions.FaultySimulationgets it viaOutcomeCompleteSimulation, and the phased simulator passesimage_z(k)as its hint, which is valid for any candidate; - adds tests on random circuits checking that outcomes match today's rule;
- adds a Criterion benchmark for circuits with frequent measurements and resets.
Describe alternatives you've considered
I replayed four recorded operation traces from the workload above (about 47,000 random-outcome measurements) and counted row updates. The replay used a copy of OutcomeSpecificSimulation in which the pivot rule can be swapped. All changes below are relative to today's first-candidate rule:
- The candidate with the fewest rows to update. This is the cheapest pivot for each measurement: 63% fewer row updates, against 55% fewer with the proposed rule. But finding it means counting the rows for every candidate, about 236 per measurement. The search alone took about 120 times as long as a whole random-outcome measurement takes today. Keeping a count per position up to date instead would add work to gates as well, while random-outcome measurements are only about 3% of operations.
- The last candidate: 4% fewer row updates.
- The candidate that was the pivot least recently: 5 times as many row updates. This is the opposite of the proposed rule, and shows that how recently a position was the pivot matters.
Additional context
- I have a prototype in
OutcomeSpecificSimulation,OutcomeFreeSimulationandOutcomeCompleteSimulation, built on commit d3969df.PhasedOutcomeCompleteSimulationis not done yet. - The prototype passes all binar, paulimer and pauliverse tests.
measure_equivalence_test.rsneeded an update: it checks thatmeasureandmeasure_with_hintgive the samestate_encoder(), and it built the hint from the first candidate. It now builds the hint with the new rule. - With the prototype, the downstream simulator's run time on this workload went from 42.7 s to 40.2 s. That is 6.0% faster: the median of 7 rounds that each ran both versions, and it was faster in every round. Its output was identical.
- In a replay of all 24 recorded traces of this workload (about 281,000 random-outcome measurements), the proposed rule needed 54% fewer row updates than today's rule and reproduced every recorded outcome.
- So far I have measured only this workload. The PR will include before/after numbers from the new Criterion benchmark and from the existing
simulation_benchmark. - Environment: rustc 1.97.1, Windows 11 x64, AMD EPYC 7763.
- Dominant language
- Rust
- Stars
- 69
- Forks
- 25
- Avg merge
- 2d 22h
- Merged PRs (30d)
- 48
Getting set up
- No Dockerfile or Docker Compose file
- No pull request template
- Read the contributing guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
More from microsoft/qdk-ec
-
Difficulty 2/5 1-3 hours Newbie friendliness 75/100
Maintainers usually reply within 1 day
-
Difficulty 2/5 1-3 hours Newbie friendliness 82/100
Maintainers usually reply within 1 day
-
Difficulty 3/5 1-2 days Newbie friendliness 72/100
Maintainers usually reply within 1 day
-
Difficulty 4/5 3-5 days Newbie friendliness 35/100
Maintainers usually reply within 1 day
-
Difficulty 5/5 Over a week Newbie friendliness 25/100
Maintainers usually reply within 1 day
All issues in microsoft/qdk-ec
Similar issues
-
chat compiler P1
Difficulty 2/5 1-3 hours Newbie friendliness 76/100
HerringtonDarkholme/hd-lang#2793 ·
Maintainers usually reply within 1 day
-
bug
Difficulty 2/5 1-3 hours Newbie friendliness 78/100
Maintainers usually reply within 1 day
-
security-advisory
Difficulty 2/5 1-3 hours Newbie friendliness 78/100
MinBZK/regelrecht#2173 ·
-
ci
Difficulty 2/5 1-3 hours Newbie friendliness 88/100
jonathanong/no-mistakes#5804 ·
-
triage: failed
Difficulty 2/5 1-3 hours Newbie friendliness 68/100
oxc-project/tsrs#1277 · 1 comment ·
Maintainers usually reply within 1 day