Skip to content

Commit 6f03300

Browse files
authored
Ray consecutive (#101)
* fix ray cleanup issue to prevent consecutive run issue * update a2c spec * prepare benchmark * change fitness marker opacity
1 parent 23d9ccf commit 6f03300

File tree

6 files changed

+90
-25
lines changed

6 files changed

+90
-25
lines changed

slm_lab/experiment/analysis.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -156,7 +156,7 @@ def plot_experiment(experiment_spec, experiment_df):
156156
x=guard_cat_x, xaxis=f'x{col_idx+1}',
157157
showlegend=False, mode='markers',
158158
marker={
159-
'symbol': 'circle-open-dot', 'color': experiment_df['fitness'],
159+
'symbol': 'circle-open-dot', 'color': experiment_df['fitness'], 'opacity': 0.5,
160160
# dump first quarter of colorscale that is too bright
161161
'cmin': min_fitness - 0.25 * (max_fitness - min_fitness), 'cmax': max_fitness,
162162
'colorscale': 'YIGnBu', 'reversescale': True

slm_lab/experiment/control.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,12 +3,12 @@
33
Creates and controls the units of SLM lab: EvolutionGraph, Experiment, Trial, Session
44
'''
55
from copy import deepcopy
6+
from importlib import reload
67
from slm_lab.agent import AgentSpace
78
from slm_lab.env import EnvSpace
89
from slm_lab.experiment import analysis, search
910
from slm_lab.experiment.monitor import AEBSpace, InfoSpace
1011
from slm_lab.lib import logger, util, viz
11-
import importlib
1212
import numpy as np
1313
import os
1414
import pandas as pd
@@ -22,7 +22,7 @@ def init_thread_vars(spec, info_space, unit):
2222
info_space.tick(unit)
2323
if logger.to_init(spec, info_space):
2424
os.environ['PREPATH'] = analysis.get_prepath(spec, info_space)
25-
importlib.reload(logger)
25+
reload(logger)
2626

2727

2828
class Session:
@@ -172,6 +172,7 @@ def init_trial_and_run(self, spec, info_space):
172172
return trial_data
173173

174174
def close(self):
175+
reload(search) # to fix ray consecutive run crash due to bad cleanup
175176
logger.info('Experiment done, closing.')
176177

177178
def run(self):

slm_lab/experiment/search.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -141,11 +141,11 @@ def generate_config(self):
141141
def run(self):
142142
'''
143143
Implement the main run_trial loop.
144-
Remember to call ray init and disconnect before and after loop.
144+
Remember to call ray init and cleanup before and after loop.
145145
'''
146146
ray.init()
147147
# loop for max_trial: generate_config(); run_trial.remote(config)
148-
ray.disconnect()
148+
ray.worker.cleanup()
149149
raise NotImplementedError
150150
return trial_data_dict
151151

@@ -177,7 +177,7 @@ def run(self):
177177
pending_ids.append(ray_id)
178178

179179
trial_data_dict.update(get_ray_results(pending_ids, ray_id_to_config))
180-
ray.disconnect()
180+
ray.worker.cleanup()
181181
return trial_data_dict
182182

183183

@@ -286,5 +286,5 @@ def run(self):
286286
population = algorithms.varAnd(
287287
population, toolbox, cxpb=0.5, mutpb=0.5)
288288

289-
ray.disconnect()
289+
ray.worker.cleanup()
290290
return trial_data_dict

slm_lab/spec/actor_critic.json

Lines changed: 9 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414
"num_step_returns": 100,
1515
"training_frequency": 32,
1616
"training_iters_per_batch": 8,
17-
"use_GAE": true,
17+
"use_GAE": false,
1818
"policy_loss_weight": 1.0,
1919
"val_loss_weight": 1.0
2020
},
@@ -51,16 +51,16 @@
5151
"num": 1
5252
},
5353
"meta": {
54-
"max_session": 2,
55-
"max_trial": 200,
56-
"search": "RandomSearch",
54+
"max_session": 4,
55+
"max_trial": null,
56+
"search": "EvolutionarySearch",
57+
"max_generation": 4,
5758
"train_mode": true
5859
},
5960
"search": {
6061
"agent": [{
6162
"algorithm": {
62-
"gamma__uniform": [0.9, 0.9999],
63-
"lambda__uniform": [0, 1]
63+
"gamma__uniform": [0.9, 0.9999]
6464
},
6565
"net": {
6666
"hid_layers__choice": [[16], [64], [32, 16], [64, 32]],
@@ -69,9 +69,7 @@
6969
},
7070
"optim_critic": {
7171
"lr__uniform": [0.001, 0.2]
72-
},
73-
"decay_lr_frequency__choice": [500, 1000, 5000, 10000],
74-
"decay_lr_min_timestep__choice": [1000, 2000, 5000]
72+
}
7573
}
7674
}]
7775
}
@@ -269,10 +267,10 @@
269267
[32, 16]
270268
],
271269
"optim_actor": {
272-
"lr__choice": [0.002, 0.02]
270+
"lr__uniform": [0.002, 0.02]
273271
},
274272
"optim_critic": {
275-
"lr__choice": [0.002, 0.02]
273+
"lr__uniform": [0.002, 0.02]
276274
}
277275
}
278276
}]

slm_lab/spec/dqn.json

Lines changed: 67 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,71 @@
11
{
2+
"dqn_benchmark": {
3+
"agent": [{
4+
"name": "DQN",
5+
"algorithm": {
6+
"name": "DQN",
7+
"action_policy": "boltzmann",
8+
"action_policy_update": "linear_decay",
9+
"explore_var_start": 1.5,
10+
"explore_var_end": 0.3,
11+
"explore_anneal_epi": 10,
12+
"gamma": 0.999,
13+
"training_epoch": 4,
14+
"training_frequency": 10,
15+
"training_iters_per_batch": 1,
16+
"training_min_timestep": 10
17+
},
18+
"memory": {
19+
"name": "Replay",
20+
"max_size": 10000
21+
},
22+
"net": {
23+
"type": "MLPNet",
24+
"hid_layers": [64],
25+
"hid_layers_activation": "sigmoid",
26+
"optim": {
27+
"name": "Adam",
28+
"lr": 0.02
29+
},
30+
"batch_size": 32,
31+
"decay_lr": true,
32+
"decay_lr_frequency": 400,
33+
"decay_lr_min_timestep": 1400,
34+
"update_type": "replace",
35+
"update_frequency": 1,
36+
"polyak_weight": 0.9
37+
}
38+
}],
39+
"env": [{
40+
"name": "CartPole-v0",
41+
"max_timestep": null,
42+
"max_episode": 200
43+
}],
44+
"body": {
45+
"product": "outer",
46+
"num": 1
47+
},
48+
"meta": {
49+
"max_session": 4,
50+
"max_trial": null,
51+
"search": "EvolutionarySearch",
52+
"max_generation": 4,
53+
"train_mode": true
54+
},
55+
"search": {
56+
"agent": [{
57+
"algorithm": {
58+
"explore_anneal_epi__randint": [10, 60]
59+
},
60+
"net": {
61+
"hid_layers__choice": [[16], [64], [32, 16], [64, 32]],
62+
"optim": {
63+
"lr__uniform": [0.001, 0.2]
64+
}
65+
}
66+
}]
67+
}
68+
},
269
"dqn_cartpole": {
370
"agent": [{
471
"name": "DQN",

slm_lab/spec/reinforce.json

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -39,9 +39,10 @@
3939
"num": 1
4040
},
4141
"meta": {
42-
"max_session": 2,
43-
"max_trial": 200,
44-
"search": "RandomSearch",
42+
"max_session": 4,
43+
"max_trial": null,
44+
"search": "EvolutionarySearch",
45+
"max_generation": 4,
4546
"train_mode": true
4647
},
4748
"search": {
@@ -52,10 +53,8 @@
5253
"net": {
5354
"hid_layers__choice": [[16], [64], [32, 16], [64, 32]],
5455
"optim": {
55-
"lr__uniform": [0.001, 0.1]
56-
},
57-
"decay_lr_frequency__choice": [500, 1000, 5000, 10000],
58-
"decay_lr_min_timestep__choice": [1000, 2000, 5000]
56+
"lr__uniform": [0.001, 0.2]
57+
}
5958
}
6059
}]
6160
}

0 commit comments

Comments
 (0)