diff --git a/exercises/Exercise1-solution.ipynb b/exercises/Exercise1-solution.ipynb new file mode 100644 index 0000000..4ffbb54 --- /dev/null +++ b/exercises/Exercise1-solution.ipynb @@ -0,0 +1,2059 @@ +{ + "cells": [ + { + "cell_type": "markdown", + "metadata": { + "tags": [ + "remove_cell" + ] + }, + "source": [ + "# Exercise Sheet 1: Quantum Logic Gates" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "To run this notebook you'll need to [install `qiskit`](https://docs.quantum.ibm.com/guides/install-qiskit), `qiskit-aer` and `qiskit-ibm-runtime`. This can be done in the cell below." + ] + }, + { + "cell_type": "code", + "execution_count": 1, + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "Requirement already satisfied: qiskit in /Users/zoemcintyre/miniconda3/envs/qenv/lib/python3.13/site-packages (2.2.1)\n", + "Requirement already satisfied: rustworkx>=0.15.0 in /Users/zoemcintyre/miniconda3/envs/qenv/lib/python3.13/site-packages (from qiskit) (0.17.1)\n", + "Requirement already satisfied: numpy<3,>=1.17 in /Users/zoemcintyre/miniconda3/envs/qenv/lib/python3.13/site-packages (from qiskit) (2.2.2)\n", + "Requirement already satisfied: scipy>=1.5 in /Users/zoemcintyre/miniconda3/envs/qenv/lib/python3.13/site-packages (from qiskit) (1.16.2)\n", + "Requirement already satisfied: dill>=0.3 in /Users/zoemcintyre/miniconda3/envs/qenv/lib/python3.13/site-packages (from qiskit) (0.4.0)\n", + "Requirement already satisfied: stevedore>=3.0.0 in /Users/zoemcintyre/miniconda3/envs/qenv/lib/python3.13/site-packages (from qiskit) (5.5.0)\n", + "Requirement already satisfied: typing-extensions in /Users/zoemcintyre/miniconda3/envs/qenv/lib/python3.13/site-packages (from qiskit) (4.12.2)\n", + "Collecting qiskit-aer\n", + " Downloading qiskit_aer-0.17.2-cp313-cp313-macosx_11_0_arm64.whl.metadata (8.3 kB)\n", + "Requirement already satisfied: qiskit>=1.1.0 in /Users/zoemcintyre/miniconda3/envs/qenv/lib/python3.13/site-packages (from qiskit-aer) (2.2.1)\n", + "Requirement already satisfied: numpy>=1.16.3 in /Users/zoemcintyre/miniconda3/envs/qenv/lib/python3.13/site-packages (from qiskit-aer) (2.2.2)\n", + "Requirement already satisfied: scipy>=1.0 in /Users/zoemcintyre/miniconda3/envs/qenv/lib/python3.13/site-packages (from qiskit-aer) (1.16.2)\n", + "Requirement already satisfied: psutil>=5 in /Users/zoemcintyre/miniconda3/envs/qenv/lib/python3.13/site-packages (from qiskit-aer) (6.1.1)\n", + "Requirement already satisfied: python-dateutil>=2.8.0 in /Users/zoemcintyre/miniconda3/envs/qenv/lib/python3.13/site-packages (from qiskit-aer) (2.9.0.post0)\n", + "Requirement already satisfied: six>=1.5 in /Users/zoemcintyre/miniconda3/envs/qenv/lib/python3.13/site-packages (from python-dateutil>=2.8.0->qiskit-aer) (1.16.0)\n", + "Requirement already satisfied: rustworkx>=0.15.0 in /Users/zoemcintyre/miniconda3/envs/qenv/lib/python3.13/site-packages (from qiskit>=1.1.0->qiskit-aer) (0.17.1)\n", + "Requirement already satisfied: dill>=0.3 in /Users/zoemcintyre/miniconda3/envs/qenv/lib/python3.13/site-packages (from qiskit>=1.1.0->qiskit-aer) (0.4.0)\n", + "Requirement already satisfied: stevedore>=3.0.0 in /Users/zoemcintyre/miniconda3/envs/qenv/lib/python3.13/site-packages (from qiskit>=1.1.0->qiskit-aer) (5.5.0)\n", + "Requirement already satisfied: typing-extensions in /Users/zoemcintyre/miniconda3/envs/qenv/lib/python3.13/site-packages (from qiskit>=1.1.0->qiskit-aer) (4.12.2)\n", + "Downloading qiskit_aer-0.17.2-cp313-cp313-macosx_11_0_arm64.whl (2.1 MB)\n", + "\u001b[2K \u001b[90m━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━\u001b[0m \u001b[32m2.1/2.1 MB\u001b[0m \u001b[31m24.6 MB/s\u001b[0m eta \u001b[36m0:00:00\u001b[0m\n", + "Installing collected packages: qiskit-aer\n", + "Successfully installed qiskit-aer-0.17.2\n", + "Collecting qiskit-ibm-runtime\n", + " Downloading qiskit_ibm_runtime-0.42.0-py3-none-any.whl.metadata (21 kB)\n", + "Requirement already satisfied: requests>=2.19 in /Users/zoemcintyre/miniconda3/envs/qenv/lib/python3.13/site-packages (from qiskit-ibm-runtime) (2.32.3)\n", + "Collecting requests-ntlm>=1.1.0 (from qiskit-ibm-runtime)\n", + " Downloading requests_ntlm-1.3.0-py3-none-any.whl.metadata (2.4 kB)\n", + "Requirement already satisfied: numpy>=1.13 in /Users/zoemcintyre/miniconda3/envs/qenv/lib/python3.13/site-packages (from qiskit-ibm-runtime) (2.2.2)\n", + "Requirement already satisfied: urllib3>=1.21.1 in /Users/zoemcintyre/miniconda3/envs/qenv/lib/python3.13/site-packages (from qiskit-ibm-runtime) (2.3.0)\n", + "Requirement already satisfied: python-dateutil>=2.8.0 in /Users/zoemcintyre/miniconda3/envs/qenv/lib/python3.13/site-packages (from qiskit-ibm-runtime) (2.9.0.post0)\n", + "Collecting ibm-platform-services>=0.22.6 (from qiskit-ibm-runtime)\n", + " Downloading ibm_platform_services-0.69.0-py3-none-any.whl.metadata (9.0 kB)\n", + "Collecting pydantic>=2.5.0 (from qiskit-ibm-runtime)\n", + " Downloading pydantic-2.11.10-py3-none-any.whl.metadata (68 kB)\n", + "Requirement already satisfied: qiskit>=1.4.1 in /Users/zoemcintyre/miniconda3/envs/qenv/lib/python3.13/site-packages (from qiskit-ibm-runtime) (2.2.1)\n", + "Requirement already satisfied: packaging in /Users/zoemcintyre/miniconda3/envs/qenv/lib/python3.13/site-packages (from qiskit-ibm-runtime) (24.2)\n", + "Collecting ibm_cloud_sdk_core<4.0.0,>=3.24.2 (from ibm-platform-services>=0.22.6->qiskit-ibm-runtime)\n", + " Downloading ibm_cloud_sdk_core-3.24.2-py3-none-any.whl.metadata (8.7 kB)\n", + "Collecting annotated-types>=0.6.0 (from pydantic>=2.5.0->qiskit-ibm-runtime)\n", + " Downloading annotated_types-0.7.0-py3-none-any.whl.metadata (15 kB)\n", + "Collecting pydantic-core==2.33.2 (from pydantic>=2.5.0->qiskit-ibm-runtime)\n", + " Downloading pydantic_core-2.33.2-cp313-cp313-macosx_11_0_arm64.whl.metadata (6.8 kB)\n", + "Requirement already satisfied: typing-extensions>=4.12.2 in /Users/zoemcintyre/miniconda3/envs/qenv/lib/python3.13/site-packages (from pydantic>=2.5.0->qiskit-ibm-runtime) (4.12.2)\n", + "Collecting typing-inspection>=0.4.0 (from pydantic>=2.5.0->qiskit-ibm-runtime)\n", + " Downloading typing_inspection-0.4.2-py3-none-any.whl.metadata (2.6 kB)\n", + "Requirement already satisfied: six>=1.5 in /Users/zoemcintyre/miniconda3/envs/qenv/lib/python3.13/site-packages (from python-dateutil>=2.8.0->qiskit-ibm-runtime) (1.16.0)\n", + "Requirement already satisfied: rustworkx>=0.15.0 in /Users/zoemcintyre/miniconda3/envs/qenv/lib/python3.13/site-packages (from qiskit>=1.4.1->qiskit-ibm-runtime) (0.17.1)\n", + "Requirement already satisfied: scipy>=1.5 in /Users/zoemcintyre/miniconda3/envs/qenv/lib/python3.13/site-packages (from qiskit>=1.4.1->qiskit-ibm-runtime) (1.16.2)\n", + "Requirement already satisfied: dill>=0.3 in /Users/zoemcintyre/miniconda3/envs/qenv/lib/python3.13/site-packages (from qiskit>=1.4.1->qiskit-ibm-runtime) (0.4.0)\n", + "Requirement already satisfied: stevedore>=3.0.0 in /Users/zoemcintyre/miniconda3/envs/qenv/lib/python3.13/site-packages (from qiskit>=1.4.1->qiskit-ibm-runtime) (5.5.0)\n", + "Requirement already satisfied: charset-normalizer<4,>=2 in /Users/zoemcintyre/miniconda3/envs/qenv/lib/python3.13/site-packages (from requests>=2.19->qiskit-ibm-runtime) (3.4.1)\n", + "Requirement already satisfied: idna<4,>=2.5 in /Users/zoemcintyre/miniconda3/envs/qenv/lib/python3.13/site-packages (from requests>=2.19->qiskit-ibm-runtime) (3.10)\n", + "Requirement already satisfied: certifi>=2017.4.17 in /Users/zoemcintyre/miniconda3/envs/qenv/lib/python3.13/site-packages (from requests>=2.19->qiskit-ibm-runtime) (2025.1.31)\n", + "Collecting cryptography>=1.3 (from requests-ntlm>=1.1.0->qiskit-ibm-runtime)\n", + " Downloading cryptography-46.0.2-cp311-abi3-macosx_10_9_universal2.whl.metadata (5.7 kB)\n", + "Collecting pyspnego>=0.4.0 (from requests-ntlm>=1.1.0->qiskit-ibm-runtime)\n", + " Downloading pyspnego-0.12.0-py3-none-any.whl.metadata (4.1 kB)\n", + "Collecting cffi>=2.0.0 (from cryptography>=1.3->requests-ntlm>=1.1.0->qiskit-ibm-runtime)\n", + " Downloading cffi-2.0.0-cp313-cp313-macosx_11_0_arm64.whl.metadata (2.6 kB)\n", + "Collecting requests>=2.19 (from qiskit-ibm-runtime)\n", + " Downloading requests-2.32.5-py3-none-any.whl.metadata (4.9 kB)\n", + "Collecting urllib3>=1.21.1 (from qiskit-ibm-runtime)\n", + " Downloading urllib3-2.5.0-py3-none-any.whl.metadata (6.5 kB)\n", + "Collecting PyJWT<3.0.0,>=2.10.1 (from ibm_cloud_sdk_core<4.0.0,>=3.24.2->ibm-platform-services>=0.22.6->qiskit-ibm-runtime)\n", + " Downloading PyJWT-2.10.1-py3-none-any.whl.metadata (4.0 kB)\n", + "Requirement already satisfied: pycparser in /Users/zoemcintyre/miniconda3/envs/qenv/lib/python3.13/site-packages (from cffi>=2.0.0->cryptography>=1.3->requests-ntlm>=1.1.0->qiskit-ibm-runtime) (2.22)\n", + "Downloading qiskit_ibm_runtime-0.42.0-py3-none-any.whl (1.4 MB)\n", + "\u001b[2K \u001b[90m━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━\u001b[0m \u001b[32m1.4/1.4 MB\u001b[0m \u001b[31m6.7 MB/s\u001b[0m eta \u001b[36m0:00:00\u001b[0ma \u001b[36m0:00:01\u001b[0m\n", + "\u001b[?25hDownloading ibm_platform_services-0.69.0-py3-none-any.whl (368 kB)\n", + "Downloading pydantic-2.11.10-py3-none-any.whl (444 kB)\n", + "Downloading pydantic_core-2.33.2-cp313-cp313-macosx_11_0_arm64.whl (1.8 MB)\n", + "\u001b[2K \u001b[90m━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━\u001b[0m \u001b[32m1.8/1.8 MB\u001b[0m \u001b[31m12.3 MB/s\u001b[0m eta \u001b[36m0:00:00\u001b[0m\n", + "Downloading requests_ntlm-1.3.0-py3-none-any.whl (6.6 kB)\n", + "Downloading annotated_types-0.7.0-py3-none-any.whl (13 kB)\n", + "Downloading cryptography-46.0.2-cp311-abi3-macosx_10_9_universal2.whl (7.3 MB)\n", + "\u001b[2K \u001b[90m━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━\u001b[0m \u001b[32m7.3/7.3 MB\u001b[0m \u001b[31m18.4 MB/s\u001b[0m eta \u001b[36m0:00:00\u001b[0ma \u001b[36m0:00:01\u001b[0m\n", + "\u001b[?25hDownloading ibm_cloud_sdk_core-3.24.2-py3-none-any.whl (75 kB)\n", + "Downloading requests-2.32.5-py3-none-any.whl (64 kB)\n", + "Downloading urllib3-2.5.0-py3-none-any.whl (129 kB)\n", + "Downloading pyspnego-0.12.0-py3-none-any.whl (130 kB)\n", + "Downloading typing_inspection-0.4.2-py3-none-any.whl (14 kB)\n", + "Downloading cffi-2.0.0-cp313-cp313-macosx_11_0_arm64.whl (181 kB)\n", + "Downloading PyJWT-2.10.1-py3-none-any.whl (22 kB)\n", + "Installing collected packages: urllib3, typing-inspection, PyJWT, pydantic-core, cffi, annotated-types, requests, pydantic, cryptography, pyspnego, ibm_cloud_sdk_core, requests-ntlm, ibm-platform-services, qiskit-ibm-runtime\n", + " Attempting uninstall: urllib3\n", + " Found existing installation: urllib3 2.3.0\n", + " Uninstalling urllib3-2.3.0:\n", + " Successfully uninstalled urllib3-2.3.0\n", + " Attempting uninstall: cffi\n", + " Found existing installation: cffi 1.17.1\n", + " Uninstalling cffi-1.17.1:\n", + " Successfully uninstalled cffi-1.17.1\n", + " Attempting uninstall: requests\n", + " Found existing installation: requests 2.32.3\n", + " Uninstalling requests-2.32.3:\n", + " Successfully uninstalled requests-2.32.3\n", + "Successfully installed PyJWT-2.10.1 annotated-types-0.7.0 cffi-2.0.0 cryptography-46.0.2 ibm-platform-services-0.69.0 ibm_cloud_sdk_core-3.24.2 pydantic-2.11.10 pydantic-core-2.33.2 pyspnego-0.12.0 qiskit-ibm-runtime-0.42.0 requests-2.32.5 requests-ntlm-1.3.0 typing-inspection-0.4.2 urllib3-2.5.0\n" + ] + } + ], + "source": [ + "!pip install qiskit\n", + "!pip install qiskit-aer\n", + "!pip install qiskit-ibm-runtime" + ] + }, + { + "cell_type": "code", + "execution_count": 31, + "metadata": {}, + "outputs": [], + "source": [ + "from qiskit import QuantumCircuit, transpile\n", + "from qiskit_aer import AerSimulator\n", + "from qiskit.visualization import plot_histogram\n", + "import numpy as np\n", + "\n", + "from tests1 import *" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "# Overview\n", + "## **Exercise 1**\n", + "\n", + "See 'Part 1' below, and find and complete the circuits required for the:\n", + "* (a) `XOR` gate;\n", + "* (b) `AND` gate;\n", + "* (c) `NAND` gate;\n", + "* (d) `OR` gate.\n", + "\n", + "'Part 2' below is for your own interest, where you will find a `layout` for which the AND gate compiles to 6 non-local gates for `Manila`. Note that there is some randomness in the compiling process. So you might need to try a few times. Feel free to transipile the other gates you have designed. \n", + "\n", + "## **Excercise 2** \n", + "Answers Code showing various properties of foundational operations such as the Pauli gates/matrices and the Hadamard gate/matrix and some practice on alternative bases. \n", + "* 1) (a)(b) Alternative Pauli Basis States\n", + "* 2) (a)(b)(c)(d) Properties of Pauli Matrices\n", + "* 3) (a)(b)(c) The Hadamard" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "# Exercise 1\n", + "

Part 1: Classical logic gates with quantum circuits

\n", + "\n", + "
\n", + "\n", + "

📓 NOT gate (an example)

\n", + "\n", + "In the following function we use a quantum circuit to do the simplest job in all of computation: apply a NOT gate to a bit." + ] + }, + { + "cell_type": "code", + "execution_count": 32, + "metadata": {}, + "outputs": [], + "source": [ + "def NOT(inp):\n", + " \"\"\"An NOT gate.\n", + " \n", + " Parameters:\n", + " inp (str): Input, encoded in qubit 0.\n", + " \n", + " Returns:\n", + " QuantumCircuit: Output NOT circuit.\n", + " str: Output value measured from qubit 0.\n", + " \"\"\"\n", + "\n", + " qc = QuantumCircuit(1, 1) # A quantum circuit with a single qubit and a single classical bit\n", + " qc.reset(0)\n", + " \n", + " # We encode '0' as the qubit state |0⟩, and '1' as |1⟩\n", + " # Since the qubit is initially |0⟩, we don't need to do anything for an input of '0'\n", + " # For an input of '1', we do an x to rotate the |0⟩ to |1⟩\n", + " if inp=='1':\n", + " qc.x(0)\n", + " \n", + " # barrier between input state and gate operation \n", + " qc.barrier()\n", + " \n", + " # Now we've encoded the input, we can do a NOT on it using x\n", + " qc.x(0)\n", + " \n", + " #barrier between gate operation and measurement\n", + " qc.barrier()\n", + " \n", + " # Finally, we extract the |0⟩/|1⟩ output of the qubit and encode it in the bit c[0]\n", + " qc.measure(0,0)\n", + " \n", + " # We'll run the program on a simulator\n", + " backend = AerSimulator()\n", + " # Since the output will be deterministic, we can use just a single shot to get it\n", + " job = backend.run(qc, shots=1, memory=True)\n", + " output = job.result().get_memory()[0]\n", + " \n", + " return qc, output" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "Now let's see it in action." + ] + }, + { + "cell_type": "code", + "execution_count": 33, + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "NOT with input 0 gives output 1\n" + ] + }, + { + "data": { + "text/html": [ + "
           ░ ┌───┐ ░ ┌─┐\n",
+       "  q: ─|0>──░─┤ X ├─░─┤M├\n",
+       "           ░ └───┘ ░ └╥┘\n",
+       "c: 1/═════════════════╩═\n",
+       "                      0 
" + ], + "text/plain": [ + " ░ ┌───┐ ░ ┌─┐\n", + " q: ─|0>──░─┤ X ├─░─┤M├\n", + " ░ └───┘ ░ └╥┘\n", + "c: 1/═════════════════╩═\n", + " 0 " + ] + }, + "metadata": {}, + "output_type": "display_data" + }, + { + "name": "stdout", + "output_type": "stream", + "text": [ + "\n", + "\n", + "NOT with input 1 gives output 0\n" + ] + }, + { + "data": { + "text/html": [ + "
          ┌───┐ ░ ┌───┐ ░ ┌─┐\n",
+       "  q: ─|0>─┤ X ├─░─┤ X ├─░─┤M├\n",
+       "          └───┘ ░ └───┘ ░ └╥┘\n",
+       "c: 1/══════════════════════╩═\n",
+       "                           0 
" + ], + "text/plain": [ + " ┌───┐ ░ ┌───┐ ░ ┌─┐\n", + " q: ─|0>─┤ X ├─░─┤ X ├─░─┤M├\n", + " └───┘ ░ └───┘ ░ └╥┘\n", + "c: 1/══════════════════════╩═\n", + " 0 " + ] + }, + "metadata": {}, + "output_type": "display_data" + }, + { + "name": "stdout", + "output_type": "stream", + "text": [ + "\n", + "\n" + ] + } + ], + "source": [ + "for inp in ['0', '1']:\n", + " qc, out = NOT(inp)\n", + " print('NOT with input',inp,'gives output',out)\n", + " display(qc.draw())\n", + " print('\\n')" + ] + }, + { + "cell_type": "code", + "execution_count": 34, + "metadata": {}, + "outputs": [ + { + "data": { + "image/png": "iVBORw0KGgoAAAANSUhEUgAAAnYAAAHWCAYAAAD6oMSKAAAAOnRFWHRTb2Z0d2FyZQBNYXRwbG90bGliIHZlcnNpb24zLjEwLjAsIGh0dHBzOi8vbWF0cGxvdGxpYi5vcmcvlHJYcgAAAAlwSFlzAAAPYQAAD2EBqD+naQAAJqJJREFUeJzt3X+UlnWB///XPT8YlAAFlB8rIJrpKqSkW4HHHyiJhKZpmm1L6mpru2Wxoml5+KTlr2xTO3bWNvVIZi6e3VZz0000NUvyx5IUbq2HTRQUEIFg0HAYmPn+4Zf7OMEgMzLM8O7xOGfO4X5f7/u+3xdnrvs855rrvqfS2traGgAAdno13b0AAAC2D2EHAFAIYQcAUAhhBwBQCGEHAFAIYQcAUAhhBwBQCGEHAFCIuu5eQE/V0tKSJUuWpG/fvqlUKt29HADgz1Rra2vWrl2bYcOGpaZm6+fkhF07lixZkuHDh3f3MgAAkiSLFy/OXnvttdU5wq4dffv2TfLmf2K/fv26eTUAwJ+rxsbGDB8+vNomWyPs2rHp16/9+vUTdgBAt9uWS8O8eQIAoBDCDgCgEMIOAKAQwo4e67LLLkulUmnzNWTIkC3OPe+881KpVHLDDTdUx1atWpXzzz8/+++/f3bdddeMGDEin//857NmzZodtAcAsGN58wQ92kEHHZSHHnqoeru2tnazOffcc0+efPLJDBs2rM34kiVLsmTJkvzTP/1TDjzwwLz44ov5zGc+kyVLluTf//3fu3ztALCjCTt6tLq6unbP0iXJyy+/nM997nN54IEHMmXKlDbbRo8enR/+8IfV2/vuu2+uvPLK/M3f/E02bNiQujrf/gCUxa9i6dEWLFiQYcOGZdSoUTnjjDPy/PPPV7e1tLRk6tSpueiii3LQQQdt0+OtWbMm/fr1E3UAFEnY0WN94AMfyO23354HHnggN998c5YtW5bx48dn5cqVSZKvf/3rqaury+c///lteryVK1fma1/7Ws4777yuXDYAdBunLeixJk+eXP33mDFjMm7cuOy777753ve+l6OOOirf+ta38qtf/WqbPrCxsbExU6ZMyYEHHpivfOUrXblsAOg2ztix0+jTp0/GjBmTBQsW5Oc//3mWL1+eESNGpK6uLnV1dXnxxRczffr07L333m3ut3bt2hx//PF517velbvvvjv19fXdswMA0MWcsWOn0dTUlN/97nc54ogjMnXq1EycOLHN9kmTJmXq1Kk5++yzq2ONjY2ZNGlSGhoacu+996Z37947etkAsMMIO3qsCy+8MCeeeGJGjBiR5cuX54orrkhjY2POPPPMDBw4MAMHDmwzv76+PkOGDMn++++f5M0zdccdd1z++Mc/5o477khjY2MaGxuTJHvssccWPzoFAHZmwo4e66WXXsonPvGJrFixInvssUc++MEP5oknnsjIkSO36f5z587Nk08+mSR597vf3WbbwoULN/uVLQDs7Cqtra2t3b2InqixsTH9+/evfjwGAEB36EiTePMEAEAhhB0AQCGEHQBAIYQdAEAhhB0AQCGEHQBAIYQdAEAhhB0AQCGEHQBAIYQdAEAhhB0AFOCyyy5LpVJp8zVkyJDq9v/4j//IpEmTMmjQoFQqlcybN6/dx2ptbc3kyZNTqVRyzz33dP3i2W6EHQAU4qCDDsrSpUurX/Pnz69ue/3113P44YfnmmuuedvHueGGG1KpVLpyqXSRuu5eAACwfdTV1bU5S/dWU6dOTZK88MILW32MX//617nuuuvy9NNPZ+jQodt7iXQxZ+wAoBALFizIsGHDMmrUqJxxxhl5/vnnO3T/P/7xj/nEJz6Rb3/72+0GIj2bsAOAAnzgAx/I7bffngceeCA333xzli1blvHjx2flypXb/Bj/+I//mPHjx+ekk07qwpXSlfwqFgAKMHny5Oq/x4wZk3HjxmXffffN9773vVxwwQVve/977703Dz/8cJ555pmuXCZdzBk7AChQnz59MmbMmCxYsGCb5j/88MP5/e9/n9122y11dXWpq3vz3M+pp56ao48+ugtXyvbkjB0AFKipqSm/+93vcsQRR2zT/EsuuSTnnntum7ExY8bk+uuvz4knntgVS6QLCDsAKMCFF16YE088MSNGjMjy5ctzxRVXpLGxMWeeeWaSZNWqVVm0aFGWLFmSJHnuueeSJEOGDGnz9adGjBiRUaNG7bgd4R3xq1gAKMBLL72UT3ziE9l///1zyimnpFevXnniiScycuTIJG9eQzd27NhMmTIlSXLGGWdk7Nix+c53vtOdy2Y7q7S2trZ29yJ6osbGxvTv3z9r1qxJv379uns5AMCfqY40iTN2AACFcI1dN9v7kvu6ewmwmReumdLdSwCgE5yxAwAohLADACiEsAMAKISwAwAohLADACiEsAMAKISwAwAohLADACiEsAMAKISwAwAohLADACiEsAMAKISwAwAohLADACiEsAMAKISwAwAohLADACiEsAMAKISwAwAoRF13LwAAttXel9zX3UuAzbxwzZTuXkKVM3YAAIUQdgAAhRB2AACFEHYAAIUQdgAAhRB2AACFEHYAAIUQdgAAhRB2AACFEHYAAIUQdgAAhRB2AACFEHYAAIUQdgAAhRB2AACFEHYAAIUQdgAAhRB2AACFEHYAAIUQdgAAhRB2AACFEHYAAIUQdgAAhRB2AACFEHYAAIUQdgAAhRB2AACFEHYAAIUQdgAAhRB2AACFEHYAAIUQdgAAhRB2AACFEHYAAIUQdgAAhRB2AACFEHYAAIUQdgAAhRB2AACFEHYAAIXo0WF39dVXp1KpZNq0adWxs846K5VKpc3XBz/4wTb3a2pqyvnnn59BgwalT58++chHPpKXXnppB68eAGDH6rFh9/TTT+e73/1u3vve92627fjjj8/SpUurX/fff3+b7dOmTcvdd9+dWbNm5Re/+EVee+21nHDCCdm4ceOOWj4AwA7XI8Putddeyyc/+cncfPPN2X333Tfb3tDQkCFDhlS/BgwYUN22Zs2a3HrrrfnmN7+ZiRMnZuzYsbnjjjsyf/78PPTQQztyNwAAdqgeGXaf/exnM2XKlEycOHGL2x999NHsueeeec973pNPf/rTWb58eXXb3Llz09zcnOOOO646NmzYsIwePTpz5szp8rUDAHSXuu5ewJ+aNWtWfvWrX+Xpp5/e4vbJkyfntNNOy8iRI7Nw4cLMmDEjxxxzTObOnZuGhoYsW7YsvXr12uxM3+DBg7Ns2bJ2n7epqSlNTU3V242NjUmS5ubmNDc3J0lqampSW1ubjRs3pqWlpTp30/iGDRvS2tpaHa+trU1NTU2745seF3qaTd+bdXVvvkRs2LChzfb6+vq0tLS0ubyhUqmkrq6u3fH2jpuuOp7aW7t92rn3CXqiHXE8baseFXaLFy/OF77whcyePTu9e/fe4pyPf/zj1X+PHj06hx12WEaOHJn77rsvp5xySruP3dramkql0u72q6++Opdffvlm47Nnz86uu+6aJBkxYkTGjh2b3/zmN1m0aFF1zv77758DDjggTz31VF599dXq+CGHHJKRI0fmsccey9q1a6vj48aNy5577pnZs2e3ux7oTpuuW/3whz+cdevW5ZFHHqluq6ury5QpU7JixYr88pe/rI737ds3xxxzTBYvXpx58+ZVx/fYY4+MHz8+CxYsyHPPPVcd74rj6a0vfhMmTMguu+yy2TW49mnn3ifoibr6eHr88ce3eS2V1remYTe755578tGPfjS1tbXVsY0bN6ZSqaSmpiZNTU1ttm2y33775dxzz83FF1+chx9+OMcee2xWrVrV5qzdwQcfnJNPPnmL8ZZs+Yzd8OHDs2LFivTr1y9J1/zkut8McUfPs+Brb17K8Od0Jsg+7Rz75DWTnuj5qyZ36fG0atWqDBw4MGvWrKk2SXt61I8/xx57bObPn99m7Oyzz84BBxyQiy++eItRt3LlyixevDhDhw5Nkhx66KGpr6/Pgw8+mNNPPz1JsnTp0jz77LO59tpr233uhoaGNDQ0bDZeX1+f+vr6NmO1tbVbXEt7P022N/6njws9xZ9+b27pe7WmpiY1NZtfptveeHvHTVcfTx0Zt087xz5BT9Ndx9MW527zzB2gb9++GT16dJuxPn36ZODAgRk9enRee+21XHbZZTn11FMzdOjQvPDCC/nyl7+cQYMG5aMf/WiSpH///jnnnHMyffr0DBw4MAMGDMiFF16YMWPGtPtmDACAEvSosHs7tbW1mT9/fm6//fasXr06Q4cOzYQJE3LXXXelb9++1XnXX3996urqcvrpp2fdunU59thjM3PmzC3WMQBAKXp82D366KPVf++yyy554IEH3vY+vXv3zo033pgbb7yxC1cGANCz9MjPsQMAoOOEHQBAIYQdAEAhhB0AQCGEHQBAIYQdAEAhhB0AQCGEHQBAIYQdAEAhhB0AQCGEHQBAIYQdAEAhhB0AQCGEHQBAIYQdAEAhhB0AQCGEHQBAIYQdAEAhhB0AQCGEHQBAIYQdAEAhhB0AQCGEHQBAIYQdAEAhhB0AQCGEHQBAIYQdAEAhhB0AQCGEHQBAIYQdAEAhhB0AQCGEHQBAIYQdAEAhhB0AQCGEHQBAIYQdAEAhhB0AQCGEHQBAIYQdAEAhhB0AQCGEHQBAIYQdAEAhhB0AQCGEHQBAIYQdAEAhhB0AQCGEHQBAIYQdAEAhhB0AQCGEHQBAIYQdAEAhhB0AQCGEHQBAIYQdAEAhhB0AQCGEHQBAIYQdAEAhhB0AQCGEHQBAIYQdAEAhhB0AQCGEHQBAIYQdAEAhhB0AQCGEHQBAIYQdAEAhhB0AQCGEHQBAIYQdAEAhhB0AQCGEHQBAIYQdAEAhhB0AQCGEHQBAIYQdAEAhhB0AQCE6HXaPPfZYFi1atNU5L730Uh577LHOPgUAAB3Q6bCbMGFCZs6cudU5P/jBDzJhwoTOPgUAAB3Q6bBrbW192zktLS2pVCqdfQoAADqgS6+xW7BgQfr379+VTwEAwP+vriOT//Zv/7bN7XvuuScvvPDCZvM2btxYvb7u+OOPf0cLBABg23Qo7N56TV2lUsm8efMyb968Lc6tVCr5q7/6q1x//fXvZH0AAGyjDoXdwoULk7x5fd0+++yTadOm5Qtf+MJm82pra7P77runT58+22eVAAC8rQ6F3ciRI6v/vu222zJ27Ng2YwAAdJ8Ohd1bnXnmmdtzHQAAvEOdDrtNnnrqqTz99NNZvXp1Nm7cuNn2SqWSGTNmvNOnAQDgbXQ67FatWpWTTz45jz/++FY/007YAQDsGJ0OuwsuuCC/+MUvcvTRR+fMM8/MXnvtlbq6d3wCEACATup0if34xz/O+9///vz0pz/11yUAAHqATv/liTfeeCNHHnmkqAMA6CE6HXZjx47d4l+dAACge3Q67C677LLce++9eeKJJ7bnegAA6KROX2P38ssv54QTTshRRx2VT37ykxk7dmz69++/xbmf+tSnOr1AAAC2TafD7qyzzkqlUklra2tmzpyZmTNnbna9XWtrayqVirADANgBOh12t9122/ZcBwAA75A/KQYAUIhOv3kCAICepdNht2jRom3+6oibbrop733ve9OvX7/069cv48aNy3/9139Vt7e2tuayyy7LsGHDsssuu+Too4/O//zP/7R5jKamppx//vkZNGhQ+vTpk4985CN56aWXOrurAAA7hU7/Knbvvffepg8nrlQq2bBhwzY/7l577ZVrrrkm7373u5Mk3/ve93LSSSflmWeeyUEHHZRrr7021113XWbOnJn3vOc9ueKKK/KhD30ozz33XPr27ZskmTZtWv7zP/8zs2bNysCBAzN9+vSccMIJmTt3bmprazu3wwAAPVynw+5Tn/rUFsNuzZo1+fWvf52FCxfmqKOOyt57792hxz3xxBPb3L7yyitz00035YknnsiBBx6YG264IZdeemlOOeWUJG+G3+DBg3PnnXfmvPPOy5o1a3Lrrbfm+9//fiZOnJgkueOOOzJ8+PA89NBDmTRpUud2GACgh+t02M2cObPdba2trfnmN7+Za6+9NrfeemtnnyIbN27Mv/3bv+X111/PuHHjsnDhwixbtizHHXdcdU5DQ0OOOuqozJkzJ+edd17mzp2b5ubmNnOGDRuW0aNHZ86cOe2GXVNTU5qamqq3GxsbkyTNzc1pbm5OktTU1KS2tjYbN25MS0tLde6m8Q0bNqS1tbU6Xltbm5qamnbHNz0u9DSbvjfr6t58ifjTs+719fVpaWnJxo0bq2OVSiV1dXXtjrd33HTV8dTe2u3Tzr1P0BPtiONpW3U67LamUqnkwgsvzH333ZeLLrooP/zhDzt0//nz52fcuHF544038q53vSt33313DjzwwMyZMydJMnjw4DbzBw8enBdffDFJsmzZsvTq1Su77777ZnOWLVvW7nNeffXVufzyyzcbnz17dnbdddckyYgRIzJ27Nj85je/aXPt4P77758DDjggTz31VF599dXq+CGHHJKRI0fmsccey9q1a6vj48aNy5577pnZs2dv638J7FD3339/kuTDH/5w1q1bl0ceeaS6ra6uLlOmTMmKFSvyy1/+sjret2/fHHPMMVm8eHHmzZtXHd9jjz0yfvz4LFiwIM8991x1vCuOp7e++E2YMCG77LJLdV82sU879z5BT9TVx9Pjjz++zWuptL41Dbeziy66KLfcckv+8Ic/dOh+69evz6JFi7J69er88Ic/zC233JKf/exnWb16dQ4//PAsWbIkQ4cOrc7/9Kc/ncWLF+cnP/lJ7rzzzpx99tltzr4lyYc+9KHsu++++c53vrPF59zSGbvhw4dnxYoV6devX5Ku+cl1vxnijp5nwdfePOP953QmyD7tHPvkNZOe6PmrJnfp8bRq1aoMHDgwa9asqTZJe7r0x5/f//73nTqN3qtXr+qbJw477LA8/fTT+da3vpWLL744yZtn5d4adsuXL6+exRsyZEjWr1+fP/zhD23O2i1fvjzjx49v9zkbGhrS0NCw2Xh9fX3q6+vbjNXW1m7xTRjt/TTZ3vifPi70FH/6vbml79WamprU1Gz+xvr2xts7brr6eOrIuH3aOfYJepruOp62uJZtnrmNWlpasnjx4nzta1/Lj370o4wbN+4dP2Zra2uampoyatSoDBkyJA8++GB12/r16/Ozn/2sGm2HHnpo6uvr28xZunRpnn322a2GHQDAzq7TZ+xqamq2+nEnra2t2W233fKNb3yjQ4/75S9/OZMnT87w4cOzdu3azJo1K48++mh+8pOfpFKpZNq0abnqqquy3377Zb/99stVV12VXXfdNX/913+dJOnfv3/OOeecTJ8+PQMHDsyAAQNy4YUXZsyYMdV3yQIAlKjTYXfkkUduMexqamqy++6757DDDsvZZ5+92Rsd3s4rr7ySqVOnZunSpenfv3/e+9735ic/+Uk+9KEPJUm++MUvZt26dfmHf/iH/OEPf8gHPvCBzJ49u/oZdkly/fXXp66uLqeffnrWrVuXY489NjNnzvQZdgBA0br0zRM7s8bGxvTv33+bLlR8J/a+5L4ue2zorBeumdLdS4At8ppJT9TVr5kdaRJ/KxYAoBDb5V2xc+bMybx586olecghh+Twww/fHg8NAMA2ekdh9+STT+bMM8/MggULkrz5holN193tt99+ue2227bLu2IBAHh7nQ673/3ud5k4cWJef/31TJo0KUcffXSGDBmSV155pfou1kmTJlX/xisAAF2r02F3+eWXZ/369XnggQeq71jd5Itf/GIeeuihTJkyJV/96lcza9asd7xQAAC2rtNvnnjkkUfysY99bLOo22TixIk59dRT2/ydPwAAuk6nw27NmjXZe++9tzpn1KhRWbNmTWefAgCADuh02A0bNixPPPHEVuc8+eSTGTZsWGefAgCADuh02J100kl59NFHM2PGjLzxxhtttr3xxhv5yle+kkceeSQnnXTSO14kAABvr9NvnpgxY0Z+/OMf56qrrsq//Mu/5P3vf38GDx6cV155JU8//XReffXV7LPPPpkxY8b2XC8AAO3odNgNGDAgTz75ZC666KLMmjUr999/f3Vb7969c/bZZ+frX/96BgwYsF0WCgDA1r2jDygeMGBAbr311nznO9/J//7v/6axsTH9+vXLAQcckPr6+u21RgAAtkGHw+7KK6/M66+/nssvv7wab/X19RkzZkx1zvr163PppZemb9++ueSSS7bfagEAaFeH3jzx0EMP5f/9v/+XgQMHbvWMXK9evTJw4MBceumlefjhh9/xIgEAeHsdCrvbb789u+++ez73uc+97dzPfvazGTBgQG677bZOLw4AgG3XobCbM2dOJk6cmIaGhred29DQkIkTJ2bOnDmdXhwAANuuQ2G3ZMmS7LPPPts8f9SoUVm6dGmHFwUAQMd1KOxqamrS3Ny8zfObm5tTU9Ppz0AGAKADOlRdw4YNy7PPPrvN85999tn8xV/8RYcXBQBAx3Uo7I444og8/PDDeeGFF9527gsvvJCHH344Rx55ZGfXBgBAB3Qo7D772c+mubk5H/vYx7JixYp2561cuTKnnXZaNmzYkL//+79/x4sEAODtdegDit/3vvdl2rRpueGGG3LggQfmM5/5TCZMmJC99torSfLyyy/npz/9ab773e/m1VdfzQUXXJD3ve99XbJwAADa6vBfnvjmN7+Z3r175xvf+EauvPLKXHnllW22t7a2pra2Nl/60pdyxRVXbLeFAgCwdR0Ou0qlkquuuirnnHNObrvttsyZMyfLli1LkgwZMiSHH354zjrrrOy7777bfbEAALSvw2G3yb777uuMHABAD+JD5gAACiHsAAAKIewAAAoh7AAACiHsAAAKIewAAAoh7AAACiHsAAAKIewAAAoh7AAACiHsAAAKIewAAAoh7AAACiHsAAAKIewAAAoh7AAACiHsAAAKIewAAAoh7AAACiHsAAAKIewAAAoh7AAACiHsAAAKIewAAAoh7AAACiHsAAAKIewAAAoh7AAACiHsAAAKIewAAAoh7AAACiHsAAAKIewAAAoh7AAACiHsAAAKIewAAAoh7AAACiHsAAAKIewAAAoh7AAACiHsAAAKIewAAAoh7AAACiHsAAAKIewAAAoh7AAACiHsAAAKIewAAAoh7AAACiHsAAAKIewAAAoh7AAACiHsAAAKIewAAAoh7AAACiHsAAAKIewAAAoh7AAACiHsAAAKIewAAAoh7AAACiHsAAAKIewAAAoh7AAACiHsAAAKIewAAAoh7AAACiHsAAAKIewAAAoh7AAACiHsAAAK0ePC7rHHHsuJJ56YYcOGpVKp5J577mmz/ayzzkqlUmnz9cEPfrDNnKamppx//vkZNGhQ+vTpk4985CN56aWXduBeAADseD0u7F5//fUcfPDB+fa3v93unOOPPz5Lly6tft1///1ttk+bNi133313Zs2alV/84hd57bXXcsIJJ2Tjxo1dvXwAgG5T190L+FOTJ0/O5MmTtzqnoaEhQ4YM2eK2NWvW5NZbb833v//9TJw4MUlyxx13ZPjw4XnooYcyadKk7b5mAICeoMedsdsWjz76aPbcc8+85z3vyac//eksX768um3u3Llpbm7OcccdVx0bNmxYRo8enTlz5nTHcgEAdoged8bu7UyePDmnnXZaRo4cmYULF2bGjBk55phjMnfu3DQ0NGTZsmXp1atXdt999zb3Gzx4cJYtW9bu4zY1NaWpqal6u7GxMUnS3Nyc5ubmJElNTU1qa2uzcePGtLS0VOduGt+wYUNaW1ur47W1tampqWl3fNPjQk+z6Xuzru7Nl4gNGza02V5fX5+WlpY2lzdUKpXU1dW1O97ecdNVx1N7a7dPO/c+QU+0I46nbbXThd3HP/7x6r9Hjx6dww47LCNHjsx9992XU045pd37tba2plKptLv96quvzuWXX77Z+OzZs7PrrrsmSUaMGJGxY8fmN7/5TRYtWlSds//+++eAAw7IU089lVdffbU6fsghh2TkyJF57LHHsnbt2ur4uHHjsueee2b27NnbttOwg226bvXDH/5w1q1bl0ceeaS6ra6uLlOmTMmKFSvyy1/+sjret2/fHHPMMVm8eHHmzZtXHd9jjz0yfvz4LFiwIM8991x1vCuOp7e++E2YMCG77LLLZtfg2qede5+gJ+rq4+nxxx/f5rVUWt+ahj1MpVLJ3XffnZNPPnmr8/bbb7+ce+65ufjii/Pwww/n2GOPzapVq9qctTv44INz8sknbzHeki2fsRs+fHhWrFiRfv36Jeman1z3myHu6HkWfO3NSxn+nM4E2aedY5+8ZtITPX/V5C49nlatWpWBAwdmzZo11SZpz07/48/KlSuzePHiDB06NEly6KGHpr6+Pg8++GBOP/30JMnSpUvz7LPP5tprr233cRoaGtLQ0LDZeH19ferr69uM1dbWpra2drO57f002d74nz4u9BR/+r25pe/Vmpqa1NRsfplue+PtHTddfTx1ZNw+7Rz7BD1Ndx1PW5y7zTN3kNdeey3/93//V729cOHCzJs3LwMGDMiAAQNy2WWX5dRTT83QoUPzwgsv5Mtf/nIGDRqUj370o0mS/v3755xzzsn06dMzcODADBgwIBdeeGHGjBlTfZcsAECJelzY/fd//3cmTJhQvX3BBRckSc4888zcdNNNmT9/fm6//fasXr06Q4cOzYQJE3LXXXelb9++1ftcf/31qaury+mnn55169bl2GOPzcyZM7dYxwAApehxYXf00Udna5f9PfDAA2/7GL17986NN96YG2+8cXsuDQCgR9spP8cOAIDNCTsAgEIIOwCAQgg7AIBCCDsAgEIIOwCAQgg7AIBCCDsAgEIIOwCAQgg7AIBCCDsAgEIIOwCAQgg7AIBCCDsAgEIIOwCAQgg7AIBCCDsAgEIIOwCAQgg7AIBCCDsAgEIIOwCAQgg7AIBCCDsAgEIIOwCAQgg7AIBCCDsAgEIIOwCAQgg7AIBCCDsAgEIIOwCAQgg7AIBCCDsAgEIIOwCAQgg7AIBCCDsAgEIIOwCAQgg7AIBCCDsAgEIIOwCAQgg7AIBCCDsAgEIIOwCAQgg7AIBCCDsAgEIIOwCAQgg7AIBCCDsAgEIIOwCAQgg7AIBCCDsAgEIIOwCAQgg7AIBCCDsAgEIIOwCAQgg7AIBCCDsAgEIIOwCAQgg7AIBCCDsAgEIIOwCAQgg7AIBCCDsAgEIIOwCAQgg7AIBCCDsAgEIIOwCAQgg7AIBCCDsAgEIIOwCAQgg7AIBCCDsAgEIIOwCAQgg7AIBCCDsAgEIIOwCAQgg7AIBCCDsAgEIIOwCAQgg7AIBCCDsAgEIIOwCAQgg7AIBCCDsAgEIIOwCAQgg7AIBCCDsAgEIIOwCAQgg7AIBCCDsAgEIIOwCAQgg7AIBCCDsAgEIIOwCAQgg7AIBCCDsAgEIIOwCAQgg7AIBCFB12//zP/5xRo0ald+/eOfTQQ/Pzn/+8u5cEANBlig27u+66K9OmTcull16aZ555JkcccUQmT56cRYsWdffSAAC6RLFhd9111+Wcc87Jueeem7/8y7/MDTfckOHDh+emm27q7qUBAHSJuu5eQFdYv3595s6dm0suuaTN+HHHHZc5c+Zs8T5NTU1pamqq3l6zZk2SZNWqVWlubk6S1NTUpLa2Nhs3bkxLS0t17qbxDRs2pLW1tTpeW1ubmpqadsebm5vT0vTHd77DsJ2tXLkySVJX9+ZLxIYNG9psr6+vT0tLSzZu3Fgdq1Qqqaura3e8veNmex5Pb9Xe2u3Tzr1PXjPpiVavXt2lx9OqVauSpM229hQZditWrMjGjRszePDgNuODBw/OsmXLtnifq6++Opdffvlm46NGjeqSNUJPNuiG7l4BwM5j9xt2zPOsXbs2/fv33+qcIsNuk0ql0uZ2a2vrZmObfOlLX8oFF1xQvd3S0pJVq1Zl4MCB7d6HnqOxsTHDhw/P4sWL069fv+5eDkCP5jVz59La2pq1a9dm2LBhbzu3yLAbNGhQamtrNzs7t3z58s3O4m3S0NCQhoaGNmO77bZbVy2RLtKvXz8vUgDbyGvmzuPtztRtUuSbJ3r16pVDDz00Dz74YJvxBx98MOPHj++mVQEAdK0iz9glyQUXXJCpU6fmsMMOy7hx4/Ld7343ixYtymc+85nuXhoAQJcoNuw+/vGPZ+XKlfnqV7+apUuXZvTo0bn//vszcuTI7l4aXaChoSFf+cpXNvt1OgCb85pZrkrrtrx3FgCAHq/Ia+wAAP4cCTsAgEIIOwCAQgg7AIBCCDsAgEIIO4qzYMGCvPLKK929DADY4Yr9HDv+vCxfvjzf//73c/3112fIkCGpqanJkCFD8rGPfSynnnpq+vTp091LBIAu53PsKMKZZ56Z5557LieccEIGDRqUVatW5Zlnnslvf/vbDBs2LBdddFGOO+647l4mQI+xbt267LLLLt29DLYzYcdOr7W1NX379s3999+fI488sjr28ssv56mnnsqtt96a559/Pv/6r/+aQw45pHsXC9BDTJ8+PYcffngOPfTQDBkyZIt/hWLlypUZOHBgN6yOznKNHTu93/72txk1alSbF6VKpZK99torp5xySu6+++707ds3d911VzeuEqDnuPPOO3P99dfnjDPOyIQJE/KlL30pjzzySJYvX54NGzYkSV5//fWcc845mT9/fjevlo5wxo6d3rp163LiiSfmjTfeyO2335699947NTVtf2b59re/nVtuuSXz5s3rnkUC9CDnnntuevXqlenTp2fWrFm55ZZb8uKLL2bs2LE57bTTMmnSpMybNy9/93d/l+bm5u5eLh3gjB07vV122SVXXHFFXnvttUydOjV33nlnli5dmnXr1iV5M/x+9rOfZfTo0d28UoDut2HDhuyzzz7Zbbfdsu++++bSSy/NwoULM2/evBx22GG55pprcuSRR+a8887L1KlTu3u5dJAzdhRj/vz5ueKKK3LvvffmXe96Vw4//PDsueeeeeCBBzJkyJDccsstGTNmTHcvE6DbrV69Oq+88kr233//rF+/PvX19alUKtXtP/jBDzJ16tQ888wzOfjgg7txpXSUsKM4y5cvz49//OP86Ec/Su/evTN69OicdtppOeCAA7p7aQA9VktLS1pbW1NbW5ubb745X/jCF/LHP/6xu5dFBwk7itbS0rLZ9XYAbN11112XjRs35qKLLurupdBBwg4AaKO5uTm1tbV+MN4JCTsAgEJIcQCAQgg7AIBCCDsAgEIIOwCAQgg7AIBCCDsAgEIIOwCAQgg7AIBCCDsAgEL8f5mZu35VnwvmAAAAAElFTkSuQmCC", + "text/plain": [ + "
" + ] + }, + "execution_count": 34, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "qc = QuantumCircuit(2,1)\n", + "qc.h(0)\n", + "qc.x(0)\n", + "qc.cx(0,1)\n", + "qc.measure(0,0)\n", + "qc.draw()\n", + "\n", + "backend = AerSimulator()\n", + "job = backend.run(qc, shots = 1056)\n", + "output = job.result()\n", + "counts = output.get_counts()\n", + "plot_histogram(counts)" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "This implementation of NOT gate was an example of what you will need to do for a range of other gates below." + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "

📓(a) XOR gate

\n", + "\n", + "Takes two binary strings as input and gives one as output.\n", + "\n", + "The output is '0' when the inputs are equal and '1' otherwise." + ] + }, + { + "cell_type": "code", + "execution_count": 35, + "metadata": {}, + "outputs": [], + "source": [ + "### BEGIN SOLUTION\n", + "def XOR(inp1,inp2):\n", + " \"\"\"An XOR gate.\n", + " \n", + " Parameters:\n", + " inpt1 (str): Input 1, encoded in qubit 0.\n", + " inpt2 (str): Input 2, encoded in qubit 1.\n", + " \n", + " Returns:\n", + " QuantumCircuit: Output XOR circuit.\n", + " str: Output value measured from qubit 1.\n", + " \"\"\"\n", + " \n", + " qc = QuantumCircuit(2, 1) \n", + " qc.reset(range(2))\n", + " \n", + " if inp1=='1':\n", + " qc.x(0)\n", + " if inp2=='1':\n", + " qc.x(1)\n", + " \n", + " # barrier between input state and gate operation \n", + " qc.barrier()\n", + " \n", + " # this is where your program for quantum XOR gate goes\n", + " \n", + " qc.cx(0,1)\n", + " \n", + " \n", + " # barrier between input state and gate operation \n", + " qc.barrier()\n", + " \n", + " qc.measure(1,0) # output from qubit 1 is measured\n", + " \n", + " #We'll run the program on a simulator\n", + " backend = AerSimulator()\n", + " #Since the output will be deterministic, we can use just a single shot to get it\n", + " job = backend.run(qc, shots=1, memory=True)\n", + " output = job.result().get_memory()[0]\n", + " \n", + " return qc, output\n", + "### END SOLUTION" + ] + }, + { + "cell_type": "code", + "execution_count": 36, + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "'0'" + ] + }, + "execution_count": 36, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "XOR('0','0')[1]\n" + ] + }, + { + "cell_type": "code", + "execution_count": 37, + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "XOR with inputs 0 0 gives output 0\n" + ] + }, + { + "data": { + "text/html": [ + "
           ░       ░    \n",
+       "q_0: ─|0>──░───■───░────\n",
+       "           ░ ┌─┴─┐ ░ ┌─┐\n",
+       "q_1: ─|0>──░─┤ X ├─░─┤M├\n",
+       "           ░ └───┘ ░ └╥┘\n",
+       "c: 1/═════════════════╩═\n",
+       "                      0 
" + ], + "text/plain": [ + " ░ ░ \n", + "q_0: ─|0>──░───■───░────\n", + " ░ ┌─┴─┐ ░ ┌─┐\n", + "q_1: ─|0>──░─┤ X ├─░─┤M├\n", + " ░ └───┘ ░ └╥┘\n", + "c: 1/═════════════════╩═\n", + " 0 " + ] + }, + "metadata": {}, + "output_type": "display_data" + }, + { + "name": "stdout", + "output_type": "stream", + "text": [ + "\n", + "\n", + "XOR with inputs 0 1 gives output 1\n" + ] + }, + { + "data": { + "text/html": [ + "
                ░       ░    \n",
+       "q_0: ─|0>───────░───■───░────\n",
+       "          ┌───┐ ░ ┌─┴─┐ ░ ┌─┐\n",
+       "q_1: ─|0>─┤ X ├─░─┤ X ├─░─┤M├\n",
+       "          └───┘ ░ └───┘ ░ └╥┘\n",
+       "c: 1/══════════════════════╩═\n",
+       "                           0 
" + ], + "text/plain": [ + " ░ ░ \n", + "q_0: ─|0>───────░───■───░────\n", + " ┌───┐ ░ ┌─┴─┐ ░ ┌─┐\n", + "q_1: ─|0>─┤ X ├─░─┤ X ├─░─┤M├\n", + " └───┘ ░ └───┘ ░ └╥┘\n", + "c: 1/══════════════════════╩═\n", + " 0 " + ] + }, + "metadata": {}, + "output_type": "display_data" + }, + { + "name": "stdout", + "output_type": "stream", + "text": [ + "\n", + "\n", + "XOR with inputs 1 0 gives output 1\n" + ] + }, + { + "data": { + "text/html": [ + "
          ┌───┐ ░       ░    \n",
+       "q_0: ─|0>─┤ X ├─░───■───░────\n",
+       "          └───┘ ░ ┌─┴─┐ ░ ┌─┐\n",
+       "q_1: ─|0>───────░─┤ X ├─░─┤M├\n",
+       "                ░ └───┘ ░ └╥┘\n",
+       "c: 1/══════════════════════╩═\n",
+       "                           0 
" + ], + "text/plain": [ + " ┌───┐ ░ ░ \n", + "q_0: ─|0>─┤ X ├─░───■───░────\n", + " └───┘ ░ ┌─┴─┐ ░ ┌─┐\n", + "q_1: ─|0>───────░─┤ X ├─░─┤M├\n", + " ░ └───┘ ░ └╥┘\n", + "c: 1/══════════════════════╩═\n", + " 0 " + ] + }, + "metadata": {}, + "output_type": "display_data" + }, + { + "name": "stdout", + "output_type": "stream", + "text": [ + "\n", + "\n", + "XOR with inputs 1 1 gives output 0\n" + ] + }, + { + "data": { + "text/html": [ + "
          ┌───┐ ░       ░    \n",
+       "q_0: ─|0>─┤ X ├─░───■───░────\n",
+       "          ├───┤ ░ ┌─┴─┐ ░ ┌─┐\n",
+       "q_1: ─|0>─┤ X ├─░─┤ X ├─░─┤M├\n",
+       "          └───┘ ░ └───┘ ░ └╥┘\n",
+       "c: 1/══════════════════════╩═\n",
+       "                           0 
" + ], + "text/plain": [ + " ┌───┐ ░ ░ \n", + "q_0: ─|0>─┤ X ├─░───■───░────\n", + " ├───┤ ░ ┌─┴─┐ ░ ┌─┐\n", + "q_1: ─|0>─┤ X ├─░─┤ X ├─░─┤M├\n", + " └───┘ ░ └───┘ ░ └╥┘\n", + "c: 1/══════════════════════╩═\n", + " 0 " + ] + }, + "metadata": {}, + "output_type": "display_data" + }, + { + "name": "stdout", + "output_type": "stream", + "text": [ + "\n", + "\n", + "✅ All XOR gate tests passed.\n" + ] + } + ], + "source": [ + "## Test the function\n", + "for inp1 in ['0', '1']:\n", + " for inp2 in ['0', '1']:\n", + " qc, output = XOR(inp1, inp2)\n", + " print('XOR with inputs',inp1,inp2,'gives output',output)\n", + " display(qc.draw())\n", + " print('\\n')\n", + "\n", + "test_xor(XOR) # DO NOT EDIT THIS LINE" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "

📓 (b) AND gate

\n", + "\n", + "Takes two binary strings as input and gives one as output.\n", + "\n", + "The output is `'1'` only when both the inputs are `'1'`." + ] + }, + { + "cell_type": "code", + "execution_count": 38, + "metadata": {}, + "outputs": [], + "source": [ + "### BEGIN SOLUTION\n", + "\n", + "def AND(inp1,inp2):\n", + " \"\"\"An AND gate.\n", + " \n", + " Parameters:\n", + " inpt1 (str): Input 1, encoded in qubit 0.\n", + " inpt2 (str): Input 2, encoded in qubit 1.\n", + " \n", + " Returns:\n", + " QuantumCircuit: Output XOR circuit.\n", + " str: Output value measured from qubit 2.\n", + " \"\"\"\n", + " qc = QuantumCircuit(3, 1) \n", + " qc.reset(range(2))\n", + " \n", + " if inp1=='1':\n", + " qc.x(0)\n", + " if inp2=='1':\n", + " qc.x(1)\n", + " \n", + " qc.barrier()\n", + "\n", + " # this is where your program for quantum AND gate goes\n", + "\n", + " \n", + " \n", + " qc.ccx(0,1,2)\n", + " \n", + " \n", + "\n", + " qc.barrier()\n", + " qc.measure(2, 0) # output from qubit 2 is measured\n", + " \n", + " # We'll run the program on a simulator\n", + " backend = AerSimulator()\n", + " #Since the output will be deterministic, we can use just a single shot to get it\n", + " job = backend.run(qc, shots=1, memory=True)\n", + " output = job.result().get_memory()[0]\n", + " \n", + " return qc, output\n", + " # Test AND gate outputs using assert statements\n", + "### END SOLUTION" + ] + }, + { + "cell_type": "code", + "execution_count": 39, + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "'0'" + ] + }, + "execution_count": 39, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "AND('0','0')[1]" + ] + }, + { + "cell_type": "code", + "execution_count": 40, + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "AND with inputs 0 0 gives output 0\n" + ] + }, + { + "data": { + "text/html": [ + "
           ░       ░    \n",
+       "q_0: ─|0>──░───■───░────\n",
+       "           ░   │   ░    \n",
+       "q_1: ─|0>──░───■───░────\n",
+       "           ░ ┌─┴─┐ ░ ┌─┐\n",
+       "q_2: ──────░─┤ X ├─░─┤M├\n",
+       "           ░ └───┘ ░ └╥┘\n",
+       "c: 1/═════════════════╩═\n",
+       "                      0 
" + ], + "text/plain": [ + " ░ ░ \n", + "q_0: ─|0>──░───■───░────\n", + " ░ │ ░ \n", + "q_1: ─|0>──░───■───░────\n", + " ░ ┌─┴─┐ ░ ┌─┐\n", + "q_2: ──────░─┤ X ├─░─┤M├\n", + " ░ └───┘ ░ └╥┘\n", + "c: 1/═════════════════╩═\n", + " 0 " + ] + }, + "metadata": {}, + "output_type": "display_data" + }, + { + "name": "stdout", + "output_type": "stream", + "text": [ + "\n", + "\n", + "AND with inputs 0 1 gives output 0\n" + ] + }, + { + "data": { + "text/html": [ + "
                ░       ░    \n",
+       "q_0: ─|0>───────░───■───░────\n",
+       "          ┌───┐ ░   │   ░    \n",
+       "q_1: ─|0>─┤ X ├─░───■───░────\n",
+       "          └───┘ ░ ┌─┴─┐ ░ ┌─┐\n",
+       "q_2: ───────────░─┤ X ├─░─┤M├\n",
+       "                ░ └───┘ ░ └╥┘\n",
+       "c: 1/══════════════════════╩═\n",
+       "                           0 
" + ], + "text/plain": [ + " ░ ░ \n", + "q_0: ─|0>───────░───■───░────\n", + " ┌───┐ ░ │ ░ \n", + "q_1: ─|0>─┤ X ├─░───■───░────\n", + " └───┘ ░ ┌─┴─┐ ░ ┌─┐\n", + "q_2: ───────────░─┤ X ├─░─┤M├\n", + " ░ └───┘ ░ └╥┘\n", + "c: 1/══════════════════════╩═\n", + " 0 " + ] + }, + "metadata": {}, + "output_type": "display_data" + }, + { + "name": "stdout", + "output_type": "stream", + "text": [ + "\n", + "\n", + "AND with inputs 1 0 gives output 0\n" + ] + }, + { + "data": { + "text/html": [ + "
          ┌───┐ ░       ░    \n",
+       "q_0: ─|0>─┤ X ├─░───■───░────\n",
+       "          └───┘ ░   │   ░    \n",
+       "q_1: ─|0>───────░───■───░────\n",
+       "                ░ ┌─┴─┐ ░ ┌─┐\n",
+       "q_2: ───────────░─┤ X ├─░─┤M├\n",
+       "                ░ └───┘ ░ └╥┘\n",
+       "c: 1/══════════════════════╩═\n",
+       "                           0 
" + ], + "text/plain": [ + " ┌───┐ ░ ░ \n", + "q_0: ─|0>─┤ X ├─░───■───░────\n", + " └───┘ ░ │ ░ \n", + "q_1: ─|0>───────░───■───░────\n", + " ░ ┌─┴─┐ ░ ┌─┐\n", + "q_2: ───────────░─┤ X ├─░─┤M├\n", + " ░ └───┘ ░ └╥┘\n", + "c: 1/══════════════════════╩═\n", + " 0 " + ] + }, + "metadata": {}, + "output_type": "display_data" + }, + { + "name": "stdout", + "output_type": "stream", + "text": [ + "\n", + "\n", + "AND with inputs 1 1 gives output 1\n" + ] + }, + { + "data": { + "text/html": [ + "
          ┌───┐ ░       ░    \n",
+       "q_0: ─|0>─┤ X ├─░───■───░────\n",
+       "          ├───┤ ░   │   ░    \n",
+       "q_1: ─|0>─┤ X ├─░───■───░────\n",
+       "          └───┘ ░ ┌─┴─┐ ░ ┌─┐\n",
+       "q_2: ───────────░─┤ X ├─░─┤M├\n",
+       "                ░ └───┘ ░ └╥┘\n",
+       "c: 1/══════════════════════╩═\n",
+       "                           0 
" + ], + "text/plain": [ + " ┌───┐ ░ ░ \n", + "q_0: ─|0>─┤ X ├─░───■───░────\n", + " ├───┤ ░ │ ░ \n", + "q_1: ─|0>─┤ X ├─░───■───░────\n", + " └───┘ ░ ┌─┴─┐ ░ ┌─┐\n", + "q_2: ───────────░─┤ X ├─░─┤M├\n", + " ░ └───┘ ░ └╥┘\n", + "c: 1/══════════════════════╩═\n", + " 0 " + ] + }, + "metadata": {}, + "output_type": "display_data" + }, + { + "name": "stdout", + "output_type": "stream", + "text": [ + "\n", + "\n", + "✅ All AND gate tests passed.\n" + ] + } + ], + "source": [ + "## Test the function\n", + "for inp1 in ['0', '1']:\n", + " for inp2 in ['0', '1']:\n", + " qc, output = AND(inp1, inp2)\n", + " print('AND with inputs',inp1,inp2,'gives output',output)\n", + " display(qc.draw())\n", + " print('\\n')\n", + "\n", + "test_and(AND) # DO NOT EDIT THIS LINE" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "

📓 NAND gate

\n", + "\n", + "Takes two binary strings as input and gives one as output.\n", + "\n", + "The output is `'0'` only when both the inputs are `'1'`." + ] + }, + { + "cell_type": "code", + "execution_count": 41, + "metadata": {}, + "outputs": [], + "source": [ + "### BEGIN SOLUTION\n", + "def NAND(inp1,inp2):\n", + " \"\"\"An NAND gate.\n", + " \n", + " Parameters:\n", + " inpt1 (str): Input 1, encoded in qubit 0.\n", + " inpt2 (str): Input 2, encoded in qubit 1.\n", + " \n", + " Returns:\n", + " QuantumCircuit: Output NAND circuit.\n", + " str: Output value measured from qubit 2.\n", + " \"\"\"\n", + " qc = QuantumCircuit(3, 1) \n", + " qc.reset(range(3))\n", + " \n", + " if inp1=='1':\n", + " qc.x(0)\n", + " if inp2=='1':\n", + " qc.x(1)\n", + " \n", + " qc.barrier()\n", + " \n", + " # this is where your program for quantum NAND gate goes\n", + "\n", + "\n", + " qc.ccx(0, 1, 2)\n", + " qc.x(2)\n", + " \n", + " \n", + " \n", + " qc.barrier()\n", + " qc.measure(2, 0) # output from qubit 2 is measured\n", + " \n", + " # We'll run the program on a simulator\n", + " backend = AerSimulator()\n", + " #Since the output will be deterministic, we can use just a single shot to get it\n", + " job = backend.run(qc, shots=1, memory=True)\n", + " output = job.result().get_memory()[0]\n", + " \n", + " return qc, output\n", + " # Test NAND gate outputs using assert statements\n", + "### END SOLUTION" + ] + }, + { + "cell_type": "code", + "execution_count": 42, + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "'1'" + ] + }, + "execution_count": 42, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "NAND('1','0')[1]" + ] + }, + { + "cell_type": "code", + "execution_count": 43, + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "NAND with inputs 0 0 gives output 1\n" + ] + }, + { + "data": { + "text/html": [ + "
           ░            ░    \n",
+       "q_0: ─|0>──░───■────────░────\n",
+       "           ░   │        ░    \n",
+       "q_1: ─|0>──░───■────────░────\n",
+       "           ░ ┌─┴─┐┌───┐ ░ ┌─┐\n",
+       "q_2: ─|0>──░─┤ X ├┤ X ├─░─┤M├\n",
+       "           ░ └───┘└───┘ ░ └╥┘\n",
+       "c: 1/══════════════════════╩═\n",
+       "                           0 
" + ], + "text/plain": [ + " ░ ░ \n", + "q_0: ─|0>──░───■────────░────\n", + " ░ │ ░ \n", + "q_1: ─|0>──░───■────────░────\n", + " ░ ┌─┴─┐┌───┐ ░ ┌─┐\n", + "q_2: ─|0>──░─┤ X ├┤ X ├─░─┤M├\n", + " ░ └───┘└───┘ ░ └╥┘\n", + "c: 1/══════════════════════╩═\n", + " 0 " + ] + }, + "metadata": {}, + "output_type": "display_data" + }, + { + "name": "stdout", + "output_type": "stream", + "text": [ + "\n", + "\n", + "NAND with inputs 0 1 gives output 1\n" + ] + }, + { + "data": { + "text/html": [ + "
                ░            ░    \n",
+       "q_0: ─|0>───────░───■────────░────\n",
+       "          ┌───┐ ░   │        ░    \n",
+       "q_1: ─|0>─┤ X ├─░───■────────░────\n",
+       "          └───┘ ░ ┌─┴─┐┌───┐ ░ ┌─┐\n",
+       "q_2: ─|0>───────░─┤ X ├┤ X ├─░─┤M├\n",
+       "                ░ └───┘└───┘ ░ └╥┘\n",
+       "c: 1/═══════════════════════════╩═\n",
+       "                                0 
" + ], + "text/plain": [ + " ░ ░ \n", + "q_0: ─|0>───────░───■────────░────\n", + " ┌───┐ ░ │ ░ \n", + "q_1: ─|0>─┤ X ├─░───■────────░────\n", + " └───┘ ░ ┌─┴─┐┌───┐ ░ ┌─┐\n", + "q_2: ─|0>───────░─┤ X ├┤ X ├─░─┤M├\n", + " ░ └───┘└───┘ ░ └╥┘\n", + "c: 1/═══════════════════════════╩═\n", + " 0 " + ] + }, + "metadata": {}, + "output_type": "display_data" + }, + { + "name": "stdout", + "output_type": "stream", + "text": [ + "\n", + "\n", + "NAND with inputs 1 0 gives output 1\n" + ] + }, + { + "data": { + "text/html": [ + "
          ┌───┐ ░            ░    \n",
+       "q_0: ─|0>─┤ X ├─░───■────────░────\n",
+       "          └───┘ ░   │        ░    \n",
+       "q_1: ─|0>───────░───■────────░────\n",
+       "                ░ ┌─┴─┐┌───┐ ░ ┌─┐\n",
+       "q_2: ─|0>───────░─┤ X ├┤ X ├─░─┤M├\n",
+       "                ░ └───┘└───┘ ░ └╥┘\n",
+       "c: 1/═══════════════════════════╩═\n",
+       "                                0 
" + ], + "text/plain": [ + " ┌───┐ ░ ░ \n", + "q_0: ─|0>─┤ X ├─░───■────────░────\n", + " └───┘ ░ │ ░ \n", + "q_1: ─|0>───────░───■────────░────\n", + " ░ ┌─┴─┐┌───┐ ░ ┌─┐\n", + "q_2: ─|0>───────░─┤ X ├┤ X ├─░─┤M├\n", + " ░ └───┘└───┘ ░ └╥┘\n", + "c: 1/═══════════════════════════╩═\n", + " 0 " + ] + }, + "metadata": {}, + "output_type": "display_data" + }, + { + "name": "stdout", + "output_type": "stream", + "text": [ + "\n", + "\n", + "NAND with inputs 1 1 gives output 0\n" + ] + }, + { + "data": { + "text/html": [ + "
          ┌───┐ ░            ░    \n",
+       "q_0: ─|0>─┤ X ├─░───■────────░────\n",
+       "          ├───┤ ░   │        ░    \n",
+       "q_1: ─|0>─┤ X ├─░───■────────░────\n",
+       "          └───┘ ░ ┌─┴─┐┌───┐ ░ ┌─┐\n",
+       "q_2: ─|0>───────░─┤ X ├┤ X ├─░─┤M├\n",
+       "                ░ └───┘└───┘ ░ └╥┘\n",
+       "c: 1/═══════════════════════════╩═\n",
+       "                                0 
" + ], + "text/plain": [ + " ┌───┐ ░ ░ \n", + "q_0: ─|0>─┤ X ├─░───■────────░────\n", + " ├───┤ ░ │ ░ \n", + "q_1: ─|0>─┤ X ├─░───■────────░────\n", + " └───┘ ░ ┌─┴─┐┌───┐ ░ ┌─┐\n", + "q_2: ─|0>───────░─┤ X ├┤ X ├─░─┤M├\n", + " ░ └───┘└───┘ ░ └╥┘\n", + "c: 1/═══════════════════════════╩═\n", + " 0 " + ] + }, + "metadata": {}, + "output_type": "display_data" + }, + { + "name": "stdout", + "output_type": "stream", + "text": [ + "\n", + "\n", + "✅ All NAND gate tests passed.\n" + ] + } + ], + "source": [ + "## Test the function\n", + "for inp1 in ['0', '1']:\n", + " for inp2 in ['0', '1']:\n", + " qc, output = NAND(inp1, inp2)\n", + " print('NAND with inputs',inp1,inp2,'gives output',output)\n", + " display(qc.draw())\n", + " print('\\n')\n", + "\n", + "test_nand(NAND) # DO NOT EDIT THIS LINE" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "

📓 OR gate

\n", + "\n", + "Takes two binary strings as input and gives one as output.\n", + "\n", + "The output is '1' if either input is '1'." + ] + }, + { + "cell_type": "code", + "execution_count": 44, + "metadata": {}, + "outputs": [], + "source": [ + "### BEGIN SOLUTION\n", + "def OR(inp1,inp2):\n", + " \"\"\"An OR gate.\n", + " \n", + " Parameters:\n", + " inpt1 (str): Input 1, encoded in qubit 0.\n", + " inpt2 (str): Input 2, encoded in qubit 1.\n", + " \n", + " Returns:\n", + " QuantumCircuit: Output XOR circuit.\n", + " str: Output value measured from qubit 2.\n", + " \"\"\"\n", + "\n", + " qc = QuantumCircuit(3, 1) \n", + " qc.reset(range(3))\n", + " \n", + " if inp1=='1':\n", + " qc.x(0)\n", + " if inp2=='1':\n", + " qc.x(1)\n", + " \n", + " qc.barrier()\n", + " \n", + " # this is where your program for quantum OR gate goes\n", + " \n", + " qc.x(0)\n", + " qc.x(1)\n", + " qc.ccx(0,1,2)\n", + " qc.x(2) \n", + " \n", + " \n", + " \n", + " \n", + " qc.barrier()\n", + " qc.measure(2, 0) # output from qubit 2 is measured\n", + " \n", + " # We'll run the program on a simulator\n", + " backend = AerSimulator()\n", + " #Since the output will be deterministic, we can use just a single shot to get it\n", + " job = backend.run(qc, shots=1, memory=True)\n", + " output = job.result().get_memory()[0]\n", + " \n", + " return qc, output\n", + "### END SOLUTION" + ] + }, + { + "cell_type": "code", + "execution_count": 45, + "metadata": {}, + "outputs": [ + { + "data": { + "text/html": [ + "
          ┌───┐ ░ ┌───┐           ░    \n",
+       "q_0: ─|0>─┤ X ├─░─┤ X ├──■────────░────\n",
+       "          └───┘ ░ ├───┤  │        ░    \n",
+       "q_1: ─|0>───────░─┤ X ├──■────────░────\n",
+       "                ░ └───┘┌─┴─┐┌───┐ ░ ┌─┐\n",
+       "q_2: ─|0>───────░──────┤ X ├┤ X ├─░─┤M├\n",
+       "                ░      └───┘└───┘ ░ └╥┘\n",
+       "c: 1/════════════════════════════════╩═\n",
+       "                                     0 
" + ], + "text/plain": [ + " ┌───┐ ░ ┌───┐ ░ \n", + "q_0: ─|0>─┤ X ├─░─┤ X ├──■────────░────\n", + " └───┘ ░ ├───┤ │ ░ \n", + "q_1: ─|0>───────░─┤ X ├──■────────░────\n", + " ░ └───┘┌─┴─┐┌───┐ ░ ┌─┐\n", + "q_2: ─|0>───────░──────┤ X ├┤ X ├─░─┤M├\n", + " ░ └───┘└───┘ ░ └╥┘\n", + "c: 1/════════════════════════════════╩═\n", + " 0 " + ] + }, + "execution_count": 45, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "OR('1','0')[0].draw()" + ] + }, + { + "cell_type": "code", + "execution_count": 46, + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "OR with inputs 0 0 gives output 0\n" + ] + }, + { + "data": { + "text/html": [ + "
           ░ ┌───┐           ░    \n",
+       "q_0: ─|0>──░─┤ X ├──■────────░────\n",
+       "           ░ ├───┤  │        ░    \n",
+       "q_1: ─|0>──░─┤ X ├──■────────░────\n",
+       "           ░ └───┘┌─┴─┐┌───┐ ░ ┌─┐\n",
+       "q_2: ─|0>──░──────┤ X ├┤ X ├─░─┤M├\n",
+       "           ░      └───┘└───┘ ░ └╥┘\n",
+       "c: 1/═══════════════════════════╩═\n",
+       "                                0 
" + ], + "text/plain": [ + " ░ ┌───┐ ░ \n", + "q_0: ─|0>──░─┤ X ├──■────────░────\n", + " ░ ├───┤ │ ░ \n", + "q_1: ─|0>──░─┤ X ├──■────────░────\n", + " ░ └───┘┌─┴─┐┌───┐ ░ ┌─┐\n", + "q_2: ─|0>──░──────┤ X ├┤ X ├─░─┤M├\n", + " ░ └───┘└───┘ ░ └╥┘\n", + "c: 1/═══════════════════════════╩═\n", + " 0 " + ] + }, + "metadata": {}, + "output_type": "display_data" + }, + { + "name": "stdout", + "output_type": "stream", + "text": [ + "\n", + "\n", + "OR with inputs 0 1 gives output 1\n" + ] + }, + { + "data": { + "text/html": [ + "
                ░ ┌───┐           ░    \n",
+       "q_0: ─|0>───────░─┤ X ├──■────────░────\n",
+       "          ┌───┐ ░ ├───┤  │        ░    \n",
+       "q_1: ─|0>─┤ X ├─░─┤ X ├──■────────░────\n",
+       "          └───┘ ░ └───┘┌─┴─┐┌───┐ ░ ┌─┐\n",
+       "q_2: ─|0>───────░──────┤ X ├┤ X ├─░─┤M├\n",
+       "                ░      └───┘└───┘ ░ └╥┘\n",
+       "c: 1/════════════════════════════════╩═\n",
+       "                                     0 
" + ], + "text/plain": [ + " ░ ┌───┐ ░ \n", + "q_0: ─|0>───────░─┤ X ├──■────────░────\n", + " ┌───┐ ░ ├───┤ │ ░ \n", + "q_1: ─|0>─┤ X ├─░─┤ X ├──■────────░────\n", + " └───┘ ░ └───┘┌─┴─┐┌───┐ ░ ┌─┐\n", + "q_2: ─|0>───────░──────┤ X ├┤ X ├─░─┤M├\n", + " ░ └───┘└───┘ ░ └╥┘\n", + "c: 1/════════════════════════════════╩═\n", + " 0 " + ] + }, + "metadata": {}, + "output_type": "display_data" + }, + { + "name": "stdout", + "output_type": "stream", + "text": [ + "\n", + "\n", + "OR with inputs 1 0 gives output 1\n" + ] + }, + { + "data": { + "text/html": [ + "
          ┌───┐ ░ ┌───┐           ░    \n",
+       "q_0: ─|0>─┤ X ├─░─┤ X ├──■────────░────\n",
+       "          └───┘ ░ ├───┤  │        ░    \n",
+       "q_1: ─|0>───────░─┤ X ├──■────────░────\n",
+       "                ░ └───┘┌─┴─┐┌───┐ ░ ┌─┐\n",
+       "q_2: ─|0>───────░──────┤ X ├┤ X ├─░─┤M├\n",
+       "                ░      └───┘└───┘ ░ └╥┘\n",
+       "c: 1/════════════════════════════════╩═\n",
+       "                                     0 
" + ], + "text/plain": [ + " ┌───┐ ░ ┌───┐ ░ \n", + "q_0: ─|0>─┤ X ├─░─┤ X ├──■────────░────\n", + " └───┘ ░ ├───┤ │ ░ \n", + "q_1: ─|0>───────░─┤ X ├──■────────░────\n", + " ░ └───┘┌─┴─┐┌───┐ ░ ┌─┐\n", + "q_2: ─|0>───────░──────┤ X ├┤ X ├─░─┤M├\n", + " ░ └───┘└───┘ ░ └╥┘\n", + "c: 1/════════════════════════════════╩═\n", + " 0 " + ] + }, + "metadata": {}, + "output_type": "display_data" + }, + { + "name": "stdout", + "output_type": "stream", + "text": [ + "\n", + "\n", + "OR with inputs 1 1 gives output 1\n" + ] + }, + { + "data": { + "text/html": [ + "
          ┌───┐ ░ ┌───┐           ░    \n",
+       "q_0: ─|0>─┤ X ├─░─┤ X ├──■────────░────\n",
+       "          ├───┤ ░ ├───┤  │        ░    \n",
+       "q_1: ─|0>─┤ X ├─░─┤ X ├──■────────░────\n",
+       "          └───┘ ░ └───┘┌─┴─┐┌───┐ ░ ┌─┐\n",
+       "q_2: ─|0>───────░──────┤ X ├┤ X ├─░─┤M├\n",
+       "                ░      └───┘└───┘ ░ └╥┘\n",
+       "c: 1/════════════════════════════════╩═\n",
+       "                                     0 
" + ], + "text/plain": [ + " ┌───┐ ░ ┌───┐ ░ \n", + "q_0: ─|0>─┤ X ├─░─┤ X ├──■────────░────\n", + " ├───┤ ░ ├───┤ │ ░ \n", + "q_1: ─|0>─┤ X ├─░─┤ X ├──■────────░────\n", + " └───┘ ░ └───┘┌─┴─┐┌───┐ ░ ┌─┐\n", + "q_2: ─|0>───────░──────┤ X ├┤ X ├─░─┤M├\n", + " ░ └───┘└───┘ ░ └╥┘\n", + "c: 1/════════════════════════════════╩═\n", + " 0 " + ] + }, + "metadata": {}, + "output_type": "display_data" + }, + { + "name": "stdout", + "output_type": "stream", + "text": [ + "\n", + "\n", + "✅ All OR gate tests passed.\n" + ] + } + ], + "source": [ + "## Test the function\n", + "for inp1 in ['0', '1']:\n", + " for inp2 in ['0', '1']:\n", + " qc, output = OR(inp1, inp2)\n", + " print('OR with inputs',inp1,inp2,'gives output',output)\n", + " display(qc.draw())\n", + " print('\\n')\n", + "\n", + "test_or(OR) # DO NOT EDIT THIS LINE" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "

Part 2: AND gate on Quantum Computer

\n", + "
\n", + "\n", + "Real quantum computers are not able to implement arbitary gates directly. Instead, everything needs to be compiled (or 'transpiled') to the set of basic gates that the device can use. This usually consists of a set of single qubit rotations, as well as two qubit gates like `cx`.\n", + "\n", + "There are also limits on which `cx` gates can be used directly: only some pairs of control and target qubits are possible. To implement other `cx` gates, tricks such as using `swap` gates to effectively move information around must be used. The possible pairs of qubits on which `cx` gates can be applied is known as the 'connectivity' of the device.\n", + "\n", + "We'll now look at some examples. To make sure you don't end up in a queue for a busy device, we'll be using mock backends. These are designed to act exactly like real backends." + ] + }, + { + "cell_type": "code", + "execution_count": 47, + "metadata": {}, + "outputs": [], + "source": [ + "from qiskit_ibm_runtime.fake_provider import FakeYorktownV2\n", + "backend = FakeYorktownV2()" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "The system we are using (or at least pretending to) is `Manila`. With this system, it is not possible to peform a `cx` gate between any arbitrary pair of qubits. Instead only the following pairings are allowed (where the qubits are labelled from 0 to 4)." + ] + }, + { + "cell_type": "code", + "execution_count": 48, + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "[[0, 1],\n", + " [0, 2],\n", + " [1, 0],\n", + " [1, 2],\n", + " [2, 0],\n", + " [2, 1],\n", + " [2, 3],\n", + " [2, 4],\n", + " [3, 2],\n", + " [3, 4],\n", + " [4, 2],\n", + " [4, 3]]" + ] + }, + "execution_count": 48, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "backend.configuration().coupling_map" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "\n", + "The following cell has a circuit that applies an `AND` gate that is constructed from single and two qubit gates. However, this circuit assumes full connectivity: that `cx` gates can be applied between any pair of qubits." + ] + }, + { + "cell_type": "code", + "execution_count": 49, + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "AND gate\n" + ] + }, + { + "data": { + "text/html": [ + "
          \n",
+       "q_0: ──■──\n",
+       "       │  \n",
+       "q_1: ──■──\n",
+       "     ┌─┴─┐\n",
+       "q_2: ┤ X ├\n",
+       "     └───┘
" + ], + "text/plain": [ + " \n", + "q_0: ──■──\n", + " │ \n", + "q_1: ──■──\n", + " ┌─┴─┐\n", + "q_2: ┤ X ├\n", + " └───┘" + ] + }, + "metadata": {}, + "output_type": "display_data" + }, + { + "name": "stdout", + "output_type": "stream", + "text": [ + "\n", + "\n", + "Transpiled AND gate for hardware with the required connectiviy\n" + ] + }, + { + "data": { + "text/html": [ + "
                                                       ┌───┐      \n",
+       "q_0: ───────────────────■─────────────────────■────■───┤ T ├───■──\n",
+       "                        │             ┌───┐   │  ┌─┴─┐┌┴───┴┐┌─┴─┐\n",
+       "q_1: ───────■───────────┼─────────■───┤ T ├───┼──┤ X ├┤ Tdg ├┤ X ├\n",
+       "     ┌───┐┌─┴─┐┌─────┐┌─┴─┐┌───┐┌─┴─┐┌┴───┴┐┌─┴─┐├───┤└┬───┬┘└───┘\n",
+       "q_2: ┤ H ├┤ X ├┤ Tdg ├┤ X ├┤ T ├┤ X ├┤ Tdg ├┤ X ├┤ T ├─┤ H ├──────\n",
+       "     └───┘└───┘└─────┘└───┘└───┘└───┘└─────┘└───┘└───┘ └───┘      
" + ], + "text/plain": [ + " ┌───┐ \n", + "q_0: ───────────────────■─────────────────────■────■───┤ T ├───■──\n", + " │ ┌───┐ │ ┌─┴─┐┌┴───┴┐┌─┴─┐\n", + "q_1: ───────■───────────┼─────────■───┤ T ├───┼──┤ X ├┤ Tdg ├┤ X ├\n", + " ┌───┐┌─┴─┐┌─────┐┌─┴─┐┌───┐┌─┴─┐┌┴───┴┐┌─┴─┐├───┤└┬───┬┘└───┘\n", + "q_2: ┤ H ├┤ X ├┤ Tdg ├┤ X ├┤ T ├┤ X ├┤ Tdg ├┤ X ├┤ T ├─┤ H ├──────\n", + " └───┘└───┘└─────┘└───┘└───┘└───┘└─────┘└───┘└───┘ └───┘ " + ] + }, + "execution_count": 49, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "qc_and = QuantumCircuit(3)\n", + "qc_and.ccx(0,1,2)\n", + "print('AND gate')\n", + "display(qc_and.draw())\n", + "print('\\n\\nTranspiled AND gate for hardware with the required connectiviy')\n", + "qc_and.decompose().draw()" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "This ideal transpilation requires 6 `cx` gates.\n", + "\n", + "There are often optimizations that the transpiler can perform that reduce the overall gate count, and thus total length of the input circuits. Note that the addition of swaps to match the device topology, and optimizations for reducing the length of a circuit are at odds with each other. In what follows we will make use of `initial_layout` that allows us to pick the qubits on a device used for the computation and `optimization_level`, an argument that allows selecting from internal defaults for circuit swap mapping and optimization methods to perform." + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "Rather than actually running the AND function, let's just look at the transpiled circuits. The following function does this for a given set of inputs." + ] + }, + { + "cell_type": "code", + "execution_count": 50, + "metadata": {}, + "outputs": [], + "source": [ + "# run the cell to define AND gate for real quantum system\n", + "\n", + "def AND(inp1, inp2, backend, layout):\n", + " \n", + " qc = QuantumCircuit(3, 1) \n", + " qc.reset(range(3))\n", + " \n", + " if inp1=='1':\n", + " qc.x(0)\n", + " if inp2=='1':\n", + " qc.x(1)\n", + " \n", + " qc.barrier()\n", + " qc.ccx(0, 1, 2) \n", + " qc.barrier()\n", + " qc.measure(2, 0) \n", + " \n", + " qc_trans = transpile(qc, backend, initial_layout=layout, optimization_level=3)\n", + " \n", + " return qc_trans" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "

📓 Assign your choice of layout to the list variable layout in the cell below

" + ] + }, + { + "cell_type": "code", + "execution_count": 63, + "metadata": {}, + "outputs": [], + "source": [ + "# Assign your choice of the initial_layout to the variable layout1 as a list \n", + "# For example\n", + "# layout = [0,2,4]\n", + "layout = [0,1,2]" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "Compile the `AND` gate on `Manila` by running the cell below." + ] + }, + { + "cell_type": "code", + "execution_count": 64, + "metadata": { + "scrolled": true + }, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "For input 00\n", + "# of nonlocal gates = 6\n", + "For input 01\n", + "# of nonlocal gates = 6\n", + "For input 10\n", + "# of nonlocal gates = 6\n", + "For input 11\n", + "# of nonlocal gates = 6\n", + "For input 00\n", + "For input 01\n", + "For input 10\n", + "For input 11\n", + "✅ Ideal transpilation acheived.\n" + ] + } + ], + "source": [ + "for input1 in ['0','1']:\n", + " for input2 in ['0','1']:\n", + " qc_trans1 = AND(input1, input2, backend, layout)\n", + " \n", + " print('For input '+input1+input2)\n", + " print('# of nonlocal gates =',qc_trans1.num_nonlocal_gates())\n", + "\n", + "test_compilation(layout) # DO NOT EDIT THIS LINE" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "# Excercise 2\n", + "## 1. Alternative Pauli Basis States\n", + "\n", + "There are an infinite number of possible single qubit states. From a theoretical stand-point, the one we choose to label $| 0 \\rangle$ is arbitrary. So let’s consider the following alternative.\n", + "\n", + "$$\n", + "| \\bar 0 \\rangle = \\cos(\\theta) \\, | 0 \\rangle + \\sin(\\theta) \\, | 1 \\rangle.\n", + "$$\n", + "\n", + "For this $| \\bar 0 \\rangle$:\n", + "\n", + "(a) Find a corresponding orthogonal state $| \\bar 1 \\rangle$;\n", + "\n", + "(b) For this basis $| \\bar 0 \\rangle$, $| \\bar 1 \\rangle$, find mutually unbiased basis states $| \\bar + \\rangle$ and $| \\bar - \\rangle$;\n", + "\n" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "### Instructions\n", + "\n", + "**Representing States**: Qubit states will be represented as NumPy arrays of shape (2, 1). For example, ket_0 = np.array([[1], [0]]).\n", + "\n", + "**Completing the Functions**: Your task is to complete the three Python functions provided in the code block below:\n", + "\n", + "`find_orthogonal_state(ket_zero_bar, theta)`\n", + "\n", + "`find_mutually_unbiased_basis_plus(ket_zero_bar, ket_one_bar)`\n", + "\n", + "`find_mutually_unbiased_basis_minus(ket_zero_bar, ket_one_bar)`\n", + "\n", + "**Running the Tests**: After implementing the functions, run the entire script. The assert statements will automatically check if your implementations are correct. If all tests pass, you will see the message \"All tests passed!\". Otherwise, an AssertionError will be raised, indicating a problem with your implementation.\n" + ] + }, + { + "cell_type": "code", + "execution_count": 117, + "metadata": {}, + "outputs": [], + "source": [ + "ket_0 = np.array([[1], [0]], dtype=complex)\n", + "ket_1 = np.array([[0], [1]], dtype=complex)\n", + "\n", + "### BEGIN SOLUTION\n", + "def find_orthogonal_state(ket_zero_bar, theta):\n", + " \"\"\"\n", + " Calculates the orthogonal state |ψ1⟩ for a given |ψ0⟩.\n", + "\n", + " Args:\n", + " ket_zero_bar: A NumPy array representing the state |ψ0⟩.\n", + " theta: The angle theta in radians.\n", + "\n", + " Returns:\n", + " A NumPy array representing the orthogonal state |ψ1⟩.\n", + " \"\"\"\n", + " # --- YOUR CODE HERE ---\n", + " # Hint: An orthogonal state can be found by swapping the amplitudes\n", + " # of the original state and changing the sign of one of them.\n", + " # For |ψ0⟩ = a|0⟩ + b|1⟩, an orthogonal state is |ψ1⟩ = b|0⟩ - a|1⟩.\n", + " # Another valid orthogonal state is |ψ1⟩ = -b|0⟩ + a|1⟩.\n", + "\n", + " state = -np.sin(theta)*ket_0 + np.cos(theta)*ket_1\n", + " return state # Replace this with your implementation\n", + "\n", + "def find_mutually_unbiased_basis_plus(ket_zero_bar, ket_one_bar):\n", + " \"\"\"\n", + " Calculates the |ψ+⟩ state for the mutually unbiased basis.\n", + "\n", + " Args:\n", + " ket_zero_bar: A NumPy array representing the state |ψ0⟩.\n", + " ket_one_bar: A NumPy array representing the state |ψ1⟩.\n", + "\n", + " Returns:\n", + " A NumPy array representing the |ψ+⟩ state.\n", + " \"\"\"\n", + " # --- YOUR CODE HERE ---\n", + " # Hint: The |+⟩ state in the standard basis is (|0⟩ + |1⟩) / sqrt(2).\n", + " # In a new basis, it will be a superposition of the new basis vectors.\n", + " state = 1/np.sqrt(2)*(ket_zero_bar + ket_one_bar)\n", + " return state # Replace this with your implementation\n", + "\n", + "def find_mutually_unbiased_basis_minus(ket_zero_bar, ket_one_bar):\n", + " \"\"\"\n", + " Calculates the |ψ-⟩ state for the mutually unbiased basis.\n", + "\n", + " Args:\n", + " ket_zero_bar: A NumPy array representing the state |ψ0⟩.\n", + " ket_one_bar: A NumPy array representing the state |ψ1⟩.\n", + "\n", + " Returns:\n", + " A NumPy array representing the |ψ-⟩ state.\n", + " \"\"\"\n", + " # --- YOUR CODE HERE ---\n", + " # Hint: The |-⟩ state in the standard basis is (|0⟩ - |1⟩) / sqrt(2).\n", + " # In a new basis, it will also be a superposition of the new basis vectors.\n", + " state = 1/np.sqrt(2)*(ket_zero_bar - ket_one_bar)\n", + " return state # Replace this with your implementation\n", + "### END SOLTUION" + ] + }, + { + "cell_type": "code", + "execution_count": 118, + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "✅ Test (a) passed: |ψ0⟩ and |ψ1⟩ are orthogonal.\n", + "✅ Test (b) passed: The bases are mutually unbiased.\n", + "\n", + "Congratulations! All tests passed!\n" + ] + } + ], + "source": [ + "# Test your solutions\n", + "test_alt(find_orthogonal_state,find_mutually_unbiased_basis_plus,find_mutually_unbiased_basis_minus) # DO NOT EDIT THIS LINE" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "## 2. Properties of the Pauli Matrices\n", + "\n", + "Note: Sometimes the Pauli matrices are written as $X$, $Y$ and $Z$, and sometimes as $\\sigma_x$, $\\sigma_y$ and $\\sigma_z$. For the most part, the convention is an arbitrary choice. Once you’ve used them enough, you’ll hardly notice the difference (to the great annoyance of your students!).\n", + "\n", + "The Pauli matrices are defined\n", + "\n", + "$$\n", + "X = \n", + "\\begin{pmatrix} \n", + "0 & 1 \\\\\n", + "1 & 0 \\\\\n", + "\\end{pmatrix}, \\,\\,\n", + "Y = \n", + "\\begin{pmatrix} \n", + "0 & -i \\\\\n", + "i & 0 \\\\\n", + "\\end{pmatrix}, \\,\\,\n", + "Z = \n", + "\\begin{pmatrix} \n", + "1 & 0 \\\\\n", + "0 & -1 \\\\\n", + "\\end{pmatrix}, \\,\\,\n", + "$$\n", + "\n", + "(a) Show that each squares to the identity matrix.\n", + "\n", + "$$\n", + "I = \n", + "\\begin{pmatrix} \n", + "1 & 0 \\\\\n", + "0 & 1 \\\\\n", + "\\end{pmatrix}\n", + "$$\n", + "\n", + "(b) Show that $P_1 P_2 = - P_2 P_1$ for any pair of Paulis $P_1$ and $P_2$.\n", + "\n", + "(c) Show that $P_1 P_2 \\sim P_3$ for any pair of Paulis $P_1$ and $P_2$, where $P_3$ is the remaining Pauli.\n", + "\n", + "(d) Find the eigenvectors and eigenvalues of each Pauli.\n", + "\n", + "### Instructions \n", + "\n", + "**Define the Matrices**: In Part 1, define the Pauli matrices X, Y, Z, and the identity matrix I using NumPy.\n", + "\n", + "**Implement the Test Functions**: In Part 2, complete the function skeletons provided. Each function is designed to test a specific property of the Pauli matrices and should return a value (usually a boolean) indicating the result of the test. Read the docstrings and hints carefully to understand what each function needs to do.\n", + "\n", + "**Sumbit**: After completing your implementation, run the entire script. The code in the test section will call your functions and use assert statements to check if they produce the correct results. If all your functions work as expected, you will see a series of \"PASS\" messages." + ] + }, + { + "cell_type": "code", + "execution_count": 127, + "metadata": {}, + "outputs": [], + "source": [ + "### BEGIN SOLUTION\n", + "# --- Part 1: Define the Matrices ---\n", + "# Define the Pauli matrices and the Identity matrix as NumPy arrays.\n", + "# Use dtype=complex for matrices with complex entries.\n", + "\n", + "X = np.array([[0,1],[1,0]]) # Replace None with the definition of the X matrix\n", + "Y = np.array([[0,-1.j],[1.j,0]]) # Replace None with the definition of the Y matrix\n", + "Z = np.array([[1,0],[0,-1]]) # Replace None with the definition of the Z matrix\n", + "I = np.array([[1,0],[0,1]]) # Replace None with the definition of the Identity matrix\n", + "\n", + "# This dictionary is used by the test functions.\n", + "paulis = {'X': X, 'Y': Y, 'Z': Z}\n", + "\n", + "# --- Part 2: Implement the Test Functions ---\n", + "# Complete the following functions to test the properties of the Pauli matrices.\n", + "\n", + "def test_square_to_identity(P):\n", + " \"\"\"\n", + " (a) Check if each Pauli matrix squares to the identity matrix.\n", + "\n", + " Returns:\n", + " np.array: matrix of your results \n", + " \"\"\"\n", + " # Hint: \n", + " # calculate P @ P\n", + " return P@P # Your implementation here\n", + "\n", + "def test_anticommutation(P1, P2):\n", + " \"\"\"\n", + " (b) Check if P1 @ P2 = -P2 @ P1 for any pair of distinct Paulis.\n", + "\n", + " Returns:\n", + " [np.array1,np.array2]: list of the left and right side of the equation for one pair\n", + " \"\"\"\n", + " # Hint: You can check the pairs (X, Y), (Y, Z), and (Z, X).\n", + " # For each pair (P1, P2), check if P1 @ P2 is close to -(P2 @ P1).\n", + " return [P1@P2,-P2@P1] # Your implementation here\n", + "\n", + "def test_product_relation():\n", + " \"\"\"\n", + " (c) Check if the Pauli product relations hold (XY=iZ, YZ=iX, ZX=iY).\n", + "\n", + " Returns:\n", + " list[np.array]: The 3 matrices resulting from your calculations in the order above\n", + " \"\"\"\n", + " # Hint: Check each of the three relations separately. For example,\n", + " # check if np.allclose(X @ Y, 1j * Z).\n", + " # All three must be correct for the function to pass.\n", + " return [X@Y, Y@Z, Z@X] # Your implementation here\n", + "\n", + "def get_eigenvalues_and_eigenvectors():\n", + " \"\"\"\n", + " (d) Calculate the eigenvalues and eigenvectors for each Pauli matrix.\n", + "\n", + " Returns:\n", + " tuple: A tuple containing two dictionaries:\n", + " (eigenvalues_dict, eigenvectors_dict)\n", + "\n", + " - eigenvalues_dict: A dictionary where keys are the names\n", + " ('X', 'Y', 'Z') and values are the corresponding eigenvalues.\n", + " - eigenvectors_dict: A dictionary where keys are the names\n", + " and values are the corresponding eigenvectors.\n", + " \"\"\"\n", + " # Hint: Use a loop and np.linalg.eig() for each Pauli matrix. This\n", + " # function returns a tuple of (eigenvalues, eigenvectors). Store these\n", + " # in the two dictionaries with the correct keys ('X', 'Y', 'Z').\n", + " eigenvalues_dict = {}\n", + " eigenvectors_dict = {}\n", + "\n", + " for key, value in paulis.items():\n", + " eigenvalues, eigenvectors = np.linalg.eig(value)\n", + " eigenvalues_dict[key] = eigenvalues\n", + " eigenvectors_dict[key] = eigenvectors\n", + "\n", + " return eigenvalues_dict, eigenvectors_dict\n", + "\n", + "### END SOLUTION\n" + ] + }, + { + "cell_type": "code", + "execution_count": 128, + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "✅ PASS (a): Your function `test_square_to_identity` works correctly.\n", + "✅ PASS (b): Your function `test_anticommutation` works correctly.\n", + "✅ PASS (c): Your function `test_product_relation` works correctly.\n", + "✅ PASS (d): Your function `get_eigenvalues_and_eigenvectors` has the correct return type and keys.\n", + "✅ PASS (d): Eigenvalues and eigenvectors are correct for all Pauli matrices.\n", + "\n", + "Congratulations! All tests passed!\n" + ] + } + ], + "source": [ + "# Test your solutions\n", + "test_paulis(I,X,Y,Z,test_square_to_identity,test_anticommutation,test_product_relation,get_eigenvalues_and_eigenvectors) # DO NOT EDIT THIS LINE" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "\n", + "## 3. The Hadamard\n", + "\n", + "The Hadamard matrix can be expressed\n", + "\n", + "$$\n", + "H = \\frac{1}{\\sqrt{2}}\n", + "\\begin{pmatrix} \n", + "1 & 1 \\\\\n", + "1 & -1 \\\\\n", + "\\end{pmatrix}\n", + "$$\n", + "\n", + "(a) Find the eigenvectors and eigenvalues of this matrix.\n", + "\n", + "(b) Show that $H$ also squares to identity.\n", + "\n", + "(c) Show that $H P_1 H^\\dagger \\sim P_2$ for Paulis $P_1$ and $P_2$. \n", + "\n", + "### Instructions:\n", + "\n", + "**Define the Matrices**: In Part 1, define the Hadamard matrix H using NumPy.\n", + "\n", + "**Implement the Functions**: In Part 2, complete the function skeletons. Each function is designed to test a specific property of the Hadamard matrix and should return a value that reflects the outcome of the test.\n", + "\n", + "Run the Grading: Once you have completed your implementation, run the entire script. The code in the grader will call your functions and use assert statements to check if they are correct.\n" + ] + }, + { + "cell_type": "code", + "execution_count": 142, + "metadata": {}, + "outputs": [], + "source": [ + "### BEGIN SOLUTION\n", + "# --- Part 1: Define the Matrices ---\n", + "# Define the Hadamard and Identity matrices as NumPy arrays.\n", + "\n", + "H = 1/np.sqrt(2)*np.array([[1,1],[1,-1]]) # Replace None with the definition of the Hadamard matrix\n", + "\n", + "# --- Part 2: Implement the Test Functions ---\n", + "# Complete the following functions to test the properties of the Hadamard matrix.\n", + "\n", + "def get_hadamard_eigen_system():\n", + " \"\"\"\n", + " (a) Find the eigenvectors and eigenvalues of the Hadamard matrix.\n", + "\n", + " Returns:\n", + " tuple: A tuple of (eigenvalues, eigenvectors)\n", + " \"\"\"\n", + " return np.linalg.eig(H)\n", + "\n", + "def test_hadamard_squares_to_identity():\n", + " \"\"\"\n", + " (b) Show that H squares to the identity matrix.\n", + "\n", + " Returns:\n", + " np.array: Result of the calculation asked for\n", + " \"\"\"\n", + " return H@H\n", + "\n", + "def test_hadamard_pauli_transformation():\n", + " \"\"\"\n", + " (c) Show that conjugating a Pauli with H results in another Pauli.\n", + " Specifically, verify:\n", + " 1. H X H† =?\n", + " 2. H Y H† = ?\n", + " 3. H Z H† =?\n", + " Returns:\n", + " [str1,str2,str3]: strings must be a X Y Z or I and must be written as\n", + " iP, -P, -iP or P, where P is the correct Pauli. \n", + " \"\"\"\n", + " return ['Z', '-Y','X']\n", + "### END SOLTUION" + ] + }, + { + "cell_type": "code", + "execution_count": 143, + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "--- Running Verification ---\n", + "✅ PASS (a): Your function `get_hadamard_eigen_system` works correctly.\n", + "✅ PASS (b): Your function `test_hadamard_squares_to_identity` works correctly.\n", + "✅ PASS (c): Your answers are correct.\n", + "\n", + "Congratulations! All tests passed!\n" + ] + } + ], + "source": [ + "# Test your solutions\n", + "test_hadamard(H,get_hadamard_eigen_system,test_hadamard_squares_to_identity,test_hadamard_pauli_transformation) # DO NOT EDIT THIS LINE" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": {}, + "outputs": [], + "source": [] + } + ], + "metadata": { + "kernelspec": { + "display_name": "Python 3 (ipykernel)", + "language": "python", + "name": "python3" + }, + "language_info": { + "codemirror_mode": { + "name": "ipython", + "version": 3 + }, + "file_extension": ".py", + "mimetype": "text/x-python", + "name": "python", + "nbconvert_exporter": "python", + "pygments_lexer": "ipython3", + "version": "3.13.2" + } + }, + "nbformat": 4, + "nbformat_minor": 4 +}