forked from google-deepmind/deepmind-research
-
Notifications
You must be signed in to change notification settings - Fork 0
/
task_examples.py
82 lines (69 loc) · 2.82 KB
/
task_examples.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
# Copyright 2020 Deepmind Technologies Limited.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
"""Functions that build representative tasks."""
from dm_control import composer
from dm_control.composer.variation import distributions
from dm_control.locomotion.mocap import loader as mocap_loader
from dm_control.locomotion.walkers import cmu_humanoid
from catch_carry import ball_toss
from catch_carry import warehouse
def build_vision_warehouse(random_state=None):
"""Build canonical 4-pedestal, 2-prop task."""
# Build a position-controlled CMU humanoid walker.
walker = cmu_humanoid.CMUHumanoidPositionControlled(
observable_options={'egocentric_camera': dict(enabled=True)})
# Build the task.
size_distribution = distributions.Uniform(low=0.75, high=1.25)
mass_distribution = distributions.Uniform(low=2, high=7)
prop_resizer = mocap_loader.PropResizer(size_factor=size_distribution,
mass=mass_distribution)
task = warehouse.PhasedBoxCarry(
walker=walker,
num_props=2,
num_pedestals=4,
proto_modifier=prop_resizer,
negative_reward_on_failure_termination=True)
# return the environment
return composer.Environment(
time_limit=15,
task=task,
random_state=random_state,
strip_singleton_obs_buffer_dim=True,
max_reset_attempts=float('inf'))
def build_vision_toss(random_state=None):
"""Build canonical ball tossing task."""
# Build a position-controlled CMU humanoid walker.
walker = cmu_humanoid.CMUHumanoidPositionControlled(
observable_options={'egocentric_camera': dict(enabled=True)})
# Build the task.
size_distribution = distributions.Uniform(low=0.95, high=1.5)
mass_distribution = distributions.Uniform(low=2, high=4)
prop_resizer = mocap_loader.PropResizer(size_factor=size_distribution,
mass=mass_distribution)
task = ball_toss.BallToss(
walker=walker,
proto_modifier=prop_resizer,
negative_reward_on_failure_termination=True,
priority_friction=True,
bucket_offset=3.,
y_range=0.5,
toss_delay=1.5,
randomize_init=True)
# return the environment
return composer.Environment(
time_limit=6,
task=task,
random_state=random_state,
strip_singleton_obs_buffer_dim=True,
max_reset_attempts=float('inf'))