|
1 | 1 | # Cirq Performance Benchmarks |
2 | 2 |
|
3 | | -This directory concerns doing Cirq performance benchmarks with [Airspeed |
4 | | -Velocity](https://asv.readthedocs.io/en/stable/index.html). |
| 3 | +This directory contains Cirq performance benchmarks established using the |
| 4 | +[pytest-benchmark] plugin for pytest. |
5 | 5 |
|
6 | 6 | ## Overview |
7 | 7 |
|
8 | | -The benchmark files (`bench_*.py`) stored in the current package |
9 | | -(`benchmarks/*`) are used by ASV to run benchmark tests for Cirq. For more |
10 | | -information on how to write new benchmarks, please refer [Writing benchmarks |
11 | | -guide by ASV](https://asv.readthedocs.io/en/stable/writing_benchmarks.html) |
| 8 | +The benchmarks are defined by the `*_perf.py` files provided in this |
| 9 | +`benchmarks` package and its sub-folders. The benchmark definitions are |
| 10 | +very similar to common pytest test functions, but they use an extra features |
| 11 | +from the pytest-benchmark plugin to collect code execution times and statistics. |
| 12 | +For more information on how to write new benchmarks, please refer to |
| 13 | +existing benchmark files and to the [pytest-benchmark] documentation |
12 | 14 |
|
13 | 15 | ## Usage |
14 | 16 |
|
15 | | -To run all benchmarks, navigate to the root Cirq directory at the command line |
16 | | -and execute the following command: |
| 17 | +To run all benchmarks, navigate to the root Cirq directory in |
| 18 | +a shell and execute the following command: |
17 | 19 |
|
18 | 20 | ```bash |
19 | | -./check/asv_run |
| 21 | +pytest -p no:randomly --override-ini="python_files=*_perf.py" \ |
| 22 | + --benchmark-enable ./benchmarks |
20 | 23 | ``` |
21 | 24 |
|
22 | | -You can also pass arguments to the `asv_run` script, which will be forwarded to |
23 | | -the `asv run` command. Here's an example: |
| 25 | +This will run the entire benchmark suite which takes approximately |
| 26 | +30 minutes. Note that it is important to pass the `--benchmark-enable` |
| 27 | +option as otherwise the code would run as a standard one-shot |
| 28 | +pytest and would not collect timing statistics (this may be preferable |
| 29 | +for benchmark development). Some of the benchmarks are labeled with |
| 30 | +the `slow` marker and are by default deselected in a standard benchmark |
| 31 | +session. The `slow` marker is applied for larger sizes of parametrized |
| 32 | +benchmarks, which are also covered at smaller computational scales, and |
| 33 | +are thus not critical for assessing performance trends. |
| 34 | +That said, to execute all benchmarks including the `slow` ones, use |
24 | 35 |
|
25 | 36 | ```bash |
26 | | -./check/asv_run --quick --bench bench_examples --python 3.11 |
| 37 | +pytest -p no:randomly --override-ini="python_files=*_perf.py" \ |
| 38 | + --benchmark-enable --enable-slow-tests ./benchmarks |
27 | 39 | ``` |
28 | 40 |
|
29 | | -Please refer to [Running Benchmarks guide by |
30 | | -ASV](https://asv.readthedocs.io/en/stable/using.html#running-benchmarks) for |
31 | | -more information. |
| 41 | +Finally, to run a single specific benchmark and save its results |
| 42 | +for later comparison, use the `--benchmark-autosave` option together |
| 43 | +with the pytest identifier of the benchmark, for example, |
| 44 | + |
| 45 | +```bash |
| 46 | +pytest -p no:randomly --benchmark-enable \ |
| 47 | + --benchmark-enable --benchmark-autosave \ |
| 48 | + "benchmarks/linalg_decompositions_perf.py::test_kak_decomposition[CNOT]" |
| 49 | +``` |
| 50 | + |
| 51 | +Please refer to the [pytest-benchmark] documentation for further instructions |
| 52 | +on comparing and visualizing benchmark results. |
32 | 53 |
|
33 | 54 | ## Results Database |
34 | 55 |
|
35 | | -TODO([#3838](https://github.com/quantumlib/Cirq/issues/3838)): Add details |
36 | | -regarding GCP setup. |
| 56 | +TODO: b/393456969 - provide pointers to the internal results database |
| 57 | + |
| 58 | +[pytest-benchmark]: https://pytest-benchmark.readthedocs.io/en/latest |
0 commit comments