Skip to content
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
25 changes: 25 additions & 0 deletions tests/notebooks/workshops/test_Qmod_tutorial_part1.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
from tests.utils_for_testbook import (
validate_quantum_program_size,
validate_quantum_model,
wrap_testbook,
)
from testbook.client import TestbookNotebookClient


@wrap_testbook("Qmod_tutorial_part1", timeout_seconds=500)
def test_notebook(tb: TestbookNotebookClient) -> None:
# todo: Has many overwrites of `qmod` and `qprog`
# as well as many missing places of "put your code"

# test models
validate_quantum_model(tb.ref("qmod"))

# test quantum programs
validate_quantum_program_size(
tb.ref("qprog"),
expected_width=7, # actual width: 5
expected_depth=100, # actual depth: 64
)

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


@wrap_testbook("Qmod_tutorial_part2", timeout_seconds=500)
def test_notebook(tb: TestbookNotebookClient) -> None:
# todo: Has many overwrites of `qmod` and `qprog`
# as well as many missing places of "put your code"

# test models
validate_quantum_model(tb.ref("qmod"))

# test quantum programs
validate_quantum_program_size(
tb.ref("qprog"),
expected_width=5, # actual width: 3
expected_depth=40, # actual depth: 22
)

# test notebook content
pass # Todo
22 changes: 22 additions & 0 deletions tests/notebooks/workshops/test_classiq_overview_tutorial.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("classiq_overview_tutorial", timeout_seconds=500)
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=20, # actual width: 16
expected_depth=300, # actual depth: 225
)

# test notebook content
pass # Todo
24 changes: 24 additions & 0 deletions tests/notebooks/workshops/test_synthesis_tutorial.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("synthesis_tutorial", timeout_seconds=500)
def test_notebook(tb: TestbookNotebookClient) -> None:
# test quantum programs
validate_quantum_program_size(
tb.ref("qprog_opt_depth"),
expected_width=20, # actual width: 16
expected_depth=250, # actual depth: 171
)
validate_quantum_program_size(
tb.ref("qprog_opt_width"),
expected_width=20, # actual width: 9
expected_depth=250, # actual depth: 199
)

# test notebook content
pass # Todo
3 changes: 2 additions & 1 deletion tests/test_notebooks.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
from contextlib import contextmanager

from testbook import testbook # type: ignore[import]
from utils_for_tests import iterate_notebooks
from utils_for_tests import iterate_notebooks, ROOT_DIRECTORY

TIMEOUT: int = 60 * 10 # 10 minutes
LOGGER = logging.getLogger(__name__)
Expand All @@ -22,6 +22,7 @@ def test_notebooks() -> None:
@contextmanager
def cwd(path):
oldpwd = os.getcwd()
os.chdir(ROOT_DIRECTORY)
os.chdir(path)
try:
yield
Expand Down
67 changes: 39 additions & 28 deletions tutorials/Classiq_tutorial/Qmod_tutorial_part1.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -19,23 +19,26 @@
},
{
"cell_type": "code",
"execution_count": 11,
"execution_count": 1,
"metadata": {},
"outputs": [],
"source": [
"from classiq import *\n",
"\n",
"\n",
"@qfunc\n",
"def foo(q: QBit) -> None:\n",
" X(q)\n",
" H(q)\n",
"\n",
"\n",
"@qfunc\n",
"def main(q: Output[QBit]) -> None:\n",
" allocate(q)\n",
" foo(q)\n",
"\n",
"qmod = create_model(main)"
"\n",
"qmod = create_model(main)"
]
},
{
Expand All @@ -57,16 +60,16 @@
},
{
"cell_type": "code",
"execution_count": 12,
"execution_count": 2,
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"[{'q': 1}: 1032, {'q': 0}: 1016]"
"[{'q': 0}: 1057, {'q': 1}: 991]"
]
},
"execution_count": 12,
"execution_count": 2,
"metadata": {},
"output_type": "execute_result"
}
Expand Down Expand Up @@ -119,16 +122,16 @@
},
{
"cell_type": "code",
"execution_count": 4,
"execution_count": 3,
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"[{'q': 1}: 1066, {'q': 0}: 982]"
"[{'q': 1}: 1065, {'q': 0}: 983]"
]
},
"execution_count": 4,
"execution_count": 3,
"metadata": {},
"output_type": "execute_result"
}
Expand All @@ -140,7 +143,7 @@
"...\n",
"\n",
"# execute the model to see that we get similar results\n",
"qmod = create_model(main)\n",
"qmod = create_model(main)\n",
"qprog = synthesize(qmod)\n",
"job = execute(qprog)\n",
"job.get_sample_result().parsed_counts"
Expand Down Expand Up @@ -186,7 +189,7 @@
"...\n",
"\n",
"# execute and inspect the results\n",
"qmod = create_model(main)\n",
"qmod = create_model(main)\n",
"qprog = synthesize(qmod)\n",
"job = execute(qprog)\n",
"job.get_sample_result().parsed_counts"
Expand Down Expand Up @@ -230,8 +233,8 @@
"...\n",
"\n",
"# synthesize the model and show the result\n",
"model = create_model(main)\n",
"qprog = synthesize(model)\n",
"qmod = create_model(main)\n",
"qprog = synthesize(qmod)\n",
"show(qprog)"
]
},
Expand All @@ -258,7 +261,9 @@
"outputs": [],
"source": [
"from typing import List\n",
"\n",
"import numpy as np\n",
"\n",
"from classiq import *\n",
"\n",
"rng = np.random.default_rng(seed=0)\n",
Expand Down Expand Up @@ -419,19 +424,22 @@
"source": [
"from classiq import *\n",
"\n",
"\n",
"# rewrite the model, initializing q inside foo\n",
"@qfunc\n",
"def foo(q: Output[QBit]) -> None:\n",
" allocate(1,q)\n",
" allocate(1, q)\n",
" X(q)\n",
" H(q)\n",
"\n",
"\n",
"@qfunc\n",
"def main(q: Output[QBit]) -> None:\n",
" foo(q)\n",
"\n",
"\n",
"# execute the model to see that we get similar results\n",
"qmod = create_model(main)\n",
"qmod = create_model(main)\n",
"qprog = synthesize(qmod)\n",
"job = execute(qprog)\n",
"job.get_sample_result().parsed_counts"
Expand Down Expand Up @@ -475,8 +483,9 @@
" allocate(2, qarr)\n",
" bell(qarr)\n",
"\n",
"\n",
"# execute and inspect the results\n",
"qmod = create_model(main)\n",
"qmod = create_model(main)\n",
"qprog = synthesize(qmod)\n",
"job = execute(qprog)\n",
"job.get_sample_result().parsed_counts"
Expand Down Expand Up @@ -509,8 +518,8 @@
" my_hadamard_transform(q)\n",
"\n",
"\n",
"model = create_model(main)\n",
"qprog = synthesize(model)\n",
"qmod = create_model(main)\n",
"qprog = synthesize(qmod)\n",
"show(qprog)"
]
},
Expand All @@ -528,7 +537,9 @@
"outputs": [],
"source": [
"from typing import List\n",
"\n",
"import numpy as np\n",
"\n",
"from classiq import *\n",
"\n",
"rng = np.random.default_rng(seed=0)\n",
Expand All @@ -544,8 +555,8 @@
" power(3, lambda: unitary(unitary_matrix, q))\n",
"\n",
"\n",
"model = create_model(main)\n",
"qprog = synthesize(model)\n",
"qmod = create_model(main)\n",
"qprog = synthesize(qmod)\n",
"show(qprog)"
]
},
Expand Down Expand Up @@ -589,8 +600,8 @@
" my_hadamard_transform(q)\n",
"\n",
"\n",
"model = create_model(main)\n",
"qprog = synthesize(model)\n",
"qmod = create_model(main)\n",
"qprog = synthesize(qmod)\n",
"show(qprog)"
]
},
Expand Down Expand Up @@ -630,8 +641,8 @@
" my_controlled_ry(control_bit, target)\n",
"\n",
"\n",
"model = create_model(main)\n",
"qprog = synthesize(model)\n",
"qmod = create_model(main)\n",
"qprog = synthesize(qmod)\n",
"show(qprog)"
]
},
Expand All @@ -658,15 +669,15 @@
" control(x == 9, lambda: X(target))\n",
"\n",
"\n",
"model = create_model(main)\n",
"qprog = synthesize(model)\n",
"qmod = create_model(main)\n",
"qprog = synthesize(qmod)\n",
"show(qprog)"
]
}
],
"metadata": {
"kernelspec": {
"display_name": "external-user-venv-PaJZMdG0-py3.11",
"display_name": "Python 3 (ipykernel)",
"language": "python",
"name": "python3"
},
Expand All @@ -680,9 +691,9 @@
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
"version": "3.11.6"
"version": "3.11.7"
}
},
"nbformat": 4,
"nbformat_minor": 2
"nbformat_minor": 4
}
Loading