{ "cells": [ { "cell_type": "markdown", "metadata": {}, "source": [ "

\n", "

# Homework 5

" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "\n", "Part I (Short answers)\n", "==========================\n", "\n", "**Q1**. Given the following Hadamard test circuit: \n", "\n", "\n", "where $U$ is unitary and Hermitian and has eigenvalues $\\pm1$, show that:\n", "\n", "$\\quad$ a). depending on the measurement outcome of the ancilla qubit $|0\\rangle$, $|\\psi_{out}\\rangle$ will be one of corresponding eigenvector of $U$;\n", " \n", "$\\quad$ b). through repeated measurements, this circuit can be used to evaluate the expectation value $\\langle U\\rangle$. Or if $U$ is non-Hermitian, it can evaluate the real part of $\\langle U\\rangle$.\n", "\n", "$\\quad$ c). What is the variance (statistical errror) $\\varepsilon^2=Var[\\langle U \\rangle]$ of the expectation value estimator in b)? " ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "Part II\n", "==========================" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "**Q2**. In this question we will use Qiskit to simulate the error suppression by derangement, based on this [reference](https://arxiv.org/pdf/2011.05942.pdf). If you are new to Qiskit, you might find this [tutorial](https://qiskit.org/documentation/intro_tutorial1.html) helpful. \n", "\n", "Consider the erroneous ansatz state of interest given by:\n", "\$$\n", "\\rho=\\lambda|\\psi\\rangle\\langle\\psi|+(1-\\lambda)\\sum_{k=2}^{2^N}p_k|\\psi_k\\rangle\\langle\\psi_k|,\n", "\$$\n", "where the $|\\psi\\rangle$ is the ideal (or dominant) input state and we assume that all $|\\psi_k\\rangle$ and $|\\psi\\rangle$ are orthogonal. The circuit for mitigating the observable measurement error is:\n", "\n", "\n", "There are multiple copies of the input state $\\rho$, the $\\sigma$ is the obervable to be measured, and the $D_n$ is the circuit that permutes the copies of $\\rho$. $D_n$ provides a full cyclic permutation: $D_n|\\psi_1,\\psi_2,...\\psi_n\\rangle = |\\psi_2,\\psi_3,...\\psi_{1}\\rangle$.\n", "\n", "The estimator for the observable measurement is ('Method A' in the reference paper):\n", "\$$\n", "\\frac{2prob_0-1}{2prob'_0-1}=\\langle\\psi|\\sigma|\\psi\\rangle + \\varepsilon,\n", "\$$\n" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "**Note**: The code below is merely for reference. Please feel free to code however you like." ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "$\\quad$ a). The input state $\\rho$ is usually generated by an parameterized ansatz circuit. Here is an example circuit with randomly parameterized single and two- qubit gates (see Appendix E of the reference paper):\n", "\n", "Construct a similar circuit and evaluate the ideal expectation value of the observable Pauli string \"$\\sigma=X_0Y_1Z_2$\". (You can do this with 'aer_simulator' backend)" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "import numpy as np\n", "from qiskit import QuantumCircuit, Aer, transpile\n", "import qiskit.quantum_info as qi\n", "\n", "qc = QuantumCircuit(3)\n", "\n", "### Create the ansatz circuit\n", "\n", "qc.draw('mpl')" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "# The following code uses aer_simulator backend\n", "simulator = Aer.get_backend('aer_simulator')\n", "qc = transpile(qc, simulator)\n", "\n", "Pauli_obs = qi.Pauli('ZYX') # Reversed string to match Qiskit convention, see qiskit.quantum_info.Pauli documentation\n", "qubit_list = range(3)\n", "qc.save_expectation_value(Pauli_obs,qubit_list)\n", "result = simulator.run(qc).result()\n", "\n", "exp = result.data()['expectation_value']\n", "print(\"The ideal expectation value is \",exp)" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "$\\quad$ b). Add the ancilla qubit and construct the Hadamard test circuit as in Q1 and evalutate the error-free 'experimental' expectation value in a). Then apply a $5\\%$ and $10\\%$ of depolarizing error associcated with the single and two- qubit gates of the ansatz circuit and evaluate the noisy 'experimental' expectation value. What are the errors $\\varepsilon$ for both cases? (Use the 'qasm_simulator' backend to simulate the sampling)" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "import qiskit.providers.aer.noise as noise\n", "\n", "qc = QuantumCircuit(4,1)\n", "\n", "### Create the full circuit\n", "\n", "# Error model\n", "prob_1 = 0.05 # 1-qubit gate\n", "prob_2 = 0.1 # 2-qubit gate\n", "\n", "error_1 = noise.depolarizing_error(prob_1, 1)\n", "error_2 = noise.depolarizing_error(prob_2, 2)\n", "\n", "noise_model = noise.NoiseModel()\n", "noise_model.add_all_qubit_quantum_error(error_1, ['rx','ry','rz'])\n", "noise_model.add_all_qubit_quantum_error(error_2, ['crz'])\n", "\n", "### Execute the circuit\n", "simulator = Aer.get_backend('qasm_simulator')\n" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "$\\quad$ c). Add a second copy of $\\rho$, and implement the controlled-$D_n$ for the two copies. Under the same error model in b), pick 20 random Pauli strings as observables, plot a histogram (log-scale) of their absolute errors $abs(\\varepsilon)$ versus the number of copies $n=1,2$." ] } ], "metadata": { "kernelspec": { "display_name": "Python 3", "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.6.7" } }, "nbformat": 4, "nbformat_minor": 2 }