Skip to content

Commit

Permalink
Fix ci pytorch cuda (#1946)
Browse files Browse the repository at this point in the history
* (bugfix): fix python-lint CI

* Try to improve python lint

* try pytorch suggested previous version 1.12 w/ cuda 11.3

Co-authored-by: Aaron Gokaslan <[email protected]>
  • Loading branch information
aclegg3 and Skylion007 authored Nov 22, 2022
1 parent 59456b9 commit 7ab0cf2
Show file tree
Hide file tree
Showing 11 changed files with 89 additions and 99 deletions.
10 changes: 2 additions & 8 deletions .circleci/config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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 \
Expand Down
4 changes: 2 additions & 2 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -68,15 +68,15 @@ repos:
exclude: docs/

- repo: https://github.com/pycqa/flake8
rev: 4.0.1
rev: 5.0.4
hooks:
- id: flake8
exclude: docs/
additional_dependencies: &flake8_dependencies
- 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
Expand Down
12 changes: 6 additions & 6 deletions examples/fairmotion_interface.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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)

Expand Down
2 changes: 1 addition & 1 deletion setup.cfg
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ ignore =
A003,
C401,C402,C408,
SIM105,SIM113,SIM9
R504,
R504,R505,
W503
per-file-ignores =
*/__init__.py:F401
Expand Down
3 changes: 1 addition & 2 deletions src_python/habitat_sim/nav/greedy_geodesic_follower.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
12 changes: 6 additions & 6 deletions src_python/habitat_sim/registry.py
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand Down Expand Up @@ -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(
Expand Down Expand Up @@ -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):
Expand Down
5 changes: 2 additions & 3 deletions src_python/habitat_sim/sensors/noise_models/no_noise_model.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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)

Expand Down
108 changes: 54 additions & 54 deletions src_python/habitat_sim/simulator.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
10 changes: 5 additions & 5 deletions src_python/habitat_sim/utils/data/data_structures.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
5 changes: 2 additions & 3 deletions src_python/habitat_sim/utils/datasets_download.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand Down

0 comments on commit 7ab0cf2

Please sign in to comment.