Skip to content

allenact_plugins.ithor_plugin.ithor_environment#

[view_source]

A wrapper for engaging with the THOR environment.

IThorEnvironment#

class IThorEnvironment(object)

[view_source]

Wrapper for the ai2thor controller providing additional functionality and bookkeeping.

See here for comprehensive documentation on AI2-THOR.

Attributes

  • controller: The ai2thor controller.

IThorEnvironment.__init__#

 | __init__(x_display: Optional[str] = None, docker_enabled: bool = False, local_thor_build: Optional[str] = None, visibility_distance: float = VISIBILITY_DISTANCE, fov: float = FOV, player_screen_width: int = 300, player_screen_height: int = 300, quality: str = "Very Low", restrict_to_initially_reachable_points: bool = False, make_agents_visible: bool = True, object_open_speed: float = 1.0, simplify_physics: bool = False) -> None

[view_source]

Initializer.

Parameters

  • x_display : The x display into which to launch ai2thor (possibly necessarily if you are running on a server without an attached display).
  • docker_enabled : Whether or not to run thor in a docker container (useful on a server without an attached display so that you don't have to start an x display).
  • local_thor_build : The path to a local build of ai2thor. This is probably not necessary for your use case and can be safely ignored.
  • visibility_distance : The distance (in meters) at which objects, in the viewport of the agent, are considered visible by ai2thor and will have their "visible" flag be set to True in the metadata.
  • fov : The agent's camera's field of view.
  • player_screen_width : The width resolution (in pixels) of the images returned by ai2thor.
  • player_screen_height : The height resolution (in pixels) of the images returned by ai2thor.
  • quality : The quality at which to render. Possible quality settings can be found in ai2thor._quality_settings.QUALITY_SETTINGS.
  • restrict_to_initially_reachable_points : Whether or not to restrict the agent to locations in ai2thor that were found to be (initially) reachable by the agent (i.e. reachable by the agent after resetting the scene). This can be useful if you want to ensure there are only a fixed set of locations where the agent can go.
  • make_agents_visible : Whether or not the agent should be visible. Most noticable when there are multiple agents or when quality settings are high so that the agent casts a shadow.
  • object_open_speed : How quickly objects should be opened. High speeds mean faster simulation but also mean that opening objects have a lot of kinetic energy and can, possibly, knock other objects away.
  • simplify_physics : Whether or not to simplify physics when applicable. Currently this only simplies object interactions when opening drawers (when simplified, objects within a drawer do not slide around on their own when the drawer is opened or closed, instead they are effectively glued down).

IThorEnvironment.scene_name#

 | @property
 | scene_name() -> str

[view_source]

Current ai2thor scene.

IThorEnvironment.current_frame#

 | @property
 | current_frame() -> np.ndarray

[view_source]

Returns rgb image corresponding to the agent's egocentric view.

IThorEnvironment.last_event#

 | @property
 | last_event() -> ai2thor.server.Event

[view_source]

Last event returned by the controller.

IThorEnvironment.started#

 | @property
 | started() -> bool

[view_source]

Has the ai2thor controller been started.

IThorEnvironment.last_action#

 | @property
 | last_action() -> str

[view_source]

Last action, as a string, taken by the agent.

IThorEnvironment.last_action#

 | @last_action.setter
 | last_action(value: str) -> None

[view_source]

Set the last action taken by the agent.

Doing this is rewriting history, be careful.

IThorEnvironment.last_action_success#

 | @property
 | last_action_success() -> bool

[view_source]

Was the last action taken by the agent a success?

IThorEnvironment.last_action_success#

 | @last_action_success.setter
 | last_action_success(value: bool) -> None

[view_source]

Set whether or not the last action taken by the agent was a success.

Doing this is rewriting history, be careful.

IThorEnvironment.last_action_return#

 | @property
 | last_action_return() -> Any

[view_source]

Get the value returned by the last action (if applicable).

For an example of an action that returns a value, see "GetReachablePositions".

IThorEnvironment.last_action_return#

 | @last_action_return.setter
 | last_action_return(value: Any) -> None

[view_source]

Set the value returned by the last action.

Doing this is rewriting history, be careful.

IThorEnvironment.start#

 | start(scene_name: Optional[str], move_mag: float = 0.25, **kwargs, ,) -> None

[view_source]

Starts the ai2thor controller if it was previously stopped.

After starting, reset will be called with the scene name and move magnitude.

Parameters

  • scene_name : The scene to load.
  • move_mag : The amount of distance the agent moves in a single MoveAhead step.
  • kwargs : additional kwargs, passed to reset.

IThorEnvironment.stop#

 | stop() -> None

[view_source]

Stops the ai2thor controller.

IThorEnvironment.reset#

 | reset(scene_name: Optional[str], move_mag: float = 0.25, **kwargs, ,)

[view_source]

Resets the ai2thor in a new scene.

Resets ai2thor into a new scene and initializes the scene/agents with prespecified settings (e.g. move magnitude).

Parameters

  • scene_name : The scene to load.
  • move_mag : The amount of distance the agent moves in a single MoveAhead step.
  • kwargs : additional kwargs, passed to the controller "Initialize" action.

IThorEnvironment.teleport_agent_to#

 | teleport_agent_to(x: float, y: float, z: float, rotation: float, horizon: float, standing: Optional[bool] = None, force_action: bool = False, only_initially_reachable: Optional[bool] = None, verbose=True, ignore_y_diffs=False) -> None

[view_source]

Helper function teleporting the agent to a given location.

IThorEnvironment.random_reachable_state#

 | random_reachable_state(seed: int = None) -> Dict

[view_source]

Returns a random reachable location in the scene.

IThorEnvironment.randomize_agent_location#

 | randomize_agent_location(seed: int = None, partial_position: Optional[Dict[str, float]] = None) -> Dict

[view_source]

Teleports the agent to a random reachable location in the scene.

IThorEnvironment.object_pixels_in_frame#

 | object_pixels_in_frame(object_id: str, hide_all: bool = True, hide_transparent: bool = False) -> np.ndarray

[view_source]

Return an mask for a given object in the agent's current view.

Parameters

  • object_id : The id of the object.
  • hide_all : Whether or not to hide all other objects in the scene before getting the mask.
  • hide_transparent : Whether or not partially transparent objects are considered to occlude the object.

Returns

A numpy array of the mask.

IThorEnvironment.object_pixels_on_grid#

 | object_pixels_on_grid(object_id: str, grid_shape: Tuple[int, int], hide_all: bool = True, hide_transparent: bool = False) -> np.ndarray

[view_source]

Like object_pixels_in_frame but counts object pixels in a partitioning of the image.

IThorEnvironment.object_in_hand#

 | object_in_hand()

[view_source]

Object metadata for the object in the agent's hand.

IThorEnvironment.initially_reachable_points#

 | @property
 | initially_reachable_points() -> List[Dict[str, float]]

[view_source]

List of {"x": x, "y": y, "z": z} locations in the scene that were reachable after initially resetting.

IThorEnvironment.initially_reachable_points_set#

 | @property
 | initially_reachable_points_set() -> Set[Tuple[float, float]]

[view_source]

Set of (x,z) locations in the scene that were reachable after initially resetting.

IThorEnvironment.currently_reachable_points#

 | @property
 | currently_reachable_points() -> List[Dict[str, float]]

[view_source]

List of {"x": x, "y": y, "z": z} locations in the scene that are currently reachable.

IThorEnvironment.get_agent_location#

 | get_agent_location() -> Dict[str, Union[float, bool]]

[view_source]

Gets agent's location.

IThorEnvironment.step#

 | step(action_dict: Optional[Dict[str, Union[str, int, float, Dict]]] = None, **kwargs: Union[str, int, float, Dict], ,) -> ai2thor.server.Event

[view_source]

Take a step in the ai2thor environment.

IThorEnvironment.position_dist#

 | @staticmethod
 | position_dist(p0: Mapping[str, Any], p1: Mapping[str, Any], ignore_y: bool = False, l1_dist: bool = False) -> float

[view_source]

Distance between two points of the form {"x": x, "y":y, "z":z"}.

IThorEnvironment.rotation_dist#

 | @staticmethod
 | rotation_dist(a: Dict[str, float], b: Dict[str, float])

[view_source]

Distance between rotations.

IThorEnvironment.closest_object_with_properties#

 | closest_object_with_properties(properties: Dict[str, Any]) -> Optional[Dict[str, Any]]

[view_source]

Find the object closest to the agent that has the given properties.

IThorEnvironment.closest_visible_object_of_type#

 | closest_visible_object_of_type(object_type: str) -> Optional[Dict[str, Any]]

[view_source]

Find the object closest to the agent that is visible and has the given type.

IThorEnvironment.closest_object_of_type#

 | closest_object_of_type(object_type: str) -> Optional[Dict[str, Any]]

[view_source]

Find the object closest to the agent that has the given type.

IThorEnvironment.closest_reachable_point_to_position#

 | closest_reachable_point_to_position(position: Dict[str, float]) -> Tuple[Dict[str, float], float]

[view_source]

Of all reachable positions, find the one that is closest to the given location.

IThorEnvironment.all_objects#

 | all_objects() -> List[Dict[str, Any]]

[view_source]

Return all object metadata.

IThorEnvironment.all_objects_with_properties#

 | all_objects_with_properties(properties: Dict[str, Any]) -> List[Dict[str, Any]]

[view_source]

Find all objects with the given properties.

IThorEnvironment.visible_objects#

 | visible_objects() -> List[Dict[str, Any]]

[view_source]

Return all visible objects.