Commit 3a83081
authored
Speed up Stim Sampling with Faster Ref Sample (#1036)
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.1 parent 626c473 commit 3a83081
4 files changed
Lines changed: 83 additions & 2 deletions
File tree
- doc
- src/stim
- cmd
- util_top
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
1676 | 1676 | | |
1677 | 1677 | | |
1678 | 1678 | | |
| 1679 | + | |
1679 | 1680 | | |
1680 | 1681 | | |
1681 | 1682 | | |
| |||
1762 | 1763 | | |
1763 | 1764 | | |
1764 | 1765 | | |
| 1766 | + | |
| 1767 | + | |
| 1768 | + | |
| 1769 | + | |
| 1770 | + | |
| 1771 | + | |
| 1772 | + | |
| 1773 | + | |
| 1774 | + | |
| 1775 | + | |
| 1776 | + | |
| 1777 | + | |
| 1778 | + | |
| 1779 | + | |
| 1780 | + | |
| 1781 | + | |
| 1782 | + | |
| 1783 | + | |
| 1784 | + | |
| 1785 | + | |
| 1786 | + | |
| 1787 | + | |
| 1788 | + | |
| 1789 | + | |
1765 | 1790 | | |
1766 | 1791 | | |
1767 | 1792 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
21 | 21 | | |
22 | 22 | | |
23 | 23 | | |
| 24 | + | |
24 | 25 | | |
25 | 26 | | |
26 | 27 | | |
27 | 28 | | |
28 | 29 | | |
29 | | - | |
| 30 | + | |
30 | 31 | | |
31 | 32 | | |
32 | 33 | | |
33 | 34 | | |
34 | 35 | | |
35 | 36 | | |
| 37 | + | |
36 | 38 | | |
37 | 39 | | |
38 | 40 | | |
| |||
56 | 58 | | |
57 | 59 | | |
58 | 60 | | |
59 | | - | |
| 61 | + | |
| 62 | + | |
| 63 | + | |
| 64 | + | |
| 65 | + | |
| 66 | + | |
| 67 | + | |
60 | 68 | | |
61 | 69 | | |
62 | 70 | | |
| |||
128 | 136 | | |
129 | 137 | | |
130 | 138 | | |
| 139 | + | |
| 140 | + | |
| 141 | + | |
| 142 | + | |
| 143 | + | |
| 144 | + | |
| 145 | + | |
| 146 | + | |
| 147 | + | |
| 148 | + | |
| 149 | + | |
| 150 | + | |
| 151 | + | |
| 152 | + | |
| 153 | + | |
| 154 | + | |
| 155 | + | |
| 156 | + | |
| 157 | + | |
| 158 | + | |
| 159 | + | |
| 160 | + | |
| 161 | + | |
| 162 | + | |
| 163 | + | |
| 164 | + | |
| 165 | + | |
| 166 | + | |
| 167 | + | |
| 168 | + | |
| 169 | + | |
131 | 170 | | |
132 | 171 | | |
133 | 172 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
37 | 37 | | |
38 | 38 | | |
39 | 39 | | |
| 40 | + | |
| 41 | + | |
| 42 | + | |
| 43 | + | |
40 | 44 | | |
41 | 45 | | |
42 | 46 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
2 | 2 | | |
3 | 3 | | |
4 | 4 | | |
| 5 | + | |
| 6 | + | |
| 7 | + | |
| 8 | + | |
| 9 | + | |
| 10 | + | |
| 11 | + | |
| 12 | + | |
| 13 | + | |
| 14 | + | |
| 15 | + | |
| 16 | + | |
| 17 | + | |
5 | 18 | | |
6 | 19 | | |
7 | 20 | | |
| |||
0 commit comments