From dfcbcc46de89f64700950c59723282a4e0e09e8a Mon Sep 17 00:00:00 2001 From: Luis Pineda Date: Fri, 9 Sep 2022 08:09:41 -0400 Subject: [PATCH] Changed requirements so that main.txt only includes essential dependencies (#294) * Changed requirements so that main.txt only includes essential dependencies. * Reverted black, mypi, flake and isort versions in requirements file. * Fixed some mypy issues. Added drm to dev requirements so unit tests pass. --- README.md | 4 ++-- docs/source/getting-started.rst | 8 ++++++++ examples/README.md | 5 +++++ examples/homography_estimation.py | 10 +++++----- requirements/dev.txt | 3 +++ requirements/main.txt | 3 --- theseus/embodied/kinematics/kinematics_model.py | 10 +++++++++- theseus/optimizer/linear_system.py | 2 +- theseus/theseus_layer.py | 2 +- theseus/utils/examples/tactile_pose_estimation/misc.py | 10 +++++----- 10 files changed, 39 insertions(+), 18 deletions(-) diff --git a/README.md b/README.md index b8f986555..73624356a 100644 --- a/README.md +++ b/README.md @@ -105,9 +105,9 @@ pip install -e ".[dev]" ``` and follow the more detailed instructions in [CONTRIBUTING](https://github.com/facebookresearch/theseus/blob/main/CONTRIBUTING.md). -### Running unit tests +### Running unit tests (requires `dev` installation) ```bash -pytest theseus +python -m pytest theseus ``` By default, unit tests include tests for our CUDA extensions. You can add the option `-m "not cudaext"` to skip them when installing without CUDA support. diff --git a/docs/source/getting-started.rst b/docs/source/getting-started.rst index aff03556e..71c66bb8a 100644 --- a/docs/source/getting-started.rst +++ b/docs/source/getting-started.rst @@ -45,6 +45,14 @@ If you are interested in contributing to ``theseus``, instead install using and follow the more detailed instructions in `CONTRIBUTING `_. +Unit tests +"""""""""" +With ``dev`` installation, you can run unit tests via + +.. code-block:: bash + + python -m pytest theseus + By default, unit tests include tests for our CUDA extensions. You can add the option ``-m "not cudaext"`` to skip them when installing without CUDA support. diff --git a/examples/README.md b/examples/README.md index e234bcbdf..8d3c461bd 100644 --- a/examples/README.md +++ b/examples/README.md @@ -37,6 +37,11 @@ The motion planning and tactile estimation examples require `hydra` installation ```bash pip install hydra-core ``` +The backward modes example requires `numdifftools`, which you can install with + +```bash +pip install numdifftools +``` The homography example requires `kornia` and `OpenCV`, which you can install with diff --git a/examples/homography_estimation.py b/examples/homography_estimation.py index c23208dc1..c23c5574e 100644 --- a/examples/homography_estimation.py +++ b/examples/homography_estimation.py @@ -17,7 +17,7 @@ from torch.utils.data import DataLoader, Dataset import theseus as th -from theseus.third_party.easyaug import RandomGeoAug, GeoAugParam, RandomPhotoAug +from theseus.third_party.easyaug import GeoAugParam, RandomGeoAug, RandomPhotoAug from theseus.third_party.utils import grid_sample FONT = cv2.FONT_HERSHEY_DUPLEX @@ -36,10 +36,10 @@ def prepare_data(): dataset_root = os.path.join(os.getcwd(), "data") chunks = [ "revisitop1m.1", - #"revisitop1m.2", # Uncomment for more data. - #"revisitop1m.3", - #"revisitop1m.4", - #"revisitop1m.5", + # "revisitop1m.2", # Uncomment for more data. + # "revisitop1m.3", + # "revisitop1m.4", + # "revisitop1m.5", ] dataset_paths = [] for chunk in chunks: diff --git a/requirements/dev.txt b/requirements/dev.txt index 032cd9529..24fe1e3b1 100644 --- a/requirements/dev.txt +++ b/requirements/dev.txt @@ -4,7 +4,10 @@ mypy>=0.910 nox==2020.8.22 pre-commit>=2.9.2 isort>=5.6.4 +differentiable-robot-model>=0.2.3 types-PyYAML==5.4.3 +numdifftools>=0.9.40 +mock>=4.0.3 types-mock>=4.0.8 Sphinx==5.0.2 sphinx-rtd-theme==1.0.0 \ No newline at end of file diff --git a/requirements/main.txt b/requirements/main.txt index 9ab32057a..2d854d5f8 100644 --- a/requirements/main.txt +++ b/requirements/main.txt @@ -1,10 +1,7 @@ -differentiable-robot-model>=0.2.3 numpy>=1.19.2 scipy>=1.5.3 scikit-sparse>=0.4.5 # torch>=1.7.1 will do separate install instructions for now (CUDA dependent) pytest>=6.2.1 -numdifftools>=0.9.40 pybind11>=2.7.1 -mock>=4.0.3 functorch>=0.2.1 \ No newline at end of file diff --git a/theseus/embodied/kinematics/kinematics_model.py b/theseus/embodied/kinematics/kinematics_model.py index 57438a823..15820ab9e 100644 --- a/theseus/embodied/kinematics/kinematics_model.py +++ b/theseus/embodied/kinematics/kinematics_model.py @@ -6,7 +6,6 @@ import abc from typing import Dict, Optional, Union -import differentiable_robot_model as drm import torch from theseus.geometry import SE3, LieGroup, Point2, Vector @@ -38,6 +37,15 @@ def forward_kinematics(self, robot_pose: RobotModelInput) -> Dict[str, LieGroup] class UrdfRobotModel(KinematicsModel): def __init__(self, urdf_path: str): + try: + import differentiable_robot_model as drm + except ModuleNotFoundError as e: + print( + "UrdfRobotModel requires installing differentiable-robot-model. " + "Please run `pip install differentiable-robot-model`." + ) + raise e + self.drm_model = drm.DifferentiableRobotModel(urdf_path) def _postprocess_quaternion(self, quat): diff --git a/theseus/optimizer/linear_system.py b/theseus/optimizer/linear_system.py index bf68dc60a..fd8d1d09c 100644 --- a/theseus/optimizer/linear_system.py +++ b/theseus/optimizer/linear_system.py @@ -16,7 +16,7 @@ def __init__( row_ptr: np.ndarray, num_rows: int, num_cols: int, - dtype: np.dtype = np.float_, + dtype: np.dtype = np.float_, # type: ignore ): self.col_ind = col_ind self.row_ptr = row_ptr diff --git a/theseus/theseus_layer.py b/theseus/theseus_layer.py index 941b40d18..5555e007b 100644 --- a/theseus/theseus_layer.py +++ b/theseus/theseus_layer.py @@ -298,7 +298,7 @@ def jacobians(self) -> Tuple[List[torch.Tensor], torch.Tensor]: return [self.var.project(euclidean_grad, is_sparse=True)], self.error() def dim(self) -> int: - return np.prod(self.var.tensor.shape[1:]) + return int(np.prod(self.var.tensor.shape[1:])) def _copy_impl(self, new_name: Optional[str] = None) -> "CostFunction": return _DLMPerturbation( diff --git a/theseus/utils/examples/tactile_pose_estimation/misc.py b/theseus/utils/examples/tactile_pose_estimation/misc.py index f91c844ed..88354ccaa 100644 --- a/theseus/utils/examples/tactile_pose_estimation/misc.py +++ b/theseus/utils/examples/tactile_pose_estimation/misc.py @@ -47,11 +47,11 @@ def __init__( stop = max(int(np.ceil(num_episodes * val_ratio)), 2) idx = order[:stop] if data_mode == "val" else order[stop:] - self.img_feats = data["img_feats"][idx] - self.eff_poses = data["eff_poses"][idx] - self.obj_poses = data["obj_poses"][idx] - self.contact_episode = data["contact_episode"][idx] - self.contact_flag = data["contact_flag"][idx] + self.img_feats = data["img_feats"][idx] # type: ignore + self.eff_poses = data["eff_poses"][idx] # type: ignore + self.obj_poses = data["obj_poses"][idx] # type: ignore + self.contact_episode = data["contact_episode"][idx] # type: ignore + self.contact_flag = data["contact_flag"][idx] # type: ignore # Check sizes of the attributes assigned above self.dataset_size: int = -1 for key in data: