From eeff4cd23503c0cd9ffbb678286b9c14891c69d7 Mon Sep 17 00:00:00 2001 From: ShellyGarion Date: Sun, 22 Dec 2024 09:10:22 -0600 Subject: [PATCH] make the choice of kak_gate deterministic --- qiskit/transpiler/passes/synthesis/unitary_synthesis.py | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/qiskit/transpiler/passes/synthesis/unitary_synthesis.py b/qiskit/transpiler/passes/synthesis/unitary_synthesis.py index fb47a29d7a5c..49c9dca1d4fa 100644 --- a/qiskit/transpiler/passes/synthesis/unitary_synthesis.py +++ b/qiskit/transpiler/passes/synthesis/unitary_synthesis.py @@ -128,14 +128,14 @@ def _choose_kak_gate(basis_gates): """Choose the first available 2q gate to use in the KAK decomposition.""" kak_gate = None - kak_gates = set(basis_gates or []).intersection(KAK_GATE_NAMES.keys()) - kak_gates_params = set(basis_gates or []).intersection(KAK_GATE_PARAM_NAMES.keys()) + kak_gates = sorted(set(basis_gates or []).intersection(KAK_GATE_NAMES.keys())) + kak_gates_params = sorted(set(basis_gates or []).intersection(KAK_GATE_PARAM_NAMES.keys())) if kak_gates_params: - kak_gate = KAK_GATE_PARAM_NAMES[kak_gates_params.pop()] + kak_gate = KAK_GATE_PARAM_NAMES[kak_gates_params[0]] elif kak_gates: - kak_gate = KAK_GATE_NAMES[kak_gates.pop()] + kak_gate = KAK_GATE_NAMES[kak_gates[0]] return kak_gate