Quantum Control Theory: GRAPE, CRAB, and the Pulse Engineering of High-Fidelity Gates
A quantum gate is, on real hardware, a shaped microwave pulse. Designing pulses that produce desired unitaries while suppressing leakage, decoherence, and crosstalk is the discipline of quantum optimal control. GRAPE (Khaneja 2005) is the gradient-based workhorse; CRAB (Caneva 2011) is the gradient-free alternative; modern automatic-differentiation methods extend the toolkit. This tutorial covers the methods, the cost functions, and the engineering tradeoffs.
Prerequisites: Tutorial 33: Transmon Qubits, Tutorial 61: Cryogenic Control Electronics
A quantum gate on real hardware is a shaped pulse — a microwave drive with a specific time-domain envelope, frequency, and phase. The standard “RX(π/2)” or “CNOT” you write in a circuit description must be translated into a physical pulse before the hardware can apply it. This translation is the discipline of quantum optimal control.
The basic problem: given a target unitary , a controllable qubit Hamiltonian depending on time-varying control parameters , find the parameter trajectory such that the time evolution implements to high fidelity. The constraints are real: bounded amplitude, bounded bandwidth, robustness to noise, suppression of leakage to non-computational levels.
The dominant algorithms:
- GRAPE (Gradient Ascent Pulse Engineering, Khaneja-Reiss-Schulte-Herbrüggen-Glaser 2005): gradient-based optimization of pulse shapes.
- CRAB (Chopped Random Basis, Caneva-Calarco-Montangero 2011): gradient-free optimization in a low-dimensional basis.
- Krotov method (1980s, applied to quantum control 2000s): iterative method with monotonic convergence guarantees.
- Automatic differentiation (modern): TensorFlow/JAX-based optimization with full quantum-mechanical gradient computation.
Each has tradeoffs. This tutorial covers the methods, the cost functions that capture real engineering constraints, and the open problems in production pulse engineering.
The control problem
Formal setup. The qubit (or coupled-qubit-system) evolves under a Hamiltonian:
where is the static drift Hamiltonian (the qubit’s own internal dynamics), are the control operators (e.g., and for amplitude-and-phase microwave drives), and are the time-varying control fields.
The unitary at time is
The control problem: find such that (or as close as possible) subject to constraints (amplitude bounds, bandwidth limits).
GRAPE: the gradient workhorse
Discretize time into steps of duration . The control fields become piecewise-constant: for . The unitary is a product:
The cost function is typically the gate infidelity:
where is the dimension. GRAPE computes the gradient analytically using a clever rearrangement that avoids re-simulating the full evolution for each derivative. The gradient is then fed to a standard optimizer (BFGS, L-BFGS).
GRAPE’s strengths:
- Fast convergence thanks to gradient information.
- Scales to thousands of time steps with reasonable memory.
- Well-understood numerical behavior — production tools exist (DYNAMO, Quasar, qutip-qoc).
GRAPE’s weaknesses:
- Gets stuck in local minima, especially for hard-to-optimize gates.
- Doesn’t directly handle constraints like bandwidth limits — these have to be added as penalty terms.
- Discretization error if the time step is too coarse.
CRAB: the gradient-free alternative
For problems where GRAPE’s gradient is hard to compute (e.g., open-system dynamics with non-trivial decoherence), or where the optimization landscape is rough, CRAB (Chopped Random Basis) takes a different approach.
Instead of optimizing pulse values at each time step, CRAB parameterizes the pulse in a low-dimensional basis (typically a Fourier series with random frequencies):
where are randomly chosen frequencies. Optimize over — say, parameters per control field, instead of pulse values per field. The optimization is done with a gradient-free method (CMA-ES, Nelder-Mead).
CRAB’s strengths:
- Gradient-free, so works for arbitrary cost functions including those with experimentally-measured fidelities.
- Inherently bandwidth-limited since the basis is sparse in frequency.
- Robust to local minima thanks to random-basis exploration.
CRAB’s weaknesses:
- Slower convergence than GRAPE for problems with usable gradients.
- Sensitive to basis choice — wrong frequencies give bad results.
- Limited fidelity ceiling in some problems where the true optimal pulse needs more parameters than the basis supports.
DRAG: the special case for transmons
A widely-used technique on transmon qubits: Derivative Removal by Adiabatic Gate (DRAG) (Motzoi-Gambetta-Rebentrost-Wilhelm 2009). Standard rectangular or Gaussian pulses on transmons cause leakage to the state because the transmon’s anharmonicity is small. DRAG adds a derivative correction to the pulse shape:
where is the original pulse envelope and is the transmon anharmonicity. The derivative correction cancels the leading-order leakage to .
DRAG is not numerically optimized — it has a closed-form derivation. For transmons, DRAG-shaped Gaussian pulses give single-qubit gate fidelities of at ns gate time, without requiring a full GRAPE run. Most production transmon control uses DRAG as the default.
For more demanding fidelity targets, GRAPE or CRAB-derived pulses can push beyond DRAG’s performance, at the cost of more complex pulse shapes that are harder to calibrate experimentally.
Cost-function engineering
Real production pulse design optimizes more than just fidelity. The cost function typically includes:
- Gate fidelity: the dominant term.
- Leakage suppression: a penalty for population escaping the computational subspace.
- Bandwidth: a penalty on high-frequency Fourier components.
- Amplitude: a penalty on exceeding hardware-amplitude limits.
- Robustness: averaging over a distribution of detuning errors or amplitude errors.
The robustness term is particularly important. A pulse that achieves fidelity at the calibrated qubit frequency but at MHz detuning is worse than a pulse that achieves fidelity over a MHz range. Production pulses balance peak fidelity against operating range.
A small GRAPE-style demonstration
Concrete code that uses gradient descent to find a pulse on a single qubit:
import numpy as np
import jax
import jax.numpy as jnp
from functools import partial
# Single-qubit Hamiltonian: H = omega * Z/2 + u_x(t) * X/2 + u_y(t) * Y/2
def step_evolution(state, u_x, u_y, dt, omega):
"""Single time-step propagator."""
sx = jnp.array([[0, 1], [1, 0]], dtype=jnp.complex64)
sy = jnp.array([[0, -1j], [1j, 0]], dtype=jnp.complex64)
sz = jnp.array([[1, 0], [0, -1]], dtype=jnp.complex64)
H = omega * sz / 2 + u_x * sx / 2 + u_y * sy / 2
U = jax.scipy.linalg.expm(-1j * H * dt)
return U @ state
def evolve_pulse(pulse_params, omega, T, n_steps):
"""Evolve under a piecewise-constant pulse."""
dt = T / n_steps
state = jnp.array([1.0 + 0j, 0.0 + 0j]) # initial |0>
for j in range(n_steps):
u_x, u_y = pulse_params[j, 0], pulse_params[j, 1]
state = step_evolution(state, u_x, u_y, dt, omega)
return state
def fidelity_to_target(pulse_params, omega, T, n_steps, target_state):
"""Compute fidelity of evolved state to target."""
final_state = evolve_pulse(pulse_params, omega, T, n_steps)
return jnp.abs(jnp.vdot(target_state, final_state)) ** 2
# Target: |+> state (X-rotation by pi/2 from |0>).
target = jnp.array([1.0, 1.0]) / jnp.sqrt(2.0)
omega_qubit = 1.0
T = 5.0
n_steps = 100
# Initialize random pulse parameters.
np.random.seed(0)
pulse_params = jnp.array(np.random.randn(n_steps, 2) * 0.1)
# Loss = 1 - fidelity (minimize this).
loss_fn = lambda params: 1.0 - fidelity_to_target(params, omega_qubit, T, n_steps, target)
grad_fn = jax.grad(loss_fn)
learning_rate = 0.01
for step in range(200):
grads = grad_fn(pulse_params)
pulse_params = pulse_params - learning_rate * grads
if step % 50 == 0:
loss = loss_fn(pulse_params)
print(f"Step {step}: loss = {float(loss):.5f}")
print(f"Final fidelity: {1.0 - float(loss_fn(pulse_params)):.5f}")
This is GRAPE in spirit: parameterized pulse, fidelity-based cost, gradient descent. Real GRAPE implementations (DYNAMO, qutip-qoc) handle the analytical gradient computation more efficiently and add constraint penalties.
Common misconceptions
“Optimal control gives perfect fidelity.” No physical control achieves perfect fidelity — coherence decay, drift, finite bandwidth, and amplitude noise all set ceilings. GRAPE/CRAB push close to the achievable maximum given those constraints.
“GRAPE is always better than CRAB.” GRAPE is better when the cost function has clean gradients. CRAB is better for noisy cost functions, experimentally-measured costs, or rough optimization landscapes. The right method depends on the cost function structure.
“DRAG is sufficient for production.” DRAG handles leakage at the leading order, but production transmon control often combines DRAG with additional GRAPE refinement and detuning-robustness optimization. DRAG is a starting point, not the endpoint.
“Pulse design is hardware-platform agnostic.” Specific platforms have specific pulse engineering: transmons use DRAG, ions use composite pulses (BB1, SK1), neutral atoms use Rydberg-blockade-aware pulses. Each platform’s optimal-control strategy is tied to its physical noise structure.
Decision rule
For pulse design on a specific gate:
- Single-qubit gates on transmons: start with DRAG, refine with GRAPE if higher fidelity needed. Production-fast.
- Two-qubit gates on transmons: start with cross-resonance theory, refine with GRAPE. Bandwidth and crosstalk become important.
- Ions: composite pulses (BB1, SK1) for robustness; GRAPE for high-precision custom gates.
- Neutral atoms: Rydberg-blockade-aware shaped pulses, often CRAB-optimized.
- Open-system / decoherence-aware: CRAB or Krotov, since GRAPE doesn’t naturally handle non-Hermitian dynamics.
For algorithm-level work, pulse design is largely an infrastructure layer — the algorithm specifies the gates, and the hardware vendor provides calibrated pulses. Direct pulse engineering matters when you’re pushing hardware limits or doing platform-specific optimizations.
Where this goes next
Tutorial 63 covers randomized benchmarking — the standard protocol that measures whether the engineered pulses actually achieve their target fidelities, as observed on real hardware. Tutorial 64 covers gate-set tomography, a more detailed-but-expensive characterization that returns a full description of the gate’s action including coherent and incoherent errors.