From ba8d070884ffd518966bf6bc0c62b68cec0b7ea2 Mon Sep 17 00:00:00 2001 From: Ashay Athalye Date: Wed, 18 Sep 2024 21:31:29 -0400 Subject: [PATCH] Fix bugs. --- predicators/envs/spot_env.py | 11 ++++++----- predicators/ground_truth_models/spot_env/nsrts.py | 7 +++++-- predicators/perception/spot_perceiver.py | 7 +++---- predicators/structs.py | 9 +++++++++ 4 files changed, 23 insertions(+), 11 deletions(-) diff --git a/predicators/envs/spot_env.py b/predicators/envs/spot_env.py index c16068e0b..7b606650f 100644 --- a/predicators/envs/spot_env.py +++ b/predicators/envs/spot_env.py @@ -1449,8 +1449,8 @@ def _get_sweeping_surface_for_container(container: Object, _FitsInXY = Predicate("FitsInXY", [_movable_object_type, _base_object_type], _fits_in_xy_classifier) # NOTE: use this predicate instead if you want to disable inside checking. -_FakeInside = Predicate(_Inside.name, _Inside.types, - _create_dummy_predicate_classifier(_Inside)) +# _FakeInside = Predicate(_Inside.name, _Inside.types, +# _create_dummy_predicate_classifier(_Inside)) _NotInsideAnyContainer = Predicate("NotInsideAnyContainer", [_movable_object_type], _not_inside_any_container_classifier) @@ -1524,7 +1524,7 @@ def _get_vlm_query_str(pred_name: str, objects: Sequence[Object]) -> str: lambda o: _get_vlm_query_str("Inside(mess, dustpan)", o)) _ALL_PREDICATES = { - _NEq, _On, _TopAbove, _Inside, _NotInsideAnyContainer, _FitsInXY, + _NEq, _On, _TopAbove, _NotInsideAnyContainer, _FitsInXY, _HandEmpty, _Holding, _NotHolding, _InHandView, _InView, _Reachable, _Blocking, _NotBlocked, _ContainerReadyForSweeping, _IsPlaceable, _IsNotPlaceable, _IsSweeper, _HasFlatTopSurface, _RobotReadyForSweeping, @@ -2592,6 +2592,7 @@ def _create_operators(self) -> Iterator[STRIPSOperator]: parameters = [robot, broom, mess, dustpan] preconds: Set[LiftedAtom] = { LiftedAtom(_Holding, [robot, broom]), + LiftedAtom(_NotHolding, [robot, dustpan]), LiftedAtom(_Touching, [dustpan, mess]) } add_effs: Set[LiftedAtom] = {LiftedAtom(_Inside, [mess, dustpan])} @@ -2603,7 +2604,7 @@ def _create_operators(self) -> Iterator[STRIPSOperator]: # Place(robot, broom) robot = Variable("?robot", _robot_type) broom = Variable("?broom", _movable_object_type) - parameters = [robot, dustpan] + parameters = [robot, broom] preconds: Set[LiftedAtom] = {LiftedAtom(_Holding, [robot, broom])} add_effs: Set[LiftedAtom] = { LiftedAtom(_HandEmpty, [robot]), @@ -2644,7 +2645,7 @@ def __init__(self, use_gui: bool = True) -> None: # Create constant objects. self._spot_object = Object("robot", _robot_type) op_to_name = {o.name: o for o in self._create_operators()} - op_names_to_keep = {"Pick", "Place"} + op_names_to_keep = {"Pick1", "Place1", "Pick2", "Sweep", "Place2"} self._strips_operators = {op_to_name[o] for o in op_names_to_keep} self._train_tasks = [] self._test_tasks = [] diff --git a/predicators/ground_truth_models/spot_env/nsrts.py b/predicators/ground_truth_models/spot_env/nsrts.py index 849854dbc..32930fbbd 100644 --- a/predicators/ground_truth_models/spot_env/nsrts.py +++ b/predicators/ground_truth_models/spot_env/nsrts.py @@ -321,8 +321,11 @@ def get_nsrts(env_name: str, types: Dict[str, Type], "PrepareContainerForSweeping": _prepare_sweeping_sampler, "DropNotPlaceableObject": utils.null_sampler, "MoveToReadySweep": utils.null_sampler, - "Pick": utils.null_sampler, - "Place": utils.null_sampler + "Pick1": utils.null_sampler, + "Place1": utils.null_sampler, + "Pick2": utils.null_sampler, + "Sweep": utils.null_sampler, + "Place2": utils.null_sampler } # If we're doing proper bilevel planning with a simulator, then diff --git a/predicators/perception/spot_perceiver.py b/predicators/perception/spot_perceiver.py index c6178f26f..5d4c63984 100644 --- a/predicators/perception/spot_perceiver.py +++ b/predicators/perception/spot_perceiver.py @@ -642,7 +642,7 @@ def _create_goal(self, state: State, # not yet set. Hopefully one day other cleanups will enable cleaning. assert self._curr_env is not None pred_name_to_pred = {p.name: p for p in self._curr_env.predicates} - VLMOn = pred_name_to_pred["VLMOn"] + # VLMOn = pred_name_to_pred["VLMOn"] Inside = pred_name_to_pred["Inside"] Holding = pred_name_to_pred["Holding"] HandEmpty = pred_name_to_pred["HandEmpty"] @@ -657,7 +657,6 @@ def _create_goal(self, state: State, # GroundAtom(VLMOn, [cup, pan]) } return goal - if goal_description == "put the mess in the dustpan": robot = Object("robot", _robot_type) dustpan = Object("dustpan", _movable_object_type) @@ -666,7 +665,7 @@ def _create_goal(self, state: State, GroundAtom(Inside, [wrappers, dustpan]), GroundAtom(Holding, [robot, dustpan]) } - + return goal raise NotImplementedError("Unrecognized goal description") def update_perceiver_with_action(self, action: Action) -> None: @@ -779,7 +778,7 @@ def step(self, observation: Observation) -> State: state_copy = self._curr_state.copy() print(f"Right before abstract state, skill in obs: {observation.executed_skill}") abstract_state = utils.abstract(state_copy, preds) - import pdb; pdb.set_trace() + # import pdb; pdb.set_trace() self._curr_state.simulator_state["abstract_state"] = abstract_state # Compute all the VLM atoms. `utils.abstract()` only returns the ones that # are True. The remaining ones are the ones that are False. diff --git a/predicators/structs.py b/predicators/structs.py index d1c8e1880..73571f5b7 100644 --- a/predicators/structs.py +++ b/predicators/structs.py @@ -430,6 +430,8 @@ def _str(self) -> str: def ground(self, sub: VarToObjSub) -> GroundAtom: """Create a GroundAtom with a given substitution.""" + # if not set(self.variables).issubset(set(sub.keys())): + # import pdb; pdb.set_trace() assert set(self.variables).issubset(set(sub.keys())) return GroundAtom(self.predicate, [sub[v] for v in self.variables]) @@ -1018,6 +1020,13 @@ def ground(self, objects: Sequence[Object]) -> _GroundNSRT: assert all( o.is_instance(p.type) for o, p in zip(objects, self.parameters)) sub = dict(zip(self.parameters, objects)) + # try: + # preconditions = {atom.ground(sub) for atom in self.preconditions} + # add_effects = {atom.ground(sub) for atom in self.add_effects} + # delete_effects = {atom.ground(sub) for atom in self.delete_effects} + # option_objs = [sub[v] for v in self.option_vars] + # except: + # import pdb; pdb.set_trace() preconditions = {atom.ground(sub) for atom in self.preconditions} add_effects = {atom.ground(sub) for atom in self.add_effects} delete_effects = {atom.ground(sub) for atom in self.delete_effects}