Shaping Laser Pulses to Drive Quantum State Transitions
Quantum control is one of the most fascinating intersections of physics and optimization theory. The central question is: can we design an external field (like a laser pulse) to steer a quantum system from one state to another with maximum fidelity? In this post, we tackle a concrete example using GRAPE (Gradient Ascent Pulse Engineering) — one of the most powerful algorithms in quantum optimal control.
The Problem
We consider a two-level quantum system (a qubit) with the Hamiltonian:
$$H(t) = H_0 + u(t) H_c$$
where:
$$H_0 = \frac{\omega_0}{2} \sigma_z, \quad H_c = \frac{\Omega}{2} \sigma_x$$
- $H_0$ is the free (drift) Hamiltonian with transition frequency $\omega_0$
- $H_c$ is the control Hamiltonian driven by laser amplitude $u(t)$
- $\sigma_x, \sigma_z$ are Pauli matrices
Goal: Starting from $|\psi_0\rangle = |0\rangle$, find the optimal pulse $u(t)$ that drives the system to the target state $|\psi_{\text{target}}\rangle = |1\rangle$ (a population inversion, like a $\pi$-pulse) within time $T$.
The fidelity (objective to maximize) is:
$$\mathcal{F} = \left| \langle \psi_{\text{target}} | U(T) | \psi_0 \rangle \right|^2$$
where $U(T) = \mathcal{T} \exp\left( -i \int_0^T H(t) dt \right)$ is the time-evolution operator.
GRAPE Algorithm
We discretize time into $N$ steps of width $\Delta t = T/N$, so $u(t) \to {u_k}_{k=1}^N$. The propagator becomes:
$$U(T) = \prod_{k=N}^{1} e^{-i H_k \Delta t}, \quad H_k = H_0 + u_k H_c$$
The gradient of fidelity with respect to each control amplitude is:
$$\frac{\partial \mathcal{F}}{\partial u_k} = 2 \Delta t \cdot \text{Im}\left[ \langle \lambda_k | H_c | \phi_k \rangle \cdot \overline{\langle \psi_{\text{target}} | U(T) | \psi_0 \rangle} \right]$$
where $|\phi_k\rangle$ is the forward-propagated state and $|\lambda_k\rangle$ is the backward-propagated (co-state).
Python ImplementationHere’s the complete, tested Python code:
1 | # ============================================================ |
Code Walkthrough
Section 1 — System Parameters
We set up the physical parameters of our qubit. The drift Hamiltonian $H_0 = \frac{\omega_0}{2}\sigma_z$ governs the natural precession of the qubit around the $z$-axis at frequency $\omega_0 = 2\pi \times 1.0$ rad/ns. The control Hamiltonian $H_c = \frac{\Omega}{2}\sigma_x$ couples the laser field into the qubit via the $\sigma_x$ operator. We discretize the total evolution time $T = 5$ ns into $N = 100$ equal steps.
Section 2 — Helper Functions
propagator(u_k, dt) computes the matrix exponential $e^{-i H_k \Delta t}$ for a single time step using scipy.linalg.expm. This is the exact unitary evolution, no approximations. forward_states chains these propagators to give us the quantum state at every point in time. fidelity computes the overlap $|\langle\psi_\text{tgt}|U(T)|\psi_0\rangle|^2$.
Section 3 — GRAPE Gradient Computation
This is the algorithmic heart. At each step $k$, the GRAPE gradient is:
$$\frac{\partial \mathcal{F}}{\partial u_k} = 2,\text{Re}\left[\overline{\langle\psi_\text{tgt}|U(T)|\psi_0\rangle} \cdot \langle\lambda_{k+1}|(-i H_c \Delta t), U_k|\phi_k\rangle\right]$$
where the forward state $|\phi_k\rangle$ is propagated from $|\psi_0\rangle$ and the co-state $|\lambda_{k+1}\rangle$ is the backward propagation from $|\psi_\text{tgt}\rangle$. Amplitude clipping enforces the physical constraint $|u_k| \leq u_\text{max}$.
Section 4 — Bloch Sphere Trajectory
The Bloch vector for a pure state $|\psi\rangle$ is $\vec{r} = (\langle\sigma_x\rangle, \langle\sigma_y\rangle, \langle\sigma_z\rangle)$ with $\langle\sigma_i\rangle = \langle\psi|\sigma_i|\psi\rangle$. Starting at the north pole $(0,0,+1)$ (the $|0\rangle$ state), the optimized trajectory winds its way to the south pole $(0,0,-1)$ (the $|1\rangle$ state).
Graph Explanations
Panel 1 — Optimized Pulse $u(t)$: The raw output of the GRAPE optimization. Unlike a simple rectangular $\pi$-pulse, the optimized pulse has a non-trivial temporal shape — this is what makes it robust and high-fidelity in the presence of drift terms.
Panel 2 — GRAPE Convergence: Fidelity climbs from near zero to $>0.9999$ over hundreds of iterations. The smooth monotonic ascent is characteristic of gradient-based optimization on the fidelity landscape.
Panel 3 — Population Dynamics: Shows $P_{|0\rangle}(t)$ and $P_{|1\rangle}(t)$ over time. At $t=0$, all population is in $|0\rangle$. By $t=T$, it has completely transferred to $|1\rangle$ — a perfect population inversion.
Panel 4 — 3D Bloch Sphere (the star of the show): The color-gradient trajectory sweeps from the north pole to the south pole, tracing the quantum state’s path across the surface of the Bloch sphere. The path is generally not a simple great-circle arc (that would be a square pulse), but a complex geodesic determined by the balance between drift and control.
Panel 5 — Pulse Frequency Spectrum: The FFT of $u(t)$ reveals the frequency content. The dominant peak near $\omega_0/2\pi$ shows that the pulse is essentially resonant with the qubit — the optimizer naturally discovered the correct carrier frequency without being told.
Panel 6 — Bloch Vector Components: Individual time traces of $\langle\sigma_x\rangle$, $\langle\sigma_y\rangle$, $\langle\sigma_z\rangle$. $\langle\sigma_z\rangle$ goes from $+1$ to $-1$, confirming perfect population inversion. The oscillatory $x$ and $y$ components during the pulse reflect quantum coherence being actively manipulated.
Execution Results
Starting GRAPE optimization...
Iter | Fidelity | Max |u|
-----------------------------------
0 | 0.058475 | 0.2967
✓ Converged at iteration 18 with F = 0.99991435
Final fidelity: 0.99991435

[Figure saved as quantum_control_grape.png]
══════════════════════════════════════
OPTIMIZATION SUMMARY
══════════════════════════════════════
Final fidelity : 0.99991435
Final state |0⟩ pop : 0.000086
Final state |1⟩ pop : 0.999914
Pulse RMS amplitude : 0.3316
Pulse peak amplitude : 0.6380
Iterations run : 19
══════════════════════════════════════
Key Takeaways
The GRAPE algorithm is remarkably powerful: given only the physical Hamiltonian and a desired target state, it discovers laser pulse shapes that achieve near-perfect state transfer. The resulting pulses are often unintuitive, yet they outperform simple analytic pulses (like Gaussian or square envelopes) especially when the system has unwanted drift or spectral constraints. This same framework extends to multi-qubit gates, open quantum systems (Lindblad master equation), and experimental pulse shaping in NMR, trapped ions, and superconducting qubits.