Skip to content
Open
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
18 changes: 10 additions & 8 deletions qiskit/transpiler/passes/optimization/consolidate_blocks.py
Original file line number Diff line number Diff line change
Expand Up @@ -117,19 +117,21 @@ def __init__(
self.decomposer = TwoQubitBasisDecomposer(kak_basis_gate)
self.basis_gate_name = kak_basis_gate.name
elif basis_gates is not None:
kak_gates = KAK_GATE_NAMES.keys() & (basis_gates or [])
kak_param_gates = KAK_GATE_PARAM_NAMES.keys() & (basis_gates or [])
if kak_param_gates:
kak_gate = next((gate for gate in KAK_GATE_NAMES if gate in basis_gates), None)
kak_param_gate = next(
(gate for gate in KAK_GATE_PARAM_NAMES if gate in basis_gates), None
)
Comment on lines -120 to +123
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.

Incredibly minor, but since KAK_GATE_NAMES and KAK_GATE_PARAM_NAMES are reliably dict, but basis_gates is a list, you might want to drive the iteration from basis_gates and lookup into KAK_GATE_NAMES instead, especially if you're in the habit of passing huge basis_gates lists.

if kak_param_gate is not None:
self.decomposer = TwoQubitControlledUDecomposer(
KAK_GATE_PARAM_NAMES[next(iter(kak_param_gates))]
KAK_GATE_PARAM_NAMES[kak_param_gate]
)
self.basis_gate_name = next(iter(kak_param_gates))
elif kak_gates:
self.basis_gate_name = kak_param_gate
elif kak_gate is not None:
self.decomposer = TwoQubitBasisDecomposer(
KAK_GATE_NAMES[next(iter(kak_gates))],
KAK_GATE_NAMES[kak_gate],
basis_fidelity=approximation_degree or 1.0,
)
self.basis_gate_name = next(iter(kak_gates))
self.basis_gate_name = kak_gate
else:
self.decomposer = None
self.basis_gate_name = "cx"
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
fixes:
- |
Fixed a problem in :class:`.ConsolidateBlocks` where basis gate selection was not always
deterministic, which could lead to different transpiled circuits across runs.
Comment on lines +4 to +5
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.

Can you add a quick mention of the configuration needed to make it non-deterministic too? I think most "common" use of the pass was always deterministic.

Loading