diff --git a/.circleci/config.yml b/.circleci/config.yml index f633341d76..1ae8ce5588 100644 --- a/.circleci/config.yml +++ b/.circleci/config.yml @@ -123,7 +123,8 @@ commands: . activate habitat # For whatever reason we have to install pytorch first. If it isn't # it installs the 1.4 cpuonly version. Which is no good. - conda install -q -y pytorch torchvision cudatoolkit=11.3 -c pytorch + #conda install -q -y pytorch=1.12 torchvision pytorch-cuda=11.3 -c pytorch -c nvidia + conda install pytorch==1.12.1 torchvision==0.13.1 cudatoolkit=11.3 -c pytorch conda install -q -y -c conda-forge ninja numpy pytest pytest-cov ccache hypothesis pytest-mock pip install pytest-sugar pytest-xdist pytest-benchmark opencv-python cython mock fi @@ -184,13 +185,6 @@ jobs: - run: name: setup command: | - # Updated llvm to v 10 - sudo apt-get update - sudo apt-get install llvm-10 - cd /usr/bin - sudo rm llvm-config - sudo ln -s llvm-config-10 llvm-config - cd ~/project/ pip install -U pip pip install -U --prefer-binary \ black \ diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml index fd3a07462d..4ef1cb1b24 100644 --- a/.pre-commit-config.yaml +++ b/.pre-commit-config.yaml @@ -68,7 +68,7 @@ repos: exclude: docs/ - repo: https://github.com/pycqa/flake8 - rev: 4.0.1 + rev: 5.0.4 hooks: - id: flake8 exclude: docs/ @@ -76,7 +76,7 @@ repos: - flake8-bugbear==22.1.11 - flake8-builtins==1.5.3 - flake8-comprehensions==3.10.0 - - flake8-return==1.1.3 + - flake8-return==1.2.0 - flake8-simplify==0.17.0 - repo: https://github.com/asottile/yesqa diff --git a/examples/fairmotion_interface.py b/examples/fairmotion_interface.py index 516662360a..60e5ba31da 100644 --- a/examples/fairmotion_interface.py +++ b/examples/fairmotion_interface.py @@ -221,7 +221,7 @@ def save_metadata(self, file: str): break # we are no longer overwriting a file - elif "/" not in file: + if "/" not in file: # file is not a file path, we need to aim it at our directory if ".json" not in file: # add file type @@ -422,14 +422,14 @@ def convert_CMUamass_single_pose( raise KeyError( "Error: pose data does not have a transform for that joint name" ) - elif joint_type not in [phy.JointType.Spherical]: + if joint_type not in [phy.JointType.Spherical]: raise NotImplementedError( f"Error: {joint_type} is not a supported joint type" ) - else: - T = pose.get_transform(pose_joint_index, local=True) - if joint_type == phy.JointType.Spherical: - Q, _ = conversions.T2Qp(T) + + T = pose.get_transform(pose_joint_index, local=True) + if joint_type == phy.JointType.Spherical: + Q, _ = conversions.T2Qp(T) new_pose += list(Q) diff --git a/setup.cfg b/setup.cfg index 2db7da3e0e..d3d0ad0f6a 100644 --- a/setup.cfg +++ b/setup.cfg @@ -27,7 +27,7 @@ ignore = A003, C401,C402,C408, SIM105,SIM113,SIM9 - R504, + R504,R505, W503 per-file-ignores = */__init__.py:F401 diff --git a/src_python/habitat_sim/nav/greedy_geodesic_follower.py b/src_python/habitat_sim/nav/greedy_geodesic_follower.py index 83223bbdbb..c274d288a7 100644 --- a/src_python/habitat_sim/nav/greedy_geodesic_follower.py +++ b/src_python/habitat_sim/nav/greedy_geodesic_follower.py @@ -163,8 +163,7 @@ def next_action_along(self, goal_pos: np.ndarray) -> Any: if next_act == GreedyFollowerCodes.ERROR: raise errors.GreedyFollowerError() - else: - return self.action_mapping[next_act] + return self.action_mapping[next_act] def find_path(self, goal_pos: np.ndarray) -> List[Any]: r"""Finds the sequence actions that greedily follow the geodesic diff --git a/src_python/habitat_sim/registry.py b/src_python/habitat_sim/registry.py index 3ef6cc353d..c57ee6a6f7 100755 --- a/src_python/habitat_sim/registry.py +++ b/src_python/habitat_sim/registry.py @@ -75,8 +75,8 @@ def _wrapper(controller: Type[SceneNodeControl]): if controller is None: return _wrapper - else: - return _wrapper(controller) + + return _wrapper(controller) @classmethod def register_noise_model( @@ -104,8 +104,8 @@ def _wrapper(noise_model: Type[SensorNoiseModel]): if noise_model is None: return _wrapper - else: - return _wrapper(noise_model) + + return _wrapper(noise_model) @classmethod def register_pose_extractor( @@ -133,8 +133,8 @@ def _wrapper(pose_extractor: Type[PoseExtractor]): if pose_extractor is None: return _wrapper - else: - return _wrapper(pose_extractor) + + return _wrapper(pose_extractor) @classmethod def _get_impl(cls, _type, name: str): diff --git a/src_python/habitat_sim/sensors/noise_models/no_noise_model.py b/src_python/habitat_sim/sensors/noise_models/no_noise_model.py index 9beb27ebbe..54d0453c3f 100755 --- a/src_python/habitat_sim/sensors/noise_models/no_noise_model.py +++ b/src_python/habitat_sim/sensors/noise_models/no_noise_model.py @@ -32,7 +32,6 @@ def apply( ) -> Union[ndarray, "torch.Tensor"]: if isinstance(x, np.ndarray): return x.copy() - elif torch is not None and torch.is_tensor(x): + if torch is not None and torch.is_tensor(x): return x.clone() - else: - return x + return x diff --git a/src_python/habitat_sim/sensors/noise_models/redwood_depth_noise_model.py b/src_python/habitat_sim/sensors/noise_models/redwood_depth_noise_model.py index 6535a4da65..4123744fc7 100755 --- a/src_python/habitat_sim/sensors/noise_models/redwood_depth_noise_model.py +++ b/src_python/habitat_sim/sensors/noise_models/redwood_depth_noise_model.py @@ -40,8 +40,8 @@ def _undistort(x, y, z, model): if f < 1e-5: return 0.0 - else: - return z / f + + return z / f @numba.jit(nopython=True, parallel=True, fastmath=True) @@ -134,13 +134,12 @@ def simulate(self, gt_depth: Union[ndarray, "Tensor"]) -> Union[ndarray, "Tensor if cuda_enabled: if isinstance(gt_depth, np.ndarray): return self._impl.simulate_from_cpu(gt_depth) - else: - noisy_depth = torch.empty_like(gt_depth) - rows, cols = gt_depth.size() - self._impl.simulate_from_gpu( - gt_depth.data_ptr(), rows, cols, noisy_depth.data_ptr() # type: ignore[attr-defined] - ) - return noisy_depth + noisy_depth = torch.empty_like(gt_depth) + rows, cols = gt_depth.size() + self._impl.simulate_from_gpu( + gt_depth.data_ptr(), rows, cols, noisy_depth.data_ptr() # type: ignore[attr-defined] + ) + return noisy_depth else: return self._impl.simulate(gt_depth) diff --git a/src_python/habitat_sim/simulator.py b/src_python/habitat_sim/simulator.py index 04b1c457a6..fe7f7f1822 100755 --- a/src_python/habitat_sim/simulator.py +++ b/src_python/habitat_sim/simulator.py @@ -649,76 +649,76 @@ def draw_observation(self) -> None: # do nothing in draw observation, get_observation will be called after this # run the simulation there return - else: - assert self._sim.renderer is not None - # see if the sensor is attached to a scene graph, otherwise it is invalid, - # and cannot make any observation - if not self._sensor_object.object: - raise habitat_sim.errors.InvalidAttachedObject( - "Sensor observation requested but sensor is invalid.\ + + assert self._sim.renderer is not None + # see if the sensor is attached to a scene graph, otherwise it is invalid, + # and cannot make any observation + if not self._sensor_object.object: + raise habitat_sim.errors.InvalidAttachedObject( + "Sensor observation requested but sensor is invalid.\ (has it been detached from a scene node?)" - ) - self._sim.renderer.draw(self._sensor_object, self._sim) + ) + self._sim.renderer.draw(self._sensor_object, self._sim) def _draw_observation_async(self) -> None: if self._spec.sensor_type == SensorType.AUDIO: # do nothing in draw observation, get_observation will be called after this # run the simulation there return - else: - assert self._sim.renderer is not None - if ( - self._spec.sensor_type == SensorType.SEMANTIC - and self._sim.get_active_scene_graph() - is not self._sim.get_active_semantic_scene_graph() - ): - raise RuntimeError( - "Async drawing doesn't support semantic rendering when there are multiple scene graphs" - ) - # TODO: sync this path with renderer changes as above (render from sensor object) - # see if the sensor is attached to a scene graph, otherwise it is invalid, - # and cannot make any observation - if not self._sensor_object.object: - raise habitat_sim.errors.InvalidAttachedObject( - "Sensor observation requested but sensor is invalid.\ - (has it been detached from a scene node?)" - ) + assert self._sim.renderer is not None + if ( + self._spec.sensor_type == SensorType.SEMANTIC + and self._sim.get_active_scene_graph() + is not self._sim.get_active_semantic_scene_graph() + ): + raise RuntimeError( + "Async drawing doesn't support semantic rendering when there are multiple scene graphs" + ) + # TODO: sync this path with renderer changes as above (render from sensor object) + + # see if the sensor is attached to a scene graph, otherwise it is invalid, + # and cannot make any observation + if not self._sensor_object.object: + raise habitat_sim.errors.InvalidAttachedObject( + "Sensor observation requested but sensor is invalid.\ + (has it been detached from a scene node?)" + ) - # get the correct scene graph based on application - if self._spec.sensor_type == SensorType.SEMANTIC: - if self._sim.semantic_scene is None: - raise RuntimeError( - "SemanticSensor observation requested but no SemanticScene is loaded" - ) - scene = self._sim.get_active_semantic_scene_graph() - else: # SensorType is DEPTH or any other type - scene = self._sim.get_active_scene_graph() + # get the correct scene graph based on application + if self._spec.sensor_type == SensorType.SEMANTIC: + if self._sim.semantic_scene is None: + raise RuntimeError( + "SemanticSensor observation requested but no SemanticScene is loaded" + ) + scene = self._sim.get_active_semantic_scene_graph() + else: # SensorType is DEPTH or any other type + scene = self._sim.get_active_scene_graph() - # now, connect the agent to the root node of the current scene graph + # now, connect the agent to the root node of the current scene graph - # sanity check is not needed on agent: - # because if a sensor is attached to a scene graph, - # it implies the agent is attached to the same scene graph - # (it assumes backend simulator will guarantee it.) + # sanity check is not needed on agent: + # because if a sensor is attached to a scene graph, + # it implies the agent is attached to the same scene graph + # (it assumes backend simulator will guarantee it.) - agent_node = self._agent.scene_node - agent_node.parent = scene.get_root_node() + agent_node = self._agent.scene_node + agent_node.parent = scene.get_root_node() - # get the correct scene graph based on application - if self._spec.sensor_type == SensorType.SEMANTIC: - scene = self._sim.get_active_semantic_scene_graph() - else: # SensorType is DEPTH or any other type - scene = self._sim.get_active_scene_graph() + # get the correct scene graph based on application + if self._spec.sensor_type == SensorType.SEMANTIC: + scene = self._sim.get_active_semantic_scene_graph() + else: # SensorType is DEPTH or any other type + scene = self._sim.get_active_scene_graph() - render_flags = habitat_sim.gfx.Camera.Flags.NONE + render_flags = habitat_sim.gfx.Camera.Flags.NONE - if self._sim.frustum_culling: - render_flags |= habitat_sim.gfx.Camera.Flags.FRUSTUM_CULLING + if self._sim.frustum_culling: + render_flags |= habitat_sim.gfx.Camera.Flags.FRUSTUM_CULLING - self._sim.renderer.enqueue_async_draw_job( - self._sensor_object, scene, self.view, render_flags - ) + self._sim.renderer.enqueue_async_draw_job( + self._sensor_object, scene, self.view, render_flags + ) def get_observation(self) -> Union[ndarray, "Tensor"]: if self._spec.sensor_type == SensorType.AUDIO: diff --git a/src_python/habitat_sim/utils/data/data_structures.py b/src_python/habitat_sim/utils/data/data_structures.py index 9586ccad42..6b9f5aeccf 100644 --- a/src_python/habitat_sim/utils/data/data_structures.py +++ b/src_python/habitat_sim/utils/data/data_structures.py @@ -14,11 +14,11 @@ def __init__(self, capacity=1000): def __getitem__(self, key): if not self.__contains__(key): raise KeyError("Key {} not in extractor cache".format(key)) - else: - # Accessing the data should move it to front of cache - k, data = self._order.pop(key) - self._order[key] = (k, data) - return data + + # Accessing the data should move it to front of cache + k, data = self._order.pop(key) + self._order[key] = (k, data) + return data def __contains__(self, key): return key in self._order diff --git a/src_python/habitat_sim/utils/datasets_download.py b/src_python/habitat_sim/utils/datasets_download.py index 45d1021b26..f6c759d65b 100755 --- a/src_python/habitat_sim/utils/datasets_download.py +++ b/src_python/habitat_sim/utils/datasets_download.py @@ -416,10 +416,9 @@ def prompt_yes_no(message): answer = input("(y|n): ") if answer.lower() == "y": return True - elif answer.lower() == "n": + if answer.lower() == "n": return False - else: - print("Invalid answer...") + print("Invalid answer...") def get_version_dir(uid, data_path):