From 396f861aabbb65ea719570827962328f37013160 Mon Sep 17 00:00:00 2001 From: Hiroki Hamaguchi Date: Tue, 19 Aug 2025 21:34:36 +0900 Subject: [PATCH 1/2] add execution time test for gridsynth_gates function --- tests/test_exec_time.py | 27 +++++++++++++++++++++++++++ 1 file changed, 27 insertions(+) create mode 100644 tests/test_exec_time.py diff --git a/tests/test_exec_time.py b/tests/test_exec_time.py new file mode 100644 index 0000000..b99796f --- /dev/null +++ b/tests/test_exec_time.py @@ -0,0 +1,27 @@ +import time + +import mpmath +import numpy as np + +from pygridsynth import gridsynth_gates + + +def test_exec_time(): + theta = "0.24" + + for eps, TL in [(1e-30, 1), (1e-40, 1.25), (1e-50, 1.5)]: + t0 = time.perf_counter() + dps = 15 + int(-np.log10(eps) * 2.5) + mpmath.mp.dps = dps + gates = gridsynth_gates( + mpmath.mpmathify(theta), mpmath.mpmathify(eps), decompose_phase_gate=False + ) + t1 = time.perf_counter() + + print(f"eps: {eps}, TL: {TL}, time: {t1 - t0:.2f} seconds") + print(f"{gates=}") + assert t1 - t0 < TL, f"Execution time exceeded for eps={eps}, TL={TL}" + + +if __name__ == "__main__": + test_exec_time() From e51be2e1192a8ec323fdb8497fb911cef547f85f Mon Sep 17 00:00:00 2001 From: Hiroki Hamaguchi Date: Tue, 19 Aug 2025 21:40:10 +0900 Subject: [PATCH 2/2] remove numpy and use mpmath for the GitHub test. --- tests/test_exec_time.py | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/tests/test_exec_time.py b/tests/test_exec_time.py index b99796f..6792c31 100644 --- a/tests/test_exec_time.py +++ b/tests/test_exec_time.py @@ -1,7 +1,6 @@ import time import mpmath -import numpy as np from pygridsynth import gridsynth_gates @@ -11,7 +10,7 @@ def test_exec_time(): for eps, TL in [(1e-30, 1), (1e-40, 1.25), (1e-50, 1.5)]: t0 = time.perf_counter() - dps = 15 + int(-np.log10(eps) * 2.5) + dps = 15 + int(-mpmath.log10(mpmath.mpmathify(eps)) * 2.5) mpmath.mp.dps = dps gates = gridsynth_gates( mpmath.mpmathify(theta), mpmath.mpmathify(eps), decompose_phase_gate=False