-
Notifications
You must be signed in to change notification settings - Fork 1k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Speed up sampling in the case of measuring all qudits (#2463)
When all qudits are being measured we can avoid looping over measurement outcomes and computing array indices which is very slow. At large qubit numbers this gives over 100x speedup. Benchmark script: ``` import timeit import cirq for n in range(8, 22, 2): state = cirq.testing.random_superposition(1 << n, random_state=1234) t0 = timeit.default_timer() _ = cirq.sample_state_vector(state, range(n), repetitions=1000) t1 = timeit.default_timer() print(f"n={n}: {t1-t0} secs") ``` Output before: ``` n=8: 0.014439163962379098 secs n=10: 0.024910022970288992 secs n=12: 0.07276041503064334 secs n=14: 0.3017184369964525 secs n=16: 1.0823597890557721 secs n=18: 4.320284072891809 secs n=20: 17.91134182305541 secs ``` Output after: ``` n=8: 0.00962069199886173 secs n=10: 0.01253505703061819 secs n=12: 0.013009974965825677 secs n=14: 0.0381400550249964 secs n=16: 0.04483150108717382 secs n=18: 0.06963291903957725 secs n=20: 0.10559344501234591 secs ```
- Loading branch information
Showing
2 changed files
with
30 additions
and
18 deletions.
There are no files selected for viewing
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