-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathmain.py
45 lines (37 loc) · 1.56 KB
/
main.py
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
# Copyright 2022-, Semiotic AI, Inc.
# SPDX-License-Identifier: Apache-2.0
import argparse
from sacred import SETTINGS
import experiment
from autoagora_agents import controller
from simulation import environment
# For good reason, sacred disallows modifying your config file in the code.
# However, our code does some clever stuff to make configs less verbose than they'd
# otherwise need to be, so we disable this check
SETTINGS.CONFIG.READ_ONLY_CONFIG = False # type: ignore
parser = argparse.ArgumentParser(description="Run experiments for autoagora")
parser.add_argument("-n", "--name")
parser.add_argument("-s", "--simulation_path", default="simulationconfig.py")
parser.add_argument("-a", "--algorithm_path", default="algorithmconfig.py")
parser.add_argument("-e", "--experiment_path", default="experimentconfig.py")
args = parser.parse_args()
ex = experiment.experiment(
name=args.name,
spath=args.simulation_path,
apath=args.algorithm_path,
epath=args.experiment_path,
)
@ex.automain
def main(_run):
# NOTE: The structure of this loop is very bandit-specific.
# This would not work for a more complex RL algorithm without
# modifications
seed = _run.config["experiment"]["seed"]
algs = controller(seed=seed) # type: ignore
env = environment(seed=seed) # type: ignore
for _ in range(env.nepisodes):
obs, act, rew, done = env.reset()
while not env.isfinished():
act = algs(observations=obs, actions=act, rewards=rew, dones=done)
algs.update()
obs, act, rew, done = env.step(actions=act)