Skip to content

Commit

Permalink
Flake8 comprehensions update (#1774)
Browse files Browse the repository at this point in the history
* --fix flake8 complaints; refactor a few expensive self-accesses in loops

* --update pre-commit-config.yaml to match pypi version used by CI

* --address bugs in conversion - generator, not list comp

* update machine image for clang-tidy job


Co-authored-by: John Turner <[email protected]>
  • Loading branch information
aclegg3 and jturner65 authored Jun 1, 2022
1 parent a776e4f commit 7a1e9c8
Show file tree
Hide file tree
Showing 6 changed files with 51 additions and 42 deletions.
4 changes: 2 additions & 2 deletions .circleci/config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -327,7 +327,7 @@ jobs:
machine:
# Available images:
# https://circleci.com/docs/2.0/configuration-reference/#available-linux-gpu-images
image: ubuntu-1604:202104-01
image: ubuntu-2004:202201-02
resource_class: xlarge
steps:
- checkout:
Expand All @@ -340,7 +340,7 @@ jobs:
name: Install clang-tidy
command: |
# Bellow is only needed for Ubuntu 20
# sudo apt-key adv --fetch-keys "https://apt.llvm.org/llvm-snapshot.gpg.key"
sudo apt-key adv --fetch-keys "https://apt.llvm.org/llvm-snapshot.gpg.key"
sudo add-apt-repository "deb http://apt.llvm.org/xenial/ llvm-toolchain-xenial-12 main"
sudo apt-get update -y || true
sudo apt-get install -y clang-tidy-12
Expand Down
2 changes: 1 addition & 1 deletion .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ repos:
additional_dependencies: &flake8_dependencies
- flake8-bugbear==22.1.11
- flake8-builtins==1.5.3
- flake8-comprehensions==3.8.0
- flake8-comprehensions==3.10.0
- flake8-return==1.1.3
- flake8-simplify==0.17.0

Expand Down
7 changes: 3 additions & 4 deletions conda-build/common/delete_old_night_packages.py
Original file line number Diff line number Diff line change
Expand Up @@ -40,15 +40,14 @@
)
# Using len(versions) - MAX_NUMBER_OF_VERSIONS to support MAX_NUMBER_OF_VERSIONS == 0
remove_versions = versions[: len(versions) - MAX_NUMBER_OF_VERSIONS]
print(
f"anaconda remove {' '.join(list(map(lambda x: f'aihabitat-nightly/habitat-sim/{x}', remove_versions)))}"
)
remove_versions_list = [f"aihabitat-nightly/habitat-sim/{x}" for x in remove_versions]
print(f"anaconda remove {' '.join(remove_versions_list)}")
result_remove = subprocess.run(
[
"anaconda",
"remove",
"-f",
*list(map(lambda x: f"aihabitat-nightly/habitat-sim/{x}", remove_versions)),
*remove_versions_list,
],
stderr=subprocess.PIPE,
stdout=subprocess.PIPE,
Expand Down
2 changes: 1 addition & 1 deletion src_python/habitat_sim/nav/greedy_geodesic_follower.py
Original file line number Diff line number Diff line change
Expand Up @@ -188,7 +188,7 @@ def find_path(self, goal_pos: np.ndarray) -> List[Any]:
if len(path) == 0:
raise errors.GreedyFollowerError()

path = list(map(lambda v: self.action_mapping[v], path))
path = [self.action_mapping[v] for v in path]

return path

Expand Down
48 changes: 31 additions & 17 deletions src_python/habitat_sim/robots/mobile_manipulator.py
Original file line number Diff line number Diff line change
Expand Up @@ -274,15 +274,17 @@ def reset(self) -> None:
@property
def arm_joint_limits(self) -> Tuple[np.ndarray, np.ndarray]:
"""Get the arm joint limits in radians"""
arm_pos_indices = list(
map(lambda x: self.joint_pos_indices[x], self.params.arm_joints)
)

# deref self vars to cut access in half
joint_pos_indices = self.joint_pos_indices
lower_joints_limits, upper_joint_limits = self.joint_limits
arm_joints = self.params.arm_joints
arm_pos_indices = [joint_pos_indices[x] for x in arm_joints]
lower_lims = np.array(
[self.joint_limits[0][i] for i in arm_pos_indices], dtype=np.float32
[lower_joints_limits[i] for i in arm_pos_indices], dtype=np.float32
)
upper_lims = np.array(
[self.joint_limits[1][i] for i in arm_pos_indices], dtype=np.float32
[upper_joint_limits[i] for i in arm_pos_indices], dtype=np.float32
)
return lower_lims, upper_lims

Expand Down Expand Up @@ -327,11 +329,15 @@ def ee_transform(self) -> mn.Matrix4:
@property
def gripper_joint_pos(self) -> np.ndarray:
"""Get the current gripper joint positions."""
gripper_pos_indices = map(
lambda x: self.joint_pos_indices[x], self.params.gripper_joints
)

# deref self vars to cut access in half
joint_pos_indices = self.joint_pos_indices
gripper_joints = self.params.gripper_joints
sim_obj_joint_pos = self.sim_obj.joint_positions

gripper_pos_indices = (joint_pos_indices[x] for x in gripper_joints)
return np.array(
[self.sim_obj.joint_positions[i] for i in gripper_pos_indices],
[sim_obj_joint_pos[i] for i in gripper_pos_indices],
dtype=np.float32,
)

Expand Down Expand Up @@ -388,11 +394,15 @@ def is_gripper_closed(self) -> bool:
@property
def arm_joint_pos(self) -> np.ndarray:
"""Get the current arm joint positions."""
arm_pos_indices = map(
lambda x: self.joint_pos_indices[x], self.params.arm_joints
)

# deref self vars to cut access in half
joint_pos_indices = self.joint_pos_indices
arm_joints = self.params.arm_joints
sim_obj_joint_pos = self.sim_obj.joint_positions

arm_pos_indices = (joint_pos_indices[x] for x in arm_joints)
return np.array(
[self.sim_obj.joint_positions[i] for i in arm_pos_indices], dtype=np.float32
[sim_obj_joint_pos[i] for i in arm_pos_indices], dtype=np.float32
)

@arm_joint_pos.setter
Expand Down Expand Up @@ -429,11 +439,15 @@ def set_fixed_arm_joint_pos(self, fix_arm_joint_pos):
@property
def arm_velocity(self) -> np.ndarray:
"""Get the velocity of the arm joints."""
arm_dof_indices = map(
lambda x: self.joint_dof_indices[x], self.params.arm_joints
)

# deref self vars to cut access in half
joint_dof_indices = self.joint_dof_indices
arm_joints = self.params.arm_joints
sim_obj_joint_vel = self.sim_obj.joint_velocities

arm_dof_indices = (joint_dof_indices[x] for x in arm_joints)
return np.array(
[self.sim_obj.joint_velocities[i] for i in arm_dof_indices],
[sim_obj_joint_vel[i] for i in arm_dof_indices],
dtype=np.float32,
)

Expand Down
30 changes: 13 additions & 17 deletions src_python/habitat_sim/simulator.py
Original file line number Diff line number Diff line change
Expand Up @@ -90,29 +90,25 @@ def _sanitize_config(config: Configuration) -> None:
)

config.sim_cfg.create_renderer = any(
map(lambda cfg: len(cfg.sensor_specifications) > 0, config.agents)
(len(cfg.sensor_specifications) > 0 for cfg in config.agents)
)
config.sim_cfg.load_semantic_mesh = any(
map(
lambda cfg: any(
map(
lambda sens_spec: sens_spec.sensor_type == SensorType.SEMANTIC,
cfg.sensor_specifications,
)
),
config.agents,
(
any(
sens_spec.sensor_type == SensorType.SEMANTIC
for sens_spec in cfg.sensor_specifications
)
for cfg in config.agents
)
)

config.sim_cfg.requires_textures = any(
map(
lambda cfg: any(
map(
lambda sens_spec: sens_spec.sensor_type == SensorType.COLOR,
cfg.sensor_specifications,
)
),
config.agents,
(
any(
sens_spec.sensor_type == SensorType.COLOR
for sens_spec in cfg.sensor_specifications
)
for cfg in config.agents
)
)

Expand Down

0 comments on commit 7a1e9c8

Please sign in to comment.