# Rabi Cycling in the Two-Level-System — From Scratch (Variation for Pauli Matrices)¶

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.

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.

In :
from sympy import Function, symbols, sqrt, Eq, Abs, exp, cos, sin, Matrix, dsolve, solve

In :
from sympy import I as 𝕚

In :
g = Function('g')
e = Function('e')
t = symbols('t', positive=True)
Δ = symbols('Delta', real=True)
Ω0 = symbols('Ω_0', real=True)
Ω = symbols('Omega', real=True)

In :
Ĥ = Matrix([
[ -Δ/2, -Ω0/2],
[-Ω0/2,   Δ/2]
])
Ĥ

Out:
$\displaystyle \left[\begin{matrix}- \frac{\Delta}{2} & - \frac{Ω_{0}}{2}\\- \frac{Ω_{0}}{2} & \frac{\Delta}{2}\end{matrix}\right]$
In :
TDSE_system = [
g(t).diff(t) + 𝕚 * (Ĥ[0,0] * g(t) + Ĥ[0,1] * e(t)),
e(t).diff(t) + 𝕚 * (Ĥ[1,0]*  g(t) + Ĥ[1,1] * e(t)),
]

In :
sols_gen = dsolve(TDSE_system, [g(t), e(t)])

In :
effective_rabi_freq = {
Ω: sqrt(Δ**2 + Ω0**2)
}

In :
Eq(Ω, effective_rabi_freq[Ω])

Out:
$\displaystyle \Omega = \sqrt{\Delta^{2} + Ω_{0}^{2}}$
In :
find_Ω = {
effective_rabi_freq[Ω]: Ω
}

In :
sols_gen.subs(find_Ω)

Out:
$\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}$
In :
sols_gen.subs(find_Ω)

Out:
$\displaystyle e{\left(t \right)} = C_{1} e^{\frac{i \Omega t}{2}} + C_{2} e^{- \frac{i \Omega t}{2}}$
In :
boundary_conditions = {
t: 0,
g(t): 1,
e(t) : 0,
}

In :
find_Ω0sq = {
Ω**2 - Δ**2: Ω0**2
}

In :
C1, C2 = symbols("C1, C2")

In :
_integration_constants = solve(
[sol.subs(find_Ω).subs(boundary_conditions) for sol in sols_gen],
[C1, C2]
)
integration_constants = {
k: v.subs(find_Ω0sq)
for (k, v) in _integration_constants.items()
}

In :
Eq(C1, integration_constants[C1])

Out:
$\displaystyle C_{1} = \frac{Ω_{0}}{2 \Omega}$
In :
Eq(C2, integration_constants[C2])

Out:
$\displaystyle C_{2} = - \frac{Ω_{0}}{2 \Omega}$
In :
def simplify_sol_g(sol_g):
rhs = (
sol_g
.rhs
.rewrite(sin)
.expand()
.collect(𝕚)
.subs(effective_rabi_freq)
.simplify()
.subs(find_Ω)
)
return Eq(sol_g.lhs, rhs)

In :
sol_g = simplify_sol_g(sols_gen.subs(find_Ω).subs(integration_constants))
sol_g

Out:
$\displaystyle g{\left(t \right)} = \frac{i \Delta \sin{\left(\frac{\Omega t}{2} \right)}}{\Omega} + \cos{\left(\frac{\Omega t}{2} \right)}$
In :
sol_e = (
sols_gen
.subs(find_Ω)
.subs(integration_constants)
.expand()
.rewrite(sin)
.expand()
)
sol_e

Out:
$\displaystyle e{\left(t \right)} = \frac{i Ω_{0} \sin{\left(\frac{\Omega t}{2} \right)}}{\Omega}$
In :
pop_e = (sol_e.rhs * sol_e.rhs.conjugate()).rewrite(sin).expand()
Eq(Abs(e(t))**2, pop_e)

Out:
$\displaystyle \left|{e{\left(t \right)}}\right|^{2} = \frac{Ω_{0}^{2} \sin^{2}{\left(\frac{\Omega t}{2} \right)}}{\Omega^{2}}$