11"""Ground-truth processes for the boil environments."""
22import logging
33from pprint import pformat
4- from typing import Dict , Set , cast
4+ from typing import Dict , Sequence , Set , cast
55
66import numpy as np
77import torch
88
9+ from predicators .envs .pybullet_boil import PyBulletBoilEnv
910from predicators .ground_truth_models import GroundTruthProcessFactory
1011from predicators .settings import CFG
11- from predicators .structs import CausalProcess , DelayDistribution , \
12- EndogenousProcess , ExogenousProcess , LiftedAtom , ParameterizedOption , \
13- Predicate , Type , Variable
12+ from predicators .structs import Array , CausalProcess , DelayDistribution , \
13+ EndogenousProcess , ExogenousProcess , GroundAtom , LiftedAtom , Object , \
14+ ParameterizedOption , Predicate , State , Type , Variable
1415from predicators .utils import ConstantDelay , DiscreteGaussianDelay , \
1516 null_sampler
1617
1718
19+ _BOIL_DROP_Z = 0.49 # table_height (0.4) + jug_handle_height (0.09)
20+
21+
22+ def _pick_sampler (state : State , goal : Set [GroundAtom ],
23+ rng : np .random .Generator ,
24+ objs : Sequence [Object ]) -> Array :
25+ del state , goal , rng , objs
26+ return np .array ([0.0 ], dtype = np .float32 )
27+
28+
29+ def _push_sampler (state : State , goal : Set [GroundAtom ],
30+ rng : np .random .Generator ,
31+ objs : Sequence [Object ]) -> Array :
32+ del state , goal , rng , objs
33+ return np .array ([0.057 , 0.104 , 0.0 , 0.25 ], dtype = np .float32 )
34+
35+
36+ def _place_on_burner_sampler (state : State , goal : Set [GroundAtom ],
37+ rng : np .random .Generator ,
38+ objs : Sequence [Object ]) -> Array :
39+ del goal , rng
40+ # objs = [robot, jug, burner]
41+ burner = objs [2 ]
42+ x = state .get (burner , "x" )
43+ y = state .get (burner , "y" ) - PyBulletBoilEnv .jug_handle_offset
44+ return np .array ([x , y , 0.0 , _BOIL_DROP_Z ], dtype = np .float32 )
45+
46+
47+ def _place_under_faucet_sampler (state : State , goal : Set [GroundAtom ],
48+ rng : np .random .Generator ,
49+ objs : Sequence [Object ]) -> Array :
50+ del goal , rng
51+ # objs = [robot, jug, faucet]
52+ faucet = objs [2 ]
53+ x = state .get (faucet , "x" )
54+ y = (state .get (faucet , "y" ) - PyBulletBoilEnv .jug_handle_offset
55+ - PyBulletBoilEnv .faucet_x_len )
56+ return np .array ([x , y , 0.0 , _BOIL_DROP_Z ], dtype = np .float32 )
57+
58+
59+ def _place_outside_sampler (state : State , goal : Set [GroundAtom ],
60+ rng : np .random .Generator ,
61+ objs : Sequence [Object ]) -> Array :
62+ del state , goal , rng , objs
63+ x = PyBulletBoilEnv .x_mid - 0.15
64+ y = PyBulletBoilEnv .y_mid + 0.10
65+ return np .array ([x , y , 0.0 , _BOIL_DROP_Z ], dtype = np .float32 )
66+
67+
1868class PyBulletBoilGroundTruthProcessFactory (GroundTruthProcessFactory ):
1969 """Ground-truth processes for the boil environment."""
2070
@@ -107,7 +157,7 @@ def get_processes(
107157 pick_jug_from_faucet_process = EndogenousProcess (
108158 "PickJugFromFaucet" , parameters , condition_at_start , set (),
109159 set (), add_effects , delete_effects , delay_distribution ,
110- torch .tensor (1.0 ), option , option_vars , null_sampler )
160+ torch .tensor (1.0 ), option , option_vars , _pick_sampler )
111161 processes .add (pick_jug_from_faucet_process )
112162
113163 # PickJugFromBurner
@@ -134,7 +184,7 @@ def get_processes(
134184 pick_jug_from_burner_process = EndogenousProcess (
135185 "PickJugFromBurner" , parameters , condition_at_start , set (),
136186 set (), add_effects , delete_effects , delay_distribution ,
137- torch .tensor (1.0 ), option , option_vars , null_sampler )
187+ torch .tensor (1.0 ), option , option_vars , _pick_sampler )
138188 processes .add (pick_jug_from_burner_process )
139189
140190 # PickJugFromOutsideFaucetAndBurner
@@ -160,7 +210,7 @@ def get_processes(
160210 "PickJugFromOutsideFaucetAndBurner" , parameters ,
161211 condition_at_start , set (),
162212 set (), add_effects , delete_effects , delay_distribution ,
163- torch .tensor (1.0 ), option , option_vars , null_sampler )
213+ torch .tensor (1.0 ), option , option_vars , _pick_sampler )
164214 processes .add (pick_jug_outside_faucet_burner_process )
165215
166216 # PlaceOnBurner
@@ -187,7 +237,7 @@ def get_processes(
187237 place_on_burner_process = EndogenousProcess (
188238 "PlaceOnBurner" , parameters , condition_at_start , set (),
189239 set (), add_effects , delete_effects , delay_distribution ,
190- torch .tensor (1.0 ), option , option_vars , null_sampler )
240+ torch .tensor (1.0 ), option , option_vars , _place_on_burner_sampler )
191241 processes .add (place_on_burner_process )
192242
193243 # PlaceUnderFaucet
@@ -214,7 +264,8 @@ def get_processes(
214264 place_under_faucet_process = EndogenousProcess (
215265 "PlaceUnderFaucet" , parameters , condition_at_start , set (),
216266 set (), add_effects , delete_effects , delay_distribution ,
217- torch .tensor (1.0 ), option , option_vars , null_sampler )
267+ torch .tensor (1.0 ), option , option_vars ,
268+ _place_under_faucet_sampler )
218269 processes .add (place_under_faucet_process )
219270
220271 # PlaceAtOutsideFaucetAndBurner
@@ -238,7 +289,7 @@ def get_processes(
238289 place_at_outside_faucet_burner_process = EndogenousProcess (
239290 "PlaceOutsideFaucetAndBurner" , parameters , condition_at_start ,
240291 set (), set (), add_effects , delete_effects , delay_distribution ,
241- torch .tensor (1.0 ), option , option_vars , null_sampler )
292+ torch .tensor (1.0 ), option , option_vars , _place_outside_sampler )
242293 processes .add (place_at_outside_faucet_burner_process )
243294
244295 # SwitchFaucetOn
@@ -262,7 +313,7 @@ def get_processes(
262313 switch_faucet_on_process = EndogenousProcess (
263314 "SwitchFaucetOn" , parameters , condition_at_start , set (),
264315 set (), add_effects , delete_effects , delay_distribution ,
265- torch .tensor (1.0 ), option , option_vars , null_sampler )
316+ torch .tensor (1.0 ), option , option_vars , _push_sampler )
266317 processes .add (switch_faucet_on_process )
267318
268319 # SwitchFaucetOff
@@ -286,7 +337,7 @@ def get_processes(
286337 switch_faucet_off_process = EndogenousProcess (
287338 "SwitchFaucetOff" , parameters , condition_at_start , set (),
288339 set (), add_effects , delete_effects , delay_distribution ,
289- torch .tensor (1.0 ), option , option_vars , null_sampler )
340+ torch .tensor (1.0 ), option , option_vars , _push_sampler )
290341 processes .add (switch_faucet_off_process )
291342
292343 # SwitchBurnerOn
@@ -310,7 +361,7 @@ def get_processes(
310361 switch_burner_on_process = EndogenousProcess (
311362 "SwitchBurnerOn" , parameters , condition_at_start , set (),
312363 set (), add_effects , delete_effects , delay_distribution ,
313- torch .tensor (1.0 ), option , option_vars , null_sampler )
364+ torch .tensor (1.0 ), option , option_vars , _push_sampler )
314365 processes .add (switch_burner_on_process )
315366
316367 # SwitchBurnerOff
@@ -334,7 +385,7 @@ def get_processes(
334385 switch_burner_off_process = EndogenousProcess (
335386 "SwitchBurnerOff" , parameters , condition_at_start , set (),
336387 set (), add_effects , delete_effects , delay_distribution ,
337- torch .tensor (1.0 ), option , option_vars , null_sampler )
388+ torch .tensor (1.0 ), option , option_vars , _push_sampler )
338389 processes .add (switch_burner_off_process )
339390
340391 # Noop
0 commit comments