From 41be5f1afcf9ffe7907b36545acfc6b42fff7fed Mon Sep 17 00:00:00 2001 From: Jake Lishman Date: Wed, 7 Aug 2024 18:43:28 +0100 Subject: [PATCH] Remove useless catch in circuit visualisation intersection check The intersection logic in here previously included a catch statement that was attempting to avoid to count the span of a `DAGOpNode` if it was already in the layer being examined. If the node to be inserted is already in the layer being examined, the drawer should not be attempting to re-insert it at all - it's already been accounted for. The previous catch should always have failed, because `DAGOpNode` equality would have decayed to `object.__eq__`, which is just `is` logic. On this new branch, `DAGOpNode` has an actual equality check, which can allow two non-referentially equal nodes (as might be created by `DAGCircuit.layers`) to compare logically equal. --- qiskit/visualization/circuit/_utils.py | 11 +++++------ 1 file changed, 5 insertions(+), 6 deletions(-) diff --git a/qiskit/visualization/circuit/_utils.py b/qiskit/visualization/circuit/_utils.py index e6ee03905d27..0eac8ce5f383 100644 --- a/qiskit/visualization/circuit/_utils.py +++ b/qiskit/visualization/circuit/_utils.py @@ -515,12 +515,11 @@ def _get_gate_span(qubits, node): def _any_crossover(qubits, node, nodes): """Return True .IFF. 'node' crosses over any 'nodes'.""" - gate_span = _get_gate_span(qubits, node) - all_indices = [] - for check_node in nodes: - if check_node != node: - all_indices += _get_gate_span(qubits, check_node) - return any(i in gate_span for i in all_indices) + return bool( + set(_get_gate_span(qubits, node)).intersection( + bit for check_node in nodes for bit in _get_gate_span(qubits, check_node) + ) + ) class _LayerSpooler(list):