From 68b72ab58810a9e9a87d110bf23d19053ff5cdf2 Mon Sep 17 00:00:00 2001 From: Matthew Treinish Date: Thu, 14 Oct 2021 19:03:40 -0400 Subject: [PATCH 1/5] Add benchmarks for missing passes This commit adds runtime benchmarks to the passes and mapping_passes benchmark modules to measure additional transpiler passes in isolation that we didn't have coverage for previously. Primarily of importance here are the basis translator and the optimize 1q decomposition passes which are in the preset pass managers but didn't have standalone benchmark coverage. One pass excluded here is the TemplateOptimization pass which would have been good to add to the benchmark but it is exceedingly slow and took well more than 5 min per iteration. --- test/benchmarks/mapping_passes.py | 19 +++++++++++++++- test/benchmarks/passes.py | 37 ++++++++++++++++++++++++++++++- 2 files changed, 54 insertions(+), 2 deletions(-) diff --git a/test/benchmarks/mapping_passes.py b/test/benchmarks/mapping_passes.py index 55bed7ffc00b..bf3aab62604b 100644 --- a/test/benchmarks/mapping_passes.py +++ b/test/benchmarks/mapping_passes.py @@ -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 @@ -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], @@ -152,8 +160,17 @@ def setup(self, n_qubits, depth): self.routed_dag = StochasticSwap(self.coupling_map, seed=42).run(self.dag) - def time_cxdirection(self, _, __): + def time_cx_direction(self, _, __): CXDirection(self.coupling_map).run(self.routed_dag) 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) diff --git a/test/benchmarks/passes.py b/test/benchmarks/passes.py index 386bdbd3f76e..2c76a26cf213 100644 --- a/test/benchmarks/passes.py +++ b/test/benchmarks/passes.py @@ -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 +from qiskit.circuit.equivalence_library import SessionEquivalenceLibrary as SEL from qiskit.transpiler.passes import * from qiskit.converters import circuit_to_dag @@ -88,6 +89,31 @@ def time_optimize_1q(self, _, __): Optimize1qGates().run(self.unrolled_dag) +class MultipleBasisPassBenchmarks: + params = ([5, 14, 20], + [1024], + [['u', 'cx'], ['rx', 'ry', 'rz', 'r', 'rxx'], + ['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]) @@ -161,3 +187,12 @@ 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) From 0b6f35ccec5ac4f779779f10e4cb3d8268009ada Mon Sep 17 00:00:00 2001 From: Matthew Treinish Date: Fri, 15 Oct 2021 10:09:59 -0400 Subject: [PATCH 2/5] Update test/benchmarks/mapping_passes.py --- test/benchmarks/mapping_passes.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/test/benchmarks/mapping_passes.py b/test/benchmarks/mapping_passes.py index bf3aab62604b..b33ed36915d8 100644 --- a/test/benchmarks/mapping_passes.py +++ b/test/benchmarks/mapping_passes.py @@ -160,7 +160,7 @@ def setup(self, n_qubits, depth): self.routed_dag = StochasticSwap(self.coupling_map, seed=42).run(self.dag) - def time_cx_direction(self, _, __): + def time_cxdirection(self, _, __): CXDirection(self.coupling_map).run(self.routed_dag) def time_check_cx_direction(self, _, __): From 3bb80833f66f33deeaa2dadb632be4d2850d0245 Mon Sep 17 00:00:00 2001 From: Matthew Treinish Date: Fri, 15 Oct 2021 10:44:44 -0400 Subject: [PATCH 3/5] Add collect multi q block benchmark --- test/benchmarks/passes.py | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) diff --git a/test/benchmarks/passes.py b/test/benchmarks/passes.py index 2c76a26cf213..57d0a9c7a8e3 100644 --- a/test/benchmarks/passes.py +++ b/test/benchmarks/passes.py @@ -196,3 +196,20 @@ def time_gates_in_basis(self, _, __): 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', 'lock_max_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) From 2ab2f285b3a5edccda62745d51cd2a397be28490 Mon Sep 17 00:00:00 2001 From: Matthew Treinish Date: Fri, 15 Oct 2021 12:36:56 -0400 Subject: [PATCH 4/5] Update test/benchmarks/passes.py Co-authored-by: Jake Lishman --- test/benchmarks/passes.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/test/benchmarks/passes.py b/test/benchmarks/passes.py index 57d0a9c7a8e3..e856ce6a57cc 100644 --- a/test/benchmarks/passes.py +++ b/test/benchmarks/passes.py @@ -202,7 +202,7 @@ class MultiQBlockPassBenchmarks: params = ([5, 14, 20], [1024], [1, 2, 3, 4, 5]) - param_names = ['n_qubits', 'depth', 'lock_max_size'] + param_names = ['n_qubits', 'depth', 'max_block_size'] timeout = 300 def setup(self, n_qubits, depth, _): From a8e0d953977521b78ed67efa69757a7be9a72155 Mon Sep 17 00:00:00 2001 From: Matthew Treinish Date: Mon, 18 Oct 2021 17:51:36 -0400 Subject: [PATCH 5/5] Update test/benchmarks/passes.py Co-authored-by: Kevin Krsulich --- test/benchmarks/passes.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/test/benchmarks/passes.py b/test/benchmarks/passes.py index e856ce6a57cc..deb1ba3c2be6 100644 --- a/test/benchmarks/passes.py +++ b/test/benchmarks/passes.py @@ -92,7 +92,7 @@ def time_optimize_1q(self, _, __): class MultipleBasisPassBenchmarks: params = ([5, 14, 20], [1024], - [['u', 'cx'], ['rx', 'ry', 'rz', 'r', 'rxx'], + [['u', 'cx', 'id'], ['rx', 'ry', 'rz', 'r', 'rxx', 'id'], ['rz', 'x', 'sx', 'cx', 'id']]) param_names = ['n_qubits', 'depth', 'basis_gates']