From efe86f150f204a5f952f683e03b19690aff26113 Mon Sep 17 00:00:00 2001 From: Vincent van Wingerden <25651976+vivanwin@users.noreply.github.com> Date: Thu, 3 Apr 2025 09:17:38 +0200 Subject: [PATCH] Clean up workbooks --- .../getting_started/part1_arithmetic.ipynb | 42 ++------- .../part2_state_preparation.ipynb | 26 ++---- .../getting_started/part3_deutsch_jozsa.ipynb | 67 +++++---------- .../getting_started/part4_ghz_state.ipynb | 35 +++----- .../getting_started/part5_grover.ipynb | 85 ++++++------------- 5 files changed, 76 insertions(+), 179 deletions(-) diff --git a/tutorials/classiq_101/getting_started/part1_arithmetic.ipynb b/tutorials/classiq_101/getting_started/part1_arithmetic.ipynb index 2afca0a2f..9d7db49b5 100644 --- a/tutorials/classiq_101/getting_started/part1_arithmetic.ipynb +++ b/tutorials/classiq_101/getting_started/part1_arithmetic.ipynb @@ -11,7 +11,7 @@ }, { "cell_type": "code", - "execution_count": 1, + "execution_count": null, "metadata": {}, "outputs": [], "source": [ @@ -20,7 +20,7 @@ }, { "cell_type": "code", - "execution_count": 2, + "execution_count": null, "metadata": {}, "outputs": [], "source": [ @@ -32,17 +32,9 @@ }, { "cell_type": "code", - "execution_count": 3, + "execution_count": null, "metadata": {}, - "outputs": [ - { - "name": "stdout", - "output_type": "stream", - "text": [ - "Opening: https://platform.classiq.io/circuit/2uFyUpZwA6NTy9gNLHxA9jrYY0q?version=0.70.0\n" - ] - } - ], + "outputs": [], "source": [ "# QFunc declares a quantum function\n", "@qfunc\n", @@ -74,7 +66,7 @@ "\n", "Now that we have created a model, it is time to execute it. With the `show()` command the IDE is opened where we can execute the circuit. A page like this should have opened:\n", "\n", - "\n", + "\n", "\n", "Click on the execute button on the right top. Next, you will get to the execution page where you can run the circuit, validate that you are running on the Classiq Aer simulation as highlighted in the image below, and press the Run button as seen below.\n", "\n", @@ -109,17 +101,9 @@ }, { "cell_type": "code", - "execution_count": 4, + "execution_count": null, "metadata": {}, - "outputs": [ - { - "name": "stdout", - "output_type": "stream", - "text": [ - "Opening: https://platform.classiq.io/circuit/2uFyV8vYzZLOSpq12sKe84ruuZX?version=0.70.0\n" - ] - } - ], + "outputs": [], "source": [ "@qfunc\n", "def main(\n", @@ -146,17 +130,9 @@ }, { "cell_type": "code", - "execution_count": 5, + "execution_count": null, "metadata": {}, - "outputs": [ - { - "name": "stdout", - "output_type": "stream", - "text": [ - "Opening: https://platform.classiq.io/circuit/2uFyXujs0DyM1VFkOaRrd6JvZUe?version=0.70.0\n" - ] - } - ], + "outputs": [], "source": [ "@qfunc\n", "def main(a: Output[QNum], b: Output[QNum], c: Output[QNum], res: Output[QNum]):\n", diff --git a/tutorials/classiq_101/getting_started/part2_state_preparation.ipynb b/tutorials/classiq_101/getting_started/part2_state_preparation.ipynb index a2c5de1d4..fcd8ee06e 100644 --- a/tutorials/classiq_101/getting_started/part2_state_preparation.ipynb +++ b/tutorials/classiq_101/getting_started/part2_state_preparation.ipynb @@ -11,7 +11,7 @@ }, { "cell_type": "code", - "execution_count": 1, + "execution_count": null, "metadata": {}, "outputs": [], "source": [ @@ -48,17 +48,9 @@ }, { "cell_type": "code", - "execution_count": 2, + "execution_count": null, "metadata": {}, - "outputs": [ - { - "name": "stdout", - "output_type": "stream", - "text": [ - "Opening: https://platform.classiq.io/circuit/2uFz2rmhHsIOvTysk7hpYPooM7a?version=0.70.0\n" - ] - } - ], + "outputs": [], "source": [ "bound = 0.3\n", "\n", @@ -93,17 +85,9 @@ }, { "cell_type": "code", - "execution_count": 3, + "execution_count": null, "metadata": {}, - "outputs": [ - { - "name": "stdout", - "output_type": "stream", - "text": [ - "Opening: https://platform.classiq.io/circuit/2uFz3Vg2tRvstyBsb69dN0PcJ17?version=0.70.0\n" - ] - } - ], + "outputs": [], "source": [ "bound = 0.3\n", "\n", diff --git a/tutorials/classiq_101/getting_started/part3_deutsch_jozsa.ipynb b/tutorials/classiq_101/getting_started/part3_deutsch_jozsa.ipynb index 12932e7ee..5f13459b3 100644 --- a/tutorials/classiq_101/getting_started/part3_deutsch_jozsa.ipynb +++ b/tutorials/classiq_101/getting_started/part3_deutsch_jozsa.ipynb @@ -32,16 +32,15 @@ "The circuit that we want to create is pictured below.\n", "To create this circuit we need to implement 4 steps:\n", "\n", - "1. Declare and initialize a single auxiliary qubit called `aux`\n", - "2. Apply the `hadamard_transform()` function on the qubits passed to the `main` function.\n", - "3. create an oracle with the `phase_oracle()` function, this is the function signature: (if you are stuck more details are below) \n", + "1. Apply the `hadamard_transform()` function on the qubits passed to the `main` function.\n", + "2. create an oracle with the `phase_oracle()` function, this is the function signature: (if you are stuck more details are below) \n", "\n", - " def simple_oracle(\n", + " def phase_oracle(\n", " predicate: QCallable[QArray[QBit], QBit],\n", " target: QArray[QBit],\n", " )\n", " \n", - "4. Uncompute step 2 by applying the `hadamard_transform()` function to the \n", + "3. Uncompute step 2 by applying the `hadamard_transform()` function to the \n", "\n", "Synthesize the circuit and execute in the IDE\n", "\n", @@ -51,28 +50,20 @@ "\n", "The function takes two named inputs:\n", "\n", - "1. predicate -> A `lambda` function with two inputs the target qubits and the auxiliary qubit, the expression will call the `my_black_box_prediate()`\n", + "1. predicate -> A `lambda` function with two inputs the target qubits and the auxiliary qubit, the expression will call the `my_black_box_prediate()`. You do not need to pass the aux qubit to the `lambda` this will be created automaticly.\n", "2. target -> The target qubit register\n", "\n", "\n", "
\n", "\n", - "\n" + "\n" ] }, { "cell_type": "code", - "execution_count": 1, + "execution_count": null, "metadata": {}, - "outputs": [ - { - "name": "stdout", - "output_type": "stream", - "text": [ - "Opening: https://platform.classiq.io/circuit/2uFzSO8cTvE2NVkAy8dR1eb4sZm?version=0.70.0\n" - ] - } - ], + "outputs": [], "source": [ "from classiq import *\n", "\n", @@ -116,17 +107,9 @@ }, { "cell_type": "code", - "execution_count": 2, + "execution_count": null, "metadata": {}, - "outputs": [ - { - "name": "stdout", - "output_type": "stream", - "text": [ - "Opening: https://platform.classiq.io/circuit/2uFzShpzAIiVqClCgiPJaTrlTxs?version=0.70.0\n" - ] - } - ], + "outputs": [], "source": [ "@qfunc\n", "def main(target: Output[QNum]):\n", @@ -184,30 +167,18 @@ }, { "cell_type": "code", - "execution_count": 3, + "execution_count": null, "metadata": {}, - "outputs": [ - { - "name": "stdout", - "output_type": "stream", - "text": [ - "Opening: https://platform.classiq.io/circuit/2uFzTDAQS6IWk5V6KbEniXGIMUB?version=0.70.0\n" - ] - } - ], + "outputs": [], "source": [ "@qfunc\n", "def my_black_box_prediate(aux: QBit, target: QNum):\n", " aux ^= target > 40\n", "\n", - "\n", "@qfunc\n", "def main(target: Output[QNum]):\n", " allocate(3, target) # Allocate 3 qubits to the target register\n", "\n", - " aux = QBit(\"aux\")\n", - " allocate(1, aux)\n", - "\n", " within_apply(\n", " within=lambda: hadamard_transform(target=target),\n", " apply=lambda: phase_oracle(\n", @@ -216,17 +187,21 @@ " ),\n", " )\n", "\n", - " free(aux)\n", - "\n", - "\n", "qprog_solution = synthesize(main)\n", "show(qprog_solution)" ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": {}, + "outputs": [], + "source": [] } ], "metadata": { "kernelspec": { - "display_name": "Python 3 (ipykernel)", + "display_name": "Python 3", "language": "python", "name": "python3" }, @@ -240,7 +215,7 @@ "name": "python", "nbconvert_exporter": "python", "pygments_lexer": "ipython3", - "version": "3.11.7" + "version": "3.10.13" } }, "nbformat": 4, diff --git a/tutorials/classiq_101/getting_started/part4_ghz_state.ipynb b/tutorials/classiq_101/getting_started/part4_ghz_state.ipynb index dc2f5c297..fe9ab2f99 100644 --- a/tutorials/classiq_101/getting_started/part4_ghz_state.ipynb +++ b/tutorials/classiq_101/getting_started/part4_ghz_state.ipynb @@ -24,17 +24,9 @@ }, { "cell_type": "code", - "execution_count": 1, + "execution_count": null, "metadata": {}, - "outputs": [ - { - "name": "stdout", - "output_type": "stream", - "text": [ - "Opening: https://platform.classiq.io/circuit/2uFzfHGxMGhCM1qrYeHzjojVohD?version=0.70.0\n" - ] - } - ], + "outputs": [], "source": [ "from classiq import *\n", "\n", @@ -59,17 +51,9 @@ }, { "cell_type": "code", - "execution_count": 2, + "execution_count": null, "metadata": {}, - "outputs": [ - { - "name": "stdout", - "output_type": "stream", - "text": [ - "Opening: https://platform.classiq.io/circuit/2uFzfUVluMz6gBPnnlJhS8lSFKf?version=0.70.0\n" - ] - } - ], + "outputs": [], "source": [ "from classiq import *\n", "\n", @@ -87,11 +71,18 @@ "qprog_solution = synthesize(main)\n", "show(qprog_solution)" ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": {}, + "outputs": [], + "source": [] } ], "metadata": { "kernelspec": { - "display_name": "Python 3 (ipykernel)", + "display_name": "Python 3", "language": "python", "name": "python3" }, @@ -105,7 +96,7 @@ "name": "python", "nbconvert_exporter": "python", "pygments_lexer": "ipython3", - "version": "3.11.7" + "version": "3.10.13" } }, "nbformat": 4, diff --git a/tutorials/classiq_101/getting_started/part5_grover.ipynb b/tutorials/classiq_101/getting_started/part5_grover.ipynb index 7f05777bf..650eed25b 100644 --- a/tutorials/classiq_101/getting_started/part5_grover.ipynb +++ b/tutorials/classiq_101/getting_started/part5_grover.ipynb @@ -15,43 +15,31 @@ }, { "cell_type": "code", - "execution_count": 1, + "execution_count": null, "metadata": {}, - "outputs": [ - { - "name": "stdout", - "output_type": "stream", - "text": [ - "" - ] - } - ], + "outputs": [], "source": [ "from classiq import *\n", "\n", "VAR_SIZE = 4\n", "\n", - "\n", "class ArithVars(QStruct):\n", " a: QNum[VAR_SIZE, False, 0]\n", " b: QNum[VAR_SIZE, True, 0] # signed variable\n", "\n", - "\n", "@qfunc\n", - "def arith_formula(x: QArray[QNum[VAR_SIZE, False, 0], 2], res: QBit):\n", - " res ^= 2 * x[0] == x[1]\n", - "\n", + "def arith_formula(vars: ArithVars, res: QBit):\n", + " res ^= 2 * vars.a == vars.b\n", "\n", "@qfunc\n", "def main(x: Output[ArithVars]):\n", " allocate(x.size, x)\n", " grover_search(\n", - " reps=1,\n", + " reps=2,\n", " oracle=lambda vars: phase_oracle(arith_formula, vars),\n", " packed_vars=x,\n", " )\n", "\n", - "\n", "qmod_grover = create_model(main)\n", "qprog_grover = synthesize(qmod_grover)\n", "show(qprog_grover)" @@ -66,7 +54,7 @@ "We are going to create a Grover algorithm that will find integer values that solve this equation: `2 * a = b`.\n", "\n", "This is the circuit that we want to create:\n", - "\n", + "\n", "\n", "\n", "The goal is to create this circuit in the Classiq SDK. This implementation will not utilize all possible functions of the Classiq SDK for learning purposes.\n", @@ -101,7 +89,7 @@ }, { "cell_type": "code", - "execution_count": 2, + "execution_count": null, "metadata": {}, "outputs": [], "source": [ @@ -122,7 +110,7 @@ "\n", "The Grover oracle will encode the arithmetic expression into the quantum circuit. We will use an in-place-xor to implement the quantum predicate, you do not have to manually do this. The part of the algorithm that we will create is seen in the image here:\n", "\n", - "\n", + "\n", "\n", "Here are some helpful: [Code examples](#Helpfull-code-examples)\n", "\n", @@ -136,7 +124,7 @@ }, { "cell_type": "code", - "execution_count": 3, + "execution_count": null, "metadata": {}, "outputs": [], "source": [ @@ -199,7 +187,7 @@ }, { "cell_type": "code", - "execution_count": 4, + "execution_count": null, "metadata": {}, "outputs": [], "source": [ @@ -224,17 +212,9 @@ }, { "cell_type": "code", - "execution_count": 5, + "execution_count": null, "metadata": {}, - "outputs": [ - { - "name": "stdout", - "output_type": "stream", - "text": [ - "Opening: https://platform.classiq.io/circuit/2uG07rDsNFRhCiv7gm7ypqUjWxU?version=0.70.0\n" - ] - } - ], + "outputs": [], "source": [ "@qfunc\n", "def main(\n", @@ -286,7 +266,7 @@ }, { "cell_type": "code", - "execution_count": 6, + "execution_count": null, "metadata": {}, "outputs": [], "source": [ @@ -320,7 +300,7 @@ }, { "cell_type": "code", - "execution_count": 7, + "execution_count": null, "metadata": {}, "outputs": [], "source": [ @@ -345,17 +325,9 @@ }, { "cell_type": "code", - "execution_count": 8, + "execution_count": null, "metadata": {}, - "outputs": [ - { - "name": "stdout", - "output_type": "stream", - "text": [ - "Opening: https://platform.classiq.io/circuit/2uG08AiPzBgHVTPMBMWBVldRhku?version=0.70.0\n" - ] - } - ], + "outputs": [], "source": [ "@qfunc\n", "def main(\n", @@ -384,7 +356,7 @@ }, { "cell_type": "code", - "execution_count": 9, + "execution_count": null, "metadata": {}, "outputs": [], "source": [ @@ -457,17 +429,9 @@ }, { "cell_type": "code", - "execution_count": 10, + "execution_count": null, "metadata": {}, - "outputs": [ - { - "name": "stdout", - "output_type": "stream", - "text": [ - "Opening: https://platform.classiq.io/circuit/2uG08upxFEGcWm3tEbew0PfcE4r?version=0.70.0\n" - ] - } - ], + "outputs": [], "source": [ "@qfunc\n", "def my_hadamard_transform(reg: QArray[QBit]):\n", @@ -526,11 +490,18 @@ "qprog_solution = synthesize(qmod_solution)\n", "show(qprog_solution)" ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": {}, + "outputs": [], + "source": [] } ], "metadata": { "kernelspec": { - "display_name": "Python 3 (ipykernel)", + "display_name": "Python 3", "language": "python", "name": "python3" }, @@ -544,7 +515,7 @@ "name": "python", "nbconvert_exporter": "python", "pygments_lexer": "ipython3", - "version": "3.11.7" + "version": "3.10.13" } }, "nbformat": 4,