{ "cells": [ { "cell_type": "markdown", "metadata": {}, "source": [ "# Lab 8 - Simple Harmonic Oscillator states\n", "Problems from Chapter 12" ] }, { "cell_type": "code", "execution_count": 1, "metadata": {}, "outputs": [], "source": [ "from numpy import sqrt\n", "from qutip import *" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "## Define the standard operators" ] }, { "cell_type": "code", "execution_count": 2, "metadata": {}, "outputs": [], "source": [ "N = 10 # pick a size for our state-space\n", "a = destroy(N)\n", "n = a.dag()*a" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "## Problem 12.1:" ] }, { "cell_type": "code", "execution_count": 3, "metadata": {}, "outputs": [ { "data": { "text/latex": [ "Quantum object: dims = [[10], [10]], shape = (10, 10), type = oper, isherm = True\\begin{equation*}\\left(\\begin{array}{*{11}c}1.0 & 0.0 & 0.0 & 0.0 & 0.0 & 0.0 & 0.0 & 0.0 & 0.0 & 0.0\\\\0.0 & 1.0 & 0.0 & 0.0 & 0.0 & 0.0 & 0.0 & 0.0 & 0.0 & 0.0\\\\0.0 & 0.0 & 1.000 & 0.0 & 0.0 & 0.0 & 0.0 & 0.0 & 0.0 & 0.0\\\\0.0 & 0.0 & 0.0 & 1.0 & 0.0 & 0.0 & 0.0 & 0.0 & 0.0 & 0.0\\\\0.0 & 0.0 & 0.0 & 0.0 & 1.0 & 0.0 & 0.0 & 0.0 & 0.0 & 0.0\\\\0.0 & 0.0 & 0.0 & 0.0 & 0.0 & 1.000 & 0.0 & 0.0 & 0.0 & 0.0\\\\0.0 & 0.0 & 0.0 & 0.0 & 0.0 & 0.0 & 1.0 & 0.0 & 0.0 & 0.0\\\\0.0 & 0.0 & 0.0 & 0.0 & 0.0 & 0.0 & 0.0 & 1.0 & 0.0 & 0.0\\\\0.0 & 0.0 & 0.0 & 0.0 & 0.0 & 0.0 & 0.0 & 0.0 & 1.000 & 0.0\\\\0.0 & 0.0 & 0.0 & 0.0 & 0.0 & 0.0 & 0.0 & 0.0 & 0.0 & -9.0\\\\\\end{array}\\right)\\end{equation*}" ], "text/plain": [ "Quantum object: dims = [[10], [10]], shape = (10, 10), type = oper, isherm = True\n", "Qobj data =\n", "[[ 1. 0. 0. 0. 0. 0. 0. 0. 0. 0.]\n", " [ 0. 1. 0. 0. 0. 0. 0. 0. 0. 0.]\n", " [ 0. 0. 1. 0. 0. 0. 0. 0. 0. 0.]\n", " [ 0. 0. 0. 1. 0. 0. 0. 0. 0. 0.]\n", " [ 0. 0. 0. 0. 1. 0. 0. 0. 0. 0.]\n", " [ 0. 0. 0. 0. 0. 1. 0. 0. 0. 0.]\n", " [ 0. 0. 0. 0. 0. 0. 1. 0. 0. 0.]\n", " [ 0. 0. 0. 0. 0. 0. 0. 1. 0. 0.]\n", " [ 0. 0. 0. 0. 0. 0. 0. 0. 1. 0.]\n", " [ 0. 0. 0. 0. 0. 0. 0. 0. 0. -9.]]" ] }, "execution_count": 3, "metadata": {}, "output_type": "execute_result" } ], "source": [ "a*a.dag() - a.dag()*a" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "## Problem 12.2:" ] }, { "cell_type": "code", "execution_count": 4, "metadata": {}, "outputs": [ { "data": { "text/latex": [ "Quantum object: dims = [[10], [10]], shape = (10, 10), type = oper, isherm = False\\begin{equation*}\\left(\\begin{array}{*{11}c}0.0 & 0.0 & 0.0 & 0.0 & 0.0 & 0.0 & 0.0 & 0.0 & 0.0 & 0.0\\\\1.0 & 0.0 & 0.0 & 0.0 & 0.0 & 0.0 & 0.0 & 0.0 & 0.0 & 0.0\\\\0.0 & 1.414 & 0.0 & 0.0 & 0.0 & 0.0 & 0.0 & 0.0 & 0.0 & 0.0\\\\0.0 & 0.0 & 1.732 & 0.0 & 0.0 & 0.0 & 0.0 & 0.0 & 0.0 & 0.0\\\\0.0 & 0.0 & 0.0 & 2.0 & 0.0 & 0.0 & 0.0 & 0.0 & 0.0 & 0.0\\\\0.0 & 0.0 & 0.0 & 0.0 & 2.236 & 0.0 & 0.0 & 0.0 & 0.0 & 0.0\\\\0.0 & 0.0 & 0.0 & 0.0 & 0.0 & 2.449 & 0.0 & 0.0 & 0.0 & 0.0\\\\0.0 & 0.0 & 0.0 & 0.0 & 0.0 & 0.0 & 2.646 & 0.0 & 0.0 & 0.0\\\\0.0 & 0.0 & 0.0 & 0.0 & 0.0 & 0.0 & 0.0 & 2.828 & 0.0 & 0.0\\\\0.0 & 0.0 & 0.0 & 0.0 & 0.0 & 0.0 & 0.0 & 0.0 & 3.000 & 0.0\\\\\\end{array}\\right)\\end{equation*}" ], "text/plain": [ "Quantum object: dims = [[10], [10]], shape = (10, 10), type = oper, isherm = False\n", "Qobj data =\n", "[[ 0. 0. 0. 0. 0. 0. 0.\n", " 0. 0. 0. ]\n", " [ 1. 0. 0. 0. 0. 0. 0.\n", " 0. 0. 0. ]\n", " [ 0. 1.41421356 0. 0. 0. 0. 0.\n", " 0. 0. 0. ]\n", " [ 0. 0. 1.73205081 0. 0. 0. 0.\n", " 0. 0. 0. ]\n", " [ 0. 0. 0. 2. 0. 0. 0.\n", " 0. 0. 0. ]\n", " [ 0. 0. 0. 0. 2.23606798 0. 0.\n", " 0. 0. 0. ]\n", " [ 0. 0. 0. 0. 0. 2.44948974\n", " 0. 0. 0. 0. ]\n", " [ 0. 0. 0. 0. 0. 0.\n", " 2.64575131 0. 0. 0. ]\n", " [ 0. 0. 0. 0. 0. 0. 0.\n", " 2.82842712 0. 0. ]\n", " [ 0. 0. 0. 0. 0. 0. 0.\n", " 0. 3. 0. ]]" ] }, "execution_count": 4, "metadata": {}, "output_type": "execute_result" } ], "source": [ "n*a.dag() - a.dag()*n" ] }, { "cell_type": "code", "execution_count": 5, "metadata": {}, "outputs": [ { "data": { "text/plain": [ "True" ] }, "execution_count": 5, "metadata": {}, "output_type": "execute_result" } ], "source": [ "n*a.dag() - a.dag()*n == a.dag()" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "## Problem 12.3 (use n=2 as a test-case):\n", "To define $|2\\rangle$ use the `basis(N,n)` command where `N` is the dimension of the vector, and `n` is the quantum number." ] }, { "cell_type": "code", "execution_count": 6, "metadata": {}, "outputs": [], "source": [ "psi = basis(N,2)" ] }, { "cell_type": "code", "execution_count": 7, "metadata": { "inputHidden": false, "outputHidden": false }, "outputs": [ { "data": { "text/latex": [ "Quantum object: dims = [[10], [1]], shape = (10, 1), type = ket\\begin{equation*}\\left(\\begin{array}{*{11}c}0.0\\\\0.0\\\\1.0\\\\0.0\\\\0.0\\\\0.0\\\\0.0\\\\0.0\\\\0.0\\\\0.0\\\\\\end{array}\\right)\\end{equation*}" ], "text/plain": [ "Quantum object: dims = [[10], [1]], shape = (10, 1), type = ket\n", "Qobj data =\n", "[[ 0.]\n", " [ 0.]\n", " [ 1.]\n", " [ 0.]\n", " [ 0.]\n", " [ 0.]\n", " [ 0.]\n", " [ 0.]\n", " [ 0.]\n", " [ 0.]]" ] }, "execution_count": 7, "metadata": {}, "output_type": "execute_result" } ], "source": [ "psi" ] }, { "cell_type": "code", "execution_count": 8, "metadata": {}, "outputs": [ { "data": { "text/latex": [ "Quantum object: dims = [[10], [1]], shape = (10, 1), type = ket\\begin{equation*}\\left(\\begin{array}{*{11}c}0.0\\\\0.0\\\\0.0\\\\1.732\\\\0.0\\\\0.0\\\\0.0\\\\0.0\\\\0.0\\\\0.0\\\\\\end{array}\\right)\\end{equation*}" ], "text/plain": [ "Quantum object: dims = [[10], [1]], shape = (10, 1), type = ket\n", "Qobj data =\n", "[[ 0. ]\n", " [ 0. ]\n", " [ 0. ]\n", " [ 1.73205081]\n", " [ 0. ]\n", " [ 0. ]\n", " [ 0. ]\n", " [ 0. ]\n", " [ 0. ]\n", " [ 0. ]]" ] }, "execution_count": 8, "metadata": {}, "output_type": "execute_result" } ], "source": [ "a.dag()*psi" ] }, { "cell_type": "code", "execution_count": 9, "metadata": {}, "outputs": [ { "data": { "text/plain": [ "True" ] }, "execution_count": 9, "metadata": {}, "output_type": "execute_result" } ], "source": [ "a.dag()*basis(N,2) == sqrt(3)*basis(N,3)" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "## Problem 12.5 and 12.6:\n", "These are simple, just view the matrix representation of the operators" ] }, { "cell_type": "code", "execution_count": 10, "metadata": {}, "outputs": [ { "data": { "text/latex": [ "Quantum object: dims = [[10], [10]], shape = (10, 10), type = oper, isherm = False\\begin{equation*}\\left(\\begin{array}{*{11}c}0.0 & 1.0 & 0.0 & 0.0 & 0.0 & 0.0 & 0.0 & 0.0 & 0.0 & 0.0\\\\0.0 & 0.0 & 1.414 & 0.0 & 0.0 & 0.0 & 0.0 & 0.0 & 0.0 & 0.0\\\\0.0 & 0.0 & 0.0 & 1.732 & 0.0 & 0.0 & 0.0 & 0.0 & 0.0 & 0.0\\\\0.0 & 0.0 & 0.0 & 0.0 & 2.0 & 0.0 & 0.0 & 0.0 & 0.0 & 0.0\\\\0.0 & 0.0 & 0.0 & 0.0 & 0.0 & 2.236 & 0.0 & 0.0 & 0.0 & 0.0\\\\0.0 & 0.0 & 0.0 & 0.0 & 0.0 & 0.0 & 2.449 & 0.0 & 0.0 & 0.0\\\\0.0 & 0.0 & 0.0 & 0.0 & 0.0 & 0.0 & 0.0 & 2.646 & 0.0 & 0.0\\\\0.0 & 0.0 & 0.0 & 0.0 & 0.0 & 0.0 & 0.0 & 0.0 & 2.828 & 0.0\\\\0.0 & 0.0 & 0.0 & 0.0 & 0.0 & 0.0 & 0.0 & 0.0 & 0.0 & 3.0\\\\0.0 & 0.0 & 0.0 & 0.0 & 0.0 & 0.0 & 0.0 & 0.0 & 0.0 & 0.0\\\\\\end{array}\\right)\\end{equation*}" ], "text/plain": [ "Quantum object: dims = [[10], [10]], shape = (10, 10), type = oper, isherm = False\n", "Qobj data =\n", "[[ 0. 1. 0. 0. 0. 0. 0.\n", " 0. 0. 0. ]\n", " [ 0. 0. 1.41421356 0. 0. 0. 0.\n", " 0. 0. 0. ]\n", " [ 0. 0. 0. 1.73205081 0. 0. 0.\n", " 0. 0. 0. ]\n", " [ 0. 0. 0. 0. 2. 0. 0.\n", " 0. 0. 0. ]\n", " [ 0. 0. 0. 0. 0. 2.23606798\n", " 0. 0. 0. 0. ]\n", " [ 0. 0. 0. 0. 0. 0.\n", " 2.44948974 0. 0. 0. ]\n", " [ 0. 0. 0. 0. 0. 0. 0.\n", " 2.64575131 0. 0. ]\n", " [ 0. 0. 0. 0. 0. 0. 0.\n", " 0. 2.82842712 0. ]\n", " [ 0. 0. 0. 0. 0. 0. 0.\n", " 0. 0. 3. ]\n", " [ 0. 0. 0. 0. 0. 0. 0.\n", " 0. 0. 0. ]]" ] }, "execution_count": 10, "metadata": {}, "output_type": "execute_result" } ], "source": [ "a" ] }, { "cell_type": "code", "execution_count": 11, "metadata": {}, "outputs": [ { "data": { "text/latex": [ "Quantum object: dims = [[10], [10]], shape = (10, 10), type = oper, isherm = False\\begin{equation*}\\left(\\begin{array}{*{11}c}0.0 & 0.0 & 0.0 & 0.0 & 0.0 & 0.0 & 0.0 & 0.0 & 0.0 & 0.0\\\\1.0 & 0.0 & 0.0 & 0.0 & 0.0 & 0.0 & 0.0 & 0.0 & 0.0 & 0.0\\\\0.0 & 1.414 & 0.0 & 0.0 & 0.0 & 0.0 & 0.0 & 0.0 & 0.0 & 0.0\\\\0.0 & 0.0 & 1.732 & 0.0 & 0.0 & 0.0 & 0.0 & 0.0 & 0.0 & 0.0\\\\0.0 & 0.0 & 0.0 & 2.0 & 0.0 & 0.0 & 0.0 & 0.0 & 0.0 & 0.0\\\\0.0 & 0.0 & 0.0 & 0.0 & 2.236 & 0.0 & 0.0 & 0.0 & 0.0 & 0.0\\\\0.0 & 0.0 & 0.0 & 0.0 & 0.0 & 2.449 & 0.0 & 0.0 & 0.0 & 0.0\\\\0.0 & 0.0 & 0.0 & 0.0 & 0.0 & 0.0 & 2.646 & 0.0 & 0.0 & 0.0\\\\0.0 & 0.0 & 0.0 & 0.0 & 0.0 & 0.0 & 0.0 & 2.828 & 0.0 & 0.0\\\\0.0 & 0.0 & 0.0 & 0.0 & 0.0 & 0.0 & 0.0 & 0.0 & 3.0 & 0.0\\\\\\end{array}\\right)\\end{equation*}" ], "text/plain": [ "Quantum object: dims = [[10], [10]], shape = (10, 10), type = oper, isherm = False\n", "Qobj data =\n", "[[ 0. 0. 0. 0. 0. 0. 0.\n", " 0. 0. 0. ]\n", " [ 1. 0. 0. 0. 0. 0. 0.\n", " 0. 0. 0. ]\n", " [ 0. 1.41421356 0. 0. 0. 0. 0.\n", " 0. 0. 0. ]\n", " [ 0. 0. 1.73205081 0. 0. 0. 0.\n", " 0. 0. 0. ]\n", " [ 0. 0. 0. 2. 0. 0. 0.\n", " 0. 0. 0. ]\n", " [ 0. 0. 0. 0. 2.23606798 0. 0.\n", " 0. 0. 0. ]\n", " [ 0. 0. 0. 0. 0. 2.44948974\n", " 0. 0. 0. 0. ]\n", " [ 0. 0. 0. 0. 0. 0.\n", " 2.64575131 0. 0. 0. ]\n", " [ 0. 0. 0. 0. 0. 0. 0.\n", " 2.82842712 0. 0. ]\n", " [ 0. 0. 0. 0. 0. 0. 0.\n", " 0. 3. 0. ]]" ] }, "execution_count": 11, "metadata": {}, "output_type": "execute_result" } ], "source": [ "a.dag()" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "## Problem 12.7:\n", "First, define $\\hat{X}$ and $\\hat{P}$ operators" ] }, { "cell_type": "code", "execution_count": 12, "metadata": {}, "outputs": [], "source": [ "X = 1/2 * (a + a.dag())\n", "P = 1/2j * (a - a.dag())" ] }, { "cell_type": "code", "execution_count": 13, "metadata": {}, "outputs": [], "source": [ "psi = 1/sqrt(2)*(basis(N,1)+basis(N,2))\n", "ex = psi.dag()*X*psi\n", "exq = psi.dag()*X*X*psi\n", "ep = psi.dag()*P*psi\n", "epq = psi.dag()*P*P*psi" ] }, { "cell_type": "code", "execution_count": 14, "metadata": {}, "outputs": [], "source": [ "deltaX = sqrt(exq[0][0][0] - ex[0][0][0]**2)\n", "deltaP = sqrt(epq[0][0][0] - ep[0][0][0]**2)" ] }, { "cell_type": "code", "execution_count": 15, "metadata": {}, "outputs": [ { "data": { "text/plain": [ "(1.4142135623730951+0j)" ] }, "execution_count": 15, "metadata": {}, "output_type": "execute_result" } ], "source": [ "deltaX * deltaP * 2 # compare to uncertainty relation (ΔxΔp >= 1/2)\n", "# the factor of two is to convert from the unitless version of the operator" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "Alternatively, we can find the indeterminacy bound for ΔX and ΔP (the unitless operators): $$\\Delta X \\Delta P \\geq \\frac{1}{2}\\left|\\left\\langle \\left[\\hat{X},\\hat{P}\\right] \\right\\rangle\\right|$$" ] }, { "cell_type": "code", "execution_count": 31, "metadata": {}, "outputs": [ { "data": { "text/plain": [ "0.24999999999999994" ] }, "execution_count": 31, "metadata": {}, "output_type": "execute_result" } ], "source": [ "1/2*(psi.dag()*commutator(X,P)*psi).norm()" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "Which is also satisfied by the calculated value (1.41 > 0.25)" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "## Problem 12.8:" ] }, { "cell_type": "code", "execution_count": 16, "metadata": {}, "outputs": [], "source": [ "psi = 1/sqrt(2)*(basis(N,2)+basis(N,4))\n", "ex = psi.dag()*X*psi\n", "exq = psi.dag()*X*X*psi\n", "ep = psi.dag()*P*psi\n", "epq = psi.dag()*P*P*psi" ] }, { "cell_type": "code", "execution_count": 17, "metadata": {}, "outputs": [], "source": [ "deltaX = sqrt(exq[0][0][0] - ex[0][0][0]**2)\n", "deltaP = sqrt(epq[0][0][0] - ep[0][0][0]**2)" ] }, { "cell_type": "code", "execution_count": 19, "metadata": {}, "outputs": [ { "data": { "text/plain": [ "(3.0413812651491092+0j)" ] }, "execution_count": 19, "metadata": {}, "output_type": "execute_result" } ], "source": [ "deltaX * deltaP * 2 # to compare to book solution which uses the full x and p operators with units" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [] } ], "metadata": { "kernel_info": { "name": "python3" }, "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.3" }, "nteract": { "version": "0.8.4" } }, "nbformat": 4, "nbformat_minor": 1 }