Skip to content

Commit 78b5611

Browse files
Merge pull request #18 from quantum-programming/fix-the-args-of-gridsynth_gates
add execution time test for gridsynth_gates function
2 parents 53f5920 + e51be2e commit 78b5611

1 file changed

Lines changed: 26 additions & 0 deletions

File tree

tests/test_exec_time.py

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
import time
2+
3+
import mpmath
4+
5+
from pygridsynth import gridsynth_gates
6+
7+
8+
def test_exec_time():
9+
theta = "0.24"
10+
11+
for eps, TL in [(1e-30, 1), (1e-40, 1.25), (1e-50, 1.5)]:
12+
t0 = time.perf_counter()
13+
dps = 15 + int(-mpmath.log10(mpmath.mpmathify(eps)) * 2.5)
14+
mpmath.mp.dps = dps
15+
gates = gridsynth_gates(
16+
mpmath.mpmathify(theta), mpmath.mpmathify(eps), decompose_phase_gate=False
17+
)
18+
t1 = time.perf_counter()
19+
20+
print(f"eps: {eps}, TL: {TL}, time: {t1 - t0:.2f} seconds")
21+
print(f"{gates=}")
22+
assert t1 - t0 < TL, f"Execution time exceeded for eps={eps}, TL={TL}"
23+
24+
25+
if __name__ == "__main__":
26+
test_exec_time()

0 commit comments

Comments
 (0)