-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy patha_temp_lr_experiment.py
More file actions
69 lines (56 loc) · 2.03 KB
/
Copy patha_temp_lr_experiment.py
File metadata and controls
69 lines (56 loc) · 2.03 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
import yaml
from concurrent.futures import ProcessPoolExecutor, as_completed
from agents.adamLMCdqn import main as adamLMCDQN
from agents.egreedy import main as egreedy
def worker(base_config, a, inverse_temperature, lr, size=20):
# Copy base config to avoid shared-state mutations
config = base_config.copy()
config["a"] = a
config["inverse_temperature"] = inverse_temperature
config["LR"] = lr
if config["ENV_NAME"] == "DeepSea-bsuite":
config["size_deepSea"] = size
return adamLMCDQN(config)
def parallelized(tasks):
with ProcessPoolExecutor(max_workers=10) as executor:
futures = [
executor.submit(worker, cfg, a, inv, lr)
for cfg, a, inv, lr in tasks
]
for future in as_completed(futures):
# Optionally handle return values or exceptions
result = future.result()
def sequential(tasks):
if tasks[0][0]["ENV_NAME"] == "DeepSea-bsuite":
for cfg, a, inv, lr, size in tasks:
worker(cfg, a, inv, lr, size)
else:
for cfg, a, inv, lr in tasks:
worker(cfg, a, inv, lr)
if __name__ == "__main__":
# Load base configuration
with open("configs/defaultConfig.yaml", "r") as f:
base_config = yaml.safe_load(f)
# Load hyperparameter sweep values
with open("configs/experiments/a_and_inv_temp_experiments.yaml", "r") as f:
sweep = yaml.safe_load(f)
if base_config["ENV_NAME"] == "DeepSea-bsuite":
tasks = [
(base_config, a, inv_temp, lr, size)
for a in sweep["a"]
for inv_temp in sweep["inverse_temperature"]
for lr in sweep['LR']
for size in sweep["size"]
]
else :
tasks = [
(base_config, a, inv_temp, lr)
for a in sweep["a"]
for inv_temp in sweep["inverse_temperature"]
for lr in sweep['LR']
]
if sweep["mode"] == "parallelized":
parallelized(tasks)
else:
sequential(tasks)
egreedy(config=base_config)