Skip to content

Commit

Permalink
feat: routine verification (#76)
Browse files Browse the repository at this point in the history
* fix: update to compatibility with changes in qref

* feat: add routine verification

* fix: fix tutorials after verification changes
  • Loading branch information
mstechly authored Jun 25, 2024
1 parent 01e64c6 commit cd1940d
Show file tree
Hide file tree
Showing 17 changed files with 558 additions and 170 deletions.
1 change: 0 additions & 1 deletion docs/data/alias_sampling_basic.json
Original file line number Diff line number Diff line change
Expand Up @@ -348,7 +348,6 @@
{
"source": "mu",
"targets": [
"had.mu",
"qrom.mu",
"compare.mu"
]
Expand Down
2 changes: 2 additions & 0 deletions docs/reference.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,3 +11,5 @@
::: bartiq.errors

::: bartiq.integrations

::: bartiq.verification
26 changes: 23 additions & 3 deletions docs/tutorials/01_basic_example.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -271,7 +271,18 @@
"execution_count": 7,
"id": "f3bfa36d-b208-4488-abd6-8b020ef6cffc",
"metadata": {},
"outputs": [],
"outputs": [
{
"name": "stderr",
"output_type": "stream",
"text": [
"/Users/mstechly/.pyenv/versions/3.9.19/envs/2024-06-04-18-validation/lib/python3.9/site-packages/pydantic/_internal/_generate_schema.py:386: UserWarning: typing_extensions.Self is not a Python type (it may be an instance of an object), Pydantic will allow any object with no validation since we cannot even enforce that the input is an instance of the given type. To get rid of this error wrap the type with `pydantic.SkipValidation`.\n",
" warn(\n",
"/Users/mstechly/.pyenv/versions/3.9.19/envs/2024-06-04-18-validation/lib/python3.9/site-packages/pydantic/_internal/_generate_schema.py:386: UserWarning: typing_extensions.Self is not a Python type (it may be an instance of an object), Pydantic will allow any object with no validation since we cannot even enforce that the input is an instance of the given type. To get rid of this error wrap the type with `pydantic.SkipValidation`.\n",
" warn(\n"
]
}
],
"source": [
"from bartiq.integrations import qref_to_bartiq\n",
"uncompiled_routine = qref_to_bartiq(my_algorithm_qref)"
Expand Down Expand Up @@ -327,7 +338,7 @@
{
"data": {
"text/plain": [
"Port(name='out', parent=<Routine name=\"my_algorithm\">, direction='output', size=None, meta={})"
"Port(my_algorithm.#out, size=None, output)"
]
},
"execution_count": 9,
Expand Down Expand Up @@ -386,7 +397,16 @@
"execution_count": 11,
"id": "0163c4b5-16a6-4510-9210-dc84f6711c61",
"metadata": {},
"outputs": [],
"outputs": [
{
"name": "stderr",
"output_type": "stream",
"text": [
"/Users/mstechly/Documents/code/2024-06-04-18-validation/bartiq/src/bartiq/compilation/_compile.py:117: UserWarning: Found the following issues with the provided routine after the compilation has finished: [\"Symbol n_b found in subroutine: my_algorithm.B, which is not among top level params: {'n', 'z'}.\"]\n",
" warnings.warn(\n"
]
}
],
"source": [
"from bartiq import compile_routine\n",
"compiled_routine = compile_routine(uncompiled_routine)"
Expand Down
19 changes: 14 additions & 5 deletions docs/tutorials/02_alias_sampling_basic.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -275,7 +275,7 @@
" \"local_variables\": [\"R=ceiling(log_2(L))\"],\n",
" \"linked_params\": [\n",
" {\"source\": \"L\", \"targets\": [\"usp.L\", \"qrom.L\", \"swap.X\"]},\n",
" {\"source\": \"mu\", \"targets\": [\"had.mu\", \"qrom.mu\", \"compare.mu\"]},\n",
" {\"source\": \"mu\", \"targets\": [\"qrom.mu\", \"compare.mu\"]},\n",
" ],\n",
"}"
]
Expand Down Expand Up @@ -306,7 +306,16 @@
"execution_count": 9,
"id": "d20ef4d2-9420-4090-a402-ee5f27034524",
"metadata": {},
"outputs": [],
"outputs": [
{
"name": "stderr",
"output_type": "stream",
"text": [
"/Users/mstechly/Documents/code/2024-06-04-18-validation/bartiq/src/bartiq/compilation/_compile.py:117: UserWarning: Found the following issues with the provided routine after the compilation has finished: [\"Symbol P_2 found in subroutine: alias_sampling.swap.passthrough_2, which is not among top level params: {'L', 'mu', 'R'}.\", \"Symbol P_1 found in subroutine: alias_sampling.swap.passthrough_1, which is not among top level params: {'L', 'mu', 'R'}.\", \"Symbol P_2 found in subroutine: alias_sampling.swap, which is not among top level params: {'L', 'mu', 'R'}.\"]\n",
" warnings.warn(\n"
]
}
],
"source": [
"from bartiq import compile_routine\n",
"compiled_routine = compile_routine(uncompiled_routine)"
Expand Down Expand Up @@ -483,12 +492,12 @@
{
"data": {
"application/vnd.jupyter.widget-view+json": {
"model_id": "811e911faa5847d59817f59b97115522",
"model_id": "6551d6b59d664fb3a126943b78445c3c",
"version_major": 2,
"version_minor": 0
},
"text/plain": [
"HBox(children=(_RoutineTree(multiple_selection=False, nodes=(Node(name='', nodes=(Node(name='usp'), Node(name="
"HBox(children=(_RoutineTree(multiple_selection=False, nodes=(Node(name='alias_sampling', nodes=(Node(name='com"
]
},
"execution_count": 14,
Expand Down Expand Up @@ -519,7 +528,7 @@
"data": {
"text/latex": [
"$\\displaystyle \\begin{align}\n",
"&\\text{Routine \\textrm{()}}\\newline\n",
"&\\text{Routine \\textrm{(alias\\_sampling)}}\\newline\n",
"&\\underline{\\text{Input ports:}}\\\\\n",
"&\\text{In\\_0} = R\\\\\n",
"&\\text{In\\_1} = 8\\\\\n",
Expand Down
Loading

0 comments on commit cd1940d

Please sign in to comment.