Skip to content

Commit

Permalink
Remove patching of SwapGate.__new__ from Sabre test (#11012)
Browse files Browse the repository at this point in the history
This made sense as a way of tracking the progress of Sabre back when our
implementation was pure-Python and generated the swaps on-the-fly, but
ever since it moved to Rust, the infinite loop would have happened
before any swaps were constructed at all.

With the move to singleton gates, this test can cause problems; the
restoration after the patching can cause issues with the
singleton-return apparatus.
  • Loading branch information
jakelishman committed Oct 13, 2023
1 parent 65e8c1a commit 7a550ad
Showing 1 changed file with 3 additions and 12 deletions.
15 changes: 3 additions & 12 deletions test/python/transpiler/test_sabre_swap.py
Original file line number Diff line number Diff line change
Expand Up @@ -230,18 +230,9 @@ def test_no_infinite_loop(self, method):
coupling_map = CouplingMap.from_line(qc.num_qubits)
routing_pass = PassManager(SabreSwap(coupling_map, method))

n_swap_gates = 0

def leak_number_of_swaps(cls, *args, **kwargs):
nonlocal n_swap_gates
n_swap_gates += 1
if n_swap_gates > 1_000:
raise Exception("SabreSwap seems to be stuck in a loop")
# pylint: disable=bad-super-call
return super(SwapGate, cls).__new__(cls, *args, **kwargs)

with unittest.mock.patch.object(SwapGate, "__new__", leak_number_of_swaps):
routed = routing_pass.run(qc)
# Since all the logic happens in Rust space these days, the best we'll really see here is
# the test hanging.
routed = routing_pass.run(qc)

routed_ops = routed.count_ops()
del routed_ops["swap"]
Expand Down

0 comments on commit 7a550ad

Please sign in to comment.