-
Notifications
You must be signed in to change notification settings - Fork 109
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add `stim.CompiledDetectorSampler.sample(..., dets_out=None, obs_out=…
…None)` (#782) - Add `obs_out` and `dets_out` parameters to the sinter-hot-path detection event sampling method - Rewrite bit-table-to-numpy code to allow passing in the buffer to write to - Avoids doing large allocations for every call to sample - Avoids some extra copies that were previously present - Also, release the GIL when doing the actual frame simulation call Benchmarked by taking 250 instances of 1024 shots from a distance 11 surface code running for 33 rounds: - Old version: 3.16 seconds - New version (no buffer): 2.36 seconds - New version (yes buffer): 2.34 seconds So... the buffer appears to not be hugely significant, but the copy reduction was very useful. ``` import numpy as np import stim import time circuit = stim.Circuit.generated( "surface_code:rotated_memory_x", distance=11, rounds=33, after_clifford_depolarization=1e-3, before_measure_flip_probability=1e-3, after_reset_flip_probability=1e-3, before_round_data_depolarization=1e-3, ) sampler = circuit.compile_detector_sampler() det_buf = np.empty((1024, (circuit.num_detectors + 7) // 8), dtype=np.uint8) obs_buf = np.empty((1024, (circuit.num_observables + 7) // 8), dtype=np.uint8) t0 = time.monotonic() if True: for _ in range(250): sampler.sample( shots=1024, bit_packed=True, dets_out=det_buf, obs_out=obs_buf, ) else: for _ in range(250): sampler.sample( shots=1024, bit_packed=True, ) t1 = time.monotonic() dt = t1 - t0 print(dt) print(dt / 1024) print(dt / 1024 / 1024) print(dt / 1024 / 1024 / circuit.num_detectors) ```
- Loading branch information
Showing
16 changed files
with
418 additions
and
1,811 deletions.
There are no files selected for viewing
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.