diff --git a/.isort.cfg b/.isort.cfg deleted file mode 100644 index 9483b04..0000000 --- a/.isort.cfg +++ /dev/null @@ -1,2 +0,0 @@ -[tool.isort] -profile = "black" \ No newline at end of file diff --git a/docs/images/alias_sampling.png b/docs/images/alias_sampling.png new file mode 100644 index 0000000..2f763f5 Binary files /dev/null and b/docs/images/alias_sampling.png differ diff --git a/docs/tutorials/01_basic_example.ipynb b/docs/tutorials/01_basic_example.ipynb index b547e50..c93454c 100644 --- a/docs/tutorials/01_basic_example.ipynb +++ b/docs/tutorials/01_basic_example.ipynb @@ -69,8 +69,8 @@ "id": "6e2460c7-8ec3-4157-8b92-3d8ac5ff300f", "metadata": { "ExecuteTime": { - "end_time": "2024-06-21T22:17:13.662311Z", - "start_time": "2024-06-21T22:17:13.657364Z" + "end_time": "2024-06-23T04:15:49.961981Z", + "start_time": "2024-06-23T04:15:49.947655Z" } }, "source": [ @@ -84,7 +84,7 @@ "}" ], "outputs": [], - "execution_count": 83 + "execution_count": 1 }, { "cell_type": "markdown", @@ -107,8 +107,8 @@ "id": "591b4a88-af8c-41ec-bc07-ca0bbe576c70", "metadata": { "ExecuteTime": { - "end_time": "2024-06-21T22:17:13.932504Z", - "start_time": "2024-06-21T22:17:13.920857Z" + "end_time": "2024-06-23T04:15:49.977319Z", + "start_time": "2024-06-23T04:15:49.966992Z" } }, "source": [ @@ -122,7 +122,7 @@ "}" ], "outputs": [], - "execution_count": 84 + "execution_count": 2 }, { "cell_type": "markdown", @@ -137,8 +137,8 @@ "id": "76a0ed1a-0acb-489e-b2fc-40ce956b8f49", "metadata": { "ExecuteTime": { - "end_time": "2024-06-21T22:17:14.025535Z", - "start_time": "2024-06-21T22:17:14.014981Z" + "end_time": "2024-06-23T04:15:49.989451Z", + "start_time": "2024-06-23T04:15:49.980200Z" } }, "source": [ @@ -153,7 +153,7 @@ "}" ], "outputs": [], - "execution_count": 85 + "execution_count": 3 }, { "cell_type": "markdown", @@ -177,8 +177,8 @@ "id": "697c5cdb-abb8-4437-97e8-d3a1e4de1ca2", "metadata": { "ExecuteTime": { - "end_time": "2024-06-21T22:17:14.102519Z", - "start_time": "2024-06-21T22:17:14.096805Z" + "end_time": "2024-06-23T04:15:50.005938Z", + "start_time": "2024-06-23T04:15:49.993607Z" } }, "source": [ @@ -191,7 +191,7 @@ "routine_b[\"resources\"] = [{\"name\": \"T_gates\", \"type\": \"additive\", \"value\": \"n_b*ceil(log_2(n_b)) * y\"}]" ], "outputs": [], - "execution_count": 86 + "execution_count": 4 }, { "cell_type": "markdown", @@ -214,8 +214,8 @@ "id": "3cc1dcef-a151-401b-a818-3be783aa68f9", "metadata": { "ExecuteTime": { - "end_time": "2024-06-21T22:17:14.148051Z", - "start_time": "2024-06-21T22:17:14.141657Z" + "end_time": "2024-06-23T04:15:50.017733Z", + "start_time": "2024-06-23T04:15:50.011154Z" } }, "source": [ @@ -229,7 +229,7 @@ "my_algorithm[\"linked_params\"] = [{\"source\": \"z\", \"targets\": [\"A.x\", \"B.y\"]}]" ], "outputs": [], - "execution_count": 87 + "execution_count": 5 }, { "cell_type": "markdown", @@ -255,70 +255,52 @@ "id": "ac4be2b0-f1be-46db-a42d-9f204727db7b", "metadata": { "ExecuteTime": { - "end_time": "2024-06-21T22:17:14.182466Z", - "start_time": "2024-06-21T22:17:14.176566Z" + "end_time": "2024-06-23T04:15:50.031736Z", + "start_time": "2024-06-23T04:15:50.021765Z" } }, "source": [ "my_algorithm_qref = {\"version\": \"v1\", \"program\": my_algorithm}" ], "outputs": [], - "execution_count": 88 + "execution_count": 6 }, { - "metadata": {}, "cell_type": "markdown", + "id": "6ef92aec51534839", + "metadata": {}, "source": [ - "So, is there an intuitive way to understand what my algorithm looks like and how the resources flow in the routine? You can use the visualization tool from [`QREF`](https://github.com/PsiQ/qref) to plot the hierarchical Directed Acyclic Graph (DAG) of the algorithm you wrote.\n", - "\n", - "To install `qref` in Jupyter Notebook, use the following command:" - ], - "id": "6ef92aec51534839" + "So, is there an intuitive way to understand what my algorithm looks like and how the resources flow in the routine? You can use the visualization tool from [`QREF`](https://github.com/PsiQ/qref) to plot the hierarchical Directed Acyclic Graph (DAG) of the algorithm you wrote." + ] }, { - "metadata": { - "ExecuteTime": { - "end_time": "2024-06-21T22:17:20.230138Z", - "start_time": "2024-06-21T22:17:14.226612Z" - } - }, - "cell_type": "code", - "source": "!pip install qref", - "id": "ff1055c0506ae741", - "outputs": [ - { - "name": "stdout", - "output_type": "stream", - "text": [ - "Looking in indexes: https://artifactory.psiquantum.com/artifactory/api/pypi/psipy/simple\r\n", - "Requirement already satisfied: qref in /Users/sliu/PycharmProjects/bartiq_33/venv/lib/python3.12/site-packages (0.3.0)\r\n", - "Requirement already satisfied: graphviz<0.21.0,>=0.20.3 in /Users/sliu/PycharmProjects/bartiq_33/venv/lib/python3.12/site-packages (from qref) (0.20.3)\r\n", - "Requirement already satisfied: pydantic<3.0,>=2.0 in /Users/sliu/PycharmProjects/bartiq_33/venv/lib/python3.12/site-packages (from qref) (2.7.4)\r\n", - "Requirement already satisfied: annotated-types>=0.4.0 in /Users/sliu/PycharmProjects/bartiq_33/venv/lib/python3.12/site-packages (from pydantic<3.0,>=2.0->qref) (0.7.0)\r\n", - "Requirement already satisfied: pydantic-core==2.18.4 in /Users/sliu/PycharmProjects/bartiq_33/venv/lib/python3.12/site-packages (from pydantic<3.0,>=2.0->qref) (2.18.4)\r\n", - "Requirement already satisfied: typing-extensions>=4.6.1 in /Users/sliu/PycharmProjects/bartiq_33/venv/lib/python3.12/site-packages (from pydantic<3.0,>=2.0->qref) (4.12.2)\r\n", - "\r\n", - "\u001b[1m[\u001b[0m\u001b[34;49mnotice\u001b[0m\u001b[1;39;49m]\u001b[0m\u001b[39;49m A new release of pip is available: \u001b[0m\u001b[31;49m24.0\u001b[0m\u001b[39;49m -> \u001b[0m\u001b[32;49m24.1\u001b[0m\r\n", - "\u001b[1m[\u001b[0m\u001b[34;49mnotice\u001b[0m\u001b[1;39;49m]\u001b[0m\u001b[39;49m To update, run: \u001b[0m\u001b[32;49mpip install --upgrade pip\u001b[0m\r\n" - ] - } - ], - "execution_count": 89 + "cell_type": "markdown", + "id": "c7d1b18a9c90420c", + "metadata": {}, + "source": [ + "

NOTE:

\n", + "To use qref in Jupyter Notebook, ensure it's installed by executing the following command:
\n", + " !pip install qref \n", + "
" + ] }, { - "metadata": {}, "cell_type": "markdown", - "source": "Then, run:", - "id": "a4f5318f14af6421" + "id": "a4f5318f14af6421", + "metadata": {}, + "source": [ + "Then, run:" + ] }, { + "cell_type": "code", + "id": "855fde880ca026b0", "metadata": { "ExecuteTime": { - "end_time": "2024-06-21T22:17:20.668061Z", - "start_time": "2024-06-21T22:17:20.292911Z" + "end_time": "2024-06-23T04:15:54.431079Z", + "start_time": "2024-06-23T04:15:53.788288Z" } }, - "cell_type": "code", "source": [ "from qref import SchemaV1\n", "from qref.experimental.rendering import to_graphviz\n", @@ -330,7 +312,6 @@ "# Render the Graphviz object to a PNG file\n", "gv_object.render(\"my_algorithm\", format=\"png\")" ], - "id": "855fde880ca026b0", "outputs": [ { "data": { @@ -338,36 +319,44 @@ "'my_algorithm.png'" ] }, - "execution_count": 90, + "execution_count": 8, "metadata": {}, "output_type": "execute_result" } ], - "execution_count": 90 + "execution_count": 8 }, { - "metadata": {}, "cell_type": "markdown", - "source": "![title](../images/my_algorithm.png)", - "id": "4fcbe269fde2e339" + "id": "4fcbe269fde2e339", + "metadata": {}, + "source": [ + "![title](../images/my_algorithm.png)" + ] }, { - "metadata": {}, "cell_type": "markdown", - "source": "From this graph, you can find both subroutines from the original algorithm, along with their `name`, and`ports`. It provides a general idea of the connectivity between subroutines in the algorithm and shows how information is stored.", - "id": "564ecc3e766e7453" + "id": "564ecc3e766e7453", + "metadata": {}, + "source": [ + "From this graph, you can find both subroutines from the original algorithm, along with their `name`, and`ports`. It provides a general idea of the connectivity between subroutines in the algorithm and shows how information is stored." + ] }, { - "metadata": {}, "cell_type": "markdown", - "source": "Now we can translate our algorithm into a proper `bartiq` routine and see what's the total cost of `my_algorithm`.", - "id": "5fe2e5a6-0487-44d1-8071-3f692ee845ba" + "id": "5fe2e5a6-0487-44d1-8071-3f692ee845ba", + "metadata": {}, + "source": [ + "Now we can translate our algorithm into a proper `bartiq` routine and see what's the total cost of `my_algorithm`." + ] }, { - "metadata": {}, "cell_type": "markdown", - "source": "## Compilation", - "id": "ea57757c-2757-4f81-93ec-b070a3b945fc" + "id": "ea57757c-2757-4f81-93ec-b070a3b945fc", + "metadata": {}, + "source": [ + "## Compilation" + ] }, { "cell_type": "markdown", @@ -385,8 +374,8 @@ "id": "f3bfa36d-b208-4488-abd6-8b020ef6cffc", "metadata": { "ExecuteTime": { - "end_time": "2024-06-21T22:17:20.680766Z", - "start_time": "2024-06-21T22:17:20.671306Z" + "end_time": "2024-06-23T04:15:55.761739Z", + "start_time": "2024-06-23T04:15:54.434241Z" } }, "source": [ @@ -395,7 +384,7 @@ "uncompiled_routine = qref_to_bartiq(my_algorithm_qref)" ], "outputs": [], - "execution_count": 91 + "execution_count": 9 }, { "cell_type": "markdown", @@ -412,8 +401,8 @@ "id": "ef6e5a99-9537-4a9a-aea2-ddf4ec28c5df", "metadata": { "ExecuteTime": { - "end_time": "2024-06-21T22:17:20.701245Z", - "start_time": "2024-06-21T22:17:20.687226Z" + "end_time": "2024-06-23T04:15:55.776584Z", + "start_time": "2024-06-23T04:15:55.766822Z" } }, "source": [ @@ -426,12 +415,12 @@ "{'T_gates': }" ] }, - "execution_count": 92, + "execution_count": 10, "metadata": {}, "output_type": "execute_result" } ], - "execution_count": 92 + "execution_count": 10 }, { "cell_type": "markdown", @@ -448,8 +437,8 @@ "id": "71860050-361e-478e-b6c8-495c9b0bb6fe", "metadata": { "ExecuteTime": { - "end_time": "2024-06-21T22:17:20.714079Z", - "start_time": "2024-06-21T22:17:20.704135Z" + "end_time": "2024-06-23T04:15:55.792519Z", + "start_time": "2024-06-23T04:15:55.779249Z" } }, "source": [ @@ -462,12 +451,12 @@ "Port(my_algorithm.#out, size=None, output)" ] }, - "execution_count": 93, + "execution_count": 11, "metadata": {}, "output_type": "execute_result" } ], - "execution_count": 93 + "execution_count": 11 }, { "cell_type": "markdown", @@ -482,8 +471,8 @@ "id": "da6566d1-f14b-4531-8029-4134143f785f", "metadata": { "ExecuteTime": { - "end_time": "2024-06-21T22:17:20.724461Z", - "start_time": "2024-06-21T22:17:20.716750Z" + "end_time": "2024-06-23T04:15:55.808806Z", + "start_time": "2024-06-23T04:15:55.794552Z" } }, "source": [ @@ -496,12 +485,12 @@ "{}" ] }, - "execution_count": 94, + "execution_count": 12, "metadata": {}, "output_type": "execute_result" } ], - "execution_count": 94 + "execution_count": 12 }, { "cell_type": "markdown", @@ -521,8 +510,8 @@ "id": "0163c4b5-16a6-4510-9210-dc84f6711c61", "metadata": { "ExecuteTime": { - "end_time": "2024-06-21T22:17:20.767983Z", - "start_time": "2024-06-21T22:17:20.726964Z" + "end_time": "2024-06-23T04:15:56.464540Z", + "start_time": "2024-06-23T04:15:55.811261Z" } }, "source": [ @@ -531,7 +520,7 @@ "compiled_routine = compile_routine(uncompiled_routine)" ], "outputs": [], - "execution_count": 95 + "execution_count": 13 }, { "cell_type": "markdown", @@ -546,8 +535,8 @@ "id": "e017c894-5203-4958-9f0f-f85904a1ad0b", "metadata": { "ExecuteTime": { - "end_time": "2024-06-21T22:17:20.783829Z", - "start_time": "2024-06-21T22:17:20.771059Z" + "end_time": "2024-06-23T04:15:56.472910Z", + "start_time": "2024-06-23T04:15:56.467032Z" } }, "source": [ @@ -566,7 +555,7 @@ ] } ], - "execution_count": 96 + "execution_count": 14 }, { "cell_type": "markdown", @@ -597,8 +586,8 @@ "id": "4c232bc3-77bb-4bd8-a587-b6591d539c41", "metadata": { "ExecuteTime": { - "end_time": "2024-06-21T22:17:20.895383Z", - "start_time": "2024-06-21T22:17:20.788901Z" + "end_time": "2024-06-23T04:15:56.818989Z", + "start_time": "2024-06-23T04:15:56.476787Z" } }, "source": [ @@ -633,7 +622,7 @@ ] } ], - "execution_count": 97 + "execution_count": 15 }, { "cell_type": "markdown", @@ -668,7 +657,7 @@ "name": "python", "nbconvert_exporter": "python", "pygments_lexer": "ipython3", - "version": "3.9.19" + "version": "3.12.3" } }, "nbformat": 4, diff --git a/docs/tutorials/02_alias_sampling_basic.ipynb b/docs/tutorials/02_alias_sampling_basic.ipynb index 93178b6..5e424f6 100644 --- a/docs/tutorials/02_alias_sampling_basic.ipynb +++ b/docs/tutorials/02_alias_sampling_basic.ipynb @@ -88,10 +88,13 @@ }, { "cell_type": "code", - "execution_count": 1, "id": "fa6d5b43-0eac-4f6f-84de-1df68b8d0d8e", - "metadata": {}, - "outputs": [], + "metadata": { + "ExecuteTime": { + "end_time": "2024-06-23T04:16:44.877026Z", + "start_time": "2024-06-23T04:16:44.864451Z" + } + }, "source": [ "usp_dict = {\n", " \"name\": \"usp\",\n", @@ -107,7 +110,9 @@ " \"input_params\": [\"L\"],\n", " \"local_variables\": [\"R=ceiling(log_2(L))\"],\n", "}" - ] + ], + "outputs": [], + "execution_count": 1 }, { "cell_type": "markdown", @@ -122,10 +127,13 @@ }, { "cell_type": "code", - "execution_count": 2, "id": "9cbe85ec-c435-4e60-8561-9b151de06b41", - "metadata": {}, - "outputs": [], + "metadata": { + "ExecuteTime": { + "end_time": "2024-06-23T04:16:44.888210Z", + "start_time": "2024-06-23T04:16:44.880801Z" + } + }, "source": [ "had_dict = {\n", " \"name\": \"had\",\n", @@ -135,14 +143,19 @@ " {\"name\": \"out\", \"direction\": \"output\", \"size\": \"N\"},\n", " ],\n", "}" - ] + ], + "outputs": [], + "execution_count": 2 }, { "cell_type": "code", - "execution_count": 3, "id": "ef43c139-304f-473f-b718-16883760658e", - "metadata": {}, - "outputs": [], + "metadata": { + "ExecuteTime": { + "end_time": "2024-06-23T04:16:44.906810Z", + "start_time": "2024-06-23T04:16:44.893127Z" + } + }, "source": [ "qrom_dict = {\n", " \"name\": \"qrom\",\n", @@ -159,14 +172,19 @@ " \"input_params\": [\"L\", \"mu\"],\n", " \"local_variables\": [\"R=ceiling(log_2(L))\"],\n", "}" - ] + ], + "outputs": [], + "execution_count": 3 }, { "cell_type": "code", - "execution_count": 4, "id": "698c0b16-2e5f-4c9f-bc81-89f0bbed9611", - "metadata": {}, - "outputs": [], + "metadata": { + "ExecuteTime": { + "end_time": "2024-06-23T04:16:44.916498Z", + "start_time": "2024-06-23T04:16:44.910082Z" + } + }, "source": [ "compare_dict = {\n", " \"name\": \"compare\",\n", @@ -182,14 +200,19 @@ " \"resources\": [{\"name\": \"T_gates\", \"type\": \"additive\", \"value\": \"4*mu-4\"}],\n", " \"input_params\": [\"mu\"],\n", "}" - ] + ], + "outputs": [], + "execution_count": 4 }, { "cell_type": "code", - "execution_count": 5, "id": "da5c61bf-7fb2-47d1-a0f5-d15b32147673", - "metadata": {}, - "outputs": [], + "metadata": { + "ExecuteTime": { + "end_time": "2024-06-23T04:16:44.932082Z", + "start_time": "2024-06-23T04:16:44.923322Z" + } + }, "source": [ "swap_dict = {\n", " \"name\": \"swap\",\n", @@ -210,7 +233,9 @@ " ],\n", " \"input_params\": [\"X\"],\n", "}" - ] + ], + "outputs": [], + "execution_count": 5 }, { "cell_type": "markdown", @@ -232,10 +257,13 @@ }, { "cell_type": "code", - "execution_count": 6, "id": "b066f011-96e1-4544-81bf-cdc7083b3f73", - "metadata": {}, - "outputs": [], + "metadata": { + "ExecuteTime": { + "end_time": "2024-06-23T04:16:44.948372Z", + "start_time": "2024-06-23T04:16:44.936966Z" + } + }, "source": [ "alias_sampling_dict = {\n", " \"name\": \"alias_sampling\",\n", @@ -278,41 +306,127 @@ " {\"source\": \"mu\", \"targets\": [\"had.mu\", \"qrom.mu\", \"compare.mu\"]},\n", " ],\n", "}" - ] + ], + "outputs": [], + "execution_count": 6 }, { "cell_type": "code", - "execution_count": 7, "id": "e3d17a61-4b9e-48e9-901a-231da501f41b", - "metadata": {}, - "outputs": [], + "metadata": { + "ExecuteTime": { + "end_time": "2024-06-23T04:16:44.957545Z", + "start_time": "2024-06-23T04:16:44.953401Z" + } + }, "source": [ "alias_sampling_qref = {\"version\": \"v1\", \"program\": alias_sampling_dict}" - ] + ], + "outputs": [], + "execution_count": 7 + }, + { + "metadata": {}, + "cell_type": "markdown", + "source": "Additionally, you can examine how the circuit is represented in `qref` format by visualizing it. ", + "id": "a97dfdd428b669cb" }, { + "metadata": {}, + "cell_type": "markdown", + "source": [ + "

NOTE:

\n", + "To use qref in Jupyter Notebook, ensure it's installed by executing the following command:
\n", + " !pip install qref \n", + "
" + ], + "id": "dfdf59f8a2ef16c5" + }, + { + "metadata": {}, + "cell_type": "markdown", + "source": "Once installed, proceed to visualize the representation of the circuit.", + "id": "ff432b4dac9921c1" + }, + { + "metadata": { + "ExecuteTime": { + "end_time": "2024-06-23T04:16:45.804837Z", + "start_time": "2024-06-23T04:16:44.993240Z" + } + }, "cell_type": "code", - "execution_count": 8, - "id": "5d0d2d69-4b77-4d62-9dd3-2405f4db21ed", + "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(alias_sampling_qref)\n", + "gv_object = to_graphviz(program)\n", + "\n", + "# Render the Graphviz object to a PNG file\n", + "gv_object.render(\"alias_sampling\", format=\"png\")" + ], + "id": "33cd4f7dae6a5edd", + "outputs": [ + { + "data": { + "text/plain": [ + "'alias_sampling.png'" + ] + }, + "execution_count": 8, + "metadata": {}, + "output_type": "execute_result" + } + ], + "execution_count": 8 + }, + { "metadata": {}, - "outputs": [], + "cell_type": "markdown", + "source": "![Alias SamplŒΩ`~ZAng](../images/alias_sampling.png)\n", + "id": "f83601e78b3ffbf0" + }, + { + "metadata": {}, + "cell_type": "markdown", + "source": "As we expected, the diagram displays five subroutines which are `usp`, `qrom`, `compare`, `had`, `swap`, and their hierarchical connections. Everything appears to be in order! Let's proceed with the compilation.\n", + "id": "2ee860fa5c451aad" + }, + { + "cell_type": "code", + "id": "5d0d2d69-4b77-4d62-9dd3-2405f4db21ed", + "metadata": { + "ExecuteTime": { + "end_time": "2024-06-23T04:16:46.936963Z", + "start_time": "2024-06-23T04:16:45.809680Z" + } + }, "source": [ "from bartiq.integrations import qref_to_bartiq\n", "\n", "uncompiled_routine = qref_to_bartiq(alias_sampling_qref)" - ] + ], + "outputs": [], + "execution_count": 9 }, { "cell_type": "code", - "execution_count": 9, "id": "d20ef4d2-9420-4090-a402-ee5f27034524", - "metadata": {}, - "outputs": [], + "metadata": { + "ExecuteTime": { + "end_time": "2024-06-23T04:16:47.486293Z", + "start_time": "2024-06-23T04:16:46.938991Z" + } + }, "source": [ "from bartiq import compile_routine\n", "\n", "compiled_routine = compile_routine(uncompiled_routine)" - ] + ], + "outputs": [], + "execution_count": 10 }, { "cell_type": "markdown", @@ -324,9 +438,17 @@ }, { "cell_type": "code", - "execution_count": 10, "id": "dad8df1e-9570-46c5-a422-4f29bba4d52c", - "metadata": {}, + "metadata": { + "ExecuteTime": { + "end_time": "2024-06-23T04:16:47.497233Z", + "start_time": "2024-06-23T04:16:47.491544Z" + } + }, + "source": [ + "for resource in compiled_routine.resources.values():\n", + " print(f\"{resource.name}: {resource.value}\")" + ], "outputs": [ { "name": "stdout", @@ -337,10 +459,7 @@ ] } ], - "source": [ - "for resource in compiled_routine.resources.values():\n", - " print(f\"{resource.name}: {resource.value}\")" - ] + "execution_count": 11 }, { "cell_type": "markdown", @@ -361,9 +480,21 @@ }, { "cell_type": "code", - "execution_count": 11, "id": "becb2091-9faf-4364-ac22-f10240072937", - "metadata": {}, + "metadata": { + "ExecuteTime": { + "end_time": "2024-06-23T04:16:47.662436Z", + "start_time": "2024-06-23T04:16:47.502688Z" + } + }, + "source": [ + "from bartiq import evaluate\n", + "\n", + "assignments = {\"L=120\", \"mu=8\"}\n", + "evaluated_routine = evaluate(compiled_routine, assignments)\n", + "for resource in evaluated_routine.resources.values():\n", + " print(f\"{resource.name}: {resource.value}\")" + ], "outputs": [ { "name": "stdout", @@ -374,14 +505,7 @@ ] } ], - "source": [ - "from bartiq import evaluate\n", - "\n", - "assignments = {\"L=120\", \"mu=8\"}\n", - "evaluated_routine = evaluate(compiled_routine, assignments)\n", - "for resource in evaluated_routine.resources.values():\n", - " print(f\"{resource.name}: {resource.value}\")" - ] + "execution_count": 12 }, { "cell_type": "markdown", @@ -398,9 +522,18 @@ }, { "cell_type": "code", - "execution_count": 12, "id": "dbf7d3a4-5a58-4dcb-990e-eccd0d7cda9a", - "metadata": {}, + "metadata": { + "ExecuteTime": { + "end_time": "2024-06-23T04:16:47.803041Z", + "start_time": "2024-06-23T04:16:47.667453Z" + } + }, + "source": [ + "compiled_routine = compile_routine(uncompiled_routine, global_functions=[\"O\"])\n", + "for resource in compiled_routine.resources.values():\n", + " print(f\"{resource.name}: {resource.value}\")" + ], "outputs": [ { "name": "stdout", @@ -411,11 +544,7 @@ ] } ], - "source": [ - "compiled_routine = compile_routine(uncompiled_routine, global_functions=[\"O\"])\n", - "for resource in compiled_routine.resources.values():\n", - " print(f\"{resource.name}: {resource.value}\")" - ] + "execution_count": 13 }, { "cell_type": "markdown", @@ -427,19 +556,13 @@ }, { "cell_type": "code", - "execution_count": 13, "id": "2909fb37-6a15-44fc-a80f-46e562220fcb", - "metadata": {}, - "outputs": [ - { - "name": "stdout", - "output_type": "stream", - "text": [ - "T_gates: 831\n", - "rotations: 2\n" - ] + "metadata": { + "ExecuteTime": { + "end_time": "2024-06-23T04:16:47.998046Z", + "start_time": "2024-06-23T04:16:47.806064Z" } - ], + }, "source": [ "import math\n", "\n", @@ -452,7 +575,18 @@ "evaluated_routine = evaluate(compiled_routine, assignments, functions_map=functions_map)\n", "for resource in evaluated_routine.resources.values():\n", " print(f\"{resource.name}: {resource.value}\")" - ] + ], + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "T_gates: 831\n", + "rotations: 2\n" + ] + } + ], + "execution_count": 14 }, { "cell_type": "markdown", @@ -481,31 +615,36 @@ }, { "cell_type": "code", - "execution_count": 14, "id": "1a346534-4f97-4855-8262-2c5df824eb27", - "metadata": {}, + "metadata": { + "ExecuteTime": { + "end_time": "2024-06-23T04:16:48.057686Z", + "start_time": "2024-06-23T04:16:48.001398Z" + } + }, + "source": [ + "from bartiq.integrations import explore_routine\n", + "\n", + "explore_routine(evaluated_routine)" + ], "outputs": [ { "data": { + "text/plain": [ + "HBox(children=(_RoutineTree(multiple_selection=False, nodes=(Node(name='alias_sampling', nodes=(Node(name='com…" + ], "application/vnd.jupyter.widget-view+json": { - "model_id": "811e911faa5847d59817f59b97115522", "version_major": 2, - "version_minor": 0 - }, - "text/plain": [ - "HBox(children=(_RoutineTree(multiple_selection=False, nodes=(Node(name='', nodes=(Node(name='usp'), Node(name=…" - ] + "version_minor": 0, + "model_id": "7adf8b4876344a98836d71b6e95728d6" + } }, - "execution_count": 14, + "execution_count": 15, "metadata": {}, "output_type": "execute_result" } ], - "source": [ - "from bartiq.integrations import explore_routine\n", - "\n", - "explore_routine(evaluated_routine)" - ] + "execution_count": 15 }, { "cell_type": "markdown", @@ -517,52 +656,33 @@ }, { "cell_type": "code", - "execution_count": 15, "id": "a925abe0-9026-4079-9c5a-8ef5e087a551", - "metadata": {}, + "metadata": { + "ExecuteTime": { + "end_time": "2024-06-23T04:16:48.083319Z", + "start_time": "2024-06-23T04:16:48.060694Z" + } + }, + "source": [ + "from bartiq.integrations import routine_to_latex\n", + "from IPython.display import Math\n", + "\n", + "Math(routine_to_latex(evaluated_routine))" + ], "outputs": [ { "data": { - "text/latex": [ - "$\\displaystyle \\begin{align}\n", - "&\\text{Routine \\textrm{()}}\\newline\n", - "&\\underline{\\text{Input ports:}}\\\\\n", - "&\\text{In\\_0} = R\\\\\n", - "&\\text{In\\_1} = 8\\\\\n", - "&\\text{In\\_2} = R\\\\\n", - "&\\text{In\\_3} = 8\\\\\n", - "&\\text{In\\_4} = 1\\newline\n", - "&\\underline{\\text{Output ports:}}\\\\\n", - "&\\text{out\\_0} = R\\\\\n", - "&\\text{temp\\_0} = 8\\\\\n", - "&\\text{temp\\_1} = R\\\\\n", - "&\\text{temp\\_2} = 8\\\\\n", - "&\\text{temp\\_3} = 1\\newline\n", - "&\\underline{\\text{Resources:}}\\\\\n", - "&T_{\\text{gates}} = 831\\\\\n", - "&rotations = 2\\\\\n", - "&\\text{usp}.\\!T_{\\text{gates}} = 320\\\\\n", - "&\\text{usp}.\\!rotations = 2\\\\\n", - "&\\text{qrom}.\\!T_{\\text{gates}} = 476\\\\\n", - "&\\text{compare}.\\!T_{\\text{gates}} = 28\\\\\n", - "&\\text{swap}.\\!T_{\\text{gates}} = 7\n", - "\\end{align}$" - ], "text/plain": [ "" - ] + ], + "text/latex": "$\\displaystyle \\begin{align}\n&\\text{Routine \\textrm{(alias\\_sampling)}}\\newline\n&\\underline{\\text{Input ports:}}\\\\\n&\\text{In\\_0} = R\\\\\n&\\text{In\\_1} = 8\\\\\n&\\text{In\\_2} = R\\\\\n&\\text{In\\_3} = 8\\\\\n&\\text{In\\_4} = 1\\newline\n&\\underline{\\text{Output ports:}}\\\\\n&\\text{out\\_0} = R\\\\\n&\\text{temp\\_0} = 8\\\\\n&\\text{temp\\_1} = R\\\\\n&\\text{temp\\_2} = 8\\\\\n&\\text{temp\\_3} = 1\\newline\n&\\underline{\\text{Resources:}}\\\\\n&T_{\\text{gates}} = 831\\\\\n&rotations = 2\\\\\n&\\text{usp}.\\!T_{\\text{gates}} = 320\\\\\n&\\text{usp}.\\!rotations = 2\\\\\n&\\text{qrom}.\\!T_{\\text{gates}} = 476\\\\\n&\\text{compare}.\\!T_{\\text{gates}} = 28\\\\\n&\\text{swap}.\\!T_{\\text{gates}} = 7\n\\end{align}$" }, - "execution_count": 15, + "execution_count": 16, "metadata": {}, "output_type": "execute_result" } ], - "source": [ - "from bartiq.integrations import routine_to_latex\n", - "from IPython.display import Math\n", - "\n", - "Math(routine_to_latex(evaluated_routine))" - ] + "execution_count": 16 }, { "cell_type": "markdown", @@ -576,14 +696,6 @@ "- How to create a routine with multiple resources, `local_variables` and custom functions\n", "- How to use `explore_routine` and latex integration to get most out of `bartiq`" ] - }, - { - "cell_type": "code", - "execution_count": null, - "id": "5897ad78-b510-4cb8-ac37-7157e054e937", - "metadata": {}, - "outputs": [], - "source": [] } ], "metadata": { diff --git a/docs/tutorials/my_algorithm b/docs/tutorials/my_algorithm deleted file mode 100644 index b7e8670..0000000 --- a/docs/tutorials/my_algorithm +++ /dev/null @@ -1,19 +0,0 @@ -digraph { - graph [fontname=Helvetica rankdir=LR] - subgraph "cluster_.my_algorithm" { - graph [label=my_algorithm style=rounded] - subgraph ".my_algorithm:inputs" { - graph [rank=same] - ".my_algorithm.in" [label=in color="#ffa44a" fontsize=10 shape=circle style=bold] - } - subgraph ".my_algorithm:outputs" { - graph [rank=same] - ".my_algorithm.out" [label=out color="#ffa44a" fontsize=10 shape=circle style=bold] - } - ".my_algorithm.A" [label="{ { in} | A | { out} }" color="#0288f5" fontsize=12 shape=Mrecord style=bold] - ".my_algorithm.B" [label="{ { in} | B | { out} }" color="#0288f5" fontsize=12 shape=Mrecord style=bold] - ".my_algorithm.A":out -> ".my_algorithm.B":in - ".my_algorithm.B":out -> ".my_algorithm.out" - ".my_algorithm.in" -> ".my_algorithm.A":in - } -}