-
Notifications
You must be signed in to change notification settings - Fork 5
/
Copy pathrun_training_only_adaptive.py
59 lines (47 loc) · 1.48 KB
/
run_training_only_adaptive.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
46
47
48
49
50
51
52
53
54
55
56
57
58
59
import pathlib
from distutils.util import strtobool
import numpy as np
import yaml
from rl import crpo
from rl.crpo import make_crpo_parser
from training_env_factory import make_env_factory
from training_env_factory import get_env_id
if __name__ == "__main__":
import argparse
parser = make_crpo_parser()
parser.add_argument(
"--use-ctrl",
type=lambda x: bool(strtobool(x)),
default=False,
nargs="?",
const=True,
help="Toggles the use of a controller",
)
parser.add_argument(
"--use-cbf",
type=lambda x: bool(strtobool(x)),
default=False,
nargs="?",
const=True,
help="Toggles the use of a CBF",
)
args = parser.parse_args()
if args.seed is None:
args.seed = np.random.randint(0, 1000000)
env_id = get_env_id(args.env_id, args.use_cbf, args.use_ctrl)
cfg_path = pathlib.Path(__file__).parent / "gym_envs" / "cfgs" / f"{env_id}.yaml"
if not cfg_path.exists():
raise FileNotFoundError(f"Env config file {cfg_path} does not exist.")
with open(cfg_path) as f:
data = yaml.load(f, Loader=yaml.FullLoader)
base_env_id = data["base_env"]
env_params = data["env_params"]
cbf_params = data["cbf_params"]
args.env_id = base_env_id
make_env = make_env_factory(env_id=args.env_id)
crpo.run_crpo(
make_env_fn=make_env,
env_params=env_params,
cbf_params=cbf_params,
args=args,
)