Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Remove patching of SwapGate.__new__ from Sabre test #11012

Merged
merged 1 commit into from
Oct 13, 2023
Merged
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
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