\part{Introduction}

Single photons are of paramount importance for modern quantum information science. Envisioned applications range from all-optical quantum computation \cite{Knill2001,Minzioni2019} to quantum communication in nonlocal quantum clouds \cite{Kimble2008,Wehner2018}. As all the conceived quantum information protocols involve, in one way or another, interference effects, coherent photons are mandatory for the implementation of these protocols \cite{Rohde2005,Raymer}. This requirement includes the (relative) coherence within the photon wave packet as well as the (absolute) coherence with respect to a common network reference clock. Full control over amplitude and phase of the photon's temporal mode is a challenge \cite{Keller2004,Eisaman2004,Eisaman2005,Balic2005,Kolchin,Kielpinski2011,McKinstrie2012,Matsuda2016,Fisher2016,Karpinski2017,
Zhou2012,Specht2009,NisbetJones2011,NisbetJones2013,Farrera2016,Averchenko2017,Sych2017}, as is the mode conversion for all regimes from narrow to broad-bandwidth single photons. Meeting these challenges would open up new possibilities like temporal mode matching in multimode quantum networks or information encoding in the optical mode of the photon.

Here we exploit the arsenal of cavity quantum electrodynamics (CQED) \cite{Reiserer2015} and demonstrate deterministic mode control over single optical photons. Toward this end, we extend previous models \cite{Law1997,Kuhn1999,Fleischhauer2000, Gorshkov2007,Muecke2013,Dilley2012,Dalibard92,Giannelli2018} and take into account the full energy-level structure of the atom that serves as photon emitter and photon receiver in a high-finesse optical resonator. We find a surprisingly strong frequency dependence of the process efficiency with a pronounced minimum that originates from destructive interference of transition amplitudes. We also show that the emission efficiency is not a reliable measure for photon coherence. We moreover shape the photon phase, demonstrate the mode selectivity of photon absorption, and stretch and compress a given single-photon wave packet by 3 orders of magnitude. All these achievements are realized in combination with a convenient-to-implement coherence-testing method that outputs the time-dependent complex-valued temporal mode function with minimal resources \cite{Morin2019}. 
As both the amplitude and the phase of the temporal mode are determined with respect to a commonly accepted reference, a phase-locked laser, we are now in a position to certify the (absolute) coherence of a network photon.



\begin{figure}[!b]
\includegraphics[width=0.99\columnwidth]{setup4.pdf}
\caption{Model of the experimental setup. (a) A single atom of $^{87}$Rb is trapped in a high finesse optical cavity via a 2D optical lattice (not shown). The control field of Rabi frequency $\Omega(t)$ and $\pi$-polarization impinges from the side of the cavity. The incoming photon is a weak coherent pulse of temporal shape $e(t)$. The atom is coupled to the cavity field $\mathcal{E}(t)$ with the light-matter coupling constant $g$. (b) We use a $\Lambda$ scheme with three excited-states. The Zeeman states involved are $m_F=0$ for $F=1$ and $m_F=-1$ for $F=2$ and $F'=1,2,3$.}
\label{fig:setup}
\end{figure}

Our system uses the quantum memory scheme described in Ref.\@  \cite{Koerber2018} and therefore all the following results are also valid for single photons encoding a qubit in their polarization degree of freedom. We use a single $^{87}$Rb atom trapped in an optical high-finesse cavity. The cavity is resonant with the $\text{D}_2$ line of $^{87}$Rb at 780nm. Our output (or input) photon is resonant with the cavity and addresses the transition $\ket{F=1,m_F=0} \leftrightarrow \ket{F'=1,m_F=-1}$ with a single-photon detuning $\Delta$ (see Fig.\@  \ref{fig:setup}). The control light addresses the transition $\ket{F=2,m_F =-1} \leftrightarrow \ket{F'=1,m_F =-1}$  with the same detuning $\Delta$ such that the $\Lambda$ scheme is in two-photon resonance.
The combination of the two light fields drives the atomic population from the state $\ket{F=1, m_F=0}$ to $\ket{F=2,m_F=-1}$ in absorption and vice versa for emission. The cavity is asymmetric such that the photon mostly enters/leaves the cavity via the mirror with the highest transmission. We refer to the decay rate via this mirror as $\kappa_c$, whereas we name $\kappa_l$ the decay rate via the second mirror including intracavity optical losses  (see Fig.\@ \ref{fig:setup}). 



Ref.\@  \cite{Giannelli2018} provides a comparison of different models describing the photon absorption/emission by atomic systems \cite{Fleischhauer2000,Dilley2012,Gorshkov2007,Dalibard92}. The one proposed by Gorshkov \textit{et al.} \cite{Gorshkov2007} is particularly relevant for us as it considers a single-photon detuning $\Delta$. We adapt the derivation to a system with multiple excited states and obtain two important expressions, one for the relation between the complex-valued temporal shape of the single photon and the control field and another one for the efficiency of the absorption/emission.



The shape of the single-photon state is specified by its  temporal mode function $e(t)$ i.e. $\ket{1}=\int_\mathbb{R}dt\ e(t) \hat{a}^\dagger(t)\ket{0}$.
For the emission process, the link between the single-photon shape $e(t)$ and the Rabi frequency of the control field $\Omega(t)$ is of the same form as the one derived in \cite{Gorshkov2007}: 
\begin{multline}\label{eq:omega}
\Omega(t) = \frac{e(t)}{ \sqrt{ 2 \Re[K] \int_t^\infty |e(t')|^2 dt' }} \\
	\exp\left(- i \frac{\Im[K]}{2\Re[K]} \ln \left( \int_t^\infty |e(t')|^2 dt' \right) \right). 
\end{multline}
Here $K$ is a parameter containing all the characteristics of the atomic structure, the cavity parameters and the detunings, as derived in the Supplemental Material (SM). For coherent light-matter interaction, time reversal guarantees that the emission and the absorption processes are described by the same equation: the efficiency is the same and Eq.\@  (\ref{eq:omega}) written for emission is just reversed in time and complex conjugated for the  absorption.

\begin{figure}[!b]
\includegraphics[width=0.99\columnwidth]{eff_det.pdf}
\caption{Efficiency as a function of the single-photon detuning. (a) The three curves correspond to three theoretical models: The dotted blue line for one excited state with $F'=1$, the orange dashed line for two excited states with $F'=1,2$ and the plain green line for three excited states. The dots correspond to experimental measurements. The statistical errors are smaller. Data can be reproduced to within about 10\% (error bars). (b)-(d) Normalized temporal amplitudes for different detunings. The black lines correspond to the targeted shapes. The blue histogram corresponds to the detected photons with right circular polarization (R) and the red with left circular polarization (L). The amount of left polarized light compared to the expectation of only right polarized light witnesses the increase of incoherent processes for large detunings.}
\label{fig:efficiency}
\end{figure}

Following \cite{Gorshkov2007}, the ideal efficiency of the photon absorption/emission process $\eta_C=2C/(2C+1)$ only depends on the cooperativity $C=g^2/2\kappa\gamma$, where $g$ is the light-matter coupling constant, $\kappa = \kappa_c+\kappa_l$ the cavity field decay rate and $\gamma$ the atomic polarization decay rate. For our setup, the parameters have the values $(g,\kappa_c,\kappa_l,\gamma)=2\pi\times(4.9,2.4,0.3,3.03)\ $MHz \cite{CQEDNote}. For an imperfect cavity, however, the overall efficiency reduces to the product of $\eta_C$ and the escape efficiency $\eta_\text{esc}=\kappa_c/(\kappa_c+\kappa_l)$ \cite{Muecke2013}. With multiple excited states, the efficiency becomes a function of the single-photon detuning, $\eta_C(\Delta)$. Indeed, $\Delta$ modifies the strength of the interaction with each excited state.



Figure \ref{fig:efficiency} (a) compares the experimentally measured efficiency with three different models. The three curves correspond to the models with $F'=1$ only, with both $F'=1$ and $F'=2$, and all three excited levels $F'=1,2,3$. 
Both states $\ket{F'=1}$ and $\ket{F'=2}$ participate in the Raman process. Depending on the detuning, constructive or destructive interference occurs in the photon absorption/emission process. This explains that the efficiency varies with the detuning and can be larger or smaller than in the case with only one excited level $F'=1$. In contrast, $\ket{F'=3}$ does not couple to the ground state $\ket{F=1}$ but potentially destroys the emission process by incoherent scattering.


Surprisingly, the experimental data tend to follow the model with two excited levels. This is explained by the fact that the models provide the efficiency for a pure temporal mode whereas the single-photon counting modules detect any mode. Therefore, the theoretical efficiency can only be compared with the experimental one in the regime of coherent emission.
For instance, populating state $\ket{F'=3}$ in the emission process leads to decay back into the initial $\ket{F=2}$ ground state and thus to a new emission attempt. This starts at a random time and potentially from a different $m_F$ state. On average, this results in a mixture of wavepackets which are all detected by the single-photon counting modules although they are not part of the coherent emission process.


The presence of incoherent processes in the photon emission is well illustrated in Fig.\@  \ref{fig:efficiency} (b)-(d). Here the temporal distributions of the single-photon detection events are plotted for left and right circular polarizations. For a large red detuning or close to the transition to $\ket{F'=3}$, the photon shape alters and (unwanted) left circularly polarized photons are generated. A simulation of the full system has been performed and supports the experimental observations (see SM). 



\begin{figure}[!t]
\includegraphics[width=0.99\columnwidth]{HDmode20MHz.pdf}
\caption{Measurement of the complex temporal shape. The real and imaginary parts of $e(t)$ reconstructed by temporal mode analysis are plotted in arbitrary units but identical scales. (a) corresponds to the case without compensation of the phase chirp induced by light shift, and (b) to the case with phase compensation.  The plain lines correspond to the experimental measurements and the dashed lines to the theoretical shapes. When the phase chirp is compensated, the fidelity between the target shape and the measured one is 90\%. The dotted lines in plot (b) correspond to the shape with a residual detuning of 180kHz with which the fidelity goes up to 98\%. In contrast, without phase compensation, the fidelity is 55\%. For these measurements, the detuning is $\Delta/2\pi = -20$MHz and the targeted temporal shape $e(t)$ of the single photon is a hyperbolic secant with the characteristic time $T=0.5\mu$s.
}
\label{fig:temporal_shape}
\end{figure}

The presence of light in both polarization modes indicates the occurrence of incoherent processes. \textit{A contrario}, the absence of two polarizations in Fig.\@  \ref{fig:efficiency} (c) does not guarantee the coherence of the wavepacket. In addition, the measurement via photon counting does not provide any information about the phase of the temporal shape $e(t)$. In particular, Eq.\@  (\ref{eq:omega}) predicts a time-dependent phase term. This term actually accounts for the light shift induced by the control field. Without compensation of this phase, a frequency chirp is imprinted on the emitted photon.
This chirp is unwanted and can enlarge the photon bandwidth to a value larger than the cavity bandwidth, thus decreasing the emission efficiency. We emphasize here that Fig.\@  \ref{fig:efficiency} was measured with phase compensation that is achieved by properly controlling the phase of the control laser.

In order to evaluate the temporal shape $e(t)$ of the emitted photon, i.e. amplitude and phase, we use a temporal mode analysis technique \cite{MorinMode,Morin2019,LvovskyMode}. As explained in the SM, from a set of homodyne measurements we obtain the real and imaginary part of the temporal mode function $e(t)$. Figure \ref{fig:temporal_shape} shows two cases: (a) without phase control and (b) with phase compensation. Figure \ref{fig:temporal_shape}(a) clearly shows the frequency chirp induced by the control field.
The fidelity with a purely real temporal shape is 55\% in that case \cite{Fid_temp_mode}, showing the detrimental impact of the phase chirp in case it is not properly compensated. With compensation, the imaginary part in Fig.\@  \ref{fig:temporal_shape}(b) becomes  smaller and the fidelity increases up to 90\%. The majority of the remaining infidelity is likely to originate from a residual constant detuning of 180kHz of the local oscillator, as including this into the theory results in a fidelity of 98\%.

In addition, we obtain a photon-number distribution with $p_\ket{0}=0.716(2)$, $p_\ket{1}=0.284(2)$ and $p_\ket{2}=0.001(2)$. Considering the global detection efficiency of 0.6 and the atom preparation efficiency of 0.74, we estimate $p_\ket{1}\approx 0.64$ at the output of the cavity for each successful preparation of the atom. This result agrees with the one obtain by single-photon counting (see SM).

\begin{figure}[!t]
\includegraphics[width=0.95\columnwidth]{mode_select.pdf}
\caption{(color online) Temporal mode selection. (a) In black is plotted the amplitude of the input photon (experimentally a weak coherent state), which at time $t=0$ has a phase jump of $\Delta\phi$. The two other plots correspond to the amplitude of the control field, in plain blue without a phase jump, in red dashed with a phase jump of $\pi$. (b) The global efficiency (absorption and emission) as a function of $\Delta\phi$ for the two different control phase profiles. The curves are fits of the form $A\sin^2 (\Delta\phi+\phi_0) +B$. }
\label{fig:selection}
\end{figure}



Similarly to the emission case, the phase of the temporal profile is also important in absorption. Indeed, not properly compensating the phase chirp induced by the light shift leads to a temporal mode mismatch between the incoming photon and the storage mode defined by the shape of the control field. Figure \ref{fig:selection} illustrates this important aspect. We apply a phase jump of $\Delta\phi$ in the middle of the temporal shape of the input photon. Hence, for a $\pi$ phase jump, the input single photon has a temporal shape orthogonal to the one defined by the control field. This results in a suppressed efficiency. In the case depicted in dashed red, we apply a $\pi$ phase jump on the control field such that, this time, the input photon without phase jump should not be stored as it lives in an orthogonal temporal mode. Note that here and in the following experiments, we use a weak coherent state with a well controlled shape as an input.





By combining absorption and emission, it is in principle possible to convert between arbitrary shapes. We have realized two different conversions. In the first one, we store a photon of duration $T=500\mu$s and re-emit it with a new duration of $T=0.5\mu$s with an overall efficiency of 17\%. In the second one, we have performed the opposite transformation, from $T=0.5\mu$s to $T=500\mu$s, with an efficiency of 22\%. Figure \ref{fig:convert} displays the two corresponding output shapes measured by photon counting. With a total efficiency of about 20\% and a change of pulse duration by three orders of magnitude, our system outperforms the non-unitary reshaping that can be achieved with any amplitude modulator \cite{Kolchin}. This opens up the possibility to connect quantum devices working at very different time scales.


\begin{figure}[!t]
\includegraphics[width=0.98\columnwidth]{convert.pdf}
\caption{Photon conversion: A single photon (experimentally a weak coherent state input) is stored and re-emitted with a different temporal shape with constant efficiency. (a) and (b) illustrate two different photon shape conversions $T=0.5\mu\text{s}\leftrightarrow T=500\mu\text{s}$. The histograms correspond to the detection event of the photon counters and the plain lines correspond to the targeted temporal shapes. In (b) we have subtracted the dark counts of the photon counters. 
}
\label{fig:convert}
\end{figure}

Although most of our results show a very good agreement between theory and experiment, the efficiency of about 20\% does not match the theoretical value of $(66\%)^2=43\%$, assuming that absorption and emission have the same efficiency. As we have measured an emission efficiency of about 66\%, this tends to indicate that the absorption is a factor of two smaller than expected. This difference remains unexplained and neither the theory nor the experimental imperfections seem to quantitatively explain the observed discrepancy. Nevertheless, except for this point, our efficiency is in principle not fundamentally limited, and ideally a unitary emission/absorption/transformation is achievable with a non-lossy cavity and a higher cooperativity, as explained above.



In conclusion, we have shown two main achievements. First, we developed a comprehensive description of light-matter interfaces using CQED. This allowed us to extend the operating parameters, especially the detuning of the control laser and the cavity, over a wide range into a regime that was not explored before. For large detunings, we found it mandatory to compensate the photon phase chirp that stems from the in this case large time-dependent control-laser intensity. We also identified efficiency limitations from destructive interference of emission pathways as well as decoherence issues from spontaneous emission and optical pumping. It is worth noting that the drawn results apply formally to any CQED system, and that most of the observed effects are relevant for other physical platforms \cite{Kurpiers2018}. 

Second, we used this understanding to demonstrate an unprecedented level of control of the temporal shape of a single photon in absorption and emission, and thus transformation. These are crucial capabilities in many quantum information protocols involving single-photon states. For instance, it allows to achieve a high level of indistinguishability between multiple systems and therefore sustains the scalability of single-photon based quantum architectures. Of course, all the discovered features can immediately be transferred to single photons carrying polarization qubits.

Last but not least, the extended parameter regime with the possibility of using the cavity far-detuned from the atomic resonance will be an important tool for coupling individual atoms from a multi-atom quantum register to the same cavity \cite{Enk97}.\\[0.2cm]





We thank L. Giannelli and S. Ritter for discussions. This work was supported by the Bundesministerium für Bildung und Forschung via the Verbund Q.Link.X (16KIS0870), by the Deutsche Forschungsgemeinschaft under Germany’s Excellence Strategy – EXC-2111 – 390814868, and by the European Union’s Horizon 2020 research and innovation programme via the project Quantum Internet Alliance (QIA, GA No. 820445).



\bibliographystyle{plain}

\let\oldaddcontentsline\addcontentslin
\renewcommand{\addcontentsline}[3]{

