An introduction to RL and its applications at CERN
Matteo Bunino (matteo.bunino@cern.ch) - Fellow @ CERN openlab
11 Jul 2024
Acknowledgements
11 Jul 2024
Matteo Bunino | An introduction to RL and its applications at CERN
RL theory: Sutton and Barto book “Reinforcement Learning: an introduction”, Prof. David Silver lectures, Prof. Marios Kountouris (EURECOM) notes, Felix Wagner.
RL use cases at CERN: M. Schenk, J. Wulff, N. Bruchon, B. Goddard, S. Hirlander, V. Kain, N. Madysa, G. Valentino, F. Velotti, CERN Openlab, and the ML Community Forum.
If you find some of your materials without the proper credits, let me know and I will update the slides accordingly. Send me an email to matteo.bunino@cern.ch
3
11 Jul 2024
Matteo Bunino | An introduction to RL and its applications at CERN
4
Image credits
Use cases motivating reinforcement learning (RL)
11 Jul 2024
Matteo Bunino | An introduction to RL and its applications at CERN
Examples from Sutton and Barto book:
5
RL in games
11 Jul 2024
Matteo Bunino | An introduction to RL and its applications at CERN
6
“AlphaStar” wins Starcraft against
99.85% of human players (2019).
“AlphaGo” winning against
the Go world champion (2016).
Look for “AlphaGo’s move 37” on the web...
Reinforcement learning concepts
11 Jul 2024
Matteo Bunino | An introduction to RL and its applications at CERN
In a nutshell: learn a policy which maximizes the total expected reward over time.
Multistage decision-making process: the learner is not told which actions to take - it discovers which actions yield the most reward by trying them.
Not supervised learning: the agent learns from its own experience, not from representative examples.
Not unsupervised learning: maximize a reward signal instead of trying to find hidden structure in data.
Reinforcement learning (RL) peculiarities:
7
…similar to human learning
Reinforcement learning concepts
11 Jul 2024
Matteo Bunino | An introduction to RL and its applications at CERN
Goal: learn the optimal policy which maximizes the total expected reward over time.
Environment: can be accessible only partially. Some dynamics may remain obscure, and we get only what we can observe.
Interpreter: that’s defined by us. Sort of pre-processing. It builds the state based on the history of previous observations and interactions. It also implements the reward function.
State: describes the environment. It belongs to the states space
Reward (scalar number) is the only feedback the agent receives, which describes the “goodness” of the trajectory so far.
Action: sampled by the agent from the actions space
Interaction defines trajectories:
8
Observation
Reinforcement learning concepts
11 Jul 2024
Matteo Bunino | An introduction to RL and its applications at CERN
Goal: learn the optimal policy which maximizes the total expected reward over time.
Policy is a mapping from perceived states of the environment to actions to be taken:
State value function: value of a state = total amount of reward an agent can expect to accumulate over the future, starting from that state (specifies what is good in the long run). �It estimates how good is for an agent to be in a given state.
9
Observation
Reinforcement learning concepts - example
11 Jul 2024
Matteo Bunino | An introduction to RL and its applications at CERN
Goal: learn the optimal policy which maximizes the total expected reward over time.
State: tuple (ball_x, ball_y, cursor_h, opponent_cursor_h), for each t.
Action: up or down of 1cm. {‘up’, ‘down’}
Reward: e.g., scored points, or +1 if agent scored, -1 if opponent scored, 0 otherwise. The design of the reward function is often tricky and shall be tuned.
Optimal policy: find the best mapping between the state and the action to take. E.g., go up when the ball is coming top right.
State value function (informal): how many points am I expecting to score given that now I am in state ?
10
Atari’s “Pong”
Reinforcement learning challenges
11 Jul 2024
Matteo Bunino | An introduction to RL and its applications at CERN
11
Foster innovative solutions, e.g., “AlphaGo’s move 37”
Markov Decision Process
11 Jul 2024
Matteo Bunino | An introduction to RL and its applications at CERN
v
Maths prerequisites
11 Jul 2024
Matteo Bunino | An introduction to RL and its applications at CERN
13
Markov Decision Process (MDP)
11 Jul 2024
Matteo Bunino | An introduction to RL and its applications at CERN
The environment can be modeled as an MDP when the following are known:
The MDP/env dynamics fully describes the MDP under analysis, allowing for analytical solutions.
MDP is finite if are finite sets.
Under this formulation, we say that the agent interacts with the environment by performing some action , transitioning to a new state and receiving a scalar feedback called reward .
This results in a trajectory: �(where is the terminal state).
Markov property:
14
Random variables
Environment dynamics
11 Jul 2024
Matteo Bunino | An introduction to RL and its applications at CERN
When the environment dynamics function is known, we can compute everything else one may want to know about the environment:
15
Episodic and continuing tasks
11 Jul 2024
Matteo Bunino | An introduction to RL and its applications at CERN
Continuing tasks:
Episodic tasks:
16
Return
11 Jul 2024
Matteo Bunino | An introduction to RL and its applications at CERN
The goal of the agent is to find the optimal policy: “what is the best action I should take in state St?”
To assess the “goodness” of a state (an action), the agent tries to estimate the cumulative future reward of a trajectory starting from that state (and taking that action). More formally, we call this property return, and we define it as the cumulative future reward:
is the discount factor. For continuing tasks , thus the discount factor has to be for the sum to converge.
17
Policy
11 Jul 2024
Matteo Bunino | An introduction to RL and its applications at CERN
A policy describes the behavior of the RL agent, mapping from state to probabilities of selecting each possible action.
Policy
Example:
The first step to find the optimal policy is to assess how good is the current one…
18
| p(a1) | p(a2) |
State s1 | 0.7 | 0.3 |
State s2 | 0.1 | 0.9 |
S1
S2
a1
a2
a1
a2
0.7
0.3
0.1
0.9
Hands-on: get familiar with MDP and return
In this first exercise we will:
19
Value Functions
11 Jul 2024
Matteo Bunino | An introduction to RL and its applications at CERN
Allow to assess the “goodness” of some policy .
The state value function is the expected return when starting in state and following thereafter:
20
How to generalize this?
Value Functions
11 Jul 2024
Matteo Bunino | An introduction to RL and its applications at CERN
Allow to assess the “goodness” of some policy .
The state value function is the expected return when starting in state and following thereafter:
21
Still not so useful… What do we do with ?
Value Functions
11 Jul 2024
Matteo Bunino | An introduction to RL and its applications at CERN
Allow to assess the “goodness” of some policy .
The state value function is the expected return when starting in state and following thereafter:
22
Interesting recursive relationship to “remove” the return… thus the explicit dependency on the future.
Value Functions
11 Jul 2024
Matteo Bunino | An introduction to RL and its applications at CERN
Allow to assess the “goodness” of some policy .
The state value function is the expected return when starting in state and following thereafter:
23
Value Functions
11 Jul 2024
Matteo Bunino | An introduction to RL and its applications at CERN
Allow to assess the “goodness” of some policy .
The state value function is the expected return when starting in state and following thereafter:
When is finite, we can solve it directly as a linear system in unknowns:
Where R is the immediate expected reward and P is the state transition matrix.
However, this is expensive also for small MDPs!
24
Value Functions
11 Jul 2024
Matteo Bunino | An introduction to RL and its applications at CERN
Allow to assess the “goodness” of some policy .
The state value function is the expected return when starting in state and following thereafter:
The state-action value function is the expected return when starting in state , taking action , and following thereafter:
25
Very similar to the state value function… but not recursive
Value Functions
11 Jul 2024
Matteo Bunino | An introduction to RL and its applications at CERN
Allow to assess the “goodness” of some policy .
The state value function is the expected return when starting in state and following thereafter:
The state-action value function is the expected return when starting in state , taking action , and following thereafter:
26
Value Functions - dynamic programming
11 Jul 2024
Matteo Bunino | An introduction to RL and its applications at CERN
Dynamic programming (DP) allows to iteratively solve Bellman equations to estimate the value function under some policy .
27
Reference: RL book - chapter 4
Bellman optimality equations
11 Jul 2024
Matteo Bunino | An introduction to RL and its applications at CERN
So far, we “evaluated” some policy by computing its associated value functions and .
How can we compute directly the optimal policy ?
The optimal policy is the one which maximizes the expected cumulative future reward in each state
28
The goal of the RL agent is to find the optimal policy which maximizes the�value functions.
a.k.a. value function
Bellman optimality equations
11 Jul 2024
Matteo Bunino | An introduction to RL and its applications at CERN
State value functions:
State-action value functions:
29
In both cases, we replace the expectation with a max over the action space
Optimal policies
11 Jul 2024
Matteo Bunino | An introduction to RL and its applications at CERN
The optimal policy is the policy that assigns non-zero probabilities only to the actions that maximize the the value function in some state, for all states.
30
| a1 | a2 | a3 |
s1 | 20 | 30 | 30.1 |
s2 | 15 | 15 | 3 |
Optimal state-action value function
| Pr(a1) | Pr(a2) | Pr(a3) |
s1 | 0 | 0 | 1.0 |
s2 | 0.5 | 0.5 | 0 |
Optimal policy #1
| Pr(a1) | Pr(a2) | Pr(a3) |
s1 | 0 | 0 | 1.0 |
s2 | 0.99 | 0.01 | 0 |
Optimal policy #2
| Pr(a1) | Pr(a2) | Pr(a3) |
s1 | 0 | 0 | 1.0 |
s2 | 1.0 | 0 | 0 |
Optimal policy #3
| Pr(a1) | Pr(a2) | Pr(a3) |
s1 | 0 | 0 | 1.0 |
s2 | 0 | 1.0 | 0 |
Optimal policy #4
Greedy policies
Optimal policies - dynamic programming
11 Jul 2024
Matteo Bunino | An introduction to RL and its applications at CERN
Dynamic programming (DP) allows to iteratively solve Bellman optimality equations to estimate the value function under the optimal policy.
31
Reference: RL book - chapter 4
Hands-on: dynamic programming
In this exercise we will learn how to use dynamic programming for:
32
MDP summary
11 Jul 2024
Matteo Bunino | An introduction to RL and its applications at CERN
In some situations, we can assume that the environment can be modeled as a Markov decision process.
The environment dynamics are fully known as a common function. In the discrete case, you can imagine p as a 4-dimensional lookup table for probabilities.
This allows us to easily compute Bellman equations and Bellman optimality equations:
These recursive equations can be solved
From the Bellman optimality equations, it is easy to obtain the optimal policy which maximizes future rewards.
33
11 Jul 2024
Matteo Bunino | An introduction to RL and its applications at CERN
34
Sample-based methods
11 Jul 2024
Matteo Bunino | An introduction to RL and its applications at CERN
v
Sample-based methods
11 Jul 2024
Matteo Bunino | An introduction to RL and its applications at CERN
When the environment dynamics are not known, we can simulate them by interacting directly with the environment.
Again we can have episodic and continuing tasks.
In this case, episodes are characterized by trajectories of finite length, terminated by some terminal state :
…at the cost of taking very long time.
Sample efficiency (informally): how many interactions with the environment do we need before being able to exploit the gained knowledge for our goals?
36
Observation
Monte Carlo methods
11 Jul 2024
Matteo Bunino | An introduction to RL and its applications at CERN
Base on experience: sample sequences of states, actions and rewards from actual or simulated interactions with the environment:
“Monte Carlo” replace expectation on the return with average:
is known only at the end of an episode, thus we can only apply Monte Carlo methods to episodic tasks, which terminate at some point (reach some terminal state ).
Therefore, value functions and policies are updated only at the end of each episode. Monte carlo is incremental in an episode-by-episode sense (off-line), but not in a step-by-step sense (on-line):
37
Monte Carlo prediction
11 Jul 2024
Matteo Bunino | An introduction to RL and its applications at CERN
38
Prediction = estimating the value function
Monte Carlo prediction - example
11 Jul 2024
Matteo Bunino | An introduction to RL and its applications at CERN
39
Observation
Interact with the env…
| p(a1) | p(a2) |
State s1 | 0.7 | 0.3 |
State s2 | 1.0 | 0 |
S1
S2
a1
a2
a1
a2
0.7
0.3
1.0
0
…according to some policy.
Q(s,a) | a1 | a2 |
State s1 | ??? | ??? |
State s2 | ??? | ??? |
Initial Q table:
Q(s,a) | a1 | a2 |
State s1 | 23.1 | 12.09 |
State s2 | 2.57 | ??? |
Resulting Q table:
Upon convergence
We never visited (s2, a2)!
Exploration vs. exploitation
11 Jul 2024
Matteo Bunino | An introduction to RL and its applications at CERN
When the env dynamics are not known, we need to sample from the environment, at the risk of incurring in bias.
Exploration requires devoting some interactions budget to low-rewarding interactions, however in the long run it can result in better rewards.
Exploiting too early can lead to suboptimal policies, which are too shortsighted. They prefer small immediate rewards versus big delayed rewards.
Too few exploration in favour of exploitation may bias the agent, with the risk of locking him sub-optimal policies forever!
To find the best policy, the agent may have to explore a lot before, at a greater computational cost. Trade-off!
40
Maintaining exploration
11 Jul 2024
Matteo Bunino | An introduction to RL and its applications at CERN
In practice, a popular way to maintain exploration is resorting to -greedy policies.
Is usually small (e.g., 0.1) and < 1 .
Example, given 3 actions a1, a2, a3 where A*=a3:
41
(Greedy action)
1-
1/3
1/3
1/3
a1
a2
a3
a3
Pr(a1) = /3
Pr(a2) = /3
Pr(a3) = /3 + (1 - )
Let’s visualize it with the help of a probability tree…
Monte Carlo control
11 Jul 2024
Matteo Bunino | An introduction to RL and its applications at CERN
42
Control = improving the current policy
Novelty
Monte Carlo control - example
11 Jul 2024
Matteo Bunino | An introduction to RL and its applications at CERN
43
Observation
Interact with the env…
| p(a1) | p(a2) |
State s1 | /2 + 1 - | /2 |
State s2 | /2 + 1 - | /2 |
S1
S2
a1
a2
a1
a2
…according to some policy.
Q(s,a) | a1 | a2 |
State s1 | ??? | ??? |
State s2 | ??? | ??? |
Initial Q table:
Estimate Q table
Loading…
Machine learning
11 Jul 2024
Matteo Bunino | An introduction to RL and its applications at CERN
Lorem ipsum dolor sit amet, consectetur adipiscing elit. Vestibulum commodo diam nec ex dignissim mollis. Nunc posuere risus eu orci ultrices, sed cursus orci malesuada. Maecenas lectus nnc, scelerisque et pharetra at, condimentum sed purus. Fusce ac massa et orci euismod auctor. Proin et hendrerit justo. Nulla facilisi. Quisque eros augue, vehicula ac cursus a, rhoncus vitae leo. In eu tortor id urna pretium feugiat.
Quisque et convallis mauris, aliquet iaculis diam. Morbi eu iaculis ipsum. Aenean justo massa, aliquam eget metus non, sodales pharetra elit. Curabitur sed varius leo. Donec volutpat purus vel molestie congue. Morbi congue commodo massa in viverra. Curabitur et hendrerit ipsum. Cras condimentum iaculis libero nec imperdiet. Integer elit nulla, mollis eget porta accumsan, semper at tellus. Duis egestas, ligula a gravida elementum, enim magna bibendum turpis, ut pretium arcu purus et urna. Pellentesque facilisis sapien eu tellus ultricies aliquet.
44
MC has high variance + off-line -> slow learning
Monte Carlo control - example
11 Jul 2024
Matteo Bunino | An introduction to RL and its applications at CERN
45
Q(s,a) | a1 | a2 |
State s1 | ??? | ??? |
State s2 | ??? | ??? |
Initial Q table:
Q(s,a) | a1 | a2 |
State s1 | 23.1 | 12.09 |
State s2 | 2.57 | 42.5 |
Resulting Q table:
Upon convergence
Red: max action value
| p(a1) | p(a2) |
State s1 | /2 + 1 - | /2 |
State s2 | /2 + 1 - | /2 |
Initial policy:
| p(a1) | p(a2) |
State s1 | /2 + 1 - | /2 |
State s2 | /2 | /2 + 1 - |
Final policy:
Control
Red background: preferred action
Monte Carlo (MC) - summary
11 Jul 2024
Matteo Bunino | An introduction to RL and its applications at CERN
The return is known only at the end of an episode, thus we can only apply Monte Carlo methods to episodic tasks, which terminate at some point (reach some terminal state ).
Therefore, value functions and policies are updated only at the end of each episode. Monte carlo is incremental in an episode-by-episode sense (off-line), but not in a step-by-step sense (on-line):
Drawbacks:
46
End of first episode. The second starts.
TD(0) methods
11 Jul 2024
Matteo Bunino | An introduction to RL and its applications at CERN
How to improve sample efficiency of MC methods?
Idea: turn off-line into on-line!
Recall that the expression of the return can be rewritten recursively:
Now, at each step (interaction) estimate the return by means of bootstrapping:
The incremental update is possible as soon as are available.
Don’t need to wait for the end of the episode to update value functions and policies.
47
“If one had to identify one idea as central and novel to reinforcement learning, it would undoubtedly be temporal-difference (TD) learning.”
– Barto-Sutton RL book.
TD(0) methods
11 Jul 2024
Matteo Bunino | An introduction to RL and its applications at CERN
Don’t need to wait for the end of the episode to update value functions and policies.
The on-line update rule becomes, for some small learning rate 0< < 1 :
In both cases, the new estimate of the value function is a linear combination of the previous estimate and the “TD error”.
48
TD(0) control - SARSA
11 Jul 2024
Matteo Bunino | An introduction to RL and its applications at CERN
49
It estimates the expected return for state-action pairs assuming the current policy continues to be followed: on-policy update for Q. �
TD(0) control - Q-learning
11 Jul 2024
Matteo Bunino | An introduction to RL and its applications at CERN
50
It estimates the expected return for state-action pairs assuming a greedy policy were followed despite the fact that it's not necessarily following a greedy policy: off-policy update for Q. �
More generally, off-policy means that the return is computed using a different policy from the one used to choose the next action (i.e., the policy through which we “explore” the environment).
Hands-on: TD(0)
In this exercise we will learn how to implement:
for policy control.
51
TD(0) summary
11 Jul 2024
Matteo Bunino | An introduction to RL and its applications at CERN
Pros (on-line method):
Cons (due to bootstrapping):
SARSA vs. Q-learning:
52
Model-based methods
11 Jul 2024
Matteo Bunino | An introduction to RL and its applications at CERN
The interaction with the environment may be expensive:
…how can we train our agent well, without interacting too much?
Keep a model of the environment and sample (also) from it!
53
General idea:
Tabular Dyna-Q
11 Jul 2024
Matteo Bunino | An introduction to RL and its applications at CERN
Model: store previous interactions with the environment. Can only sample state-action pairs visited previously.
54
Tabular Dyna-Q
11 Jul 2024
Matteo Bunino | An introduction to RL and its applications at CERN
Model: store previous interactions with the environment. Can only sample state-action pairs visited previously.
55
Model-based methods - summary
11 Jul 2024
Matteo Bunino | An introduction to RL and its applications at CERN
Pros:
Cons:
56
Function approximation
v
Limitations of tabular methods
11 Jul 2024
Matteo Bunino | An introduction to RL and its applications at CERN
Tabular methods encountered: Monte Carlo, SARSA, Q-learning, tabular Dyna-Q.
58
How do we represent this in a table?
One entry for each unique combination of the colors of all pixels?
. . . . . . . . . . .
. . . . . . . . . . .
. . . . . . .
. . .
. . . . . . . . . . .
Can we find a better way?
Atari’s “Pong”
Function approximation - value function
11 Jul 2024
Matteo Bunino | An introduction to RL and its applications at CERN
Function approximation shifts the task of learning the values for each state or state-action pair to learning a parameterized version of the value functions that minimizes a given objective.
The parametric state value function is with parameters .
The objective to minimize is the Mean Squared Error in the approximation of by .
where is the proportion of times state s was visited.
The objective above can be minimized by means of Stochastic Gradient Descent (SGD), obtaining the update rule:
A similar reasoning holds for the parametric state-action value function:
59
Function approximation - value function
11 Jul 2024
Matteo Bunino | An introduction to RL and its applications at CERN
Since the value function is unknown, we substitute it with an unbiased estimator of it: .
60
Depends on the trainable parameters!
Function approximation - value function
11 Jul 2024
Matteo Bunino | An introduction to RL and its applications at CERN
Since the value function is unknown, we substitute it with an unbiased estimator of it: .
61
Nice but… how to put everything together?
Function approximation - value function
11 Jul 2024
Matteo Bunino | An introduction to RL and its applications at CERN
Example of on-policy control with function approximation: SARSA.
62
Function approximation - DQN
11 Jul 2024
Matteo Bunino | An introduction to RL and its applications at CERN
Train RL agent to play Atari games. Feature extractor: convolutional neural network (CNN). Reward: +1 if scored a point, -1 otherwise.
Example of off-policy control with function approximation. The Q function is approximated with a neural network
63
Image credits.
Image credits.
Experience replay
DQN
Image credits.
Gameplay
Off-policy: DQN is updated using “old” transitions sampled from the replay buffer
Function approximation - DQN
11 Jul 2024
Matteo Bunino | An introduction to RL and its applications at CERN
Continuous state space: embedding vector produced by the feature extractor (CNN, part of DQN).
Discrete actions space: depends on the specific game.
Experience replay:
64
Q(s, a1)
Q(s, a2)
Q(s, a3)
Q(s, a4)
State features
Image credits.
Function approximation - DQN
11 Jul 2024
Matteo Bunino | An introduction to RL and its applications at CERN
Update rule:
65
“Target” network
-
“Policy” network
Function approximation - DQN
11 Jul 2024
Matteo Bunino | An introduction to RL and its applications at CERN
Target and policy networks visualized:
66
Image credits.
Copy parameters every K steps
Policy network
Hands-on: DQN
11 Jul 2024
Matteo Bunino | An introduction to RL and its applications at CERN
In this exercise we will learn how to implement Q-learning with function approximation.
67
Image credits.
Function approximation - policy gradient
11 Jul 2024
Matteo Bunino | An introduction to RL and its applications at CERN
So far we obtained the optimal greedy policy from the (approx) optimal value function
However, in some cases it would be more convenient to learn directly the policy!
68
A greedy policy is easily exploited by the opponent.
Example:
Always draw paper
Function approximation - policy gradient
11 Jul 2024
Matteo Bunino | An introduction to RL and its applications at CERN
Write the policy as a parametrized function:
For instance:
Define an objective, for instance:
And the corresponding param. update rule:
69
Is called actions preferences. Can by a neural network.
Function approximation - policy gradient
11 Jul 2024
Matteo Bunino | An introduction to RL and its applications at CERN
Episodic case
70
Function approximation - policy gradient
11 Jul 2024
Matteo Bunino | An introduction to RL and its applications at CERN
REINFORCE is based on MC -> high variance.
Adding a “baseline” leaves the expected value of the update unchanged, but it can have a large effect on its variance.
71
Image from Barto-Sutton book
For instance:
Function approximation - policy gradient
11 Jul 2024
Matteo Bunino | An introduction to RL and its applications at CERN
REINFORCE with baseline
72
Image from Barto-Sutton book
Kind of “loss”, depends on Gt
Function approximation - actor-critic
11 Jul 2024
Matteo Bunino | An introduction to RL and its applications at CERN
REINFORCE based on MC -> off-line.
Solution: substitute MC return with its bootstrapped version. Becomes on-line.
Keep using value function as a baseline:
Update rules become:
73
Value function params (critic)
Policy function params (actor)
Note: they may use different alphas.
Function approximation - actor-critic
11 Jul 2024
Matteo Bunino | An introduction to RL and its applications at CERN
74
Episodic case because for the continuing case we need to change the objective function
(out of the context of this lecture)
RL for particle accelerators
v
AWAKE - background
11 Jul 2024
Matteo Bunino | An introduction to RL and its applications at CERN
Problem: difficult to accelerate electrons in the LHC. Due to curvature, they emit radiation and lose energy. Since the circumference of the LHC is finite, it can provide a finite amount of energy to the particles. This results in a dynamic equilibrium.
A possible solution could be using linear/larger accelerators (e.g., FCC), or improving how we accelerate particles.
Wakefield Acceleration Experiment: experimental beamline exploring innovative acceleration techniques.
Use two beams in the same line:
e-e-e-e-e- p+p+p+p+p+
Go through a plasma cell:
Wakefield acceleration could replace current RF cavities in�the far future.
76
e-
q+
wakefield
AWAKE - beam steering
11 Jul 2024
Matteo Bunino | An introduction to RL and its applications at CERN
RL problem: keep the electrons beam within the beamline and steer them into the plasma to best exploit the wakefield.
States: readouts from 10 sensors (BPMs)
Actions: 10 correctors
Simulation of the beamline available: train the agent in simulation and fine-tune it on the real machine.
…remember the expensive agent-environment interactions mentioned before?
77
Beam-time is expensive: the agent has to learn fast! Sample efficiency is critical.
AWAKE - beam steering
11 Jul 2024
Matteo Bunino | An introduction to RL and its applications at CERN
Illustration of Q-learning: 1D beam steering
78
AWAKE - Q-learning with NAF
11 Jul 2024
Matteo Bunino | An introduction to RL and its applications at CERN
79
AWAKE - train Q-learning on simulation
11 Jul 2024
Matteo Bunino | An introduction to RL and its applications at CERN
80
AWAKE - train Q-learning on simulation
11 Jul 2024
Matteo Bunino | An introduction to RL and its applications at CERN
81
Further experiments improved sample efficiency by using model-based RL, inspired to Dyna-Q
Bunch splitting
11 Jul 2024
Matteo Bunino | An introduction to RL and its applications at CERN
82
Bunch splitting - background
11 Jul 2024
Matteo Bunino | An introduction to RL and its applications at CERN
RF cavities: used to accelerated particles in the LHC
83
Bunch splitting - background
11 Jul 2024
Matteo Bunino | An introduction to RL and its applications at CERN
RF cavities: used to accelerated particles… but also to split bunches!
The split is done in PS to prepare beams for LHC. �We gradually change the intensity (voltage) of high harmonics in the RF cavities: h7, h14, h21
Voltage and phase has to be dynamically adjusted for each harmonic:
Done manually: not always reproducible.�Task: RL to optimise splittings to produce uniform bunches. Good for science!
84
t
Bunch splitting - background
11 Jul 2024
Matteo Bunino | An introduction to RL and its applications at CERN
Animation of a bunch (triple) splitting. Note the variation of intensity per harmonics.
85
Bunch splitting - RL problem
11 Jul 2024
Matteo Bunino | An introduction to RL and its applications at CERN
Automating bunch splitting is good for reproducibility. RL-based splitting is “in production” at PS.
Challenge: reward function design. For both phase and voltage, compare bunch profiles (Means Squared Error).
Phase profiles:
86
Bunch splitting - RL problem
11 Jul 2024
Matteo Bunino | An introduction to RL and its applications at CERN
Automating bunch splitting is good for reproducibility. RL-based splitting is “in production” at PS.
Challenge: reward function design. For both phase and voltage, compare bunch profiles (Means Squared Error).
Similarly, for voltage profiles:
87
Bunch splitting - RL problem
11 Jul 2024
Matteo Bunino | An introduction to RL and its applications at CERN
Optimization of voltage profiles is based on the assumption that the phase is already optimal.
Train two RL agents:
88
Bunch splitting - RL problem
11 Jul 2024
Matteo Bunino | An introduction to RL and its applications at CERN
Optimization of voltage profiles is based on the assumption that the phase is already optimal.
89
Bunch splitting - RL problem
11 Jul 2024
Matteo Bunino | An introduction to RL and its applications at CERN
For stability reasons, it is convenient to “bias” the agent with a prediction from a supervised CNN.
The CNN is trained on simulated data.
90
CNN feature extractor
Regression head
(phases)
Guess initial phase values
Bunch splitting - the big picture
11 Jul 2024
Matteo Bunino | An introduction to RL and its applications at CERN
91
Bunch splitting - conclusions
11 Jul 2024
Matteo Bunino | An introduction to RL and its applications at CERN
Trained on simulation and applied on machine without re-training.
Consistent good performance for:
Consistently rivals experienced operators in optimisation steps: averaging ~8.5 steps per optimisation (depending on initial conditions).
92
11 Jul 2024
Matteo Bunino | An introduction to RL and its applications at CERN
93
Questions?
Matteo Bunino | An introduction to RL and its applications at CERN