summaries: The paper addresses multi-goal reinforcement learning. It presents empirical results with a variation of an existing algorithm, Hindsight Experience Replay (HER). Specifically, the paper uses HER alongside AlphaZero.  This paper presents AlphaZeroHER, an extension of the AlphaZero learning-informed Monte Carlo Tree Search algorithm in which the ideas of Hindsight Experience Replay (HER) are applied to augment training and therefore better support goal-directed planning tasks. Consistent with the general HER procedure, the approach generates new data under the assumption that the goal was one of a set of sampled "subgoals", requiring that that the reward and target policy be recomputed. The target policy is chosen to be the empirical policy achieved during the episode, for though it is not optimal for the new goal, it did indeed reach the subgoal. The authors demonstrate performance on a handful of goal-directed planning tasks—including BitFlip, navigation, and a quantum compiling task—on which they show improved performance over AlphaZero without the addition of HER.  The authors discuss the impact of Monte Carlo Tree Search (MCTS) algorithms.  MCTS allows us to roll out trajectories using state value estimates to determine local actions, however computational cost can be high. This means that the approach is prohibitive for large problem spaces.  RL seeks to learn a control policy that generalizes well over the state space. This can be challenging and MCTS algorithms can help with this.  In goal reaching problems the agent takes as input the current state of the env as well as the goals state.  The only trajectories that confer positive reward are those where the goal is reached. RL can struggle here as the rewards are sparse due to the success criteria.  More informative reward functions can be used (e.g. distance to goal) but this isn't always possible.  Hindsight Experience Replay (HER) is applied to offline RL algorithms to improve sample efficiency where a replay buffer is maintained over retained trajectories and a set of sub-goals are defined over visited states with returns applied accordingly.  The authors propose to apply HER to AlphaZero to solve goal directed tasks and thereby avoid computationally intense tasks. They evaluate the approach against a set of simulated environments and compare to AlphaZero, including a novel Quantum compiling environment.  Much of the challenge in solving games like Go and Chess comes down to the size of the state space.  AlphaZeroHER works by sampling new sub-goals from already visited states and thus avoiding both the high computational cost involved in tree re-weighting and also the problem of sparse rewards.   This is done by retracing episodes and sample M subgoals from a trajectory of length T and training the policy and value networks on these hindsight inferred goals.  Since AlphaZero is on on-policy the policies used during play are retained when computing updates from the sub-goal rollouts which alleviates the computational burden.  The authors show that AlphaZeroHER outperforms AlphaZero over a number of simulated environments where the latter often fails to achieve learning much while the former achieves strong results.    For the AlphaZero approach, the rewards of goal-directed planning environments are too sparse to learn efficiently. To solve this problem, the authors proposed the AlphaZeroHER method by combining AlphaZero with Hindsight Experience Replay(HER) to enable AlphaZero agents to learn in goal-directed environments. The experiments showed that AlphaZeroHER is better than AlphaZero on BitFlip, 2D Navigation Task, 2D Maze and Quantum Compiler environments. 
abstractText: We consider the problem of goal-directed planning under a deterministic transition model. Monte Carlo Tree Search has shown remarkable performance in solving deterministic control problems. By using function approximators to bias the search of the tree, MCTS has been extended to complex continuous domains, resulting in the AlphaZero family of algorithms. Nonetheless, these algorithms still struggle with control problems with sparse rewards such as goal-directed domains, where a positive reward is awarded only when reaching a goal state. In this work, we extend AlphaZero with Hindsight Experience Replay to tackle complex goal-directed planning tasks. We demonstrate the effectiveness of the proposed approach through an extensive empirical evaluation in several simulated domains, including a novel application to a quantum compiling domain.
references.authors: Marcin Andrychowicz Filip Wolski Alex Ray Jonas Schneider Rachel Fong Peter Welinder Bob McGrew Josh Tobin OpenAI Pieter Abbeel Wojciech Zaremba
references.title: Hindsight experience replay
references.venue: Advances in Neural Information Processing Systems,
references.authors: Peter Auer Nicolò Cesa-Bianchi Paul Fischer
references.title: Finite-time analysis of the multiarmed bandit problem
references.venue: Mach. Learn.,
references.authors: C.B. Browne E. Powley D. Whitehouse S.M. Lucas P.I. Cowling P. Rohlfshagen S. Tavener D. Perez S. Samothrakis S. Colton
references.title: A survey of monte carlo tree search methods
references.venue: IEEE Transactions on Computational Intelligence and AI in Games,
references.authors: Rich Caruana
references.title: Multitask learning
references.venue: Mach. Learn.,
references.authors: Shantanu Debnath Norbert M Linke Caroline Figgatt Kevin A Landsman Kevin Wright Christopher Monroe
references.title: Demonstration of a small programmable quantum computer with atomic qubits
references.authors: Vikas Dhiman Shurjo Banerjee Jeffrey Mark Siskind Jason J. Corso
references.title: Floyd-warshall reinforcement learning learning from past experiences to reach new goals
references.venue: CoRR, abs/1809.09318,
references.authors: M. Enzenberger M. Müller B. Arneson R. Segal
references.title: Fuego—an open-source framework for board games and go engine based on monte carlo tree search
references.venue: IEEE Transactions on Computational Intelligence and AI in Games,
references.authors: Chelsea Finn Pieter Abbeel Sergey Levine
references.title: Model-agnostic meta-learning for fast adaptation of deep networks
references.venue: Proceedings of the 34th International Conference on Machine Learning,
references.authors: Chelsea Finn Kelvin Xu Sergey Levine
references.title: Probabilistic model-agnostic meta-learning
references.venue: CoRR, abs/1806.02817,
references.authors: Ronan Fruit Matteo Pirotta Alessandro Lazaric Emma Brunskill
references.title: Regret minimization in mdps with options without prior knowledge
references.venue: Advances in Neural Information Processing Systems,
references.authors: Dibya Ghosh Abhishek Gupta Sergey Levine
references.title: Learning actionable representations with goal-conditioned policies
references.venue: CoRR, abs/1811.07819,
references.authors: Marek Grzes Daniel Kudenko
references.title: Theoretical and empirical analysis of reward shaping in reinforcement learning
references.venue: In 2009 International Conference on Machine Learning and Applications,
references.authors: Nozomu Ikehata Takeshi Ito
references.title: Monte-carlo tree search in ms. pac-man
references.venue: IEEE Conference on Computational Intelligence and Games (CIG’11),
references.authors: Tom Jurgenson Or Avner Edward Groshev Aviv Tamar
references.title: Sub-goal trees - a framework for goal-based reinforcement learning
references.venue: CoRR, abs/2002.12361,
references.authors: Levente Kocsis Csaba Szepesvári
references.title: Bandit based monte-carlo planning
references.venue: In In: ECML-06. Number 4212 in LNCS,
references.authors: D Leibfried E Knill Christian Ospelkaus David J Wineland
references.title: Transport quantum logic gates for trapped ions
references.venue: Physical Review A,
references.authors: Norbert M Linke Dmitri Maslov Martin Roetteler Shantanu Debnath Caroline Figgatt Kevin A Landsman Kenneth Wright Christopher Monroe
references.title: Experimental comparison of two quantum computing architectures
references.venue: Proceedings of the National Academy of Sciences,
references.authors: Dmitri Maslov
references.title: Basic circuit compilation techniques for an ion-trap quantum machine
references.venue: New Journal of Physics,
references.authors: Stephen McAleer Forest Agostinelli Alexander Shmakov Pierre Baldi
references.title: Solving the rubik’s cube with approximate policy iteration
references.venue: In International Conference on Learning Representations,
references.authors: Lorenzo Moro Matteo G.A. Paris Marcello Restelli Enrico Prati
references.title: Quantum compiling by deep reinforcement learning
references.venue: Communications Physics,
references.authors: Soroush Nasiriany Vitchyr Pong Steven Lin Sergey Levine
references.title: Planning with goalconditioned policies
references.venue: Advances in Neural Information Processing Systems,
references.authors: Michael A Nielsen
references.title: A simple formula for the average gate fidelity of a quantum dynamical operation
references.venue: Physics Letters A,
references.authors: Michael A Nielsen Isaac Chuang
references.title: Quantum computation and quantum information
references.authors: Giambattista Parascandolo Lars Buesing Josh Merel Leonard Hasenclever John Aslanides Jessica B. Hamrick Nicolas Heess Alexander Neitz Theophane Weber
references.title: Divide-andconquer monte carlo tree search for goal-directed planning
references.venue: CoRR, abs/2004.11410,
references.authors: Lerrel Pinto Abhinav Gupta
references.title: Learning to push by grasping: Using multiple tasks for effective learning
references.venue: CoRR, abs/1609.09025,
references.authors: Christopher D. Rosin
references.title: Multi-armed bandits with episode context
references.venue: Annals of Mathematics and Artificial Intelligence,
references.authors: Nicholas J Russell Levon Chakhmakhchyan Jeremy L O’Brien Anthony Laing
references.title: Direct dialling of haar random unitary matrices
references.venue: New Journal of Physics,
references.authors: Tom Schaul Daniel Horgan Karol Gregor David Silver
references.title: Universal value function approximators
references.venue: Proceedings of the 32nd International Conference on Machine Learning,
references.authors: Jurgen Schmidhuber
references.title: Evolutionary principles in self-referential learning. on learning now to learn: The meta-meta-meta...-hook
references.venue: Diploma thesis, Technische Universitat Munchen, Germany,
references.authors: Jürgen Schmidhuber
references.title: Optimal ordered problem solver
references.venue: CoRR, cs.AI/0207097,
references.authors: Jürgen Schmidhuber
references.title: Gödel Machines: Fully Self-referential Optimal Universal Self-improvers, pages 199–226
references.venue: doi: 10.1007/978-3-540-68677-4_7
references.authors: David Silver Thomas Hubert Julian Schrittwieser Ioannis Antonoglou Matthew Lai Arthur Guez Marc Lanctot Laurent Sifre Dharshan Kumaran Thore Graepel Timothy P. Lillicrap Karen Simonyan Demis Hassabis
references.title: Mastering chess and shogi by self-play with a general reinforcement learning
references.authors: David Silver Julian Schrittwieser Karen Simonyan Ioannis Antonoglou Aja Huang Arthur Guez Thomas Hubert Lucas Baker Matthew Lai Adrian Bolton Yutian Chen Timothy Lillicrap Fan Hui Laurent Sifre George van den Driessche Thore Graepel Demis Hassabis
references.title: Mastering the game of go without human knowledge
references.venue: doi: 10.1038/nature24270. URL https://doi.org/10.1038/
references.authors: Richard S Sutton Andrew G Barto
references.title: Reinforcement learning: An introduction
references.venue: MIT press,
references.authors: Emanuel Todorov Tom Erez Yuval Tassa
references.title: Mujoco: A physics engine for model-based control
references.venue: In 2012 IEEE/RSJ International Conference on Intelligent Robots and Systems,
sections.heading: 1 Introduction
sections.text: Monte Carlo Tree Search (MCTS) (Browne et al., 2012) algorithms have shown outstanding results in solving sequential decision-making problems, especially in deterministic transition tasks, such as games. MCTS planners use a forward environment model to build a search tree, estimate the value of each action in the current state, and execute the best-estimated one, respectively. Such a procedure allows finding a “local” solution to the decision problem in every decision step by sampling trajectories of possible future policies using the forward model. Although providing local solutions is advantageous in some contexts, it comes at a high computational cost since acting in the environment requires interleaved planning phases and possibly large search trees. These high computational costs have been a barrier in applying MCTS to larger problems, especially those with long planning horizons and huge tree branching factors (number of actions). However, MCTS does not require a training phase and can be deployed immediately.
  Reinforcement Learning (RL) (Sutton et al., 1998), on the other hand, aims to find a global solution to the control problem by learning a policy that performs adequately in the whole state space. While this may seem a more desirable outcome, it can often be hard to produce a policy that generalizes satisfactorily across different state regions. For this reason, MCTS algorithms have achieved tremendous success in a wide range of tasks (Borsboom et al.; Enzenberger et al., 2010; Ikehata and Ito, 2011). The AlphaZero (Silver et al., 2016) family of algorithms made it possible to use sequential planners like MCTS in more challenging environments, such as the game of Go, where the AlphaGo agent defeated the world champion, achieving super-human performance. AlphaGo was in turn defeated by the AlphaZero, a version of the algorithm without any heuristic related to the game of Go. AlphaZero combines MCTS with the ability of RL algorithms to generalize across the state-action space by keeping a parametrized policy and value network. Specifically, the policy network biases the exploration during the tree search, and the value network estimates the value of the states corresponding to the search tree leaves, replacing the trajectory-based evaluation usually performed with an ad-hoc evaluation policy called rollout policy. On the other hand, the MCTS algorithm acts as a policy improvement step. It takes as input the current state, as well as the policy and value networks, therefore improving the parametrized policy and generating the samples used to train the networks in a supervised manner. Although a tree search is still required, the deployment is cheaper since it usually requires a humbler
  planning budget, thanks to the policy and value networks which bias the search by making it more efficient. The algorithm has been successfully applied to different games such as Go, Chess, and Shogi (Silver et al., 2017a) without game-specific heuristics. However, despite its success, the algorithm suffers from a high sample complexity, especially prominent in tasks with sparse reward functions, such as goal-directed planning.
  In goal-directed tasks, the agent aims to reach a goal state, and in general, the policies take both the current state of the environment and the goal state as input. Usually, the actual reward function in these problems is zero for any transition except the one to the goal state, which gives a positive reward. RL algorithms struggle to optimize sparse reward functions since it might be hard to reach goal states, or even practically impossible during exploration if the task is quite challenging. Therefore, there is not a reward signal to guide the exploration. While in practice, in specific tasks, it is possible to use more informative reward functions, such as a distance from the goal state, such a choice is not possible for every task. Furthermore, it might also lead to sub-optimal solutions since a reward function based on a state distance might generate local-optima in the policy space (Grzes and Kudenko, 2009). Hindsight Experience Replay (HER) (Andrychowicz et al., 2017) is a straightforward method to tackle the problem of sparse-reward functions in goal-directed tasks. HER can be used with any off-policy RL algorithm to extend the training dataset for the value networks. Practically, whenever the goal state is not reached during a training episode, the states visited during the episode are used as alternative goal states and are fed to the network during training. It allows reward signals to be given to the value networks and generalize them to reach the input goal state.
  In this work, we consider the problem of applying HER to AlphaZero to tackle goal-directed tasks. We provide a scheme that does not involve computationally heavy tree re-weighting procedures or high additional computational costs. Finally, we benchmark the method with simulated environments, and we show a novel application to quantum compiling, where it is extremely hard to find unitary gate sequences from a set to approximate arbitrary single-qubit unitary operators.
sections.heading: 2 Preliminaries
sections.heading: 2.1 Goal-Directed Reinforcement Learning
sections.text: In this work, we focus on goal-directed Reinforcement Learning problems. In such setting, an autonomous agent interacts with an environment to maximize the sum of observed reward signals. Formally, in deterministic transition models, the environment consists of a state space S, a set of goal states G (that can also be equal to S), an action space A, a goal-state dependent reward function r : S × A × G → R, a transition model P : S × A → S, a probability distribution over S for the initial state s0 ∼ µ, and a probability distribution over G for the goal state sg ∼ ν. The behavior of the agent is described by a Markovian stationary goal-dependent policy, π : S×G → ∆(A), which takes as input the current state s and the goal state sg, and outputs a probability distribution over the actions in A. At the beginning of each episode, an initial state s0 ∼ µ and a goal state sg ∼ ν are sampled. Then, at time step t, the agent observes the current state st, selects an action at ∼ π(st, sg), observes the next state st+1 = P(st, at) and it gets the reward signal rt = r(st, at, sg).
  The goal of the agent is to maximize the expected return E[Rt] defined as the expectation of the discounted sum of future rewards Rt = ∑∞ i=t γ
  i−tri taken over the initial state and goal state. Given a policy π, the value of each state is encoded by the value function V π(s, sg) = Eat∼π[R0|s0 = s]. Similarly, the action-value function is defined for each stateaction pair, conditioning on the first action of the trajectories, Qπ(s, a, sg) = Eat∼π[R0|s0 = s, a0 = a]. The goal of maximizing the return can be expressed as finding an optimal policy, π∗ = argmaxπ V π(s, sg), ∀(s, sg) ∈ S × G.
sections.heading: 2.2 Monte Carlo Tree Search
sections.text: We briefly introduce the Monte Carlo Tree Search (MCTS) family of algorithms, which combine tree-search algorithms with Monte Carlo sampling to build a search tree iteratively. We focus on the most popular algorithm in the MCTS family, i.e., the upper confidence bound for trees (UCT) (Kocsis and Szepesvári, 2006). More precisely the general MCTS algorithm consists of four stages (Browne et al., 2012):
  Selection. In the selection stage, the selection policy is applied from the root of the search tree recursively until an unexpanded leaf node is reached.
  Expansion. In the expansion stage, one or more successors to the previously-found unexpanded node are generated according to the actions available in the node.
  Evaluation. The newly generated nodes are evaluated, generally through a simulation (rollout) using a default policy.
  Backpropagation. In the last stage, the rewards collected during the selection and evaluation phase are backed up following the previously visited tree branch.
  UCT performs the selection phase using the Upper Confidence Bound (UCB1) (Auer et al., 2002) bandit algorithm. Specifically, each node of the search tree maintains statistics related to the future value of each action, including the number of visits, the number of times an action is performed, and the total sum of the returns observed, used to estimate the mean return. Using such statistics UCB1 chooses the next action to perform, an, according to
  an = argmax i=1..K B(ai) = Ri,Ti(n−1) + C
  √ 2 log n
  Ti(n− 1) , (1)
  where K is the number of actions, C is a constant that regulates the exploration-exploitation trade-off, Ti(n− 1) is the number of times action i has been played up to time n− 1 and Ri,Ti(n−1) is the average payoff observed from arm i. UCT recursively updates the values of the nodes from the leaf to the root of the tree, during the backup phase. The algorithm is proved to be consistent, i.e., it converges to the optimal policy in the limit, and asymmetric, which means that it iteratively builds the search tree by favoring the most promising regions of the tree while still giving a probability of selection to all branches. Such propriety is paramount in some applications where the search tree is extremely large.
sections.heading: 2.3 AlphaZero
sections.text: AlphaZero (Silver et al., 2017a) bridges the gap between RL and MCTS by maintaining a parametric policy, πθ and value function vρ. The policy and value networks are provided as input to the MCTS algorithm to bias the tree search. In contrast, the visit counts in the tree’s root are used to build the targets for the supervised training of the policy network.
  Compared to general MCTS, the selection and evaluation phases are modified. The former phase uses the policy πθ, to bias the exploration according to the policy recommendations. Furthermore, AlphaZero replaces the classic UCT algorithm with PUCT (Rosin, 2011) and performs the selection according to:
  an = argmax i=1..K B(ai) = Ri,Ti(n−1) + Cπθ(s, ai)
  √ n
  1 + Ti(n− 1) . (2)
  By multiplying the PUCT confidence interval with the probability given to ai by πθ, AlphaZero initially prefers actions with high probability and a low visit count but asymptotically prefers actions with high values. In the latter phase, AlphaZero evaluates the leaf nodes using the estimate provided by the value network vρ, instead of performing expensive simulations with a default rollout policy. The training targets of the value network are the actual returns collected during acting. More formally, at each time step t, AlphaZero performs M search iterations of MCTS, starting from the current environment state st and using πθ during the selection phase, and vρ during the evaluation of the leaves. After the search phase, the policy targets pt are constructed using the visit counts at the root of the tree:
  pt(ai) = Nt,i∑ j Nt,j ∀i = 1, . . . ,K, (3)
  where Nt,i is the visit count of the i-th action in the search tree at step t, and K is the number of actions. Then at is sampled according to pt and is executed observing the next state st+1 and the reward signal rt. In practice, pt is often constructed as a greedy policy over the action counts, only executing the most explored one. At the end of each episode, the collected rewards are used to build the value network targets Rt. The triples (st,pt, Rt) are added to a replay buffer D used during training of the networks. In the original AlphaZero paper, the policy and value networks share the parameter vector θ and AlphaZero minimizes:
  E (s,p,R)∼D
  [ (R− vθ(s))2 − pT log πθ(s) + c∥θ∥2 ] , (4)
  where c controls the amount of L2 regularization.
sections.heading: 2.4 Hindsight Experience Replay
sections.text: Hindsight Experience Replay (Andrychowicz et al., 2017) is a method of extending off-policy RL algorithms to improve sample efficiency even in the presence of sparse reward functions. HER requires parameterizing the reward, policy, and value as a function of the current and the goal state. The basic idea behind HER is to extend the replay buffer B after each episode {s0, s1, . . . , sT } with the returns calculated based on a set of subgoals. While the main goal influences the agent’s actions during training, it does not influence the state transitions. Consequently, we can generate additional training samples by considering a subset of the states visited during the episode as subgoals. This is extremely beneficial in cases with sparse rewards, such as a reward function of the type r(st, at, sg) = 1(st+1 = sg), where reward signals would be null until the goal state is visited by chance. However, HER enables the reward signals to be generalized across the state space.
sections.heading: 3 AlphaZero with Hindsight Experience Replay
sections.text: This section describes the AlphaZeroHER algorithm. AlphaZero has been successfully applied to challenging games such as Go and Chess with outstanding results. The complexity of these games stands in the vast state-action spaces and the highly sparse reward function, since the agents will only know at the end of the game whether they have won (a reward of +1), lost (a reward of −1) or drawn (a reward of 0). Although in the context of Temporal Difference (TD) (Sutton et al., 1998) algorithms, Chess and Go fall under the definition of sparse reward, when considering returns observed at the end of the episode (Monte Carlo returns), such games have a clear reward function: the game’s result is either a win, a loss or a draw. This reason may give the impression that AlphaZero doesn’t suffer in sparse reward setting. However, in goal-directed planning, the Monte Carlo returns are often sparse, in the sense that the whole episode might finish without a reward signal. This problem was also mitigated in the original AlphaGo Zero paper (Silver et al., 2017b), where the authors employed ad-hoc board evaluators to compute the Monte Carlo returns when episodes of Go were interrupted because they were too long. Due to the criticality of sparse rewards, we extend AlphaZero with HER to tackle goal-directed tasks.
sections.heading: 3.1 AlphaZeroHER
sections.text: The basic idea of AlphaZeroHER, is to extend AlphaZero by using a goal-directed policy and value network and injecting HER into such a setting. Exploiting a goal-directed policy and value network in AlphaZero is effortless since the experience samples also include the goal state sg. However, AlphaZero is not an off-policy algorithm since the value network is trained with the returns collected while playing the MCTS augmented policy. Moreover, it is not straightforward how to evaluate the new policy when considering a new goal st ≠ sg without introducing additional prohibitive computational costs and tree re-weighting procedures. Ideally, we aim at estimating a new policy conditioned on a subgoal st ̸= sg. However, estimating such a policy requires building an additional tree since the policy targets in AlphaZero are a function of the action counts in the tree’s root node, and this with an obvious additional computational cost. An alternative approach could keep the original goal’s search tree and re-weight the statistics in the nodes conditioned on the reward function for
  the new goal st. However, such a procedure would require at least traversing the whole tree once, which would be computationally prohibitive for a large search-tree. Such problems represent the main obstacle toward introducing HER.
  We propose a procedure that extends AlphaZero with HER without adding high computational costs. The basic idea is to neglect its on-policy nature generating additional training samples at the end of each episode by sampling additional subgoals from the visited states. In fact, even though the MCTS augmented policy of AlphaZero did not reach the goal state, it successfully reached all the states visited during the episode. More precisely, we employ HER after finishing an episode of length T and having generated the sequence of states, reward and policies, {st,pt, rt}Tt=1. The episode is retraced so that at each state st, M subgoals are sampled from future visited states, {si}Ti=t+1. After selecting the subgoals states for state st, we need to compute these states’ policy and value targets. This task is not straightforward since AlphaZero is an on-policy algorithm. If we computed, in some way, a different policy target from the actual policy played pt, these would generate a different sequence of state and rewards after timestep t, which are not available. We could use the built tree to evaluate these returns related to the subgoals, but these would come with heavy tree-reweighting schemes for an already computationally heavy algorithm as AlphaZero. For this reason, we select as additional policy targets the policies played during the episode pt since, although these are not the optimal policies that the MCTS agent would have played if the subgoal states were the goal during the search, they successfully reached the alternative goal states. Therefore, these samples still represent an improvement over the current policy pθ, which can be used as policy improvement steps. Finally, we compute the new returns based on the states visited only by computing the new reward signals for each new subgoal. Such procedure is done once for each episode and involves negligible additional computation. We call this method AlphaZeroHER. Algorithm 1 in the appendix shows the pseudocode of the proposed procedure.
sections.heading: 3.2 Motivating Example
sections.text: To highlight the AlphaZero criticality in sparse reward environments, we consider a simple BitFlip domain from (Andrychowicz et al., 2017), described in detail in Section 5. In this domain, the goal is to modify a long series of n bits to reach the desired bit configuration. While it might be easy to achieve the goal configuration by applying a random policy when considering few bits only, it is practically impossible reaching the goal state if the bit length is increased.
  Figure 1 shows the performance of plain AlphaZero in the bit-flip environment, where we have plotted the expected return and the percentage of solved episodes as a function of the training epochs for three different scenarios. While AlphaZero can consistently solve an “easy” scenario of 10 bits achieving almost perfect performance, it struggles with a modest increase in the number of bits, dramatically failing to solve the task with 18 bits.
sections.heading: 4 Related Works
sections.text: Goal-Directed Reinforcement Learning has been extensively studied over the years. The optimization of multiple goals has been largely investigated in multi-goal policy optimization, curriculum learning, goal-directed planning, and multiple-task off-policy learning.
  In the context of universal value function approximators, in (Schaul et al., 2015) the authors consider the problem of approximating multiple value functions in a single architecture. In this line of work, various works study the problem of compact representations of multiple tasks (Dhiman et al., 2018; Ghosh et al., 2018). In such context, the use of sub-goals (intermediate states between the current state and the goal state) have been studied to accelerate learning and generalize over the state-space (Nasiriany et al., 2019; Jurgenson et al., 2020). In (Parascandolo et al., 2020), the authors move the problem of goal-directed planning from the space of possible policies to the problem of finding suitable sub-goals. While this has some advantages in certain situations, it cannot be applied in large state spaces since the complexity of the algorithm scales linearly with the number of states. Approximate value iteration has also been used with great results to solve the Rubic’s cube with a goal-directed framework in (McAleer et al., 2019)
  In the context of policy search, (Pinto and Gupta, 2016) and (Caruana, 1997) aim to learn policies to solve multiple tasks simultaneously. Meta-learning has also been extensively studied in recent years and can be seen as closely related to multi-task learning. In metalearning, a meta-learner is trained to learn swiftly in ever-changing tasks to adapt to learning in new untested tasks quickly. While meta-learning has been investigated early in the literature (Schmidhuber, 1987; 2007), recent work has shown impressive results in the context of Deep RL (Finn et al., 2017; 2018). Hierarchical Reinforcement Learning is also closely related to meta-learning (and our work). Here the goal is to (automatically) learn to perform multiple tasks by splitting the main problem into sub-tasks (Schmidhuber, 2002; Fruit et al., 2017). This is also closely related to the options framework.
sections.heading: 5 Experiments
sections.text: In this section, we provide an experimental evaluation of AlphaZeroHER on simulated domains, including a novel application on a quantum compiling task, modeled as a deterministic goal-directed MDP. We ran each experiment in a single multi-core machine, with no GPUs. In the following, “search iteration” refers to a single application of the 4 MCTS phases. Details on the hyperparameters employed are given in Appendix B.1 together with some additional experiments including a comparison with DQN+HER.
sections.heading: 5.1 BitFlip
sections.text: We consider a BitFlip environment where the individual bits of a long series of n bits are changed to reach a desired final configuration. More precisely, the state space is S = {0, 1}n, as well as the goal space G. The action space A = {0, 1, . . . , n − 1} specifies which bit of the current state changes from 0 to 1 or vice-versa. At the beginning of each episode, the starting bits and goal state are set randomly with uniform measures over the state space. We use a “sparse” reward of −1 for each transition, unless the goal state is reached. We tested such an environment as a motivating example for the application of HER in AlphaZero and a benchmark test since increasing the number of bits can vary the task’s difficulty sensibly. In all the runs in BitFlip, we use 20 neurons for the shared layer, 8 neurons for the policy layer and 4 for the value layer. The network hyper-parameters were not optimized. Figure 2 reports the performance of AlphaZeroHER in the scenario of 70 bits for different number of subgoals sampled (0 subgoals refers to plain AlphaZero). While AlphaZero struggles with 12 bits and fails with 18 bits, AlphaZeroHER manages to achieve great results in the case of 70 bits. Moreover, the agent achieves better performance by increasing the number of additional goals, getting perfect performance by using 4 subgoals only.
sections.heading: 5.2 2D Navigation Task
sections.text: In this section, we consider a 2D navigation task built on top of the Mujoco (Todorov et al., 2012) robotics simulator, called Point. The purpose of this experiment is to observe the performance of AlphaZero and AlphaZeroHER in a more challenging task, that requires a fair amount of exploration. More precisely, the agent’s goal (orange ball) has to reach the goal state highlighted by the green rectangle as shown in Figure 4. The task is made more challenging by the presence of a wall in the center of the environment. At the beginning of each episode, the starting state and the goal state are sampled on the left and right sides of the wall, respectively. The agent observes its current position and its current velocities in both directions and the coordinates of the goal state, while the action space is represented as control over two actuators of the agent. Although the original action space is continuous over the domain [−1, 1]2, we restricted the space to 9 discrete actions, representing the center (no action) and 8 points on the circle centered at action (0, 0) with radius 1. The reward function is −1 at each step, making the optimal policy the shortest path that reaches the green rectangle while circumventing the wall.
  We use a simple MLP with 20 neurons for the shared layer, 10 neurons for the policy layer and 4 for the value layer. Figure 3 shows the results of the experiments in this domain. We use a large horizon of 200 steps, after which we interrupt if the goal state was not reached. While AlphaZero fails to solve the environment, only reaching the goal state in 10% of the episodes, by applying HER we manage to solve most of the episodes, with only sampling 2 additional goals each episode of experience.
sections.heading: 5.3 2D Maze
sections.text: This section considers an environment of 2D procedurally generated mazes whose structure changes at each episode, as shown in Figure 4. This experiment aims to test the algorithm’s performance in a challenging image task, where Convolutional Neural Networks represent the policy and value space. At each episode, the agent is spawned on a free cell (shown in red) and moves to reach the goal cell (shown in green). The action space consists of four
  directional movements, which move the agent to one of the adjacent cells. However, if the action points towards a wall, the agent does not move. The reward function employed in this environment is a constant reward of −1, prompting the agent to find the shortest path to the goal. The state-space corresponds to a 2D image of the complete maze.
  We employ the same network architecture in all the experiments, consisting of a 3-Layer CNN, with a kernel size of 3, a Layer Normalization after each convolutional layer, and strides of [1,1,2]. The policy and value network heads have two additional fully connected layers of 128 and 64 neurons each. We run experiments in 10x10 mazes, using an horizon of 60 steps, after which we interrupt if the goal state was not reached. Figure 5 shows the results of the experiments in this domain. We can see that AlphaZeroHER clearly outperforms plain AlphaZero in this environment, although it does not itself achieve a perfect score. We attribute this low general performance to the fact that the hyperparameters of the training process were not optimized, and in an image based task, with CNNs as policy and value space, the architecture and training procedure is crucial. Nonetheless, AlphaZeroHER manages to substantially clearly improve over plain AlphaZero with only 2 additional goals.
sections.heading: 5.4 Quantum Compiler Environment
sections.text: Gate-model quantum computers achieve quantum computation by applying quantum transformations on quantum physical systems called qubits (Nielsen and Chuang, 2002). Due to hardware constraints and quantum disturbances (Linke et al., 2017; Maslov, 2017; Leibfried et al., 2007; Debnath et al., 2016), quantum computers require compilers to approximate any quantum transformations as ordered sequences of quantum gates that can be applied on the hardware. In this work, we employ AlphaZeroHER to address the problem of quantum compilation. We consider a Quantum Compiler (QC) environment consisting of a sequence Un = ∏n j=1 Aj of quantum gates Aj that starts empty at the beginning of each episode, as fully described in Moro et al. (2021). Such sequence is built incrementally at each time-step by the agent, choosing from a finite set of quantum gates B corresponding to
  the action space. More specifically, we chose the base composed of six finite rotations, i.e B = ( Rx̂(± π128 ), Rŷ(± π 128 ), Rẑ(± π 128 ) ) .
  The goal of the agent consists to approximate a single-qubit unitary transformation U that is chosen at each episode from Haar matrices. Pictorially, sampling Haar unitary matrices can be seen as choosing a number from a uniform distribution (Russell et al., 2017). The observation used as input at time-step t corresponds to the vector of the real and imaginary parts of the elements of the matrix On, where U = Un ·On. Such representation encodes all the useful information required to achieve the task, i.e the unitary transformation to approximate U and the current sequence of gates. We exploited average gate fidelity (AGF) (Nielsen, 2002) as a metric to evaluate the distance between the target gate U and the current sequence of gates Un. The task is solved whenever the agent reaches a distance equal to or greater than 0.99 AGF. The base of gates B allows defining a distance-based reward, which allows solving the problem with relative ease, although it leads to sub-optimal solutions as shown in Moro et al. (2021). However, in this work, we employ a sparse reward equal to −1 regardless of the action performed by the agent. For such reason, the task is very challenging since a high number of steps are required to approximate Haar unitary targets on average.
  In all the experiments, we use the same network architecture, consisting of a simple MLP with one initial layers of 16 hidden neurons. The policy and value network heads have an additional layer of 8 and 4 hidden neurons respectively. Figure 6 shows the results of the experiments in the QC task. In this task, the planning horizon is substantially longer than in previous environments. We interrupted the episodes at 300 steps since a perfect policy achieves an average episode length of 180 steps, and 95% of the solution can be achieved using less than 200 steps (Moro et al., 2021). AlphaZero shows a slow performance improvement, but after 100 training epochs it fails to learn the optimal policy. On the other hand, AlphaZeroHER consistently improves the performance and achieves almost perfect resolution of the problem.
sections.heading: 6 Conclusions
sections.text: We introduced a novel algorithm for goal-directed planning, consisting of the extension of AlphaZero with the Hindsight Experience Replay (HER) method to overcome the issues caused by sparse reward functions typical of goal-directed planning. We provide a straightforward procedure that does not involve high computational costs by sampling other goals from the visited states and addressing the intrinsic on-policy nature of AlphaZero. The proposed approach outperforms AlphaZero in several test domains, including a novel application to quantum compiling, with negligible additional computation compared to plain AlphaZero. In the future, we aim to apply the proposed method to more challenging goal-directed tasks, including tasks with stochastic transition models, which were not considered in this work.
sections.heading: A Additional Description of AlphaZeroHER
sections.text: In this appendix, we present the pseudocode of AlphaZeroHERO in Algorithm 1. We notice that the main loop of AlphaZero, where target values are generated from the policy targets given from MCTS and the Monte Carlo returns observed during the episodes, are extended with a set of additional experiences, based on the secondary goal states. In our implementation, the goal states are sampled uniformly from the states visited during each episode. Algorithm 1: AlphaZeroHER Initialize memory buffer B Initialize policy πθ and value network vθ for epoch = 1, · · · , N do
  for episode = 1, · · · ,M do experiences ← {} st ∼ µ // Sample initial state while not done do
  pt, at ← MCTS(st, πθ, vθ) st+1, rt, done ← applyAction(at) experiences ← experiences ⋃ (st,pt, rt)
  st ← st+1 end Store every experience (st,pt, zt) in B, where zt = ∑T i=t γ
  i−tri for t in episode experiences do // Generate new experiences
  G← Sample k goals from future visited states sj where j > t for g in G do
  rgt ← r(st, at, g) end Store every (st,pt, z g t ) in B, where z g t = ∑T i=t γ
  i−trgi end update πθ, vθ according to Equation 4
  end end
sections.heading: B Experimental Appendix
sections.text: B.1 Reproducibility Details
  In this section, we provide the hyper-parameters employed in the experiments presented in this work. Table 1 and Table 2 provide a list of hyperparameters employed for both AlphaZero and AlphaZeroHER, without being optimized.
  B.2 Varying the number of subgoals sampled
  In this section, we study the effect of increasing the number of sampled subgoals in AlphaZeroHER. Figure 7 and Figure 8 show the results of varying the number of subgoal in the BitFlip and quantum compiling environments respectively. We can see that in both enviroments the performance increases as we increase the number of subgoals k, until we
  reach a (problem dependend) threshold after which the performance starts falling until it reaches the lower levels when we use as subgoals, all the available ones (label All). This is in line with the results presented in the original HER paper (Andrychowicz et al., 2017).
  B.3 Comparison with DQN + HER
  In this section, we compared the proposed AlphaZeroHER with DQN+HER used in the original HER paper. The goal of this experiment is to answer whether using HER in a MCTS method like AlphaZero was needed, or using “more traditional” HER implementations, like DQN was enough to solve the considered environments. We use the implementation
  of DQN and HER given from stable-baselines 1. To make the comparison fair, we first employed the same network architecture used by our agents. However, except for the bitflip domains of less than 20 bits, the DQN agents could not solve any of the domains. For this reason, in the following results, we have employed a more complex network architecture for all domains (except Maze where we use the same CNN), namely an MLP with a single hidden layer of 128 neurons. We optimized the DQN hyperparameters using hyperopt2. The best hyperparameters used in all domains are listed in Table 3. It is worth noting that the hyperparameters for AlphaZero and AlphaZeroHer presented in Section 5 were not tuned.
  Figure 9 shows the results of DQN+HER in the Bitflip domain for different numbers of bits. We used four additional subgoals like in the AlphaZero case but a more complex network architecture. We can reproduce the results presented in the HER paper, as the top-performing policies solve the problems 100% of the time. When comparing the average performance, though, DQN+HER still performs worse than AlphaZeroHER, only solving on average 80% of the episodes up to 60 bits, and even less when increasing to 70 bits.
  1https://github.com/hill-a/stable-baselines 2http://hyperopt.github.io/hyperopt/
  We also achieved satisfactory results in the quantum compiling domain, solving around 80% of the episodes within the given horizon, yet still less than the 95% achieved from the AlphaZeroHER agent presented in Section 5. Figure 10 shows the performance in this domain. There, a more complex network structure was needed to achieve this performance too. DQN+HER starts to fail in the 2D navigation task. Figure 11 presents the results in this domain. Even after tuning the DQN parameters, we only can achieve around 5% of solved episodes on average, in contrast to the 80% achieved by AlphaZeroHER. Finally, in the Maze domain, even after tuning, DQN+HER could not resolve a single episode of the task against the 60% solve rate of AlphaZeroHER.
title: Goal-Directed Planning via Hindsight Expe- rience Replay