{ "cells": [ { "cell_type": "markdown", "metadata": {}, "source": [ "#Lab 4 - Measurements\n", "First our standard definitions:" ] }, { "cell_type": "code", "execution_count": 72, "metadata": {}, "outputs": [], "source": [ "import matplotlib.pyplot as plt\n", "from numpy import sqrt,pi,cos,sin,arange,random,exp\n", "from qutip import *" ] }, { "cell_type": "code", "execution_count": 2, "metadata": {}, "outputs": [], "source": [ "H = Qobj([[1],[0]])\n", "V = Qobj([[0],[1]])\n", "P45 = Qobj([[1/sqrt(2)],[1/sqrt(2)]])\n", "M45 = Qobj([[1/sqrt(2)],[-1/sqrt(2)]])\n", "R = Qobj([[1/sqrt(2)],[-1j/sqrt(2)]])\n", "L = Qobj([[1/sqrt(2)],[1j/sqrt(2)]])" ] }, { "cell_type": "code", "execution_count": 3, "metadata": {}, "outputs": [], "source": [ "def sim_transform(o_basis1, o_basis2, n_basis1, n_basis2):\n", " a = n_basis1.dag()*o_basis1\n", " b = n_basis1.dag()*o_basis2\n", " c = n_basis2.dag()*o_basis1\n", " d = n_basis2.dag()*o_basis2\n", " return Qobj([[a.data[0,0],b.data[0,0]],[c.data[0,0],d.data[0,0]]])" ] }, { "cell_type": "code", "execution_count": 4, "metadata": {}, "outputs": [], "source": [ "def Delta(state, op):\n", " \"\"\"Calculate std. dev. of an observable in a given state\"\"\"\n", " eO2 = state.dag()*op*op*state\n", " eO = state.dag()*op*state\n", " return sqrt(eO2.data[0,0] - (eO.data[0,0])**2)" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "###Q: Define the $\\hat{\\mathscr{P}}_{HV}$ operator" ] }, { "cell_type": "code", "execution_count": 5, "metadata": {}, "outputs": [ { "data": { "text/latex": [ "Quantum object: dims = [[2], [2]], shape = [2, 2], type = oper, isherm = True\\begin{equation*}\\left(\\begin{array}{*{11}c}1.0 & 0.0\\\\0.0 & -1.0\\\\\\end{array}\\right)\\end{equation*}" ], "text/plain": [ "Quantum object: dims = [[2], [2]], shape = [2, 2], type = oper, isherm = True\n", "Qobj data =\n", "[[ 1. 0.]\n", " [ 0. -1.]]" ] }, "execution_count": 5, "metadata": {}, "output_type": "execute_result" } ], "source": [ "Phv = H*H.dag() - V*V.dag()\n", "Phv" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "###Q: What is the expectation value $\\langle \\hat{\\mathscr{P}}_{HV}\\rangle$ for state $|\\psi\\rangle = \\frac{1}{\\sqrt{5}}|H\\rangle + \\frac{2}{\\sqrt{5}}|V\\rangle$? Interpret this result given the amplitudes in the state." ] }, { "cell_type": "code", "execution_count": 6, "metadata": {}, "outputs": [], "source": [ "psi = 1/sqrt(5)*H + 2/sqrt(5)*V" ] }, { "cell_type": "code", "execution_count": 7, "metadata": {}, "outputs": [ { "data": { "text/latex": [ "Quantum object: dims = [[1], [1]], shape = [1, 1], type = oper, isherm = True\\begin{equation*}\\left(\\begin{array}{*{11}c}-0.600\\\\\\end{array}\\right)\\end{equation*}" ], "text/plain": [ "Quantum object: dims = [[1], [1]], shape = [1, 1], type = oper, isherm = True\n", "Qobj data =\n", "[[-0.6]]" ] }, "execution_count": 7, "metadata": {}, "output_type": "execute_result" } ], "source": [ "psi.dag()*Phv*psi" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "###Q: What is the variance of $\\mathscr{P}_{HV}$?" ] }, { "cell_type": "code", "execution_count": 8, "metadata": {}, "outputs": [ { "data": { "text/latex": [ "Quantum object: dims = [[1], [1]], shape = [1, 1], type = oper, isherm = True\\begin{equation*}\\left(\\begin{array}{*{11}c}1.000\\\\\\end{array}\\right)\\end{equation*}" ], "text/plain": [ "Quantum object: dims = [[1], [1]], shape = [1, 1], type = oper, isherm = True\n", "Qobj data =\n", "[[ 1.]]" ] }, "execution_count": 8, "metadata": {}, "output_type": "execute_result" } ], "source": [ "psi.dag()*Phv*Phv*psi" ] }, { "cell_type": "code", "execution_count": 9, "metadata": {}, "outputs": [ { "data": { "text/plain": [ "0.64" ] }, "execution_count": 9, "metadata": {}, "output_type": "execute_result" } ], "source": [ "1.0 - (-0.6)**2" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "###Ex: Use the random function to generate a mock data set for the state $|\\psi\\rangle$.\n", " random.choice([1,-1],size=10,p=[0.2,0.8])\n", "gives a list of 10 numbers, either 1 or -1 with the associated probability p:" ] }, { "cell_type": "code", "execution_count": 43, "metadata": {}, "outputs": [], "source": [ "data = random.choice([1, -1],size=20,p=[0.2,0.8])" ] }, { "cell_type": "code", "execution_count": 44, "metadata": {}, "outputs": [ { "data": { "text/plain": [ "-0.69999999999999996" ] }, "execution_count": 44, "metadata": {}, "output_type": "execute_result" } ], "source": [ "data.mean()" ] }, { "cell_type": "code", "execution_count": 45, "metadata": {}, "outputs": [ { "data": { "text/plain": [ "0.51000000000000001" ] }, "execution_count": 45, "metadata": {}, "output_type": "execute_result" } ], "source": [ "data.var()" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "###Q: Verify the mean and variance of the mock data set match your QM predictions. How big does the set need to be for you to get ±5% agreement?" ] }, { "cell_type": "code", "execution_count": 62, "metadata": {}, "outputs": [], "source": [ "data = random.choice([1, -1],size=10000,p=[0.2,0.8])" ] }, { "cell_type": "code", "execution_count": 63, "metadata": {}, "outputs": [ { "data": { "text/plain": [ "-0.59840000000000004" ] }, "execution_count": 63, "metadata": {}, "output_type": "execute_result" } ], "source": [ "data.mean()" ] }, { "cell_type": "code", "execution_count": 64, "metadata": {}, "outputs": [ { "data": { "text/plain": [ "0.64191744000000017" ] }, "execution_count": 64, "metadata": {}, "output_type": "execute_result" } ], "source": [ "data.var()" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "10,000 does pretty well for getting to the predictions. \"There is no substitute for an adequate sample size.\"" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "###Q: Answer problems 5.11, 5.12, 5.13, 5.14, 5.17, 5.18, 5.19 from the textbook. These are an opportunity to practice with a new operator $\\hat{\\mathscr{P}}_{C}$" ] }, { "cell_type": "code", "execution_count": 65, "metadata": {}, "outputs": [], "source": [ "# 5.11\n", "P_45 = P45*P45.dag() - M45*M45.dag()" ] }, { "cell_type": "code", "execution_count": 66, "metadata": {}, "outputs": [], "source": [ "#5.12\n", "P_c = L*L.dag() - R*R.dag()" ] }, { "cell_type": "code", "execution_count": 67, "metadata": {}, "outputs": [ { "data": { "text/plain": [ "True" ] }, "execution_count": 67, "metadata": {}, "output_type": "execute_result" } ], "source": [ "#5.13\n", "(Phv*P_45 - P_45*Phv) == 2j * P_c" ] }, { "cell_type": "code", "execution_count": 68, "metadata": {}, "outputs": [ { "data": { "text/plain": [ "True" ] }, "execution_count": 68, "metadata": {}, "output_type": "execute_result" } ], "source": [ "#5.14\n", "(Phv*P_c - P_c*Phv) == -2j * P_45" ] }, { "cell_type": "code", "execution_count": 69, "metadata": {}, "outputs": [], "source": [ "#5.15\n", "P_p45 = P45*P45.dag()\n", "P_v = V*V.dag()" ] }, { "cell_type": "code", "execution_count": 70, "metadata": {}, "outputs": [ { "data": { "text/latex": [ "Quantum object: dims = [[2], [2]], shape = [2, 2], type = oper, isherm = False\\begin{equation*}\\left(\\begin{array}{*{11}c}0.0 & 0.500\\\\-0.500 & 0.0\\\\\\end{array}\\right)\\end{equation*}" ], "text/plain": [ "Quantum object: dims = [[2], [2]], shape = [2, 2], type = oper, isherm = False\n", "Qobj data =\n", "[[ 0. 0.5]\n", " [-0.5 0. ]]" ] }, "execution_count": 70, "metadata": {}, "output_type": "execute_result" } ], "source": [ "P_p45*P_v - P_v*P_p45" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "##5.19 - this one is tricky, but is easier with our custom function" ] }, { "cell_type": "code", "execution_count": 73, "metadata": {}, "outputs": [ { "data": { "text/plain": [ "1.0" ] }, "execution_count": 73, "metadata": {}, "output_type": "execute_result" } ], "source": [ "psi = 1/sqrt(3)*H + sqrt(2/3.0)*exp(1j*pi/3.0)*V\n", "psi.norm()" ] }, { "cell_type": "code", "execution_count": 74, "metadata": {}, "outputs": [ { "data": { "text/plain": [ "(0.83147941928309788+0j)" ] }, "execution_count": 74, "metadata": {}, "output_type": "execute_result" } ], "source": [ "Delta(psi,P_45)*Delta(psi,Phv)" ] }, { "cell_type": "code", "execution_count": 75, "metadata": {}, "outputs": [ { "data": { "text/plain": [ "(0.81649658092772592+0j)" ] }, "execution_count": 75, "metadata": {}, "output_type": "execute_result" } ], "source": [ "1/2j*(psi.dag()*(Phv*P_45 - P_45*Phv)*psi).data[0,0]" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [] } ], "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.7.4" } }, "nbformat": 4, "nbformat_minor": 1 }