Solution (source code)

= Solution

Three standard objectives are state preparation, <observable> optimization and process implementation. All optimizations are over admissible <control inputs> and a specified final time $T$.

For state preparation, steer an initial <density operator> to a target $\rho_d$. An exact goal is $\rho_f(T)=\rho_d$, or one may minimize the squared <Hilbert-Schmidt distance>
$$
\boxed{J_{\mathrm{state}}(f)=\tfrac12\operatorname{Tr}[(\rho_f(T)-\rho_d)^2].}
$$
For a pure target $\rho_d=|\psi_d\rangle\langle\psi_d|$, maximizing $\langle\psi_d|\rho_f(T)|\psi_d\rangle$ is a useful alternative. The target must be physically attainable: <Hamiltonian engineering> alone preserves the initial <spectrum> of the <density operator>.

For an <observable> objective, choose a <Hermitian operator> $O$ and maximize its expected final value:
$$
\boxed{J_O(f)=\operatorname{Tr}[O\rho_f(T)]\quad\text{to be maximized}.}
$$
Population transfer is a special case with $O$ the projector onto the desired level or subspace; suppressing an unwanted population reverses the sign or minimizes this quantity.

For coherent process engineering, implement a target <unitary operator> $V$ on every input, rather than merely arranging one state transfer. If the propagator is $U_f(T)$, a phase-insensitive error is
$$
\boxed{J_{\mathrm{gate}}(f)=1-\frac{|\operatorname{Tr}[V^\dagger U_f(T)]|^2}{N^2}.}
$$
The error vanishes precisely when $U_f(T)=e^{i\phi}V$: equality in the <Hilbert-Schmidt inner product> <Cauchy-Schwarz inequality> bound makes the two operators proportional. For an open-system process, the analogous objective compares the implemented <quantum channel> with the target channel. These objectives can be supplemented by pulse-energy, amplitude, bandwidth and duration constraints in <quantum optimal control>.