Real-time calibration of coherent-state receivers: learning by trial and error

The optimal discrimination of coherent states of light with current technology is a key problem in classical and quantum communication, whose solution would enable the realization of efficient receivers for long-distance communications in free-space and optical fiber channels. In this article, we show that reinforcement learning (RL) protocols allow an agent to learn near-optimal coherent-state receivers made of passive linear optics, photodetectors and classical adaptive control. Each agent is trained and tested in real time over several runs of independent discrimination experiments and has no knowledge about the energy of the states nor the receiver setup nor the quantum-mechanical laws governing the experiments. Based exclusively on the observed photodetector outcomes, the agent adaptively chooses among a set of ~3 10^3 possible receiver setups, and obtains a reward at the end of each experiment if its guess is correct. At variance with previous applications of RL in quantum physics, the information gathered in each run is intrinsically stochastic and thus insufficient to evaluate exactly the performance of the chosen receiver. Nevertheless, we present families of agents that: (i) discover a receiver beating the best Gaussian receiver after ~3 10^2 experiments; (ii) surpass the cumulative reward of the best Gaussian receiver after ~10^3 experiments; (iii) simultaneously discover a near-optimal receiver and attain its cumulative reward after ~10^5 experiments. Our results show that RL techniques are suitable for on-line control of quantum receivers and can be employed for long-distance communications over potentially unknown channels.

In the past few years, the use of machine learning methods to deepen the understanding of fundamental physics has become a standard technique [27][28][29][30][31][32][33][34][35][36].Machine learning can be classified as supervised, unsupervised and reinforcement learning (RL).In particular, RL studies the behaviour of an agent interacting with an environment via observations, actions and rewards.The goal is to optimize such interactions in order to maximize a suitable figure of merit, e.g., the expected reward over time.Combinations of these three machine-learning classes have recently led to out-performing the best human GO player, discovering strategies never played before [37].Recently, RL techniques have also been proved successful in quantum information, e.g., in the design of novel quantum experiments [32], quantum errorcorrection codes [33], quantum communication protocols [34] and optimal control of quantum systems [35,36].
We propose an innovative and experimentally appealing approach to the problem: the search for optimal discrimination strategies is cast as a test-bed for RL, by studying how well an agent can perform in calibrating a receiver by means of model-free methods.The nature of our approach is particularly appealing for scenarios where an accurate description of the system is not possible, e.g., due to intrinsic complexity, experimental constraints or imperfections, untrusted devices or simply lack of knowledge.This is precisely the case for applications of coherent-state discrimination in communication scenarios, where discriminating multiple hypotheses may require tuning long sequences of gate parameters [53][54][55][56], the detectors may be affected by losses and darkcounts [43,52], the actual communication channel may add different kinds of noise depending on the physical implementation [4,5,57,58] and device-independent security may be additionally required [13,17].
In this article we show that a RL agent can achieve near-optimal control of a coherent-state detector when it has zero prior knowledge of: (i) the energy of the coherent states themselves; (ii) the actual operations that the detector performs; (iii) the underlying quantum-mechanical laws governing the system.By trial and error, the RL agent has to sequentially press buttons and select actions according to previous measurement outcomes and at a final stage guess for one of the possible hypotheses.A non-zero reward is given only if the guess is correct.By repeating the procedure over several episodes (or runs), the agent earns experience and learns a near-optimal discrimination protocol and guessing rule with the resources at its disposal.
Our approach differs from previous applications of RL in quantum information [32][33][34][35][36] at least in three crucial aspects: (i) our agents can simultaneously learn and be tested in a completely model-free setting; (ii) each reward is obtained directly from a single-shot experiment and not indirectly inferred from a known model or from several runs of the experiment as in the case were the reward is, say, a target fidelity or a success probability; (iii) we will not only be concerned about finding nearoptimal detectors but also, importantly, on the actual on-line success rate of the agents as measured by the cumulative reward.
We tackle the problem in three stages of increasing complexity: first, in the model-aware setting, where the outcome probability function of the receiver is known, we find the optimal action sequence by solving the Bellman equation via dynamic programming [43,59]; second, in the model-free setting, where the receiver is completely unknown, we apply Watkins' Q-Learning [60,61], a standard RL method whose update rule approximates the optimal Bellman equation; third, in the model-free setting we study the trade-off between exploiting potential optimal strategies and exploring new ones, by applying two state-of-the-art methods adapted from bandit theory [62][63][64][65], thus enhancing the learning speed or accuracy of our agents.With these methods, in the modelaware setting we are able to compute numerically the optimal success probability and set of actions for several control rounds.Moreover, in the model-free setting we are able to construct agents that surpass the performance of the best Gaussian receiver [40] after ∼ 3 • 10 2 episodes and its cumulative reward after ∼ 10 3 episodes and then attain near-optimal performance (> 97% optimal) after ∼ 10 5 episodes, searching on a parameter-space of size ∼ 3 • 10 3 .Our results provide a flexible and comprehensive ensemble of methods both in the model-aware and model-free settings that enable the on-line optimization of small quantum devices and the benchmarking of their performance.Furthermore, the methods we propose can be enhanced by the use of deep-learning techniques [37], which would allow their application to more complex problems and devices, e.g., multi-state QSD and the study of generalization performance.
The article is organized as follows.In Sec.II we introduce our QSD problem, the receiver architecture and the target function for a RL agent controlling the receiver.In Sec.III we present the theoretical framework of standard RL methods, introducing the state-action value function, the Bellman equation and Q-Learning.In Sec.IV we describe the implementation of these methods and analyze their performance in terms of the cumulative reward.The bandit problem is introduced here as a basic framework to study, quantify and optimize the real-time performance of agents over sequential learning strategies.
We analyse and compare the performance of standard and bandit-inspired learning strategies in a variety of experimentally relevant settings.We conclude in Sec.V by mentioning possible extensions of our work.We consider the discrimination of two electromagnetic signals with opposite phases, described by two coherent states of the field, |±α , whose energy is proportional to |α| 2 .When the energy of the signals approaches zero, i.e., |α| 2  1, quantum effects become evident and it becomes impossible to discriminate between them perfectly.
Any binary discrimination protocol is described compactly by a quantum positive-operator-valued measurement (POVM), M = {M 0 , M 1 } with M 1,2 ≥ 0 and M 1 + M 2 = I.Defining the k-th hypothesis as α (k) = (−1) k α, with prior probability p k , the probability of obtaining outcome k given that hypothesis k was true is p( k|α (k) ) = α (k) M k α (k) and the best guess is given by the most likely hypothesis given that outcome.Thus the average success probability over all outcomes is given We depict the experimental setup of the receiver considered.For L → ∞ one gets Dolinar reciever. by For non-orthogonal quantum states, this quantity is bounded below 1 by the so-called Helstrom bound [1], which in our case reads where the optimization is carried out over all twooutcome POVMs; note that the Helstrom probability tends to 1/2 for |α| → 0, i.e., the states become indistinguishable at very low energies.The optimal Helstrom measurement that attains Eq. ( 2) is a difficult projection on a superposition of |±α , i.e., a Schrödinger-catlike state, which cannot be realized with simple linearoptical operations [44].Quite surprisingly, Dolinar [41] showed that Eq. ( 2) can be asymptotically attained by continuous-time control of a displacement operator; his receiver has since been extended to the discrete-time scenario by Takeoka et al. [44].Nevertheless, the practical implementation of these receivers still proves demanding at present [46,51], due to various experimental limitations.Moreover, in a general communication scenario, the states will be transferred through a noisy channel and could be subject to various kinds of noise, e.g., loss, thermal noise and phase diffusion [52,58].
Based on these premises, we aim to construct a modelfree RL agent that, without any knowledge of the problem at hand nor of the receiver setup, learns to tune the receiver's parameters in order to maximize its success probability.In this way, when placed in a real-life situation, the agent will be able to train and optimize the receiver for the specific experimental conditions it encounters in real time.The receiver we consider comprises passive linear optics, photodetectors and classical feed-forward, structured into successive processing layers = 0, • • • , L, as depicted in Fig. 1; this receiver is known to attain the Helstrom probability in the limit L → ∞ [44].For each layer < L, the following operations are applied: 1.The input signal |α is split on a beamsplitter (BS) of transmissivity θ, effectively extracting a fraction 1−θ of the energy for detection.The BS transforms the input signal and vacuum states as where the added phase of the second mode has been corrected via a proper phase-shift, not shown in the figure.3. The displaced signal is measured via a on/off photodetector, which detects no photon, i.e., outcome o +1 = 0, with conditional probability and detects one or more photons, i.e., o +1 = 1, with probability 1 − p(o +1 = 0|α, (β, θ)).
4. The transmitted part of the signal enters layer +1.
Finally, the last processing layer = L consists in elaborating a guess k of the true hypothesis k, based on previous measurement outcomes and parameter choices.
For an initial coherent state |α , the input state at the -th layer is |α Since the experimenter can use all the past history h = (a 0 , o 1 , • • • , a −1 , o ), with h 0 = ∅, to decide the next value of (β, θ) and the final guess, the total set of parameters over all possible histories is of exponential size in L. We label them compactly as a (h ) = (β h , θ h ) and a L (h L ) = k, omitting the label or the dependence on h when it is clear from the context.Hence, the average success probability of this strategy over all possible outcomes' sequences where {a } is the total set of actions over all histories and we have written the conditional probability of the sequence of outcomes o 1:L factors as a product of singlelayer conditional probabilities, (4).
In the model-aware setting, this expression can be optimized using dynamic programming, as we show in Sec.IV A, finding the set of optimal parameters {a * } for any given α and L: As a shorthand we denote the optimal success probability (over the available actions) as and omit the label L when it is clear from the context.In the model-free setting instead, the agent has no knowledge of Eqs.(4,5), so it must resort to exploring the set of possible parameters and sample from the probability of (5) during several runs of the experiment to discover an optimal choice of parameters and guessing rule by trial and error.

III. SEQUENTIAL DECISION-MAKING
The framework of RL is based on the interaction between an agent and an environment during several episodes [61].At each time-step = 0, The environment is usually modeled to be Markovian: its dynamics is completely determined by the last timestep via the transition function τ (s , r|s, a), i.e., the conditional probability of ending up in a state s and conferring a reward r, given that the previous state was s and the agent took an action a; the next future states accessible from s are thus restricted to S(s) = {s : τ (s |s) = 0} ⊆ S. The agent does not have control of nor access to the transition function, but it will influence the dynamics of the environment by choosing actions according to an interaction policy π(a|s), i.e., the conditional probability of performing an action a when the observed environment's state is s; hence the available actions at a given state may be restricted to a subset A(s) ⊆ A. This setting is usually known as a Markov decision process (MDP).
Informally, the agent's objective is to interact with the environment through an optimal policy π * , such that the total reward acquired during an episode is as high as possible.To achieve this goal, a value function is assigned to each state and optimized over all possible policies, as further explained below in Sec.III A.
The Markov assumption is justified whenever the agent's observations provide a complete description of the state of the environment s .However, in general this is not the case, and the agent has only access to partial observations o ∈ O at each time-step.Such observations would not allow to determine the dynamics even if τ was known, and they are generated from the current state and the previous action.In RL literature this is called a partially-observable MDP (POMDP) and developing methods to solve it efficiently constitutes an active area of research [66][67][68][69][70]; usually, the problem is tackled by first reducing it to an effective MDP.The most straightforward approach is to define an effective state that contains all the past history of observations and actions up to a given time-step, i.e., h = (a 0 , o 1 , • • • , a −1 , o ).In this way, the dynamics observed by the agent can always be described by an effective MDP with transition function τ (h , r|h, a), which is unknown to the agent and determined by the underlying environmental transition function.Clearly, this approach makes the problem intractable for large time-steps, since the number of states increases exponentially in L. In the model-aware setting, one can condense the history in a belief distribution over the states, b o (s ) = p(s |o , a, b o ), i.e., the probability that the environment is in state s given the current observation o , the previous action a and the belief at the previous time-step b o .The belief has an initial value b(s) equal to the prior distribution over the initial states and at each time-step it is updated using Bayes' rule.In the following parts of this Section we will introduce several tools for MDPs, which can be immediately adapted to POMDPs by exchanging the unknown state with the history h or the belief b o (s).

A. Value functions and the Bellman equation
The agent's objective is to acquire as much reward as possible during an episode.As a matter of fact this strongly depends on the agent's policy.At the end of episode t, in which a sequence of L tuples {(s , a , r +1 )} L =0 has been experienced (with s L+1 a terminal state, and L generally varying among different episodes), the agent's performance after each time-step can be evaluated using the so-called return, i.e., the weighted sum of rewards obtained at all future time-steps, with a discount factor γ ∈ (0, 1], which weighs more the rewards that are closer in the future.Note that for infinite-horizon MDPs, i.e., L → ∞, it must hold γ < 1 to ensure that G remains finite.By introducing the return, it is straightforward to assign a value to a state s for a given interaction policy π, via the so-called value function: which is the expected return over all possible trajectories that start from state s, take actions according to policy π and whose dynamics is governed by τ .In other words, the value function measures how convenient it is to visit state s when policy π is being followed.Note that this quantity is completely determined by the future trajectories accessible from s and hence its dependence on the time-step can have at most the effect of restricting the set of states on which v π (s) is supported at that time; we keep this dependence implicit unless otherwise stated.By writing explicitly the expected value for the first future time-step in Eq. ( 9) and then applying the definition of v recursively, it is easy to show that the state-value function satisfies, for any policy, the following Bellman equation [59]: τ (s , r|s, a)π(a|s) r + γvπ(s ) .(10) This equation relates the value of a state s with that of its nearest neighbours s , which can be reached with a single action from s, and with the corresponding reward obtained by performing such action.
The problem can then be solved by finding an optimal policy π * , namely one that maximizes the state-value function for each s (also called optimal value function), and thus satisfies the optimal Bellman equation: Similarly, one can define the state-action value function (or Q-function) as the expected return when starting from state s and performing action a: which is related to the state-value function by v π (s) = a∈A π(a|s)Q π (s, a).Thus, the optimal policy π * can also be obtained by maximizing the Q-function, with a corresponding optimal Bellman equation

B. Model-aware learning
In the model-aware setting, where the transition function is known, an optimal policy can be efficiently found off-line by optimizing the corresponding state-value function.This problem, known as planning [61], can be solved for finite-horizon MDPs via dynamic programming methods.We follow the method introduced by Bellman [59], which makes use of the recursive relation of Eq. ( 11) to find the optimal policy step by step; for this we assume that every episode deterministically ends at a fixed timestep L, and denote by v * (s) the optimal value function of state s at time-step (problems in which L is not fixed can be solved, for instance, via value iteration [61]).
Since the optimal policy consists in taking the best possible action from any given state, it can be constructed by concatenation of the optimal policies at each time-step: we start by solving Eq. ( 11) at the last time-step, where we have omitted the terminal state s L+1 and used the fact that v L+1 (s) = 0.The solution to Eq. ( 14) provides the optimal action at step L − 1 for each s and the optimal value function v * L (s).Then we plug the latter into the optimal Bellman equation for the previous time-step, which in turn can be solved to obtain the optimal action and value function v * L−1 (s).By repeating this procedure iteratively for each time-step = L, • • • , 0, we can obtain the optimal sequence of actions and value functions for any state at any time-step.

C. Q-learning
In the model-free setting, the agent not only has to find an optimal policy by exploiting valuable actions, but also needs to characterize the environment in the first place by exploring possibly advantageous configurations.This is known as the exploration-exploitation trade-off and lies at the core of RL problems [61].In this setting, the Qfunction is quite helpful since it associates a value to the transitions determined by taking action a from state s and following policy π thereafter.
Q-learning was first proposed by Watkins [60], and it is often used as a basis for more advanced RL algorithms [67,71].It is based on the observation that any Bellman operator, i.e., the operator describing the evolution of a value function as in Eqs.(10,11,13), is contractive [72].This implies that, under repeated applications of a Bellman operator, any value function converges to a fixed point, which by construction satisfies the corresponding Bellman equation.Thus, in order to find Q * (s, a), Q-learning turns the optimal Bellman equation for Q, Eq. ( 13), into an update rule for Q(s , a ), i.e., the Q-function's estimate available to the agent at a given time-step of any episode t = 1, • • • , T .
After an interaction step s → a → r +1 → s +1 is experienced, the update rule for the Q-estimate is where λ t (s, a) is the learning rate, which depends on the number of times the state-action pair (s , a ) has been visited.Note that in order to do the update at each timestep , it is only necessary to enjoy the next immediate reward r +1 and observe the next state s +1 ; this method thereby allows an on-line learning of the MDP.A pseudocode of the algorithm is given in Algorithm 1.
After a large number n of iterations of the update rule Eq. ( 15) for all state-action couples, the convergence of the Q-estimate to the optimal Q-function is guaranteed by two general conditions on the learning rate (also known as Robinson conditions) [60,61]: where the sums are taken over all interactions at which a given state-action couple is visited.Once the optimal Q-Algorithm 1: Q-learning pseudo-code.
input : Q(s, a) arbitrarly initialized ∀s ∈ S ∀a ∈ A(s); learning rates λt(s , a for t in 1 ... T do initialize s0 for step in episode t do take action a according to π (e.g.-greedy) observe reward r +1 and next state s +1 update Q(s , a ) according to: function is obtained, an optimal deterministic policy can be constructed by "going greedy" with respect to it, i.e., π * (a|s) = δ(a, arg max a∈A Q * (s, a)) for all s ∈ S, where δ(x, y) is a Kronecker delta.
In RL literatue, Q-learning is classified as an off-policy method [61], meaning that it learns the state-action values of a target policy -in this case the optimal policy -by taking actions according to an interaction policy, generally differing from the first one.The standard Q-learning method commits to an -greedy interaction policy, where with probability the agent chooses a random action and otherwise it chooses the greedy action that maximizes the current Q-estimate.However, as we will see below, more general strategies can be considered.

IV. MODEL-FREE REINFORCEMENT LEARNING OF DISCRIMINATION STRATEGIES
In the following we frame the optimization of the receiver described in Sec.II into a RL context, in which an agent has to attain optimal reward-per-episode rate (success rate) by departing from a situation of complete ignorance of the experiment.For simplicity, we assume that the sender and receiver have a shared reference frame, so that we can take the states and displacements to be real, α, β ∈ R, without loss of generality.
The notation introduced in Sec.II is straightforward to translate into the RL notation of Sec.III: • Each episode t corresponds to an independent discrimination experiment, with a new default state s 0 = α (k) sampled from p k , k ∈ {0, 1}; we set γ = 1 since the process has finite horizon; • Each episode consists of L + 1 time-step = 0, • • • , L, corresponding to the L detection layers followed by the final guessing stage; • The possible states of the environment at timesteps are s = α (k) , i.e., the transmitted part of s 0 at that layer; • The agent is not aware of the state s , in particular it does not know which hypothesis is true, but it can observe the measurement outcome o , 0 < ≤ L; • The actions a available at time-step 0 ≤ < L are the displacements β and BS parameters θ available at that layer, conditioned on the history of observations h , while at the last step they constitute the guess, a(h L ) = k ∈ {0, 1}; • The reward r ∈ {0, 1} is non-zero only at the end of the episode and provided that the guess is correct, hence the transition function for the environment is were we omitted the trivial reward for ≤ L.

A. Benchmarking the success probability via dynamic programming
In order to benchmark the performance of our RL agent, we start by considering a model-aware POMDP where the agent knows the amplitude |α| of the optical signals and the transition probabilities; its task is to optimize the success probability of Eq. (5).In this case, we define b (k) = p(α The optimal Bellman equation, Eq. ( 14), for the statevalue function of this POMDP at step L reads which means that at the last step, if the final belief distribution over the states is known, the best guess is the hypothesis with maximum likelihood.The optimal Bellman equation at step < L instead reads of the belief distribution, these cannot always coincide with the values, determined by Eq. ( 19), needed to solve Eq. ( 21) and hence we use interpolation methods to obtain them.
The maximum success probability attainable with the receiver is equal to the optimal value function at step = 0, since the latter corresponds to the expected reward starting from the initial belief distribution: as can be seen by repeated applications of Eqs.(19,21) and detailed in Appendix A In Fig. 2 we show the optimal success probability obtained with this method as a function of |α| 2 and for up to L = 8 layers.We also show the results at fixed θ such that the input state of each layer has equal amplitude

√
L−1 for all (dashed lines).We observe that for all L ≥ 2 there is an energy threshold above which allowing adaptive optimization of the attenuations gives a better success probability than adding one layer with fixed attenuations.

B. Learning a near-optimal receiver via Q-learning
In this Subsection we present the results obtained by a RL agent based on Q-Learning with -greedy interaction policy.The experiment is modelled as a POMDP, which can be reduced to an effective MDP for the history of observations and actions h , as explained in Sec.III.The update rule for the Q-function is given by Eq. ( 15) with s → h and learning rates λ t (h, a) = N t (h, a) −1 , the inverse of the number of times a state-action pair has been visited.This choice guarantees convergence as per Eq. ( 16).As for dynamic programming, the optimal value of the success probability of Eq. ( 5) is obtained by maximizing the optimal Q-function at time-step = 0: where we have omitted the default history state h 0 = ∅; this is detailed in Appendix A. At variance with the model-aware case, where the guessing rule was obtained straightforwardly from the Bellman equation at the last time-step, the optimization of Eq. ( 23) includes a nontrivial search for the optimal guessing rule, determined by the optimal Q-function.
We evaluate the performance of the agent using two figures of merit as a function of the number of episodes elapsed so far, t: (i) the cumulative return per episode (also called average reward per episode) where r (i) L+1 = {1, 0} stands for the correctness of the guess made at episode i, and (ii) the success probability of the best actions according to the agent, at the current episode, where the best actions {a (t) * } at episode t are obtained by going greedy with respect to the current Q-estimate, i.e., The first figure of merit, R t , is usually employed to describe the learning process in RL and it evaluates the success rate obtained by the agent so far.On the other hand, the second figure of merit, P t , is standard in QSD and in our context it evaluates the best strategy discovered by the agent so far.As t → ∞, for a good learner it is expected that R t → P t , i.e. with enough learning time the average reward should tend to the success probability for the best actions found by the agent, which in turn should converge to the optimal success probability P (L) * .Therefore, the learner is not only expected to find a good discrimination strategy, but to also follow it: the interaction policy should tend to the optimal policy.This feature is captured by the evolution of R t over different episodes: a good learner is asked to obtain as much reward as possible during the learning process.
Here and in the rest of the article, we restrict to L = 2 interaction layers and fix the attenuation coefficients to give equal amplitude at each layer, since the difference in success probability is small compared with the additional number of episodes one would need to learn it, as shown in Sec.IV A. We choose a resolution of 21 points for each displacement, each one ranging from -1 to 1 with step 0.1, leading to a fairly large state-action space: the agent has 3528 possible Q-values to learn from (including the last guess).We note that each discretized displacement is an independent action or "button" in the eyes of the agent -the agent is dispossessed of any notion of closeness between buttons corresponding to similar values of β.As the behaviour of the RL agent strongly depends on the actions chosen at early episodes, we averaged the learning curves over 24 agents.Our results are compared with: (i) the maximum success probability attainable with this number of layers and discretization of displacements, Eq. ( 7), and (ii) the success probability attainable via a standard homodyne measurement, which is optimal among Gaussian receivers [40].
In Fig. 3 we plot these two figures of merit for Qlearning agents with three different -greedy interaction policies: (i) a completely random one, i.e., = 1, (ii) a 0.3-greedy one, i.e., = 0.3, and (iii) a dynamic one (exp-greedy) that becomes exponentially greedier as time passes, i.e., (t) = max{e − t τ , 0.01}; this standard choice assures that at initial episodes the agent favours exploration, whereas at t = τ log 1 0 the agent's behaviour collapses to an 0 -greedy policy.
In the first place we note in Fig. 3 that a fully random search over the action space (1-greedy policy) leads to the extremely poor cumulative reward per episode of R t ≈ 1/2, even for long times, which is expected because a random guess (last action) leads to P s (α, {a }) = 1/2.Instead, since all the actions will be sampled enough times for the agent to learn the optimal policy, P t will converge to optimal value at long enough episode number.Nevertheless, if the action space is large, the fully random strategy will require a large number of episodes to explore each action a significant number of times, and for moderate times a -greedy strategy might reach a better strategy.Indeed, Fig. 3 shows that the 0.3greedy policy has at all episodes a higher P t than the 1-greedy one, being 99% the optimal success probability P (L=2) * at episode t = 10 5 .Of course, for 0.3-greedy policy the agent collects many more rewards (actual correct guesses) than for the 1-greedy but it is still limited to R t ≈ 0.7P (L=2) * . In order to reach a better exploration-exploitation trade-off, it is customary to consider an episode-dependent , e.g.(t) = max{e − t τ , 0 }.Fig. 3 shows the results for this tunable interaction policy with τ = 2•10 2 and 0 = 0.01.This allows the agent's R t to surpass the homodyne limit at about episode ∼ 5 • 10 3 (which is comparable with the size of the action space), while at later times the performance converges to that of the 0.01-greedy policy.Notice finally that 0.3-greedy discovers a strategy whose P t surpasses the homodyne limit at episode ∼ 3 • 10 2 .
Our numerical results show that standard Q-learning successfully trains agents that surpass the homodyne limit of optical detection and discover strategies whose error rate is comparable with that of the optimal receiver.This is remarkable, especially taking into consideration that the agents are not initially trained for this task, and run in a model-free setting entirely based on the feedback they get (correct/incorrect) on their guess.As mentioned above, although many RL schemes focus on extracting the optimal policy from the agent (as measured e.g. by P t ), our central figure of merit, R t , captures the real performance of the agent, and can actually be assessed by the agent itself.It is hence important to design strategies that not only aim at finding the optimal policy within an episode, but also maximize the cumulative reward per episode, reaching R t → P (L) * as fast as possible.We have seen above an example of such strategy (the exponential greedy) and in the next sections we will study more advanced ones.For this purpose we will first study a simplified setting, called the multi-armed bandit problem, where the intra-episode dynamics is trivial, and the main focus is drawn on how to optimize the inter-episode learning strategy.In passing, we introduce some theoretical tools in order to study the bandits' learning curves, which are a cornerstone to tackle more challenging situ-ations such as learning optimal policies over a MDP.

C. The multi-armed bandit problem
Multi-armed bandit problems are MDPs with a single default state at which the agent faces a fixed set of actions a ∈ A, each one leading to a reward r ∈ R with an unknown probability τ (r|a).After action a is performed, the reward r is enjoyed and the episode finishes: the return defined in Eq. ( 8) becomes r.The situation models a gambler at a row of slot machines that has to decide which arms to pull, how many times to pull each one and in which order, with the aim of maximizing the earned rewards.
The bandit problem is an ideal framework to highlight the aforementioned crucial difference between learning strategies that accomplish the main goal of identifying the optimal policy after a given number of episodes, and more refined strategies that also procure high de facto cumulative returns during the learning process.This is why bandit problems are very relevant in real-life applications where the final success probability is not the only figure of merit, as for example in clinical trials [73] where one needs to find the right compromise between advancing in the search of the best treatment while effectively treating current patients.
The general traits of the cumulative return per episode R t in Fig. 3 could inspire several ways of quantifying the performance of the learning agent, e.g., (a) the onset episode at which R t starts exceeding the random policy; (b) the transient episode at which R t reaches a given fraction of the optimal success probability; (c) the learning speed as quantified by the slope of R t after the onset episode; (d) the learning speed at which R t converges to the optimal success probability.Unfortunately, very little is known about these or alternative ways to characterize the learning curves.Nonetheless, bandit theory provides us with a framework were some of these notions can be defined and rigorously studied.In particular, bandit theory defines the so-called cumulative regret: where E indicates the expected value with respect to different agents following the same strategy, and a (t) is the action actually taken by an agent at episode t.The cumulative regret is closely related to the (expected) cumulative return per episode R t , and quantifies the price to pay, or loss, for taking actions different from the optimal one (a * ).In other words, it quantifies the difference in earnings of the agent with respect to those of a modelaware super-agent.One of the most fundamental results in bandit theory is the Lai-Robbins bound [74] for the asymptotic expected cumulative regret: and KL(a|| * ) the Kullback-Leibler divergence between the reward distributions τ (r|a) and τ (r|a * ).Recalling the definition in Eq. ( 27) we note that the Lai-Robbins bound characterizes the learning curve in the asymptotic regime, indeed the average return over agents, E R t can approach the optimal value not faster than E R t Q(a Algorithm 2: -greedy for bandit problems.
input : Q(a) arbitrarily initialized and learning rates λ t (a) ∈ (0, 1] ∀a ∈ A , ∈ (0, 1] for t in 1 ... T do generate a random number j if j ≤ then choose a at random else Note that by choosing the learning rates λ t (a) to be the inverse of the number of times action a was visited up to time t, then As stressed in Sec.IV B, the -greedy policy never attains the optimal success rate, ER t < Q(a * ) for all t, since at every episode there is a finite probability that the agent performs a suboptimal action.For this reason the expected cumulative regret grows linearly with t.It is then clear that there is room for improvement before reaching the logarithmic scaling of the ultimate limit of Eq. ( 28).We will present two strategies, one based on Upper Confidence Bounds (UCB) [63,74,75] and the other called Thompson sampling (TS) [64,73,76,77], which substantially improve the performance of -greedy and may even attain the Lai-Robbins ultimate bound [63,78].
In UCB, the agent keeps a record of the number of times each action a was selected up to episode t, which we denote as N t (a).Hoeffding's inequality bounds the probability that the Q(a) underestimates the true value of Q(a) by more than ε(t) > 0, as where here and in the rest of this section we assume that r ∈ [0, 1].Then, for N t (a) > 0, the upper confidence represents an upper bound to the true value Q(a) with (high) probability 1 − P(t).This value is used to compare and choose among the different actions, i.e. a = arg max a∈A ucb t (a), and responds to the motto "optimism under the face of uncertainty": actions that have not been visited enough are assigned an "optimistic" value of the return and hence more chances of being picked; in addition, actions whose Q-estimate is accurate but sub-optimal will have little chances to be picked again.The functional form of P(t) can be tuned to balance exploration and exploitation.In particular, for the standard choice P(t) = t −4 (here called UCB-1) it can be easily seen that the expected cumulative regret follows the logarithmic scaling [62,63].In Appendix B we also discuss a different choice, which is known to saturate the Lai-Robbins bound, but that performs worst than UCB-1 for our setting and moderately small number of episodes we consider.
Thompson sampling (TS) departs from the standard Q-learning paradigm, which is based on keeping track and be updating the Q-table.Instead, TS follows a Bayesian approach and at every episode assigns a full prior distribution (not just an expectation value) for the Algorithm 3: UCB for bandit problems.
input : P(t), initialize Q(a), N (a) to zero ∀a ∈ A . for t in 1, ..., T do if t ≤ A then (choose each action once) a = t else choose a = arg max a∈A ucbt(a), (Eq.( 31)) observe reward r record visit: expected reward r of every arm a, f t (r|a) ∀a ∈ A. This distribution characterizes the knowledge the agent has about the expected earnings of each arm, Q(a), and at the first episode can be taken to be flat over the whole interval [0, 1].The policy then consists in sampling an expected reward r ∼ f t−1 (r|a) for each possible action a and choosing the action with the largest sample r: a = arg max a∈A {r ∼ f t (r|a)}).Finally, the distribution for the chosen action is updated according to the true reward r obtained, using Bayes' theorem.
In order to avoid computationally-expensive Bayesian updates, families of distributions that are closed under the update rule are used.In the case of Bernoulli bandits, beta-distributions are employed since those are precisely their conjugate priors.That is, given upon obtaining a reward r the prior is updated to a beta distribution with parameters µ t+1 (a) = µ t (a) + r, ν t+1 (a) = ν t (a) + 1 − r, where at the first episode it is µ 1 (a) = ν 1 (a) = 1 ∀a ∈ A (flat prior).By mimicking the underlying distributions, TS gauges exploration according to the information acquired so far: if a certain action has not been sampled enough at episode t, its reward distribution will still be broad and, when sampled, can easily return a higher value of r than that obtained from other (more peaked) distributions; thereby TS will favour to explore such action.At the same time, if a sub-optimal action has been sampled enough episodes, it will be very unlikely that it is sampled again, since the corresponding prior will be highly peaked at low values.The pseudo-code of TS for Bernoulli bandits is described in Algorithm 4.
Figure 4 shows the performance of different strategies in a 3-armed bandit problem.For this purpose we have considered a simple optical receiver as described in Sec.II with a single layer L = 1.Since there is only a single detector with binary outcome, we have assumed a fixed decision rule.With this, each possible displacement β constitutes an action a 0 (recalling the notation used in last section) of a bandit problem.The figure shows that the cumulative regret scales linearly with time for thegreedy strategy, while it has a logarithmic scaling for the i.e. sub-leading constants and terms of order log(log t) might be important.Nevertheless, in the setting of Fig. 4 we see that the leading term captured by the slope of the curve is consistent with the ultimate bound.Let us conclude this overview of bandit theory by introducing the simple regret, another widely used figure of merit that, as P t , quantifies how well has the agent learned so far, regardless of his actual performance: where a (t) * is the agent's recommendation of which the optimal action is at episode t, which, e.g., in Q-learning would be given by a (t) * = arg max a Q(a).Strategies designed to minimize Λ t will prioritize to learn what the optimal arm to pull is, and the probability that the agent confuses the optimal arm by a sub-optimal one will be exponentially small, hence Λ t will converge to zero exponentially fast.Recent results [80] show that the exploitation-exploration trade-off manifests itself in the asymptotic scaling of the simple and cumulative regret in the sense that one imposes lower and upper-bounds on the other, and therefore optimizing one usually affects the performance of the other.

D. Enhancing the agent via UCB and TS
In this Subsection we consider two enhanced RL strategies, inspired by the advanced bandit methods introduced in Sec.IV C, and adapted to our MDP problem.
The first strategy employs the standard Q-learning update rule for the estimate Q, as described in Eq. ( 15), but it employs UCB to determine the interaction policy at each time-step of each episode, as described in Sec.IV C, with P(t) = t −4 (see Appendix B for a comparison of different choices on P(t)).This is implemented by keeping count of the number of visits of each history-action couple FIG. 5. We show the learning curves for the enhanced Qlearning agents via bandit methods.On the upper plot we despict Rt, the agent's success rate per episode, whereas on the bottom plot we despict Pt, the success probability of the agent's recommended actions at episode t, {a (t) * }.Each of the learning curves is averaged over 24 agents; the amplitude was fixed to α = 0.4.
up to the current episode t, i.e., N t (h , a ), which is then used to compute an upper confidence bound, ucb t (h , a ) as in Eq. ( 31), for each action a and history h .Finally, at time-step the agent chooses the greedy action w.r.t. the UCB, i.e., a (t) = arg max a ucb t (h , a).The second strategy is instead based entirely on TS, considering each action conditioned on the past history as a bandit problem and rewarding each sequence of actions that led to a successful experiment.In detail, the agent keeps a beta-distribution, Eq. ( 32), of the mean reward obtainable at each time-step from each action a given each possible history h , i.e., f t (r|h , a ).In order to choose a new action at time-step given history h , the agent samples an expected reward r ∼ f t (r|h , a ) for each a and selects the action with the largest sample r.At the end of the episode a reward is obtained as usual, and f t (r|h , a ) is updated in a Bayesian way for all the history-action couples visited at the episode.In this case, when computing P t , the best actions are chosen by going greedy w.r.t.their mean reward distribution f t (r|h , a ) [64].
In Fig. 5 we plot the two figures of merit R t , P t for agents trained using these two enhanced strategies, as well as for those based on the exp-greedy and 0.3-greedy strategies, considered in Sec.IV B, which had respectively the largest final R t and P t out of all the analyzed strategies.We observe that UCB performs a thorough exploration of the action space and indeed it is able to attain a value of P t close to that of 0.3-greedy.This result comes at the price of a small R t value, which nevertheless shows that UCB has better exploitation properties than 0.3-greedy; in particular it has a strikingly larger slope than the latter at long times.As for TS, we observe that this strategy attains the best R t values, surpassing exp-greedy at intermediate times.Moreover, TS also radically improves the values of P t w.r.t.expgreedy and it is even able to attain the performance of the other two strategies that favour exploration.Overall, it appears that for our problem TS provides the most profitable balance of exploration and exploitation; we expect this strategy to perform worst in scenarios in which the underlying distribution probability does not belong to the family of distributions used by TS.
In Fig. 6 we study the guessing rule discovered by the UCB agent at episode t = 5 • 10 5 .For each sequence of outcomes o 1 , o 2 , we plot the difference between the Qvalues of guessing for |−α , i.e., a L = 1, and |+α , i.e., a L = 0, as a function of the past actions: (34) Note that the sign of Eq. ( 34) corresponds to the agent's best guess for the true hypothesis, since the latter is obtained by going greedy towards Q(h L , a L ), as explained in Appendix A. We compare these results with the optimal guessing rule in the model-aware setting, plotting a shaded region when the maximum-likelihood guess is |±α .The plot shows that UCB agents perfectly learn the guessing rule at the given resolution.Moreover, the difference between the two Q-values is more pronounced in the surroundings of the optimal β values, meaning that the agents are more confident about their guess in these regions.
Finally, we show that RL agent's performance is independent of the coherent states' energy.For this we evaluate, for a range of different amplitudes |α|, the values of R t and P t attained by different the agents at episode t = 5 • 10 5 , comparing them with the optimal success probability P (L=2) * , as can be seen in Fig. 7.
In the following we turn to test model-free methods in realistic experimental scenarios, where the ultimate success probability is affected by the presence of noise.

E. Noise robustness
In the previous subsections we have shown that our RL agents are able to learn near-optimal discrimination strategies and -most importantly -exploit them in real time, employing exclusively the detectors' outcomes and the rewards at the end of each episode.Here we show that these results do not sensibly change in the presence of noise, i.e., that the same agents are able to attain nearoptimal performance even when unknown errors affect the experiment and hence the learning process.
Firstly, we consider a common experimental imperfection known as dark counts: due to the presence of background noise, each photodetector of the receiver has a non-zero probability p dc of detecting a photon even when it receives a vacuum signal.Accordingly, the con- ditional probability of obtaining an outcome 0 given an input state |α , Eq. ( 4), is modified by a multiplicative factor (1 − p dc ).In Fig. 8 we plot R t and P t at time t = 5 • 10 5 for several RL strategies as a function of p dc ∈ [0, 1], along with the maximum success probability attainable by the corresponding receiver.We see that the final values of P t are near-optimal for all values of p dc , while R t seems to be slightly affected in an intermediate region of values of p dc .Since the agents operate on a completely model-free basis and the reward system has been chosen to ensure convergence of the value function to the true success probability, it can be expected that they are still be able to learn in the long term, as shown by the high values of P t attained.However, since a dark count effectively increases the chance of (not) obtaining a reward for a (correct) wrong action, the time it takes to learn a near-optimal strategy and to start exploiting it might increase, as shown by the behaviour of R t .Note that for p dc ∼ 0.5 the best guess is the random one and thus easier to learn.
Next, we consider the case where the phase of the incoming signal is flipped before arriving to the receiver, with probability p f .In this scenario, if the agent guesses for the correct received phase, the corresponding reward will be zero since the phase initially sent was opposite than the received one.In particular, the probability of observing a string of outcomes p(o 1:L |α, {a(h L−1 )}) in Eq. ( 4) is modified such that In Fig. 9 we despict the values of R t and P t attained by several agents at episode t = 5 • 10 5 , as a function of p f ∈ [0.5, 1], along with the maximum success probability attainable by the corresponding receiver.As in the case of dark counts, we see that for all values of p f , the agents are able to converge to near-optimal P t values and they exhibit very small variations in R t as p f increases.

V. DISCUSSION AND CONCLUSIONS
In this article we provided an in-depth study of RL methods for the on-line optimization of coherent-state receivers based on current technology.Such receivers are crucial for the deployment of high-data-rate long-distance communications in free space or optical fiber and they are based on the interplay of several simple quantum gates and measurements, combined to create a complex structure.The RL methods that we analyzed enable to optimize such structure based on the actual experimental conditions and limitations of the communication channel and of the receiver.Thus, they possess a high potential for increasing the flexibility and effectiveness of current receivers and provide a useful addition to the current experimental toolbox.This is even more so the case if we consider that the methods we studied are relatively simple and rely only on "shallow" RL techniques, i.e., they are not based on the use of neural networks, which would allow to consider larger state-action spaces, possibly at the cost of a longer training time.We expect that the use of such "deep" RL methods could allow to control receivers of multiple and/or multi-mode coherent states, whose best performance is still to be determined at present.
On the other hand, the characterization of the cumulative or simple regret for intermediate times, through general non-asymptotic upper and lower bounds, as well as its extension from bandits to more general MDPs is still an open and active field of research.Quantum technologies can benefit from this progress, and non-trivial quantum features might appear in more general quantum learning scenarios.
Finally, we would like to stress that the RL problem induced by real-time state discrimination is characterized by intrinsically noisy and stochastic rewards.As such, it stands out from other instances where RL has been applied to quantum physics.In particular, even when performing a good set of actions and guessing rule, an agent might still not be rewarded.This is due to two crucial factors: (i) quantum states are intrinsically indistinguishable, i.e., even the best receiver has a non-zero probability of discrimination error; (ii) our methods can be applied in real time to the experiment, hence the binary reward received for a given set of actions is not sufficient to estimate the success probability of the corresponding receiver.Still, the best among our agents are able to reach good configurations and start exploiting them in a number of experiments which is roughly sufficient to try each set of actions only once.This is a key signature of the agents' intelligent behaviour, showing that they make the most out of each reward rather than blindly trying actions at random.Hence we believe that the discrimination problem provides an interesting, rich and flexible sandbox for testing RL in quantum-physicsinspired scenarios and will constitute an interesting line of work at the intersection between these two fields.

VI. CODE
The code developed to obtain the numerical results of this research can be found at github.com/matibilkis/marek.git.
Any suggestions, comments and even collaborations are welcome.

VII. ACKNOWLEDGMENTS
This project has received funding from the European Union's Horizon 2020 research and innovation programme under the Marie Sk lodowska-Curie grant agreement No 845255.We acknowledge support by the Catalan Government for the project QuantumCAT 001-P-001644 (RIS3CAT comunitats) co-financed by the European Regional Development Fund (FEDER), the Spanish MINECO, project FIS2016-80681-P and BES-2017-081836 with the support of AEI/FEDER funds; the Generalitat de Catalunya, project CIRIT 2017-SGR-1127.In this section we verify that -by construction -the optimal policy leads to the maximum success probability P (L) * (α).It is assumed that Q is always associated with the optimal policy π * ; we simplify notation by Q = Q π * .
At step L, given any history h L , the actions available to the agent are k = a L , i.e. guessing for one of the possible phases of the coherent state.The Q-values at this time-step read as r L+1 p(r L+1 |h L , a L ) = p(α (a L ) |o 1:L ; a 0:(L−1) ), (A1) with o 1: = {o 1 , o 2 , ..., o } the observations obtained up to the ( ) th photodetector, and a 0: = {a 0 , a 1 , ..., a } the actions done up to step .Recalling that the optimal action, given h , is obtained from Q as π * (h ) = arg max a Q(h , a ), the optimal guess a * L is the one of maximum-likelihood: By definition of the optimal policy and because optimal Bellman equation Eq. ( 13) holds, the optimal action to take given history h L−1 at step L − 1 is where in the last line we have used Bayes theorem.Following this line of reasoning, we can obtain the optimal actions a * at any time-step.In particular, for = 0, by recursively applying the optimal Bellman equation (Eq.( 13)) we have  for the initial state is the optimal success probability: (A5) In Fig. 10 we show several sections of the estimats Q, using 1-greedy as the interaction policy and each update made according to Algorithm 1, at episode t = 10 8 ,

2 .
The reflected part of the signal undergoes a displacement operation D(β), realizable via interference with a strong coherent signal on a smallreflectivity BS, not shown in the figure.The resulting state is |α(β, θ) = |α √ 1 − θ + β .
(k) |o , a −1 , b −1 ) to be the belief distribution over the states α (k) , after performing action a −1 and observing o , with prior belief b −1 (k).The initial value of the prior is b 0 (k) = p k and its update rule follows Bayes' theorem: b

)
FIG.2.We show the difference between the best probability of success attainable for a fix L and the optimal probability of success in discriminating two coherent states.The results were obtained by dynamic programming, exaplained in Sec.III B. Solid lines correspond to fixed attenuations θ such that the input state of each layer has equal amplitudeα (k) = α (k) √L−1 for all , whereas dashed lines correspond to the probability of success optimized also on conditional attenuations.

FIG. 3 .
FIG. 3. We benchmark traditional Q-learning with different schedules on as the episode number increases.The figures of merit are averaged over A = 48 agents and show the corresponding uncertainty region.

Algorithm 4 :
TS for Bernoulli bandit problems.input : µ1(a), ν1(a) initialized to one ∀a ∈ A for t in 1, ..., T do for a in A do draw ra according to Beta(µt(a), νt(a)) choose a = arg max a ra observe reward r update Beta distribution: µt+1(a) = µt(a) + r νt+1(a) = νt(a) + 1 − r UCB and TS strategies.The inset shows the cumulative regret as a function of log t together with the ultimate bound given by Lai-Robbins bound.The achievability of this bound is hard to observe in simulations because the convergence to the asymptotic results is very slow [79],

FIG. 6 .
FIG.6.Density plot of the difference between the estimated Q-values for guessing "plus" and "minus" as a function of the displacements at the first and second layer, for each possible sequence of outcomes, with α = 0.4.The shaded areas correspond to the regions where the optimal guess, taken according to maximum-likelihood, is "plus".The white dots corresponds to the optimal values of the displacements for the proper discretization).

FIG. 7 .
FIG.7.The performance at episode t = 5 • 10 5 of three different RL agents is evaluated as the energy of the coherent states increase.All data points are averaged over 24 agents.

FIG. 9 .
FIG.9.The performance at episode t = 5 • 10 5 of three different RL agents (the same considered in 5) is evaluated as a function of phase flipping probability before the signal arrives to the receiver.The amplitude of the coherent states is fixed to α = 0.4; all data points are averaged over 24 agents.

a 2 o 3 (FIG. 10 . 1 o
FIG.10.plot different values of the Q-estimates, after 10 8 episodes of random exploration ( = 1), updating the Q-estimates according to Q-learning (see Algorithm 1).The random exploration is used in order to ensure that, at finite number of episodes, all state-action pairs were equally visited on average.The lower plot corresponds to the estimates Q(a0), and it is compared with the optimal success probability as a function of a0, i.e.P (L=2) * (α, a0) =