pauliverse: speed up random-outcome measurements by choosing a cheaper pivot

Open
#273 0 comments 0 reactions 0 assignees View on GitHub

Maintainers usually reply within 1 day

@Mohini204 is already working on this.

Since Nov 17, 2026.

  • #274 by @Mohini204 — open

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 measure functions. FaultySimulation gets it via OutcomeCompleteSimulation, and the phased simulator passes image_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, OutcomeFreeSimulation and OutcomeCompleteSimulation, built on commit d3969df. PhasedOutcomeCompleteSimulation is not done yet.
  • The prototype passes all binar, paulimer and pauliverse tests. measure_equivalence_test.rs needed an update: it checks that measure and measure_with_hint give the same state_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

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

More from microsoft/qdk-ec

All issues in microsoft/qdk-ec

Similar issues

More Rust issues

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.