Skip to content

Add LEAKAGE_SWAP after rebasing main#1059

Open
mliqai wants to merge 17 commits intoquantumlib:stimsidefrom
mliqai:stimside-dev
Open

Add LEAKAGE_SWAP after rebasing main#1059
mliqai wants to merge 17 commits intoquantumlib:stimsidefrom
mliqai:stimside-dev

Conversation

@mliqai
Copy link
Copy Markdown

@mliqai mliqai commented Apr 18, 2026

Rebasing main to keep up with the latest commits. Then added LEAKAGE_SWAP tag which swaps the classical registers of paired up targets in a target group. It can only be used for II, II_ERROR, and SWAP operations. Example is

II[LEAKAGE_SWAP] 0 1 2 3

mliqai and others added 17 commits January 27, 2026 18:36
This PR speeds up `stim sample` by switching the reference sample
calculation from the `TableauSimulator` to the `ReferenceSampleTree`.
Calculating the reference sample takes a large portion of the time for
larger codes.

Testing of performance for larger codes (disance 25 at 1M rounds) was
done by building stim with `bazel build :stim`, then running the
following CLI command:
`time bazel-bin/stim --gen surface_code --task rotated_memory_x
--distance 25 --rounds 1000000 --after_clifford_depolarization 0.001 |
bazel-bin/stim sample --shots 10 --out_format=r8 > ./debug.r8`
Metrics given are based on my machine (linux), but all metrics should be
considered relative to eachother.

The time taken for generating the circuit is considered trivial (<
0.1s).

Before this change, this sample took ~7m 23s.
With this change, this sample took ~2m 12s, a ~3.4x speedup (about as
fast as not calculating a reference sample at all).

I also looked into `FrameSimulator`'s logic to look for more speedup
opportunities.
The only real opportunity seen is to use multi-threading with worker
threads.
In particular, any of the overloads for
`simd_bits_range_ref::for_each_word()` could likely benefit from being
done in parallel across multiple worker threads.
Async file IO (either using native `<aio.h>`/`OVERLAPPED`/etc, or
hand-rolling queued writes where `putc()` is called from another thread)
could also possibly help to bring down total sample duration.
However, any multi-threaded work can be handled/discussed in another PR.

Changes:
* Added an overload for `ReferenceSampleTree::decompress_into()` that
works with `simd_bits`.
* Uses the `vector` overload (instead of using `operator[]` on the tree
directly in the loop) as it is the roughly same speed when built
normally, but much faster in debug (from what I saw).
* Updated `stim::command_sample()` to use `ReferenceSampleTree` instead
of `TableauSimulator` for calculating the reference sample.
* The output sample is still fully expanded out into a flat `simd_bits`
for use with the compare / file writing logic.
* Adding `--skip_loop_folding` CLI flag to disable
`ReferenceSampleTree`, falling back to `TableauSimulator`.
  * Updating `command_sample_help()` to document this new command.
The general sinter plotting function already exists, but is hidden from
the user. This PR liberates plot_custom, so that I can perform fun
tricks like plotting error rate / physical error rate vs distance, or
plotting cpu-seconds per number of rounds, or plotting strong_id vs
number of qubits, or whatever else sounds fun at the time, without
having to write any plotting code other than y_func.
…umlib#1038)

Both were not calling the methods, so the shortcuts didn’t work.

Authored by: raycosine <17799860+Raycosine@users.noreply.github.com>
This adds an optional kwarg to `stimcirq.stim_circuit_to_cirq_circuit`
for using a fixed measure key for a all cirq.MeasurementGate ops. This
will result in cirq.Result containing a single measure record array with
all measurements ordered along the "instance" axis in the order they
appear in the stim circuit.
d25, 25 rounds: 83ms -> 39ms
d11, 1000 rounds: 640ms -> 300ms

This addresses issue quantumlib#1004, although probably doesn't completely resolve
it.
Also, the new benchmark introduces didn't reproduce the 60 seconds in
the original issue; it took only ~640ms on my machine.
- RareErrorIterator was passing probabilities 0 and 1 into
std::geometric_distribution>-
- command_sample.test.cc was checking for '\0' past the end of a
std::string_view
Bumps [minimatch](https://github.com/isaacs/minimatch) from 3.1.2 to
3.1.5.
<details>
<summary>Commits</summary>
<ul>
<li><a
href="https://github.com/isaacs/minimatch/commit/7bba97888a27a6162983056bcce2a6e28f668712"><code>7bba978</code></a>
3.1.5</li>
<li><a
href="https://github.com/isaacs/minimatch/commit/bd259425b2ca17b42897997f93e890314155522d"><code>bd25942</code></a>
docs: add warning about ReDoS</li>
<li><a
href="https://github.com/isaacs/minimatch/commit/1a9c27c75725474dbde57db2995b6281b267756d"><code>1a9c27c</code></a>
fix partial matching of globstar patterns</li>
<li><a
href="https://github.com/isaacs/minimatch/commit/1a2e084af579731af66c221214e3ca8222c9bf23"><code>1a2e084</code></a>
3.1.4</li>
<li><a
href="https://github.com/isaacs/minimatch/commit/ae24656237c3d58067442f790ce17eff84463a47"><code>ae24656</code></a>
update lockfile</li>
<li><a
href="https://github.com/isaacs/minimatch/commit/b1003749228b2a79e1f237963a0d559ef7a0941e"><code>b100374</code></a>
limit recursion for **, improve perf considerably</li>
<li><a
href="https://github.com/isaacs/minimatch/commit/26ffeaa091b9f660833e23f42e07165b33e85c13"><code>26ffeaa</code></a>
lockfile update</li>
<li><a
href="https://github.com/isaacs/minimatch/commit/9eca892a4e5dbb20534f9f30483b85cdeee6c2eb"><code>9eca892</code></a>
lock node version to 14</li>
<li><a
href="https://github.com/isaacs/minimatch/commit/00c323b188b704e5d4bc534ecec2268cfa70a32a"><code>00c323b</code></a>
3.1.3</li>
<li><a
href="https://github.com/isaacs/minimatch/commit/30486b2048929264f44d18822891cfffa02af78b"><code>30486b2</code></a>
update CI matrix and actions</li>
<li>Additional commits viewable in <a
href="https://github.com/isaacs/minimatch/compare/v3.1.2...v3.1.5">compare
view</a></li>
</ul>
</details>
<br />


[![Dependabot compatibility
score](https://dependabot-badges.githubapp.com/badges/compatibility_score?dependency-name=minimatch&package-manager=npm_and_yarn&previous-version=3.1.2&new-version=3.1.5)](https://docs.github.com/en/github/managing-security-vulnerabilities/about-dependabot-security-updates#about-compatibility-scores)

Dependabot will resolve any conflicts with this PR as long as you don't
alter it yourself. You can also trigger a rebase manually by commenting
`@dependabot rebase`.

[//]: # (dependabot-automerge-start)
[//]: # (dependabot-automerge-end)

---

<details>
<summary>Dependabot commands and options</summary>
<br />

You can trigger Dependabot actions by commenting on this PR:
- `@dependabot rebase` will rebase this PR
- `@dependabot recreate` will recreate this PR, overwriting any edits
that have been made to it
- `@dependabot show <dependency name> ignore conditions` will show all
of the ignore conditions of the specified dependency
- `@dependabot ignore this major version` will close this PR and stop
Dependabot creating any more for this major version (unless you reopen
the PR or upgrade to it yourself)
- `@dependabot ignore this minor version` will close this PR and stop
Dependabot creating any more for this minor version (unless you reopen
the PR or upgrade to it yourself)
- `@dependabot ignore this dependency` will close this PR and stop
Dependabot creating any more for this dependency (unless you reopen the
PR or upgrade to it yourself)
You can disable automated security fix PRs for this repo from the
[Security Alerts
page](https://github.com/quantumlib/Stim/network/alerts).

</details>
- Currently fails to round trip while preserving simulability
- cirq->stim can handle cirq.ClassicallyControlledOperation (wrapping
Paulis with a single control) and turns it in "CX rec[-1] 0" or similar
- stim->cirq produces a stimcirq.FeedbackPauli which is not simulable
(due to not knowing how to lookup the measurement)
Basically a straight theft of Oscar's PR, but without adding the
`package` dependency at Craig's request.
This was causing problems in a variety of places, and ultimately just
isn't very pythonic.

Obsoletes quantumlib#1039

Fixes quantumlib#1000
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

6 participants