Skip to content

Commit

Permalink
Fix bugs.
Browse files Browse the repository at this point in the history
  • Loading branch information
ashay-bdai committed Sep 19, 2024
1 parent a60692a commit ba8d070
Show file tree
Hide file tree
Showing 4 changed files with 23 additions and 11 deletions.
11 changes: 6 additions & 5 deletions predicators/envs/spot_env.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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,
Expand Down Expand Up @@ -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])}
Expand All @@ -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]),
Expand Down Expand Up @@ -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 = []
Expand Down
7 changes: 5 additions & 2 deletions predicators/ground_truth_models/spot_env/nsrts.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
7 changes: 3 additions & 4 deletions predicators/perception/spot_perceiver.py
Original file line number Diff line number Diff line change
Expand Up @@ -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"]
Expand All @@ -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)
Expand All @@ -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:
Expand Down Expand Up @@ -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.
Expand Down
9 changes: 9 additions & 0 deletions predicators/structs.py
Original file line number Diff line number Diff line change
Expand Up @@ -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])

Expand Down Expand Up @@ -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}
Expand Down

0 comments on commit ba8d070

Please sign in to comment.