Full text
University of Minho School of Engineering Rodrigo da Silva Gomes Peres Coelho Tradeoff between moving targets, gradient magnitude and performance in quantum variational Q-Learning september 2023
University of Minho School of Engineering Rodrigo da Silva Gomes Peres Coelho Tradeoff between moving targets, gradient magnitude and performance in quantum variational Q-Learning Masters Dissertation Master’s in Engineering Physics Dissertation supervised by Luís Paulo Santos André Sequeira september 2023
Copyright and Terms of Use for Third Party Work This dissertation reports on academic work that can be used by third parties as long as the internationally accepted standards and good practices are respected concerning copyright and related rights. This work can thereafter be used under the terms established in the license below. Readers needing authorization conditions not provided for in the indicated licensing should contact the author through the RepositóriUM of the University of Minho. License granted to users of this work: CC BY https://creativecommons.org/licenses/by/4.0/ i
Acknowledgements Writing this thesis has been a significant endeavor, and its completion would not have been possible without the assistance and support of many individuals. I’d like to take a moment to express my gratitude to those who have helped me throughout this process. I would first like to thank my supervisor, Professor Luís Paulo Santos, for providing guidance, feedback and support throughout this year. I am also extremely grateful to my co-supervisor André Sequeira, who was always available to discuss my research and to guide me in the correct direction. This work could not have been complete without your help. On this note, thank you for taking me under your wing on my first conference, which is always a scary experience. I would also like to thank my family, my parents, my brothers, my girlfriend and my friends. Thank you for the laughs and the good memories, but also for the continued support, especially during the hardships. I am sorry for sometimes pestering you with quantum computing and machine learning. Needless to say, I would not be here without each and every single one of you. This work is financed by National Funds through the Portuguese funding agency, FCT - Fundação para a Ciência e a Tecnologia, within project UIDB/50014/2020. I also thank the support of the Foundation for Science and Technology (FCT, Portugal) under grant 10053/BII-E_B4/2023. ii
Statement of Integrity I hereby declare having conducted this academic work with integrity. I confirm that I have not used plagiarism or any form of undue use of information or falsification of results along the process leading to its elaboration. I further declare that I have fully acknowledged the Code of Ethical Conduct of the University of Minho. University of Minho, Braga, september 2023 Rodrigo da Silva Gomes Peres Coelho iii Assinado por: Rodrigo da Silva Gomes Peres Coelho Num. de Identificação: 14431066 Data: 2023.09.27 13:38:24+01'00'
Abstract Reinforcement Learning (RL) consists of designing agents that make intelligent decisions without human supervision. When used alongside function approximators such as Neural Networks (NNs), RL is capable of solving extremely complex problems. Deep Q-Learning, a RL algorithm that uses Deep NNs, even achieved super-human performance in some specific tasks. Nonetheless, it is also possible to use Variational Quantum Circuits (VQCs) as function approximators in RL algorithms. This work empirically studies the performance and trainability of such VQC-based Deep Q-Learning models in OpenAI’s gym CartPole-v0 and Acrobot-v1 environments. More specifically, we research how data re-uploading affects both these metrics. We show that the magnitude and the variance of the gradients of these models remain substantial throughout training due to the moving targets of Deep Q-Learning. Moreover, we show that increasing the number of qubits does not lead to a decrease in the magnitude and variance of the gradients, unlike what was expected due to the Barren Plateau Phenomenon. This hints at the possibility of VQCs being specially adequate for being used as function approximators in such a context. We also use the Universal Quantum Classifier as a function approximator in VQC-based Deep Q-Learning and implement VQC-based models capable of achieving considerable performance in the Acrobot-v1 environment, a previously untapped environment for VQCs. Keywords Reinforcement Learning, Quantum Computing, Variational Quantum Circuits, Neural Networks iv
Resumo Reinforcement Learning (RL) consiste em projetar agentes que tomam decisões inteligentes sem supervisão humana. Quando usado em conjunto com aproximadores de funções, como Redes Neuronais (RNs), RL é capaz de resolver problemas extremamente complexos. Deep Q-Learning é um algoritmo de RL que usa RNs profundas e que alcançou um desempenho super-humano em algumas tarefas específicas. No entanto, também é possível utilizar Circuitos Variacionais Quânticos (VQCs) como aproximadores de funções em algoritmos de RL. Este trabalho estuda empiricamente o desempenho e a treinabilidade de tais modelos de Deep Q-Learning baseados em VQC nos ambientes CartPole-v0 e Acrobot-v1 do OpenAI gym. Mais especificamente, investigamos como o data re-uploading afeta ambas estas métricas. Demonstramos que a magnitude e a variância dos gradientes destes modelos permanecem substanciais ao longo do treino devido aos alvos móveis do Deep Q-Learning. Além disso, mostramos que aumentar o número de qubits não leva a uma diminuição na magnitude e variância dos gradientes, contrariamente ao que era esperado devido ao Barren Plateau Phenomenon. Isto sugere a possibilidade dos VQCs serem especialmente adequados para serem usados como aproximadores de funções neste contexto. Também utilizamos o Universal Quantum Classifier como um aproximador de funções em Deep Q-Learning e implementamos modelos baseados em VQC capazes de alcançar um desempenho considerável no ambiente Acrobot-v1, um ambiente anteriormente inexplorado para VQCs. Palavras-chave Reinforcement Learning, Computação Quântica, Circuitos Variacionais Quânticos, Redes Neuronais v
Contents I Introductory material 1 1 Introduction 2 1.1 Context ........................................ 2 1.2 Motivation ...................................... 4 1.3 Contributions ..................................... 5 1.4 Outline ........................................ 6 2 Reinforcement Learning 8 2.1 The Reinforcement Learning Problem Statement .................... 8 2.2 State and Value Functions and the Notion of Optimality ................. 12 2.3 Bellman Equations and Dynamic Programming .................... 14 2.4 Q-Learning ...................................... 16 2.5 Deep Reinforcement Learning ............................. 19 2.6 Deep Q-Learning ................................... 21 2.7 Policy-Gradient Algorithms and Taxonomy of RL .................... 24 2.8 Summary ....................................... 25 3 Quantum Computing 27 3.1 Context ........................................ 27 3.2 Quantum Circuits ................................... 28 3.2.1 Single-Qubit and Multi-Qubit Systems ..................... 28 3.2.2 Single-Qubit and Multi-Qubit Quantum Gates ................. 30 3.2.3 Measurements ................................ 32 3.3 Variational Quantum Circuits ............................. 32 3.3.1 Data Encoding ................................ 33 vi
List of Tables 1 Cartpole’s state space ................................. 49 2 Acrobot’s action-space ................................ 50 3 Acrobot’s state-space ................................. 50 4 Chosen observables for the two models tested in the Acrobot-v1 environment. ..... 80 5 An explanation of VQC-Based Deep Q-Learning’s hyperparameters ........... 94 6 Models’ hyperpameters from Figure 16 ........................ 95 7 Models’ hyperpameters from Figure 17 ........................ 95 8 Models’ hyperpameters from Figures 19 and 28. .................... 96 9 Models’ hyperpameters from Figure 26 ........................ 96 10 Models’ hyperpameters from Figure 29. ........................ 97 xiii
xiv
Part I Introductory material 1
Chapter 1 Introduction 1.1 Context Intelligence has played a pivotal role in evolution. Loosely defined, intelligence is the ability to process information and make decisions based on that information. Humans, in particular, possess unique cognitive abilities that set them apart from all other animals. These abilities enable technological evolution, complex communication, environmental manipulation, and music, among many others. Consequently, a question arose - Can machines replicate these capabilities if humans build them? Alan Turing posed this question in the 1940s in a public conference and, in 1950, published the seminal work Turing [1950], which started the development of the research area known as Artificial Intelligence (AI) . AI is the research of machines performing tasks typically associated with human intelligence. Since then, the trajectory of AI has featured waves of optimistic predictions, followed by disillusionment, and then a resurgence of hope. However, the past decade has seen remarkable advancements in AI applications across diverse domains, such as medicine Hamet and Tremblay [2017], education Holmes et al. [2023], finance Bahrammirzaee [2010], and engineering Salehi and Burgueño [2018]. We currently find ourselves amidst a phase of palpable optimism, where investment in AI has reached unprecedented levels Mou [2019]. Nonetheless, some skepticism persists, with many anticipating a new wave of disillusionment after encountering some unforeseen barrier. However, widely recognized that AI offers numerous practical applications. Although the full extent of its impact remains uncertain, AI undoubtedly influences and will keep influencing the world in significant ways. At the core of AI lies the pursuit of designing agents that learn how to make informed decisions and self-correct in possibly ever-changing environments without human supervision Russell and Norvig [2010]. Reinforcement Learning (RL) represents a significant stride toward realizing this vision. A RL agent learns from interaction with its surrounding environment in a feedback loop, relying solely on a reward signal to guide its actions. The concept of learning from interaction forms the bedrock of nearly all theories of 2
learning and intelligence Sutton and Barto [2018], with some even conjecturing that rewards alone can pave the path to achieving general AI agents Silver et al. [2021]. However, RL agents face a problem unparalleled in other AI frameworks: acting in unknown environments resorts to discovering the optimal balance between exploration and exploitation, also known as the exploration-exploitation tradeoff Kaelbling et al. [1996]. RL techniques, successful in the past, found their use in low-dimensional problems because of scalability limitations. This restriction meant RL couldn’t address real-world challenges, which often involve complex and high-dimensional domains. Yet, recent advancements in RL, powered by Deep Neural Networks (DNNs) as potent function approximators LeCun et al. [2015], have changed the landscape. These algorithms now match or even exceed the performance levels of human experts in tasks like Chess Silver et al. [2017], Go Silver et al. [2016], video-games Mnih et al. [2015], and communications and networking Luong et al. [2019]. Nevertheless, state-of-the-art algorithms are extremely data-hungry and often not efficiently learnable in the language of statistical learning theory Agarwal et al. [2019]. Given the significant potential impact of RL and AI on the future, a continuous effort exists to improve and refine AI algorithms and systems. This momentum stems from the realization that, despite recent advancements, AI has yet to achieve its full potential. Therefore, besides just enhancing and optimizing existing algorithms, exploring new methods and emerging technologies remains essential. One such technology is quantum computing. Richard Feynman introduced the concept of Quantum Computers Feynman [1982] that operate based on quantum physics principles, leveraging quantum phenomena like superposition and entanglement to manipulate quantum data. Nonetheless, it is also possible to use quantum computers to process classical data as long as it is encoded into a quantum state. Remarkably, quantum computers, in theory, offer a means to efficiently solve some problems that lack efficient classical algorithms. One such example is Shor’s Algorithm for finding the prime factors of an integer, which is exponentially faster than the bestknown classical algorithm and holds the promise of breaking public-key cryptography schemes given a quantum computer with a sufficient number of qubits Shor [1999]. Therefore, one might speculate that quantum computers may outperform classical computers in machine learning tasks, even though the immediate advantages remain somewhat uncertain Biamonte et al. [2017]. Nevertheless, ongoing research actively explores the potential applications of near-term quantum computers in machine learning tasks, primarily focused on seeking advantages in practical, real-world problems. Having listed both the potential of Artificial Intelligence and Quantum Computing, and considering how both technologies can be combined, the importance of exploring their intersection becomes obvious. That is what this dissertation seeks to do. Specifically, the main goal is to research the field of variational 3
quantum circuits and their application to reinforcement learning problems. 1.2 Motivation Quantum computers yield complexity advantages over classical computers in some problems, assuming enough qubits to implement error-correction codes to mitigate noise and errors due to decoherence Preskill [1998]. Nonetheless, in near-term devices or Noisy Intermediate-Scale Quantum (NISQ) devices, the algorithms that yield these advantages can not be implemented successfully to solve real-world problems Preskill [2018]. The challenge thus revolves around devising quantum algorithms that are resource-friendly and resilient to errors to harness near-term quantum computation’s potential. Variational Quantum Circuits (VQCs) are especially suitable for NISQ devices, given their lower demands in the number of qubits and circuit depth, which mitigates the effect of noise Cerezo et al. [2021a]. Consequently, integrating VQCs into machine learning algorithms has become an intriguing field of study. As delineated by Schuld et al. [2021], VQCs can be seen as Partial Fourier Series in the data, where the data encoding gates define the frequency spectrum. The authors also introduce a technique known as Data Re-Uploading, which consists of repeating the data encoding gates several times throughout the circuit, effectively increasing the frequency spectrum accessible to the quantum model. This subsequently broadens the scope of functions the model can approximate, rendering it more expressive. However, such an increase in circuit depth is not without its trade-offs. On the one hand, noise escalation in actual quantum hardware due to circuit depth could nullify the effectiveness of algorithms employing this technique in NISQ devices. On the other hand, the Barren Plateau Phenomenon states that the partial derivatives of a hardware-efficient VQC vanish exponentially with the number of qubits and layers McClean et al. [2018]. Thus, a balance between expressivity and trainability becomes essential. Given that Data Re-Uploading enhances the expressivity of the quantum model through increased circuit depth, it could potentially make the model more challenging to train. Finally, VQCs as function approximators in RL problems have already been researched and proven to work for two different main algorithms: REINFORCE Sequeira et al. [2022], Jerbi et al. [2021] and Q-learning Chen et al. [2020], Lockwood and Si [2020], Skolik et al. [2022]. In all of these articles, VQCs were used as function approximators and managed to solve benchmark environments. However, none of them research the effect of Data Re-Uploading on the trainability of the RL models. Hence, that is the goal of this work. The focus is solely on Q-learning for several reasons. First, Q-Learning stands out in the RL domain because of recent accomplishments in addressing complex problems using this method Mnih et al. 4
[2015]. Furthermore, while the trainability of quantum models based on the REINFORCE algorithm has been researched, such as in Sequeira et al. [2022] and Jerbi et al. [2021], literature on models grounded on Q-learning is nonexistent. This gap underscores the need for the proposed research. 1.3 Contributions The first contribution is the re-utilization of the methodology developed in Skolik et al. [2022] to analyze VQC-based Deep Q-Learning models’ performance in benchmark environments. More specifically, using this methodology, the effect of data re-uploading and trainable input/output scaling on models’ performance in the CartPole-V0 environment is empirically verified, reaffirming the importance of such techniques. Furthermore, a methodology for analysing models’ trainability throughout training in benchmark environments is developed. It consists of observing the gradients’ norm and its variance throughout training of agents initialized from said model in the benchmark environment. It is verified that the gradients’ norm and its variance remain substantial throughout training. Moreover, more expressive models appear to have higher gradients, which is surprising given the expressivity-trainability tradeoff demonstrated in Holmes et al. [2022]. Moreover, the tradeoff between the moving targets inherent to the Deep Q-Learning algorithm and the magnitude of the gradients is empirically studied in the CartPole-V0 environment. The single-qubit Universal Quantum Classifier (UQC) from Pérez-Salinas et al. [2020] is adapted to be used as a function approximator in Deep Q-Learning and its performance and trainability are tested on the CartPole-v0 environment. Then, the multi-qubit version of the architecture is also tested using the same methods. Finally, we developed VQC-based Deep Q-Learning models capable of achieving a considerable performance (according to our methodology) on the more complex Acrobot-v1 environment, a previously untouched environment for such models, to the best of our knowledge. Some of the contributions of this work were accepted as posters at two different prestigious international conferences: • Theory of Quantum Computation, Communication and Cryptography (TQC) - Data Re-Uploading in Quantum Variational Q-Learning, July 2023 • Quantum Techniques in Machine Learning (QTML) - Tradeoff between moving targets, gradient magnitude and performance in quantum variational Q-Learning, November 2023 5
1.4 Outline As previously mentioned, this work’s goal is to research the effect of Data Re-Uploading on the performance and trainability of VQC-based Deep Q-Learning models. To accomplish that goal, this dissertation is organized as follows. Chapter 2introduces Reinforcement Learning (RL), a type of machine learning in which an agent learns to make intelligent decisions by interacting with the surrounding environment in a feedback loop, a process that resembles trial-and-error learning. Moreover, this chapter also introduces the mathematical framework behind RL problems and some common methods for solving such problems. Furthermore, it introduces function approximation as a means to solve more complex RL problems, with a special emphasis on Deep Neural Networks (DNNs) and Deep RL. Finally, this chapter also introduces the Deep Q-Learning algorithm, which is the most important algorithm for this work. Chapter 3explains the basic concepts of the circuit model of quantum computation, before delving into Variational Quantum Circuits (VQCs) and some related concepts, such as the Barren Plateau Phenomenon and the Data Re-Uploading technique, which will be relevant throughout this work. It then introduces VQC- based RL, where VQCs are used as function approximators in Deep RL problems instead of the typical DNNs. Finally, this chapter reviews some recent papers on VQC-based RL, with a special emphasis on VQC-based Deep Q-Learning. Afterward, Chapter 4defines the problem this work attempts to research, using the knowledge acquired in the previous chapters. Then, it introduces the benchmark environments that will be used to test the VQC-based models and the methodologies that will be used throughout this work to analyze the models’ performance and trainability. Chapter 5shows and discusses the empirical results obtained throughout the work. It first starts by analyzing the performance of the models from Skolik et al. [2022] in the CartPole-v0 environment with and without data re-uploading and trainable input/output scaling and discussing the importance of each of these techniques in the models’ performance. Then, the single-qubit and multi-qubit Universal Quantum Classifiers are introduced and their performance is also analyzed in the same environment. Furthermore, the effect of entanglement on performance is discussed. After that, we shift our focus to the trainability of the models. We first start with the models from Skolik et al. [2022] and then repeat the procedure for the Universal Quantum Classifier. Subsequently, we show the effect that the moving targets of Deep Q- Learning have on the trainability of these models. Then, we study how the models’ trainability behaves as the number of qubits increases. Finally, the performance and trainability of these models are analyzed in 6
the Acrobot-v1 environment, a previously untapped environment for VQC-based Deep Q-Learning models. 7
Chapter 2 Reinforcement Learning The main goal of AI involves designing agents that make intelligent decisions without human supervision. Reinforcement Learning (RL) agents achieve this by interacting with their surrounding environment in a feedback loop. This learning method resembles the trial-and-error process seen in humans and other animals, allowing RL agents to address various real-world problems and identify practical solutions. This chapter explains RL based on Sutton and Barto [2018]. 2.1 The Reinforcement Learning Problem Statement Any RL problem has two primary constituents: the Agent and the Environment. The agent is the decisionmaker and the representation of that which learns. The environment is everything that surrounds the agent and is affected by its decisions. The agent must learn which actions to take by interacting with the environment and receiving a reward that indicates the goodness of that particular action concerning the goal. This process is called trial and error search and is one of the defining characteristics of RL. In addition, important to note that actions are taken in a sequence and can have an impact not only on immediate rewards but also on all future rewards. This is commonly referred to as delayed reward . Going into further detail, the agent interacts with the environment by taking actions at each moment t. The environment receives these actions and produces a reward and a new state at the next moment in time t+ 1. The agent then receives the new state and the reward to determine the following action. This iterative process forms what is termed The Agent-Environment Interface Sutton and Barto [2018], illustrated in Figure 1. 8
exhaustive search (making it unfeasible for complex problems with high dimensional state and action spaces) and relies on the agent knowing the dynamics of the environment, a property known as Complete Knowledge , which is an assumption that very rarely holds in real-world problems Sutton and Barto [2018]. This is a good opportunity to introduce the two major types of RL methods: Model-Based and Model- Free Kaelbling et al. [1996]: • In model-based methods, the agent has access to (or learns an approximated version of) the model and can use it to plan. Since the agent knows the dynamics of the environment, it can use that knowledge to simulate the different possible paths and their consequences, before taking an actual action in the real environment. For example, in Chess, because the rules and the structure of the game are known and the transitions are deterministic, the agent can search through the different possible paths and, in a sense, think a couple of steps ahead. Then, using that knowledge, it can choose the path that seems most favorable. An example of this is Silver et al. [2017]. • In model-free methods, the agent doesn’t have access to a model. These methods are simpler and easier to implement, but also usually suffer from a higher sample complexity, since the agent has to deal with the extra burden of not knowing the dynamics of the environment, and thus needs extra interactions to reach a considerable level of performance. Model-free methods are more popular and more researched than model-based methods for a couple of reasons, with the main one being that, most of the time, the real model of the environment is not known. Consequently, model-based algorithms have to learn an approximation of the model, which by itself may be a complicated process, but this also leads to another problem. Since the model the agent is using to plan isn’t a perfect model of the environment, the best performance in the model doesn’t have to translate to the best performance in the actual environment. In other words, the policy of the agent will only be as good as the model it built from the environment. In this work, we will only research a particular model-free method known as Q-Learning Watkins and Dayan [1992]. Nonetheless, before getting into Q-Learning, it is important to explain what Dynamic Programming (DP) is. DP is a collection of model-based algorithms that require access to the dynamics of the environment p(s′, r|s, a)and that use value-functions as guides in the search for optimal policies Sutton and Barto [2018]. These algorithms are of limited utility because they are computationally costly and require a perfect model. However, they are extremely important from a theoretical standpoint and serve as the basis for Q- Learning, as well as many other RL algorithms. In short, they turn the Bellman Equations into assignments (update rules) that, every time they are applied, improve the approximations of the value functions, with convergence guarantees as the number of updates tends to infinity. 15
They work by intertwining two different processes: Policy Evaluation and Policy Improvement . In Policy Evaluation, the goal is to approximate the value function given by the policy π. This is done by sweeping over the entire state space using the Bellman Equation as an update rule. Then, as this process is repeated time and time again, the approximation of the value function becomes better and better. In practice, a stopping criterion has to be used. A common one is to define a small threshold θ > 0and, if the difference between the new values and the previous values is smaller than θ, the process is stopped. In Policy Improvement, a new policy is created, one which is greedy with respect to the original value function. This new policy is guaranteed to always be at least as good as the original policy Sutton and Barto [2018]. The alternation of any variation of these two processes is known as Generalized Policy Iteration (GPI) and, as long as all the states continue to be updated, converges to the optimal value function and the optimal policy. In this section, the Bellman Equations and Dynamic Programming, which offer a means to solve the RL problem, are introduced. In the next section, Q-Learning is explained. 2.4 Q-Learning In model-free RL, the agent does not have access to the environment dynamics. In other words, a model is neither known nor learned. Consequently, agents learn from experience - finite sequences of states, actions, and rewards, in the format {s, a, r, s′}, which are called trajectories Sutton and Barto [2018]. However, learning from experience introduces some new problems. The first problem has to do with the policy. The agent is learning from experience that has to be generated by some policy π. Now, how is this policy chosen? On the one hand, the agent has to explore the state space to find high-value states. On the other hand, the agent has to exploit the acquired knowledge, taking actions that it knows yield high rewards and lead to good states. This problem is known as the exploration-exploitation tradeoff Kaelbling et al. [1996] and has some practical solutions. Maybe the simplest one, which will be used in this work, is an ϵ -greedy policy Sutton and Barto [2018], which chooses a random action with probability ϵand the greedy action with probability 1−ϵ. It is typical to decay ϵ over time. This idea comes from the understanding that, in the beginning, as the agent has very little to no knowledge, exploration is crucial. Then, as the agent learns, exploitation becomes more important. Still, a minimum value for ϵis defined to ensure continuous exploration (a requirement for convergence guarantees) Sutton and Barto [2018]. Nonetheless, the choice of the decaying scheduling of ϵdepends on the environment and must be chosen carefully taking the aforementioned tradeoff into consideration. 16
In addition, model-free RL algorithms can be classified into two types: On-Policy and Off-Policy. Onpolicy algorithms learn a policy πfrom experience generated from the same policy π, while off-policy algorithms learn a policy νfrom experience generated from a different policy π. The latter are noteworthy as they enable agents to learn from humans or other agents and reuse experience generated from previous policies. Notably, Q-Learning is an off-policy algorithm. The second problem has to do with the value function the agent learns. In model-free methods, if one wants to find the optimal policy (or a near-optimal one), the learned value function has to be the action-value function Q(s, a). Learning the state-value function V(s)requires a model of the MDP for greedy policy improvement, as the agent must identify the action leading to the highest valued state. To do so, the agent must know the resulting state and reward for each action. Greedy policy improvement over Q(s, a)is model-free and involves maximizing over actions, as mentioned in the previous section. To estimate the action-value function and determine the optimal policy, two effective methods exist: Monte-Carlo (MC) and Temporal Difference Learning (TD-Learning). Monte-Carlo techniques use averages to approximate expected returns and GPI to derive a policy πthat approximates the optimal policy π∗. Specifically, these techniques use averages of returns for estimating the action-value functions in the Policy Evaluation step and an ϵ-greedy policy in the Policy Improvement step. However, these methods apply only to episodic environments where all trajectories terminate. In this scenario, each trajectory is often called an episode. TD-Learning overcomes some MC limitations, by combining it with DP. Like MC methods, it learns from raw experience but updates estimates with other learning estimates without waiting for an outcome - bootstrapping . For instance, consider a robot that has to guess how many steps it needs to take before reaching a goal using TD-Learning. Let’s say each step yields a −1reward. In its original position, the agent might think that 15 steps are necessary, and thus expects a return of −15 (assuming γ= 1). Then, the agent takes one step and receives a reward of −1. However, now being closer to the goal, the agent notices that it overshot its first prediction and now thinks only 10 steps are necessary to reach the goal. Consequently, the agent updates its estimation of the original state toward the improved estimation of the successor state. That is the idea behind TD-Learning - updating estimates with other estimates. TD-Learning offers lower variance, updates state values at every time step, and functions in non-episodic environments. For a more detailed explanation of MC and TD methods and their differences, refer to Sutton and Barto [2018]. Finally, one has all the information needed to understand Q-Learning. In summary, it is an off-policy algorithm that attempts to approximate the optimal action-value function q∗(s, a)using TD-learning. The pseudo-code for the algorithm follows: 17
Algorithm 1 Q-Learning (Sutton and Barto [2018]) 1: Algorithm parameters: step size α∈(0,1], small ϵ∈[0,1] 2: Initialize Q(s, a),∀s∈ S, a ∈ A(s), arbitrarily, and Q(terminal_state, ·) = 0 3: loop for each episode: 4: Initialize S 5: repeat for each step of the episode: 6: Choose Afrom A(S)using policy derived from Q(e.g., ϵ-greedy) 7: Take action A, observe R,S′ 8: Q(S, A)←Q(S, A) + α[R+γmaxaQ(S′, a)−Q(S, A)] 9: S←S′ 10: until Sis terminal 11: end loop As previously explained, uppercase letters indicate random variables and lowercase letters indicate values these variables can take. Hence, all the variables in the pseudo-code are uppercase letters. As one can see from lines 6 and 7, the experience is generated from a behavior policy, which has to balance the exploration-exploitation tradeoff. As previously mentioned, this work will use an ϵ-greedy policy for simplicity. Then, line 8 establishes the update rule for the Q-Values. Put in words, the Q-values are updated a little (depending on step size α) in the direction of the immediate reward plus the discounted maximum Q-values of the successor states. There is much to unpack there, so let’s start one step at a time. •αis the step size and must be chosen depending on the problem. A larger αleads to more pronounced updates. The larger the α, the more the agent considers recent information and ignores prior knowledge. •R+γmaxaQ(S′, a)is the TD-target and consists of the immediate reward plus the discounted maximum Q-values of the successor states. TD-Learning bootstraps by updating estimates using other estimates. It is also possible to verify why Q-Learning is an off-policy algorithm. Even though the experience is generated from a behavior policy π(e.g. ϵ-greedy), the agent always considers the maximum Q-values of the successor states. In other words, the target policy (the one the agent is learning) is greedy with respect to the Q-values. • The difference δ=R+γmaxaQ(S′, a)−Q(S, A)is called TD-Error and determines the update to be done to the current estimates of the Q-values. It consists of the difference between the TD- 18
target and the current estimates of the Q-values. These estimates are the updated in the direction of the TD-error, scaled by the step-size α. This section introduced methods to determine the (near) optimal policy using value functions as guides, such as Q-Learning. The next section will explain the scalability problem that undermines this algorithm and introduce one of the possible solutions to solve it. 2.5 Deep Reinforcement Learning The previous section outlines tabular approaches Sutton and Barto [2018], which use lookup tables of (at most) dimensions S×Ato assign values to state-action pairs encountered by the agent. However, these methods suffer from the curse of dimensionality , making them inadequate for handling large problems. For instance, the game of Go has 10170 states, making it unfeasible to construct a lookup table with at least 10170 entries and determine values for each entry with current technology. Additionally, some problems have continuous state and/or action spaces. To apply RL to real-world issues, the methods must possess the capability to solve intricate, complex problems. Can model-free methods be expanded to tackle these challenges? The answer to the question is positive. In fact, there are several possible solutions, such as using stateabstraction Andre and Russell [2002] and/or dimensionality reduction techniques Sorzano et al. [2014]. This work focuses on the most popular solution - using Function Approximation . The idea is to generalize from seen states to unseen states by approximating a target function. Consequently, a new function is defined: ˆq(s, a, w)≈qπ(s, a)(2.13) where wis a vector of parameters that must be updated using TD-Learning or MC. It is important to refer that function approximation is only useful if dim(w) |S ×A|, otherwise it would be the same as the tabular regime. There are many function approximators, each with pros and cons, such as linear combinations of features and Kernel-based approximators Busoniu et al. [2017]. Nonetheless, the most used function approximators, not only in RL but in machine learning in general, are Neural Networks (NNs). NNs are popular because they are differentiable, accurately approximate complex functions, have strong generalization capabilities, scale up to handle larger datasets, and benefit from GPU computing and groundbreaking results in practice Morales [2020]. Neural networks (NNs) are made up of neurons that receive inputs, 19
State Output Neural Network Input Layer Hidden Layers Output Layer . . . Activation Function Output Neuron Figure 3: A neural network is composed of neurons, which are grouped into layers. Each neuron receives minputs {x1, ..., xm}, which are multiplied by the mrespective weights {w1, ..., wm}and summed. A bias bis also added. Finally, the result is passed through an activation function φ, which produces the output. each with a weight that is adjusted during training. The neuron multiplies each input by its weight and sums all weighted inputs, adds a trainable weight called the bias, and passes the result through a nonlinear activation function to determine the neuron’s output. These neurons are organized into layers, with the input layer receiving the data, and the output layer yielding the processed result. Any layer in between is called a hidden layer. If a neural network has two or more hidden layers, it is known as a Deep Neural Network (DNN). See Figure 3for a visualization of a NN and a neuron. The more layers, the more complex functions the NN can approximate. To train a neural network (NN), an objective function, commonly known as a loss function, is defined. This function quantifies the discrepancy between the NN’s predicted outputs and the desired outputs. The goal during training is to minimize this error. Typically, the learning algorithm adjusts the network’s weights based on the gradient of this loss function. The gradient, for each weight, indicates how much the error would change if that weight were perturbed by a small amount. The general idea is to adjust the weights in the direction that reduces the error. This concept was extensively discussed by LeCun et al. LeCun et al. [2015]. In practice, an optimization algorithm, often a variant of Stochastic Gradient Descent (SGD), is employed. Instead of calculating the gradient using the entire dataset — which can be computationally intensive — SGD approximates the gradient using a subset of the data. This subset, called a mini-batch, is randomly sampled from the dataset. This approach not only reduces computational requirements but can also introduce beneficial noise, potentially aiding in generalization and avoiding local minima LeCun et al. [2015]. Any RL algorithm that uses DNNs as function approximators is considered Deep Reinforcement Learning (DRL). DRL has been applied to increasingly complex problems, with high-dimensional state-spaces 20
and/or action-spaces, achieving comparable or better performance than humans in a variety of benchmark environments. In 2016, Deepmind’s Alpha-Go, a Go-playing computer program that used DRL and Monte-Carlo Tree Search, defeated the European Go Champion by 5-0 Silver et al. [2016]. This result was a breakthrough for DRL and AI in general since Go was considered the most challenging classic game for artificial intelligence due to its vast search space. In 2017, a subsequent version of Alpha-Go, based solely on RL, without human data, achieved super-human performance, beating the previous Alpha-Go version by 100-0 Silver et al. [2017]. Even outside of the typical benchmark environments of board games and video games, DRL has been applied with great success in real-world problems. Nvidia, a multinational technology company that specializes in designing Graphics Processing Units (GPUs), has recently announced that they have used DRL for designing more efficient arithmetic circuits Roy et al. [2021]. Deepmind has also shown that DRL can be used to assist the operations of nuclear fusion Degrave et al. [2022].In quantum physics, it has been applied to the many-body problem that consists of predicting the properties of systems made of many interacting quantum particles. Since the numerical solution to this problem is intractable for systems of moderate size, different methods that use approximations have been used to solve it. Recently, NNs have been used to approximate the quantum states and DRL techniques have been employed to find the ground-state and describe the unitary time-evolution of complex interacting quantum systems Carleo and Troyer [2017]. DRL has been applied successfully in diverse fields, such as robotics Nguyen and La [2019], finance Hu and Lin [2019], healthcare Yu et al. [2021] and communications/networking Luong et al. [2019]. In this section, the need for function approximators in RL was made clear, considering the scalability limitations of tabular approaches. In particular, DNN and, consequently, DRL were introduced. The following section will explain how DNN can be used in Q-Learning. 2.6 Deep Q-Learning To solve the dimensionality problem, function approximators can be used to approximate the Q-function in Q-Learning Melo and Ribeiro [2007]. In the seminal work Mnih et al. [2015], a DNN is used as the Q- function approximator and the resulting algorithm is named Deep Q-Network (DQN). A comparison between Q-Learning and DQN can be seen in Figure 4. 21
State Action Q-Learning State Deep Q- Learning Figure 4: A comparison between Q-Learning and Deep Q-Learning (DQN). Q-Learning is a tabular approach, where the values of all the visited state-action pairs are stored in a lookup table. DQN, on the other hand, uses a deep neural network as the Q-function approximator. The Figure shows one of the possible architectures for the NN, where the input layer receives the components of the state and the output layer outputs the Q-values for all possible actions. See Morales [2020] for other possible architectures. The pseudo-code for the algorithm follows: Algorithm 2 Deep Q-Learning 1: Algorithm parameters: step size α∈[0,1], small ϵ∈[0,1] 2: Initialize replay buffer Dto capacity N 3: Initialize action-value function Qwith random weights θ 4: Initialize target action-value function ˆ Qwith weights θ−=θ 5: for episode= 1, M do 6: Initialize s1 7: for t= 1, T do 8: Choose atfrom stusing ϵ-greedy policy 9: Take action at, observe rt+1,st+1 10: Store experience (st, at, rt+1, st+1)in replay memory D 11: Sample random mini-batch of transitions (s, a, r, s′)from D 12: Compute the TD-targets using target network (with old, fixed parameters θ−) 13: Perform a gradient descent step on r+γmaxa′Q(s′, a′;θ− i)−Q(s, a;θi)2w.r.t parameters θ 14: Every Csteps reset ˆ Q=Q 15: Initialize st 16: end for 17: end for 22
In the algorithm, several control constants warrant additional explanation. Firstly, the Experience Replay Buffer is initialized with a capacity of N. This capacity determines the maximum number of experiences that the buffer can hold. It is a hyperparameter that requires fine-tuning, since its optimal value varies across different environments. In line 10, for clarity, only the storage of experiences in the replay buffer was described. However, when the replay buffer reaches its capacity, older experiences are discarded to accommodate newer ones. The parameter Mdenotes the number of episodes, Tthe steps per episode, and Cstands for the target network update frequency, which will be further elaborated in the subsequent paragraph. The authors demonstrated that this algorithm achieves super-human performance on a number of arcade games. They also introduce two novel improvements over previous approaches: experience replay and target network . The former consists of using a Replay Buffer , where all experiences - interactions with the environment in the format (st, at, rt+1, st+1)- are stored. Then, batches of these experiences are randomly sampled to compute the parameter updates. This way, temporal correlations between the samples are broken, making the data appear more Independent and Identically Distributed (IID) , which stabilizes training. The Target Network consists of a second NN that is used to compute the TD-targets. The target network has ”frozen” weights that are sporadically (every Csteps) updated with a copy of the parameters of the online network. The idea behind this is to make the targets more stationary, which also stabilizes training. However, there is a tradeoff here between speed of convergence and stability which must be accounted for when choosing C. For a more nuanced discussion on the necessity of these techniques, the reader is referred to the original paper Mnih et al. [2015] and the book Morales [2020]. It is also important to note that there are algorithms that build on DQN, such as the Double DQN Hasselt [2010] (DDQN) and the Dueling DDQN Wang et al. [2016]. Nonetheless, the concept is essentially the same. DQN has been applied successfully to various problems. Starting with the aforementioned research paper that introduced DQN, which created a DQN agent that, receiving only raw visual input, achieved a level of performance comparable to (and sometimes better than) that of a professional human games tester in 49 games from the Atari 2600 games Mnih et al. [2015], which is one of the most exciting results in DRL. It has also been used in stock market forecasting, proving to develop strategies better than a typical benchmark strategy Carta et al. [2021]. Additionally, it has been employed in the path planning of coastal ships, improving the safety, economy, and autonomous decision-making ability of ship navigation Guo et al. [2021]. Nonetheless, there is an important caveat to DQN that must be mentioned - it is highly unstable and 23
has no convergence guarantees Tsitsiklis and Van Roy [1996]. In fact, Sutton and Barto [2018] even go as far as to define what they call the deadly triad - function approximation, bootstrapping, and off-policy data. Every algorithm that uses these three elements, such as DQN, is unstable and likely to diverge. The target network and experience replay techniques were introduced to DQN to ameliorate this problem. 2.7 Policy-Gradient Algorithms and Taxonomy of RL So far, many different RL algorithms have been discussed. The first distinction made was between modelfree and model-based algorithms. Then, some model-free methods that use value functions as guides in the search for the optimal policy were introduced and explained. These methods are usually referred to as Value-Based . However, those are not the only model-free methods for solving RL problems. Some try to learn the policy directly - Policy-Based algorithms. They typically work by parameterizing the policy πθ(a|s), defining an objective function that serves as some performance measure J(πθ)and optimizing the parameters θby performing gradient ascent on an approximation of the gradient ∇J(πθ), which is obtained using Monte-Carlo samples. Consequently, they are commonly referred to as policy gradient methods. Some notable policy-gradient algorithms include REINFORCE Williams [1992], REINFORCE with baseline Sutton and Barto [2018] and Proximal Policy Optimization (PPO) Schulman et al. [2017]. Policy-based methods have their pros and cons when compared with value-based methods. On the one hand, unlike value-based methods, they can learn stochastic policies, which makes them more suitable for problems with incomplete information (POMDPs). Additionally, the action probabilities change smoothly with small changes to the parameters, whereas in value-based methods a small change to the estimated action values may lead to a dramatic change in the action probabilities, meaning that the former have better convergence guarantees Sutton and Barto [2018]. Perhaps the simplest advantage is that, in some scenarios, it may be easier to learn the policy than a value function. On the other hand, since updates are based on Monte-Carlo samples, they suffer from high variance, which may slow down training Greensmith et al. [2004]. The important conclusion from this comparison is that both methods are useful and their applicability vastly depends on the problem itself. Consequently, both are actively researched and equally important. There is also another type of RL algorithm that combines both value-based and policy-based methods, leveraging their strengths while undermining their weaknesses, called actor-critic algorithms Konda and Tsitsiklis [1999]. In these, both the parameterized policy and the value function are learned, where the former can be seen as the actor and the latter the critic. Actor-critic algorithms often yield state-of-the-art performance in many DRL benchmark environments Morales [2020], Mnih et al. [2016]. 24
There are some other important single-qubit gates, such as the Pauli X,Yand Zgates and the Identity gate I: X= 0 1 1 0 Y= 0−i i0 Z= 1 0 0−1 I= 1 0 0 1 (3.12) Even if one is not familiar with quantum computing, some of these gates are pretty intuitive. For example, the identity gate Idoes nothing to a quantum state, such that I|Ψi=|Ψi. The Pauli Xgate is the quantum analog of the classical NOT gate. It turns |0iinto |1iand vice-versa. More importantly, it turns a superposition α|0i+β|1iinto α|1i+β|0i. In other words, it acts linearly . This is a characteristic of quantum computing - quantum gates act on quantum states via linear transformations. The Pauli Zgate, also known as a phase-flip gate, flips the phase of the |1istate but leaves the |0istate unchanged. The Pauli-Ygate transforms |0ito i|1iand |1ito −i|0i. In other words, it applies both Pauli-Xand Pauli-Zoperations simultaneously but with a complex coefficient. From the Pauli matrices, one can also define the RX,RYand RZrotation gates, which perform rotations on a quantum state over the x,yand zaxis of the Bloch Sphere, respectively: RX=e−iθX/2 = cos(θ/2) −isin(θ/2) −isin(θ/2) cos(θ/2) (3.13) RY=e−iθY /2 = cos(θ/2) −sin(θ/2) sin(θ/2) cos(θ/2) (3.14) RZ=e−iθZ/2 = e−iθ/2 0 0eiθ/2 (3.15) An arbitrary single-qubit gate can be decomposed as a product of these rotation gates: U(θ, φ, λ) = RZ(θ)RY(φ)RZ(λ) = cos(θ/2) −eiλ sin(θ/2) eiφ sin(θ/2) eiφ+iλ cos(θ/2) (3.16) Some of the main single-qubit quantum gates were introduced. However, to create entanglement between multiple qubits and extract the full power of quantum computing, multi-qubit gates are needed. The typical multi-qubit quantum gate is the Controlled-NOT or CNOT gate. It is given by the following unitary matrix: CNOT = 1 0 0 0 0 1 0 0 0 0 0 1 0 0 1 0 (3.17) 31
It receives two inputs, a control qubit and a target qubit, and its action is very simple. If the control qubit is set to 1, then a Xgate is applied to the target qubit (in other words, the target qubit is flipped). If the control qubit is set to 0, then nothing changes in the target qubit. Using a CNOT and the arbitrary single-qubit gate defined in equation 3.17, it is possible to implement any arbitrary n-qubit operation Nielsen and Chuang [2010]. Thus, the CNOT, RX,RYand RZgates form a universal set of gates. However, it is possible to build arbitrarily good approximations of any n-qubit operations using fixed values of θ,φand λin the arbitrary single-qubit gate along with the CNOT gate. In other words, it is possible to approximate any single-qubit gate using a finite set of quantum gates, which are also considered universal gate sets. Keeping all of this in mind, quantum computations are done through quantum circuits . These involve a set of qubits, which are acted on by a circuit of quantum gates (which can be conditioned on classical computations) and measured at the output (and possibly at intermediate steps) Nielsen and Chuang [2010]. 3.2.3 Measurements An arbitrary state |Ψi ∈ C2nis represented by: |Ψi= 2n−1 X i=0 ci|Ψii(3.18) where |Ψiiare the basis states and cithe probability amplitudes associated with each of these states. Measuring this state in the computational basis will collapse it into one of the basis states |Ψii with probability |ci|2Nielsen and Chuang [2010]. Furthermore, the expectation value of some observable ˆ Ois given by: Dˆ OE=hΨ|ˆ O|Ψi= 2n−1 X i=0 λipi(3.19) where λiis the eigenvalue associated with the eigenvector of ˆ Oand pi=|ci|2its respective probability. This notion of expectation values will be critical in Variational Quantum Circuits. 3.3 Variational Quantum Circuits As was mentioned in section 3.1, fault-tolerant quantum computers are still not available and may remain that way for years, maybe decades Cerezo et al. [2021a]. Instead, one has to make do with NISQ devices, which have a limited number of qubits and circuit depth due to noise. Consequently, it is crucial to find 32
Data Encoding Ansatz Measurement Cost Function Classical Optimizer Figure 7: The building blocks of a VQC and how it is trained. In a typical VQC, data is encoded, then processed by a parameterized unitary and, finally, the expectation value of some observable is measured. Then, a cost function that depends on the expectation value is calculated and a classical optimizer updates the parameters θ. practical applications for such devices. A promising approach consists of using hybrid classical/quantum algorithms to find approximate solutions to optimization problems Farhi et al. [2014]. Variational Quantum Circuits (VQCs) are quantum circuits that depend on free parameters, which are iteratively updated by a classical optimizer to minimize an objective function estimated from measurements Ostaszewski et al. [2021]. Typically, VQCs can be divided into three main components: Data Encoding , Ansatz , and Measurement and Cost Function , which will be explained in the next three subsections. In Figure 7, one can see the general structure of a VQC. 3.3.1 Data Encoding When dealing with classical data (as will be the case in this work), the data has to be encoded into a quantum state so that it can be processed by a quantum computer. There are several techniques to encode classical data into quantum states Schuld and Petruccione [2021]. However, this work will focus solely on Angle Encoding . Using this technique, each component (also known as feature) of the input data xis encoded by a single qubit using arbitrary Pauli rotations RX, RY, RZ, where the angle is usually the feature itself after some classical pre-processing, e.g. normalization. Thus, given the input data x={x0, x1, ..., xn−1}, the resulting quantum state is given by: |xi= n−1 O i=0 Rα(ϕ(xi)) |0ii(3.20) where Rα∈ {RX, RY, RZ},ϕis some classical pre-processing function and |0iiis the ith qubit 33
initialized in state |0i. This technique has pros and cons. On the one hand, it allows the encoding of a given input vector using circuits of depth 1Sequeira et al. [2022]. On the other hand, the number of qubits grows linearly with the number of features of the input vector, which limits the dimensionality of the inputs one can encode due to the reduced number of qubits in NISQ devices. 3.3.2 Ansatz An architecture (sometimes referred to as ansatz ) needs to be chosen for the VQC. What specific sequence of gates applied to which qubits will be used to solve the task? There are several choices, some of them are problem-inspired , meaning that knowledge about the problem is used to build them. These types of ansatzes are commonly used in quantum chemistry Cao et al. [2019], as well as other tasks where the physics behind the problem might help tailor the ansatz. However, in RL, to the best of our knowledge, there aren’t any problem-inspired anstazes. Thus, a particular subset of problem-agnostic ones are typically used - Hardware-Efficient Ansatzes . These ansatzes allow for implementations with reduced circuit depth by bringing correlated qubits together for depth-reduction Cerezo et al. [2021a]. Furthermore, they usually consist of a layered architecture composed of single-qubit parameterized gates followed by a cascade of entangling gates Sequeira et al. [2022]. Usually, the ansatz U(θ)can be divided into layers , such that: U(θ) = UL(θL)...U2(θ2)U1(θ1)(3.21) An example of a Hardware-Efficient VQC may be seen in Figure 8. ... Layer 1 Layer 2 Layer L Figure 8: Example of a hardware-efficient VQC. |xiis processed by layers of unitaries, each of them composed of parameterized single-qubit gates followed by a cascade of entangling gates. 34
3.3.3 Cost Function To use a VQC to solve a problem, one has to first encode the problem into a cost function, such that solving the problem corresponds to finding the global optima of said function. Let fθ(x)be the expectation value of some observable ˆ Oas follows: fθ(x) = h0|U†(x, θ)ˆ OU(x, θ)|0i(3.22) where U(x, θ)is a quantum circuit that depends on the input xand a set of free parameters θ. In short, it is a VQC. Then, the cost function L(θ)is a function of the expectation value itself. In many scenarios, L(θ) reduces to fθ(x). However, in the context of machine learning, classical post-processing is usually added to the expectation value. For instance, consider the typical supervised learning scenario. Given a labeled dataset D={(xi, yi)}M, the typical cost function is the Mean Squared Error, which can be expressed as follows: L(θ) = 1 M M−1 X i=0 (fθ(xi)−yi)2(3.23) Such a cost function will be important in the context of this dissertation applied to the RL problem, as treated in Subsection 3.5.1. In practice, the value of fθfor a specific input xis given by running the VQC multiple times and averaging over the results. Then, typically, gradient-based methods are used to update the parameters of the VQC. However, gradient-free methods also exist and have their advantages and disadvantages, see Cerezo et al. [2021a]. When using gradient-based methods, as will be the case of this work, the gradient of the cost function with respect to the parameters is calculated using the Parameter-Shift Rules Schuld et al. [2019]. These rules state that the partial derivative of fθ(x)w.r.t a single variational parameter (assuming this parameter is the angle of a Pauli-rotation) is given by: ∂fθ(x) ∂θi =1 2[fθ(x;θi+π/2) −fθ(x;θi−π/2)] (3.24) To compute the partial derivative of the cost function w.r.t a single parameter, two circuit executions are needed. Thus, to compute the gradient of the cost function, which has pparameters, 2×pexecutions are necessary. However, there is one problem that pertains to the gradients of hardware-efficient ansatzes, which will be explained in the following section. 35
3.3.4 Barren Plateau Phenomenon There is a tradeoff one needs to take into account when using hardware-efficient VQCs. Since these ansatzes take no inspiration from the structure of the problem itself, they need to be highly expressive so they can be applied to any generic task Bilkis et al. [2021]. In this context, high expressivity means these quantum circuits are able to nearly cover the full Hilbert space associated with its quantum register space. Let L(θ)be a hardware-efficient VQC cost-function. The gradient of this function is given by: ∇θL(θ) = ∂L ∂θ1 ,∂L ∂θ2 , ..., ∂L ∂θk,θ∈Rk(3.25) where θare the cost function’s parameters and kthe number of parameters. The Barren Plateau Phenomenon asserts that V ar[||∇θL(θ)||]∈ O1 αn, α > 1(3.26) where ||∇θL(θ)||is the gradient’s L2-norm. Put in words, the variance of the gradient of hardware-efficient VQC-based cost functions decays exponentially with system size McClean et al. [2018]. Furthermore, Holmes et al. [2022] demonstrated that the more expressive the ansatz, the lower the variance in the cost gradient. Consequently, the cost landscape is flatter, making these circuits extremely hard to train. Nonetheless, it is important to emphasize that Cerezo et al. [2021b] observed that the Barren Plateau Phenomenon highly depends on the locality of the observable employed. To solve this issue, several strategies have been proposed, such as initialization strategies Grant et al. [2019]. Nonetheless, the problem severely limits the applicability of hybrid classical/quantum algorithms to solve practical problems, warranting further research. 3.4 Data Re-Uploading In the previous section, it was explained that classical data needs to be encoded into a quantum state to be processed by the VQC. Furthermore, from Figure 7, it seems as though this encoding is done just once at the beginning of the circuit to prepare the quantum state. However, that doesn’t need to be the case. Schuld et al. [2021] determined that the data encoding strategy used in the quantum circuit influences the expressive power of the quantum model. Specifically, they show that a VQC may be written as a Partial Fourier Series, where the accessible data frequencies are determined by the eigenvalues of the dataencoding Hamiltonians. Furthermore, quantum models can access increasingly rich frequency spectra by repeating simple data encoding gates multiple times either in series or in parallel, a technique called Data 36
Re-uploading Pérez-Salinas et al. [2020]. To demonstrate this, the authors considered a standard quantum model that consists of multiple layers, each made up of a data encoding block S(x)and a trainable block W(θ)(see Figure 9), and assume that the input data is encoded using angle encoding, such that: U(x, θ) = WL+1(θL+1)S(x)WL(θL)...W 2(θ2)S(x)W1(θ1)(3.27) Where Wi(θi)is the i-th parameterized trainable block, S(x)is a data encoding block that utilizes angle encoding, and Lis the number of layers. . . . ... Figure 9: The Data Re-Uploading technique in action. The same data encoding block S(x)is repeated several times throughout the quantum circuit to increase the expressivity of the quantum model. To exemplify the power of data re-uploading, the authors showed that a quantum model employing a single Pauli-rotation encoding can only learn a sine function. In other words, if the encoding is done just once, the VQC can only approximate functions with a single non-zero frequency in the frequency spectrum. However, repeating Pauli encoding linearly extends the frequency spectrum, such that, if the encoding is repeated ntimes, then the quantum model can approximate functions with up to ndifferent non-zero frequencies. The authors also verified that input scaling , a technique that consists of multiplying each of the input features by a scaling factor, before encoding it as the angle of some Pauli rotation, scales the frequency spectrum itself. Moreover, Pérez-Salinas et al. [2020] proposed making this scaling weight trainable to allow for an ”adaptive frequency matching”. 3.5 VQC-Based Reinforcement Learning VQCs have been extensively researched in supervised Mitarai et al. [2018], Schuld et al. [2020], Schuld and Killoran [2019], Farhi et al. [2014] and unsupervised Coyle et al. [2020], Zoufal et al. [2021] machine learning. However, research on Quantum RL remains scarce, and only recently have variational approaches emerged Chen et al. [2020],Lockwood and Si [2020],Skolik et al. [2022], Jerbi et al. [2021], Sequeira et al. [2022]. All of these references apply VQCs to RL in the same intuitive way. Just like NNs can be used 37
to approximate either a value-function or a parameterized policy, so can VQCs, see Figure 10. The result is a hybrid classical-quantum algorithm that generally works as follows. The agent observes some state st and applies some classical pre-processing ϕ. Then, the result ϕ(s)is encoded into a VQC Uθ(ϕ(s)) using some data encoding technique. The VQC, with the current parameters θt, prepares a quantum state. An observable Oais measured for each possible action. The expectation values of these observables hOais,θ are post-processed and the result represents either the Q-values Qθ(s, a)in value-based methods or the policy πθ(a|s)in policy-based methods. Then, the agent chooses an action atusing these predictions and executes it in the environment. The reward rtand the consecutive state st+1 are observed by the classical optimizer. Using the parameter-shift rule, the gradients of the VQC w.r.t the parameters θtare calculated. Finally, the classical optimizer determines the new parameters θt+1 Meyer et al. [2022]. Agent Environment ActionRewardState Agent Environment ActionRewardState Figure 10: Deep RL versus VQC-based RL. The image on the left represents Deep RL, where Deep Neural Networks are used as function approximators for either value functions or policies. Similarly, the image on the right represents VQC-based RL, where VQCs are used for the same effect. The algorithms themselves are identical, with the exception of the model used as a function approximator. It is important to note that this work will consider only VQCs being used as function approximators in classical environments, even though they can also be used in quantum environments Jerbi et al. [2021]. For a survey that encompasses all of the quantum approaches to RL, the reader is referred to Meyer 38
et al. [2022]. Some of the aforementioned references apply VQCs to the policy-based algorithm named REINFORCE with baseline. These references will be reviewed in subsection 3.5.2. Others apply VQCs to the value-based algorithm Q-Learning (DQN), which will be reviewed in subsection 3.5.1. Even though this work is particularly concerned with Q-Learning, it is important to understand the methodologies used in the policy-based algorithm as well as the results obtained, since some details translate from one algorithm to the other. 3.5.1 VQC-Based Q-Learning To the best of our knowledge, Chen et al. [2020] was the first paper to use VQCs as function approximators in RL algorithms. Specifically, the authors used VQCs to approximate the Q-function in a Deep Q-Learning algorithm. The pseudo-code of the algorithm follows: Algorithm 3 Variational Quantum Deep Q-Learning 1: Algorithm parameters: step size α∈[0,1], small ϵ∈[0,1] 2: Initialize replay buffer Dto capacity N 3: Initialize action-value function Q(quantum circuit) with random parameters θ 4: Initialize target action-value function ˆ Q(target quantum circuit) with parameters θ−=θ 5: for episode= 1, M do 6: Initialize s1and encode into the quantum state 7: for t= 1, T do 8: With probability ϵselect a random action at, otherwise select at=maxaQ∗(st, a;θ)from the output of the quantum circuit 9: Execute action atin emulator and observe rt+1,st+1 10: Store experience (st, at, rt+1, st+1)in replay memory D 11: Sample random mini-batch of transitions (s, a, r, s′)from D 12: Compute the TD-targets using target quantum circuit (with old, fixed parameters θ−) 13: Perform a gradient descent step on r+γmaxa′Q(s′, a′;θ− i)−Q(s, a;θi)2w.r.t parameters θ 14: Every Csteps reset ˆ Q=Q 15: Initialize stand encode into the quantum state 16: end for 17: end for 39
The authors used computational basis encoding Schuld and Petruccione [2021] to encode the states into the VQC. Then, they used an ansatz composed of a ladder of CNOTs that connects the nearest neighbors followed by general-single qubit gates with three parameters per qubit, see Figure 11a. ... (a) ... (b) ... (c) Figure 11: Architectures used in Chen et al. [2020] (Subfigure 11a), Lockwood and Si [2020] (Subfigure 11b) and Skolik et al. [2022] (Subfigure 11c) for n= 4 qubits, Llayers, parameters θand input x= [x0, x1, x2, x3]. The data encoding gates are green-coloured and compose the blocks S(x). The variational gates are blue-coloured and compose the blocks W(θl), where lis the layer, along with the entangling gates. When Data Re-Uploading is used, as in Subfigure 11c, a layer is composed of the data encoding and variational blocks U(x, θl). 40
Deep Q-Learning models. This work aims to directly address these questions. Specifically, we seek to investigate the impact of data re-uploading on both the performance and trainability of VQC-based Deep Q-Learning models. While data re-uploading can enhance model expressivity Schuld et al. [2021], increasing performance in VQC- based RL algorithms, it may also reduce the trainability. If this reduction is considerable, the practical use of data re-uploading becomes questionable. Conversely, if the reduction is minimal, then the increased expressivity more than compensates for it. We plan to empirically study this tradeoff, testing the algorithms in benchmark environments and evaluating both performance and trainability metrics. In the following sections, the implementation of the algorithm, the benchmark environments and the methodologies used during this research will be explained. 4.2 The Algorithm Implementation Choices The first step toward completing the aforementioned goal is to implement VQC-based Deep Q-Learning in a quantum differentiable programming language. The algorithm to be implemented is the one from 3. So, all that’s missing is choosing the programming language. There are several possibilities, the main ones being IBM’s Qiskit Qiskit contributors [2023], Xanadu’s Pennylane Bergholm et al. [2018] and TensorFlow- Quantum Broughton et al. [2020]. All of them have their pros and cons. Qiskit is more general and has direct integration with IBM’s quantum machines. However, it is less abstract than the other languages and suffers from some performance problems, which would rather complicate this task. Pennylane, on the other hand, is designed to integrate seamlessly with machine learning libraries, which would be useful for this work. Nonetheless, the chosen language was tensorflow-quantum for a few reasons. It has integration with TensorFlow, a popular machine learning library, offers high-level abstraction in the design and training of hybrid quantum-classical algorithms and is compatible with high-performance quantum simulators Broughton et al. [2020]. Moreover, being built on TensorFlow, it is highly optimized for machine learning. Finally, Jerbi et al. [2021] and Skolik et al. [2022] implemented their VQC-based algorithms on TensorFlow-Quantum and even created a tutorial, which facilitates the beginning of the implementation. Building upon the insights from the tutorial mentioned earlier, code was written using predominantly Python objects. This design choice promotes high customizability and adaptability, especially in components like the policy, the VQC architecture, the classical pre-processing technique, input scaling, output scaling, and more. A fitting analogy is to compare the code structure to Lego. It is designed in a way that allows for easy swapping of individual ”pieces” or components. In addition to this, the training function is 47
parallelized, enabling simultaneous training of multiple agents. For those keen to delve deeper,the code is available in Coelho [2023]. 4.3 Benchmark Environments This study will focus on numerical analysis of the developed algorithms. In particular, they need to be tested in benchmark environments to analyse and compare them. OpenAI Gym, an open-source Python library, offers a standardized API that bridges learning algorithms with a standard set of environments, providing a platform to analyse and compare RL algorithms. Two specific environments were chosen: CartPole-v0 and Acrobot-V1. The preference for these is twofold: firstly, they are established benchmark environments that have been frequently adopted in academic research for algorithm testing and comparison. Secondly, these environments strike a balance in complexity; they present sufficient challenges to test the robustness of VQC-based algorithms, yet remain tractable for experimental purposes. While CartPole has already been the subject of investigation in several studies, Acrobot presents a heightened degree of complexity and intriguingly, hasn’t yet been solved using VQC-based Q-Learning. 4.3.1 CartPole-v0 RightLeft Figure 12: The CartPole Environment A cart moves on a frictionless track. There is a pendulum placed upright on the cart attached by a joint. The goal is to balance the pole by applying forces in the left and right direction on the cart, see Figure 12. Consequently, the action can take the values {0,1} indicating whether the cart is pushed with a fixed force to the left or right, respectively. The state-space, on the other hand, is composed of 4 features: 48
Feature Range Cart Position [−4.8,4.8] Cart Velocity ]−∞,∞[ Pole Angle [−0.418,0.418] rad Pole Angular Velocity ]−∞,∞[ Table 1: Cartpole’s state space For the starting state, all the features are assigned a value between −0.05 and 0.05. The episode ends if one of three conditions is verified: • The Pole Angle is greater than ±0.214 rad • The Cart Position is greater than ∓2.4 • Episode length is greater than 200 The reward function is very simple: the agent receives a +1 reward per time-step. Consequently, the third condition asserts that the maximum return possible in an episode is 200 if one considers γ= 1. This environment is considered solved if the average return over the previous 100 episodes is greater than 195. 4.3.2 Acrobot-v1 Actuated joint Fixed, nonactuated joint Figure 13: The Acrobot Environment 49
Two links are linearly connected to form a chain, with one end of the chain fixed. The joint between the two links is the one we can act upon and the goal is to apply torques to this joint to swing the free end of the chain above a given height while starting from the initial position of hanging downwards, see Figure 13. There are three possible actions: Action Unit Apply −1torque to the actuated joint Torque (Nm) Apply 0torque to the actuated joint (do nothing) No unit Apply 1torque to the actuated joint Torque (Nm) Table 2: Acrobot’s action-space There are two important angles for the definition of the state-space. First, θ1is the angle of the first joint, where an angle of zero indicates the first link is pointing directly downwards. Moreover, θ2is relative to the angle of the first link, where an angle of zero corresponds to having the same angle between the two links. Then, the state-space can be defined: Action Range Cossine of θ1[−1,1] Sine of θ1[−1,1] Cossine of θ2[−1,1] Sine of θ2[−1,1] Angular Velocity of θ1[−4π, 4π] Angular Velocity of θ2[−9π, 9π] Table 3: Acrobot’s state-space The starting state is defined as follows. Each feature of the state is initialized uniformly between −0.1 and 0.1, such that the links are pointing downwards with some initial stochasticity. The goal is for the free end to reach a given height in as few steps as possible. Consequently, every step that does not reach the goal receives a reward of −1and achieving it results in termination with a reward of 0. Moreover, the maximum number of steps in an episode is 500, after which the episode also terminates. 50
4.4 Methodologies for Analysing Model’s Performance and Trainability As outlined earlier, this study seeks to empirically assess the impact of data re-uploading on the performance and trainability of VQC-based Q-Learning models. To achieve this, we must establish methodologies for analyzing both metrics. The subsequent sections detail these methodologies. 4.4.1 Performance of a Model In any RL problem, the goal is for the agent to find the optimal or a near-optimal policy, which translates to the behaviour that accumulates the most rewards. Consequently, performance is typically measured by the return models achieve in benchmark environments. However, there are several methodologies to measure this performance. We are particularly concerned with keeping the randomness inherent to Deep Q-Learning to a minimum. The algorithm has several stochastic parts. For example, since the initialization of the parameters is random, some agents may be initialized in a good spot in the optimization landscape, such as near a good local minimum, while others may be initialized in poor spots. To evaluate models fairly and make results reproducible, the methodology for testing the performance of a model on a particular environment is the following: Nagents are randomly initialized according to the model. These agents are then trained in the environment over Mepisodes. Should an agent solve the environment before completing the M episodes, its training ceases (i.e., no further updates to the model’s parameters), but the agent continues interacting with the environment using its learned knowledge until all episodes conclude. The returns from each episode are collected for all agents. Ultimately, we average the returns across all Nagents for each episode, compute the standard deviation, and plot the results. An advantage of this methodology is that the randomness inherent to Q-Learning is mitigated by using mean returns of Nagents. However, how is performance compared between different models? Imagine we apply this methodology to two different models in a particular environment. How can we claim one of the models is superior to the other when it comes to performance? Let’s use Figure 14 as an example. Let’s begin by analysing the two models from Figure 14a. In this scenario, it is easy to decide which is the best performing model. The blue model achieved an average return much higher than the red model. In other words, the agents generated from the former were able to derive a policy much better than the agents derived from the latter. Consequently, the blue model is the best performing model out of the two. 51
0 200 400 600 800 1000 Episode 0 25 50 75 100 125 150 175 200 Mean Return Baseline w/o input scaling Data Reuploading (a) 0 50 100 150 200 250 300 Episode 0 25 50 75 100 125 150 175 200 Mean Return Target 1 Target 1000 (b) Figure 14: Both figures represent the performance of two random models on the CartPole-v0 environment. The thick lines are the mean returns for each model (in this case, 5agents were initialized per model) and the shaded areas the standard deviation. This is how the performance of all models will be plotted. Figure 14b represents a different scenario. In this case, both models were able to achieve a similar average return. Nonetheless, the blue model was able to achieve that average return much sooner than the red model. This reveals an advantage in sample complexity, since it requires less samples to learn a good policy. Consequently, the blue model is also the best performing model out of the two in this scenario. However, it is important to note that some cases are not as easy to analyse. For example, some models may achieve a very high return with fewer samples but then keep unlearning, with the average return decreasing as training goes on. Nonetheless, we are not particularly interested in being able to perfectly distinguish the performances of all models. We are simply concerned with being able to gauge considerable differences in performance between models. The standard deviation is particularly interesting for measuring the instability of the models. If it is substantial, then it means different agents initialized from the same model performed very differently on the environment. Some may have achieved high returns during training, while others might have gotten stuck in low returns. Conversely, if it is small, then it means that the agents achieved similar returns throughout training. Consequently, the best model would be one that achieves and maintains the highest possible return in the fewest amount of episodes and exhibits minimal standard deviation. 52
4.4.2 Trainability of a Model There are several methods for analyzing a model’s trainability. For instance, Sequeira et al. [2022] used the empirical Fisher Information matrix Ly et al. [2017]. Another prevalent and straightforward approach is examining the gradient of the cost function, defined in Equation 3.25. In the training of machine learning models, including Neural Networks (NNs) and Variational Quantum Circuits (VQCs), parameters are updated iteratively using variations of Gradient Descent. Essentially, an approximation of the gradient is calculated, and parameters are updated in an inverse proportion, aiming to minimize the cost function. If these partial derivatives are large, the updates to parameters are significant, potentially causing unstable training. Conversely, if these derivatives are small, then the parameter updates are also small, which leads to the opposite problem, in which the model gets stuck on the optimization landscape. While both extremes are problematical, we are particularly concerned with the latter. Let L(θ) be a hardware-efficient VQC-based cost function as defined in Subsection 3.3.3. The Barren Plateau Phenomenon, detailed in Subsection 3.3.4, asserts that V ar[||∇θL(θ)||]∈ O1 αn, α > 1(4.1) where ||∇θL(θ)||is the gradient norm. As a result, we will analyse the gradients of the cost function for each model to draw conclusions about their trainability using the following methodology: When using the methodology for measuring model’s performance described in the previous section, we also store the gradient of the cost function with respect to the parameters at each training step, which is every step where the parameters are updated. Subsequently, we compute the norm of these gradients for every training step. To mitigate the effects of stochasticity, we calculate the average norm of the gradients across the Nagents and the variance of these norms at each training step. However, since agents cease training once the environment is solved, different agents have a different number of training steps. As a result, we limited our procedure to only encompass the steps up until the first agent successfully solved the environment. To facilitate the visualization of the results, a rolling average of the last 100 training steps is used for both the norm of the gradients and the variance of the norms. 4.5 Summary In this chapter, we started by defining the precise issue addressed in this research. The primary focus is centered on investigating the performance and trainability of VQC-based Deep Q-Learning models, with 53
a special emphasis on understanding the potential implications of data re-uploading on those metrics. Furthermore, we explained the reasoning behind the selection of Tensorflow-Quantum as the preferred language for implementing the VQC-based Deep Q-Learning models. Subsequently, we introduced the benchmark environments chosen for testing the models and outlined the methodologies that will be employed to analyse their performance and trainability. 54
Chapter 5 Results and Discussion The previous section explained the benchmark environments that will be used to test the Deep Q-Learning models throughout this work. Moreover, the methodologies for analyzing a model’s performance and trainability were explained. In this chapter, we aim to test different VQC-based Deep Q-Learning models on the aforementioned environments and analyze their performance and trainability. 5.1 Replication of Skolik et al. [2022]’s results Having implemented the algorithm in TensorFlow-Quantum, it was imperative to test it. Since this work is going to build upon the paper by Skolik et al. [2022], it is only natural that the first step should be to replicate their methods and compare the results. If the algorithm is well implemented, then the results should be equivalent. Skolik et al. [2022]’s VQC solved the CartPole environment using a VQC-based algorithm with the defining characteristics (see Figure 15): •Classical Pre-Processing and Data Encoding method - To allow for the encoding of continuous features, each feature was passed through an arctan function which normalized it to the interval [−π/2, π/2]. Then, a Pauli-X rotation with the result as the angle was used to encode the data into the VQC. The authors named this technique Continuous Encoding . Consequently, each feature siof the input state vector swas encoded as RX(arctan(si)). Since CartPole state-space has four features which have to be encoded by different qubits, the VQC has four qubits. •Trainable Input Scaling - When applicable, each feature siof the state-space sis multiplied by a classical trainable weight Pérez-Salinas et al. [2020], such that the encoding is given by RX(arctan(si×λi)), where λiis the input scaling weight. •Ansatz - The ansatz is a hardware efficient one, composed of two parametrized rotations over the y 55
and zaxis per qubit, followed by a cascade of CZ gates in a circular setup (all nearest-neighbours are connected and then the last qubit is connected to the first one). •Data Re-Uploading - When applicable, to increase the expressivity of the quantum model, the data encoding block is repeated several times throughout the circuit. Specifically, it is repeated once every layer, such that the VQC is expressed as: U(s, λ,θ) = WL+1(θL+1)S(s, λL)WL(θL)...W 2(θ2)S(s, λ1)W1(θ1)(5.1) where sis the input state, S(s, λi)is the data encoding block, Wi(θi)is the i-th parametrized trainable block and Lthe number of layers. •Measurement and Trainable Output Scaling - The expectation value of one observable has to be measured for each possible action. Since CartPole’s action-space has two possible actions, two observables need to be measured. In particular, Skolik et al. [2022] used hZ0Z1ifor the ”left” action and hZ2Z3ifor the ”right” action, where Zis the Pauli-Z observable and the numbers 0to 3 indicate the qubit in which the observable is measured. Moreover, output scaling is used, meaning each of the two expectation values is multiplied by a classical trainable weight to allow for arbitrary Q-values, as explained in section 3.5. Consequently, the two Q-values are given by: Q(s, left) = 0⊗nU† θ(s)Z0Z1Uθ(s)0⊗n×w0(5.2) Q(s, right) = 0⊗nU† θ(s)Z2Z3Uθ(s)0⊗n×w1(5.3) •Parameters Initialization - The rotational parameters are randomly initialized by sampling from a uniform distribution between 0and π. Moreover, the input and output scaling weights are initialized as 1s. •Cost Function - The Mean Squared Error (MSE) cost function is used, according to algorithm 3. Skolik et al. [2022] tested the effect of data re-uploading and trainable input scaling in the performance of the agents in the CartPole environment. In particular, they verified that agents which used just one of the techniques couldn’t solve the environment in up to 5000 episodes. However, when both techniques were used together, the models were able to solve the environment using a set of optimal hyperparameters and sub-optimal hyperparameters (as defined by the authors after a search over some of the hyperparemeters). According to the authors, this result demonstrates the importance of both these techniques in increasing the expressivity of the VQC, as described in Schuld et al. [2021]. However, we are also concerned with the 56
then it doesn’t showcase any quantum advantage. After all, we can replicate its behaviour with classical means. However, this observation carries a caveat: the CartPole environment is very simple. More intricate environments, specially those inspired by complex physical phenomena, might demand quantum resources such as entanglement to generate good policies. 5.2.2 The Multi-qubit Universal Quantum Classifier It is possible to generalize from the single-qubit UQC to a multi-qubit UQC. The main reason for doing so is that the UQC allows for the choice of an arbitrary number of qubits. Thus, it would be interesting to study if increasing the number of qubits also leads to an increase in performance. That is the goal of this section. Nonetheless, a data encoding technique has to be defined. We experiment with two different types of encoding: •Full Encoding: Using full encoding, the whole input vector is encoded into all the qubits. For instance, consider the CartPole environment which has four features per state s = [s1, s2, s3, s4] and a full encoding multi-qubit UQC with five qubits. Then, the whole state vector s would be encoded into the five different qubits. Consequently, the number of parameters grows linearly with the number of qubits. •Partial Encoding: In this data encoding technique, we divide the number of the input vector features by the number of qubits used and encode a different subvector in each qubit. Let’s consider the CartPole environment once again. Then, if a partial encoding multi-qubit UQC with two qubits is used, the first two features are encoded into the first qubit and the last two into the second qubit. A limitation of this method is that the number of qubits has to be smaller than or equal to the number of features of the input vector. The reason for using these two types of encoding is two-fold. On the one hand, these two techniques allow us to study the impact of introducing entanglement on the performance of the models in the CartPolev0 environment. We will see how throughout this section. On the other hand, the Full Encoding technique allows us to encode a given input vector in an arbitrary number of qubits that may even be greater than the number of features of the input vector. Thus, we may study how the performance and trainability behave as the number of qubits increases, see Section 5.6. We also modified the observables used in the model. In the single-qubit version of the UQC, the expectation values of the Z and X observables were measured on the same qubit, serving as Q-values that 63
encode the two potential actions in the CartPole environment (after being multiplied by a classical trainable weight - output scaling). However, in the multi-qubit UQC, the necessity to measure the observables on the same qubit across different circuit executions is eliminated. Consequently, in the two-qubit UQC, we designate the expectation value of the Pauli-Z observable on the first qubit, denoted as hZ0i, to represent the ”left” action, and hZ1ithe ”right” action, where 0and 1are the indices of the two qubits. Extending this approach to the four-qubit UQC, we employ hZ0Z1ias the observable indicating the ”left” action, and hZ2Z3ifor the ”right” action, a strategy in line with the methodology outlined in the work of Skolik et al. [2022]. In the previous section, we observed that the single-qubit UQC, which is a product state, is capable of solving the CartPole-v0 environment. Expanding on those results, we would like to see if multi-qubit UQCs, without entanglement, are also capable of solving the environment. Thus, we first start by testing how the two-qubit UQC and the four-qubit UQC perform without entanglement with the two different data encoding techniques, see Figure 18. 0 200 400 600 800 1000 Episode 0 25 50 75 100 125 150 175 200 Mean Return Two-qubit UQC (Full Encoding) Two-qubit UQC (Partial Encoding) (a) 0 200 400 600 800 1000 Episode 0 25 50 75 100 125 150 175 200 Mean Return Four-qubit UQC (Full Encoding) Four-qubit UQC (Partial Encoding) (b) Figure 18: Performance analysis of the two-qubit (see Subfigure 18a) and four-qubit (see Subfigure 18b) UQCs using the Partial and Full encoding techniques without entanglement. 10 agents were initialized from each model. The full set of hyperparameters can be seen in Table 8. Analyzing Figure 18, it is clear that the different encoding techniques have a significant impact on the performance of the model when entanglement is not used. This result has a simple but interesting explanation. Let’s consider the two-qubit UQC. When Partial Encoding is used, see the orange line of Subfigure 18a, the first two features of the CartPole’s state-space are encoded into the first qubit, and the last two are encoded into the second qubit (remembering that CartPole’s state-space has four features). Moreover, the expectation value of the Z observable is measured on the first qubit as the Q-value for the ”left” action and the expectation value of 64
the Zobservable is measured on the second qubit as the Q-value for the ”right” action. Thus, it is clear to see why this model is not capable of generating optimal or near-optimal policies. The Q-values for each of the two actions are approximated using just a subset of the features of the state-space. For instance, the Q-values for the ”left” action are being approximated using only the cart’s position and the cart’s velocity, without any information about the pole angle and the pole angular velocity, see Table 1. Thus, the models are capable of learning a little bit and achieving an average return of 30 but are not capable of learning near-optimal policies, since some information is missing. Nonetheless, it is important to note that these models could still be able to achieve near-optimal performance in an environment where certain features are not as relevant as others. That does not seem to be the case with CartPole-v0. On the other hand, when Full Encoding is used, models without entanglement are capable of solving the environment, similar to what was observed for the single-qubit UQC. This result is expected, since each qubit, which is a universal function approximant, has full information about the CartPole’s statespace, thus being capable of approximating with good precision the optimal Q-value of the corresponding action. Consequently, the models, which are composed of two of these qubits each approximating the Q-value of one of the actions with good precision, generate a good approximation of the optimal Q-function and, hence, near-optimal policies. Surprisingly though, this model is the most stable of all the models tested so far, with small deviations from the maximum average return of 200 achieved around episode 200. Analyzing Subfigure 18b, the results seem to be similar for the four-qubit models. The Partial Encoding model is not capable of learning near-optimal policies, since the Q-values for the two actions are approximated using partial information about the state-space. When Full Encoding is used, the model achieves the highest possible average return, although this model appears to have a worse performance than the Full Encoding two-qubit UQC since it takes more episodes to achieve the same average return and also suffers from a higher standard deviation. Thus, interestingly, it appears that increasing the number of qubits and, consequently, the number of parameters, does not necessarily lead to an increase in performance. To see if the performance changes when entanglement is used, we added a circular layer of CZ gates after every processing layer and tested the models in the CartPole-v0 environment, see Figure 19. For a comprehensive analysis, we have also included comparisons with the multi-qubit UQC models without entanglement. 65
0 200 400 600 800 1000 Episode 0 25 50 75 100 125 150 175 200 Mean Return Two-qubit UQC (Full Encoding) without entanglement Two-qubit UQC (Partial Encoding) without entanglement Two-qubit UQC (Full Encoding) with entanglement Two-qubit UQC (Partial Encoding) with entanglement (a) 0 200 400 600 800 1000 Episode 0 25 50 75 100 125 150 175 200 Mean Return Four-qubit UQC (Full Encoding) without entanglement Four-qubit UQC (Partial Encoding) without entanglement Four-qubit UQC (Full Encoding) with entanglement Four-qubit UQC (Partial Encoding) with entanglement (b) Figure 19: Performance analysis of the two-qubit (see Subfigure 18a) and four-qubit (see Subfigure 18b) UQCs using the Partial and Full encoding techniques with and without entanglement. 10 agents were initialized from each model. The full set of hyperparameters can be seen in Table 8. The first notable observation from Figure 19 is that the models that use the Partial Encoding technique and entanglement can generate near-optimal policies, unlike the models that do not use entanglement. Although interesting, it is not surprising. Even though each qubit only encodes a subset of the features of the state-space, entanglement introduces strong correlations between the qubits, such that the output state depends on all the features. Thus, the Q-values for each action are approximated using all the available information about the state-space. In fact, this is similar to what the models from Skolik et al. [2022] do. They encode each feature into a different qubit and then use entanglement to correlate all of the subsystems. Another interesting observation is that, for the Full Encoding models, it seems that introducing entanglement does not lead to a considerable increase in performance. In fact, for the two-qubit UQC, see Subfigure 19a, introducing entanglement decreased the model’s performance. For the four-qubit UQC, see Subfigure 19b, it is not so clear which model performs the best at the end of the training, but the model without entanglement learns much faster than the model with entanglement. Finally, having tested all of the different models, Figure 20 compares the performance of the bestperforming models obtained in the CartPole-v0 environment. Consequently, we included the Skolik Data Re-Uploading Model, the Single-Qubit UQC, and the Multi-Qubit UQC without entanglement. 66
0 200 400 600 800 1000 Episode 0 25 50 75 100 125 150 175 200 Mean Return Skolik Data Re-Uploading Single-qubit UQC Two-qubit UQC (Full Encoding) without entanglement Figure 20: Performance Analysis of the best-performing models in the CartPole-v0 environment. In concrete, the Skolik Data Re-Uploading model, the Single-Qubit UQC and the Full Encoding Multi-Qubit UQC without entanglement. 10 agents were initialized from each model. Interestingly, Figure 20 shows that the best-performing model is the Full Encoding Two-Qubit UQC without entanglement. Thus, it seems that increasing the number of qubits of the UQC from one to two increased the average return obtained in the environment and improved the model’s stability, as one can see by the small deviations from the average return. However, increasing it beyond two qubits negatively impacted the performance of the models. Moreover, out of the three different models, the Skolik Data Re-Uploading appears to be the worstperforming model both in terms of the average return obtained as well as in stability. 5.3 Trainability Analysis of Skolik et al. [2022]’s models In the previous sections, we analyzed the performance of the models from Skolik et al. [2022] and the single/multi-qubit UQC. Nonetheless, our goal is to study the trainability of these models by observing the norm and the variance of the gradients throughout training. That will be done from this section onwards. We start by applying the procedure described in 4.4.2 to the four models from Figure 16 which used output scaling (the red, green, blue and black lines), since the others achieved a level of performance so poor that further study is not relevant. The results can be seen in Figure 21. From Figure 21, it is clear that both the norm of the gradients and the variance of the norm appear to be closely tied to the model’s performance in the environment. The model with the poorest performance among the four (as shown in Figure 16) also exhibits the lowest average gradient norm and variance of that norm, and vice versa. Moreover, the difference in the gradients’ norm and its variance is substantial 67
between the different models, but particularly between the data re-uploading model with input scaling and all the other models. 0 10000 20000 30000 40000 Training Step 0 200 400 600 800 1000 Mean Norm of Vector Gradient Baseline Data Reuploading Baseline w/o Input Scaling DataReuploading w/o Input Scaling (a) 0 10000 20000 30000 40000 Training Step 0.00 0.25 0.50 0.75 1.00 1.25 1.50 1.75 2.00 Variance of the Norm of the Vector Gradient 1e6 Baseline Data Reuploading Baseline w/o Input Scaling DataReuploading w/o Input Scaling (b) Figure 21: Comparison of the gradients of the baseline and data re-uploading models with and without trainable input scaling in the CartPole environment. Subfigure 21a shows the mean norm of the vector gradient throughout training and Subfigure 21b the variace in the norms of the vector gradients throughout training. The optimal set of hyperparameters from Skolik et al. [2022] is used, see Table 6. Moreover, 10 agents are initialized from each model. If an agent solves the environment, training is stopped. These metrics are stopped after the first agent solves the environment, hence why some curves are shorter than others. The data re-uploading model with input scaling, depicted as the top-performing model in Figure 16, is noteworthy in several ways. Despite its greater circuit depth and enhanced expressivity, it exhibits the highest variance in the gradient norm among all models. This promising finding is in stark contrast to our initial expectations derived from Holmes et al. [2022], which suggests a trade-off between expressivity and trainability. In particular, Barren Plateaus are to be expected when using hardware-efficient ansatzes with high expressivities. However, in this case, the most expressive model is also the one with the highest gradients’ magnitude and variance. In fact, at a certain point during training, this model achieved a gradient norm of 1000 and a variance in this norm of 2,000,000! This result is the exact opposite of the Barren Plateau Phenomenon. The norm of the gradients and its variance are so high that parameter updates should be very large and lead to unstable training. Nonetheless, this model achieves the best performance. It is crucial, however, to set these observations in their proper context: they are specific to RL and the CartPole-v0 environment, and any broader generalizations would be premature. Still, these results warrant further investigation. Finally, examining Figure 21 also reveals intriguing patterns in the training process. The norm of the 68
gradients and its variance display similar trajectories: both increase in the early stages of training, achieve a maximum value, and then start to decrease as training progresses. However, from Figures 16 and 21, determining the exact performance at which the model’s gradients begin to decrease is challenging due to their distinct x-axes. While Figure 16 uses episodes for the x-axis, Figure 21 employs training steps. Thus, there isn’t a direct correlation, as each episode can entail an arbitrary number of steps. To address this, we opted to analyze three randomly-selected agents from the Data Re-uploading and Baseline models, plotting both performance and gradient norm against training steps. This choice, over averaging returns and gradients across all 10 agents, offers a clearer visual representation of the potential performance disparities between agents within the same model, highlighting the inherent instability of the algorithm. Furthermore, the three agents displayed for each model represent the ten agents well, as similar results are observed across all of them. These results are illustrated in Figure 22. Training Steps 25 50 75 100 125 150 Return Training Steps 50 100 150 200 Return Training Steps 50 100 150 200 Return 0 20000 40000 60000 Training Steps 0 50 100 150 200 Norm of the Gradient 0 5000 10000 15000 20000 25000 30000 Training Steps 0 50 100 150 200 Norm of the Gradient 0 5000 10000 15000 20000 25000 30000 Training Steps 0 50 100 150 200 Norm of the Gradient (a) Training Steps 50 100 150 200 Return Training Steps 50 100 150 200 Return Training Steps 50 100 150 200 Return 0 10000 20000 30000 40000 50000 Training Steps 0 250 500 750 1000 1250 1500 Norm of the Gradient 0 50000 100000 150000 Training Steps 0 200 400 600 800 Norm of the Gradient 0 10000 20000 30000 40000 50000 Training Steps 0 250 500 750 1000 1250 1500 Norm of the Gradient (b) Figure 22: Return and Norm of the gradients for 3random Baseline (see Subfigure 22a) and Data Re- Uploading (see Subfigure 22b) agents. Both the return an the norm of the agents are presented as moving averages to mitigate noise due to the unstable nature of DQN. 69
In Subfigure 22b, representing the three data re-uploading agents, there is a common trend: as the return increases, so does the norm of the gradients. Upon reaching a stabilization point between 150 and 200 of return, the gradient norm peaks before gradually descending to a lower value. Two of the baseline agents follow a similar pattern. However, one agent peaks at return 150, concurrent with the gradient norm’s maximum, after which both metrics decline. Section 5.5 delves deeper into the potential reasons behind this behavior. 5.4 Trainability Analysis of the UQC After analyzing the trainability of the models used by Skolik et al. [2022], we applied the same methodology to study the trainability of the single-qubit and multi-qubit UQCs. Figure 23 shows the trainability analysis of the single-qubit model, using the Skolik Data Re-Uploading model for reference (the analysis of the performance of these two models was done in Figure 17 and the color scheme is the same). 0 5000 10000 15000 20000 25000 30000 35000 Training Step 0 1000 2000 3000 4000 5000 6000 Mean Norm of the Gradient Skolik Data Re-Uploading Single-Qubit UQC (a) 0 5000 10000 15000 20000 25000 30000 35000 Training Step 0 1 2 3 4 5 6 7 Variance of the norm of the Gradient 1e7 Skolik Data Re-Uploading Single-Qubit UQC (b) Figure 23: Trainability analysis of the single-qubit UQC and Skolik data re-uploading models in the CartPolev0 environment from Figure 17 following the methodology defined in Section 4.4.2. Subfigure 23a shows the mean norm of the vector gradient throughout training and Subfigure 23b the variance in the norms of the vector gradients throughout training. 10 agents were initialized from each model. The gradient norms and their variance were already notably large for the data re-uploading model. Yet, they’re even more pronounced for the single-qubit UQC. This reaffirms the idea that Deep Q-Learning’s inherent instability can result in models with significant gradient magnitudes, yet these models can still excel in the given environment. Notably, the magnitude of the gradients and its variance seem to be influenced by the choice of model. The reason why the single-qubit UQC shows much larger gradient magnitudes than the Data Re-uploading model is still a topic for further investigation. 70
Now, let’s study the trainability of the multi-qubit UQC models. Figures 24a and 24b show the trainability analysis of the two-qubit UQC and the four-qubit UQC with and without entanglement in the CartPole-v0 environment. Once again, the same set of hyperparameters is used and all quantum circuits have 5layers. 0 5000 10000 15000 20000 25000 30000 35000 Training Step 0 1000 2000 3000 4000 5000 6000 Mean Norm of Vector Gradient Two qubit UQC (Full Encoding) without entanglement Two qubit UQC (Partial Encoding) without entanglement Two qubit UQC (Full Encoding) with entanglement Two qubit UQC (Partial Encoding) with entanglement One qubit UQC 0 5000 10000 15000 20000 25000 30000 35000 Training Step 0 1 2 3 4 5 6 7 Variance of the orm of Vector Gradient 1e7 Two qubit UQC (Full Encoding) without entanglement Two qubit UQC (Partial Encoding) without entanglement Two qubit UQC (Full Encoding) with entanglement Two qubit UQC (Partial Encoding) with entanglement One qubit UQC (a) 0 5000 10000 15000 20000 25000 30000 35000 Training Step 0 2000 4000 6000 8000 Mean Norm of Vector Gradient Four qubit UQC (Full Encoding) without entanglement Four qubit UQC (Partial Encoding) without entanglement Four qubit UQC (Full Encoding) with entanglement Four qubit UQC (Partial Encoding) with entanglement One qubit UQC 0 5000 10000 15000 20000 25000 30000 35000 Training Step 0.0 0.2 0.4 0.6 0.8 1.0 Variance of the orm of Vector Gradient 1e8 Four qubit UQC (Full Encoding) without entanglement Four qubit UQC (Partial Encoding) without entanglement Four qubit UQC (Full Encoding) with entanglement Four qubit UQC (Partial Encoding) with entanglement One qubit UQC (b) Figure 24: Trainability analysis of the two-qubit (see Subfigure 24a) and four-qubit (see Subfigure 24b) UQCs using the Partial and Full encoding techniques with and without entanglement. 10 agents were initialized from each model. The full set of hyperparameters can be seen in Table 8. The trainability analysis reveals insights into the behavior of the gradients as we increase the number of qubits in the UQC and also the effect that entanglement has on this behavior. The first observation is that the Partial Encoding models without entanglement have a much lower gradient norm and variance, which is to be expected since these models perform poorly (see Figure 19) and we have already seen that performance and gradient magnitude are deeply correlated. Moreover, interestingly, the Full Encoding models without entanglement achieve a higher gradient norm and variance than the models with entanglement. In fact, these models have the highest gradient norms and variances out of all the tested models. One possible explanation for this result is that the models with entanglement have a worse performance than the models without entanglement (see Figure 71
19) which, according to the connection between performance and gradients, might lead to this decrease in the gradients’ norm and variance. Finally, the decrease in the variance does not seem to be exponential as the number of qubits increases. In fact, the four-qubit UQC without entanglement has the highest variance out of all the tested models. These observations reinforce the possibility of using the inherent instability of Deep Q-Learning to mitigate the Barren Plateau Phenomenon. The following section explains some of the main causes behind this instability. 5.5 Tradeoff between Moving Targets and Gradient Magnitude As we have seen in the previous section, the magnitude of the gradients and their variance throughout training behave differently from expected. Concretely, they continuously increase as the agent learns, reach substantial values when the agent achieves the maximum return, and then start decreasing until the end of training. Moreover, the performance of the agents and their gradients seem to be deeply correlated, which might be useful for VQC-based Deep Q-Learning. If the more expressive models, which typically perform better on the environment since they can better approximate the optimal Q-function, also have higher gradients due to this observed behavior, then the Barren Plateau Phenomenon might be mitigated. However, this is only a possibility for now, since the results pertain only to the CartPole environment, specific models, and the MSE cost function. Consequently, further research is required. In this section, we attempt to comprehend the reasons behind this behavior. Let’s start by looking at the mean loss function across the 10 different agents initialized from the Data Re-Uploading model (the blue lines from Figures 16b,21a and 21b), see Figure 25. Immediately after the start of training, the loss increases in a manner that is similar to the norm and variance of the norm of the gradients. It reaches a maximum when the agent achieves the highest return, then decreases throughout the rest of training. This loss curve reveals why the behavior of the gradients is different from the expected. The gradient is a vector containing the partial derivatives of the loss function w.r.t all the parameters. If the loss function increases sharply at the beginning of training, the partial derivatives should also increase, leading to a higher norm of the gradients. But why does the loss function behave in such a way? 72
functions that use half the qubits. However, the locality of the observables used influences the norm and the variance of the gradients Cerezo et al. [2021b], such that different cost functions that consider other observables should be tested. Moreover, how these gradients change as the depth of the circuit increases should also be researched. Unfortunately, due to a lack of time and computational resources, we could not afford to do such a study. Thus, these results should serve as the basis for more nuanced studies. 5.7 The Acrobot Environment In previous sections, we focused our discussion on the CartPole-v0 environment. However, as highlighted in section 4.3, the CartPole is relatively simple. The Acrobot-v1 environment, on the other hand, presents a more complex scenario. In fact, to the best of our knowledge, no VQC-based Deep Q-Learning model has yet been tested in this environment. Moreover, we have noted substantial gradient magnitudes and variances in the CartPole environment. We are keen to investigate whether similar behavior can be observed in the Acrobot environment. Consequently, in this section, we will delve into the performance and trainability of VQC-based Deep Q-Learning models in the Acrobot environment. We plan to test two models that have achieved some of the best performances so far: the Skolik Data Re-Uploading model with four qubits and the Full Encoding Multi- Qubit UQC with three qubits and entanglement. In fact, the multi-qubit UQC models without entanglement performed better than the models with entanglement, but due to the computational demands of the Acrobot environment, we decided to test just the model with entanglement. Nevertheless, it is necessary to make a few adjustments before proceeding with these tests: •Hyperparameter Search - In our previous experiments, we utilized a consistent set of hyperparameters across all models to facilitate fair comparisons and isolate the influence of hyperparameter variations. However, given the shift to a different and more complex environment, it became necessary to conduct a hyperparameter search to optimize the learning potential of the models. We used optuna Akiba et al. [2019] to perform a smart search method that usually reduces the number of combinations tested before finding a near-optimal set of hyperparameters when compared with a grid-search method. Details of the final hyperparameter set can be found in Table 10. One particularly important hyperparameter is the target network update frequency, which we set to C= 250. •Classical Pre-Processing - The state-space of the Acrobot environment encompasses six features: [cos(θ1),sin(θ1),cos(θ2),sin(θ2), ω(θ1), ω(θ2)] where ωis the angular velocity, as detailed in section 4.3.2. We reduced the dimensionality of the state-space to include only [θ1, θ2, 79
ω(θ1), ω(θ2)], and normalized all features to fall within the range of [−2π, 2π]. •Observables - In the Acrobot environment, the set of actions is given by A={−1,0,1}, with each of the actions corresponding to applying the respective torque to the actuated joint. This requires the measurement of three different observables to accurately represent these actions. The observables used for the two tested models are seen in Table 4. Expectation Values Action Skolik Data Re-Uploading 3-Qubit UQC −1hZ0i hZ0i 0hZ1Z2i hZ1i 1hZ3i hZ2i Table 4: Chosen observables for the two models tested in the Acrobot-v1 environment. There is also a significant difference that must be mentioned. In the CartPole environment, if an agent gets a return greater or equal to 195 over the past 100 episodes, the environment is considered solved and training is halted. However, the Acrobot environment has no such condition, so the goal is to obtain the maximum return possible in a finite number of episodes. The results of the performance and trainability analysis of these models with a varying number of layers can be seen in Figure 29 Let’s start by analysing the performance of the models. It is important to note that fairly good performing NN-based Deep Q-Learning agents on the Acrobot environment typically achieve an average return close to or less than −100 OpenAI [2023]. From Figure 29a, one can observe that the Skolik Data Re- Uploading model is able to perform considerably well in this environment. Nonetheless, there is a clear improvement in the performance when the number of layers is increased from five to ten. From Figure 29b, one can see that the three-qubit UQC is also capable of achieving a high average return. However, increasing the number of layers of this model doesn’t seem to considerably impact performance. Moreover, the UQC appears to achieve the mark of −100 average return sooner than the Skolik Data Re-uploading models. Once again, we emphasize that, to the best of our knowledge, this is the first implementation of VQC-based Deep Q-Learning models in the Acrobot environment. 80
0 100 200 300 400 500 Episode 500 400 300 200 100 Mean Return Skolik (5 Layers) Skolik (10 Layers) Skolik (15 Layers) 0 5000 10000 15000 20000 Training Step 0 20 40 60 80 100 Mean Gradient Norm Skolik (5 Layers) Skolik (10 Layers) Skolik (15 Layers) 0 5000 10000 15000 20000 Training Step 0 1000 2000 3000 4000 5000 Variance of the Gradient Norms Skolik (5 Layers) Skolik (10 Layers) Skolik (15 Layers) (a) Performance and trainability analysis of the Skolik Data Re-Uploading model on the Acrobot environment. 0 100 200 300 400 500 Episode 500 400 300 200 100 Mean Return uqc3qubits (5 Layers) uqc3qubits (10 Layers) uqc3qubits (15 Layers) 0 5000 10000 15000 20000 Training Step 0 100 200 300 400 Mean Gradient Norm uqc3qubits (5 Layers) uqc3qubits (10 Layers) uqc3qubits (15 Layers) 0 5000 10000 15000 20000 Training Step 0 20000 40000 60000 80000 Variance of the Gradient Norms uqc3qubits (5 Layers) uqc3qubits (10 Layers) uqc3qubits (15 Layers) (b) Performance and trainability analysis of the three- Qubit UQC model on the Acrobot environment. Figure 29: Performance and Trainability analysis of the Skolik Data Re-Uploading and three-qubit UQC models on the Acrobot environment. 10 agents were initialized from each model. The full set of hyperparameters can be seen in Table 10. Next, we proceed to analyze the trainability of the models, focusing particularly on the gradient behavior observed during the training process. We verify a similar gradient behavior to the observed in the Cartpole environment, where both the norm of the gradients and its variance escalate to substantial values. However, unlike what was verified in the CartPole environment, the gradients don’t peak and then decrease sustainably throughout training. Instead, they continuously increase (with the exception of the variance of the gradient norm of the three-qubit UQC). These results suggest that the observed behavior might not be intrinsically linked to the characteristics of the environment, but possibly influenced by 81
another variable or parameter. Based on the analysis conducted thus far, it is reasonable to assume that the two most important factors for this gradient behavior are the target network update frequency and the cost function, as seen in section 5.5. The former due to the tradeoff between moving targets and gradient magnitude. The latter because the MSE cost function squares the (already large due to the moving targets) TD-errors, exacerbating the gradients. Although replicating all experiments conducted in the CartPole environment would be interesting, the associated computational expenses are prohibitively high. Nonetheless, we were still able to create VQC- based models capable of achieving a considerable performance in the previously untapped Acrobot-V1 environment and seeing a substantial gradients’ norm and variance, which hints at the possibility that the results obtained in the Acrobot environment would be similar to those obtained in the CartPole environment. Thus, further research is needed to confirm or deny these claims. 5.8 Summary In this chapter, we examined the performance and trainability of various VQC-based models within the CartPole-v0 and Acrobot-v1 environments. Initially, we replicated the study conducted by Skolik et al. [2022] in the CartPole environment, reaffirming the significance of data re-uploading as well as trainable input and output scaling in enhancing the models’ performance. After that, we used the single-qubit UQC as a function approximator in VQC-based Deep Q-Learning which, to the best of our knowledge, had never been done. Moreover, the multi-qubit UQC was also introduced and tested in the CartPole environment. Subsequently, we analyzed the trainability of these models and found that the gradient norms and variances reached significant values, especially in highly expressive models that use data re-uploading. This result is in stark contrast with what is expected since models with an increased circuit depth and expressivity should lead to smaller gradients Holmes et al. [2022]. Afterward, we empirically verified that the gradients’ behavior is affected by a characteristic inherent to Deep Q-Learning - moving targets. This instability is further exacerbated by the mean squared error loss function. These results suggest that this inherent instability to Deep Q-Learning might counterbalance the effects of the Barren Plateau Phenomenon. If confirmed, this would be a promising result for VQC- Based Deep Q-Learning, since highly expressive VQCs could be used as function approximators without the negative effects of the vanishing gradients. However, it is important to note that these findings are confined 82
to the models explored within the CartPole environment and the mean squared error loss function. Afterward, we verified that increasing the number of qubits does not seem to considerably affect the gradients’ magnitudes nor their variance in the CartPole environment. Finally, we used VQC-based Deep Q-Learning models to achieve a considerable performance in the slightly more complex Acrobot-v1 environment which, to the best of our knowledge, has not been previously done. It was also verified that the gradients’ magnitudes and their variance remain significant even in this more complex environment. 83
Chapter 6 Conclusions and future work 6.1 Conclusions This work researched the intersection between Quantum Computing and Deep Reinforcement Learning. More concretely, the main goal was to study the effects of data re-uploading on the performance and trainability of VQC-based Deep Q-Learning models. It was already empirically shown by Skolik et al. [2022] that using data re-uploading increases the performance of these models in the CartPole environment, possibly due to its increased expressivity, which allows the approximation of more intricate functions Schuld et al. [2021]. Throughout this work, we implemented and tested different data re-uploading models on the CartPole environment and the results match those by Skolik et al. [2022] and Schuld et al. [2021]. Moreover, we adapted the Universal Quantum Classifier (UQC) Pérez-Salinas et al. [2020], which also uses data re-uploading, to be used as a function approximator in this setting and achieved the best performance of all VQC models tested thus far on the CartPole environment. Furthermore, we tested different data reuploading models on the more complex Acrobot-v1 environment and achieved a considerable level of performance. To the best of our knowledge, this was the first implementation of a VQC-based Deep Q- Learning model in the Acrobot environment. From these results, we conclude that data re-uploading indeed increases the performance of the Deep Q-Learning models. However, a concern would be that the increase in expressivity and circuit depth that arises from the use of data re-uploading could decrease the trainability of these models due to the Barren Plateau Phenomenon McClean et al. [2018]. To investigate such a concern, we analyzed the norm of the gradients and the variance of this norm. From this analysis, we verified that the gradients achieve substantial values and actually increase when data re-uploading is used versus when it is not used. Furthermore, we empirically showed that this increase is due to an instability that is inherent to Deep Q-Learning, which is the fact that the targets are non-stationary. Alongside the Mean Squared Error loss function, this leads to a very unstable algorithm with substantial gradients. Moreover, we also verified that increasing the number of 84
qubits of the multi-qubit UQC in the CartPole environment does not lead to a decrease in the gradients’ magnitude or variance. Nonetheless, it is important to note that these results pertain only to the CartPole and Acrobot environments, specific data re-uploading models and sets of hyperparameters, and the mean squared error loss function. Thus, while promising, it is still too preliminary to generalize. 6.2 Prospect for future work For future work, it would be very interesting to develop a different methodology to analyze the trainability of VQC-based models. The magnitude and variance of the gradients already give some insights into the trainability of a model, but a more complex and intricate methodology that could add more information to this analysis would be interesting. For instance, it may be possible to study the eigenvalues of the Hessian Matrix. Another interesting possibility would be to analyze these models from a Fourier Analysis perspective. Schuld et al. [2021] show that VQCs may be seen as Partial Fourier Series in the data and that using data re-uploading increases the frequencies the VQC ”has access to”. Thus, it may be possible to analyze the optimal Q-functions of certain environments and the Fourier Series that the VQCs are approximating. This might reveal some insights into what is happening behind the scenes. Finally, while the results of this work hint at the possibility of the inherent instability of Deep Q-Learning counteracting the effects of the Barren Plateau Phenomenon, they are still insufficient for making such a claim. However, if this were true, then VQCs would be especially adequate for being used as function approximators in such a setting. Thus, it would be interesting to build upon this work and analyze the trainability of VQC-based Deep Q-Learning models on different, more complex environments, with different loss functions and sets of hyperparameters. It might even be possible to theoretically derive bounds for the gradients of these models, which could reinforce the empirical analysis. 85
Bibliography Alekh Agarwal, Nan Jiang, Sham M Kakade, and Wen Sun. Reinforcement learning: Theory and algorithms. CS Dept., UW Seattle, Seattle, WA, USA, Tech. Rep , pages 10–4, 2019. Takuya Akiba, Shotaro Sano, Toshihiko Yanase, Takeru Ohta, and Masanori Koyama. Optuna: A nextgeneration hyperparameter optimization framework. In Proceedings of the 25th ACM SIGKDD International Conference on Knowledge Discovery and Data Mining , 2019. David Andre and Stuart J Russell. State abstraction for programmable reinforcement learning agents. In Aaai/iaai , pages 119–125, 2002. Frank Arute, Kunal Arya, Ryan Babbush, Dave Bacon, Joseph C Bardin, Rami Barends, Rupak Biswas, Sergio Boixo, Fernando GSL Brandao, David A Buell, et al. Quantum supremacy using a programmable superconducting processor. Nature , 574(7779):505–510, 2019. Arash Bahrammirzaee. A comparative survey of artificial intelligence applications in finance: artificial neural networks, expert system and hybrid intelligent systems. Neural Computing and Applications , 19 (8):1165–1195, 2010. Ville Bergholm, Josh Izaac, Maria Schuld, Christian Gogolin, Shahnawaz Ahmed, Vishnu Ajith, M Sohaib Alam, Guillermo Alonso-Linaje, B AkashNarayanan, Ali Asadi, et al. Pennylane: Automatic differentiation of hybrid quantum-classical computations. arXiv preprint arXiv:1811.04968 , 2018. Jacob Biamonte, Peter Wittek, Nicola Pancotti, Patrick Rebentrost, Nathan Wiebe, and Seth Lloyd. Quantum machine learning. Nature , 549(7671):195–202, 2017. M Bilkis, María Cerezo, Guillaume Verdon, Patrick J Coles, and Lukasz Cincio. A semi-agnostic ansatz with variable structure for quantum machine learning. arXiv preprint arXiv:2103.06712 , 2021. Michael Broughton, Guillaume Verdon, Trevor McCourt, Antonio J Martinez, Jae Hyeon Yoo, Sergei V Isakov, Philip Massey, Ramin Halavati, Murphy Yuezhen Niu, Alexander Zlokapa, et al. Tensorflow quantum: A software framework for quantum machine learning. arXiv preprint arXiv:2003.02989 , 2020. 86
Lucian Busoniu, Robert Babuska, Bart De Schutter, and Damien Ernst. Reinforcement learning and dynamic programming using function approximators . CRC press, 2017. Yudong Cao, Jonathan Romero, Jonathan P Olson, Matthias Degroote, Peter D Johnson, Mária Kieferová, Ian D Kivlichan, Tim Menke, Borja Peropadre, Nicolas PD Sawaya, et al. Quantum chemistry in the age of quantum computing. Chemical reviews , 119(19):10856–10915, 2019. Giuseppe Carleo and Matthias Troyer. Solving the quantum many-body problem with artificial neural networks. Science , 355(6325):602–606, 2017. Salvatore Carta, Anselmo Ferreira, Alessandro Sebastian Podda, Diego Reforgiato Recupero, and Antonio Sanna. Multi-dqn: An ensemble of deep q-learning agents for stock market forecasting. Expert systems with applications , 164:113820, 2021. Marco Cerezo, Andrew Arrasmith, Ryan Babbush, Simon C Benjamin, Suguru Endo, Keisuke Fujii, Jarrod R McClean, Kosuke Mitarai, Xiao Yuan, Lukasz Cincio, et al. Variational quantum algorithms. Nature Reviews Physics , 3(9):625–644, 2021a. Marco Cerezo, Akira Sone, Tyler Volkoff, Lukasz Cincio, and Patrick J Coles. Cost function dependent barren plateaus in shallow parametrized quantum circuits. Nature communications , 12(1):1791, 2021b. Samuel Yen-Chi Chen, Chao-Han Huck Yang, Jun Qi, Pin-Yu Chen, Xiaoli Ma, and Hsi-Sheng Goan. Variational quantum circuits for deep reinforcement learning. IEEE Access , 8:141007–141024, 2020. Rodrigo Coelho. Vqc_qlearning: A github repository. https://github.com/RodrigoCoelho7/ VQC_Qlearning, 2023. GitHub repository. Iris Cong, Soonwon Choi, and Mikhail D Lukin. Quantum convolutional neural networks. Nature Physics , 15(12):1273–1278, 2019. Brian Coyle, Daniel Mills, Vincent Danos, and Elham Kashefi. The born supremacy: quantum advantage and training of an ising born machine. npj Quantum Information , 6(1):60, 2020. Jonas Degrave, Federico Felici, Jonas Buchli, Michael Neunert, Brendan Tracey, Francesco Carpanese, Timo Ewalds, Roland Hafner, Abbas Abdolmaleki, Diego de Las Casas, et al. Magnetic control of tokamak plasmas through deep reinforcement learning. Nature , 602(7897):414–419, 2022. 87
David Deutsch. Quantum theory, the church–turing principle and the universal quantum computer. Proceedings of the Royal Society of London. A. Mathematical and Physical Sciences , 400(1818):97–117, 1985. Edward Farhi, Jeffrey Goldstone, and Sam Gutmann. A quantum approximate optimization algorithm. arXiv preprint arXiv:1411.4028 , 2014. Richard P Feynman. Simulating physics with computers. International Journal of Theoretical Physics , 21 (6/7), 1982. Edward Grant, Leonard Wossnig, Mateusz Ostaszewski, and Marcello Benedetti. An initialization strategy for addressing barren plateaus in parametrized quantum circuits. Quantum , 3:214, 2019. Evan Greensmith, Peter L Bartlett, and Jonathan Baxter. Variance reduction techniques for gradient estimates in reinforcement learning. Journal of Machine Learning Research , 5(9), 2004. Siyu Guo, Xiuguo Zhang, Yiquan Du, Yisong Zheng, and Zhiying Cao. Path planning of coastal ships based on optimized dqn reward function. Journal of Marine Science and Engineering , 9(2):210, 2021. Pavel Hamet and Johanne Tremblay. Artificial intelligence in medicine. Metabolism , 69:S36–S40, 2017. Serge Haroche and Jean-Michel Raimond. Quantum computing: dream or nightmare? Physics Today , 49 (8):51–52, 1996. Hado Hasselt. Double q-learning. Advances in neural information processing systems , 23, 2010. Wayne Holmes, Maya Bialik, and Charles Fadel. Artificial intelligence in education. Globethics Publications, 2023. Zoë Holmes, Kunal Sharma, Marco Cerezo, and Patrick J Coles. Connecting ansatz expressibility to gradient magnitudes and barren plateaus. PRX Quantum , 3(1):010313, 2022. Kurt Hornik. Approximation capabilities of multilayer feedforward networks. Neural networks , 4(2):251– 257, 1991. Yuh-Jong Hu and Shang-Jen Lin. Deep reinforcement learning for optimizing finance portfolio management. In 2019 amity international conference on artificial intelligence (AICAI) , pages 14–20. IEEE, 2019. Peter J Huber. Robust estimation of a location parameter. The Annals of Mathematical Statistics , pages 73–101, 1964. 88
CartPole-v0 qubits 4 layers 5 γ0.99 trainable input scaling yes, no trainable output scaling yes, no learning rate of parameters θ0.001 learning rate of input scaling parameters 0.001 learning rate of output scaling parameters 0.1 batch size 16 decaying schedule of ϵ-greedy policy Exponential ϵinit 1 ϵdec 0.99 ϵmin 0.01 update model 1 update target model 1 size of replay buffer 10000 data re-uploading yes, no Table 6: Models’ hyperpameters from Figure 16 The set of hyperparameters used for the single-qubit UQC in Figure 17 can be seen in table 7. CartPole-v0 qubits 1 layers 5 γ0.99 trainable input scaling yes trainable output scaling yes learning rate of parameters θ0.001 learning rate of input scaling parameters 0.001 learning rate of output scaling parameters 0.1 batch size 16 decaying schedule of ϵ-greedy policy Exponential ϵinit 1 ϵdec 0.99 ϵmin 0.01 update model 1 update target model 1 size of replay buffer 10000 data re-uploading yes Table 7: Models’ hyperpameters from Figure 17 The set of hyperparameters used for the multi-qubit UQCs in Figures 19 and 28 can be seen in table 7. 95
CartPole-v0 qubits 2,4,6,8,10,12 layers 5 γ0.99 trainable input scaling yes trainable output scaling yes learning rate of parameters θ0.001 learning rate of input scaling parameters 0.001 learning rate of output scaling parameters 0.1 batch size 16 decaying schedule of ϵ-greedy policy Exponential ϵinit 1 ϵdec 0.99 ϵmin 0.01 update model 1 update target model 1 size of replay buffer 10000 data re-uploading yes Table 8: Models’ hyperpameters from Figures 19 and 28. The set of hyperparameters used for the models of Figure 26 can be seen in table 9. CartPole-v0 qubits 4 layers 5 γ0.99 trainable input scaling yes trainable output scaling yes learning rate of parameters θ0.001 learning rate of input scaling parameters 0.001 learning rate of output scaling parameters 0.1 batch size 16 decaying schedule of ϵ-greedy policy Exponential ϵinit 1 ϵdec 0.99 ϵmin 0.01 update model 1 update target model 1,10,100,500,1000,2500 size of replay buffer 10000 data re-uploading yes Table 9: Models’ hyperpameters from Figure 26 The set of hyperparameters used for the multi-qubit UQC and Skolik Data Re-uploading models in Figure 29 can be seen in table 10. 96
Skolik Data-Reup Acrobot-v1 Multiqubit UQC Acrobot-V1 qubits 4 3 layers 5,10,15 5,10,15 γ0.99 0.99 trainable input scaling yes yes trainable output scaling yes yes learning rate of parameters θ0.001 0.001 learning rate of input scaling parameters 0.001 0.001 learning rate of output scaling parameters 0.1 0.1 batch size 32 32 decaying schedule of ϵ-greedy policy Exponential Exponential ϵinit 1 1 ϵdec 0.99 0.99 ϵmin 0.01 0.01 update model 5 5 update target model 250 250 size of replay buffer 50000 50000 data re-uploading yes yes Table 10: Models’ hyperpameters from Figure 29.