from Eq. \[eqn:3LJ\] as $$\frac{\delta J}{\delta \Omega(\tau)} = -2 \tilde{\mu}_{1s} \int_0^1 d\tilde{z}\, \mathrm{Im}{\left[\bar{S}^*P_1-\bar{P}_1 S^* \right]}. \label{eqn:3Lgrad}$$ Thus, the prescription for obtaining the maximum storage efficiency and optimal control pulse for a given input quantum field and optical depth is as follows. First, take a trial control pulse and solve the equations of motion Eq. \[eqn:3LEoME\]-\[eqn:3LEoMS\] with the storage boundary conditions to obtain $P_1(\tilde{z},\tau)$ and $S(\tilde{z},\tau)$. Then, solve Eq. \[eqn:3LEoMbE\]-\[eqn:3LEoMbS\] using the boundary conditions for backwards retrieval (note that these equations run backwards in time and space) to obtain $\bar{P}_1(\tilde{z},\tau)$ and $\bar{S}(\tilde{z},\tau)$. Now the gradient can be determined from Eq. \[eqn:3Lgrad\] and the control pulse can be updated using the replacement rule. This process is then repeated until the desired tolerance of the storage (or total) efficiency is obtained.

![(Color online) Results of the numerical calculation using gradient ascent for storage and retrieval of a quantum dot photon in an idealized Rb gas. The storage (total) efficiency is plotted as a function of the optical depth $d$ in blue (red). Solid curves are guides to the eye.[]{data-label="fig:fig3"}](fig_3.eps){width="0.95\columnwidth"}

As an example we consider the case of an idealized Rb gas ($\tilde{\mu}_{1g} = \tilde{\mu}_{1s}=1$, $\gamma = 2\pi\times3.035$ MHz) storing a quantum-dot photon with 