Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Analytical solutions for the dynamics of a two-level system (Rabi cycling)
.ipynb_checkpoints
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
{
"cells": [
{
"cell_type": "markdown",
"id": "345ef76a",
"metadata": {},
"source": [
"# Rabi Cycling in the Two-Level-System — From Scratch (Variation for Pauli Matrices)"
]
},
{
"cell_type": "markdown",
"id": "2f71805d",
"metadata": {},
"source": [
"This notebook uses sympy to symbolically solve the Schrödinger equation for a two-level system, resulting in the exact analytic expressions for the complex amplitudes and the population dynamics of Rabi cycling.\n",
"\n",
"The particular variation in this notebook is for a Hamiltonian written in Terms of Pauli matrices, specifically a drift Hamiltonian of $\\Delta \\hat{S}_z$ where $\\hat{S}_z = \\frac{1}{2} \\hat{\\sigma}_z$, so that the energy levels are symmetric around zero. This symmetry eliminates the global phase induced otherwise, and thus leads to a simpler expression."
]
},
{
"cell_type": "code",
"execution_count": 1,
"id": "3f934a01",
"metadata": {
"ExecuteTime": {
"end_time": "2021-12-12T23:33:27.877985Z",
"start_time": "2021-12-12T23:33:27.664523Z"
}
},
"outputs": [],
"source": [
"from sympy import Function, symbols, sqrt, Eq, Abs, exp, cos, sin, Matrix, dsolve, solve"
]
},
{
"cell_type": "code",
"execution_count": 2,
"id": "81ff8a59",
"metadata": {
"ExecuteTime": {
"end_time": "2021-12-12T23:33:27.881082Z",
"start_time": "2021-12-12T23:33:27.879248Z"
}
},
"outputs": [],
"source": [
"from sympy import I as 𝕚"
]
},
{
"cell_type": "code",
"execution_count": 3,
"id": "e0bcca3e",
"metadata": {
"ExecuteTime": {
"end_time": "2021-12-12T23:33:27.887195Z",
"start_time": "2021-12-12T23:33:27.884226Z"
}
},
"outputs": [],
"source": [
"g = Function('g')\n",
"e = Function('e')\n",
"t = symbols('t', positive=True)\n",
"Δ = symbols('Delta', real=True)\n",
"Ω0 = symbols('Ω_0', real=True)\n",
"Ω = symbols('Omega', real=True)"
]
},
{
"cell_type": "code",
"execution_count": 4,
"id": "5d543823",
"metadata": {
"ExecuteTime": {
"end_time": "2021-12-12T23:33:28.013056Z",
"start_time": "2021-12-12T23:33:27.888159Z"
}
},
"outputs": [
{
"data": {
"text/latex": [
"$\\displaystyle \\left[\\begin{matrix}- \\frac{\\Delta}{2} & - \\frac{Ω_{0}}{2}\\\\- \\frac{Ω_{0}}{2} & \\frac{\\Delta}{2}\\end{matrix}\\right]$"
],
"text/plain": [
"Matrix([\n",
"[-Delta/2, -Ω_0/2],\n",
"[ -Ω_0/2, Delta/2]])"
]
},
"execution_count": 4,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"Ĥ = Matrix([\n",
" [ -Δ/2, -Ω0/2],\n",
" [-Ω0/2, Δ/2]\n",
"])\n",
""
]
},
{
"cell_type": "code",
"execution_count": 5,
"id": "76d909e3",
"metadata": {
"ExecuteTime": {
"end_time": "2021-12-12T23:33:28.019014Z",
"start_time": "2021-12-12T23:33:28.014085Z"
}
},
"outputs": [],
"source": [
"TDSE_system = [\n",
" g(t).diff(t) + 𝕚 * (Ĥ[0,0] * g(t) + Ĥ[0,1] * e(t)),\n",
" e(t).diff(t) + 𝕚 * (Ĥ[1,0]* g(t) + Ĥ[1,1] * e(t)),\n",
"]"
]
},
{
"cell_type": "code",
"execution_count": 6,
"id": "a03c7545",
"metadata": {
"ExecuteTime": {
"end_time": "2021-12-12T23:33:28.307418Z",
"start_time": "2021-12-12T23:33:28.020101Z"
}
},
"outputs": [],
"source": [
"sols_gen = dsolve(TDSE_system, [g(t), e(t)])"
]
},
{
"cell_type": "code",
"execution_count": 7,
"id": "72bd8853",
"metadata": {
"ExecuteTime": {
"end_time": "2021-12-12T23:33:28.310271Z",
"start_time": "2021-12-12T23:33:28.308287Z"
}
},
"outputs": [],
"source": [
"effective_rabi_freq = {\n",
" Ω: sqrt(Δ**2 + Ω0**2)\n",
"}"
]
},
{
"cell_type": "code",
"execution_count": 8,
"id": "18d59382",
"metadata": {
"ExecuteTime": {
"end_time": "2021-12-12T23:33:28.314965Z",
"start_time": "2021-12-12T23:33:28.311116Z"
}
},
"outputs": [
{
"data": {
"text/latex": [
"$\\displaystyle \\Omega = \\sqrt{\\Delta^{2} + Ω_{0}^{2}}$"
],
"text/plain": [
"Eq(Omega, sqrt(Delta**2 + Ω_0**2))"
]
},
"execution_count": 8,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"Eq(Ω, effective_rabi_freq[Ω])"
]
},
{
"cell_type": "code",
"execution_count": 9,
"id": "720c39fc",
"metadata": {
"ExecuteTime": {
"end_time": "2021-12-12T23:33:28.319714Z",
"start_time": "2021-12-12T23:33:28.317982Z"
}
},
"outputs": [],
"source": [
"find_Ω = {\n",
" effective_rabi_freq[Ω]: Ω\n",
"}"
]
},
{
"cell_type": "code",
"execution_count": 10,
"id": "1b9d8db8",
"metadata": {
"ExecuteTime": {
"end_time": "2021-12-12T23:33:28.340314Z",
"start_time": "2021-12-12T23:33:28.320648Z"
}
},
"outputs": [
{
"data": {
"text/latex": [
"$\\displaystyle g{\\left(t \\right)} = - \\frac{C_{1} Ω_{0} e^{\\frac{i \\Omega t}{2}}}{\\Delta - \\Omega} - \\frac{C_{2} Ω_{0} e^{- \\frac{i \\Omega t}{2}}}{\\Delta + \\Omega}$"
],
"text/plain": [
"Eq(g(t), -C1*Ω_0*exp(I*Omega*t/2)/(Delta - Omega) - C2*Ω_0*exp(-I*Omega*t/2)/(Delta + Omega))"
]
},
"execution_count": 10,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"sols_gen[0].subs(find_Ω)"
]
},
{
"cell_type": "code",
"execution_count": 11,
"id": "830e8660",
"metadata": {
"ExecuteTime": {
"end_time": "2021-12-12T23:33:28.351092Z",
"start_time": "2021-12-12T23:33:28.341445Z"
}
},
"outputs": [
{
"data": {
"text/latex": [
"$\\displaystyle e{\\left(t \\right)} = C_{1} e^{\\frac{i \\Omega t}{2}} + C_{2} e^{- \\frac{i \\Omega t}{2}}$"
],
"text/plain": [
"Eq(e(t), C1*exp(I*Omega*t/2) + C2*exp(-I*Omega*t/2))"
]
},
"execution_count": 11,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"sols_gen[1].subs(find_Ω)"
]
},
{
"cell_type": "code",
"execution_count": 12,
"id": "7e47f4a9",
"metadata": {
"ExecuteTime": {
"end_time": "2021-12-12T23:33:28.353627Z",
"start_time": "2021-12-12T23:33:28.351901Z"
}
},
"outputs": [],
"source": [
"boundary_conditions = {\n",
" t: 0,\n",
" g(t): 1,\n",
" e(t) : 0,\n",
"}"
]
},
{
"cell_type": "code",
"execution_count": 13,
"id": "e0cbc902",
"metadata": {
"ExecuteTime": {
"end_time": "2021-12-12T23:33:28.356446Z",
"start_time": "2021-12-12T23:33:28.354637Z"
}
},
"outputs": [],
"source": [
"find_Ω0sq = {\n",
" Ω**2 - Δ**2: Ω0**2\n",
"}"
]
},
{
"cell_type": "code",
"execution_count": 14,
"id": "18167c81",
"metadata": {
"ExecuteTime": {
"end_time": "2021-12-12T23:33:28.358981Z",
"start_time": "2021-12-12T23:33:28.357324Z"
}
},
"outputs": [],
"source": [
"C1, C2 = symbols(\"C1, C2\")"
]
},
{
"cell_type": "code",
"execution_count": 15,
"id": "0e5b5f21",
"metadata": {
"ExecuteTime": {
"end_time": "2021-12-12T23:33:28.392953Z",
"start_time": "2021-12-12T23:33:28.359672Z"
}
},
"outputs": [],
"source": [
"_integration_constants = solve(\n",
" [sol.subs(find_Ω).subs(boundary_conditions) for sol in sols_gen],\n",
" [C1, C2]\n",
")\n",
"integration_constants = {\n",
" k: v.subs(find_Ω0sq)\n",
" for (k, v) in _integration_constants.items()\n",
"}"
]
},
{
"cell_type": "code",
"execution_count": 16,
"id": "59b65998",
"metadata": {
"ExecuteTime": {
"end_time": "2021-12-12T23:33:28.398470Z",
"start_time": "2021-12-12T23:33:28.393848Z"
}
},
"outputs": [
{
"data": {
"text/latex": [
"$\\displaystyle C_{1} = \\frac{Ω_{0}}{2 \\Omega}$"
],
"text/plain": [
"Eq(C1, Ω_0/(2*Omega))"
]
},
"execution_count": 16,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"Eq(C1, integration_constants[C1])"
]
},
{
"cell_type": "code",
"execution_count": 17,
"id": "4cde0003",
"metadata": {
"ExecuteTime": {
"end_time": "2021-12-12T23:33:28.404200Z",
"start_time": "2021-12-12T23:33:28.399273Z"
}
},
"outputs": [
{
"data": {
"text/latex": [
"$\\displaystyle C_{2} = - \\frac{Ω_{0}}{2 \\Omega}$"
],
"text/plain": [
"Eq(C2, -Ω_0/(2*Omega))"
]
},
"execution_count": 17,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"Eq(C2, integration_constants[C2])"
]
},
{
"cell_type": "code",
"execution_count": 18,
"id": "9cc7f8cb",
"metadata": {
"ExecuteTime": {
"end_time": "2021-12-12T23:33:28.407499Z",
"start_time": "2021-12-12T23:33:28.405169Z"
}
},
"outputs": [],
"source": [
"def simplify_sol_g(sol_g):\n",
" rhs = (\n",
" sol_g\n",
" .rhs\n",
" .rewrite(sin)\n",
" .expand()\n",
" .collect(𝕚)\n",
" .subs(effective_rabi_freq)\n",
" .simplify()\n",
" .subs(find_Ω)\n",
" )\n",
" return Eq(sol_g.lhs, rhs)"
]
},
{
"cell_type": "code",
"execution_count": 19,
"id": "426e3a3b",
"metadata": {
"ExecuteTime": {
"end_time": "2021-12-12T23:33:28.779441Z",
"start_time": "2021-12-12T23:33:28.408542Z"
}
},
"outputs": [
{
"data": {
"text/latex": [
"$\\displaystyle g{\\left(t \\right)} = \\frac{i \\Delta \\sin{\\left(\\frac{\\Omega t}{2} \\right)}}{\\Omega} + \\cos{\\left(\\frac{\\Omega t}{2} \\right)}$"
],
"text/plain": [
"Eq(g(t), I*Delta*sin(Omega*t/2)/Omega + cos(Omega*t/2))"
]
},
"execution_count": 19,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"sol_g = simplify_sol_g(sols_gen[0].subs(find_Ω).subs(integration_constants))\n",
"sol_g"
]
},
{
"cell_type": "code",
"execution_count": 20,
"id": "461fcc6d",
"metadata": {
"ExecuteTime": {
"end_time": "2021-12-12T23:33:28.816220Z",
"start_time": "2021-12-12T23:33:28.780376Z"
}
},
"outputs": [
{
"data": {
"text/latex": [
"$\\displaystyle e{\\left(t \\right)} = \\frac{i Ω_{0} \\sin{\\left(\\frac{\\Omega t}{2} \\right)}}{\\Omega}$"
],
"text/plain": [
"Eq(e(t), I*Ω_0*sin(Omega*t/2)/Omega)"
]
},
"execution_count": 20,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"sol_e = (\n",
" sols_gen[1]\n",
" .subs(find_Ω)\n",
" .subs(integration_constants)\n",
" .expand()\n",
" .rewrite(sin)\n",
" .expand()\n",
")\n",
"sol_e"
]
},
{
"cell_type": "code",
"execution_count": 21,
"id": "6e135065",
"metadata": {
"ExecuteTime": {
"end_time": "2021-12-12T23:33:28.825993Z",
"start_time": "2021-12-12T23:33:28.817227Z"
}
},
"outputs": [
{
"data": {
"text/latex": [
"$\\displaystyle \\left|{e{\\left(t \\right)}}\\right|^{2} = \\frac{Ω_{0}^{2} \\sin^{2}{\\left(\\frac{\\Omega t}{2} \\right)}}{\\Omega^{2}}$"
],
"text/plain": [
"Eq(Abs(e(t))**2, Ω_0**2*sin(Omega*t/2)**2/Omega**2)"
]
},
"execution_count": 21,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"pop_e = (sol_e.rhs * sol_e.rhs.conjugate()).rewrite(sin).expand()\n",
"Eq(Abs(e(t))**2, pop_e)"
]
}
],
"metadata": {
"hide_input": false,
"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.9.7"
},
"toc": {
"base_numbering": 1,
"nav_menu": {},
"number_sections": true,
"sideBar": true,
"skip_h1_title": false,
"title_cell": "Table of Contents",
"title_sidebar": "Contents",
"toc_cell": false,
"toc_position": {},
"toc_section_display": true,
"toc_window_display": false
},
"varInspector": {
"cols": {
"lenName": 16,
"lenType": 16,
"lenVar": 40
},
"kernels_config": {
"python": {
"delete_cmd_postfix": "",
"delete_cmd_prefix": "del ",
"library": "var_list.py",
"varRefreshCmd": "print(var_dic_list())"
},
"r": {
"delete_cmd_postfix": ") ",
"delete_cmd_prefix": "rm(",
"library": "var_list.r",
"varRefreshCmd": "cat(var_dic_list()) "
}
},
"types_to_exclude": [
"module",
"function",
"builtin_function_or_method",
"instance",
"_Feature"
],
"window_display": false
}
},
"nbformat": 4,
"nbformat_minor": 5
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment