Skip to content
This repository was archived by the owner on Aug 19, 2023. It is now read-only.
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 17 additions & 0 deletions test/benchmarks/mapping_passes.py
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,11 @@ def time_stochastic_swap(self, _, __):
swap.property_set['layout'] = self.layout
swap.run(self.dag)

def time_sabre_swap(self, _, __):
swap = SabreSwap(self.coupling_map, seed=42)
swap.property_set['layout'] = self.layout
swap.run(self.dag)

def time_basic_swap(self, _, __):
swap = BasicSwap(self.coupling_map)
swap.property_set['layout'] = self.layout
Expand Down Expand Up @@ -111,6 +116,9 @@ def time_set_layout(self, _, __):
def time_noise_adaptive_layout(self, _, __):
NoiseAdaptiveLayout(self.backend_props).run(self.fresh_dag)

def time_sabre_layout(self, _, __):
SabreLayout(self.coupling_map, seed=42).run(self.fresh_dag)


class RoutedPassBenchmarks:
params = ([5, 14, 20],
Expand Down Expand Up @@ -157,3 +165,12 @@ def time_cxdirection(self, _, __):

def time_check_cx_direction(self, _, __):
CheckCXDirection(self.coupling_map).run(self.routed_dag)

def time_gate_direction(self, _, __):
GateDirection(self.coupling_map).run(self.routed_dag)

def time_check_gate_direction(self, _, __):
CheckGateDirection(self.coupling_map).run(self.routed_dag)

def time_check_map(self, _, __):
CheckMap(self.coupling_map).run(self.routed_dag)
54 changes: 53 additions & 1 deletion test/benchmarks/passes.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,10 @@

# pylint: disable=no-member,invalid-name,missing-docstring,no-name-in-module
# pylint: disable=attribute-defined-outside-init,unsubscriptable-object
# pylint: disable=unused-wildcard-import,wildcard-import
# pylint: disable=unused-wildcard-import,wildcard-import,undefined-variable
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What's pylint complaining about that requires this? By name, at least, it sounds like something we shouldn't be ignoring.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's because pylint runs with the latest terra release and there are passes I'm adding benchmarks for here that are only on main. So pylint was complaining about an undefined variable for those passes.

Honestly I should just turn pylint off for the benchmarks and use flake8 and black only since it is serving a different use case than the other things being linted in this repo

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ah, that makes sense. Yeah, given the huge number of exclusions here, stopping pylint on these files is probably a good idea.



from qiskit.circuit.equivalence_library import SessionEquivalenceLibrary as SEL
from qiskit.transpiler.passes import *
from qiskit.converters import circuit_to_dag

Expand Down Expand Up @@ -88,6 +89,31 @@ def time_optimize_1q(self, _, __):
Optimize1qGates().run(self.unrolled_dag)


class MultipleBasisPassBenchmarks:
params = ([5, 14, 20],
[1024],
[['u', 'cx', 'id'], ['rx', 'ry', 'rz', 'r', 'rxx', 'id'],
['rz', 'x', 'sx', 'cx', 'id']])

param_names = ['n_qubits', 'depth', 'basis_gates']
timeout = 300

def setup(self, n_qubits, depth, basis_gates):
seed = 42
self.circuit = random_circuit(n_qubits, depth, measure=True, seed=seed)
self.dag = circuit_to_dag(self.circuit)
self.basis_gates = basis_gates

def time_optimize_1q_decompose(self, _, __, ___):
Optimize1qGatesDecomposition(self.basis_gates).run(self.dag)

def time_optimize_1q_commutation(self, _, __, ___):
Optimize1qGatesSimpleCommutation(self.basis_gates).run(self.dag)

def time_basis_translator(self, _, __, ___):
BasisTranslator(SEL, self.basis_gates).run(self.dag)


class PassBenchmarks:
params = ([5, 14, 20],
[1024])
Expand Down Expand Up @@ -161,3 +187,29 @@ def time_remove_diagonal_gates_before_measurement(self, _, __):

def time_remove_final_measurements(self, _, __):
RemoveFinalMeasurements().run(self.dag)

def time_contains_instruction(self, _, __):
ContainsInstruction('cx').run(self.dag)

def time_gates_in_basis(self, _, __):
GatesInBasis(self.basis_gates).run(self.dag)

def time_remove_barriers(self, _, __):
RemoveBarriers().run(self.dag)


class MultiQBlockPassBenchmarks:
params = ([5, 14, 20],
[1024], [1, 2, 3, 4, 5])

param_names = ['n_qubits', 'depth', 'max_block_size']
timeout = 300

def setup(self, n_qubits, depth, _):
seed = 42
self.circuit = random_circuit(n_qubits, depth, measure=True,
conditional=True, reset=True, seed=seed)
self.dag = circuit_to_dag(self.circuit)

def time_collect_multiq_block(self, _, __, max_block_size):
CollectMultiQBlocks(max_block_size).run(self.dag)