Simulate the gates before the first mid-circuit measurement only once

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

Nobody has claimed this yet.

Assessment

Difficulty
4/5
Estimated time
3-5 days
Newbie friendliness
56/100
Issue type
Feature
Clarity
Clearly specified
Activity status
Active
Tech stack
rust
Domain
performance

Research direction

Start at the shortcut: note in src/circuit.rs:408 and trace how instructions are simulated for each shot, stopping at the first Measure or Reset. Then inspect the QuantumBackend implementations to see how CPU and GPU state buffers are managed. Done means the cached prefix is reused when two states fit in memory, with the current behavior retained when they do not.

Written by the indexing model from the issue text.

Description

enhancement
What you want to do

A circuit that measures part-way is simulated from scratch for every shot, including all the gates
before the first measurement, whose result is the same every time. For a deep state-preparation
circuit followed by one mid-circuit measurement, almost all of the time goes on repeating that
prefix. src/circuit.rs:408 notes this as a shortcut:.

Implementation notes
  • Run the instructions up to the first Measure / Reset once, keep a copy of that state, and
    start each shot from the copy instead of collapse_to(0).
  • This needs a "copy this state" primitive on QuantumBackend. CPU: copy the Vec. GPU:
    copy_buffer_to_buffer into a second buffer, which stays on the GPU.
  • This doubles memory, so skip the cache when two states would not fit (for example above 29 qubits
    on the CPU), and fall back to the current behaviour.
  • A further step is to also sample the first measurement's outcome from the cached state and only
    branch from there.
What it could look like
No API change.
Contributing
  • I would like to open a pull request for this (see CONTRIBUTING.md).
Dominant language
Rust
Stars
1
Forks
0
Avg merge
12m
Merged PRs (30d)
4

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 kaiwave/qsengine

All issues in kaiwave/qsengine

Similar issues

More Rust issues

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.