From f7375c178590c3e5e48d1366b119feadcc8bf464 Mon Sep 17 00:00:00 2001 From: Matthew Treinish Date: Wed, 25 Oct 2023 12:33:22 -0400 Subject: [PATCH 1/2] Always run vf2 scoring serially The VF2Layout and VF2PostLayout passes' Rust scoring function has the option to use a parallel iterator for computing the score of a layout given a sufficiently large circuit (both in number of 2q interactions or qubits). Previously the scoring would be multithreaded if there were > 50 qubits or > 50 2q interactions in the circuit. However, as recent testing has shown in most cases the performance of doing this operation in parallel is much worse than serial execution. To address this issue, this commit just always uses the serial version. The parallel option is left in place for now just in case someone was manually calling the scoring function with the parallel option set to ``True``. --- qiskit/transpiler/passes/layout/vf2_layout.py | 6 ------ qiskit/transpiler/passes/layout/vf2_post_layout.py | 7 ------- qiskit/transpiler/passes/layout/vf2_utils.py | 2 +- 3 files changed, 1 insertion(+), 14 deletions(-) diff --git a/qiskit/transpiler/passes/layout/vf2_layout.py b/qiskit/transpiler/passes/layout/vf2_layout.py index 9eb2b4d68284..d6de8f51d31f 100644 --- a/qiskit/transpiler/passes/layout/vf2_layout.py +++ b/qiskit/transpiler/passes/layout/vf2_layout.py @@ -12,7 +12,6 @@ """VF2Layout pass to find a layout using subgraph isomorphism""" -import os from enum import Enum import itertools import logging @@ -172,10 +171,6 @@ def run(self, dag): chosen_layout_score = None start_time = time.time() trials = 0 - run_in_parallel = ( - os.getenv("QISKIT_IN_PARALLEL", "FALSE").upper() != "TRUE" - or os.getenv("QISKIT_FORCE_THREADS", "FALSE").upper() == "TRUE" - ) def mapping_to_layout(layout_mapping): return Layout({reverse_im_graph_node_map[k]: v for k, v in layout_mapping.items()}) @@ -204,7 +199,6 @@ def mapping_to_layout(layout_mapping): reverse_im_graph_node_map, im_graph, self.strict_direction, - run_in_parallel, ) # If the layout score is 0 we can't do any better and we'll just # waste time finding additional mappings that will at best match diff --git a/qiskit/transpiler/passes/layout/vf2_post_layout.py b/qiskit/transpiler/passes/layout/vf2_post_layout.py index 96ffc745b451..cee0e1cf04a8 100644 --- a/qiskit/transpiler/passes/layout/vf2_post_layout.py +++ b/qiskit/transpiler/passes/layout/vf2_post_layout.py @@ -12,7 +12,6 @@ """VF2PostLayout pass to find a layout after transpile using subgraph isomorphism""" -import os from enum import Enum import logging import inspect @@ -253,10 +252,6 @@ def run(self, dag): call_limit=self.call_limit, ) chosen_layout = None - run_in_parallel = ( - os.getenv("QISKIT_IN_PARALLEL", "FALSE").upper() != "TRUE" - or os.getenv("QISKIT_FORCE_THREADS", "FALSE").upper() == "TRUE" - ) try: if self.strict_direction: initial_layout = Layout({bit: index for index, bit in enumerate(dag.qubits)}) @@ -276,7 +271,6 @@ def run(self, dag): reverse_im_graph_node_map, im_graph, self.strict_direction, - run_in_parallel, ) # Circuit not in basis so we have nothing to compare against return here except KeyError: @@ -309,7 +303,6 @@ def run(self, dag): reverse_im_graph_node_map, im_graph, self.strict_direction, - run_in_parallel, ) logger.debug("Trial %s has score %s", trials, layout_score) if layout_score < chosen_layout_score: diff --git a/qiskit/transpiler/passes/layout/vf2_utils.py b/qiskit/transpiler/passes/layout/vf2_utils.py index ed14df998caa..b6fc73f18802 100644 --- a/qiskit/transpiler/passes/layout/vf2_utils.py +++ b/qiskit/transpiler/passes/layout/vf2_utils.py @@ -102,7 +102,7 @@ def score_layout( _reverse_bit_map, im_graph, strict_direction=False, - run_in_parallel=True, + run_in_parallel=False, ): """Score a layout given an average error map.""" if layout_mapping: From a86803271e0b07dafaee605a735ceb2136db8f47 Mon Sep 17 00:00:00 2001 From: Matthew Treinish Date: Thu, 26 Oct 2023 14:30:29 -0400 Subject: [PATCH 2/2] Add release note --- releasenotes/notes/vf2-threading-b778a36de5b8832a.yaml | 8 ++++++++ 1 file changed, 8 insertions(+) create mode 100644 releasenotes/notes/vf2-threading-b778a36de5b8832a.yaml diff --git a/releasenotes/notes/vf2-threading-b778a36de5b8832a.yaml b/releasenotes/notes/vf2-threading-b778a36de5b8832a.yaml new file mode 100644 index 000000000000..e813f9ed5129 --- /dev/null +++ b/releasenotes/notes/vf2-threading-b778a36de5b8832a.yaml @@ -0,0 +1,8 @@ +--- +other: + - | + The :class:`.VF2Layout` and :class:`.VF2PostLayout` transpiler passes previously would + potentially run their internal scoring using multithreading if the input + circuit's were sufficiently large. However, the multithreading usage has + been removed from the passes as it was shown to cause a performance + regression instead of an improvement like originally intended.