├── baselines
└── lompo
│ └── __init__.py
├── figs
└── envs.png
├── drqbc
├── cfgs
│ ├── task
│ │ ├── online
│ │ │ ├── easy.yaml
│ │ │ ├── hard.yaml
│ │ │ ├── medium.yaml
│ │ │ ├── cup_catch.yaml
│ │ │ ├── finger_spin.yaml
│ │ │ ├── hopper_hop.yaml
│ │ │ ├── cheetah_run.yaml
│ │ │ ├── hopper_stand.yaml
│ │ │ ├── reach_duplo.yaml
│ │ │ ├── reacher_easy.yaml
│ │ │ ├── reacher_hard.yaml
│ │ │ ├── acrobot_swingup.yaml
│ │ │ ├── cartpole_balance.yaml
│ │ │ ├── cartpole_swingup.yaml
│ │ │ ├── finger_turn_easy.yaml
│ │ │ ├── pendulum_swingup.yaml
│ │ │ ├── quadruped_walk.yaml
│ │ │ ├── finger_turn_hard.yaml
│ │ │ ├── cartpole_balance_sparse.yaml
│ │ │ ├── cartpole_swingup_sparse.yaml
│ │ │ ├── walker_run.yaml
│ │ │ ├── quadruped_run.yaml
│ │ │ ├── walker_stand.yaml
│ │ │ ├── walker_walk.yaml
│ │ │ ├── humanoid_run.yaml
│ │ │ ├── humanoid_stand.yaml
│ │ │ └── humanoid_walk.yaml
│ │ └── offline_dmc.yaml
│ ├── algo
│ │ ├── noaug_bc.yaml
│ │ ├── noaug_drqv2.yaml
│ │ ├── bc.yaml
│ │ ├── drqv2.yaml
│ │ └── cql.yaml
│ └── config.yaml
├── LICENSE
└── video.py
├── envs
├── fb_mtenv_dmc
│ ├── common
│ │ ├── visual.xml
│ │ ├── skybox.xml
│ │ ├── materials.xml
│ │ ├── materials_white_floor.xml
│ │ └── __init__.py
│ ├── utils
│ │ ├── __init__.py
│ │ └── parse_amc_test.py
│ ├── wrappers
│ │ ├── __init__.py
│ │ └── action_noise.py
│ ├── lqr.xml
│ ├── LICENSE
│ ├── pendulum.xml
│ ├── cartpole.xml
│ ├── cartpole_cart_mass_1.xml
│ ├── cartpole_cart_mass_10.xml
│ ├── cartpole_cart_mass_2.xml
│ ├── cartpole_cart_mass_3.xml
│ ├── cartpole_cart_mass_4.xml
│ ├── cartpole_cart_mass_5.xml
│ ├── cartpole_cart_mass_6.xml
│ ├── cartpole_cart_mass_7.xml
│ ├── cartpole_cart_mass_8.xml
│ ├── cartpole_cart_mass_9.xml
│ ├── cartpole_pole_mass_1.xml
│ ├── cartpole_pole_mass_10.xml
│ ├── cartpole_pole_mass_2.xml
│ ├── cartpole_pole_mass_3.xml
│ ├── cartpole_pole_mass_4.xml
│ ├── cartpole_pole_mass_5.xml
│ ├── cartpole_pole_mass_6.xml
│ ├── cartpole_pole_mass_7.xml
│ ├── cartpole_pole_mass_8.xml
│ ├── cartpole_pole_mass_9.xml
│ ├── tests
│ │ ├── loader_test.py
│ │ └── lqr_test.py
│ ├── acrobot.xml
│ ├── point_mass.xml
│ ├── ball_in_cup.xml
│ ├── README.md
│ ├── reacher.xml
│ ├── swimmer.xml
│ ├── hopper.xml
│ ├── demos
│ │ └── mocap_demo.py
│ ├── walker.xml
│ ├── walker_len_3.xml
│ ├── walker_friction_1.xml
│ ├── walker_friction_2.xml
│ ├── walker_friction_3.xml
│ ├── walker_len_1.xml
│ ├── walker_len_10.xml
│ ├── walker_len_2.xml
│ ├── walker_len_4.xml
│ ├── walker_len_5.xml
│ ├── walker_len_6.xml
│ ├── walker_len_7.xml
│ ├── walker_len_8.xml
│ ├── walker_len_9.xml
│ ├── walker_friction_10.xml
│ ├── walker_friction_4.xml
│ ├── walker_friction_5.xml
│ ├── walker_friction_6.xml
│ ├── walker_friction_7.xml
│ ├── walker_friction_8.xml
│ ├── walker_friction_9.xml
│ ├── explore.py
│ ├── finger.xml
│ ├── finger_size_1.xml
│ ├── finger_size_10.xml
│ ├── finger_size_2.xml
│ ├── finger_size_3.xml
│ ├── finger_size_4.xml
│ ├── finger_size_5.xml
│ ├── finger_size_6.xml
│ ├── finger_size_7.xml
│ ├── finger_size_8.xml
│ └── finger_size_9.xml
└── distracting_control
│ ├── README.md
│ └── suite_utils.py
├── offlinedv2
├── dreamerv2
│ └── common
│ │ ├── __init__.py
│ │ ├── counter.py
│ │ └── when.py
└── LICENSE
├── CITATION.cff
├── LICENSE
├── conversion_scripts
├── split_hdf5_shards.py
├── hdf5_to_npz.py
└── npz_to_hdf5.py
├── dockerfiles
├── Dockerfile-dv2
└── Dockerfile-drqv2
└── .gitignore
/baselines/lompo/__init__.py:
--------------------------------------------------------------------------------
1 |
--------------------------------------------------------------------------------
/figs/envs.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/conglu1997/v-d4rl/HEAD/figs/envs.png
--------------------------------------------------------------------------------
/drqbc/cfgs/task/online/easy.yaml:
--------------------------------------------------------------------------------
1 | num_train_frames: 1100000
2 | stddev_schedule: 'linear(1.0,0.1,100000)'
--------------------------------------------------------------------------------
/drqbc/cfgs/task/online/hard.yaml:
--------------------------------------------------------------------------------
1 | num_train_frames: 30100000
2 | stddev_schedule: 'linear(1.0,0.1,2000000)'
--------------------------------------------------------------------------------
/drqbc/cfgs/task/online/medium.yaml:
--------------------------------------------------------------------------------
1 | num_train_frames: 3100000
2 | stddev_schedule: 'linear(1.0,0.1,500000)'
--------------------------------------------------------------------------------
/drqbc/cfgs/task/online/cup_catch.yaml:
--------------------------------------------------------------------------------
1 | defaults:
2 | - easy
3 | - _self_
4 |
5 | task_name: cup_catch
6 |
--------------------------------------------------------------------------------
/drqbc/cfgs/task/online/finger_spin.yaml:
--------------------------------------------------------------------------------
1 | defaults:
2 | - easy
3 | - _self_
4 |
5 | task_name: finger_spin
6 |
--------------------------------------------------------------------------------
/drqbc/cfgs/task/online/hopper_hop.yaml:
--------------------------------------------------------------------------------
1 | defaults:
2 | - medium
3 | - _self_
4 |
5 | task_name: hopper_hop
6 |
--------------------------------------------------------------------------------
/drqbc/cfgs/task/online/cheetah_run.yaml:
--------------------------------------------------------------------------------
1 | defaults:
2 | - medium
3 | - _self_
4 |
5 | task_name: cheetah_run
6 |
--------------------------------------------------------------------------------
/drqbc/cfgs/task/online/hopper_stand.yaml:
--------------------------------------------------------------------------------
1 | defaults:
2 | - easy
3 | - _self_
4 |
5 | task_name: hopper_stand
6 |
--------------------------------------------------------------------------------
/drqbc/cfgs/task/online/reach_duplo.yaml:
--------------------------------------------------------------------------------
1 | defaults:
2 | - medium
3 | - _self_
4 |
5 | task_name: reach_duplo
6 |
--------------------------------------------------------------------------------
/drqbc/cfgs/task/online/reacher_easy.yaml:
--------------------------------------------------------------------------------
1 | defaults:
2 | - medium
3 | - _self_
4 |
5 | task_name: reacher_easy
6 |
--------------------------------------------------------------------------------
/drqbc/cfgs/task/online/reacher_hard.yaml:
--------------------------------------------------------------------------------
1 | defaults:
2 | - medium
3 | - _self_
4 |
5 | task_name: reacher_hard
6 |
--------------------------------------------------------------------------------
/drqbc/cfgs/task/online/acrobot_swingup.yaml:
--------------------------------------------------------------------------------
1 | defaults:
2 | - medium
3 | - _self_
4 |
5 | task_name: acrobot_swingup
6 |
--------------------------------------------------------------------------------
/drqbc/cfgs/task/online/cartpole_balance.yaml:
--------------------------------------------------------------------------------
1 | defaults:
2 | - easy
3 | - _self_
4 |
5 | task_name: cartpole_balance
6 |
--------------------------------------------------------------------------------
/drqbc/cfgs/task/online/cartpole_swingup.yaml:
--------------------------------------------------------------------------------
1 | defaults:
2 | - easy
3 | - _self_
4 |
5 | task_name: cartpole_swingup
6 |
--------------------------------------------------------------------------------
/drqbc/cfgs/task/online/finger_turn_easy.yaml:
--------------------------------------------------------------------------------
1 | defaults:
2 | - medium
3 | - _self_
4 |
5 | task_name: finger_turn_easy
--------------------------------------------------------------------------------
/drqbc/cfgs/task/online/pendulum_swingup.yaml:
--------------------------------------------------------------------------------
1 | defaults:
2 | - easy
3 | - _self_
4 |
5 | task_name: pendulum_swingup
6 |
--------------------------------------------------------------------------------
/drqbc/cfgs/task/online/quadruped_walk.yaml:
--------------------------------------------------------------------------------
1 | defaults:
2 | - medium
3 | - _self_
4 |
5 | task_name: quadruped_walk
6 |
--------------------------------------------------------------------------------
/drqbc/cfgs/task/online/finger_turn_hard.yaml:
--------------------------------------------------------------------------------
1 | defaults:
2 | - medium
3 | - _self_
4 |
5 | task_name: finger_turn_hard
6 |
--------------------------------------------------------------------------------
/drqbc/cfgs/task/online/cartpole_balance_sparse.yaml:
--------------------------------------------------------------------------------
1 | defaults:
2 | - easy
3 | - _self_
4 |
5 | task_name: cartpole_balance_sparse
6 |
--------------------------------------------------------------------------------
/drqbc/cfgs/task/online/cartpole_swingup_sparse.yaml:
--------------------------------------------------------------------------------
1 | defaults:
2 | - medium
3 | - _self_
4 |
5 | task_name: cartpole_swingup_sparse
6 |
--------------------------------------------------------------------------------
/drqbc/cfgs/task/online/walker_run.yaml:
--------------------------------------------------------------------------------
1 | defaults:
2 | - medium
3 | - _self_
4 |
5 | task_name: walker_run
6 | nstep: 1
7 | batch_size: 512
--------------------------------------------------------------------------------
/drqbc/cfgs/task/online/quadruped_run.yaml:
--------------------------------------------------------------------------------
1 | defaults:
2 | - medium
3 | - _self_
4 |
5 | task_name: quadruped_run
6 | replay_buffer_size: 100000
--------------------------------------------------------------------------------
/drqbc/cfgs/task/online/walker_stand.yaml:
--------------------------------------------------------------------------------
1 | defaults:
2 | - easy
3 | - _self_
4 |
5 | task_name: walker_stand
6 | nstep: 1
7 | batch_size: 512
8 |
--------------------------------------------------------------------------------
/drqbc/cfgs/task/online/walker_walk.yaml:
--------------------------------------------------------------------------------
1 | defaults:
2 | - easy
3 | - _self_
4 |
5 | task_name: walker_walk
6 | nstep: 1
7 | batch_size: 512
8 |
--------------------------------------------------------------------------------
/drqbc/cfgs/task/online/humanoid_run.yaml:
--------------------------------------------------------------------------------
1 | defaults:
2 | - hard
3 | - _self_
4 |
5 | task_name: humanoid_run
6 | lr: 8e-5
7 | feature_dim: 100
8 |
--------------------------------------------------------------------------------
/drqbc/cfgs/task/online/humanoid_stand.yaml:
--------------------------------------------------------------------------------
1 | defaults:
2 | - hard
3 | - _self_
4 |
5 | task_name: humanoid_stand
6 | lr: 8e-5
7 | feature_dim: 100
8 |
--------------------------------------------------------------------------------
/drqbc/cfgs/task/online/humanoid_walk.yaml:
--------------------------------------------------------------------------------
1 | defaults:
2 | - hard
3 | - _self_
4 |
5 | task_name: humanoid_walk
6 | lr: 8e-5
7 | feature_dim: 100
8 |
--------------------------------------------------------------------------------
/drqbc/cfgs/algo/noaug_bc.yaml:
--------------------------------------------------------------------------------
1 | defaults:
2 | - bc
3 | - _self_
4 |
5 | # experiment
6 | experiment: noaug_bc
7 |
8 | agent:
9 | augmentation:
10 | _target_: drqv2.NoShiftAug
--------------------------------------------------------------------------------
/drqbc/cfgs/algo/noaug_drqv2.yaml:
--------------------------------------------------------------------------------
1 | defaults:
2 | - drqv2
3 | - _self_
4 |
5 | # experiment
6 | experiment: noaug_drqv2
7 |
8 | agent:
9 | augmentation:
10 | _target_: drqv2.NoShiftAug
11 |
--------------------------------------------------------------------------------
/envs/fb_mtenv_dmc/common/visual.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
--------------------------------------------------------------------------------
/envs/fb_mtenv_dmc/common/skybox.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
5 |
6 |
7 |
--------------------------------------------------------------------------------
/drqbc/cfgs/task/offline_dmc.yaml:
--------------------------------------------------------------------------------
1 | defaults:
2 | - _self_
3 |
4 | num_train_frames: 1100000
5 | stddev_schedule: 'linear(1.0,0.1,250000)'
6 | nstep: 1
7 | show_train_stats_every_frames: 2000
8 | lr: 3e-4
9 | replay_buffer_size: 1_000_000
10 | offline: True
11 | task_name: offline_walker_walk_random
12 | offline_dir: ...
13 |
--------------------------------------------------------------------------------
/offlinedv2/dreamerv2/common/__init__.py:
--------------------------------------------------------------------------------
1 | # General tools.
2 | from .config import *
3 | from .counter import *
4 | from .flags import *
5 | from .logger import *
6 | from .when import *
7 |
8 | # RL tools.
9 | from .other import *
10 | from .driver import *
11 | from .envs import *
12 | from .replay import *
13 |
14 | # TensorFlow tools.
15 | from .tfutils import *
16 | from .dists import *
17 | from .nets import *
18 |
--------------------------------------------------------------------------------
/CITATION.cff:
--------------------------------------------------------------------------------
1 | @article{
2 | lu2023challenges,
3 | title={Challenges and Opportunities in Offline Reinforcement Learning from Visual Observations},
4 | author={Cong Lu and Philip J. Ball and Tim G. J. Rudner and Jack Parker-Holder and Michael A Osborne and Yee Whye Teh},
5 | journal={Transactions on Machine Learning Research},
6 | issn={2835-8856},
7 | year={2023},
8 | url={https://openreview.net/forum?id=1QqIfGZOWu},
9 | note={}
10 | }
11 |
--------------------------------------------------------------------------------
/drqbc/cfgs/algo/bc.yaml:
--------------------------------------------------------------------------------
1 | defaults:
2 | - _self_
3 |
4 | # experiment
5 | experiment: bc
6 |
7 | agent:
8 | _target_: bcagent.BCAgent
9 | obs_shape: ??? # to be specified later
10 | action_shape: ??? # to be specified later
11 | device: ${device}
12 | lr: ${lr}
13 | critic_target_tau: 0.01
14 | update_every_steps: 2
15 | use_tb: ${use_tb}
16 | num_expl_steps: 2000
17 | hidden_dim: 1024
18 | feature_dim: ${feature_dim}
19 | stddev_schedule: ${stddev_schedule}
20 | stddev_clip: 0.3
--------------------------------------------------------------------------------
/drqbc/cfgs/algo/drqv2.yaml:
--------------------------------------------------------------------------------
1 | defaults:
2 | - _self_
3 |
4 | # experiment
5 | experiment: drqv2
6 |
7 | agent:
8 | _target_: drqv2.DrQV2Agent
9 | obs_shape: ??? # to be specified later
10 | action_shape: ??? # to be specified later
11 | device: ${device}
12 | lr: ${lr}
13 | critic_target_tau: 0.01
14 | update_every_steps: 2
15 | use_tb: ${use_tb}
16 | num_expl_steps: 2000
17 | hidden_dim: 1024
18 | feature_dim: ${feature_dim}
19 | stddev_schedule: ${stddev_schedule}
20 | stddev_clip: 0.3
21 | offline: ${offline}
22 | bc_weight: ${bc_weight}
23 | use_bc: ${use_bc}
--------------------------------------------------------------------------------
/offlinedv2/dreamerv2/common/counter.py:
--------------------------------------------------------------------------------
1 | import functools
2 |
3 |
4 | @functools.total_ordering
5 | class Counter:
6 | def __init__(self, initial=0):
7 | self.value = initial
8 |
9 | def __int__(self):
10 | return int(self.value)
11 |
12 | def __eq__(self, other):
13 | return int(self) == other
14 |
15 | def __ne__(self, other):
16 | return int(self) != other
17 |
18 | def __lt__(self, other):
19 | return int(self) < other
20 |
21 | def __add__(self, other):
22 | return int(self) + other
23 |
24 | def __mod__(self, other):
25 | return int(self) % other
26 |
27 | def increment(self, amount=1):
28 | self.value += amount
29 |
--------------------------------------------------------------------------------
/drqbc/cfgs/algo/cql.yaml:
--------------------------------------------------------------------------------
1 | defaults:
2 | - _self_
3 |
4 | # experiment
5 | experiment: cql
6 |
7 | agent:
8 | _target_: cql.CQLAgent
9 | obs_shape: ??? # to be specified later
10 | action_shape: ??? # to be specified later
11 | device: ${device}
12 | lr: ${lr}
13 | critic_target_tau: 0.01
14 | update_every_steps: 2
15 | use_tb: ${use_tb}
16 | num_expl_steps: 2000
17 | hidden_dim: 1024
18 | feature_dim: ${feature_dim}
19 | stddev_schedule: ${stddev_schedule}
20 | stddev_clip: 0.3
21 | offline: ${offline}
22 | cql_importance_sample: ${cql_importance_sample}
23 | temp: ${temp}
24 | min_q_weight: ${min_q_weight}
25 | num_random: ${num_random}
26 | with_lagrange: ${with_lagrange}
27 | lagrange_thresh: ${lagrange_thresh}
28 |
--------------------------------------------------------------------------------
/envs/fb_mtenv_dmc/utils/__init__.py:
--------------------------------------------------------------------------------
1 | # Copyright 2017 The dm_control Authors.
2 | #
3 | # Licensed under the Apache License, Version 2.0 (the "License");
4 | # you may not use this file except in compliance with the License.
5 | # You may obtain a copy of the License at
6 | #
7 | # http://www.apache.org/licenses/LICENSE-2.0
8 | #
9 | # Unless required by applicable law or agreed to in writing, software
10 | # distributed under the License is distributed on an "AS IS" BASIS,
11 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 | # See the License for the specific language governing permissions and
13 | # limitations under the License.
14 | # ============================================================================
15 |
16 | """Utility functions used in the control suite."""
17 |
--------------------------------------------------------------------------------
/envs/fb_mtenv_dmc/wrappers/__init__.py:
--------------------------------------------------------------------------------
1 | # Copyright 2018 The dm_control Authors.
2 | #
3 | # Licensed under the Apache License, Version 2.0 (the "License");
4 | # you may not use this file except in compliance with the License.
5 | # You may obtain a copy of the License at
6 | #
7 | # http://www.apache.org/licenses/LICENSE-2.0
8 | #
9 | # Unless required by applicable law or agreed to in writing, software
10 | # distributed under the License is distributed on an "AS IS" BASIS,
11 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 | # See the License for the specific language governing permissions and
13 | # limitations under the License.
14 | # ============================================================================
15 |
16 | """Environment wrappers used to extend or modify environment behaviour."""
17 |
--------------------------------------------------------------------------------
/envs/fb_mtenv_dmc/lqr.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
11 |
12 |
13 |
14 |
15 |
18 |
19 |
20 |
21 |
22 |
23 |
24 |
25 |
26 |
27 |
--------------------------------------------------------------------------------
/offlinedv2/dreamerv2/common/when.py:
--------------------------------------------------------------------------------
1 | class Every:
2 |
3 | def __init__(self, every):
4 | self._every = every
5 | self._last = None
6 |
7 | def __call__(self, step):
8 | step = int(step)
9 | if not self._every:
10 | return False
11 | if self._last is None:
12 | self._last = step
13 | return True
14 | if step >= self._last + self._every:
15 | self._last += self._every
16 | return True
17 | return False
18 |
19 |
20 | class Once:
21 |
22 | def __init__(self):
23 | self._once = True
24 |
25 | def __call__(self):
26 | if self._once:
27 | self._once = False
28 | return True
29 | return False
30 |
31 |
32 | class Until:
33 |
34 | def __init__(self, until):
35 | self._until = until
36 |
37 | def __call__(self, step):
38 | step = int(step)
39 | if not self._until:
40 | return True
41 | return step < self._until
42 |
--------------------------------------------------------------------------------
/offlinedv2/LICENSE:
--------------------------------------------------------------------------------
1 | Copyright (c) 2020 Danijar Hafner
2 |
3 | Permission is hereby granted, free of charge, to any person obtaining a copy
4 | of this software and associated documentation files (the "Software"), to deal
5 | in the Software without restriction, including without limitation the rights
6 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
7 | copies of the Software, and to permit persons to whom the Software is
8 | furnished to do so, subject to the following conditions:
9 |
10 | The above copyright notice and this permission notice shall be included in all
11 | copies or substantial portions of the Software.
12 |
13 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
14 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
15 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
16 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
17 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
18 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
19 | SOFTWARE.
20 |
--------------------------------------------------------------------------------
/drqbc/LICENSE:
--------------------------------------------------------------------------------
1 | MIT License
2 |
3 | Copyright (c) Facebook, Inc. and its affiliates.
4 |
5 | Permission is hereby granted, free of charge, to any person obtaining a copy
6 | of this software and associated documentation files (the "Software"), to deal
7 | in the Software without restriction, including without limitation the rights
8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9 | copies of the Software, and to permit persons to whom the Software is
10 | furnished to do so, subject to the following conditions:
11 |
12 | The above copyright notice and this permission notice shall be included in all
13 | copies or substantial portions of the Software.
14 |
15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21 | SOFTWARE.
22 |
--------------------------------------------------------------------------------
/envs/fb_mtenv_dmc/LICENSE:
--------------------------------------------------------------------------------
1 | MIT License
2 |
3 | Copyright (c) Facebook, Inc. and its affiliates.
4 |
5 | Permission is hereby granted, free of charge, to any person obtaining a copy
6 | of this software and associated documentation files (the "Software"), to deal
7 | in the Software without restriction, including without limitation the rights
8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9 | copies of the Software, and to permit persons to whom the Software is
10 | furnished to do so, subject to the following conditions:
11 |
12 | The above copyright notice and this permission notice shall be included in all
13 | copies or substantial portions of the Software.
14 |
15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21 | SOFTWARE.
--------------------------------------------------------------------------------
/envs/fb_mtenv_dmc/pendulum.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
9 |
10 |
11 |
12 |
13 |
14 |
15 |
16 |
17 |
18 |
19 |
20 |
21 |
22 |
23 |
24 |
25 |
26 |
27 |
--------------------------------------------------------------------------------
/envs/fb_mtenv_dmc/common/materials.xml:
--------------------------------------------------------------------------------
1 |
6 |
7 |
8 |
9 |
10 |
11 |
12 |
13 |
14 |
15 |
16 |
17 |
18 |
19 |
20 |
21 |
22 |
23 |
24 |
--------------------------------------------------------------------------------
/LICENSE:
--------------------------------------------------------------------------------
1 | MIT License
2 |
3 | Copyright (c) 2022 Cong Lu, Philip J. Ball, Tim G. J. Rudner, Jack Parker-Holder, Michael A. Osborne, Yee Whye Teh.
4 |
5 | Permission is hereby granted, free of charge, to any person obtaining a copy
6 | of this software and associated documentation files (the "Software"), to deal
7 | in the Software without restriction, including without limitation the rights
8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9 | copies of the Software, and to permit persons to whom the Software is
10 | furnished to do so, subject to the following conditions:
11 |
12 | The above copyright notice and this permission notice shall be included in all
13 | copies or substantial portions of the Software.
14 |
15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21 | SOFTWARE.
22 |
--------------------------------------------------------------------------------
/envs/fb_mtenv_dmc/common/materials_white_floor.xml:
--------------------------------------------------------------------------------
1 |
6 |
7 |
8 |
9 |
10 |
11 |
12 |
13 |
14 |
15 |
16 |
17 |
18 |
19 |
20 |
21 |
22 |
23 |
24 |
--------------------------------------------------------------------------------
/drqbc/cfgs/config.yaml:
--------------------------------------------------------------------------------
1 | defaults:
2 | - _self_
3 | - task@_global_: offline_dmc
4 | - algo@_global_: drqv2
5 | - override hydra/launcher: submitit_local
6 |
7 | # task settings
8 | frame_stack: 3
9 | action_repeat: 2
10 | discount: 0.99
11 | distracting_mode: null
12 | # train settings
13 | num_seed_frames: 4000
14 | # eval
15 | eval_every_frames: 10000
16 | num_eval_episodes: 10
17 | eval_on_distracting: False
18 | eval_on_multitask: False
19 | eval_save_vid_every_step: 100000
20 | # snapshot
21 | save_snapshot: False
22 | # replay buffer
23 | replay_buffer_size: 1_000_000
24 | replay_buffer_num_workers: 1
25 | nstep: 3
26 | batch_size: 256
27 | # misc
28 | seed: 1
29 | device: cuda
30 | save_video: True
31 | save_train_video: False
32 | use_tb: True
33 | # experiment
34 | experiment: exp
35 | # agent
36 | lr: 1e-4
37 | feature_dim: 50
38 | # offline
39 | offline: False
40 | bc_weight: 2.5
41 | use_bc: True
42 | # cql
43 | cql_importance_sample: False
44 | temp: 1.0
45 | min_q_weight: 1.0
46 | num_random: 10
47 | with_lagrange: False
48 | lagrange_thresh: 0.0
49 |
50 | hydra:
51 | run:
52 | dir: drqv2_data/${experiment}/${task_name}/${now:%Y.%m.%d}/${now:%H%M%S}`
53 | sweep:
54 | dir: ./exp/${now:%Y.%m.%d}/${now:%H%M}_${agent_cfg.experiment}
55 | subdir: ${hydra.job.num}
56 | launcher:
57 | timeout_min: 4300
58 | cpus_per_task: 10
59 | gpus_per_node: 1
60 | tasks_per_node: 1
61 | mem_gb: 160
62 | nodes: 1
63 | submitit_folder: ./exp/${now:%Y.%m.%d}/${now:%H%M%S}_${agent_cfg.experiment}/.slurm
64 |
--------------------------------------------------------------------------------
/envs/fb_mtenv_dmc/common/__init__.py:
--------------------------------------------------------------------------------
1 | # Copyright 2017 The dm_control Authors.
2 | #
3 | # Licensed under the Apache License, Version 2.0 (the "License");
4 | # you may not use this file except in compliance with the License.
5 | # You may obtain a copy of the License at
6 | #
7 | # http://www.apache.org/licenses/LICENSE-2.0
8 | #
9 | # Unless required by applicable law or agreed to in writing, software
10 | # distributed under the License is distributed on an "AS IS" BASIS,
11 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 | # See the License for the specific language governing permissions and
13 | # limitations under the License.
14 | # ============================================================================
15 |
16 | """Functions to manage the common assets for domains."""
17 |
18 | from __future__ import absolute_import
19 | from __future__ import division
20 | from __future__ import print_function
21 |
22 | import os
23 | from dm_control.utils import io as resources
24 |
25 | _SUITE_DIR = os.path.dirname(os.path.dirname(__file__))
26 | _FILENAMES = [
27 | "./common/materials.xml",
28 | "./common/materials_white_floor.xml",
29 | "./common/skybox.xml",
30 | "./common/visual.xml",
31 | ]
32 |
33 | ASSETS = {
34 | filename: resources.GetResource(os.path.join(_SUITE_DIR, filename))
35 | for filename in _FILENAMES
36 | }
37 |
38 |
39 | def read_model(model_filename):
40 | """Reads a model XML file and returns its contents as a string."""
41 | return resources.GetResource(os.path.join(_SUITE_DIR, model_filename))
42 |
--------------------------------------------------------------------------------
/envs/fb_mtenv_dmc/cartpole.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
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 |
--------------------------------------------------------------------------------
/envs/fb_mtenv_dmc/cartpole_cart_mass_1.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
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 |
--------------------------------------------------------------------------------
/envs/fb_mtenv_dmc/cartpole_cart_mass_10.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
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 |
--------------------------------------------------------------------------------
/envs/fb_mtenv_dmc/cartpole_cart_mass_2.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
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 |
--------------------------------------------------------------------------------
/envs/fb_mtenv_dmc/cartpole_cart_mass_3.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
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 |
--------------------------------------------------------------------------------
/envs/fb_mtenv_dmc/cartpole_cart_mass_4.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
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 |
--------------------------------------------------------------------------------
/envs/fb_mtenv_dmc/cartpole_cart_mass_5.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
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 |
--------------------------------------------------------------------------------
/envs/fb_mtenv_dmc/cartpole_cart_mass_6.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
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 |
--------------------------------------------------------------------------------
/envs/fb_mtenv_dmc/cartpole_cart_mass_7.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
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 |
--------------------------------------------------------------------------------
/envs/fb_mtenv_dmc/cartpole_cart_mass_8.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
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 |
--------------------------------------------------------------------------------
/envs/fb_mtenv_dmc/cartpole_cart_mass_9.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
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 |
--------------------------------------------------------------------------------
/envs/fb_mtenv_dmc/cartpole_pole_mass_1.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
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 |
--------------------------------------------------------------------------------
/envs/fb_mtenv_dmc/cartpole_pole_mass_10.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
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 |
--------------------------------------------------------------------------------
/envs/fb_mtenv_dmc/cartpole_pole_mass_2.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
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 |
--------------------------------------------------------------------------------
/envs/fb_mtenv_dmc/cartpole_pole_mass_3.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
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 |
--------------------------------------------------------------------------------
/envs/fb_mtenv_dmc/cartpole_pole_mass_4.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
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 |
--------------------------------------------------------------------------------
/envs/fb_mtenv_dmc/cartpole_pole_mass_5.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
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 |
--------------------------------------------------------------------------------
/envs/fb_mtenv_dmc/cartpole_pole_mass_6.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
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 |
--------------------------------------------------------------------------------
/envs/fb_mtenv_dmc/cartpole_pole_mass_7.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
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 |
--------------------------------------------------------------------------------
/envs/fb_mtenv_dmc/cartpole_pole_mass_8.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
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 |
--------------------------------------------------------------------------------
/envs/fb_mtenv_dmc/cartpole_pole_mass_9.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
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 |
--------------------------------------------------------------------------------
/conversion_scripts/split_hdf5_shards.py:
--------------------------------------------------------------------------------
1 | import pathlib
2 | import numpy as np
3 | import h5py
4 | import argparse
5 |
6 |
7 | def main():
8 | # Include argument parser
9 | parser = argparse.ArgumentParser(description='Split hdf5 shards to smaller.')
10 | parser.add_argument('--input_dir', type=str, required=True,
11 | help='Path to input files')
12 | parser.add_argument('--output_dir', type=str, required=True,
13 | help='Path to output files')
14 | parser.add_argument('--split_size', type=int, default=5)
15 | args = parser.parse_args()
16 |
17 | in_dir = pathlib.Path(args.input_dir)
18 | out_dir = pathlib.Path(args.output_dir)
19 | out_dir.mkdir(parents=True, exist_ok=True)
20 |
21 | counter = 0
22 | for filename in in_dir.glob('*.hdf5'):
23 | print(filename)
24 | with h5py.File(filename, "r") as episodes:
25 | episodes = {k: episodes[k][:] for k in episodes.keys()}
26 | print(episodes['action'].shape[0])
27 |
28 | split_episodes = {k: np.array_split(v, args.split_size) for k, v in episodes.items()}
29 | split_episodes = [{k: v[idx] for k, v in split_episodes.items()} for idx in range(args.split_size)]
30 |
31 | for eps in split_episodes:
32 | with h5py.File(out_dir / f'{counter}.hdf5', 'w') as shard_file:
33 | for k, v in eps.items():
34 | shard_file.create_dataset(k, data=v, compression='gzip')
35 | print(counter)
36 | counter += 1
37 |
38 |
39 | if __name__ == '__main__':
40 | main()
41 |
--------------------------------------------------------------------------------
/envs/fb_mtenv_dmc/tests/loader_test.py:
--------------------------------------------------------------------------------
1 | # Copyright 2017 The dm_control Authors.
2 | #
3 | # Licensed under the Apache License, Version 2.0 (the "License");
4 | # you may not use this file except in compliance with the License.
5 | # You may obtain a copy of the License at
6 | #
7 | # http://www.apache.org/licenses/LICENSE-2.0
8 | #
9 | # Unless required by applicable law or agreed to in writing, software
10 | # distributed under the License is distributed on an "AS IS" BASIS,
11 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 | # See the License for the specific language governing permissions and
13 | # limitations under the License.
14 | # ============================================================================
15 |
16 | """Tests for the dm_control.suite loader."""
17 |
18 | from __future__ import absolute_import
19 | from __future__ import division
20 | from __future__ import print_function
21 |
22 | # Internal dependencies.
23 |
24 | from absl.testing import absltest
25 |
26 | from dm_control import suite
27 | from dm_control.rl import control
28 |
29 |
30 | class LoaderTest(absltest.TestCase):
31 | def test_load_without_kwargs(self):
32 | env = suite.load("cartpole", "swingup")
33 | self.assertIsInstance(env, control.Environment)
34 |
35 | def test_load_with_kwargs(self):
36 | env = suite.load(
37 | "cartpole", "swingup", task_kwargs={"time_limit": 40, "random": 99}
38 | )
39 | self.assertIsInstance(env, control.Environment)
40 |
41 |
42 | class LoaderConstantsTest(absltest.TestCase):
43 | def testSuiteConstants(self):
44 | self.assertNotEmpty(suite.BENCHMARKING)
45 | self.assertNotEmpty(suite.EASY)
46 | self.assertNotEmpty(suite.HARD)
47 | self.assertNotEmpty(suite.EXTRA)
48 |
49 |
50 | if __name__ == "__main__":
51 | absltest.main()
52 |
--------------------------------------------------------------------------------
/envs/fb_mtenv_dmc/acrobot.xml:
--------------------------------------------------------------------------------
1 |
8 |
9 |
10 |
11 |
12 |
13 |
14 |
15 |
16 |
17 |
18 |
21 |
22 |
23 |
24 |
25 |
26 |
27 |
28 |
29 |
30 |
31 |
32 |
33 |
34 |
35 |
36 |
37 |
38 |
39 |
40 |
41 |
42 |
43 |
44 |
--------------------------------------------------------------------------------
/envs/distracting_control/README.md:
--------------------------------------------------------------------------------
1 | # The Distracting Control Suite
2 |
3 | `distracting_control` extends `dm_control` with static or dynamic visual
4 | distractions in the form of changing colors, backgrounds, and camera poses.
5 | Details and experimental results can be found in our
6 | [paper](https://arxiv.org/pdf/2101.02722.pdf).
7 |
8 | ## Requirements and Installation
9 |
10 | * Clone this repository
11 | * `sh run.sh`
12 | * Follow the instructions and install
13 | [dm_control](https://github.com/deepmind/dm_control#requirements-and-installation). Make sure you setup your MuJoCo keys correctly.
14 | * Download the [DAVIS 2017
15 | dataset](https://davischallenge.org/davis2017/code.html). Make sure to select the 2017 TrainVal - Images and Annotations (480p). The training images will be used as distracting backgrounds.
16 |
17 | ## Instructions
18 |
19 | * You can run the `distracting_control_demo` to generate sample images of the
20 | different tasks at different difficulties:
21 |
22 | ```
23 | python distracting_control_demo --davis_path=$HOME/DAVIS/JPEGImages/480p/
24 | --output_dir=/tmp/distrtacting_control_demo
25 | ```
26 | * As seen from the demo to generate an instance of the environment you simply
27 | need to import the suite and use `suite.load` while specifying the
28 | `dm_control` domain and task, then choosing a difficulty and providing the
29 | dataset_path.
30 |
31 | * Note the environment follows the dm_control environment APIs.
32 |
33 | ## Paper
34 |
35 | If you use this code, please cite the accompanying [paper](https://arxiv.org/pdf/2101.02722.pdf) as:
36 |
37 | ```
38 | @article{stone2021distracting,
39 | title={The Distracting Control Suite -- A Challenging Benchmark for Reinforcement Learning from Pixels},
40 | author={Austin Stone and Oscar Ramirez and Kurt Konolige and Rico Jonschkowski},
41 | year={2021},
42 | journal={arXiv preprint arXiv:2101.02722},
43 | }
44 | ```
45 |
46 | ## Disclaimer
47 |
48 | This is not an official Google product.
49 |
--------------------------------------------------------------------------------
/envs/fb_mtenv_dmc/point_mass.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
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 |
--------------------------------------------------------------------------------
/dockerfiles/Dockerfile-dv2:
--------------------------------------------------------------------------------
1 | # FROM MAIN DIR: docker build -t offline-dv2 -f dockerfiles/Dockerfile-dv2 .
2 |
3 | FROM tensorflow/tensorflow:2.6.0-gpu
4 | MAINTAINER Anonymous
5 |
6 | # System packages.
7 | RUN apt-get update && apt-get install -y \
8 | ffmpeg \
9 | libgl1-mesa-dev \
10 | libosmesa6-dev \
11 | python3-pip \
12 | unrar \
13 | wget \
14 | && apt-get clean
15 |
16 | RUN apt-get update && apt-get install -y \
17 | git \
18 | && apt-get clean
19 |
20 | RUN useradd -u <> --create-home user
21 | USER user
22 | WORKDIR /home/user
23 |
24 | RUN wget -q https://repo.anaconda.com/miniconda/Miniconda3-latest-Linux-x86_64.sh && \
25 | bash Miniconda3-latest-Linux-x86_64.sh -b -p miniconda3 && \
26 | rm Miniconda3-latest-Linux-x86_64.sh
27 | ENV PATH /home/user/miniconda3/bin:$PATH
28 |
29 | # MuJoCo
30 | ENV MUJOCO_GL egl
31 | ENV MUJOCO_PY_MUJOCO_PATH /home/user/.mujoco/mujoco210
32 | RUN mkdir -p .mujoco \
33 | && wget https://mujoco.org/download/mujoco210-linux-x86_64.tar.gz -O mujoco.tar.gz \
34 | && tar -xf mujoco.tar.gz -C .mujoco \
35 | && rm mujoco.tar.gz
36 | ENV LD_LIBRARY_PATH /home/user/.mujoco/mujoco210/bin:${LD_LIBRARY_PATH}
37 |
38 | # Python packages.
39 | RUN pip3 install --no-cache-dir 'gym[atari]'
40 | RUN pip3 install --no-cache-dir atari_py
41 | RUN pip3 install --no-cache-dir crafter
42 | RUN pip3 install --no-cache-dir dm_control
43 | RUN pip3 install --no-cache-dir ruamel.yaml
44 | RUN pip3 install --no-cache-dir tensorflow==2.6.0 tensorflow_probability==0.14.1 tensorflow-estimator==2.6.0 tensorboard==2.6.0 keras==2.6.0
45 | RUN pip3 install --no-cache-dir gym-minigrid sklearn
46 |
47 | # Atari ROMS.
48 | RUN wget -L -nv http://www.atarimania.com/roms/Roms.rar && \
49 | unrar x Roms.rar && \
50 | unzip ROMS.zip && \
51 | python3 -m atari_py.import_roms ROMS && \
52 | rm -rf Roms.rar ROMS.zip ROMS
53 |
54 | RUN pip3 install -U 'mujoco-py<2.2,>=2.1'
55 | RUN wget https://www.roboti.us/file/mjkey.txt -O /home/user/.mujoco/mjkey.txt
56 | RUN conda install patchelf
57 |
58 | WORKDIR /vd4rl
59 |
--------------------------------------------------------------------------------
/envs/fb_mtenv_dmc/ball_in_cup.xml:
--------------------------------------------------------------------------------
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 |
--------------------------------------------------------------------------------
/envs/fb_mtenv_dmc/README.md:
--------------------------------------------------------------------------------
1 | # DeepMind Control Suite.
2 |
3 | This submodule contains the domains and tasks described in the
4 | [DeepMind Control Suite tech report](https://arxiv.org/abs/1801.00690).
5 |
6 | ## Quickstart
7 |
8 | ```python
9 | from dm_control import suite
10 | import numpy as np
11 |
12 | # Load one task:
13 | env = suite.load(domain_name="cartpole", task_name="swingup")
14 |
15 | # Iterate over a task set:
16 | for domain_name, task_name in suite.BENCHMARKING:
17 | env = suite.load(domain_name, task_name)
18 |
19 | # Step through an episode and print out reward, discount and observation.
20 | action_spec = env.action_spec()
21 | time_step = env.reset()
22 | while not time_step.last():
23 | action = np.random.uniform(action_spec.minimum,
24 | action_spec.maximum,
25 | size=action_spec.shape)
26 | time_step = env.step(action)
27 | print(time_step.reward, time_step.discount, time_step.observation)
28 | ```
29 |
30 | ## Illustration video
31 |
32 | Below is a video montage of solved Control Suite tasks, with reward
33 | visualisation enabled.
34 |
35 | [](https://www.youtube.com/watch?v=rAai4QzcYbs)
36 |
37 |
38 | ### Quadruped domain [April 2019]
39 |
40 | Roughly based on the 'ant' model introduced by [Schulman et al. 2015](https://arxiv.org/abs/1506.02438). Main modifications to the body are:
41 |
42 | - 4 DoFs per leg, 1 constraining tendon.
43 | - 3 actuators per leg: 'yaw', 'lift', 'extend'.
44 | - Filtered position actuators with timescale of 100ms.
45 | - Sensors include an IMU, force/torque sensors, and rangefinders.
46 |
47 | Four tasks:
48 |
49 | - `walk` and `run`: self-right the body then move forward at a desired speed.
50 | - `escape`: escape a bowl-shaped random terrain (uses rangefinders).
51 | - `fetch`, go to a moving ball and bring it to a target.
52 |
53 | All behaviors in the video below were trained with [Abdolmaleki et al's
54 | MPO](https://arxiv.org/abs/1806.06920).
55 |
56 | [](https://www.youtube.com/watch?v=RhRLjbb7pBE)
57 |
--------------------------------------------------------------------------------
/envs/fb_mtenv_dmc/reacher.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
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 |
--------------------------------------------------------------------------------
/dockerfiles/Dockerfile-drqv2:
--------------------------------------------------------------------------------
1 | # FROM MAIN DIR: docker build -t offline-drqv2 -f dockerfiles/Dockerfile-drqv2 .
2 |
3 | FROM nvidia/cuda:11.3.0-cudnn8-devel-ubuntu18.04
4 | MAINTAINER Anonymous
5 |
6 | ENV DEBIAN_FRONTEND=noninteractive
7 |
8 | RUN apt-get update && apt-get install -y \
9 | vim wget unzip \
10 | libosmesa6-dev libgl1-mesa-glx libgl1-mesa-dev patchelf libglfw3 build-essential
11 |
12 | RUN apt-get update && apt-get install -y --no-install-recommends \
13 | tzdata \
14 | cmake \
15 | git \
16 | curl \
17 | ca-certificates \
18 | libjpeg-dev \
19 | libpng-dev \
20 | libglib2.0-0
21 |
22 | # ZOO PACKAGES
23 | RUN apt-get -y update \
24 | && apt-get -y install \
25 | ffmpeg \
26 | freeglut3-dev \
27 | swig \
28 | xvfb \
29 | libxrandr2 \
30 | && apt-get clean \
31 | && rm -rf /var/lib/apt/lists/*
32 |
33 | # ATARI PACKAGES
34 | RUN apt-get -y update \
35 | && apt-get -y install \
36 | tmux \
37 | libsm6 \
38 | libxext6 \
39 | libxrender-dev \
40 | unrar \
41 | zlib1g \
42 | zlib1g-dev \
43 | && apt-get clean \
44 | && rm -rf /var/lib/apt/lists/*
45 |
46 | # mujoco
47 | RUN mkdir -p /.mujoco \
48 | && wget https://mujoco.org/download/mujoco210-linux-x86_64.tar.gz -O mujoco.tar.gz \
49 | && tar -xf mujoco.tar.gz -C /.mujoco \
50 | && rm mujoco.tar.gz
51 | ENV MUJOCO_PY_MUJOCO_PATH /.mujoco/mujoco210
52 | ENV LD_LIBRARY_PATH /.mujoco/mujoco210/bin:${LD_LIBRARY_PATH}
53 | ENV LD_LIBRARY_PATH /usr/local/cuda/lib64:${LD_LIBRARY_PATH}
54 | ENV MJLIB_PATH /.mujoco/mujoco210/bin/libmujoco210.so
55 |
56 | RUN useradd -u <> --create-home user
57 | USER user
58 | WORKDIR /home/user
59 |
60 | RUN wget -q https://repo.anaconda.com/miniconda/Miniconda3-latest-Linux-x86_64.sh && \
61 | bash Miniconda3-latest-Linux-x86_64.sh -b -p miniconda3 && \
62 | rm Miniconda3-latest-Linux-x86_64.sh
63 | ENV PATH /home/user/miniconda3/bin:$PATH
64 |
65 | RUN pip install --upgrade pip
66 | RUN pip install mujoco_py seaborn
67 | RUN conda install pytorch torchvision torchaudio cudatoolkit=11.3 -c pytorch
68 | RUN pip install absl-py
69 | RUN pip install dm_control
70 | RUN pip install tb-nightly termcolor
71 | RUN pip install imageio imageio-ffmpeg hydra-core hydra-submitit-launcher pandas
72 | RUN pip install ipdb yapf sklearn matplotlib opencv-python
73 |
74 | WORKDIR /vd4rl
75 |
--------------------------------------------------------------------------------
/conversion_scripts/hdf5_to_npz.py:
--------------------------------------------------------------------------------
1 | import datetime
2 | import io
3 | import pathlib
4 | import uuid
5 | import numpy as np
6 | import h5py
7 | import argparse
8 |
9 |
10 | def save_episode(directory, episode):
11 | timestamp = datetime.datetime.now().strftime('%Y%m%dT%H%M%S')
12 | identifier = str(uuid.uuid4().hex)
13 | length = len(episode['action'])
14 | filename = directory / f'{timestamp}-{identifier}-{length}.npz'
15 | with io.BytesIO() as f1:
16 | np.savez_compressed(f1, **episode)
17 | f1.seek(0)
18 | with filename.open('wb') as f2:
19 | f2.write(f1.read())
20 | return filename
21 |
22 |
23 | def main():
24 | # Include argument parser
25 | parser = argparse.ArgumentParser(description='Convert hdf5 files to npz.')
26 | parser.add_argument('--input_dir', type=str, required=True,
27 | help='Path to input files')
28 | parser.add_argument('--output_dir', type=str, required=True,
29 | help='Path to output files')
30 | args = parser.parse_args()
31 |
32 | is_last = np.zeros(501, dtype=bool)
33 | is_last[500] = True
34 | is_first = np.zeros(501, dtype=bool)
35 | is_first[0] = True
36 | is_terminal = np.zeros(501, dtype=bool)
37 |
38 | out_dir = pathlib.Path(args.output_dir)
39 | out_dir.mkdir(parents=True, exist_ok=True)
40 |
41 | filenames = sorted(pathlib.Path(args.input_dir).glob('*.hdf5'))
42 | for filename in filenames:
43 | with h5py.File(filename, "r") as f:
44 | actions = f['action'][:]
45 | observations = f['observation'][:]
46 | rewards = f['reward'][:]
47 | discounts = f['discount'][:]
48 | while len(actions) > 0:
49 | ep = {
50 | 'image': observations[:501].transpose(0, 2, 3, 1),
51 | 'action': actions[:501],
52 | 'reward': rewards[:501],
53 | 'discount': discounts[:501],
54 | 'is_last': is_last,
55 | 'is_first': is_first,
56 | 'is_terminal': is_terminal,
57 | }
58 | actions = actions[501:]
59 | observations = observations[501:]
60 | rewards = rewards[501:]
61 | discounts = discounts[501:]
62 | save_episode(out_dir, ep)
63 |
64 |
65 | if __name__ == '__main__':
66 | main()
67 |
--------------------------------------------------------------------------------
/.gitignore:
--------------------------------------------------------------------------------
1 | # Byte-compiled / optimized / DLL files
2 | __pycache__/
3 | *.py[cod]
4 | *$py.class
5 |
6 | # C extensions
7 | *.so
8 |
9 | # Distribution / packaging
10 | .Python
11 | build/
12 | develop-eggs/
13 | dist/
14 | downloads/
15 | eggs/
16 | .eggs/
17 | lib/
18 | lib64/
19 | parts/
20 | sdist/
21 | var/
22 | wheels/
23 | pip-wheel-metadata/
24 | share/python-wheels/
25 | *.egg-info/
26 | .installed.cfg
27 | *.egg
28 | MANIFEST
29 |
30 | # PyInstaller
31 | # Usually these files are written by a python script from a template
32 | # before PyInstaller builds the exe, so as to inject date/other infos into it.
33 | *.manifest
34 | *.spec
35 |
36 | # Installer logs
37 | pip-log.txt
38 | pip-delete-this-directory.txt
39 |
40 | # Unit test / coverage reports
41 | htmlcov/
42 | .tox/
43 | .nox/
44 | .coverage
45 | .coverage.*
46 | .cache
47 | nosetests.xml
48 | coverage.xml
49 | *.cover
50 | *.py,cover
51 | .hypothesis/
52 | .pytest_cache/
53 |
54 | # Translations
55 | *.mo
56 | *.pot
57 |
58 | # Django stuff:
59 | *.log
60 | local_settings.py
61 | db.sqlite3
62 | db.sqlite3-journal
63 |
64 | # Flask stuff:
65 | instance/
66 | .webassets-cache
67 |
68 | # Scrapy stuff:
69 | .scrapy
70 |
71 | # Sphinx documentation
72 | docs/_build/
73 |
74 | # PyBuilder
75 | target/
76 |
77 | # Jupyter Notebook
78 | .ipynb_checkpoints
79 |
80 | # IPython
81 | profile_default/
82 | ipython_config.py
83 |
84 | # pyenv
85 | .python-version
86 |
87 | # pipenv
88 | # According to pypa/pipenv#598, it is recommended to include Pipfile.lock in version control.
89 | # However, in case of collaboration, if having platform-specific dependencies or dependencies
90 | # having no cross-platform support, pipenv may install dependencies that don't work, or not
91 | # install all needed dependencies.
92 | #Pipfile.lock
93 |
94 | # PEP 582; used by e.g. github.com/David-OConnor/pyflow
95 | __pypackages__/
96 |
97 | # Celery stuff
98 | celerybeat-schedule
99 | celerybeat.pid
100 |
101 | # SageMath parsed files
102 | *.sage.py
103 |
104 | # Environments
105 | .env
106 | .venv
107 | env/
108 | venv/
109 | ENV/
110 | env.bak/
111 | venv.bak/
112 |
113 | # Spyder project settings
114 | .spyderproject
115 | .spyproject
116 |
117 | # Rope project settings
118 | .ropeproject
119 |
120 | # mkdocs documentation
121 | /site
122 |
123 | # mypy
124 | .mypy_cache/
125 | .dmypy.json
126 | dmypy.json
127 |
128 | # Pyre type checker
129 | .pyre/
130 | .idea/
131 |
--------------------------------------------------------------------------------
/drqbc/video.py:
--------------------------------------------------------------------------------
1 | # Copyright (c) Facebook, Inc. and its affiliates. All Rights Reserved.
2 | #
3 | # This source code is licensed under the MIT license found in the
4 | # LICENSE file in the root directory of this source tree.
5 | import cv2
6 | import imageio
7 | import numpy as np
8 |
9 |
10 | class VideoRecorder:
11 | def __init__(self, root_dir, render_size=256, fps=20):
12 | if root_dir is not None:
13 | self.save_dir = root_dir / 'eval_video'
14 | self.save_dir.mkdir(exist_ok=True)
15 | else:
16 | self.save_dir = None
17 |
18 | self.render_size = render_size
19 | self.fps = fps
20 | self.frames = []
21 |
22 | def init(self, env, enabled=True):
23 | self.frames = []
24 | self.enabled = self.save_dir is not None and enabled
25 | self.record(env)
26 |
27 | def record(self, env):
28 | if self.enabled:
29 | if hasattr(env, 'physics'):
30 | frame = env.physics.render(height=self.render_size,
31 | width=self.render_size,
32 | camera_id=0)
33 | else:
34 | frame = env.render()
35 | self.frames.append(frame)
36 |
37 | def save(self, file_name):
38 | if self.enabled:
39 | path = self.save_dir / file_name
40 | imageio.mimsave(str(path), self.frames, fps=self.fps)
41 |
42 |
43 | class TrainVideoRecorder:
44 | def __init__(self, root_dir, render_size=256, fps=20):
45 | if root_dir is not None:
46 | self.save_dir = root_dir / 'train_video'
47 | self.save_dir.mkdir(exist_ok=True)
48 | else:
49 | self.save_dir = None
50 |
51 | self.render_size = render_size
52 | self.fps = fps
53 | self.frames = []
54 |
55 | def init(self, obs, enabled=True):
56 | self.frames = []
57 | self.enabled = self.save_dir is not None and enabled
58 | self.record(obs)
59 |
60 | def record(self, obs):
61 | if self.enabled:
62 | frame = cv2.resize(obs[-3:].transpose(1, 2, 0),
63 | dsize=(self.render_size, self.render_size),
64 | interpolation=cv2.INTER_CUBIC)
65 | self.frames.append(frame)
66 |
67 | def save(self, file_name):
68 | if self.enabled:
69 | path = self.save_dir / file_name
70 | imageio.mimsave(str(path), self.frames, fps=self.fps)
71 |
--------------------------------------------------------------------------------
/envs/fb_mtenv_dmc/utils/parse_amc_test.py:
--------------------------------------------------------------------------------
1 | # Copyright 2017 The dm_control Authors.
2 | #
3 | # Licensed under the Apache License, Version 2.0 (the "License");
4 | # you may not use this file except in compliance with the License.
5 | # You may obtain a copy of the License at
6 | #
7 | # http://www.apache.org/licenses/LICENSE-2.0
8 | #
9 | # Unless required by applicable law or agreed to in writing, software
10 | # distributed under the License is distributed on an "AS IS" BASIS,
11 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 | # See the License for the specific language governing permissions and
13 | # limitations under the License.
14 | # ============================================================================
15 |
16 | """Tests for parse_amc utility."""
17 |
18 | from __future__ import absolute_import
19 | from __future__ import division
20 | from __future__ import print_function
21 |
22 | import os
23 |
24 | # Internal dependencies.
25 |
26 | from absl.testing import absltest
27 | from . import humanoid_CMU
28 | from dm_control.suite.utils import parse_amc
29 |
30 | from dm_control.utils import io as resources
31 |
32 | _TEST_AMC_PATH = resources.GetResourceFilename(
33 | os.path.join(os.path.dirname(__file__), "../demos/zeros.amc")
34 | )
35 |
36 |
37 | class ParseAMCTest(absltest.TestCase):
38 | def test_sizes_of_parsed_data(self):
39 |
40 | # Instantiate the humanoid environment.
41 | env = humanoid_CMU.stand()
42 |
43 | # Parse and convert specified clip.
44 | converted = parse_amc.convert(
45 | _TEST_AMC_PATH, env.physics, env.control_timestep()
46 | )
47 |
48 | self.assertEqual(converted.qpos.shape[0], 63)
49 | self.assertEqual(converted.qvel.shape[0], 62)
50 | self.assertEqual(converted.time.shape[0], converted.qpos.shape[1])
51 | self.assertEqual(converted.qpos.shape[1], converted.qvel.shape[1] + 1)
52 |
53 | # Parse and convert specified clip -- WITH SMALLER TIMESTEP
54 | converted2 = parse_amc.convert(
55 | _TEST_AMC_PATH, env.physics, 0.5 * env.control_timestep()
56 | )
57 |
58 | self.assertEqual(converted2.qpos.shape[0], 63)
59 | self.assertEqual(converted2.qvel.shape[0], 62)
60 | self.assertEqual(converted2.time.shape[0], converted2.qpos.shape[1])
61 | self.assertEqual(converted.qpos.shape[1], converted.qvel.shape[1] + 1)
62 |
63 | # Compare sizes of parsed objects for different timesteps
64 | self.assertEqual(converted.qpos.shape[1] * 2, converted2.qpos.shape[1])
65 |
66 |
67 | if __name__ == "__main__":
68 | absltest.main()
69 |
--------------------------------------------------------------------------------
/envs/fb_mtenv_dmc/swimmer.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
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 |
--------------------------------------------------------------------------------
/envs/fb_mtenv_dmc/hopper.xml:
--------------------------------------------------------------------------------
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 |
--------------------------------------------------------------------------------
/envs/fb_mtenv_dmc/demos/mocap_demo.py:
--------------------------------------------------------------------------------
1 | # Copyright 2017 The dm_control Authors.
2 | #
3 | # Licensed under the Apache License, Version 2.0 (the "License");
4 | # you may not use this file except in compliance with the License.
5 | # You may obtain a copy of the License at
6 | #
7 | # http://www.apache.org/licenses/LICENSE-2.0
8 | #
9 | # Unless required by applicable law or agreed to in writing, software
10 | # distributed under the License is distributed on an "AS IS" BASIS,
11 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 | # See the License for the specific language governing permissions and
13 | # limitations under the License.
14 | # ============================================================================
15 |
16 | """Demonstration of amc parsing for CMU mocap database.
17 |
18 | To run the demo, supply a path to a `.amc` file:
19 |
20 | python mocap_demo --filename='path/to/mocap.amc'
21 |
22 | CMU motion capture clips are available at mocap.cs.cmu.edu
23 | """
24 |
25 | from __future__ import absolute_import
26 | from __future__ import division
27 | from __future__ import print_function
28 |
29 | import time
30 |
31 | # Internal dependencies.
32 |
33 | from absl import app
34 | from absl import flags
35 |
36 | from . import humanoid_CMU
37 | from dm_control.suite.utils import parse_amc
38 |
39 | import matplotlib.pyplot as plt
40 | import numpy as np
41 |
42 | FLAGS = flags.FLAGS
43 | flags.DEFINE_string("filename", None, "amc file to be converted.")
44 | flags.DEFINE_integer(
45 | "max_num_frames", 90, "Maximum number of frames for plotting/playback"
46 | )
47 |
48 |
49 | def main(unused_argv):
50 | env = humanoid_CMU.stand()
51 |
52 | # Parse and convert specified clip.
53 | converted = parse_amc.convert(FLAGS.filename, env.physics, env.control_timestep())
54 |
55 | max_frame = min(FLAGS.max_num_frames, converted.qpos.shape[1] - 1)
56 |
57 | width = 480
58 | height = 480
59 | video = np.zeros((max_frame, height, 2 * width, 3), dtype=np.uint8)
60 |
61 | for i in range(max_frame):
62 | p_i = converted.qpos[:, i]
63 | with env.physics.reset_context():
64 | env.physics.data.qpos[:] = p_i
65 | video[i] = np.hstack(
66 | [
67 | env.physics.render(height, width, camera_id=0),
68 | env.physics.render(height, width, camera_id=1),
69 | ]
70 | )
71 |
72 | tic = time.time()
73 | for i in range(max_frame):
74 | if i == 0:
75 | img = plt.imshow(video[i])
76 | else:
77 | img.set_data(video[i])
78 | toc = time.time()
79 | clock_dt = toc - tic
80 | tic = time.time()
81 | # Real-time playback not always possible as clock_dt > .03
82 | plt.pause(max(0.01, 0.03 - clock_dt)) # Need min display time > 0.0.
83 | plt.draw()
84 | plt.waitforbuttonpress()
85 |
86 |
87 | if __name__ == "__main__":
88 | flags.mark_flag_as_required("filename")
89 | app.run(main)
90 |
--------------------------------------------------------------------------------
/conversion_scripts/npz_to_hdf5.py:
--------------------------------------------------------------------------------
1 | import pathlib
2 | import numpy as np
3 | import h5py
4 | import cv2
5 | import argparse
6 |
7 |
8 | def load_episodes(directory, capacity=None):
9 | # The returned directory from filenames to episodes is guaranteed to be in
10 | # temporally sorted order.
11 | filenames = sorted(directory.glob('*.npz'))
12 | if capacity:
13 | num_steps = 0
14 | num_episodes = 0
15 | for filename in reversed(filenames):
16 | length = int(str(filename).split('-')[-1][:-4])
17 | num_steps += length
18 | num_episodes += 1
19 | if num_steps >= capacity:
20 | break
21 | filenames = filenames[-num_episodes:]
22 | episodes = {}
23 | for filename in filenames:
24 | try:
25 | with filename.open('rb') as f:
26 | episode = np.load(f)
27 | episode = {k: episode[k] for k in episode.keys()}
28 | # Conversion for older versions of npz files.
29 | if 'is_terminal' not in episode:
30 | episode['is_terminal'] = episode['discount'] == 0.
31 | except Exception as e:
32 | print(f'Could not load episode {str(filename)}: {e}')
33 | continue
34 | episodes[str(filename)] = episode
35 | return episodes
36 |
37 |
38 | def main():
39 | # Include argument parser
40 | parser = argparse.ArgumentParser(description='Convert npz files to hdf5.')
41 | parser.add_argument('--input_dir', type=str, required=True,
42 | help='Path to input files')
43 | parser.add_argument('--output_dir', type=str, required=True,
44 | help='Path to output files')
45 | args = parser.parse_args()
46 |
47 | step_type = np.ones(501)
48 | step_type[0] = 0
49 | step_type[500] = 2
50 |
51 | output = {}
52 | episodes = load_episodes(pathlib.Path(args.input_dir))
53 | episodes = list(episodes.values())
54 |
55 | actions = [e['action'] for e in episodes]
56 | discounts = [e['discount'] for e in episodes]
57 | observations = []
58 | for e in episodes:
59 | resized_images = np.empty((501, 84, 84, 3), dtype=e['image'].dtype)
60 | for (k, i) in enumerate(e['image']):
61 | resized_images[k] = cv2.resize(i, dsize=(84, 84), interpolation=cv2.INTER_CUBIC)
62 | observations.append(resized_images.transpose(0, 3, 1, 2))
63 | rewards = [e['reward'] for e in episodes]
64 | step_types = [step_type for _ in episodes]
65 |
66 | output['action'] = np.concatenate(actions)
67 | output['discount'] = np.concatenate(discounts)
68 | output['observation'] = np.concatenate(observations)
69 | output['reward'] = np.concatenate(rewards)
70 | output['step_type'] = np.concatenate(step_types)
71 |
72 | out_dir = pathlib.Path(args.output_dir)
73 | out_dir.mkdir(parents=True, exist_ok=True)
74 |
75 | with h5py.File(out_dir / 'data.hdf5', 'w') as shard_file:
76 | for k, v in output.items():
77 | shard_file.create_dataset(k, data=v, compression='gzip')
78 |
79 |
80 | if __name__ == '__main__':
81 | main()
82 |
--------------------------------------------------------------------------------
/envs/fb_mtenv_dmc/wrappers/action_noise.py:
--------------------------------------------------------------------------------
1 | # Copyright 2018 The dm_control Authors.
2 | #
3 | # Licensed under the Apache License, Version 2.0 (the "License");
4 | # you may not use this file except in compliance with the License.
5 | # You may obtain a copy of the License at
6 | #
7 | # http://www.apache.org/licenses/LICENSE-2.0
8 | #
9 | # Unless required by applicable law or agreed to in writing, software
10 | # distributed under the License is distributed on an "AS IS" BASIS,
11 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 | # See the License for the specific language governing permissions and
13 | # limitations under the License.
14 | # ============================================================================
15 |
16 | """Wrapper control suite environments that adds Gaussian noise to actions."""
17 |
18 | from __future__ import absolute_import
19 | from __future__ import division
20 | from __future__ import print_function
21 |
22 | import dm_env
23 | import numpy as np
24 |
25 |
26 | _BOUNDS_MUST_BE_FINITE = (
27 | "All bounds in `env.action_spec()` must be finite, got: {action_spec}"
28 | )
29 |
30 |
31 | class Wrapper(dm_env.Environment):
32 | """Wraps a control environment and adds Gaussian noise to actions."""
33 |
34 | def __init__(self, env, scale=0.01):
35 | """Initializes a new action noise Wrapper.
36 |
37 | Args:
38 | env: The control suite environment to wrap.
39 | scale: The standard deviation of the noise, expressed as a fraction
40 | of the max-min range for each action dimension.
41 |
42 | Raises:
43 | ValueError: If any of the action dimensions of the wrapped environment are
44 | unbounded.
45 | """
46 | action_spec = env.action_spec()
47 | if not (
48 | np.all(np.isfinite(action_spec.minimum))
49 | and np.all(np.isfinite(action_spec.maximum))
50 | ):
51 | raise ValueError(_BOUNDS_MUST_BE_FINITE.format(action_spec=action_spec))
52 | self._minimum = action_spec.minimum
53 | self._maximum = action_spec.maximum
54 | self._noise_std = scale * (action_spec.maximum - action_spec.minimum)
55 | self._env = env
56 |
57 | def step(self, action):
58 | noisy_action = action + self._env.task.random.normal(scale=self._noise_std)
59 | # Clip the noisy actions in place so that they fall within the bounds
60 | # specified by the `action_spec`. Note that MuJoCo implicitly clips out-of-
61 | # bounds control inputs, but we also clip here in case the actions do not
62 | # correspond directly to MuJoCo actuators, or if there are other wrapper
63 | # layers that expect the actions to be within bounds.
64 | np.clip(noisy_action, self._minimum, self._maximum, out=noisy_action)
65 | return self._env.step(noisy_action)
66 |
67 | def reset(self):
68 | return self._env.reset()
69 |
70 | def observation_spec(self):
71 | return self._env.observation_spec()
72 |
73 | def action_spec(self):
74 | return self._env.action_spec()
75 |
76 | def __getattr__(self, name):
77 | return getattr(self._env, name)
78 |
--------------------------------------------------------------------------------
/envs/fb_mtenv_dmc/walker.xml:
--------------------------------------------------------------------------------
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 |
--------------------------------------------------------------------------------
/envs/fb_mtenv_dmc/walker_len_3.xml:
--------------------------------------------------------------------------------
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 |
--------------------------------------------------------------------------------
/envs/fb_mtenv_dmc/walker_friction_1.xml:
--------------------------------------------------------------------------------
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 |
--------------------------------------------------------------------------------
/envs/fb_mtenv_dmc/walker_friction_2.xml:
--------------------------------------------------------------------------------
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 |
--------------------------------------------------------------------------------
/envs/fb_mtenv_dmc/walker_friction_3.xml:
--------------------------------------------------------------------------------
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 |
--------------------------------------------------------------------------------
/envs/fb_mtenv_dmc/walker_len_1.xml:
--------------------------------------------------------------------------------
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 |
--------------------------------------------------------------------------------
/envs/fb_mtenv_dmc/walker_len_10.xml:
--------------------------------------------------------------------------------
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 |
--------------------------------------------------------------------------------
/envs/fb_mtenv_dmc/walker_len_2.xml:
--------------------------------------------------------------------------------
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 |
--------------------------------------------------------------------------------
/envs/fb_mtenv_dmc/walker_len_4.xml:
--------------------------------------------------------------------------------
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 |
--------------------------------------------------------------------------------
/envs/fb_mtenv_dmc/walker_len_5.xml:
--------------------------------------------------------------------------------
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 |
--------------------------------------------------------------------------------
/envs/fb_mtenv_dmc/walker_len_6.xml:
--------------------------------------------------------------------------------
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 |
--------------------------------------------------------------------------------
/envs/fb_mtenv_dmc/walker_len_7.xml:
--------------------------------------------------------------------------------
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 |
--------------------------------------------------------------------------------
/envs/fb_mtenv_dmc/walker_len_8.xml:
--------------------------------------------------------------------------------
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 |
--------------------------------------------------------------------------------
/envs/fb_mtenv_dmc/walker_len_9.xml:
--------------------------------------------------------------------------------
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 |
--------------------------------------------------------------------------------
/envs/fb_mtenv_dmc/walker_friction_10.xml:
--------------------------------------------------------------------------------
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 |
--------------------------------------------------------------------------------
/envs/fb_mtenv_dmc/walker_friction_4.xml:
--------------------------------------------------------------------------------
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 |
--------------------------------------------------------------------------------
/envs/fb_mtenv_dmc/walker_friction_5.xml:
--------------------------------------------------------------------------------
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 |
--------------------------------------------------------------------------------
/envs/fb_mtenv_dmc/walker_friction_6.xml:
--------------------------------------------------------------------------------
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 |
--------------------------------------------------------------------------------
/envs/fb_mtenv_dmc/walker_friction_7.xml:
--------------------------------------------------------------------------------
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 |
--------------------------------------------------------------------------------
/envs/fb_mtenv_dmc/walker_friction_8.xml:
--------------------------------------------------------------------------------
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 |
--------------------------------------------------------------------------------
/envs/fb_mtenv_dmc/walker_friction_9.xml:
--------------------------------------------------------------------------------
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 |
--------------------------------------------------------------------------------
/envs/distracting_control/suite_utils.py:
--------------------------------------------------------------------------------
1 | # coding=utf-8
2 | # Copyright 2021 The Google Research Authors.
3 | #
4 | # Licensed under the Apache License, Version 2.0 (the "License");
5 | # you may not use this file except in compliance with the License.
6 | # You may obtain a copy of the License at
7 | #
8 | # http://www.apache.org/licenses/LICENSE-2.0
9 | #
10 | # Unless required by applicable law or agreed to in writing, software
11 | # distributed under the License is distributed on an "AS IS" BASIS,
12 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | # See the License for the specific language governing permissions and
14 | # limitations under the License.
15 |
16 | """A collection of MuJoCo-based Reinforcement Learning environments.
17 |
18 | The suite provides a similar API to the original dm_control suite.
19 | Users can configure the distractions on top of the original tasks. The suite is
20 | targeted for loading environments directly with similar configurations as those
21 | used in the original paper. Each distraction wrapper can be used independently
22 | though.
23 | """
24 | import numpy as np
25 |
26 | DIFFICULTY_SCALE = dict(easy=0.1, medium=0.2, hard=0.3)
27 | DIFFICULTY_NUM_VIDEOS = dict(easy=4, medium=8, hard=None)
28 | DEFAULT_BACKGROUND_PATH = "$HOME/davis/"
29 |
30 |
31 | def get_color_kwargs(scale, dynamic):
32 | max_delta = scale
33 | step_std = 0.03 * scale if dynamic else 0.0
34 | return dict(max_delta=max_delta, step_std=step_std)
35 |
36 |
37 | def get_camera_kwargs(domain_name, scale, dynamic):
38 | assert domain_name in ['reacher', 'cartpole', 'finger', 'cheetah',
39 | 'ball_in_cup', 'walker']
40 | assert scale >= 0.0
41 | assert scale <= 1.0
42 | return dict(
43 | vertical_delta=np.pi / 2 * scale,
44 | horizontal_delta=np.pi / 2 * scale,
45 | # Limit camera to -90 / 90 degree rolls.
46 | roll_delta=np.pi / 2. * scale,
47 | vel_std=.1 * scale if dynamic else 0.,
48 | max_vel=.4 * scale if dynamic else 0.,
49 | roll_std=np.pi / 300 * scale if dynamic else 0.,
50 | max_roll_vel=np.pi / 50 * scale if dynamic else 0.,
51 | max_zoom_in_percent=.5 * scale,
52 | max_zoom_out_percent=1.5 * scale,
53 | limit_to_upper_quadrant='reacher' not in domain_name,
54 | )
55 |
56 |
57 | def get_background_kwargs(domain_name,
58 | num_videos,
59 | dynamic,
60 | dataset_path,
61 | dataset_videos=None,
62 | shuffle=False,
63 | video_alpha=1.0):
64 | assert domain_name in ['reacher', 'cartpole', 'finger', 'cheetah',
65 | 'ball_in_cup', 'walker']
66 | if domain_name == 'reacher':
67 | ground_plane_alpha = 0.0
68 | elif domain_name in ['walker', 'cheetah']:
69 | ground_plane_alpha = 1.0
70 | else:
71 | ground_plane_alpha = 0.3
72 |
73 | return dict(
74 | num_videos=num_videos,
75 | video_alpha=video_alpha,
76 | ground_plane_alpha=ground_plane_alpha,
77 | dynamic=dynamic,
78 | dataset_path=dataset_path,
79 | dataset_videos=dataset_videos,
80 | shuffle_buffer_size=100 if shuffle else None,
81 | )
82 |
--------------------------------------------------------------------------------
/envs/fb_mtenv_dmc/explore.py:
--------------------------------------------------------------------------------
1 | # Copyright 2018 The dm_control Authors.
2 | #
3 | # Licensed under the Apache License, Version 2.0 (the "License");
4 | # you may not use this file except in compliance with the License.
5 | # You may obtain a copy of the License at
6 | #
7 | # http://www.apache.org/licenses/LICENSE-2.0
8 | #
9 | # Unless required by applicable law or agreed to in writing, software
10 | # distributed under the License is distributed on an "AS IS" BASIS,
11 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 | # See the License for the specific language governing permissions and
13 | # limitations under the License.
14 | # ============================================================================
15 | """Control suite environments explorer."""
16 |
17 | from __future__ import absolute_import
18 | from __future__ import division
19 | from __future__ import print_function
20 |
21 | from absl import app
22 | from absl import flags
23 | from dm_control import suite
24 | from dm_control.suite.wrappers import action_noise
25 | from six.moves import input
26 |
27 | from dm_control import viewer
28 |
29 |
30 | _ALL_NAMES = [".".join(domain_task) for domain_task in suite.ALL_TASKS]
31 |
32 | flags.DEFINE_enum(
33 | "environment_name",
34 | None,
35 | _ALL_NAMES,
36 | "Optional 'domain_name.task_name' pair specifying the "
37 | "environment to load. If unspecified a prompt will appear to "
38 | "select one.",
39 | )
40 | flags.DEFINE_bool("timeout", True, "Whether episodes should have a time limit.")
41 | flags.DEFINE_bool(
42 | "visualize_reward",
43 | True,
44 | "Whether to vary the colors of geoms according to the " "current reward value.",
45 | )
46 | flags.DEFINE_float(
47 | "action_noise",
48 | 0.0,
49 | "Standard deviation of Gaussian noise to apply to actions, "
50 | "expressed as a fraction of the max-min range for each "
51 | "action dimension. Defaults to 0, i.e. no noise.",
52 | )
53 | FLAGS = flags.FLAGS
54 |
55 |
56 | def prompt_environment_name(prompt, values):
57 | environment_name = None
58 | while not environment_name:
59 | environment_name = input(prompt)
60 | if not environment_name or values.index(environment_name) < 0:
61 | print('"%s" is not a valid environment name.' % environment_name)
62 | environment_name = None
63 | return environment_name
64 |
65 |
66 | def main(argv):
67 | del argv
68 | environment_name = FLAGS.environment_name
69 | if environment_name is None:
70 | print("\n ".join(["Available environments:"] + _ALL_NAMES))
71 | environment_name = prompt_environment_name(
72 | "Please select an environment name: ", _ALL_NAMES
73 | )
74 |
75 | index = _ALL_NAMES.index(environment_name)
76 | domain_name, task_name = suite.ALL_TASKS[index]
77 |
78 | task_kwargs = {}
79 | if not FLAGS.timeout:
80 | task_kwargs["time_limit"] = float("inf")
81 |
82 | def loader():
83 | env = suite.load(
84 | domain_name=domain_name, task_name=task_name, task_kwargs=task_kwargs
85 | )
86 | env.task.visualize_reward = FLAGS.visualize_reward
87 | if FLAGS.action_noise > 0:
88 | env = action_noise.Wrapper(env, scale=FLAGS.action_noise)
89 | return env
90 |
91 | viewer.launch(loader)
92 |
93 |
94 | if __name__ == "__main__":
95 | app.run(main)
96 |
--------------------------------------------------------------------------------
/envs/fb_mtenv_dmc/tests/lqr_test.py:
--------------------------------------------------------------------------------
1 | # Copyright 2017 The dm_control Authors.
2 | #
3 | # Licensed under the Apache License, Version 2.0 (the "License");
4 | # you may not use this file except in compliance with the License.
5 | # You may obtain a copy of the License at
6 | #
7 | # http://www.apache.org/licenses/LICENSE-2.0
8 | #
9 | # Unless required by applicable law or agreed to in writing, software
10 | # distributed under the License is distributed on an "AS IS" BASIS,
11 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 | # See the License for the specific language governing permissions and
13 | # limitations under the License.
14 | # ============================================================================
15 |
16 | """Tests specific to the LQR domain."""
17 |
18 | from __future__ import absolute_import
19 | from __future__ import division
20 | from __future__ import print_function
21 |
22 | import math
23 | import unittest
24 |
25 | # Internal dependencies.
26 | from absl import logging
27 |
28 | from absl.testing import absltest
29 | from absl.testing import parameterized
30 |
31 | from . import lqr
32 | from . import lqr_solver
33 |
34 | import numpy as np
35 | from six.moves import range
36 |
37 |
38 | class LqrTest(parameterized.TestCase):
39 | @parameterized.named_parameters(("lqr_2_1", lqr.lqr_2_1), ("lqr_6_2", lqr.lqr_6_2))
40 | def test_lqr_optimal_policy(self, make_env):
41 | env = make_env()
42 | p, k, beta = lqr_solver.solve(env)
43 | self.assertPolicyisOptimal(env, p, k, beta)
44 |
45 | @parameterized.named_parameters(("lqr_2_1", lqr.lqr_2_1), ("lqr_6_2", lqr.lqr_6_2))
46 | @unittest.skipUnless(
47 | condition=lqr_solver.sp,
48 | reason="scipy is not available, so non-scipy DARE solver is the default.",
49 | )
50 | def test_lqr_optimal_policy_no_scipy(self, make_env):
51 | env = make_env()
52 | old_sp = lqr_solver.sp
53 | try:
54 | lqr_solver.sp = None # Force the solver to use the non-scipy code path.
55 | p, k, beta = lqr_solver.solve(env)
56 | finally:
57 | lqr_solver.sp = old_sp
58 | self.assertPolicyisOptimal(env, p, k, beta)
59 |
60 | def assertPolicyisOptimal(self, env, p, k, beta):
61 | tolerance = 1e-3
62 | n_steps = int(math.ceil(math.log10(tolerance) / math.log10(beta)))
63 | logging.info("%d timesteps for %g convergence.", n_steps, tolerance)
64 | total_loss = 0.0
65 |
66 | timestep = env.reset()
67 | initial_state = np.hstack(
68 | (timestep.observation["position"], timestep.observation["velocity"])
69 | )
70 | logging.info("Measuring total cost over %d steps.", n_steps)
71 | for _ in range(n_steps):
72 | x = np.hstack(
73 | (timestep.observation["position"], timestep.observation["velocity"])
74 | )
75 | # u = k*x is the optimal policy
76 | u = k.dot(x)
77 | total_loss += 1 - (timestep.reward or 0.0)
78 | timestep = env.step(u)
79 |
80 | logging.info("Analytical expected total cost is .5*x^T*p*x.")
81 | expected_loss = 0.5 * initial_state.T.dot(p).dot(initial_state)
82 | logging.info("Comparing measured and predicted costs.")
83 | np.testing.assert_allclose(expected_loss, total_loss, rtol=tolerance)
84 |
85 |
86 | if __name__ == "__main__":
87 | absltest.main()
88 |
--------------------------------------------------------------------------------
/envs/fb_mtenv_dmc/finger.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
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 |
--------------------------------------------------------------------------------
/envs/fb_mtenv_dmc/finger_size_1.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
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 |
--------------------------------------------------------------------------------
/envs/fb_mtenv_dmc/finger_size_10.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
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 |
--------------------------------------------------------------------------------
/envs/fb_mtenv_dmc/finger_size_2.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
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 |
--------------------------------------------------------------------------------
/envs/fb_mtenv_dmc/finger_size_3.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
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 |
--------------------------------------------------------------------------------
/envs/fb_mtenv_dmc/finger_size_4.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
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 |
--------------------------------------------------------------------------------
/envs/fb_mtenv_dmc/finger_size_5.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
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 |
--------------------------------------------------------------------------------
/envs/fb_mtenv_dmc/finger_size_6.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
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 |
--------------------------------------------------------------------------------
/envs/fb_mtenv_dmc/finger_size_7.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
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 |
--------------------------------------------------------------------------------
/envs/fb_mtenv_dmc/finger_size_8.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
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 |
--------------------------------------------------------------------------------
/envs/fb_mtenv_dmc/finger_size_9.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
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 |
--------------------------------------------------------------------------------