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

Aperta
#273 0 commenti 0 reazioni 0 assegnatari Vedi su GitHub

I maintainer di solito rispondono entro 1 giorno

@Mohini204 ci sta già lavorando.

Dal 17/11/2026.

  • #274 di @Mohini204 — aperta

Valutazione

Difficoltà
4/5
Tempo stimato
3-5 giorni
Idoneità per principianti
48/100
Tipo di issue
Funzionalità
Chiarezza
Specificata chiaramente
Stato di attività
Attiva
Stack tecnologico
rust
Ambito
performance

Direzione di ricerca

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.

Scritto dal modello di indicizzazione a partire dal testo della issue.

Descrizione

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.
Lingua principale
Rust
Stelle
69
Fork
25
Merge medio
2g 22h
PR unite (30g)
48

Preparare l'ambiente

Come iniziare

  1. Leggi tutta la issue e poi la guida ai contributi del progetto.
  2. Commenta sulla issue per dire che te ne occupi tu — evita che due persone facciano lo stesso lavoro.
  3. Fai un fork del repository e lavora su un branch.
  4. Apri una pull request che faccia riferimento al numero della issue.

Altre issue di microsoft/qdk-ec

Tutte le issue di microsoft/qdk-ec

Issue simili

Altre issue su Rust

Ricevi le nuove issue nella tua casella

Un breve riepilogo di issue GitHub adatte ai principianti.