Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Hyperparameter Optimization Module #164

Open
wants to merge 135 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 129 commits
Commits
Show all changes
135 commits
Select commit Hold shift + click to select a range
8d3be23
1. bug fixed. 2. kernel extension. 3. batch GP implementatoin.
middleyuan Jun 30, 2023
7f0e3ff
update dependencies
middleyuan Jul 10, 2023
cf3d4e8
explicitliy import scipy.linalg
middleyuan Jul 10, 2023
359eecc
add cartpole configs for gpmpc
middleyuan Jul 10, 2023
89a29b8
add hyperparameter optimization module
middleyuan Jul 10, 2023
9e2a7ef
catch all the exception in hpo for debugging purpose.
middleyuan Jul 10, 2023
27454da
put cartpole configs for gpmpc under the folder of gpmpc
middleyuan Jul 10, 2023
17e408b
add hpo scripts
middleyuan Jul 10, 2023
bb4e1b0
1. include pandas 2. change rel import in gpmpc_experiment.py 3. remo…
middleyuan Jul 10, 2023
14a6db1
rename config to match default algo name.
middleyuan Jul 10, 2023
e6a2e3d
remove old configs
middleyuan Jul 10, 2023
0484388
add tests
middleyuan Jul 10, 2023
84830df
edit bash file with correct arg name
middleyuan Jul 10, 2023
e69e048
add another host in gpmpc_hpo.sh
middleyuan Jul 10, 2023
097e1c2
change to new dir in gpmpc_hpo.sh
middleyuan Jul 10, 2023
405dcea
1. fix a small bug 2. add test_train_gpmpc_cartpole
middleyuan Jul 11, 2023
549ff3e
add a hpo parallelism test
middleyuan Jul 11, 2023
81b5602
saving before runing hpo
middleyuan Jul 11, 2023
a5ad5f2
I think the bug is that it reaches thee goal in the first step.
middleyuan Jul 11, 2023
ce4d75e
1. PPO configs. 2. Make cartpole init states harder. 3. First version…
middleyuan Jul 18, 2023
b40566c
Re-organize a bit (file name, remove __init__.py in test folders).
middleyuan Jul 18, 2023
23f571d
1. HPO strategies. 2. test on hpo for ppo. 3. another way to save che…
middleyuan Jul 22, 2023
802edb6
update gitignore
middleyuan Jul 24, 2023
02d1c33
change configs
middleyuan Jul 24, 2023
20d3a7f
update bash for hpo on gpmpc
middleyuan Jul 24, 2023
ad96f6f
add prior arg in gpmpc_sampler
middleyuan Jul 24, 2023
5318c25
1. HPO effort evaluations. 2. Bash file for hpo strategy evalution.
middleyuan Jul 24, 2023
924d3b3
update dependencies
middleyuan Jul 25, 2023
14ae2aa
add the freedom to choose between random sampler and TPE sampler.
middleyuan Jul 26, 2023
c0b1b34
1. add strategy 5. 2. add unit test accordingly.
middleyuan Aug 3, 2023
f5c3a5a
1. prior configs. 2. update eval.py, sen.sh, and .gitifonore.
middleyuan Aug 3, 2023
0e1248a
gpmpc hpo strategy study
middleyuan Aug 4, 2023
a0feec7
refactor the code
middleyuan Aug 7, 2023
bd39347
1. hpo on sac. 2. add activation arg in sac and fix a small bug.
middleyuan Aug 8, 2023
4342b2a
fix typos
middleyuan Aug 8, 2023
1e1f7cf
change to two jobs
middleyuan Aug 9, 2023
b087c87
change num of repetitions to make sure it at least has same num of sa…
middleyuan Aug 9, 2023
59b4220
Merge branch 'hpo-on-ppo' into hpo-on-sac
middleyuan Aug 9, 2023
4c22c86
reduce the budget
middleyuan Aug 9, 2023
fe02a65
toy example
middleyuan Aug 10, 2023
3d33487
consider 4 version of noisy functions.
middleyuan Aug 11, 2023
714a76d
include var study
middleyuan Aug 13, 2023
2663cde
improve visualization in toy examples
middleyuan Aug 14, 2023
249a284
updated visualization improvement in toy examples.
middleyuan Aug 14, 2023
e03cb33
change naming
middleyuan Aug 14, 2023
ee29967
final experiment setup
middleyuan Aug 30, 2023
3a6448d
Merge branch 'hpo-on-ppo' into hpo-on-sac
middleyuan Aug 30, 2023
831e186
final experiment setup
middleyuan Aug 30, 2023
452937d
modify seeding
middleyuan Aug 30, 2023
7b4a844
Ignore runtime error for hpo
middleyuan Aug 31, 2023
bfd6f21
Merge branch 'hpo-on-ppo' into hpo-on-gpmpc
middleyuan Aug 31, 2023
e310829
Merge branch 'hpo-on-sac' into hpo-on-gpmpc
middleyuan Aug 31, 2023
c45e3e4
merge from sac
middleyuan Aug 31, 2023
8596fc8
fix a bug in hpo_sampler.py
middleyuan Aug 31, 2023
df01b80
final design to show possible lower compute time.
middleyuan Aug 31, 2023
9faae33
1. hpo on ddpg. 2. fix a small bug in ddpg_utils.
middleyuan Aug 31, 2023
de90501
relax the threshold
middleyuan Aug 31, 2023
4322f67
relax the threshold
middleyuan Sep 1, 2023
038f046
make rl_hpo_strategy_eval.sh automatic.
middleyuan Sep 4, 2023
4703d8b
Merge branch 'hpo-on-ppo' into hpo-on-sac
middleyuan Sep 4, 2023
807e358
Merge branch 'hpo-on-ppo' into hpo-on-ddpg
middleyuan Sep 4, 2023
6590134
fix a bug in rl_hpo_strategy_eval.sh
middleyuan Sep 4, 2023
8c594c3
Merge branch 'hpo-on-ppo' into hpo-on-sac
middleyuan Sep 4, 2023
87cbd1e
Merge branch 'hpo-on-ppo' into hpo-on-ddpg
middleyuan Sep 4, 2023
8211c52
add gpmpc_hpo_strategy_eval.sh
middleyuan Sep 4, 2023
26536e9
fix a small bug
middleyuan Sep 4, 2023
5bca27a
fix the budget (trial) bug in configs.
middleyuan Sep 5, 2023
f083b64
prepare comparing hpo strategy on gpmpc
middleyuan Sep 5, 2023
bed32ce
fix a bug in gpmpc_hpo_strategy.sh
middleyuan Sep 5, 2023
9503398
fix bugs in bash files
middleyuan Sep 5, 2023
6cd934f
fix the trial bug in config
middleyuan Sep 5, 2023
ecb27b1
fix a function bug in eval.py
middleyuan Sep 5, 2023
69d416b
Merge branch 'hpo-on-ppo' into hpo-on-ddpg
middleyuan Sep 5, 2023
a1b0756
1. add hpo resume functionality. 2. make eval function more general.
middleyuan Sep 6, 2023
c88e7e7
Merge branch 'hpo-on-ppo' into hpo-on-sac
middleyuan Sep 6, 2023
a9aa83b
update configs
middleyuan Sep 6, 2023
7f791aa
make main.sh general
middleyuan Sep 6, 2023
d8d047b
Merge branch 'hpo-on-ppo' into hpo-on-sac
middleyuan Sep 6, 2023
1e16f06
Merge branch 'hpo-on-ppo' into hpo-on-ddpg
middleyuan Sep 6, 2023
c4a8ded
resume previous config with trial increasd.
middleyuan Sep 6, 2023
80e59ec
fix the sorting bug.
middleyuan Sep 11, 2023
1a3a98a
Merge branch 'hpo-on-ppo' into hpo-on-ddpg
middleyuan Sep 11, 2023
43387d5
Merge branch 'hpo-on-ppo' into hpo-on-sac
middleyuan Sep 11, 2023
952b267
fix sorting bug
middleyuan Sep 11, 2023
7f62195
a small bug fixed
middleyuan Sep 12, 2023
d5109f4
fix a bug on computing reward
middleyuan Sep 12, 2023
1618395
Merge branch 'hpo-on-ppo' into hpo-on-gpmpc
middleyuan Sep 14, 2023
778128b
adsd resume functionality
middleyuan Sep 14, 2023
61ea053
edit main bash file and fix some typos
middleyuan Sep 14, 2023
1caae68
simply assign zero if numerical issues happen during HPO
middleyuan Sep 14, 2023
8583978
Merge branch 'hpo-on-ppo' into hpo-on-gpmpc
middleyuan Sep 14, 2023
f9f701d
adjust eval
middleyuan Sep 16, 2023
5caf0c6
change to boxenplot
middleyuan Sep 19, 2023
eea138a
fix typo
middleyuan Sep 21, 2023
362ea75
add reliable_stats
middleyuan Sep 24, 2023
3649c44
Merge branch 'hpo-on-gpmpc' into hpo-on-ppo
middleyuan Sep 24, 2023
d6e0b08
Merge branch 'hpo-on-ddpg' into hpo-on-ppo
middleyuan Sep 24, 2023
55624cd
update outdated configs
middleyuan Sep 24, 2023
6e9bbc9
Merge remote-tracking branch 'origin/hpo-on-sac' into hpo-on-ppo
middleyuan Sep 24, 2023
02d75ad
update jupyter notebooks
middleyuan Oct 5, 2023
00f6608
update jupyter notebooks.
middleyuan Oct 23, 2023
b5749d0
final update for appendix
middleyuan Oct 24, 2023
e4d616d
update readme
middleyuan Oct 24, 2023
ef29146
fix typo
middleyuan Oct 25, 2023
47f1598
1. clean up code for ppo controller, hyperparameter module. 2. Test o…
middleyuan Apr 10, 2024
83ec989
test training with given optimized hp files.
middleyuan Apr 10, 2024
e890c04
1. test hpo with and without MySQL. 2. update README.
middleyuan Apr 10, 2024
e9499cd
remove discrepancy of readme.
middleyuan Apr 10, 2024
c45a975
update readme
middleyuan Apr 10, 2024
8350b63
1. remove 'pandas' and 'seaborn' in package dependencies. 2. move tes…
middleyuan Apr 15, 2024
ee9ec34
-
middleyuan Apr 15, 2024
a260695
update config_overrides in examples of rl
middleyuan Apr 15, 2024
13ef164
run pre-commit hooks to improve linting
middleyuan Apr 16, 2024
3bbd0ba
1. ignore W503 and W504 as they conflict in pre-commit-config. 2. run…
middleyuan Apr 16, 2024
56f2738
add activation config to the examples that use RL.
middleyuan Apr 16, 2024
ba837c5
1. standardize hpo template in the examples. 2. remove _learn(). 3. a…
middleyuan Apr 17, 2024
51c601e
run pre-commit hooks.
middleyuan Apr 17, 2024
fb572f2
add gpmpc hpo test without using mysql
middleyuan Apr 17, 2024
c5fbeed
1. update config of cartpole task. 2. add max_steps and exponentiated…
middleyuan Apr 19, 2024
f8e3d0c
1. add bash files to automate hpo pipeline for gpmpc. 2. update gpmpc…
middleyuan Apr 22, 2024
1f62d3b
Merge remote-tracking branch 'upstream/main' into hpo
middleyuan Apr 22, 2024
ffb29de
match .gitignore to upstram/main.
middleyuan Apr 22, 2024
1508634
update for review
middleyuan Apr 24, 2024
896ac9f
update based on the review comments.
middleyuan May 13, 2024
3b49f7b
fix typo in readme.
middleyuan May 14, 2024
133dfee
make test_train.py faster.
middleyuan May 14, 2024
fc6fd06
Merge remote-tracking branch 'utiasDSL/main' into hpo
middleyuan Sep 23, 2024
2cf9424
1. add Vizier package. 2. update dependencies. 3. change database to …
middleyuan Sep 23, 2024
1828ff1
update readme.
middleyuan Sep 23, 2024
265d8df
commit for the second round review.
middleyuan Sep 27, 2024
32596c8
1. improve docstrings. 2. add a metric for hpo. 3. add hpo.sh bash.
middleyuan Sep 30, 2024
adbbb46
1. some bugs fixed. 2. add special handling. 3. make tests faster.
middleyuan Oct 1, 2024
f89197a
1. add hpo objective bounds in config. 2. improve logging.py. 3. all …
middleyuan Oct 2, 2024
2c046ef
fix minor config issue.
middleyuan Oct 2, 2024
67cb7e3
some bug fix.
middleyuan Oct 8, 2024
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
68 changes: 68 additions & 0 deletions examples/hpo/cartpole/config_overrides/cartpole_stab.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,68 @@
task_config:
seed: 42
info_in_reset: true
ctrl_freq: 15
pyb_freq: 750
physics: pyb

init_state_randomization_info:
init_x:
distrib: uniform
high: 1.0
low: 1.0
init_x_dot:
distrib: uniform
high: 0.05
low: -0.05
init_theta:
distrib: uniform
high: 0.05
low: -0.05
init_theta_dot:
distrib: uniform
high: 0.05
low: -0.05
# disturbances:
# observation:
# - disturbance_func: white_noise
# std: 0.0001
inertial_prop:
cart_mass: 1.0
pole_length: 0.5
pole_mass: 0.1
inertial_prop_randomization_info: null
randomized_inertial_prop: false


# normalized_rl_action_space: false

task: stabilization
task_info:
stabilization_goal: [0.0, 0.0, 0.0, 0.0]
# stabilization_goal_tolerance: 0.01
stabilization_goal_tolerance: 0.0
use_constraint_penalty: false

episode_len_sec: 5
cost: quadratic
done_on_violation: false
done_on_out_of_bound: false

obs_goal_horizon: 1

# RL Reward
rew_state_weight: [1, 1, 1, 1]
rew_act_weight: 0.1
rew_exponential: True

constraints:
- constraint_form: default_constraint
constrained_variable: input
upper_bounds: [3.0]
lower_bounds: [-3.0]
- constraint_form: default_constraint
constrained_variable: state
# upper_bounds: [1.5, 0.45, 0.1, 0.3]
# lower_bounds: [-1.5, -0.45, -0.1, -0.3]
upper_bounds: [1.5, 0.45, 0.5, 0.5]
lower_bounds: [-1.5, -0.45, -0.5, -0.5]
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
hpo_config:

hpo: True # do hyperparameter optimization
load_if_exists: True # this should set to True if hpo is run in parallel
use_database: False # this is set to true if MySQL is used
objective: [exponentiated_avg_return] # [other metrics defined in base_experiment.py]
direction: [maximize] # [maximize, maximize]
use_database: True # this is set to true if MySQL is used
objective: [average_rmse] # [other metrics defined in base_experiment.py]
direction: [minimize] # [maximize, maximize]
dynamical_runs: False # if True, dynamically increase runs
warm_trials: 20 # number of trials to run before dyamical runs
approximation_threshold: 5 # this is only used when dynamical_runs is True
Expand Down Expand Up @@ -33,3 +34,5 @@ hpo_config:
n_ind_points: 35
num_epochs: 5
num_samples: 75
state_weight: [1, 1, 1, 1]
action_weight: [0.1]
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ algo_config:
deque_size: 10
eval_batch_size: 10
gp_approx: mean_eq
# gp_model_path: ./gp_mpc/results/
gp_model_path: null
horizon: 20
prior_info:
Expand All @@ -27,17 +28,17 @@ algo_config:
- 3000
- 3000
overwrite_saved_data: false
prior_param_coeff: 1.5
prior_param_coeff: 2.0
prob: 0.95
q_mpc:
- 1
- 0.1
- 1
- 1
- 1
- 0.1
r_mpc:
- 0.1
kernel: Matern
sparse_gp: True
sparse_gp: true
n_ind_points: 40
inducing_point_selection_method: 'kmeans'
recalc_inducing_points_at_every_step: false
Expand All @@ -49,18 +50,18 @@ algo_config:
target_mask: null
train_iterations: null
test_data_ratio: 0.2
use_prev_start: true
warmstart: true
num_epochs: 5
num_samples: 75
num_test_episodes_per_epoch: 2
num_train_episodes_per_epoch: 2
num_epochs: 2
num_samples: 50
num_test_episodes_per_epoch: 1
num_train_episodes_per_epoch: 1
same_test_initial_state: true
same_train_initial_state: false
rand_data_selection: false
terminate_train_on_done: True
terminate_test_on_done: False
# parallel: False
parallel: True

device: cpu
restore: null
device: cuda
restore: null
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

there should be a newline at the end of the file. I think the pre-commit hooks handle that. If not, you can configure vs code to always add one when a file is saved, which is what I do

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah the pre-commit hook should fix this, which means you haven't yet run the hook. This should be done ASAP as it may change a lot

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think the hooks have still not been run, since there are double quotes here and there.

27 changes: 27 additions & 0 deletions examples/hpo/cartpole/config_overrides/ilqr_cartpole_hpo.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
hpo_config:

hpo: True # do hyperparameter optimization
load_if_exists: True # this should set to True if hpo is run in parallel
use_database: True # this is set to true if MySQL is used
objective: [average_rmse] # [other metrics defined in base_experiment.py]
direction: [minimize] # [maximize, maximize]
dynamical_runs: False # if True, dynamically increase runs
warm_trials: 20 # number of trials to run before dyamical runs
approximation_threshold: 5 # this is only used when dynamical_runs is True
repetitions: 5 # number of samples of performance for each objective query
alpha: 1 # significance level for CVaR
use_gpu: True
dashboard: False
seed: 24
save_n_best_hps: 3
# budget
trials: 40

# hyperparameters
hps_config:
max_iterations: 15
lamb_factor: 10
lamb_max: 1000
epsilon: 0.01
state_weight: [1, 1, 1, 1]
action_weight: [0.1]
24 changes: 24 additions & 0 deletions examples/hpo/cartpole/config_overrides/ilqr_cartpole_stab_100.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
algo: ilqr
algo_config:
# Cost parameters
q_lqr: [1, 1, 1, 1]
r_lqr: [0.1]

# Model arguments
# Note: Higher simulation frequency is required if using controller designed
# based on the continuous-time model
discrete_dynamics: True

# iLQR arguments
max_iterations: 15
lamb_factor: 10
lamb_max: 1000
epsilon: 0.01

# prior info
prior_param_coeff: 1.0
prior_info:
prior_prop:
cart_mass: 1.0
pole_length: 0.5
pole_mass: 0.1
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
safety_filter: linear_mpsc
sf_config:
# LQR controller parameters
r_lin:
- 0.1
q_lin:
- 1
- 0.1
- 1
- 0.1

# MPC Parameters
horizon: 20
warmstart: True
integration_algo: rk4
# use_terminal_set: False
use_terminal_set: True

# Prior info
prior_info:
prior_prop: null
randomize_prior_prop: False
prior_prop_rand_info: null

# Safe set calculation
n_samples: 600
n_samples_terminal_set: 100
learn_terminal_set: False

# Tau parameter for the calcuation of the RPI
tau: 0.95

# Cost function
cost_function: one_step_cost
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
hpo_config:

hpo: True # do hyperparameter optimization
load_if_exists: True # this should set to True if hpo is run in parallel
use_database: False # this is set to true if MySQL is used
objective: [average_return] # [other metrics defined in base_experiment.py]
direction: [maximize] # [maximize, maximize]
use_database: True # this is set to true if MySQL is used
objective: [average_rmse] # [other metrics defined in base_experiment.py]
direction: [minimize] # [maximize, maximize]
dynamical_runs: False # if True, dynamically increase runs
warm_trials: 20 # number of trials to run before dyamical runs
approximation_threshold: 5 # this is only used when dynamical_runs is True
Expand All @@ -14,13 +15,13 @@ hpo_config:
seed: 24
save_n_best_hps: 3
# budget
trials: 80
trials: 40

# hyperparameters
hps_config:
# model args
hidden_dim: 64
activation: relu
activation: "relu"

# loss args
gamma: 0.99
Expand All @@ -37,5 +38,8 @@ hpo_config:
# max_grad_norm: 0.5 (currently not implemented in PPO controller)

# runner args
rollout_steps: 100
max_env_steps: 72000

# objective
state_weight: [1, 1, 1, 1]
action_weight: [0.1]
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ algo: ppo
algo_config:
# model args
hidden_dim: 64
activation: relu
activation: "relu"
Federico-PizarroBejarano marked this conversation as resolved.
Show resolved Hide resolved
norm_obs: False
norm_reward: False
clip_obs: 10.0
Expand Down Expand Up @@ -38,4 +38,4 @@ algo_config:
eval_interval: 73000
num_checkpoints: 50
eval_save_best: True
tensorboard: False
tensorboard: False
67 changes: 0 additions & 67 deletions examples/hpo/gp_mpc/config_overrides/cartpole/cartpole_stab.yaml

This file was deleted.

This file was deleted.

Loading