From a1c9e6fecb5604b2c23d6b1948f592cc7904b448 Mon Sep 17 00:00:00 2001 From: Michael Hucka Date: Tue, 25 Mar 2025 21:31:01 -0700 Subject: [PATCH 1/2] Fix frequent test failure in greedy_test.py On my MacOS 15.x Apple M1 laptop, I frequently get a test failure in `cirq-core/cirq/contrib/routing/greedy_test.py`: ``` [gw2] darwin -- Python 3.11.9 /Users/mhucka/.pyenv/versions/cirq-py311-np1/bin/python3 def test_router_hanging(): """Run a separate process and check if greedy router hits timeout (5s).""" circuit, device_graph = create_circuit_and_device() process = Process(target=create_hanging_routing_instance, args=[circuit, device_graph]) process.start() process.join(timeout=5) try: > assert not process.is_alive(), "Greedy router timeout" E AssertionError: Greedy router timeout E assert not True E + where True = is_alive() E + where is_alive = .is_alive cirq-core/cirq/contrib/routing/greedy_test.py:58: AssertionError ``` This happens with Python 3.10 and 3.12 as well. Since assertion being tested is that the process is _not_ alive, it seems that 5 seconds can be too short. And indeed, the timeout is increased to 20 seconds, the error never seems to occur in my local Mac testing. It's not obvious whether a short timeout is needed for the purposes of the test. Shortening the duration to 10 sec also works, but might not in other people's environments. So, 20 sec seems safer. However, if it needs to be as short as possible, then 10 seconds seems workable too. --- cirq-core/cirq/contrib/routing/greedy_test.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/cirq-core/cirq/contrib/routing/greedy_test.py b/cirq-core/cirq/contrib/routing/greedy_test.py index 977484a82f5..26cc9e20e39 100644 --- a/cirq-core/cirq/contrib/routing/greedy_test.py +++ b/cirq-core/cirq/contrib/routing/greedy_test.py @@ -53,7 +53,7 @@ def test_router_hanging(): circuit, device_graph = create_circuit_and_device() process = Process(target=create_hanging_routing_instance, args=[circuit, device_graph]) process.start() - process.join(timeout=5) + process.join(timeout=20) try: assert not process.is_alive(), "Greedy router timeout" finally: From 428433c1e9239acb9c2f9413dc185f0038097c15 Mon Sep 17 00:00:00 2001 From: Michael Hucka Date: Tue, 25 Mar 2025 23:42:54 -0700 Subject: [PATCH 2/2] Update docstring to match change in code --- cirq-core/cirq/contrib/routing/greedy_test.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/cirq-core/cirq/contrib/routing/greedy_test.py b/cirq-core/cirq/contrib/routing/greedy_test.py index 26cc9e20e39..b64cd24623b 100644 --- a/cirq-core/cirq/contrib/routing/greedy_test.py +++ b/cirq-core/cirq/contrib/routing/greedy_test.py @@ -49,7 +49,7 @@ def create_hanging_routing_instance(circuit, device_graph): def test_router_hanging(): - """Run a separate process and check if greedy router hits timeout (5s).""" + """Run a separate process and check if greedy router hits timeout (20s).""" circuit, device_graph = create_circuit_and_device() process = Process(target=create_hanging_routing_instance, args=[circuit, device_graph]) process.start()