Skip to content

Commit 0a74ef8

Browse files
committed
Add test: swap_test
1 parent a4cb8ba commit 0a74ef8

File tree

1 file changed

+33
-0
lines changed

1 file changed

+33
-0
lines changed

tests/notebooks/test_swap_test.py

+33
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
from tests.utils_for_testbook import (
2+
validate_quantum_program_size,
3+
validate_quantum_model,
4+
wrap_testbook,
5+
)
6+
from testbook.client import TestbookNotebookClient
7+
8+
import numpy as np
9+
10+
11+
@wrap_testbook(
12+
"swap_test",
13+
timeout_seconds=40,
14+
)
15+
def test_notebook(tb: TestbookNotebookClient) -> None:
16+
"""
17+
A notebook for a hybrid classical quantum neural network.
18+
The test verifies that the pre-trained model is indeed well trained.
19+
"""
20+
# test models
21+
validate_quantum_model(tb.ref("qmod"))
22+
# test quantum programs
23+
validate_quantum_program_size(
24+
tb.ref("qprog"),
25+
expected_width=10, # actual width: 7
26+
expected_depth=150, # actual depth: 122
27+
)
28+
29+
# test notebook content
30+
RTOL = 0.05
31+
assert np.isclose(
32+
tb.ref("overlap_from_swap_test"), tb.ref("exact_overlap"), RTOL
33+
), f"The quantum result is too far than classical one, by a relative tolerance of {RTOL}. Please verify your parameters"

0 commit comments

Comments
 (0)