From 497d5a4c3f6df0ae3392b13034066821380525a8 Mon Sep 17 00:00:00 2001 From: "mergify[bot]" <37929162+mergify[bot]@users.noreply.github.com> Date: Tue, 4 May 2021 23:22:46 +0000 Subject: [PATCH] BasisTranslator skips translating gates already in target basis (#6350) (#6356) * skip translating gates in target basis * Update releasenotes/notes/bugfix-skip-target-basis-translation-12a9fa02c9ceef25.yaml * fix lint issue Co-authored-by: Matthew Treinish Co-authored-by: mergify[bot] <37929162+mergify[bot]@users.noreply.github.com> (cherry picked from commit 8aceb73958566c1b59e47c51ebf38c8ea7321351) Co-authored-by: Abdullah Ash- Saki <44783187+ashsaki@users.noreply.github.com> --- qiskit/transpiler/passes/basis/basis_translator.py | 3 +++ ...ugfix-skip-target-basis-translation-12a9fa02c9ceef25.yaml | 5 +++++ 2 files changed, 8 insertions(+) create mode 100644 releasenotes/notes/bugfix-skip-target-basis-translation-12a9fa02c9ceef25.yaml diff --git a/qiskit/transpiler/passes/basis/basis_translator.py b/qiskit/transpiler/passes/basis/basis_translator.py index df329165e61b..7dbea4dee2e0 100644 --- a/qiskit/transpiler/passes/basis/basis_translator.py +++ b/qiskit/transpiler/passes/basis/basis_translator.py @@ -269,6 +269,9 @@ def _basis_search(equiv_lib, source_basis, target_basis, heuristic): closed_set.add(current_basis) for gate_name, gate_num_qubits in current_basis: + if gate_name in target_basis: + continue + equivs = equiv_lib._get_equivalences((gate_name, gate_num_qubits)) basis_remain = current_basis - {(gate_name, gate_num_qubits)} diff --git a/releasenotes/notes/bugfix-skip-target-basis-translation-12a9fa02c9ceef25.yaml b/releasenotes/notes/bugfix-skip-target-basis-translation-12a9fa02c9ceef25.yaml new file mode 100644 index 000000000000..c139b7919036 --- /dev/null +++ b/releasenotes/notes/bugfix-skip-target-basis-translation-12a9fa02c9ceef25.yaml @@ -0,0 +1,5 @@ +--- +fixes: + - | + Fixed an issue with :class:`~qiskit.transpiler.passes.BasisTranslator` where in some + cases it would translate gates already in the target basis.