{ "cells": [ { "cell_type": "markdown", "metadata": {}, "source": [ "## QobjEvo usage example\n", "Features of QobjEvo for the users. \n", "Made by Eric Giguere" ] }, { "cell_type": "code", "execution_count": 1, "metadata": {}, "outputs": [], "source": [ "from qutip import *\n", "import time\n", "import numpy as np" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "## Definition of time-dependant Qobj\n", "\n", "QobjEvo are definied from list of Qobj: \n", "[Qobj0, [Qobj1, coeff1], [Qobj2, coeff2]] \n", "coeff can be one of: \n", "- function\n", "- string\n", "- np.array" ] }, { "cell_type": "code", "execution_count": 2, "metadata": {}, "outputs": [], "source": [ "# Definition of base Qobj and \n", "N = 4\n", "\n", "def sin_w(t, args):\n", " return np.cos(args[\"w\"]*t)\n", "\n", "def cos_w(t, args):\n", " return np.cos(args[\"w\"]*t)\n", "\n", "tlist = np.linspace(0,10,10000)\n", "tlistlog = np.logspace(-3,1,10000)\n" ] }, { "cell_type": "code", "execution_count": 3, "metadata": {}, "outputs": [ { "data": { "text/latex": [ "Quantum object: dims = [[4], [4]], shape = (4, 4), type = oper, isherm = False\\begin{equation*}\\left(\\begin{array}{*{11}c}0.0 & 1.0 & 0.0 & 0.0\\\\0.0 & 0.0 & 1.414 & 0.0\\\\0.0 & 0.0 & 0.0 & 1.732\\\\0.0 & 0.0 & 0.0 & 0.0\\\\\\end{array}\\right)\\end{equation*}" ], "text/plain": [ "Quantum object: dims = [[4], [4]], shape = (4, 4), type = oper, isherm = False\n", "Qobj data =\n", "[[0. 1. 0. 0. ]\n", " [0. 0. 1.41421356 0. ]\n", " [0. 0. 0. 1.73205081]\n", " [0. 0. 0. 0. ]]" ] }, "execution_count": 3, "metadata": {}, "output_type": "execute_result" } ], "source": [ "# constant QobjEvo\n", "cte_QobjEvo = QobjEvo(destroy(N))\n", "cte_QobjEvo(1)" ] }, { "cell_type": "code", "execution_count": 4, "metadata": {}, "outputs": [ { "data": { "text/latex": [ "Quantum object: dims = [[4], [4]], shape = (4, 4), type = oper, isherm = False\\begin{equation*}\\left(\\begin{array}{*{11}c}-0.416 & 1.0 & 0.0 & 0.0\\\\0.0 & -0.416 & 1.414 & 0.0\\\\0.0 & 0.0 & -0.416 & 1.732\\\\0.0 & 0.0 & 0.0 & -0.416\\\\\\end{array}\\right)\\end{equation*}" ], "text/plain": [ "Quantum object: dims = [[4], [4]], shape = (4, 4), type = oper, isherm = False\n", "Qobj data =\n", "[[-0.41614684 1. 0. 0. ]\n", " [ 0. -0.41614684 1.41421356 0. ]\n", " [ 0. 0. -0.41614684 1.73205081]\n", " [ 0. 0. 0. -0.41614684]]" ] }, "execution_count": 4, "metadata": {}, "output_type": "execute_result" } ], "source": [ "# QobjEvo with function based coeff\n", "func_QobjEvo = QobjEvo([destroy(N),[qeye(N),cos_w]],args={\"w\":2})\n", "func_QobjEvo(1)" ] }, { "cell_type": "code", "execution_count": 5, "metadata": {}, "outputs": [ { "data": { "text/latex": [ "Quantum object: dims = [[4], [4]], shape = (4, 4), type = oper, isherm = False\\begin{equation*}\\left(\\begin{array}{*{11}c}-0.416 & 1.0 & 0.0 & 0.0\\\\0.0 & -0.416 & 1.414 & 0.0\\\\0.0 & 0.0 & -0.416 & 1.732\\\\0.0 & 0.0 & 0.0 & -0.416\\\\\\end{array}\\right)\\end{equation*}" ], "text/plain": [ "Quantum object: dims = [[4], [4]], shape = (4, 4), type = oper, isherm = False\n", "Qobj data =\n", "[[-0.41614684 1. 0. 0. ]\n", " [ 0. -0.41614684 1.41421356 0. ]\n", " [ 0. 0. -0.41614684 1.73205081]\n", " [ 0. 0. 0. -0.41614684]]" ] }, "execution_count": 5, "metadata": {}, "output_type": "execute_result" } ], "source": [ "# QobjEvo with sting based coeff\n", "str_QobjEvo = QobjEvo([destroy(N),[qeye(N),\"cos(w*t)\"]],args={\"w\":2})\n", "str_QobjEvo(1)" ] }, { "cell_type": "code", "execution_count": 6, "metadata": {}, "outputs": [ { "data": { "text/latex": [ "Quantum object: dims = [[4], [4]], shape = (4, 4), type = oper, isherm = False\\begin{equation*}\\left(\\begin{array}{*{11}c}-0.416 & 1.0 & 0.0 & 0.0\\\\0.0 & -0.416 & 1.414 & 0.0\\\\0.0 & 0.0 & -0.416 & 1.732\\\\0.0 & 0.0 & 0.0 & -0.416\\\\\\end{array}\\right)\\end{equation*}" ], "text/plain": [ "Quantum object: dims = [[4], [4]], shape = (4, 4), type = oper, isherm = False\n", "Qobj data =\n", "[[-0.41614684 1. 0. 0. ]\n", " [ 0. -0.41614684 1.41421356 0. ]\n", " [ 0. 0. -0.41614684 1.73205081]\n", " [ 0. 0. 0. -0.41614684]]" ] }, "execution_count": 6, "metadata": {}, "output_type": "execute_result" } ], "source": [ "# QobjEvo with array based coeff\n", "array_QobjEvo = QobjEvo([destroy(N),[qeye(N),np.cos(2*tlist)]],tlist=tlist)\n", "array_QobjEvo(1)" ] }, { "cell_type": "code", "execution_count": 7, "metadata": {}, "outputs": [ { "data": { "text/latex": [ "Quantum object: dims = [[4], [4]], shape = (4, 4), type = oper, isherm = False\\begin{equation*}\\left(\\begin{array}{*{11}c}-0.416 & 1.0 & 0.0 & 0.0\\\\0.0 & -0.416 & 1.414 & 0.0\\\\0.0 & 0.0 & -0.416 & 1.732\\\\0.0 & 0.0 & 0.0 & -0.416\\\\\\end{array}\\right)\\end{equation*}" ], "text/plain": [ "Quantum object: dims = [[4], [4]], shape = (4, 4), type = oper, isherm = False\n", "Qobj data =\n", "[[-0.41614684 1. 0. 0. ]\n", " [ 0. -0.41614684 1.41421356 0. ]\n", " [ 0. 0. -0.41614684 1.73205081]\n", " [ 0. 0. 0. -0.41614684]]" ] }, "execution_count": 7, "metadata": {}, "output_type": "execute_result" } ], "source": [ "# QobjEvo with array based coeff, log timescale\n", "Log_array_QobjEvo = QobjEvo([destroy(N),[qeye(N),np.cos(2*tlistlog)]],tlist=tlistlog)\n", "Log_array_QobjEvo(1)" ] }, { "cell_type": "code", "execution_count": 8, "metadata": {}, "outputs": [ { "data": { "text/latex": [ "Quantum object: dims = [[4], [4]], shape = (4, 4), type = oper, isherm = False\\begin{equation*}\\left(\\begin{array}{*{11}c}-0.416 & 1.0 & 0.0 & 0.0\\\\0.0 & -0.416 & 1.414 & 0.0\\\\0.0 & 0.0 & -0.416 & 1.732\\\\0.0 & 0.0 & 0.0 & -0.416\\\\\\end{array}\\right)\\end{equation*}" ], "text/plain": [ "Quantum object: dims = [[4], [4]], shape = (4, 4), type = oper, isherm = False\n", "Qobj data =\n", "[[-0.41614684 1. 0. 0. ]\n", " [ 0. -0.41614684 1.41421356 0. ]\n", " [ 0. 0. -0.41614684 1.73205081]\n", " [ 0. 0. 0. -0.41614684]]" ] }, "execution_count": 8, "metadata": {}, "output_type": "execute_result" } ], "source": [ "# Reference\n", "destroy(N) + qeye(N) * np.cos(2)" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "## Mathematic\n", "- addition (QobjEvo, Qobj)\n", "- substraction (QobjEvo, Qobj)\n", "- product (QobjEvo, Qobj, scalar)\n", "- division (scalar)\n", "\n", "The examples are done with function type coefficients only, but work for any type of coefficient. \n", "Mixing coefficients type is possible, however this support would be removed if QobjEvo * QobjEvo is to be implemented." ] }, { "cell_type": "code", "execution_count": 9, "metadata": {}, "outputs": [], "source": [ "# Build objects\n", "o1 = QobjEvo([qeye(N),[destroy(N),sin_w]],args={\"w\":2})\n", "o2 = QobjEvo([qeye(N),[create(N),cos_w]],args={\"w\":2})\n", "t = np.random.random()*10" ] }, { "cell_type": "code", "execution_count": 10, "metadata": {}, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "True\n", "True\n", "True\n", "True\n" ] } ], "source": [ "# addition and subtraction \n", "o3 = o1 + o2\n", "print(o3(t) == o1(t) + o2(t))\n", "o3 = o1 - o2\n", "print(o3(t) == o1(t) - o2(t))\n", "o3 = o1 + destroy(N)\n", "print(o3(t) == o1(t) + destroy(N))\n", "o3 = o1 - destroy(N)\n", "print(o3(t) == o1(t) - destroy(N))" ] }, { "cell_type": "code", "execution_count": 11, "metadata": {}, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "True\n", "True\n", "True\n", "True\n", "True\n", "True\n" ] } ], "source": [ "# product\n", "oc = QobjEvo([qeye(N)])\n", "o3 = o1 * destroy(N)\n", "print(o3(t) == o1(t) * destroy(N))\n", "o3 = o1 * (0.5+0.5j)\n", "print(o3(t) == o1(t) * (0.5+0.5j))\n", "o3 = o1 / (0.5+0.5j)\n", "print(o3(t) == o1(t) / (0.5+0.5j))\n", "o3 = o1 * oc\n", "print(o3(t) == o1(t) * oc(t))\n", "o3 = oc * o1\n", "print(o3(t) == oc(t) * o1(t))\n", "o3 = o1 * o2\n", "print(o3(t) == o1(t) * o2(t))" ] }, { "cell_type": "code", "execution_count": 12, "metadata": {}, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "True\n" ] } ], "source": [ "o1 = QobjEvo([qeye(N),[destroy(N),sin_w]],args={\"w\":2})\n", "o2 = QobjEvo([qeye(N),[create(N),cos_w]],args={\"w\":2})\n", "o1 += o2\n", "print(o1(t) == (qeye(N)*2 + destroy(N)*sin_w(t,args={\"w\":2}) + create(N)*cos_w(t,args={\"w\":2})))" ] }, { "cell_type": "code", "execution_count": 13, "metadata": {}, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "True\n", "True\n" ] } ], "source": [ "o1 = QobjEvo([qeye(N),[destroy(N),sin_w]],args={\"w\":2})\n", "o2 = QobjEvo([qeye(N),[create(N),cos_w]],args={\"w\":2})\n", "o1 -= o2\n", "print(o1(t) == (destroy(N)*sin_w(t,args={\"w\":2}) - create(N)*cos_w(t,args={\"w\":2})))\n", "\n", "o1 = QobjEvo([qeye(N),[destroy(N),sin_w]],args={\"w\":2})\n", "o2 = QobjEvo([qeye(N),[create(N),cos_w]],args={\"w\":2})\n", "o1 += -o2\n", "print(o1(t) == (destroy(N)*sin_w(t,args={\"w\":2}) - create(N)*cos_w(t,args={\"w\":2})))" ] }, { "cell_type": "code", "execution_count": 14, "metadata": {}, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "True\n" ] } ], "source": [ "o1 = QobjEvo([qeye(N),[destroy(N),sin_w]],args={\"w\":2})\n", "o1 *= destroy(N)\n", "print(o1(t) == (destroy(N) + destroy(N)*destroy(N)*sin_w(t,args={\"w\":2})))" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "## Unitary operations: \n", "- conj\n", "- dag \n", "- trans \n", "- _cdc: QobjEvo.dag * QobjEvo" ] }, { "cell_type": "code", "execution_count": 15, "metadata": {}, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "True\n", "True\n", "True\n", "True\n", "True\n", "True\n" ] } ], "source": [ "o_real = QobjEvo([qeye(N),[destroy(N), sin_w]], args={\"w\":2})\n", "o_cplx = QobjEvo([qeye(N),[create(N), cos_w]], args={\"w\":-1j})\n", "\n", "print(o_real(t).trans() == o_real.trans()(t))\n", "print(o_real(t).conj() == o_real.conj()(t))\n", "print(o_real(t).dag() == o_real.dag()(t))\n", "\n", "print(o_cplx(t).trans() == o_cplx.trans()(t))\n", "print(o_cplx(t).conj() == o_cplx.conj()(t))\n", "print(o_cplx(t).dag() == o_cplx.dag()(t))" ] }, { "cell_type": "code", "execution_count": 16, "metadata": {}, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "True\n", "True\n", "True\n", "True\n" ] } ], "source": [ "# the operator norm correspond to c.dag * c.\n", "td_cplx_f0 = qobjevo.QobjEvo([qeye(N)])\n", "td_cplx_f1 = qobjevo.QobjEvo([qeye(N),[destroy(N)*create(N),sin_w]], args={'w':2.+0.001j})\n", "td_cplx_f2 = qobjevo.QobjEvo([qeye(N),[destroy(N),cos_w]], args={'w':2.+0.001j})\n", "td_cplx_f3 = qobjevo.QobjEvo([qeye(N),[create(N),1j*np.sin(tlist)]], tlist=tlist)\n", "\n", "print(td_cplx_f0(t).dag()*td_cplx_f0(t) == td_cplx_f0._cdc()(t))\n", "print(td_cplx_f1(t).dag()*td_cplx_f1(t) == td_cplx_f1._cdc()(t))\n", "print(td_cplx_f2(t).dag()*td_cplx_f2(t) == td_cplx_f2._cdc()(t))\n", "print(td_cplx_f3(t).dag()*td_cplx_f3(t) == td_cplx_f3._cdc()(t))" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "## Liouvillian and lindblad dissipator, to use in solver\n", "\n", "Functions in qutip.superoperator can be used for QobjEvo." ] }, { "cell_type": "code", "execution_count": 17, "metadata": {}, "outputs": [ { "data": { "text/plain": [ "True" ] }, "execution_count": 17, "metadata": {}, "output_type": "execute_result" } ], "source": [ "td_L = liouvillian(H=func_QobjEvo)\n", "L = liouvillian(H=func_QobjEvo(t))\n", "td_L(t) == L" ] }, { "cell_type": "code", "execution_count": 18, "metadata": {}, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "True\n" ] } ], "source": [ "td_cplx_f0 = qobjevo.QobjEvo([qeye(N)])\n", "td_cplx_f1 = qobjevo.QobjEvo([[destroy(N)*create(N),sin_w]], args={'w':2.})\n", "\n", "td_L = liouvillian(H=func_QobjEvo,c_ops=[td_cplx_f0,td_cplx_f1])\n", "L = liouvillian(H=func_QobjEvo(t),c_ops=[td_cplx_f0(t),td_cplx_f1(t)])\n", "print(td_L(t) == L)" ] }, { "cell_type": "code", "execution_count": 19, "metadata": {}, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "True\n" ] } ], "source": [ "td_P = spre(td_cplx_f1)\n", "P = spre(td_cplx_f1(t))\n", "print(td_P(t) == P)" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "## Getting the list back for the object" ] }, { "cell_type": "code", "execution_count": 20, "metadata": { "scrolled": true }, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "[Quantum object: dims = [[[4], [4]], [[4], [4]]], shape = (16, 16), type = super, isherm = False\n", "Qobj data =\n", "[[0.+0.j 0.-1.j 0.+0.j 0.+0.j\n", " 0.+0.j 0.+0.j 0.+0.j 0.+0.j\n", " 0.+0.j 0.+0.j 0.+0.j 0.+0.j\n", " 0.+0.j 0.+0.j 0.+0.j 0.+0.j ]\n", " [0.+0.j 0.+0.j 0.-1.41421356j 0.+0.j\n", " 0.+0.j 0.+0.j 0.+0.j 0.+0.j\n", " 0.+0.j 0.+0.j 0.+0.j 0.+0.j\n", " 0.+0.j 0.+0.j 0.+0.j 0.+0.j ]\n", " [0.+0.j 0.+0.j 0.+0.j 0.-1.73205081j\n", " 0.+0.j 0.+0.j 0.+0.j 0.+0.j\n", " 0.+0.j 0.+0.j 0.+0.j 0.+0.j\n", " 0.+0.j 0.+0.j 0.+0.j 0.+0.j ]\n", " [0.+0.j 0.+0.j 0.+0.j 0.+0.j\n", " 0.+0.j 0.+0.j 0.+0.j 0.+0.j\n", " 0.+0.j 0.+0.j 0.+0.j 0.+0.j\n", " 0.+0.j 0.+0.j 0.+0.j 0.+0.j ]\n", " [0.+1.j 0.+0.j 0.+0.j 0.+0.j\n", " 0.+0.j 0.-1.j 0.+0.j 0.+0.j\n", " 0.+0.j 0.+0.j 0.+0.j 0.+0.j\n", " 0.+0.j 0.+0.j 0.+0.j 0.+0.j ]\n", " [0.+0.j 0.+1.j 0.+0.j 0.+0.j\n", " 0.+0.j 0.+0.j 0.-1.41421356j 0.+0.j\n", " 0.+0.j 0.+0.j 0.+0.j 0.+0.j\n", " 0.+0.j 0.+0.j 0.+0.j 0.+0.j ]\n", " [0.+0.j 0.+0.j 0.+1.j 0.+0.j\n", " 0.+0.j 0.+0.j 0.+0.j 0.-1.73205081j\n", " 0.+0.j 0.+0.j 0.+0.j 0.+0.j\n", " 0.+0.j 0.+0.j 0.+0.j 0.+0.j ]\n", " [0.+0.j 0.+0.j 0.+0.j 0.+1.j\n", " 0.+0.j 0.+0.j 0.+0.j 0.+0.j\n", " 0.+0.j 0.+0.j 0.+0.j 0.+0.j\n", " 0.+0.j 0.+0.j 0.+0.j 0.+0.j ]\n", " [0.+0.j 0.+0.j 0.+0.j 0.+0.j\n", " 0.+1.41421356j 0.+0.j 0.+0.j 0.+0.j\n", " 0.+0.j 0.-1.j 0.+0.j 0.+0.j\n", " 0.+0.j 0.+0.j 0.+0.j 0.+0.j ]\n", " [0.+0.j 0.+0.j 0.+0.j 0.+0.j\n", " 0.+0.j 0.+1.41421356j 0.+0.j 0.+0.j\n", " 0.+0.j 0.+0.j 0.-1.41421356j 0.+0.j\n", " 0.+0.j 0.+0.j 0.+0.j 0.+0.j ]\n", " [0.+0.j 0.+0.j 0.+0.j 0.+0.j\n", " 0.+0.j 0.+0.j 0.+1.41421356j 0.+0.j\n", " 0.+0.j 0.+0.j 0.+0.j 0.-1.73205081j\n", " 0.+0.j 0.+0.j 0.+0.j 0.+0.j ]\n", " [0.+0.j 0.+0.j 0.+0.j 0.+0.j\n", " 0.+0.j 0.+0.j 0.+0.j 0.+1.41421356j\n", " 0.+0.j 0.+0.j 0.+0.j 0.+0.j\n", " 0.+0.j 0.+0.j 0.+0.j 0.+0.j ]\n", " [0.+0.j 0.+0.j 0.+0.j 0.+0.j\n", " 0.+0.j 0.+0.j 0.+0.j 0.+0.j\n", " 0.+1.73205081j 0.+0.j 0.+0.j 0.+0.j\n", " 0.+0.j 0.-1.j 0.+0.j 0.+0.j ]\n", " [0.+0.j 0.+0.j 0.+0.j 0.+0.j\n", " 0.+0.j 0.+0.j 0.+0.j 0.+0.j\n", " 0.+0.j 0.+1.73205081j 0.+0.j 0.+0.j\n", " 0.+0.j 0.+0.j 0.-1.41421356j 0.+0.j ]\n", " [0.+0.j 0.+0.j 0.+0.j 0.+0.j\n", " 0.+0.j 0.+0.j 0.+0.j 0.+0.j\n", " 0.+0.j 0.+0.j 0.+1.73205081j 0.+0.j\n", " 0.+0.j 0.+0.j 0.+0.j 0.-1.73205081j]\n", " [0.+0.j 0.+0.j 0.+0.j 0.+0.j\n", " 0.+0.j 0.+0.j 0.+0.j 0.+0.j\n", " 0.+0.j 0.+0.j 0.+0.j 0.+1.73205081j\n", " 0.+0.j 0.+0.j 0.+0.j 0.+0.j ]], [Quantum object: dims = [[[4], [4]], [[4], [4]]], shape = (16, 16), type = super, isherm = True\n", "Qobj data =\n", "[[0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0.]\n", " [0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0.]\n", " [0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0.]\n", " [0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0.]\n", " [0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0.]\n", " [0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0.]\n", " [0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0.]\n", " [0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0.]\n", " [0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0.]\n", " [0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0.]\n", " [0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0.]\n", " [0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0.]\n", " [0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0.]\n", " [0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0.]\n", " [0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0.]\n", " [0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0.]], ], [Quantum object: dims = [[[4], [4]], [[4], [4]]], shape = (16, 16), type = super, isherm = True\n", "Qobj data =\n", "[[1. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0.]\n", " [0. 2. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0.]\n", " [0. 0. 3. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0.]\n", " [0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0.]\n", " [0. 0. 0. 0. 2. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0.]\n", " [0. 0. 0. 0. 0. 4. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0.]\n", " [0. 0. 0. 0. 0. 0. 6. 0. 0. 0. 0. 0. 0. 0. 0. 0.]\n", " [0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0.]\n", " [0. 0. 0. 0. 0. 0. 0. 0. 3. 0. 0. 0. 0. 0. 0. 0.]\n", " [0. 0. 0. 0. 0. 0. 0. 0. 0. 6. 0. 0. 0. 0. 0. 0.]\n", " [0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 9. 0. 0. 0. 0. 0.]\n", " [0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0.]\n", " [0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0.]\n", " [0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0.]\n", " [0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0.]\n", " [0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0.]], ], [Quantum object: dims = [[[4], [4]], [[4], [4]]], shape = (16, 16), type = super, isherm = True\n", "Qobj data =\n", "[[-0.5 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0.\n", " 0. 0. ]\n", " [ 0. -2. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0.\n", " 0. 0. ]\n", " [ 0. 0. -4.5 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0.\n", " 0. 0. ]\n", " [ 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0.\n", " 0. 0. ]\n", " [ 0. 0. 0. 0. -0.5 0. 0. 0. 0. 0. 0. 0. 0. 0.\n", " 0. 0. ]\n", " [ 0. 0. 0. 0. 0. -2. 0. 0. 0. 0. 0. 0. 0. 0.\n", " 0. 0. ]\n", " [ 0. 0. 0. 0. 0. 0. -4.5 0. 0. 0. 0. 0. 0. 0.\n", " 0. 0. ]\n", " [ 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0.\n", " 0. 0. ]\n", " [ 0. 0. 0. 0. 0. 0. 0. 0. -0.5 0. 0. 0. 0. 0.\n", " 0. 0. ]\n", " [ 0. 0. 0. 0. 0. 0. 0. 0. 0. -2. 0. 0. 0. 0.\n", " 0. 0. ]\n", " [ 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. -4.5 0. 0. 0.\n", " 0. 0. ]\n", " [ 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0.\n", " 0. 0. ]\n", " [ 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. -0.5 0.\n", " 0. 0. ]\n", " [ 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. -2.\n", " 0. 0. ]\n", " [ 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0.\n", " -4.5 0. ]\n", " [ 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0.\n", " 0. 0. ]], ], [Quantum object: dims = [[[4], [4]], [[4], [4]]], shape = (16, 16), type = super, isherm = True\n", "Qobj data =\n", "[[-0.5 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0.\n", " 0. 0. ]\n", " [ 0. -0.5 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0.\n", " 0. 0. ]\n", " [ 0. 0. -0.5 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0.\n", " 0. 0. ]\n", " [ 0. 0. 0. -0.5 0. 0. 0. 0. 0. 0. 0. 0. 0. 0.\n", " 0. 0. ]\n", " [ 0. 0. 0. 0. -2. 0. 0. 0. 0. 0. 0. 0. 0. 0.\n", " 0. 0. ]\n", " [ 0. 0. 0. 0. 0. -2. 0. 0. 0. 0. 0. 0. 0. 0.\n", " 0. 0. ]\n", " [ 0. 0. 0. 0. 0. 0. -2. 0. 0. 0. 0. 0. 0. 0.\n", " 0. 0. ]\n", " [ 0. 0. 0. 0. 0. 0. 0. -2. 0. 0. 0. 0. 0. 0.\n", " 0. 0. ]\n", " [ 0. 0. 0. 0. 0. 0. 0. 0. -4.5 0. 0. 0. 0. 0.\n", " 0. 0. ]\n", " [ 0. 0. 0. 0. 0. 0. 0. 0. 0. -4.5 0. 0. 0. 0.\n", " 0. 0. ]\n", " [ 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. -4.5 0. 0. 0.\n", " 0. 0. ]\n", " [ 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. -4.5 0. 0.\n", " 0. 0. ]\n", " [ 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0.\n", " 0. 0. ]\n", " [ 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0.\n", " 0. 0. ]\n", " [ 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0.\n", " 0. 0. ]\n", " [ 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0.\n", " 0. 0. ]], ]]\n" ] } ], "source": [ "print(td_L.to_list())" ] }, { "cell_type": "markdown", "metadata": { "collapsed": true }, "source": [ "## Arguments modification\n", "\n", "To change the args: qobjevo.arguments(new_args)\n", "\n", "Call with other arguments without changing them: qobjevo.with_args(t, new_args)\n" ] }, { "cell_type": "code", "execution_count": 21, "metadata": {}, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "True\n", "True\n", "True\n" ] } ], "source": [ "def Args(t, args):\n", " return args['w']\n", "td_args = qobjevo.QobjEvo([qeye(N), Args],args={'w':1.}) \n", "print(td_args(t) == qeye(N))\n", "td_args.arguments({'w':2.})\n", "print(td_args(t) == qeye(N)*2)\n", "print(td_args(t,args={'w':3.}) == qeye(N)*3)" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "When summing QobjEvo that have an arguments in common, only one is kept." ] }, { "cell_type": "code", "execution_count": 22, "metadata": { "scrolled": true }, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "False\n", "True\n", "True\n" ] } ], "source": [ "td_args_1 = qobjevo.QobjEvo([qeye(N), [destroy(N), Args]],args={'w':1.})\n", "td_args_2 = qobjevo.QobjEvo([qeye(N), [destroy(N), Args]],args={'w':2.})\n", "td_str_sum = td_args_1 + td_args_2\n", "\n", "# Only one value for args is kept\n", "print(td_str_sum(t) == td_args_1(t) + td_args_2(t)) \n", "print(td_str_sum(t) == 2*td_args_2(t)) \n", "\n", "# Updating args affect all part\n", "td_str_sum.arguments({'w':1.})\n", "print(td_str_sum(t) == 2*td_args_1(t))" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "Argument with different names are fine." ] }, { "cell_type": "code", "execution_count": 23, "metadata": {}, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "True\n" ] } ], "source": [ "def Args2(t, args):\n", " return args['x']\n", "td_args_1 = qobjevo.QobjEvo([qeye(N), [destroy(N), cos_w]],args={'w':1.})\n", "td_args_2 = qobjevo.QobjEvo([qeye(N), [destroy(N), Args2]],args={'x':2.})\n", "td_str_sum = td_args_1 + td_args_2\n", "\n", "# Only one value for args is kept\n", "print(td_str_sum(t) == td_args_1(t) + td_args_2(t))" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "## Other" ] }, { "cell_type": "code", "execution_count": 24, "metadata": {}, "outputs": [ { "data": { "text/plain": [ "<4x4 sparse matrix of type ''\n", "\twith 7 stored elements in Compressed Sparse Row format>" ] }, "execution_count": 24, "metadata": {}, "output_type": "execute_result" } ], "source": [ "# Obtain the sparce matrix at a time t instead of a Qobj\n", "str_QobjEvo(1, data=True)" ] }, { "cell_type": "code", "execution_count": 25, "metadata": {}, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "True\n", "False\n" ] } ], "source": [ "# Test is the QobjEvo does depend on time\n", "print(cte_QobjEvo.const)\n", "print(str_QobjEvo.const)" ] }, { "cell_type": "code", "execution_count": 26, "metadata": {}, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "[[4], [4]]\n", "(4, 4)\n", "True\n", "Quantum object: dims = [[4], [4]], shape = (4, 4), type = oper, isherm = True\n", "Qobj data =\n", "[[0. 0. 0. 0.]\n", " [0. 0. 0. 0.]\n", " [0. 0. 0. 0.]\n", " [0. 0. 0. 0.]]\n" ] } ], "source": [ "# Obtain the size, shape, oper flag etc:\n", "# The QobjEvo.cte always exist and contain the constant part of the QobjEvo\n", "# It can be used to get the shape, etc. since the QobjEvo do not directly have them.\n", "td_cplx_f1 = qobjevo.QobjEvo([[destroy(N)*create(N),sin_w]], args={'w':2.})\n", "print(td_cplx_f1.cte.dims)\n", "print(td_cplx_f1.cte.shape)\n", "print(td_cplx_f1.cte.isoper)\n", "print(td_cplx_f1.cte)" ] }, { "cell_type": "code", "execution_count": 27, "metadata": {}, "outputs": [ { "data": { "text/latex": [ "Quantum object: dims = [[4], [4]], shape = (4, 4), type = oper, isherm = True\\begin{equation*}\\left(\\begin{array}{*{11}c}1.0 & 0.0 & 0.0 & 0.0\\\\0.0 & 1.0 & 0.0 & 0.0\\\\0.0 & 0.0 & 1.0 & 0.0\\\\0.0 & 0.0 & 0.0 & 1.0\\\\\\end{array}\\right)\\end{equation*}" ], "text/plain": [ "Quantum object: dims = [[4], [4]], shape = (4, 4), type = oper, isherm = True\n", "Qobj data =\n", "[[1. 0. 0. 0.]\n", " [0. 1. 0. 0.]\n", " [0. 0. 1. 0.]\n", " [0. 0. 0. 1.]]" ] }, "execution_count": 27, "metadata": {}, "output_type": "execute_result" } ], "source": [ "# Creating a copy\n", "str_QobjEvo_2 = str_QobjEvo.copy()\n", "str_QobjEvo_2 += 1\n", "str_QobjEvo_2(1) - str_QobjEvo(1)" ] }, { "cell_type": "code", "execution_count": 28, "metadata": {}, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "\n", "QuTiP: Quantum Toolbox in Python\n", "Copyright (c) 2011 and later.\n", "A. J. Pitchford, P. D. Nation, R. J. Johansson, A. Grimsmo, and C. Granade\n", "\n", "QuTiP Version: 4.4.0.dev0+8b414dd\n", "Numpy Version: 1.16.2\n", "Scipy Version: 1.2.1\n", "Cython Version: 0.29.6\n", "Matplotlib Version: 3.0.1\n", "Python Version: 3.7.0\n", "Number of CPUs: 4\n", "BLAS Info: OPENBLAS\n", "OPENMP Installed: False\n", "INTEL MKL Ext: False\n", "Platform Info: Linux (x86_64)\n", "Installation path: /home/eric/anaconda3/lib/python3.7/site-packages/qutip-4.4.0.dev0+8b414dd-py3.7-linux-x86_64.egg/qutip\n", "==============================================================================\n", "Please cite QuTiP in your publication.\n", "==============================================================================\n", "For your convenience a bibtex reference can be easily generated using `qutip.cite()`\n" ] } ], "source": [ "about()" ] }, { "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.0" } }, "nbformat": 4, "nbformat_minor": 2 }