{ "cells": [ { "cell_type": "markdown", "id": "833a9d8c-18bf-4c0e-a36c-4d3e4b5311c4", "metadata": {}, "source": [ "# PRELAB --Intro to IBM Qiskit" ] }, { "cell_type": "markdown", "id": "c081821d", "metadata": {}, "source": [ "## Problem 1\n", "### (a)\n", "Show that\n", "\n", "$$\n", "\\begin{align}\n", "H|0\\rangle &= |+\\rangle\\\\\n", "H|1\\rangle &= |-\\rangle\n", "\\end{align}\n", "$$\n", "\n", "where \n", "\n", "$$\n", "H = \\frac{1}{\\sqrt{2}} \\left(\\begin{array}{cc} 1& 1\\\\1& -1 \\end{array} \\right)\n", "$$\n", "\n", "is the Hadamard gate.\n", "\n", "Recall that $|\\pm\\rangle = (|0\\rangle\\pm |1\\rangle)/\\sqrt{2}$ is an eigenstate of the Pauli-$X$ operator." ] }, { "cell_type": "markdown", "id": "e2a064fe", "metadata": {}, "source": [ "### (b)\n", "Show that (up to a global phase)\n", "\n", "$$\n", "\\begin{align}\n", "H &= e^{-i\\frac{\\pi}{2} \\sigma_{\\hat{i}}}\n", "\\end{align}\n", "$$\n", "\n", "where $ \\hat{i} = \\frac{1}{\\sqrt{2}}\\left( \\begin{array}{c} 1\\\\0\\\\1 \\end{array} \\right) $." ] }, { "cell_type": "markdown", "id": "029af910", "metadata": {}, "source": [ "## Problem 2\n", "Show that the following circuit performs a SWAP operation:" ] }, { "cell_type": "code", "execution_count": 4, "id": "bb5988a7", "metadata": {}, "outputs": [ { "data": { "text/html": [ "<pre style=\"word-wrap: normal;white-space: pre;background: #fff0;line-height: 1.1;font-family: "Courier New",Courier,monospace\"> ┌───┐ \n", "q_0: ──■──┤ X ├──■──\n", " ┌─┴─┐└─┬─┘┌─┴─┐\n", "q_1: ┤ X ├──■──┤ X ├\n", " └───┘ └───┘</pre>" ], "text/plain": [ " ┌───┐ \n", "q_0: ──■──┤ X ├──■──\n", " ┌─┴─┐└─┬─┘┌─┴─┐\n", "q_1: ┤ X ├──■──┤ X ├\n", " └───┘ └───┘" ] }, "execution_count": 4, "metadata": {}, "output_type": "execute_result" } ], "source": [ "from qiskit import QuantumCircuit\n", "from qiskit.circuit import Gate\n", "qc = QuantumCircuit(2)\n", "qc.cx(0,1)\n", "qc.cx(1,0)\n", "qc.cx(0,1)\n", "qc.draw()" ] }, { "cell_type": "markdown", "id": "ad2a66e1", "metadata": {}, "source": [ "## Problem 3\n", "### (a)\n", "Show that $ HXH = Z $ and $ HZH = X $." ] }, { "cell_type": "markdown", "id": "7f11a99f", "metadata": {}, "source": [ "### (b)\n", "Using the identities above, which two-qubit gate is the following quantum circuit equivalent to?" ] }, { "cell_type": "code", "execution_count": 5, "id": "2ed97488", "metadata": {}, "outputs": [ { "data": { "text/html": [ "<pre style=\"word-wrap: normal;white-space: pre;background: #fff0;line-height: 1.1;font-family: "Courier New",Courier,monospace\"> \n", "q_0: ──────■──────\n", " ┌───┐ │ ┌───┐\n", "q_1: ┤ H ├─■─┤ H ├\n", " └───┘ └───┘</pre>" ], "text/plain": [ " \n", "q_0: ──────■──────\n", " ┌───┐ │ ┌───┐\n", "q_1: ┤ H ├─■─┤ H ├\n", " └───┘ └───┘" ] }, "execution_count": 5, "metadata": {}, "output_type": "execute_result" } ], "source": [ "from qiskit import QuantumCircuit\n", "from qiskit.circuit import Gate\n", "qc = QuantumCircuit(2)\n", "qc.h(1)\n", "qc.cz(0,1)\n", "qc.h(1)\n", "qc.draw()" ] }, { "cell_type": "markdown", "id": "6e283f04", "metadata": {}, "source": [ "### (c)\n", "In real-world experiments, qubits often _do not_ have all-to-all connectivities. For example, the quantum circuit below performs effectively a two-qubit gate between q_1 and q_2 by using q_0 as an auxiliary qubit. Which two-qubit gate is it and prove that this is indeed the case." ] }, { "cell_type": "code", "execution_count": 6, "id": "f02c583f", "metadata": {}, "outputs": [ { "data": { "text/html": [ "<pre style=\"word-wrap: normal;white-space: pre;background: #fff0;line-height: 1.1;font-family: "Courier New",Courier,monospace\"> ┌───┐ ┌───┐\n", "q_0: ─■─┤ H ├─■─┤ H ├\n", " │ └───┘ │ └───┘\n", "q_1: ─■───────┼──────\n", " │ \n", "q_2: ─────────■──────\n", " </pre>" ], "text/plain": [ " ┌───┐ ┌───┐\n", "q_0: ─■─┤ H ├─■─┤ H ├\n", " │ └───┘ │ └───┘\n", "q_1: ─■───────┼──────\n", " │ \n", "q_2: ─────────■──────\n", " " ] }, "execution_count": 6, "metadata": {}, "output_type": "execute_result" } ], "source": [ "from qiskit import QuantumCircuit\n", "from qiskit.circuit import Gate\n", "qc = QuantumCircuit(3)\n", "qc.cz(0,1)\n", "qc.h(0)\n", "qc.cz(0,2)\n", "qc.h(0)\n", "qc.draw()" ] }, { "cell_type": "markdown", "id": "44c877ae", "metadata": {}, "source": [ "## Problem 4\n", "Quantum Fourier transform (QFT) is an essential primitive for many quantum algorithms. It is a unitary transformation that maps\n", "\n", "$$ |X\\rangle = \\sum_{j=0}^{N-1} x_j |j\\rangle $$\n", "\n", "to \n", "\n", "$$ |Y\\rangle = \\sum_{k=0}^{N-1} y_k |k\\rangle$$\n", "\n", ", where $ y_k = \\frac{1}{\\sqrt{N}} \\sum_{j=0}^{N-1} x_j \\omega_N^{jk}$ and $ \\omega_N^{jk}=e^{2\\pi i \\frac{jk}{N}}$. $N=2^n$ represents the size of the Hilbert space spanned by $n$ qubits.\n", "\n", "Show that the Hadamard gate is a 1-qubit QFT." ] }, { "cell_type": "markdown", "id": "e8977e2b", "metadata": {}, "source": [ "## Problem 5\n", "Typically, a CNOT gate performed on a control qubit q_c and a target qubit q_t results in a change in the state of q_t depending on the state of q_c. Show that in the $X$-basis, instead, the state of q_c changes depending on the state of q_t. This phenomenon is called phase kickback, a mechanism essential to the quantum phase estimation algorithm as you will see in lab." ] } ], "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.8.13" }, "widgets": { "application/vnd.jupyter.widget-state+json": { "state": {}, "version_major": 2, "version_minor": 0 } } }, "nbformat": 4, "nbformat_minor": 5 }