Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add tests for several notebooks #740

Merged
merged 2 commits into from
Feb 6, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 0 additions & 1 deletion .github/workflows/Test-CI-main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,6 @@ jobs:
mask-aws-account-id: true

- name: Install dependencies
if: steps.cache-pip.outputs.cache-hit != 'true'
run: |
set -e
python -m pip install -U pip
Expand Down
30 changes: 30 additions & 0 deletions tests/notebooks/test_3_sat_grover.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
from tests.utils_for_testbook import (
validate_quantum_program_size,
validate_quantum_model,
wrap_testbook,
)
from testbook.client import TestbookNotebookClient


@wrap_testbook(
"3_sat_grover",
timeout_seconds=36,
)
def test_notebook(tb: TestbookNotebookClient) -> None:
# test models
validate_quantum_model(tb.ref("qmod"))
validate_quantum_model(tb.ref("qmod_large"))
# test quantum programs
validate_quantum_program_size(
tb.ref("qprog"),
expected_width=10, # actual width: 10
expected_depth=450, # actual depth: 429
)
validate_quantum_program_size(
tb.ref("qprog_large"),
expected_width=20, # actual width: 19
expected_depth=2500, # actual depth: 2375
)

# test notebook content
pass # TODO
2 changes: 1 addition & 1 deletion tests/notebooks/test_bernstein_vazirani.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@


@wrap_testbook("bernstein_vazirani", timeout_seconds=20)
def test_bernstein_vazirani(tb: TestbookNotebookClient) -> None:
def test_notebook(tb: TestbookNotebookClient) -> None:
# test models
validate_quantum_model(tb.ref("qmod"))
# test quantum programs
Expand Down
19 changes: 19 additions & 0 deletions tests/notebooks/test_deutsch_jozsa.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
from tests.utils_for_testbook import (
validate_quantum_program_size,
validate_quantum_model,
wrap_testbook,
)
from testbook.client import TestbookNotebookClient


@wrap_testbook("deutsch_jozsa", timeout_seconds=48)
def test_notebook(tb: TestbookNotebookClient) -> None:
# test models
validate_quantum_model(tb.ref("qmod"))
# test quantum programs
validate_quantum_program_size(
tb.ref("qprog"), expected_width=None, expected_depth=None
)

# test notebook content
pass
21 changes: 21 additions & 0 deletions tests/notebooks/test_discrete_poisson_solver.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
from tests.utils_for_testbook import (
validate_quantum_program_size,
validate_quantum_model,
wrap_testbook,
)
from testbook.client import TestbookNotebookClient


@wrap_testbook("discrete_poisson_solver", timeout_seconds=300)
def test_notebook(tb: TestbookNotebookClient) -> None:
# test models
validate_quantum_model(tb.ref("qmod"))
# test quantum programs
validate_quantum_program_size(
tb.ref("qprog"),
expected_width=16, # actual width: 16
expected_depth=12000, # actual depth: 11538
)

# test notebook content
pass # TODO
12 changes: 12 additions & 0 deletions tests/notebooks/test_glued_trees.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
from tests.utils_for_testbook import (
validate_quantum_program_size,
validate_quantum_model,
wrap_testbook,
)
from testbook.client import TestbookNotebookClient


@wrap_testbook("glued_trees", timeout_seconds=500)
def test_notebook(tb: TestbookNotebookClient) -> None:
# everything in this test is inside a function, storing results in a file
pass # TODO: need to rewrite the notebook in order to test it
24 changes: 24 additions & 0 deletions tests/notebooks/test_grover_max_cut.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
from tests.utils_for_testbook import (
validate_quantum_program_size,
validate_quantum_model,
wrap_testbook,
)
from testbook.client import TestbookNotebookClient


@wrap_testbook(
"grover_max_cut",
timeout_seconds=220,
)
def test_notebook(tb: TestbookNotebookClient) -> None:
# test models
validate_quantum_model(tb.ref("qmod"))
# test quantum programs
validate_quantum_program_size(
tb.ref("qprog"),
expected_width=None, # actual width: ???
expected_depth=None, # actual depth: ???
)

# test notebook content
pass # TODO
3 changes: 2 additions & 1 deletion tests/notebooks/test_hidden_shift.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
"hidden_shift",
timeout_seconds=272, # we may lower this value
)
def test_hidden_shift(tb: TestbookNotebookClient) -> None:
def test_notebook(tb: TestbookNotebookClient) -> None:
# test models
validate_quantum_model(tb.ref("qmod_simple"))
validate_quantum_model(tb.ref("qmod_complex"))
Expand All @@ -31,5 +31,6 @@ def test_hidden_shift(tb: TestbookNotebookClient) -> None:
expected_width=20, # actual width: 20
expected_depth=1700, # actual depth: 1685
)

# test notebook content
pass # TODO
22 changes: 22 additions & 0 deletions tests/notebooks/test_hybrid_qnn_for_subset_majority.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
from tests.utils_for_testbook import (
validate_quantum_program_size,
validate_quantum_model,
wrap_testbook,
)
from testbook.client import TestbookNotebookClient


@wrap_testbook(
"hybrid_qnn_for_subset_majority",
timeout_seconds=120,
)
def test_notebook(tb: TestbookNotebookClient) -> None:
"""
A notebook for a hybrid classical quantum neural network.
The test verifies that the pre-trained model is indeed well trained.
"""

assert (
tb.ref("accuracy") > 0.85
), "The network is not trained, although we load a pre-trained model."
pass
33 changes: 33 additions & 0 deletions tests/notebooks/test_qmc_user_defined.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
from tests.utils_for_testbook import (
validate_quantum_program_size,
validate_quantum_model,
wrap_testbook,
)
from testbook.client import TestbookNotebookClient


@wrap_testbook("qmc_user_defined", timeout_seconds=176)
def test_notebook(tb: TestbookNotebookClient) -> None:
# test models
validate_quantum_model(tb.ref("model"))
validate_quantum_model(tb.ref("model_2"))
validate_quantum_model(tb.ref("model_3"))
# test quantum programs
validate_quantum_program_size(
tb.ref("qprog"),
expected_width=4, # actual width: 4
expected_depth=150, # actual depth: 104
)
validate_quantum_program_size(
tb.ref("qprog_2"),
expected_width=5, # actual width: 4
expected_depth=350, # actual depth: 236
)
validate_quantum_program_size(
tb.ref("qprog_3"),
expected_width=7, # actual width: 7
expected_depth=2500, # actual depth: 2008
)

# test notebook content
pass # TODO
27 changes: 27 additions & 0 deletions tests/notebooks/test_quantum_counting.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
from tests.utils_for_testbook import (
validate_quantum_program_size,
validate_quantum_model,
wrap_testbook,
)
from testbook.client import TestbookNotebookClient


@wrap_testbook("quantum_counting", timeout_seconds=300)
def test_notebook(tb: TestbookNotebookClient) -> None:
# test models
validate_quantum_model(tb.ref("qmod_qpe"))
validate_quantum_model(tb.ref("qmod_iqae"))
# test quantum programs
validate_quantum_program_size(
tb.ref("qprog_qpe"),
expected_width=11, # actual width: 11
expected_depth=8100, # actual depth: 8058
)
validate_quantum_program_size(
tb.ref("qprog_iqae"),
expected_width=6, # actual width: 6
expected_depth=500, # actual depth: 486
)

# test notebook content
pass # TODO
42 changes: 42 additions & 0 deletions tests/notebooks/test_shor.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
from tests.utils_for_testbook import (
validate_quantum_program_size,
validate_quantum_model,
wrap_testbook,
)
from testbook.client import TestbookNotebookClient


@wrap_testbook("shor", timeout_seconds=104)
def test_notebook(tb: TestbookNotebookClient) -> None:
# test models
validate_quantum_model(tb.ref("qmod"))
# test quantum programs
validate_quantum_program_size(
tb.ref("qprog"),
expected_width=12, # actual width: 12
expected_depth=1111, # actual depth: 1099
)

# test notebook content
pass # TODO


@wrap_testbook("shor_modular_exponentiation", timeout_seconds=300)
def test_notebook(tb: TestbookNotebookClient) -> None:
# test models
validate_quantum_model(tb.ref("qmod_1"))
validate_quantum_model(tb.ref("qmod_2"))
# test quantum programs
validate_quantum_program_size(
tb.ref("qprog_1"),
expected_width=8, # actual width: 8
expected_depth=300, # actual depth: 296
)
validate_quantum_program_size(
tb.ref("qprog_2"),
expected_width=22, # actual width: 22
expected_depth=30000, # actual depth: 26607
)

# test notebook content
pass # TODO
Loading