Skip to content

Commit

Permalink
Add ClearTable task
Browse files Browse the repository at this point in the history
  • Loading branch information
Kajiih committed Sep 2, 2024
1 parent 196497e commit 29693ee
Show file tree
Hide file tree
Showing 12 changed files with 250 additions and 220 deletions.
1 change: 0 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -134,7 +134,6 @@ docker/ai2thor_simulator_resources/
old/
rl_thor_1
runs*/
rl_thor
weird_runs/
examples/benchmark/script/

Expand Down
26 changes: 15 additions & 11 deletions src/rl_thor/envs/tasks/_item_prop_complex.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,6 @@

from __future__ import annotations

from typing import Any

from rl_thor.envs.sim_objects import (
COOKING_SOURCES,
HEAT_SOURCES,
Expand All @@ -32,20 +30,21 @@
)
from rl_thor.envs.tasks._item_prop_variable import IndirectIsToggledProp, IsPickedUpProp, IsToggledProp
from rl_thor.envs.tasks.item_prop_interface import (
AI2ThorBasedProp,
FillableLiquid,
ItemVariableProp,
MultiValuePSF,
SingleValuePSF,
TemperatureValue,
)
from rl_thor.envs.tasks.items import AuxItem
from rl_thor.envs.tasks.relations import ContainedInRelation, ReceptacleOfRelation
from rl_thor.envs.tasks.relations import ReceptacleOfRelation, Relation


# %% === Property Definitions ===
# TODO: Support filling with other liquids and contextual interactions
# TODO: Add sink as an auxiliary item and a contained_in relation -> doesn't work, we need "fill_liquid" action
class IsFilledWithLiquidProp(ItemVariableProp[bool, bool]):
class IsFilledWithLiquidProp(AI2ThorBasedProp[bool, bool], ItemVariableProp[bool]):
"""Is filled with liquid item property."""

target_ai2thor_property = SimObjVariableProp.IS_FILLED_WITH_LIQUID
Expand All @@ -63,15 +62,15 @@ class IsFilledWithLiquidProp(ItemVariableProp[bool, bool]):

# TODO: Support filling with other liquids and contextual interactions
# TODO: Add IsFilledWithLiquidProp as auxiliary property
class FillLiquidProp(ItemVariableProp[FillableLiquid, bool]):
class FillLiquidProp(AI2ThorBasedProp[FillableLiquid, bool], ItemVariableProp[bool]):
"""Fill liquid item property."""

target_ai2thor_property = SimObjVariableProp.FILL_LIQUID
candidate_required_prop = CanFillWithLiquidProp(True)


# TODO: Add sink as an auxiliary item and a contained_in relation -> Check if that works
class IsDirtyProp(ItemVariableProp[bool, bool]):
class IsDirtyProp(AI2ThorBasedProp[bool, bool], ItemVariableProp[bool]):
"""Is dirty item property."""

target_ai2thor_property = SimObjVariableProp.IS_DIRTY
Expand All @@ -91,7 +90,7 @@ class IsDirtyProp(ItemVariableProp[bool, bool]):
# TODO: Implement better handling for StoveBurner not being directly toggleable.
# TODO: Implement contextual cooking interactions (e.g. toaster...)
# TODO: Implement cooking with Microwave that requires to be open to put the object inside first.
class IsCookedProp(ItemVariableProp[bool, bool]):
class IsCookedProp(AI2ThorBasedProp[bool, bool], ItemVariableProp[bool]):
"""
Property for cooked items.
Expand All @@ -116,7 +115,7 @@ class IsCookedProp(ItemVariableProp[bool, bool]):
# TODO: Implement contextual temperature interactions (e.g. coffee machine and mugs...)
# TODO: Add the fact that the Microwave has to be open to put the object inside first then closed then turned on.
# TODO: Add the fact that the Fridge has to be open to put the object inside first then closed.
class TemperatureProp(ItemVariableProp[TemperatureValue, Any]):
class TemperatureProp(AI2ThorBasedProp[TemperatureValue, None], ItemVariableProp[None]):
"""
Property for items with a certain temperature.
Expand All @@ -127,7 +126,12 @@ class TemperatureProp(ItemVariableProp[TemperatureValue, Any]):

target_ai2thor_property = SimObjVariableProp.TEMPERATURE

def __init__(self, target_satisfaction_function: SingleValuePSF[TemperatureValue] | TemperatureValue) -> None:
def __init__(
self,
target_satisfaction_function: SingleValuePSF[TemperatureValue] | TemperatureValue,
main_prop: ItemVariableProp | None = None,
main_relation: Relation | None = None,
) -> None:
"""Initialize the Property object."""
if isinstance(target_satisfaction_function, TemperatureValue):
target_satisfaction_function = SingleValuePSF(target_satisfaction_function)
Expand All @@ -154,11 +158,11 @@ def __init__(self, target_satisfaction_function: SingleValuePSF[TemperatureValue
)
})

super().__init__(target_satisfaction_function)
super().__init__(target_satisfaction_function, main_prop=main_prop, main_relation=main_relation)
self.target_satisfaction_function: SingleValuePSF[TemperatureValue]


class BaseIsSlicedProp(ItemVariableProp[bool, bool]):
class BaseIsSlicedProp(AI2ThorBasedProp[bool, bool], ItemVariableProp):
"""Is sliced item property."""

target_ai2thor_property = SimObjVariableProp.IS_SLICED
Expand Down
76 changes: 46 additions & 30 deletions src/rl_thor/envs/tasks/_item_prop_variable.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,9 @@

from __future__ import annotations

from typing import Any
from typing import TYPE_CHECKING

from rl_thor.envs.sim_objects import (
SimObjMetadata,
SimObjVariableProp,
)
from rl_thor.envs.tasks._item_prop_fixed import (
Expand All @@ -21,43 +20,46 @@
ToggleableProp,
)
from rl_thor.envs.tasks.item_prop_interface import (
AI2ThorBasedProp,
EmptyContainerPSF,
ItemVariableProp,
PropAuxProp,
SizeLimitPSF,
)

if TYPE_CHECKING:
from rl_thor.envs.tasks.relations import Relation

# %% === Constants ===
RECEPTACLE_MAX_OBJECTS_PROP_LIMIT = 15 # Up to 15 objects on dining tables; see read_scene_objects_metadata.ipynb


# %% === Property Definitions ===
class VisibleProp(ItemVariableProp[bool, Any]):
class VisibleProp(AI2ThorBasedProp, ItemVariableProp[None]):
"""Visible item property."""

target_ai2thor_property = SimObjVariableProp.VISIBLE


class IsInteractableProp(ItemVariableProp[bool, Any]):
class IsInteractableProp(AI2ThorBasedProp, ItemVariableProp[None]):
"""Is interactable item property."""

target_ai2thor_property = SimObjVariableProp.IS_INTERACTABLE


class IsPickedUpProp(ItemVariableProp[bool, bool]):
class IsPickedUpProp(AI2ThorBasedProp, ItemVariableProp[bool]):
"""Is picked up item property."""

target_ai2thor_property = SimObjVariableProp.IS_PICKED_UP
candidate_required_prop = PickupableProp(True)


class IsPickedUpIfPossibleProp(ItemVariableProp[bool, bool]):
class IsPickedUpIfPossibleProp(AI2ThorBasedProp, ItemVariableProp[bool]):
"""Same as IsPickedUpProp, but doesn't require the item to be pickupable."""

target_ai2thor_property = SimObjVariableProp.IS_PICKED_UP


class IsToggledProp(ItemVariableProp[bool, bool]):
class IsToggledProp(AI2ThorBasedProp, ItemVariableProp[bool]):
"""Is toggled item property."""

target_ai2thor_property = SimObjVariableProp.IS_TOGGLED
Expand All @@ -74,22 +76,22 @@ class IndirectIsToggledProp(IsToggledProp):
candidate_required_prop = None


class IsUsedUpProp(ItemVariableProp[bool, bool]):
class IsUsedUpProp(AI2ThorBasedProp, ItemVariableProp[bool]):
"""Is used up item property."""

target_ai2thor_property = SimObjVariableProp.IS_USED_UP
candidate_required_prop = CanBeUsedUpProp(True)


class IsOpenProp(ItemVariableProp[bool, bool]):
class IsOpenProp(AI2ThorBasedProp, ItemVariableProp[bool]):
"""Is open item property."""

target_ai2thor_property = SimObjVariableProp.IS_OPEN
candidate_required_prop = OpenableProp(True)


# TODO: Test this property
class IsOpenIfPossibleProp(ItemVariableProp[bool, bool]):
class IsOpenIfPossibleProp(AI2ThorBasedProp, ItemVariableProp[bool]):
"""
Same as IsOpenProp, but doesn't require the item to be openable.
Expand All @@ -100,22 +102,22 @@ class IsOpenIfPossibleProp(ItemVariableProp[bool, bool]):
target_ai2thor_property = SimObjVariableProp.IS_OPEN


class OpennessProp(ItemVariableProp[float, bool]):
class OpennessProp(AI2ThorBasedProp, ItemVariableProp[bool]):
"""Openness item property."""

target_ai2thor_property = SimObjVariableProp.OPENNESS
candidate_required_prop = OpenableProp(True)


class IsBrokenProp(ItemVariableProp[bool, bool]):
class IsBrokenProp(AI2ThorBasedProp, ItemVariableProp[bool]):
"""Is broken item property."""

target_ai2thor_property = SimObjVariableProp.IS_BROKEN
candidate_required_prop = BreakableProp(True)
auxiliary_properties = frozenset({PropAuxProp(IsPickedUpIfPossibleProp, True)})
auxiliary_properties_blueprint = frozenset({(IsPickedUpIfPossibleProp, True)})


class ReceptacleClearedProp(ItemVariableProp[bool, bool]):
class ReceptacleClearedProp(AI2ThorBasedProp, ItemVariableProp[bool]):
"""Property of a receptacle being empty."""

target_ai2thor_property = SimObjVariableProp.RECEPTACLE_OBJ_IDS
Expand All @@ -124,44 +126,58 @@ class ReceptacleClearedProp(ItemVariableProp[bool, bool]):
def __init__(
self,
expect_clear: bool = True,
main_prop: ItemVariableProp | None = None,
main_relation: Relation | None = None,
) -> None:
"""
Initialize the Property object.
Args:
expect_clear (bool, optional): Whether the receptacle should be cleared or not.
Defaults to False.
main_prop (ItemVariableProp): For auxiliary properties.
main_relation (Relation): For auxiliary properties.
"""
auxiliary_properties: list[PropAuxProp] = [PropAuxProp(IsOpenIfPossibleProp, True)]
auxiliary_properties += [
PropAuxProp(ReceptacleMaxObjectsProp, i) for i in range(1, RECEPTACLE_MAX_OBJECTS_PROP_LIMIT)
auxiliary_properties_blueprint = [
(IsOpenIfPossibleProp, True),
(ReceptacleMaxObjectsProp, 1),
]
# TODO: Let only PropAuxProp(ReceptacleMaxObjectsProp, RECEPTACLE_MAX_OBJECTS_PROP_LIMIT) once the auxiliary properties of auxiliary properties
self.auxiliary_properties = frozenset(auxiliary_properties)
# auxiliary_properties_blueprint += [
# (ReceptacleMaxObjectsProp, i) for i in range(1, RECEPTACLE_MAX_OBJECTS_PROP_LIMIT)
# ]
self.auxiliary_properties_blueprint = frozenset(auxiliary_properties_blueprint)

super().__init__(EmptyContainerPSF(expect_clear))
super().__init__(EmptyContainerPSF(expect_clear), main_prop=main_prop, main_relation=main_relation)


class ReceptacleMaxObjectsProp(ItemVariableProp[int, bool]):
class ReceptacleMaxObjectsProp(AI2ThorBasedProp, ItemVariableProp[bool]):
"""Property of a receptacle containing fewer than a given number of objects."""

target_ai2thor_property = SimObjVariableProp.RECEPTACLE_OBJ_IDS
candidate_required_prop = ReceptacleProp(True)

def __init__(self, max_objects: int) -> None:
def __init__(
self,
max_objects: int,
main_prop: ItemVariableProp | None = None,
main_relation: Relation | None = None,
) -> None:
"""
Initialize the Property object.
Args:
max_objects (int): The maximum number of objects the receptacle can hold for the
property to be satisfied.
main_prop (ItemVariableProp): For auxiliary properties.
main_relation (Relation): For auxiliary properties.
"""
# auxiliary_properties: list[PropAuxProp] = [PropAuxProp(IsOpenIfPossibleProp, True)]
# if max_objects < RECEPTACLE_MAX_OBJECTS_PROP_LIMIT:
# auxiliary_properties.append(PropAuxProp(ReceptacleMaxObjectsProp, max_objects + 1))
# auxiliary_properties_blueprint: list[tuple[type[ItemVariableProp], Any]] = [(IsOpenIfPossibleProp, True)]
# TODO: Add this when elimination of duplicate auxiliary props is finished
auxiliary_properties_blueprint = []
if max_objects < RECEPTACLE_MAX_OBJECTS_PROP_LIMIT:
auxiliary_properties_blueprint.append((ReceptacleMaxObjectsProp, max_objects + 1))

# self.auxiliary_properties = frozenset(auxiliary_properties)
# TODO: Uncomment this once the auxiliary properties of auxiliary properties are implemented
self.auxiliary_properties_blueprint = frozenset(auxiliary_properties_blueprint)

# super().__init__(SizeLimitPSF(max_elements=max_objects))
ItemVariableProp.__init__(self, SizeLimitPSF(max_elements=max_objects))
super().__init__(SizeLimitPSF(max_elements=max_objects), main_prop=main_prop, main_relation=main_relation)
# ItemVariableProp.__init__(self, SizeLimitPSF(max_elements=max_objects))
2 changes: 2 additions & 0 deletions src/rl_thor/envs/tasks/item_prop.py
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,8 @@
IsToggledProp,
IsUsedUpProp,
OpennessProp,
ReceptacleClearedProp,
ReceptacleMaxObjectsProp,
VisibleProp,
)
from rl_thor.envs.tasks.item_prop_interface import ItemProp
Expand Down
Loading

0 comments on commit 29693ee

Please sign in to comment.