From ef421e5ae8ce23c34bc75bc7786855c181127240 Mon Sep 17 00:00:00 2001 From: Pavol Juhas Date: Mon, 14 Apr 2025 13:19:43 -0700 Subject: [PATCH] Adjust quantum_order_finder result for power-of-two multiples of the actual order Fix test failure where order of 2 for 7 is returned as 6 instead of 3: pytest --randomly-seed=2114237555 examples/examples_test.py --- examples/shor.py | 2 ++ 1 file changed, 2 insertions(+) diff --git a/examples/shor.py b/examples/shor.py index a6ad08a2b8b..63bda4b5b73 100644 --- a/examples/shor.py +++ b/examples/shor.py @@ -268,6 +268,8 @@ def quantum_order_finder(x: int, n: int) -> Optional[int]: r = f.denominator if x**r % n != 1: return None # pragma: no cover + while r % 2 == 0 and x ** (r // 2) > n: + r //= 2 # pragma: no cover return r