diff --git a/docs/guides/serverless-template-hamiltonian-simulation.ipynb b/docs/guides/serverless-template-hamiltonian-simulation.ipynb index 08de2a770ea..8835061e4c1 100644 --- a/docs/guides/serverless-template-hamiltonian-simulation.ipynb +++ b/docs/guides/serverless-template-hamiltonian-simulation.ipynb @@ -3,13 +3,7 @@ { "cell_type": "markdown", "id": "b3e994de-6477-421d-8a9a-6b20d45260ae", - "metadata": { - "editable": true, - "slideshow": { - "slide_type": "" - }, - "tags": [] - }, + "metadata": {}, "source": [ "# Build a function template for Hamiltonian simulation" ] @@ -18,10 +12,6 @@ "cell_type": "markdown", "id": "31aee42c-1834-4fae-a05f-f78d8e5db7c0", "metadata": { - "editable": true, - "slideshow": { - "slide_type": "" - }, "tags": [ "version-info" ] @@ -45,13 +35,7 @@ { "cell_type": "markdown", "id": "5103c621-809d-48e9-ac86-2bf02916e2af", - "metadata": { - "editable": true, - "slideshow": { - "slide_type": "" - }, - "tags": [] - }, + "metadata": {}, "source": [ "By now you've seen a basic example of how to get started writing, uploading, and running a program with Qiskit Serverless. If you haven't, start with [What is Qiskit Serverless?](/guides/serverless) for some background information first.\n", "\n", @@ -65,13 +49,7 @@ { "cell_type": "markdown", "id": "e451f954-1d8f-4687-a7e9-e4b0dfa170f3", - "metadata": { - "editable": true, - "slideshow": { - "slide_type": "" - }, - "tags": [] - }, + "metadata": {}, "source": [ "## Write the function template\n", "\n", @@ -85,10 +63,6 @@ "execution_count": 1, "id": "35f5800c-163d-47a6-9fcf-13377be57282", "metadata": { - "editable": true, - "slideshow": { - "slide_type": "" - }, "tags": [ "remove-cell" ] @@ -104,13 +78,7 @@ { "cell_type": "markdown", "id": "115c14aa-5028-46f9-ab19-b49d47519636", - "metadata": { - "editable": true, - "slideshow": { - "slide_type": "" - }, - "tags": [] - }, + "metadata": {}, "source": [ "### Get the domain-level inputs\n", "\n", @@ -121,13 +89,7 @@ "cell_type": "code", "execution_count": 2, "id": "5e1e974b-feaa-47ce-abd1-65d442e8176e", - "metadata": { - "editable": true, - "slideshow": { - "slide_type": "" - }, - "tags": [] - }, + "metadata": {}, "outputs": [ { "name": "stdout", @@ -174,13 +136,7 @@ "cell_type": "code", "execution_count": 3, "id": "3f2629d5-5183-432a-8802-115a3b2f6ff7", - "metadata": { - "editable": true, - "slideshow": { - "slide_type": "" - }, - "tags": [] - }, + "metadata": {}, "outputs": [ { "name": "stdout", @@ -296,13 +252,7 @@ { "cell_type": "markdown", "id": "0e5495ee-82e2-43dc-bca7-f8e81f8b6302", - "metadata": { - "editable": true, - "slideshow": { - "slide_type": "" - }, - "tags": [] - }, + "metadata": {}, "source": [ "### Perform the Hamiltonian simulation workflow using AQC-Tensor\n", "\n", @@ -313,13 +263,7 @@ "cell_type": "code", "execution_count": 6, "id": "1677fa7c-3b4a-4a24-b1e4-e03d9b3c49da", - "metadata": { - "editable": true, - "slideshow": { - "slide_type": "" - }, - "tags": [] - }, + "metadata": {}, "outputs": [ { "name": "stdout", @@ -338,13 +282,7 @@ { "cell_type": "markdown", "id": "3acd5522-a880-4de7-9251-2d68efc261ad", - "metadata": { - "editable": true, - "slideshow": { - "slide_type": "" - }, - "tags": [] - }, + "metadata": {}, "source": [ "#### Step 1: Map\n", "\n", @@ -357,13 +295,7 @@ "cell_type": "code", "execution_count": 7, "id": "92b59882-2844-4312-a09b-3da02c63f60b", - "metadata": { - "editable": true, - "slideshow": { - "slide_type": "" - }, - "tags": [] - }, + "metadata": {}, "outputs": [ { "name": "stdout", @@ -492,13 +424,7 @@ { "cell_type": "markdown", "id": "ae8e53a6-2106-4753-ad1a-ebc146cd44ab", - "metadata": { - "editable": true, - "slideshow": { - "slide_type": "" - }, - "tags": [] - }, + "metadata": {}, "source": [ "#### Step 2: Optimize\n", "\n", @@ -509,13 +435,7 @@ "cell_type": "code", "execution_count": 8, "id": "1db2749f-1285-48c6-8ec3-bc9f422686e2", - "metadata": { - "editable": true, - "slideshow": { - "slide_type": "" - }, - "tags": [] - }, + "metadata": {}, "outputs": [ { "name": "stdout", @@ -547,13 +467,7 @@ { "cell_type": "markdown", "id": "c41b9c0e-1f00-454c-acff-c194cc16e03e", - "metadata": { - "editable": true, - "slideshow": { - "slide_type": "" - }, - "tags": [] - }, + "metadata": {}, "source": [ "#### Exit early if using dry run mode\n", "\n", @@ -564,13 +478,7 @@ "cell_type": "code", "execution_count": 9, "id": "e7c6c770-0453-4ad7-9a3e-20a47208768a", - "metadata": { - "editable": true, - "slideshow": { - "slide_type": "" - }, - "tags": [] - }, + "metadata": {}, "outputs": [ { "name": "stdout", @@ -595,13 +503,7 @@ { "cell_type": "markdown", "id": "3a603817-abaf-4403-beea-cca838a59577", - "metadata": { - "editable": true, - "slideshow": { - "slide_type": "" - }, - "tags": [] - }, + "metadata": {}, "source": [ "#### Step 3: Execute on hardware" ] @@ -610,13 +512,7 @@ "cell_type": "code", "execution_count": 10, "id": "b7525014-a473-4d9d-b7cb-9c590f2364ae", - "metadata": { - "editable": true, - "slideshow": { - "slide_type": "" - }, - "tags": [] - }, + "metadata": {}, "outputs": [ { "name": "stdout", @@ -659,13 +555,7 @@ { "cell_type": "markdown", "id": "12df35c4-4f1c-48cb-a323-d0cf33422fab", - "metadata": { - "editable": true, - "slideshow": { - "slide_type": "" - }, - "tags": [] - }, + "metadata": {}, "source": [ "#### Save the output\n", "\n", @@ -676,13 +566,7 @@ "cell_type": "code", "execution_count": 11, "id": "bfb8ab87-c42d-4993-92bd-8b38364dc443", - "metadata": { - "editable": true, - "slideshow": { - "slide_type": "" - }, - "tags": [] - }, + "metadata": {}, "outputs": [ { "name": "stdout", @@ -701,13 +585,7 @@ { "cell_type": "markdown", "id": "220f8bc8-4f04-41d3-86f1-15e9c2f45a56", - "metadata": { - "editable": true, - "slideshow": { - "slide_type": "" - }, - "tags": [] - }, + "metadata": {}, "source": [ "## Deploy to IBM Quantum Platform\n", "\n", @@ -722,13 +600,7 @@ "cell_type": "code", "execution_count": 12, "id": "313bd03b-bf9b-4e6c-aa05-1fe8def3868d", - "metadata": { - "editable": true, - "slideshow": { - "slide_type": "" - }, - "tags": [] - }, + "metadata": {}, "outputs": [], "source": [ "from qiskit_ibm_catalog import QiskitServerless, QiskitFunction\n", @@ -740,13 +612,7 @@ { "cell_type": "markdown", "id": "e9c495d4-cdab-4329-b65d-d111029aee64", - "metadata": { - "editable": true, - "slideshow": { - "slide_type": "" - }, - "tags": [] - }, + "metadata": {}, "source": [ "This program has custom `pip` dependencies. Add them to a `dependencies` array when constructing the `QiskitFunction` instance:" ] @@ -755,13 +621,7 @@ "cell_type": "code", "execution_count": 13, "id": "ca386323-d92d-4c41-908b-1670324e1264", - "metadata": { - "editable": true, - "slideshow": { - "slide_type": "" - }, - "tags": [] - }, + "metadata": {}, "outputs": [], "source": [ "template = QiskitFunction(\n", @@ -780,13 +640,7 @@ "cell_type": "code", "execution_count": 14, "id": "80a2c6b5-1f1e-4e90-9b1f-75907caf1df3", - "metadata": { - "editable": true, - "slideshow": { - "slide_type": "" - }, - "tags": [] - }, + "metadata": {}, "outputs": [ { "data": { @@ -806,13 +660,7 @@ { "cell_type": "markdown", "id": "06677105-627a-4948-aac7-071f44327a0b", - "metadata": { - "editable": true, - "slideshow": { - "slide_type": "" - }, - "tags": [] - }, + "metadata": {}, "source": [ "To check if the program successfully uploaded, use `serverless.list()`:" ] @@ -821,13 +669,7 @@ "cell_type": "code", "execution_count": 15, "id": "11f14088-8eca-4a99-a291-3f37a61b0d26", - "metadata": { - "editable": true, - "slideshow": { - "slide_type": "" - }, - "tags": [] - }, + "metadata": {}, "outputs": [ { "data": { @@ -847,13 +689,7 @@ { "cell_type": "markdown", "id": "385bda3e-73de-413c-8e45-cf7047303219", - "metadata": { - "editable": true, - "slideshow": { - "slide_type": "" - }, - "tags": [] - }, + "metadata": {}, "source": [ "## Run the function template remotely\n", "\n", @@ -864,13 +700,7 @@ "cell_type": "code", "execution_count": 16, "id": "d4ff8dea-95ab-4cc9-92b9-e28e277e76f2", - "metadata": { - "editable": true, - "slideshow": { - "slide_type": "" - }, - "tags": [] - }, + "metadata": {}, "outputs": [], "source": [ "template = serverless.load(\"template_hamiltonian_simulation\")" @@ -879,13 +709,7 @@ { "cell_type": "markdown", "id": "57964962-87e9-4c0b-a717-cb620019960e", - "metadata": { - "editable": true, - "slideshow": { - "slide_type": "" - }, - "tags": [] - }, + "metadata": {}, "source": [ "Next, run the template with the domain-level inputs for Hamiltonian simulation. This example specifies a 50-qubit XXZ model with random couplings, and an initial state and observable." ] @@ -894,13 +718,7 @@ "cell_type": "code", "execution_count": 17, "id": "e5d1555c-9abb-4fef-b8a2-f8d1b723df01", - "metadata": { - "editable": true, - "slideshow": { - "slide_type": "" - }, - "tags": [] - }, + "metadata": {}, "outputs": [], "source": [ "from itertools import chain\n", @@ -955,13 +773,7 @@ "cell_type": "code", "execution_count": 19, "id": "ac8d8fec-0290-4d6b-a18c-afd02acfa850", - "metadata": { - "editable": true, - "slideshow": { - "slide_type": "" - }, - "tags": [] - }, + "metadata": {}, "outputs": [ { "name": "stdout", @@ -992,13 +804,7 @@ { "cell_type": "markdown", "id": "2249cabc-6821-4d84-b4d8-e519c2d94a5c", - "metadata": { - "editable": true, - "slideshow": { - "slide_type": "" - }, - "tags": [] - }, + "metadata": {}, "source": [ "Check the status of the job:" ] @@ -1007,13 +813,7 @@ "cell_type": "code", "execution_count": 20, "id": "ed3b744d-cb00-43e0-907c-34dfebe2fa9b", - "metadata": { - "editable": true, - "slideshow": { - "slide_type": "" - }, - "tags": [] - }, + "metadata": {}, "outputs": [ { "data": { @@ -1042,13 +842,7 @@ "cell_type": "code", "execution_count": 21, "id": "3be62464-18b0-4598-b386-0ac0cc9cccb6", - "metadata": { - "editable": true, - "slideshow": { - "slide_type": "" - }, - "tags": [] - }, + "metadata": {}, "outputs": [ { "name": "stdout", @@ -1065,13 +859,7 @@ { "cell_type": "markdown", "id": "a8384509-2a9d-44e6-a729-40464ff52bea", - "metadata": { - "editable": true, - "slideshow": { - "slide_type": "" - }, - "tags": [] - }, + "metadata": {}, "source": [ "Block the rest of the program until a result is available. After the job is done, you can retrieve the results. These include the domain-level output of Hamiltonian simulation (expectation value) and useful metadata." ] @@ -1080,13 +868,7 @@ "cell_type": "code", "execution_count": 22, "id": "fc678bcd-539d-4970-86e0-9a69f0a367ef", - "metadata": { - "editable": true, - "slideshow": { - "slide_type": "" - }, - "tags": [] - }, + "metadata": {}, "outputs": [ { "data": { @@ -1325,13 +1107,7 @@ { "cell_type": "markdown", "id": "196d6261-e26b-4057-ae55-19f003fdc10a", - "metadata": { - "editable": true, - "slideshow": { - "slide_type": "" - }, - "tags": [] - }, + "metadata": {}, "source": [ "## Next steps\n", "\n", @@ -1343,24 +1119,24 @@ ] }, { - "cell_type": "markdown", + "cell_type": "code", "id": "20502fe4-7940-40fa-a978-64cc3ff6c1b1", "metadata": { - "editable": true, - "slideshow": { - "slide_type": "" - }, "tags": [ - "version-info" + "id-full-source" ] }, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "Overwriting ./source_files/template_hamiltonian_simulation_full.py\n" + ] + } + ], "source": [ - "
\n", - "Full program source code\n", - "\n", - "Here is the entire source of `./source_files/template_hamiltonian_simulation.py` as one code block.\n", - "\n", - "```python\n", + "%%writefile ./source_files/template_hamiltonian_simulation_full.py\n", "\n", "from qiskit import QuantumCircuit\n", "from qiskit_serverless import get_arguments, save_result\n", @@ -1436,7 +1212,7 @@ " f\"Invalid stopping fidelity: {aqc_stopping_fidelity}. It must be a positive float no greater than 1.\"\n", " )\n", "\n", - "output = {\"metadata\": arguments}\n", + "output = {}\n", "\n", "import os\n", "os.environ[\"NUMBA_CACHE_DIR\"] = \"/data\"\n", @@ -1599,8 +1375,21 @@ "print(\"Hardware expectation values\", hw_expvals)\n", "output[\"hw_expvals\"] = hw_expvals[0]\n", "\n", - "save_result(output)\n", - "```\n", + "save_result(output)" + ] + }, + { + "cell_type": "markdown", + "id": "d7f1776a-a8f6-43a3-85b7-33975c4eeec0", + "metadata": {}, + "source": [ + "
\n", + "Full program source code\n", + "\n", + "Here is the entire source of `./source_files/template_hamiltonian_simulation.py` as one code block.\n", + "\n", + "\n", + "\n", "
" ] }, @@ -1609,19 +1398,19 @@ "execution_count": 24, "id": "0a5ab26b-baea-48d0-979e-485df3118ac6", "metadata": { - "editable": true, - "slideshow": { - "slide_type": "" - }, "tags": [ "remove-cell" ] }, "outputs": [], "source": [ - "# This cell is hidden from users, it just deletes the working folder we created\n", + "# This cell is hidden from users. It verifies both source listings are identical then deletes the working folder we created\n", "import shutil\n", "\n", + "with open(\"./source_files/template_hamiltonian_simulation.py\") as f1:\n", + " with open(\"./source_files/template_hamiltonian_simulation_full.py\") as f2:\n", + " assert f1.read() == f2.read()\n", + "\n", "shutil.rmtree(\"./source_files/\")" ] }