Welcome to the Badger hands-on sessions! Please read through the prerequisites section before the hands-on session to get ready for it :)
A video for the instruction part of the first hands-on session can be found here.
Please do these before the hands-on session, since the setup could take tens of minutes or even longer, based on your network condition. Thank you!
Run the following command in terminal:
git clone https://github.com/SLAC-ML/Badger-Handson.git
Then cd
to the root of the cloned repo:
cd Badger-Handson
Badger and its plugins are python-based packages/scripts, so a proper python environment is needed. The easiest way to play with Badger w/o messing w/ your system is through docker. If you feel confident and would like to install Badger directly on your system, conda would be a good choice. Please choose one of the two paths below to get Badger installed on your computer.
-
Install docker if you haven't done so already. You can follow the tutorial showed up when you launch docker for the first time to get a feeling of what docker is about
-
Pull the pre-configured Badger docker image into your computer:
docker pull slacml/badger-handson
The docker image is around 2.5GB so it would take some time to get downloaded. When the pulling is done, run
docker images
to make sure the image is listed there -
Install XQuartz if you are using a mac. In order to expose the GUI from within the Badger docker images, we need to forward the GUI to an X window system, which is provided by XQuartz
After the installation, for the mac users, you'll need to check the Allow connections from network clients
option under the Security
tab of the XQuartz preference, as shown below:
If you choose to go with the docker option, a set of bash scripts are provided to make life easier:
-
Run Badger in docker:
./run.sh
-
Use Badger in docker again after quit the container:
./resume.sh
-
Run Badger in docker and delete the container when quit:
./run_once.sh
Note that Badger that launched by
run_once.sh
cannot be resumed after quit! -
Remove the Badger docker container and reset other system settings:
./clean_up.sh
-
Install conda if you haven't done so already
-
List all conda environments on your computer:
conda env list
and make sure you don't have an environment named
badger
. Then create the badger conda environment with the given yaml env file:conda env create -f environment.yml
It would take some time (~30min) since there are some bulky packages to be resolved/installed in the predefined conda env
These slides contain some cheat sheets and solutions to the following tasks, so please give it a look when you get stuck!
Tell Badger where to find:
- Plugins
- Database (routines)
- Logbook
- Archived runs
This task should be done w/ Badger CLI.
- Investigate
silly
algo to see the hyperparameters - Investigate
silly
env to see the available variables/observations - Use
silly
algorithm to optimizesilly
environment with the routine config given intasks/01/config.yaml
- Modify
tasks/01/config.yaml
to limit the viable range ofq1
to[0.4, 0.6]
, run and save the routine ashelloworld
- Rerun the
helloworld
routine you just saved
This task should be done w/ Badger GUI.
-
Launch the Badger GUI
-
Load the
helloworld
routine -
Add
l1
as a constraint, set the rule:l1 < 0.5
And make it a hard constraint, run the optimization, keep going until alert being triggered 3 times
This task should be done w/ Badger GUI.
- Load the
helloworld
routine - Set all available
silly
environment variables (q1
,q2
,q3
,q4
) to be optimization variables - Try to also add
q5
,q7
, andq9
as optimization variables, run the optimization
This task should be done w/ Badger GUI.
-
Create a new routine with
simplex
algorithm andinj_surrogate
environment -
Set optimization variables to be:
SOL1:solenoid_field_scale
CQ01:b1_gradient
SQ01:b1_gradient
And optimization objective to be:
- Minimize
norm_emit
We'll refer to this routine config lately as
routine config X
-
Use the default params of
simplex
algo, run the routine, save the optimal to logbook -
Set the
start_from_current
hyperparameter ofsimplex
algo tofalse
, run the routine -
Tune the
x0
hyperparameter (the initial solution) to make the routine work, save the optimal to logbook, reset the environment -
Close and relaunch Badger GUI, figure out a way to add a hard constraint:
sigma_x < 0.15
to
routine config X
, WITHOUT configuring everything from the beginning (note that we didn't save the routine) -
Switch the algorithm to
basic_bo
, run the optimization again, save the optimal to logbook, reset the environment -
Delete all the failed runs in this task
-
Read code of the
_get_obs
function inplugins/environments/inj_surrogate/__init__.py
-
Add a Gaussian noise ~
N(0, 0.01)
to thenorm_emit
observation. To generate a Gaussian noise ~N(mu, sigma^2)
, in Python one could:import numpy as np noise = sigma * np.random.randn() + mu
- Based on
silly
algorithm plugin, create aconst
algorithm plugin that repeatly evaluates the initial solution for a given times - Use your
const
algorithm to optimizeroutine config X
- Change the objective in
routine config X
tonorm_emit_x
, use yourconst
algorithm to optimize the modified problem