Skip to content

Commit 66a5d9f

Browse files
committed
Convert ASV files for use on Terra
The configuration is rewritten because several components of it needed to changes as it came other, and it was mostly autogenerated or out-of-date anyway. We may want to tweak how requirements are managed and installed in the future. Black is applied to the test files, and various tweaks needed to satisfy Terra's lint requirements.
1 parent ec5c9ca commit 66a5d9f

28 files changed

+1173
-849
lines changed

.gitignore

+1
Original file line numberDiff line numberDiff line change
@@ -98,6 +98,7 @@ celerybeat-schedule
9898
.env
9999

100100
# virtualenv
101+
.asv/
101102
.venv
102103
venv/
103104
ENV/

asv.conf.json

+8-155
Original file line numberDiff line numberDiff line change
@@ -1,172 +1,25 @@
11
{
2-
// The version of the config file format. Do not change, unless
3-
// you know what you are doing.
42
"version": 1,
5-
6-
// The name of the project being benchmarked
7-
"project": "qiskit-terra",
8-
9-
// The project's homepage
3+
"project": "qiskit",
104
"project_url": "https://qiskit.org",
11-
12-
// The URL or local path of the source code repository for the
13-
// project being benchmarked
14-
"repo": "https://github.com/Qiskit/qiskit-terra.git",
15-
16-
// The Python project's subdirectory in your repo. If missing or
17-
// the empty string, the project is assumed to be located at the root
18-
// of the repository.
19-
// "repo_subdir": "",
20-
21-
// Customizable commands for building, installing, and
22-
// uninstalling the project. See asv.conf.json documentation.
23-
//
5+
"repo": ".",
246
"install_command": [
25-
"return-code=any python -c \"import shutil; shutil.rmtree('{build_dir}/build')\"",
26-
"return-code=any python -c \"import shutil; shutil.rmtree('{build_dir}/qiskit_terra.egg-info')\"",
27-
"python -mpip install seaborn",
28-
"python -mpip install pygments",
29-
"python -mpip install {wheel_file}",
30-
"python -mpip install -U qiskit-experiments==0.3.0",
31-
"python -mpip install -U python-constraint"
7+
"in-dir={env_dir} python -mpip install {wheel_file}[all] python-constraint qiskit-experiments==0.3.0"
328
],
339
"uninstall_command": [
34-
"return-code=any python -mpip uninstall -y {project}",
35-
"return-code=any python -mpip uninstall -y qiskit-experiments"
10+
"return-code=any python -mpip uninstall -y {project}"
3611
],
3712
"build_command": [
38-
"pip install -U Cython setuptools-rust",
13+
"pip install -U setuptools-rust",
3914
"python setup.py build_rust --release",
4015
"PIP_NO_BUILD_ISOLATION=false python -mpip wheel --no-deps --no-index -w {build_cache_dir} {build_dir}"
4116
],
42-
43-
// List of branches to benchmark. If not provided, defaults to "master"
44-
// (for git) or "default" (for mercurial).
45-
"branches": ["main"], // for git
46-
// "branches": ["default"], // for mercurial
47-
48-
// The DVCS being used. If not set, it will be automatically
49-
// determined from "repo" by looking at the protocol in the URL
50-
// (if remote), or by looking for special directories, such as
51-
// ".git" (if local).
17+
"branches": ["main"],
5218
"dvcs": "git",
53-
54-
// The tool to use to create environments. May be "conda",
55-
// "virtualenv" or other value depending on the plugins in use.
56-
// If missing or the empty string, the tool will be automatically
57-
// determined by looking for tools on the PATH environment
58-
// variable.
5919
"environment_type": "virtualenv",
60-
61-
// timeout in seconds for installing any dependencies in environment
62-
// defaults to 10 min
63-
//"install_timeout": 600,
64-
65-
// the base URL to show a commit for the project.
6620
"show_commit_url": "http://github.com/Qiskit/qiskit-terra/commit/",
67-
68-
// The Pythons you'd like to test against. If not provided, defaults
69-
// to the current version of Python used to run `asv`.
70-
"pythons": ["3.7", "3.8", "3.9", "3.10"],
71-
72-
// The list of conda channel names to be searched for benchmark
73-
// dependency packages in the specified order
74-
// "conda_channels": ["conda-forge", "defaults"]
75-
76-
// The matrix of dependencies to test. Each key is the name of a
77-
// package (in PyPI) and the values are version numbers. An empty
78-
// list or empty string indicates to just test against the default
79-
// (latest) version. null indicates that the package is to not be
80-
// installed. If the package to be tested is only available from
81-
// PyPi, and the 'environment_type' is conda, then you can preface
82-
// the package name by 'pip+', and the package will be installed via
83-
// pip (with all the conda available packages installed first,
84-
// followed by the pip installed packages).
85-
//
86-
// "matrix": {
87-
// "numpy": ["1.6", "1.7"],
88-
// "six": ["", null], // test with and without six installed
89-
// "pip+emcee": [""], // emcee is only available for install with pip.
90-
// },
91-
92-
// Combinations of libraries/python versions can be excluded/included
93-
// from the set to test. Each entry is a dictionary containing additional
94-
// key-value pairs to include/exclude.
95-
//
96-
// An exclude entry excludes entries where all values match. The
97-
// values are regexps that should match the whole string.
98-
//
99-
// An include entry adds an environment. Only the packages listed
100-
// are installed. The 'python' key is required. The exclude rules
101-
// do not apply to includes.
102-
//
103-
// In addition to package names, the following keys are available:
104-
//
105-
// - python
106-
// Python version, as in the *pythons* variable above.
107-
// - environment_type
108-
// Environment type, as above.
109-
// - sys_platform
110-
// Platform, as in sys.platform. Possible values for the common
111-
// cases: 'linux2', 'win32', 'cygwin', 'darwin'.
112-
//
113-
// "exclude": [
114-
// {"python": "3.2", "sys_platform": "win32"}, // skip py3.2 on windows
115-
// {"environment_type": "conda", "six": null}, // don't run without six on conda
116-
// ],
117-
//
118-
// "include": [
119-
// // additional env for python2.7
120-
// {"python": "2.7", "numpy": "1.8"},
121-
// // additional env if run on windows+conda
122-
// {"platform": "win32", "environment_type": "conda", "python": "2.7", "libpython": ""},
123-
// ],
124-
125-
// The directory (relative to the current directory) that benchmarks are
126-
// stored in. If not provided, defaults to "benchmarks"
21+
"pythons": ["3.8", "3.9", "3.10", "3.11"],
12722
"benchmark_dir": "test/benchmarks",
128-
129-
// The directory (relative to the current directory) to cache the Python
130-
// environments in. If not provided, defaults to "env"
13123
"env_dir": ".asv/env",
132-
133-
// The directory (relative to the current directory) that raw benchmark
134-
// results are stored in. If not provided, defaults to "results".
135-
"results_dir": ".asv/results",
136-
137-
// The directory (relative to the current directory) that the html tree
138-
// should be written to. If not provided, defaults to "html".
139-
// "html_dir": "html",
140-
141-
// The number of characters to retain in the commit hashes.
142-
// "hash_length": 8,
143-
144-
// `asv` will cache results of the recent builds in each
145-
// environment, making them faster to install next time. This is
146-
// the number of builds to keep, per environment.
147-
// "build_cache_size": 2,
148-
149-
// The commits after which the regression search in `asv publish`
150-
// should start looking for regressions. Dictionary whose keys are
151-
// regexps matching to benchmark names, and values corresponding to
152-
// the commit (exclusive) after which to start looking for
153-
// regressions. The default is to start from the first commit
154-
// with results. If the commit is `null`, regression detection is
155-
// skipped for the matching benchmark.
156-
//
157-
// "regressions_first_commits": {
158-
// "some_benchmark": "352cdf", // Consider regressions only after this commit
159-
// "another_benchmark": null, // Skip regression detection altogether
160-
// },
161-
162-
// The thresholds for relative change in results, after which `asv
163-
// publish` starts reporting regressions. Dictionary of the same
164-
// form as in ``regressions_first_commits``, with values
165-
// indicating the thresholds. If multiple entries match, the
166-
// maximum is taken. If no entry matches, the default is 5%.
167-
//
168-
// "regressions_thresholds": {
169-
// "some_benchmark": 0.01, // Threshold of 1%
170-
// "another_benchmark": 0.5, // Threshold of 50%
171-
// },
24+
"results_dir": ".asv/results"
17225
}

test/benchmarks/__init__.py

+11
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
# This code is part of Qiskit.
2+
#
3+
# (C) Copyright IBM 2023
4+
#
5+
# This code is licensed under the Apache License, Version 2.0. You may
6+
# obtain a copy of this license in the LICENSE.txt file in the root directory
7+
# of this source tree or at http://www.apache.org/licenses/LICENSE-2.0.
8+
#
9+
# Any modifications or derivative works of this code must retain this
10+
# copyright notice, and modified files need to carry a notice indicating
11+
# that they have been altered from the originals.

test/benchmarks/assembler.py

+7-15
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,6 @@
1-
# -*- coding: utf-8 -*-
2-
31
# This code is part of Qiskit.
42
#
5-
# (C) Copyright IBM 2019.
3+
# (C) Copyright IBM 2023
64
#
75
# This code is licensed under the Apache License, Version 2.0. You may
86
# obtain a copy of this license in the LICENSE.txt file in the root directory
@@ -22,34 +20,28 @@
2220

2321

2422
class AssemblerBenchmarks:
25-
params = ([8],
26-
[4096],
27-
[1, 100])
28-
param_names = ['n_qubits', 'depth', 'number of circuits']
23+
params = ([8], [4096], [1, 100])
24+
param_names = ["n_qubits", "depth", "number of circuits"]
2925
timeout = 600
3026
version = 2
3127

3228
def setup(self, n_qubits, depth, number_of_circuits):
3329
seed = 42
34-
self.circuit = random_circuit(n_qubits, depth, measure=True,
35-
conditional=True, seed=seed)
30+
self.circuit = random_circuit(n_qubits, depth, measure=True, conditional=True, seed=seed)
3631
self.circuits = [self.circuit] * number_of_circuits
3732

3833
def time_assemble_circuit(self, _, __, ___):
3934
assemble(self.circuits)
4035

4136

4237
class DisassemblerBenchmarks:
43-
params = ([8],
44-
[4096],
45-
[1, 100])
46-
param_names = ['n_qubits', 'depth', 'number of circuits']
38+
params = ([8], [4096], [1, 100])
39+
param_names = ["n_qubits", "depth", "number of circuits"]
4740
timeout = 600
4841

4942
def setup(self, n_qubits, depth, number_of_circuits):
5043
seed = 424242
51-
self.circuit = random_circuit(n_qubits, depth, measure=True,
52-
conditional=True, seed=seed)
44+
self.circuit = random_circuit(n_qubits, depth, measure=True, conditional=True, seed=seed)
5345
self.circuits = [self.circuit] * number_of_circuits
5446
self.qobj = assemble(self.circuits)
5547

test/benchmarks/circuit_construction.py

+12-18
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,6 @@
1-
# -*- coding: utf-8 -*
2-
31
# This code is part of Qiskit.
42
#
5-
# (C) Copyright IBM 2018, 2019.
3+
# (C) Copyright IBM 2023
64
#
75
# This code is licensed under the Apache License, Version 2.0. You may
86
# obtain a copy of this license in the LICENSE.txt file in the root directory
@@ -28,15 +26,15 @@ def build_circuit(width, gates):
2826
while len(qc) < gates:
2927
for k in range(width):
3028
qc.h(qr[k])
31-
for k in range(width-1):
32-
qc.cx(qr[k], qr[k+1])
29+
for k in range(width - 1):
30+
qc.cx(qr[k], qr[k + 1])
3331

3432
return qc
3533

3634

3735
class CircuitConstructionBench:
3836
params = ([1, 2, 5, 8, 14, 20], [8, 128, 2048, 8192, 32768, 131072])
39-
param_names = ['width', 'gates']
37+
param_names = ["width", "gates"]
4038
timeout = 600
4139

4240
def setup(self, width, gates):
@@ -54,7 +52,7 @@ def time_circuit_copy(self, _, __):
5452

5553

5654
def build_parameterized_circuit(width, gates, param_count):
57-
params = [Parameter('param-%s' % x) for x in range(param_count)]
55+
params = [Parameter("param-%s" % x) for x in range(param_count)]
5856
param_iter = itertools.cycle(params)
5957

6058
qr = QuantumRegister(width)
@@ -64,17 +62,16 @@ def build_parameterized_circuit(width, gates, param_count):
6462
for k in range(width):
6563
param = next(param_iter)
6664
qc.u2(0, param, qr[k])
67-
for k in range(width-1):
65+
for k in range(width - 1):
6866
param = next(param_iter)
69-
qc.crx(param, qr[k], qr[k+1])
67+
qc.crx(param, qr[k], qr[k + 1])
7068

7169
return qc, params
7270

7371

7472
class ParameterizedCircuitConstructionBench:
75-
params = ([20], [8, 128, 2048, 8192, 32768, 131072],
76-
[8, 128, 2048, 8192, 32768, 131072])
77-
param_names = ['width', 'gates', 'number of params']
73+
params = ([20], [8, 128, 2048, 8192, 32768, 131072], [8, 128, 2048, 8192, 32768, 131072])
74+
param_names = ["width", "gates", "number of params"]
7875
timeout = 600
7976

8077
def setup(self, _, gates, params):
@@ -86,17 +83,14 @@ def time_build_parameterized_circuit(self, width, gates, params):
8683

8784

8885
class ParameterizedCircuitBindBench:
89-
params = ([20], [8, 128, 2048, 8192, 32768, 131072],
90-
[8, 128, 2048, 8192, 32768, 131072])
91-
param_names = ['width', 'gates', 'number of params']
86+
params = ([20], [8, 128, 2048, 8192, 32768, 131072], [8, 128, 2048, 8192, 32768, 131072])
87+
param_names = ["width", "gates", "number of params"]
9288
timeout = 600
9389

9490
def setup(self, width, gates, params):
9591
if params > gates:
9692
raise NotImplementedError
97-
self.circuit, self.params = build_parameterized_circuit(width,
98-
gates,
99-
params)
93+
self.circuit, self.params = build_parameterized_circuit(width, gates, params)
10094

10195
def time_bind_params(self, _, __, ___):
10296
self.circuit.bind_parameters({x: 3.14 for x in self.params})

test/benchmarks/converters.py

+3-6
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,6 @@
1-
# -*- coding: utf-8 -*-
2-
31
# This code is part of Qiskit.
42
#
5-
# (C) Copyright IBM 2019.
3+
# (C) Copyright IBM 2023
64
#
75
# This code is licensed under the Apache License, Version 2.0. You may
86
# obtain a copy of this license in the LICENSE.txt file in the root directory
@@ -23,7 +21,7 @@
2321

2422
class ConverterBenchmarks:
2523
params = ([1, 2, 5, 8, 14, 20, 32, 53], [8, 128, 2048, 8192])
26-
param_names = ['n_qubits', 'depth']
24+
param_names = ["n_qubits", "depth"]
2725
timeout = 600
2826

2927
def setup(self, n_qubits, depth):
@@ -38,8 +36,7 @@ def setup(self, n_qubits, depth):
3836
elif n_qubits == 14:
3937
if depth > 2048:
4038
raise NotImplementedError
41-
self.qc = random_circuit(n_qubits, depth, measure=True,
42-
conditional=True, seed=seed)
39+
self.qc = random_circuit(n_qubits, depth, measure=True, conditional=True, seed=seed)
4340
self.dag = converters.circuit_to_dag(self.qc)
4441
self.qasm = qasm.Qasm(data=self.qc.qasm()).parse()
4542

test/benchmarks/import.py

+2-4
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,6 @@
1-
# -*- coding: utf-8 -*-
2-
31
# This code is part of Qiskit.
42
#
5-
# (C) Copyright IBM 2019.
3+
# (C) Copyright IBM 2023
64
#
75
# This code is licensed under the Apache License, Version 2.0. You may
86
# obtain a copy of this license in the LICENSE.txt file in the root directory
@@ -23,4 +21,4 @@
2321

2422
class QiskitImport:
2523
def time_qiskit_import(self):
26-
call((executable, '-c', 'import qiskit'))
24+
call((executable, "-c", "import qiskit"))

0 commit comments

Comments
 (0)