From 2f0661d14d031bfcd7a071746b8691d39b075a1a Mon Sep 17 00:00:00 2001 From: Winson Han Date: Fri, 2 Aug 2024 14:29:13 -0700 Subject: [PATCH] running formatting --- ai2thor/benchmarking.py | 1 - ai2thor/build.py | 2 -- ai2thor/docker.py | 2 -- ai2thor/downloader.py | 1 - ai2thor/hooks/metadata_hook.py | 3 ++- ai2thor/interact.py | 2 -- ai2thor/offline_controller.py | 3 --- ai2thor/platform.py | 3 --- ai2thor/robot_controller.py | 1 - ai2thor/server.py | 8 -------- ai2thor/tests/test_controller.py | 8 -------- ai2thor/tests/test_event.py | 1 - ai2thor/tests/test_fifo_server.py | 3 --- ai2thor/tests/test_server.py | 5 ----- ai2thor/tests/test_unity.py | 7 ------- ai2thor/tests/test_unity_procedural.py | 1 - ai2thor/util/depth.py | 1 - ai2thor/util/scene_yaml_edit.py | 1 - ai2thor/util/trials.py | 6 ++++-- ai2thor/video_controller.py | 1 - ai2thor/wsgi_server.py | 5 ----- arm_test/base.py | 1 - arm_test/check_determinism_different_machines.py | 1 - ...heck_determinism_event_collision_different_machines.py | 2 -- 24 files changed, 6 insertions(+), 63 deletions(-) diff --git a/ai2thor/benchmarking.py b/ai2thor/benchmarking.py index 9b916aa5a0..bef7669d56 100644 --- a/ai2thor/benchmarking.py +++ b/ai2thor/benchmarking.py @@ -451,7 +451,6 @@ def __create_experiments(self): return experiment_list def benchmark(self, action_map={}): - env, controller_params = self.__init_env() experiment_list = self.__create_experiments() hostname = "" diff --git a/ai2thor/build.py b/ai2thor/build.py index 5e8a36c15e..dc426d2f09 100644 --- a/ai2thor/build.py +++ b/ai2thor/build.py @@ -109,7 +109,6 @@ def base_dir(self): class Build(object): def __init__(self, platform, commit_id, include_private_scenes, releases_dir=None): - if type(platform) is str: if platform in STR_PLATFORM_MAP: platform = STR_PLATFORM_MAP[platform] @@ -126,7 +125,6 @@ def __init__(self, platform, commit_id, include_private_scenes, releases_dir=Non self.tmp_dir = os.path.normpath(self.releases_dir + "/../tmp") def download(self): - makedirs(self.releases_dir) makedirs(self.tmp_dir) diff --git a/ai2thor/docker.py b/ai2thor/docker.py index c8bd470382..a09456623c 100644 --- a/ai2thor/docker.py +++ b/ai2thor/docker.py @@ -77,7 +77,6 @@ def nvidia_version(): def generate_dockerfile(tag): - driver_url = "http://us.download.nvidia.com/XFree86/Linux-x86_64/{version}/NVIDIA-Linux-x86_64-{version}.run".format( version=nvidia_version() ) @@ -127,7 +126,6 @@ def kill_container(container_id): def build_image(): - version = nvidia_version() image_name = "ai2thor/ai2thor-nvidia-%s:%s" % (version, COMMIT_ID) diff --git a/ai2thor/downloader.py b/ai2thor/downloader.py index 6c9d97cad7..ab9a0a46eb 100644 --- a/ai2thor/downloader.py +++ b/ai2thor/downloader.py @@ -9,7 +9,6 @@ def download(url, sha256_digest, include_private_scenes=False): - auth = None if include_private_scenes: auth = ai2thor.build.boto_auth() diff --git a/ai2thor/hooks/metadata_hook.py b/ai2thor/hooks/metadata_hook.py index 5f08d631ad..2225c1721e 100644 --- a/ai2thor/hooks/metadata_hook.py +++ b/ai2thor/hooks/metadata_hook.py @@ -10,4 +10,5 @@ class MetadataHook(Protocol): - def __call__(self, metadata: Dict[str, Any], controller: "Controller"): ... + def __call__(self, metadata: Dict[str, Any], controller: "Controller"): + ... diff --git a/ai2thor/interact.py b/ai2thor/interact.py index 8e0593d7dd..341b39e894 100644 --- a/ai2thor/interact.py +++ b/ai2thor/interact.py @@ -91,7 +91,6 @@ def interact( color_frame=False, metadata=False, ): - if not sys.stdout.isatty(): raise RuntimeError("controller.interact() must be run from a terminal") @@ -198,7 +197,6 @@ def add_command(cc, action, **args): print(" ".join(command_info)) def next_interact_command(self): - current_buffer = "" while True: commands = self._interact_commands diff --git a/ai2thor/offline_controller.py b/ai2thor/offline_controller.py index 32ec6c1e69..48cda4c7de 100644 --- a/ai2thor/offline_controller.py +++ b/ai2thor/offline_controller.py @@ -18,7 +18,6 @@ class Controller(object): def __init__(self, base_dir, grid_size=0.25): - self.grid_size = grid_size self.base_dir = base_dir if grid_size < 0.25: @@ -153,7 +152,6 @@ def inc(self): def write_frame(event, base_dir, scene_name, frame_name): - events_dir = "%s/%s/events" % (base_dir, scene_name) met_dir = "%s/%s/metadata" % (base_dir, scene_name) os.makedirs(met_dir, exist_ok=True) @@ -167,7 +165,6 @@ def write_frame(event, base_dir, scene_name, frame_name): def look_up_down_write(controller, base_dir, fc, scene_name): - fc.inc() write_frame(controller.step(action="LookUp"), base_dir, scene_name, fc.counter) fc.inc() diff --git a/ai2thor/platform.py b/ai2thor/platform.py index f70557e407..f3d3bcb951 100644 --- a/ai2thor/platform.py +++ b/ai2thor/platform.py @@ -16,7 +16,6 @@ def __init__(self, system, width, height, x_display, headless): class BasePlatform: - enabled = True @classmethod @@ -65,7 +64,6 @@ def dependency_instructions(cls, request): @classmethod def _select_x_display(cls, width, height): - valid_displays = cls._valid_x_displays(width, height) if valid_displays: return valid_displays[0] @@ -173,7 +171,6 @@ def executable_path(cls, base_dir, name): @classmethod def parse_plist(cls, base_dir, name): - plist_path = os.path.join(base_dir, name + ".app", "Contents/Info.plist") with open(plist_path) as f: diff --git a/ai2thor/robot_controller.py b/ai2thor/robot_controller.py index c96fe2c0be..9e11580b6f 100644 --- a/ai2thor/robot_controller.py +++ b/ai2thor/robot_controller.py @@ -83,7 +83,6 @@ def reset(self, scene_name=None): return self.last_event def step(self, action=None, **action_args): - if type(action) is dict: action = copy.deepcopy(action) # prevent changes from leaking else: diff --git a/ai2thor/server.py b/ai2thor/server.py index 46e5f09b10..047e5cecdd 100644 --- a/ai2thor/server.py +++ b/ai2thor/server.py @@ -28,12 +28,10 @@ def default(self, obj): class LazyMask(Mapping): - def __contains__(self, key: object) -> bool: return self.mask(cast(str, key)) is not None def __getitem__(self, key: str): - m = self.mask(key) if m is None: @@ -59,7 +57,6 @@ def __len__(self): class LazyInstanceSegmentationMasks(LazyMask): - def __init__(self, image_ids_data: bytes, metadata: dict): self._masks: Dict[str, np.ndarray] = {} self._loaded = False @@ -213,7 +210,6 @@ def mask(self, key: str, default: Optional[np.ndarray] = None) -> Optional[np.nd class LazyDetections2D(Mapping): def __init__(self, instance_masks: LazyInstanceSegmentationMasks): - self.instance_masks = instance_masks def mask_bounding_box(self, mask: np.ndarray) -> Optional[Tuple[int, int, int, int]]: @@ -239,7 +235,6 @@ def __eq__(self, other: object): class LazyInstanceDetections2D(LazyDetections2D): - def __init__(self, instance_masks: LazyInstanceSegmentationMasks): super().__init__(instance_masks) self._detections2d: Dict[str, Optional[Tuple[int, int, int, int]]] = {} @@ -282,9 +277,7 @@ def __iter__(self): class LazyClassDetections2D(LazyDetections2D): - def __init__(self, instance_masks: LazyInstanceSegmentationMasks): - super().__init__(instance_masks) self._loaded = False self._detections2d: Dict[str, Optional[Tuple[Tuple[int, int, int, int], ...]]] = {} @@ -533,7 +526,6 @@ def objects_by_type(self, object_type): return [obj for obj in self.metadata["objects"] if obj["objectType"] == object_type] def process_colors_ids(self, image_ids_data): - self.instance_masks = LazyInstanceSegmentationMasks(image_ids_data, self.metadata) self.class_masks = LazyClassSegmentationMasks(self.instance_masks) self.class_detections2D = LazyClassDetections2D(self.instance_masks) diff --git a/ai2thor/tests/test_controller.py b/ai2thor/tests/test_controller.py index 71b38c9515..abca08106a 100644 --- a/ai2thor/tests/test_controller.py +++ b/ai2thor/tests/test_controller.py @@ -103,7 +103,6 @@ def empty(self): def controller(**args): - # delete display so the tests can run on Linux if "DISPLAY" in os.environ: del os.environ["DISPLAY"] @@ -171,7 +170,6 @@ def test_linux_explicit_xdisplay(mocker): def test_linux_invalid_linux64_invalid_cr(mocker): - mocker.patch("ai2thor.controller.platform_system", fake_linux_system) mocker.patch("ai2thor.controller.ai2thor.build.Build.exists", fake_exists) mocker.patch("ai2thor.controller.ai2thor.build.Build.download", noop_download) @@ -195,7 +193,6 @@ def test_linux_invalid_linux64_invalid_cr(mocker): def test_linux_invalid_linux64_valid_cr(mocker): - mocker.patch("ai2thor.controller.platform_system", fake_linux_system) mocker.patch("ai2thor.controller.ai2thor.build.Build.exists", fake_exists) mocker.patch("ai2thor.controller.ai2thor.build.Build.download", noop_download) @@ -215,7 +212,6 @@ def test_linux_invalid_linux64_valid_cr(mocker): def test_linux_valid_linux64_valid_cloudrendering(mocker): - mocker.patch("ai2thor.controller.platform_system", fake_linux_system) mocker.patch("ai2thor.controller.ai2thor.build.Build.exists", fake_exists) mocker.patch("ai2thor.controller.ai2thor.build.Build.download", noop_download) @@ -229,7 +225,6 @@ def test_linux_valid_linux64_valid_cloudrendering(mocker): def test_linux_valid_linux64_valid_cloudrendering_enabled_cr(mocker): - mocker.patch("ai2thor.controller.platform_system", fake_linux_system) mocker.patch("ai2thor.controller.ai2thor.build.Build.exists", fake_exists) mocker.patch("ai2thor.controller.ai2thor.build.Build.download", noop_download) @@ -246,7 +241,6 @@ def test_linux_valid_linux64_valid_cloudrendering_enabled_cr(mocker): def test_linux_valid_linux64_invalid_cloudrendering(mocker): - mocker.patch("ai2thor.controller.platform_system", fake_linux_system) mocker.patch("ai2thor.controller.ai2thor.build.Build.exists", fake_exists) mocker.patch("ai2thor.controller.ai2thor.build.Build.download", noop_download) @@ -263,7 +257,6 @@ def test_linux_valid_linux64_invalid_cloudrendering(mocker): def test_linux_missing_linux64(mocker): - mocker.patch("ai2thor.controller.platform_system", fake_linux_system) mocker.patch("ai2thor.controller.ai2thor.build.Build.exists", fake_cr_exists) mocker.patch("ai2thor.controller.ai2thor.build.Build.download", noop_download) @@ -278,7 +271,6 @@ def test_linux_missing_linux64(mocker): def test_linux_missing_cloudrendering(mocker): - mocker.patch("ai2thor.controller.platform_system", fake_linux_system) mocker.patch("ai2thor.controller.ai2thor.build.Build.exists", fake_linux64_exists) mocker.patch("ai2thor.controller.ai2thor.build.Build.download", noop_download) diff --git a/ai2thor/tests/test_event.py b/ai2thor/tests/test_event.py index bec7873395..70eff1e2d8 100644 --- a/ai2thor/tests/test_event.py +++ b/ai2thor/tests/test_event.py @@ -3602,7 +3602,6 @@ def test_lazy_class_segmentation(event_with_segmentation): @pytest.mark.parametrize("event_with_segmentation", segmentation_events) def test_lazy_class_segmentation_missing(event_with_segmentation): - with pytest.raises(KeyError): event_with_segmentation.class_masks["Stove"] diff --git a/ai2thor/tests/test_fifo_server.py b/ai2thor/tests/test_fifo_server.py index bbf6e2c14a..6cb223f613 100644 --- a/ai2thor/tests/test_fifo_server.py +++ b/ai2thor/tests/test_fifo_server.py @@ -9,7 +9,6 @@ def test_multi_agent_train(): - s = ai2thor.fifo_server.FifoServer(width=300, height=300) s.send(dict(action="RotateRight")) c = FifoClient(s.server_pipe_path, s.client_pipe_path) @@ -25,7 +24,6 @@ def test_multi_agent_train(): def test_train_numpy_action(): - s = ai2thor.fifo_server.FifoServer(width=300, height=300) s.send( dict( @@ -56,7 +54,6 @@ def generate_multi_agent_metadata_payload(metadata, sequence_id): def test_simple(): - s = ai2thor.fifo_server.FifoServer(width=300, height=300) s.send(dict(action="RotateRight")) c = FifoClient(s.server_pipe_path, s.client_pipe_path) diff --git a/ai2thor/tests/test_server.py b/ai2thor/tests/test_server.py index a9a16b8ce3..84a3c93f9c 100644 --- a/ai2thor/tests/test_server.py +++ b/ai2thor/tests/test_server.py @@ -75,7 +75,6 @@ def test_ping(client): def test_multi_agent_train(): - s = ai2thor.wsgi_server.WsgiServer(host="127.0.0.1") s.send(dict(action="RotateRight")) c = s.app.test_client() @@ -89,7 +88,6 @@ def test_multi_agent_train(): def test_train_numpy_action(): - s = ai2thor.wsgi_server.WsgiServer(host="127.0.0.1") s.send( dict( @@ -118,7 +116,6 @@ def test_train_numpy_action(): def test_train(): - s = ai2thor.wsgi_server.WsgiServer(host="127.0.0.1") s.send(dict(action="RotateRight")) c = s.app.test_client() @@ -132,7 +129,6 @@ def test_train(): def test_client_token_mismatch(): - s = ai2thor.wsgi_server.WsgiServer(host="127.0.0.1") s.send(dict(action="RotateRight")) s.client_token = "123456" @@ -166,7 +162,6 @@ def test_non_multipart(): def test_sequence_id_mismatch(): - s = ai2thor.wsgi_server.WsgiServer(host="127.0.0.1") s.send(dict(action="RotateRight")) c = s.app.test_client() diff --git a/ai2thor/tests/test_unity.py b/ai2thor/tests/test_unity.py index 9db19cdcb1..80437433e5 100644 --- a/ai2thor/tests/test_unity.py +++ b/ai2thor/tests/test_unity.py @@ -257,7 +257,6 @@ def test_third_party_camera_with_image_synthesis(fifo_controller): def test_rectangle_aspect(fifo_controller): - fifo_controller.reset(TEST_SCENE, width=600, height=300) event = fifo_controller.step(dict(action="Initialize", gridSize=0.25)) assert event.frame.shape == (300, 600, 3) @@ -385,7 +384,6 @@ def test_lookdown(controller): @pytest.mark.parametrize("controller", fifo_wsgi) def test_no_leak_params(controller): - action = dict(action="RotateLook", rotation=0, horizon=0) e = controller.step(action) assert "sequenceId" not in action @@ -404,7 +402,6 @@ def test_target_invocation_exception(controller): @pytest.mark.parametrize("controller", fifo_wsgi) def test_lookup(controller): - e = controller.step(dict(action="RotateLook", rotation=0, horizon=0)) position = controller.last_event.metadata["agent"]["position"] horizon = controller.last_event.metadata["agent"]["cameraHorizon"] @@ -419,7 +416,6 @@ def test_lookup(controller): @pytest.mark.parametrize("controller", fifo_wsgi) def test_rotate_left(controller): - e = controller.step(dict(action="RotateLook", rotation=0, horizon=0)) position = controller.last_event.metadata["agent"]["position"] rotation = controller.last_event.metadata["agent"]["rotation"] @@ -435,7 +431,6 @@ def test_rotate_left(controller): @pytest.mark.parametrize("controller", fifo_wsgi) def test_simobj_filter(controller): - objects = controller.last_event.metadata["objects"] unfiltered_object_ids = sorted([o["objectId"] for o in objects]) filter_object_ids = sorted([o["objectId"] for o in objects[0:3]]) @@ -645,7 +640,6 @@ def test_update_third_party_camera(fifo_controller): @pytest.mark.parametrize("controller", fifo_wsgi) def test_rotate_look(controller): - e = controller.step(dict(action="RotateLook", rotation=0, horizon=0)) position = controller.last_event.metadata["agent"]["position"] rotation = controller.last_event.metadata["agent"]["rotation"] @@ -660,7 +654,6 @@ def test_rotate_look(controller): @pytest.mark.parametrize("controller", fifo_wsgi) def test_rotate_right(controller): - e = controller.step(dict(action="RotateLook", rotation=0, horizon=0)) position = controller.last_event.metadata["agent"]["position"] rotation = controller.last_event.metadata["agent"]["rotation"] diff --git a/ai2thor/tests/test_unity_procedural.py b/ai2thor/tests/test_unity_procedural.py index 20dfe4b357..2bef03250f 100644 --- a/ai2thor/tests/test_unity_procedural.py +++ b/ai2thor/tests/test_unity_procedural.py @@ -279,7 +279,6 @@ def test_determinism(controller_args): print(f"{pos}") object_positions.append(pos) if prev_pos: - diffs = list(diff(pos, prev_pos, tolerance=0.00001)) print(diffs) assert [] == diffs diff --git a/ai2thor/util/depth.py b/ai2thor/util/depth.py index 78f14e5a09..a3eb2613fb 100644 --- a/ai2thor/util/depth.py +++ b/ai2thor/util/depth.py @@ -35,7 +35,6 @@ def generate_noise_indices(img_size): corner = t for i, c in enumerate(corner): - offset = 0 i_offset = 0 if j % 2 != 0: diff --git a/ai2thor/util/scene_yaml_edit.py b/ai2thor/util/scene_yaml_edit.py index 6a96656644..4e7747baae 100755 --- a/ai2thor/util/scene_yaml_edit.py +++ b/ai2thor/util/scene_yaml_edit.py @@ -39,7 +39,6 @@ def GetSceneNames(start_index, last_index, nameTemplate="", prefix_path="unity/A def main(): - # testSceneNames = GetRoboSceneNames(3, 5, "Val") # valSceneNames = GetRoboSceneNames(2, 2, "test-dev", "unity/Assets/Private/Scenes") # trainSceneNames = GetRoboSceneNames(12, 5, "Train") diff --git a/ai2thor/util/trials.py b/ai2thor/util/trials.py index 5a2f84c63a..327086d137 100644 --- a/ai2thor/util/trials.py +++ b/ai2thor/util/trials.py @@ -3,9 +3,11 @@ class TrialMetric(object): - def init_trials(self, num_trials, metadata): ... + def init_trials(self, num_trials, metadata): + ... - def update_with_trial(self, trial_index, metadata): ... + def update_with_trial(self, trial_index, metadata): + ... class ObjectPositionVarianceAverage(TrialMetric): diff --git a/ai2thor/video_controller.py b/ai2thor/video_controller.py index e4196ecf9b..f16cd05544 100644 --- a/ai2thor/video_controller.py +++ b/ai2thor/video_controller.py @@ -27,7 +27,6 @@ def __init__( cam_fov=60, **controller_kwargs, ): - self.saved_frames = [] self.ceiling_off = False self.initial_cam_rot = cam_rot.copy() diff --git a/ai2thor/wsgi_server.py b/ai2thor/wsgi_server.py index d901289e04..cd0d448fe8 100644 --- a/ai2thor/wsgi_server.py +++ b/ai2thor/wsgi_server.py @@ -105,7 +105,6 @@ def get_boundary(request_headers): return None def __init__(self, data, boundary): - self.form = {} self.files = {} @@ -125,7 +124,6 @@ def __init__(self, data, boundary): headers = {} for header in raw_headers.tobytes().decode("ascii").strip().split("\r\n"): - k, v = header.split(":") headers[k.strip()] = v.strip() @@ -149,7 +147,6 @@ def __init__(self, data, boundary): class WsgiServer(ai2thor.server.Server): - server_type = "WSGI" def __init__( @@ -163,7 +160,6 @@ def __init__( width=300, height=300, ): - app = Flask( __name__, template_folder=os.path.realpath( @@ -204,7 +200,6 @@ def ping(): @app.route("/train", methods=["post"]) def train(): - action_returns = [] if request.headers["Content-Type"].split(";")[0] == "multipart/form-data": diff --git a/arm_test/base.py b/arm_test/base.py index 2fdaa39c79..b71009625b 100644 --- a/arm_test/base.py +++ b/arm_test/base.py @@ -114,7 +114,6 @@ def standard_pose(): def execute_actions(actions, **kwargs): - for a in actions: if a == {} or a == {"action": ""}: continue diff --git a/arm_test/check_determinism_different_machines.py b/arm_test/check_determinism_different_machines.py index 1e82ac3bd6..9c85469a68 100644 --- a/arm_test/check_determinism_different_machines.py +++ b/arm_test/check_determinism_different_machines.py @@ -93,7 +93,6 @@ def get_reachable_positions(controller): def execute_command(controller, command, action_dict_addition_by_action): - base_position = get_current_arm_state(controller) change_height = MOVE_CONSTANT change_value = change_height diff --git a/arm_test/check_determinism_event_collision_different_machines.py b/arm_test/check_determinism_event_collision_different_machines.py index 4465586687..1267768f8d 100644 --- a/arm_test/check_determinism_event_collision_different_machines.py +++ b/arm_test/check_determinism_event_collision_different_machines.py @@ -48,7 +48,6 @@ def get_reachable_positions(controller): def execute_command(controller, command, action_dict_addition): - base_position = get_current_arm_state(controller) change_height = action_dict_addition["move_constant"] change_value = change_height @@ -118,7 +117,6 @@ def execute_command(controller, command, action_dict_addition): action_details = {} if command in ["w", "z", "s", "a", "3", "4"]: - controller.step( action="MoveMidLevelArm", position=dict(x=base_position["x"], y=base_position["y"], z=base_position["z"]),