Skip to content

Commit abc448f

Browse files
committed
Tighten _robot_matches_state atol so set_state hint forces reset
The fast-path joint-match check used atol=1e-2, which let a caller's initial_joint_positions hint be silently treated as "already there" when live joints were within 1e-2 of initial — leaving the EE pose up to ~3e-3 off the requested state. State.allclose compares features at 1e-3, so the test then failed reconstruction. Match the State.allclose tolerance. Also pick up trailing yapf reformatting in two approach files.
1 parent 8b6d709 commit abc448f

3 files changed

Lines changed: 19 additions & 15 deletions

File tree

predicators/approaches/agent_planner_approach.py

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -65,9 +65,8 @@ def __init__(self,
6565
# __init__.
6666
if CFG.wait_option_terminate_on_atom_change:
6767
cast( # pylint: disable=protected-access
68-
Any, self._option_model
69-
)._abstract_function = (
70-
lambda s: utils.abstract(s, self._get_all_predicates()))
68+
Any, self._option_model)._abstract_function = (
69+
lambda s: utils.abstract(s, self._get_all_predicates()))
7170
self._online_learning_cycle = 0
7271
self._requests_train_task_idxs: Optional[List[int]] = None
7372
self._run_id = datetime.datetime.now().strftime("%Y%m%d_%H%M%S")

predicators/approaches/bilevel_planning_approach.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -58,9 +58,9 @@ def __init__(self,
5858
# and so predicates invented later are reflected at call time.
5959
if CFG.wait_option_terminate_on_atom_change:
6060
cast( # pylint: disable=protected-access
61-
Any, self._option_model
62-
)._abstract_function = (
63-
lambda s: utils.abstract(s, self._get_current_predicates()))
61+
Any, self._option_model)._abstract_function = (
62+
lambda s: utils.abstract(s, self._get_current_predicates())
63+
)
6464
self._num_calls = 0
6565
self._last_plan: List[_Option] = [] # used if plan WITH sim
6666
self._last_nsrt_plan: List[_GroundNSRT] = [] # plan WITHOUT sim

predicators/envs/pybullet_env.py

Lines changed: 14 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -453,10 +453,10 @@ def _set_state(self, state: State) -> None:
453453
# constraint, so a kept constraint would leave the held
454454
# body behind).
455455
new_held_id = self._held_obj_id_in_state(state)
456-
held_obj_moved = (self._held_obj_id is not None and any(
457-
o.id == self._held_obj_id for o in objects_to_reset))
458-
rebuild_constraint = (full_reset
459-
or new_held_id != self._held_obj_id
456+
held_obj_moved = (self._held_obj_id is not None
457+
and any(o.id == self._held_obj_id
458+
for o in objects_to_reset))
459+
rebuild_constraint = (full_reset or new_held_id != self._held_obj_id
460460
or (self._held_obj_id is not None and
461461
(robot_changed or held_obj_moved)))
462462

@@ -506,9 +506,7 @@ def _set_state(self, state: State) -> None:
506506
logging.warning(
507507
"Could not reconstruct state exactly in reset.")
508508

509-
def _robot_matches_state(self,
510-
state: State,
511-
atol: float = 1e-2) -> bool:
509+
def _robot_matches_state(self, state: State, atol: float = 1e-3) -> bool:
512510
"""True if PyBullet's live robot pose already equals state's.
513511
514512
Compares at the joint level. The EE-quaternion path that
@@ -517,6 +515,13 @@ def _robot_matches_state(self,
517515
fail an EE-pose comparison and trigger a full robot reset on
518516
every simulate() call (visible jitter).
519517
518+
``atol`` matches ``State.allclose``'s feature tolerance: a looser
519+
check would let the fast-path skip a reset even when the live EE
520+
pose differs from the requested state by more than allclose
521+
accepts (e.g. when a caller hands us
522+
``initial_joint_positions`` as a hint and the live joints are
523+
only 1e-2 close).
524+
520525
Returns False when ``state`` has no joint_positions — the only
521526
live caller in that situation is
522527
``_add_pybullet_state_to_tasks``, where forcing a reset is
@@ -572,8 +577,8 @@ def _object_pose_matches_state(self,
572577
def _held_obj_id_in_state(self, state: State) -> Optional[int]:
573578
"""Which PyBullet body id is marked is_held > 0.5 in ``state``.
574579
575-
Returns None if no object is held in ``state``. Mirrors the
576-
per-object logic in _reset_single_object before constraint
580+
Returns None if no object is held in ``state``. Mirrors the per-
581+
object logic in _reset_single_object before constraint
577582
management was hoisted out into _set_state.
578583
"""
579584
for obj in state.data:

0 commit comments

Comments
 (0)