Skip to content

Commit e781aff

Browse files
committed
Merge benchmark suite from Qiskit/qiskit-metapackage
This merge commit pulls in the history of the airspeed-velocity benchmark suite from its original location in the metapackage. The commits have been filtered to only include the history of the benchmark suite itself, and their messages rewritten to change GitHub issue and PR references to point to the renamed metapackage.
2 parents 28113b6 + f97b7b1 commit e781aff

37 files changed

Lines changed: 13286 additions & 0 deletions

test/benchmarks/__init__.py

Whitespace-only changes.

test/benchmarks/assembler.py

Lines changed: 57 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,57 @@
1+
# -*- coding: utf-8 -*-
2+
3+
# This code is part of Qiskit.
4+
#
5+
# (C) Copyright IBM 2019.
6+
#
7+
# This code is licensed under the Apache License, Version 2.0. You may
8+
# obtain a copy of this license in the LICENSE.txt file in the root directory
9+
# of this source tree or at http://www.apache.org/licenses/LICENSE-2.0.
10+
#
11+
# Any modifications or derivative works of this code must retain this
12+
# copyright notice, and modified files need to carry a notice indicating
13+
# that they have been altered from the originals.
14+
15+
# pylint: disable=no-member,invalid-name,missing-docstring,no-name-in-module
16+
# pylint: disable=attribute-defined-outside-init,unsubscriptable-object
17+
18+
from qiskit.compiler import assemble
19+
from qiskit.assembler import disassemble
20+
21+
from .utils import random_circuit
22+
23+
24+
class AssemblerBenchmarks:
25+
params = ([8],
26+
[4096],
27+
[1, 100])
28+
param_names = ['n_qubits', 'depth', 'number of circuits']
29+
timeout = 600
30+
version = 2
31+
32+
def setup(self, n_qubits, depth, number_of_circuits):
33+
seed = 42
34+
self.circuit = random_circuit(n_qubits, depth, measure=True,
35+
conditional=True, seed=seed)
36+
self.circuits = [self.circuit] * number_of_circuits
37+
38+
def time_assemble_circuit(self, _, __, ___):
39+
assemble(self.circuits)
40+
41+
42+
class DisassemblerBenchmarks:
43+
params = ([8],
44+
[4096],
45+
[1, 100])
46+
param_names = ['n_qubits', 'depth', 'number of circuits']
47+
timeout = 600
48+
49+
def setup(self, n_qubits, depth, number_of_circuits):
50+
seed = 424242
51+
self.circuit = random_circuit(n_qubits, depth, measure=True,
52+
conditional=True, seed=seed)
53+
self.circuits = [self.circuit] * number_of_circuits
54+
self.qobj = assemble(self.circuits)
55+
56+
def time_disassemble_circuit(self, _, __, ___):
57+
disassemble(self.qobj)
Lines changed: 102 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,102 @@
1+
# -*- coding: utf-8 -*
2+
3+
# This code is part of Qiskit.
4+
#
5+
# (C) Copyright IBM 2018, 2019.
6+
#
7+
# This code is licensed under the Apache License, Version 2.0. You may
8+
# obtain a copy of this license in the LICENSE.txt file in the root directory
9+
# of this source tree or at http://www.apache.org/licenses/LICENSE-2.0.
10+
#
11+
# Any modifications or derivative works of this code must retain this
12+
# copyright notice, and modified files need to carry a notice indicating
13+
# that they have been altered from the originals.
14+
15+
# pylint: disable=missing-docstring,invalid-name,no-member
16+
# pylint: disable=attribute-defined-outside-init
17+
18+
import itertools
19+
20+
from qiskit import QuantumRegister, QuantumCircuit
21+
from qiskit.circuit import Parameter
22+
23+
24+
def build_circuit(width, gates):
25+
qr = QuantumRegister(width)
26+
qc = QuantumCircuit(qr)
27+
28+
while len(qc) < gates:
29+
for k in range(width):
30+
qc.h(qr[k])
31+
for k in range(width-1):
32+
qc.cx(qr[k], qr[k+1])
33+
34+
return qc
35+
36+
37+
class CircuitConstructionBench:
38+
params = ([1, 2, 5, 8, 14, 20], [8, 128, 2048, 8192, 32768, 131072])
39+
param_names = ['width', 'gates']
40+
timeout = 600
41+
42+
def setup(self, width, gates):
43+
self.empty_circuit = build_circuit(width, 0)
44+
self.sample_circuit = build_circuit(width, gates)
45+
46+
def time_circuit_construction(self, width, gates):
47+
build_circuit(width, gates)
48+
49+
def time_circuit_extend(self, _, __):
50+
self.empty_circuit.extend(self.sample_circuit)
51+
52+
def time_circuit_copy(self, _, __):
53+
self.sample_circuit.copy()
54+
55+
56+
def build_parameterized_circuit(width, gates, param_count):
57+
params = [Parameter('param-%s' % x) for x in range(param_count)]
58+
param_iter = itertools.cycle(params)
59+
60+
qr = QuantumRegister(width)
61+
qc = QuantumCircuit(qr)
62+
63+
while len(qc) < gates:
64+
for k in range(width):
65+
param = next(param_iter)
66+
qc.u2(0, param, qr[k])
67+
for k in range(width-1):
68+
param = next(param_iter)
69+
qc.crx(param, qr[k], qr[k+1])
70+
71+
return qc, params
72+
73+
74+
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']
78+
timeout = 600
79+
80+
def setup(self, _, gates, params):
81+
if params > gates:
82+
raise NotImplementedError
83+
84+
def time_build_parameterized_circuit(self, width, gates, params):
85+
build_parameterized_circuit(width, gates, params)
86+
87+
88+
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']
92+
timeout = 600
93+
94+
def setup(self, width, gates, params):
95+
if params > gates:
96+
raise NotImplementedError
97+
self.circuit, self.params = build_parameterized_circuit(width,
98+
gates,
99+
params)
100+
101+
def time_bind_params(self, _, __, ___):
102+
self.circuit.bind_parameters({x: 3.14 for x in self.params})

test/benchmarks/converters.py

Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,56 @@
1+
# -*- coding: utf-8 -*-
2+
3+
# This code is part of Qiskit.
4+
#
5+
# (C) Copyright IBM 2019.
6+
#
7+
# This code is licensed under the Apache License, Version 2.0. You may
8+
# obtain a copy of this license in the LICENSE.txt file in the root directory
9+
# of this source tree or at http://www.apache.org/licenses/LICENSE-2.0.
10+
#
11+
# Any modifications or derivative works of this code must retain this
12+
# copyright notice, and modified files need to carry a notice indicating
13+
# that they have been altered from the originals.
14+
15+
# pylint: disable=no-member,invalid-name,missing-docstring,no-name-in-module
16+
# pylint: disable=attribute-defined-outside-init,unsubscriptable-object
17+
18+
from qiskit import converters
19+
from qiskit import qasm
20+
21+
from .utils import random_circuit
22+
23+
24+
class ConverterBenchmarks:
25+
params = ([1, 2, 5, 8, 14, 20, 32, 53], [8, 128, 2048, 8192])
26+
param_names = ['n_qubits', 'depth']
27+
timeout = 600
28+
29+
def setup(self, n_qubits, depth):
30+
seed = 42
31+
# NOTE: Remove the benchmarks larger than 20x2048 and 14x8192, this is
32+
# a tradeoff for speed of benchmarking, creating circuits this size
33+
# takes more time than is worth it for benchmarks that take a couple
34+
# seconds
35+
if n_qubits >= 20:
36+
if depth >= 2048:
37+
raise NotImplementedError
38+
elif n_qubits == 14:
39+
if depth > 2048:
40+
raise NotImplementedError
41+
self.qc = random_circuit(n_qubits, depth, measure=True,
42+
conditional=True, seed=seed)
43+
self.dag = converters.circuit_to_dag(self.qc)
44+
self.qasm = qasm.Qasm(data=self.qc.qasm()).parse()
45+
46+
def time_circuit_to_dag(self, *_):
47+
converters.circuit_to_dag(self.qc)
48+
49+
def time_circuit_to_instruction(self, *_):
50+
converters.circuit_to_instruction(self.qc)
51+
52+
def time_dag_to_circuit(self, *_):
53+
converters.dag_to_circuit(self.dag)
54+
55+
def time_ast_to_circuit(self, *_):
56+
converters.ast_to_dag(self.qasm)

test/benchmarks/import.py

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
# -*- coding: utf-8 -*-
2+
3+
# This code is part of Qiskit.
4+
#
5+
# (C) Copyright IBM 2019.
6+
#
7+
# This code is licensed under the Apache License, Version 2.0. You may
8+
# obtain a copy of this license in the LICENSE.txt file in the root directory
9+
# of this source tree or at http://www.apache.org/licenses/LICENSE-2.0.
10+
#
11+
# Any modifications or derivative works of this code must retain this
12+
# copyright notice, and modified files need to carry a notice indicating
13+
# that they have been altered from the originals.
14+
15+
# pylint: disable=no-member,invalid-name,missing-docstring,no-name-in-module
16+
# pylint: disable=attribute-defined-outside-init,unsubscriptable-object
17+
18+
"""Module for estimating import times."""
19+
20+
from sys import executable
21+
from subprocess import call
22+
23+
24+
class QiskitImport:
25+
def time_qiskit_import(self):
26+
call((executable, '-c', 'import qiskit'))

test/benchmarks/isometry.py

Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
# -*- coding: utf-8 -*-
2+
3+
# This code is part of Qiskit.
4+
#
5+
# (C) Copyright IBM 2019.
6+
#
7+
# This code is licensed under the Apache License, Version 2.0. You may
8+
# obtain a copy of this license in the LICENSE.txt file in the root directory
9+
# of this source tree or at http://www.apache.org/licenses/LICENSE-2.0.
10+
#
11+
# Any modifications or derivative works of this code must retain this
12+
# copyright notice, and modified files need to carry a notice indicating
13+
# that they have been altered from the originals.
14+
15+
# pylint: disable=missing-docstring,invalid-name,no-member
16+
# pylint: disable=attribute-defined-outside-init
17+
# pylint: disable=unused-argument
18+
19+
from qiskit import QuantumRegister, QuantumCircuit
20+
from qiskit.compiler import transpile
21+
from qiskit.quantum_info.random import random_unitary
22+
23+
24+
class IsometryTranspileBench:
25+
params = ([0, 1, 2, 3], [3, 4, 5, 6])
26+
param_names = ['number of input qubits', 'number of output qubits']
27+
28+
def setup(self, m, n):
29+
q = QuantumRegister(n)
30+
qc = QuantumCircuit(q)
31+
if not hasattr(qc, 'iso'):
32+
raise NotImplementedError
33+
iso = random_unitary(2 ** n, seed=0).data[:, 0:2 ** m]
34+
if len(iso.shape) == 1:
35+
iso = iso.reshape((len(iso), 1))
36+
qc.iso(iso, q[:m], q[m:])
37+
self.circuit = qc
38+
39+
def track_cnot_counts_after_mapping_to_ibmq_16_melbourne(self, *unused):
40+
coupling = [[1, 0], [1, 2], [2, 3], [4, 3], [4, 10], [5, 4],
41+
[5, 6], [5, 9], [6, 8], [7, 8], [9, 8], [9, 10],
42+
[11, 3], [11, 10], [11, 12], [12, 2], [13, 1], [13, 12]]
43+
circuit = transpile(self.circuit, basis_gates=['u1', 'u3', 'u2', 'cx'],
44+
coupling_map=coupling, seed_transpiler=0)
45+
counts = circuit.count_ops()
46+
cnot_count = counts.get('cx', 0)
47+
return cnot_count

0 commit comments

Comments
 (0)