Skip to content

Commit 89993a9

Browse files
authored
Finalize conversion from asv to pytest-benchmark (#8051)
- Delete asv benchmarks and configuration files as they were were already converted to `*_perf.py` files. - Update benchmarks/README to with pytest-benchmark instructions. Resolves #7796
1 parent 8691276 commit 89993a9

12 files changed

Lines changed: 39 additions & 520 deletions

.gitignore

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -23,9 +23,6 @@ docs/api_docs
2323
# swap files
2424
*.swp
2525

26-
# From asv
27-
*.asv/
28-
2926
# Ignore generated Jupyter files
3027
*.ipynb_checkpoints/
3128

asv.conf.json

Lines changed: 0 additions & 22 deletions
This file was deleted.

benchmarks/README.md

Lines changed: 39 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1,36 +1,58 @@
11
# Cirq Performance Benchmarks
22

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.
55

66
## Overview
77

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
1214

1315
## Usage
1416

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:
1719

1820
```bash
19-
./check/asv_run
21+
pytest -p no:randomly --override-ini="python_files=*_perf.py" \
22+
--benchmark-enable ./benchmarks
2023
```
2124

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
2435

2536
```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
2739
```
2840

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.
3253

3354
## Results Database
3455

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

benchmarks/bench_linalg_decompositions.py

Lines changed: 0 additions & 43 deletions
This file was deleted.

benchmarks/circuit_construction.py

Lines changed: 0 additions & 139 deletions
This file was deleted.

benchmarks/parameter_resolution.py

Lines changed: 0 additions & 38 deletions
This file was deleted.

0 commit comments

Comments
 (0)