@@ -88,7 +88,7 @@ def __init__(self,
8888 velocities are less than this threshold.
8989 max_attempts_per_prop: The maximum number of rejection sampling attempts
9090 per prop. If a non-colliding pose cannot be found before this limit is
91- reached, a `RuntimeError ` will be raised.
91+ reached, an `EpisodeInitializationError ` will be raised.
9292 settle_physics: (optional) If True, the physics simulation will be
9393 advanced for a few steps to allow the prop positions to settle.
9494 min_settle_physics_time: (optional) When `settle_physics` is True, lower
@@ -170,8 +170,9 @@ def __call__(self, physics, random_state, ignore_contacts_with_entities=None):
170170 subsequently).
171171
172172 Raises:
173- RuntimeError: If `ignore_collisions == False` and a non-colliding prop
174- pose could not be found within `max_attempts_per_prop`.
173+ EpisodeInitializationError: If `ignore_collisions == False` and a
174+ non-colliding prop pose could not be found within
175+ `max_attempts_per_prop`.
175176 """
176177 if ignore_contacts_with_entities is None :
177178 ignore_contacts_with_entities = []
@@ -222,9 +223,12 @@ def place_props():
222223 break
223224
224225 if not success :
225- raise RuntimeError (_REJECTION_SAMPLING_FAILED .format (
226- model_name = prop .mjcf_model .model ,
227- max_attempts = self ._max_attempts_per_prop ))
226+ raise composer .EpisodeInitializationError (
227+ _REJECTION_SAMPLING_FAILED .format (
228+ model_name = prop .mjcf_model .model ,
229+ max_attempts = self ._max_attempts_per_prop ,
230+ )
231+ )
228232
229233 for prop in ignore_contacts_with_entities :
230234 self ._restore_contact_parameters (physics , prop , cached_contact_params )
@@ -237,22 +241,26 @@ def place_and_settle():
237241
238242 # Step physics and check prop states.
239243 original_time = physics .data .time
240- props_isolator = utils .JointStaticIsolator (physics , self ._prop_joints )
241- prop_joints_mj = physics .bind (self ._prop_joints )
242- while physics .data .time - original_time < self ._max_settle_physics_time :
243- with props_isolator :
244- physics .step ()
245- max_qvel = np .max (np .abs (prop_joints_mj .qvel ))
246- max_qacc = np .max (np .abs (prop_joints_mj .qacc ))
247- if (max_qvel < self ._max_qvel_tol ) and (
248- max_qacc < self ._max_qacc_tol ) and (
249- physics .data .time - original_time
250- ) > self ._min_settle_physics_time :
251- return True
252- physics .data .time = original_time
244+ try :
245+ props_isolator = utils .JointStaticIsolator (physics , self ._prop_joints )
246+ prop_joints_mj = physics .bind (self ._prop_joints )
247+ while (
248+ physics .data .time - original_time < self ._max_settle_physics_time
249+ ):
250+ with props_isolator :
251+ physics .step ()
252+ max_qvel = np .max (np .abs (prop_joints_mj .qvel ))
253+ max_qacc = np .max (np .abs (prop_joints_mj .qacc ))
254+ if (max_qvel < self ._max_qvel_tol ) and (
255+ max_qacc < self ._max_qacc_tol ) and (
256+ physics .data .time - original_time
257+ ) > self ._min_settle_physics_time :
258+ return True
259+ finally :
260+ physics .data .time = original_time
253261
254262 if self ._raise_exception_on_settle_failure :
255- raise RuntimeError (
263+ raise composer . EpisodeInitializationError (
256264 _SETTLING_PHYSICS_FAILED .format (
257265 max_attempts = self ._max_settle_physics_attempts ,
258266 max_time = self ._max_settle_physics_time ,
0 commit comments