forked from danijar/dreamerv3
-
Notifications
You must be signed in to change notification settings - Fork 0
/
example_pybullet.py
85 lines (71 loc) · 2.45 KB
/
example_pybullet.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
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
import warnings
from functools import partial as bind
import os
os.environ['MUJOCO_GL'] = 'egl'
import dreamerv3
import embodied
warnings.filterwarnings('ignore', '.*truncated to dtype int32.*')
def main():
config = embodied.Config(dreamerv3.Agent.configs['defaults'])
config = config.update({
**dreamerv3.Agent.configs['size12m'],
'logdir': f'{os.getcwd()}/logdir/{embodied.timestamp()}-example',
'run.train_ratio': 512,
'run.steps': 1e7,
'enc.spaces': 'state|image',
'dec.spaces': 'state|image',
'run.script': 'train',
'replay_length': 65,
'replay_length_eval': 33,
'run.log_video_fps': 50,
})
config = embodied.Flags(config).parse()
print('Logdir:', config.logdir)
logdir = embodied.Path(config.logdir)
logdir.mkdir()
config.save(logdir / 'config.yaml')
def make_agent(config):
env = make_env(config)
agent = dreamerv3.Agent(env.obs_space, env.act_space, config)
env.close()
return agent
def make_logger(config):
logdir = embodied.Path(config.logdir)
return embodied.Logger(embodied.Counter(), [
embodied.logger.TerminalOutput(config.filter),
embodied.logger.JSONLOutput(logdir, 'metrics.jsonl'),
embodied.logger.JSONLOutput(logdir, 'scores.jsonl', 'episode/score'),
embodied.logger.TensorBoardOutput(logdir, config.run.log_video_fps, config.tensorboard_videos),
# embodied.logger.WandbOutput(logdir.name, config=config),
])
def make_replay(config):
return embodied.replay.Replay(
length=config.batch_length,
capacity=config.replay.size,
directory=embodied.Path(config.logdir) / 'replay',
online=config.replay.online)
def make_env(config, env_id=0):
import sys
sys.path.append("../")
from testing.envs.solo12_pybullet import Solo12Env
#from embodied.envs.solo12_v0 import Solo12Env
from embodied.envs import from_gym
env = Solo12Env()
env = from_gym.FromGym(env, obs_key='image')
env = dreamerv3.wrap_env(env, config)
return env
args = embodied.Config(
**config.run,
logdir=config.logdir,
batch_size=config.batch_size,
batch_length=config.batch_length,
batch_length_eval=config.batch_length_eval,
replay_context=config.replay_context,
)
embodied.run.train(
bind(make_agent, config),
bind(make_replay, config),
bind(make_env, config),
bind(make_logger, config), args)
if __name__ == '__main__':
main()