Skip to content

Commit

Permalink
Updated the tutorials.
Browse files Browse the repository at this point in the history
  • Loading branch information
sitong1011 committed Jun 24, 2024
1 parent 82e429e commit 806d1fb
Show file tree
Hide file tree
Showing 4 changed files with 114 additions and 134 deletions.
Binary file removed docs/images/alias_sampling.png
Binary file not shown.
Binary file removed docs/images/my_algorithm.png
Binary file not shown.
122 changes: 56 additions & 66 deletions docs/tutorials/01_basic_example.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -69,8 +69,8 @@
"id": "6e2460c7-8ec3-4157-8b92-3d8ac5ff300f",
"metadata": {
"ExecuteTime": {
"end_time": "2024-06-24T20:20:03.787166Z",
"start_time": "2024-06-24T20:20:03.775518Z"
"end_time": "2024-06-24T20:58:18.268334Z",
"start_time": "2024-06-24T20:58:18.259199Z"
}
},
"source": [
Expand All @@ -84,7 +84,7 @@
"}"
],
"outputs": [],
"execution_count": 1
"execution_count": 31
},
{
"cell_type": "markdown",
Expand All @@ -107,8 +107,8 @@
"id": "591b4a88-af8c-41ec-bc07-ca0bbe576c70",
"metadata": {
"ExecuteTime": {
"end_time": "2024-06-24T20:20:04.129187Z",
"start_time": "2024-06-24T20:20:04.118808Z"
"end_time": "2024-06-24T20:58:18.403637Z",
"start_time": "2024-06-24T20:58:18.391328Z"
}
},
"source": [
Expand All @@ -122,7 +122,7 @@
"}"
],
"outputs": [],
"execution_count": 2
"execution_count": 32
},
{
"cell_type": "markdown",
Expand All @@ -137,8 +137,8 @@
"id": "76a0ed1a-0acb-489e-b2fc-40ce956b8f49",
"metadata": {
"ExecuteTime": {
"end_time": "2024-06-24T20:20:04.235251Z",
"start_time": "2024-06-24T20:20:04.221155Z"
"end_time": "2024-06-24T20:58:18.438587Z",
"start_time": "2024-06-24T20:58:18.425845Z"
}
},
"source": [
Expand All @@ -153,7 +153,7 @@
"}"
],
"outputs": [],
"execution_count": 3
"execution_count": 33
},
{
"cell_type": "markdown",
Expand All @@ -177,8 +177,8 @@
"id": "697c5cdb-abb8-4437-97e8-d3a1e4de1ca2",
"metadata": {
"ExecuteTime": {
"end_time": "2024-06-24T20:20:04.360747Z",
"start_time": "2024-06-24T20:20:04.340596Z"
"end_time": "2024-06-24T20:58:18.530086Z",
"start_time": "2024-06-24T20:58:18.521327Z"
}
},
"source": [
Expand All @@ -191,7 +191,7 @@
"routine_b[\"resources\"] = [{\"name\": \"T_gates\", \"type\": \"additive\", \"value\": \"n_b*ceil(log_2(n_b)) * y\"}]"
],
"outputs": [],
"execution_count": 4
"execution_count": 34
},
{
"cell_type": "markdown",
Expand All @@ -214,8 +214,8 @@
"id": "3cc1dcef-a151-401b-a818-3be783aa68f9",
"metadata": {
"ExecuteTime": {
"end_time": "2024-06-24T20:20:04.440831Z",
"start_time": "2024-06-24T20:20:04.433276Z"
"end_time": "2024-06-24T20:58:18.603781Z",
"start_time": "2024-06-24T20:58:18.587847Z"
}
},
"source": [
Expand All @@ -229,7 +229,7 @@
"my_algorithm[\"linked_params\"] = [{\"source\": \"z\", \"targets\": [\"A.x\", \"B.y\"]}]"
],
"outputs": [],
"execution_count": 5
"execution_count": 35
},
{
"cell_type": "markdown",
Expand All @@ -255,15 +255,15 @@
"id": "ac4be2b0-f1be-46db-a42d-9f204727db7b",
"metadata": {
"ExecuteTime": {
"end_time": "2024-06-24T20:20:04.507785Z",
"start_time": "2024-06-24T20:20:04.488963Z"
"end_time": "2024-06-24T20:58:18.643939Z",
"start_time": "2024-06-24T20:58:18.637009Z"
}
},
"source": [
"my_algorithm_qref = {\"version\": \"v1\", \"program\": my_algorithm}"
],
"outputs": [],
"execution_count": 6
"execution_count": 36
},
{
"cell_type": "markdown",
Expand All @@ -279,13 +279,9 @@
"<div class=\"alert alert-block alert-info admonition note\">\n",
" <p class=\"admonition-title\"><b>NOTE:</b></p>\n",
" <p>\n",
" To use <a href=\"https://github.com/PsiQ/qref\">qref</a>'s rendering tool in Jupyter Notebook, ensure it's installed by running:\n",
" <code>poetry install -E jupyter</code>\n",
" To use the <a href=\"https://github.com/PsiQ/qref\">qref</a> rendering tool in Jupyter Notebook, ensure the Graphviz software is installed on your OS and that its executables are included in your system variables. For installation instructions, please refer to the <a href=\"https://graphviz.org/download/\">Graphviz download page</a>.\n",
" </p>\n",
" <p>\n",
" Additionally, ensure the Graphviz software is installed on your OS and that its executables are on your system variable. For installation instructions, please refer to the <a href=\"https://graphviz.org/download/\">Graphviz download page</a>.\n",
" </p>\n",
"</div>\n"
"</div>"
]
},
{
Expand All @@ -297,44 +293,38 @@
{
"metadata": {
"ExecuteTime": {
"end_time": "2024-06-24T20:20:07.541905Z",
"start_time": "2024-06-24T20:20:05.151454Z"
"end_time": "2024-06-24T20:58:19.585394Z",
"start_time": "2024-06-24T20:58:18.727647Z"
}
},
"cell_type": "code",
"source": [
"from qref import SchemaV1\n",
"from qref.experimental.rendering import to_graphviz\n",
"\n",
"# Validate the schema and convert to Graphviz object\n",
"program = SchemaV1.model_validate(my_algorithm_qref)\n",
"gv_object = to_graphviz(program)\n",
"# Convert the qref format to Graphviz object\n",
"gv_object = to_graphviz(my_algorithm_qref)\n",
"\n",
"# Render the Graphviz object to a PNG file\n",
"gv_object.render(\"my_algorithm\", format=\"png\")"
"gv_object.render(\"my_algorithm\", format=\"png\")\n",
"\n",
"# Render the Graphviz object in the notebook\n",
"gv_object"
],
"id": "3464d3b49599fe1d",
"outputs": [
{
"data": {
"image/svg+xml": "<?xml version=\"1.0\" encoding=\"UTF-8\" standalone=\"no\"?>\n<!DOCTYPE svg PUBLIC \"-//W3C//DTD SVG 1.1//EN\"\n \"http://www.w3.org/Graphics/SVG/1.1/DTD/svg11.dtd\">\n<!-- Generated by graphviz version 11.0.0 (20240428.1522)\n -->\n<!-- Pages: 1 -->\n<svg width=\"381pt\" height=\"101pt\"\n viewBox=\"0.00 0.00 381.25 101.00\" xmlns=\"http://www.w3.org/2000/svg\" xmlns:xlink=\"http://www.w3.org/1999/xlink\">\n<g id=\"graph0\" class=\"graph\" transform=\"scale(1 1) rotate(0) translate(4 97)\">\n<polygon fill=\"white\" stroke=\"none\" points=\"-4,4 -4,-97 377.25,-97 377.25,4 -4,4\"/>\n<g id=\"clust1\" class=\"cluster\">\n<title>cluster_.my_algorithm</title>\n<path fill=\"none\" stroke=\"black\" d=\"M20,-8C20,-8 353.25,-8 353.25,-8 359.25,-8 365.25,-14 365.25,-20 365.25,-20 365.25,-73 365.25,-73 365.25,-79 359.25,-85 353.25,-85 353.25,-85 20,-85 20,-85 14,-85 8,-79 8,-73 8,-73 8,-20 8,-20 8,-14 14,-8 20,-8\"/>\n<text text-anchor=\"middle\" x=\"186.62\" y=\"-67.7\" font-family=\"Helvetica,sans-Serif\" font-size=\"14.00\">my_algorithm</text>\n</g>\n<!-- .my_algorithm.in -->\n<g id=\"node1\" class=\"node\">\n<title>.my_algorithm.in</title>\n<ellipse fill=\"none\" stroke=\"#ffa44a\" stroke-width=\"2\" cx=\"34\" cy=\"-35\" rx=\"18\" ry=\"18\"/>\n<text text-anchor=\"middle\" x=\"34\" y=\"-31.12\" font-family=\"Times,serif\" font-size=\"10.00\">in</text>\n</g>\n<!-- .my_algorithm.A -->\n<g id=\"node3\" class=\"node\">\n<title>.my_algorithm.A</title>\n<path fill=\"none\" stroke=\"#0288f5\" stroke-width=\"2\" d=\"M100,-17C100,-17 157,-17 157,-17 163,-17 169,-23 169,-29 169,-29 169,-41 169,-41 169,-47 163,-53 157,-53 157,-53 100,-53 100,-53 94,-53 88,-47 88,-41 88,-41 88,-29 88,-29 88,-23 94,-17 100,-17\"/>\n<text text-anchor=\"middle\" x=\"100.5\" y=\"-31.1\" font-family=\"Times,serif\" font-size=\"12.00\">in</text>\n<polyline fill=\"none\" stroke=\"#0288f5\" stroke-width=\"2\" points=\"113,-17.75 113,-53\"/>\n<text text-anchor=\"middle\" x=\"125.5\" y=\"-31.1\" font-family=\"Times,serif\" font-size=\"12.00\">A</text>\n<polyline fill=\"none\" stroke=\"#0288f5\" stroke-width=\"2\" points=\"138,-17.75 138,-53\"/>\n<text text-anchor=\"middle\" x=\"153.5\" y=\"-31.1\" font-family=\"Times,serif\" font-size=\"12.00\">out</text>\n</g>\n<!-- .my_algorithm.in&#45;&gt;.my_algorithm.A -->\n<g id=\"edge3\" class=\"edge\">\n<title>.my_algorithm.in&#45;&gt;.my_algorithm.A:in</title>\n<path fill=\"none\" stroke=\"black\" d=\"M52.19,-35.18C59.4,-35.25 68.11,-35.32 76.77,-35.35\"/>\n<polygon fill=\"black\" stroke=\"black\" points=\"76.48,-38.85 86.49,-35.37 76.49,-31.85 76.48,-38.85\"/>\n</g>\n<!-- .my_algorithm.out -->\n<g id=\"node2\" class=\"node\">\n<title>.my_algorithm.out</title>\n<ellipse fill=\"none\" stroke=\"#ffa44a\" stroke-width=\"2\" cx=\"339.25\" cy=\"-35\" rx=\"18\" ry=\"18\"/>\n<text text-anchor=\"middle\" x=\"339.25\" y=\"-31.12\" font-family=\"Times,serif\" font-size=\"10.00\">out</text>\n</g>\n<!-- .my_algorithm.B -->\n<g id=\"node4\" class=\"node\">\n<title>.my_algorithm.B</title>\n<path fill=\"none\" stroke=\"#0288f5\" stroke-width=\"2\" d=\"M217,-17C217,-17 273.25,-17 273.25,-17 279.25,-17 285.25,-23 285.25,-29 285.25,-29 285.25,-41 285.25,-41 285.25,-47 279.25,-53 273.25,-53 273.25,-53 217,-53 217,-53 211,-53 205,-47 205,-41 205,-41 205,-29 205,-29 205,-23 211,-17 217,-17\"/>\n<text text-anchor=\"middle\" x=\"217.5\" y=\"-31.1\" font-family=\"Times,serif\" font-size=\"12.00\">in</text>\n<polyline fill=\"none\" stroke=\"#0288f5\" stroke-width=\"2\" points=\"230,-17.75 230,-53\"/>\n<text text-anchor=\"middle\" x=\"242.12\" y=\"-31.1\" font-family=\"Times,serif\" font-size=\"12.00\">B</text>\n<polyline fill=\"none\" stroke=\"#0288f5\" stroke-width=\"2\" points=\"254.25,-17.75 254.25,-53\"/>\n<text text-anchor=\"middle\" x=\"269.75\" y=\"-31.1\" font-family=\"Times,serif\" font-size=\"12.00\">out</text>\n</g>\n<!-- .my_algorithm.A&#45;&gt;.my_algorithm.B -->\n<g id=\"edge1\" class=\"edge\">\n<title>.my_algorithm.A:out&#45;&gt;.my_algorithm.B:in</title>\n<path fill=\"none\" stroke=\"black\" d=\"M169,-35.38C180.38,-35.38 185.68,-35.38 193.55,-35.38\"/>\n<polygon fill=\"black\" stroke=\"black\" points=\"193.49,-38.88 203.49,-35.38 193.49,-31.88 193.49,-38.88\"/>\n</g>\n<!-- .my_algorithm.B&#45;&gt;.my_algorithm.out -->\n<g id=\"edge2\" class=\"edge\">\n<title>.my_algorithm.B:out&#45;&gt;.my_algorithm.out</title>\n<path fill=\"none\" stroke=\"black\" d=\"M285.25,-35.38C293.19,-35.38 301.81,-35.33 309.73,-35.28\"/>\n<polygon fill=\"black\" stroke=\"black\" points=\"309.58,-38.78 319.55,-35.2 309.52,-31.78 309.58,-38.78\"/>\n</g>\n</g>\n</svg>\n",
"text/plain": [
"'my_algorithm.png'"
"<graphviz.graphs.Digraph at 0x113b577a0>"
]
},
"execution_count": 7,
"execution_count": 37,
"metadata": {},
"output_type": "execute_result"
}
],
"execution_count": 7
},
{
"cell_type": "markdown",
"id": "4fcbe269fde2e339",
"metadata": {},
"source": [
"![title](../images/my_algorithm.png)"
]
"execution_count": 37
},
{
"cell_type": "markdown",
Expand Down Expand Up @@ -376,8 +366,8 @@
"id": "f3bfa36d-b208-4488-abd6-8b020ef6cffc",
"metadata": {
"ExecuteTime": {
"end_time": "2024-06-24T20:20:08.841567Z",
"start_time": "2024-06-24T20:20:07.548889Z"
"end_time": "2024-06-24T20:58:19.598730Z",
"start_time": "2024-06-24T20:58:19.589741Z"
}
},
"source": [
Expand All @@ -386,7 +376,7 @@
"uncompiled_routine = qref_to_bartiq(my_algorithm_qref)"
],
"outputs": [],
"execution_count": 8
"execution_count": 38
},
{
"cell_type": "markdown",
Expand All @@ -403,8 +393,8 @@
"id": "ef6e5a99-9537-4a9a-aea2-ddf4ec28c5df",
"metadata": {
"ExecuteTime": {
"end_time": "2024-06-24T20:20:08.856565Z",
"start_time": "2024-06-24T20:20:08.843774Z"
"end_time": "2024-06-24T20:58:19.615088Z",
"start_time": "2024-06-24T20:58:19.601383Z"
}
},
"source": [
Expand All @@ -417,12 +407,12 @@
"{'T_gates': <Resource name=\"T_gates\" value=\"2*n_a + x\">}"
]
},
"execution_count": 9,
"execution_count": 39,
"metadata": {},
"output_type": "execute_result"
}
],
"execution_count": 9
"execution_count": 39
},
{
"cell_type": "markdown",
Expand All @@ -439,8 +429,8 @@
"id": "71860050-361e-478e-b6c8-495c9b0bb6fe",
"metadata": {
"ExecuteTime": {
"end_time": "2024-06-24T20:20:08.883465Z",
"start_time": "2024-06-24T20:20:08.867971Z"
"end_time": "2024-06-24T20:58:19.641159Z",
"start_time": "2024-06-24T20:58:19.625793Z"
}
},
"source": [
Expand All @@ -453,12 +443,12 @@
"Port(my_algorithm.#out, size=None, output)"
]
},
"execution_count": 10,
"execution_count": 40,
"metadata": {},
"output_type": "execute_result"
}
],
"execution_count": 10
"execution_count": 40
},
{
"cell_type": "markdown",
Expand All @@ -473,8 +463,8 @@
"id": "da6566d1-f14b-4531-8029-4134143f785f",
"metadata": {
"ExecuteTime": {
"end_time": "2024-06-24T20:20:08.921547Z",
"start_time": "2024-06-24T20:20:08.885642Z"
"end_time": "2024-06-24T20:58:19.665379Z",
"start_time": "2024-06-24T20:58:19.652567Z"
}
},
"source": [
Expand All @@ -487,12 +477,12 @@
"{}"
]
},
"execution_count": 11,
"execution_count": 41,
"metadata": {},
"output_type": "execute_result"
}
],
"execution_count": 11
"execution_count": 41
},
{
"cell_type": "markdown",
Expand All @@ -512,8 +502,8 @@
"id": "0163c4b5-16a6-4510-9210-dc84f6711c61",
"metadata": {
"ExecuteTime": {
"end_time": "2024-06-24T20:20:09.706495Z",
"start_time": "2024-06-24T20:20:08.937015Z"
"end_time": "2024-06-24T20:58:19.716932Z",
"start_time": "2024-06-24T20:58:19.667445Z"
}
},
"source": [
Expand All @@ -522,7 +512,7 @@
"compiled_routine = compile_routine(uncompiled_routine)"
],
"outputs": [],
"execution_count": 12
"execution_count": 42
},
{
"cell_type": "markdown",
Expand All @@ -537,8 +527,8 @@
"id": "e017c894-5203-4958-9f0f-f85904a1ad0b",
"metadata": {
"ExecuteTime": {
"end_time": "2024-06-24T20:20:09.725257Z",
"start_time": "2024-06-24T20:20:09.708736Z"
"end_time": "2024-06-24T20:58:19.733877Z",
"start_time": "2024-06-24T20:58:19.720524Z"
}
},
"source": [
Expand All @@ -557,7 +547,7 @@
]
}
],
"execution_count": 13
"execution_count": 43
},
{
"cell_type": "markdown",
Expand Down Expand Up @@ -588,8 +578,8 @@
"id": "4c232bc3-77bb-4bd8-a587-b6591d539c41",
"metadata": {
"ExecuteTime": {
"end_time": "2024-06-24T20:20:10.233333Z",
"start_time": "2024-06-24T20:20:09.732547Z"
"end_time": "2024-06-24T20:58:19.846940Z",
"start_time": "2024-06-24T20:58:19.739023Z"
}
},
"source": [
Expand Down Expand Up @@ -624,7 +614,7 @@
]
}
],
"execution_count": 14
"execution_count": 44
},
{
"cell_type": "markdown",
Expand Down
Loading

0 comments on commit 806d1fb

Please sign in to comment.