Skip to content

Commit

Permalink
Fix a bug un precommit that was preventing isort and black from b…
Browse files Browse the repository at this point in the history
…eing run (#546)

* Fix some bugs in pre-commit config.

* isort.
  • Loading branch information
luisenp authored Jun 24, 2023
1 parent bc0223d commit fa6fca5
Show file tree
Hide file tree
Showing 35 changed files with 80 additions and 61 deletions.
10 changes: 5 additions & 5 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
@@ -1,28 +1,28 @@
exclude: "setup.py|torchlie/setup.py|examples|tests"
exclude: "setup.py|torchlie/setup.py"

repos:
- repo: https://github.com/psf/black
rev: 23.3.0
hooks:
- id: black
files: 'theseus'
files: 'examples'
files: "^theseus|^examples|^tests|^torchlie"

- repo: https://github.com/pycqa/flake8
rev: 6.0.0
hooks:
- id: flake8
files: "^theseus|^torchlie"

- repo: https://github.com/pre-commit/mirrors-mypy
rev: v1.4.0
hooks:
- id: mypy
additional_dependencies: [torch, tokenize-rt==3.2.0, types-PyYAML, types-mock]
args: [--no-strict-optional, --ignore-missing-imports, --implicit-reexport, --explicit-package-bases]
files: "^theseus|^torchlie"

- repo: https://github.com/pycqa/isort
rev: 5.12.0
hooks:
- id: isort
files: 'theseus'
files: 'examples'
files: "^theseus|^examples|^torchlie"
2 changes: 1 addition & 1 deletion theseus/_version.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@
# LICENSE file in the root directory of this source tree.
import warnings

from torch import __version__ as _torch_version
from semantic_version import Version
from torch import __version__ as _torch_version

if Version(_torch_version) < Version("2.0.0"):
warnings.warn(
Expand Down
2 changes: 1 addition & 1 deletion theseus/constants.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@
#
# This source code is licensed under the MIT license found in the
# LICENSE file in the root directory of this source tree.
from typing import Optional, Union
import math
from typing import Optional, Union

import torch

Expand Down
1 change: 1 addition & 0 deletions theseus/core/variable.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
from typing import Any, List, Optional, Sequence, Union

import torch

from theseus.constants import DeviceType


Expand Down
1 change: 1 addition & 0 deletions theseus/geometry/point_types.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
import torch

from theseus.constants import DeviceType

from .vector import Vector


Expand Down
2 changes: 1 addition & 1 deletion theseus/geometry/se3.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,9 @@
from typing import List, Optional, Union, cast

import torch
from torchlie.functional import SE3 as SE3_base

import theseus.constants
from torchlie.functional import SE3 as SE3_base

from .lie_group import LieGroup
from .lie_group_check import _LieGroupCheckContext, no_lie_group_check
Expand Down
3 changes: 2 additions & 1 deletion theseus/geometry/so3.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,11 @@
from typing import List, Optional, Union, cast

import torch
from torchlie.functional import SO3 as SO3_base

import theseus.constants
from theseus.options import _THESEUS_GLOBAL_OPTIONS
from torchlie.functional import SO3 as SO3_base

from .lie_group import LieGroup
from .lie_group_check import _LieGroupCheckContext
from .point_types import Point3
Expand Down
7 changes: 4 additions & 3 deletions theseus/labs/embodied/robot/forward_kinematics.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,13 @@
# This source code is licensed under the MIT license found in the
# LICENSE file in the root directory of this source tree.

import torch

from typing import List, Optional

import torch

from torchlie.functional import SE3
from .robot import Robot, Joint, Link

from .robot import Joint, Link, Robot

# TODO: Add support for joints with DOF>1

Expand Down
3 changes: 2 additions & 1 deletion theseus/labs/embodied/robot/joint.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,11 @@
import abc
import warnings
from typing import List, Optional

import torch

from torchlie.functional import SO3
from theseus.constants import DeviceType
from torchlie.functional import SO3


class Link(abc.ABC):
Expand Down
10 changes: 6 additions & 4 deletions theseus/labs/embodied/robot/robot.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,15 @@
# LICENSE file in the root directory of this source tree.

import abc
from typing import List, Dict, Optional
import urdf_parser_py.urdf as urdf
from typing import Dict, List, Optional

import torch
import urdf_parser_py.urdf as urdf

from torchlie.functional import SE3
from theseus.constants import DeviceType
from .joint import Joint, FixedJoint, RevoluteJoint, PrismaticJoint, Link
from torchlie.functional import SE3

from .joint import FixedJoint, Joint, Link, PrismaticJoint, RevoluteJoint


class Robot(abc.ABC):
Expand Down
2 changes: 1 addition & 1 deletion theseus/optimizer/autograd/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@
# LICENSE file in the root directory of this source tree.

from .baspacho_sparse_autograd import BaspachoSolveFunction
from .lu_cuda_sparse_autograd import LUCudaSolveFunction
from .cholmod_sparse_autograd import CholmodSolveFunction
from .lu_cuda_sparse_autograd import LUCudaSolveFunction

__all__ = [
"BaspachoSolveFunction",
Expand Down
8 changes: 5 additions & 3 deletions theseus/optimizer/autograd/baspacho_sparse_autograd.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,15 @@
#
# This source code is licensed under the MIT license found in the
# LICENSE file in the root directory of this source tree.
from typing import Any, Tuple, Optional
from typing import Any, Optional, Tuple

import torch

from .common import compute_A_grad
from ..linear_system import SparseStructure
from theseus.utils.sparse_matrix_utils import mat_vec, tmat_vec

from ..linear_system import SparseStructure
from .common import compute_A_grad

_BaspachoSolveFunctionBwdReturnType = Tuple[
torch.Tensor, torch.Tensor, None, None, None, None, None, None, None
]
Expand Down
2 changes: 1 addition & 1 deletion theseus/optimizer/autograd/cholmod_sparse_autograd.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,8 @@
import torch
from sksparse.cholmod import Factor as CholeskyDecomposition

from .common import compute_A_grad
from ..linear_system import SparseStructure
from .common import compute_A_grad

_CholmodSolveFunctionBwdReturnType = Tuple[
torch.Tensor, torch.Tensor, None, None, None, None
Expand Down
1 change: 1 addition & 0 deletions theseus/optimizer/autograd/lu_cuda_sparse_autograd.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
# This source code is licensed under the MIT license found in the
# LICENSE file in the root directory of this source tree.
from typing import Any, Optional, Tuple

import torch

from ..linear_system import SparseStructure
Expand Down
4 changes: 2 additions & 2 deletions theseus/optimizer/linear/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,9 @@

import torch

from .baspacho_sparse_solver import BaspachoSparseSolver
from .cholmod_sparse_solver import CholmodSparseSolver
from .dense_solver import CholeskyDenseSolver, DenseSolver, LUDenseSolver
from .linear_optimizer import LinearOptimizer
from .linear_solver import LinearSolver
from .baspacho_sparse_solver import BaspachoSparseSolver
from .lu_cuda_sparse_solver import LUCudaSparseSolver
from .cholmod_sparse_solver import CholmodSparseSolver
4 changes: 2 additions & 2 deletions theseus/optimizer/linear/baspacho_sparse_solver.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,9 @@

from typing import Any, Dict, Optional, Type, Union

import numpy as np
import torch
from scipy.sparse import csr_matrix

from theseus.constants import DeviceType
from theseus.core import Objective
Expand All @@ -14,8 +16,6 @@

from .linear_solver import LinearSolver
from .utils import convert_to_alpha_beta_damping_tensors
from scipy.sparse import csr_matrix
import numpy as np

# assuming the want to use cuda if supported and available
DEFAULT_DEVICE = "cuda" if torch.cuda.is_available() else "cpu"
Expand Down
2 changes: 2 additions & 0 deletions theseus/optimizer/linear/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,9 @@
# This source code is licensed under the MIT license found in the
# LICENSE file in the root directory of this source tree.
from typing import Tuple, Union

import torch

from theseus.constants import DeviceType


Expand Down
8 changes: 4 additions & 4 deletions theseus/optimizer/nonlinear/dcem.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,23 +3,23 @@
# This source code is licensed under the MIT license found in the
# LICENSE file in the root directory of this source tree.

from typing import Optional, Union, List, Dict
from typing import Dict, List, Optional, Union

import numpy as np
import torch
from torch.distributions import Normal

from theseus.third_party.lml import LML
from theseus.core.objective import Objective
from theseus.optimizer import OptimizerInfo
from theseus.optimizer.variable_ordering import VariableOrdering
from theseus.third_party.lml import LML

from .nonlinear_optimizer import (
NonlinearOptimizer,
BackwardMode,
EndIterCallbackType,
NonlinearOptimizer,
NonlinearOptimizerInfo,
NonlinearOptimizerStatus,
EndIterCallbackType,
)


Expand Down
5 changes: 3 additions & 2 deletions theseus/optimizer/nonlinear/nonlinear_least_squares.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,16 +13,17 @@
from theseus.core.objective import error_squared_norm_fn
from theseus.optimizer import Linearization, OptimizerInfo
from theseus.optimizer.linear import (
LinearSolver,
CholeskyDenseSolver,
LinearSolver,
LUCudaSparseSolver,
)

from .nonlinear_optimizer import (
BackwardMode,
EndIterCallbackType,
NonlinearOptimizer,
NonlinearOptimizerInfo,
NonlinearOptimizerStatus,
EndIterCallbackType,
)


Expand Down
2 changes: 1 addition & 1 deletion theseus/optimizer/nonlinear/nonlinear_optimizer.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
import warnings
from dataclasses import dataclass
from enum import Enum
from typing import Dict, Optional, Tuple, Union, Callable, NoReturn
from typing import Callable, Dict, NoReturn, Optional, Tuple, Union

import numpy as np
import torch
Expand Down
1 change: 0 additions & 1 deletion theseus/optimizer/nonlinear/trust_region.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@

from .nonlinear_least_squares import NonlinearLeastSquares


# See Nocedal and Wright, Numerical Optimization, Chapter 4
# https://www.csie.ntu.edu.tw/~r97002/temp/num_optimization.pdf

Expand Down
2 changes: 1 addition & 1 deletion theseus/optimizer/sparse_linearization.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
import torch

from theseus.core import Objective
from theseus.utils.sparse_matrix_utils import sparse_mv, sparse_mtv
from theseus.utils.sparse_matrix_utils import sparse_mtv, sparse_mv

from .linear_system import SparseStructure
from .linearization import Linearization
Expand Down
5 changes: 3 additions & 2 deletions theseus/options.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,13 @@
#
# This source code is licensed under the MIT license found in the
# LICENSE file in the root directory of this source tree.
from typing import Any, Dict
from dataclasses import dataclass
from typing import Any, Dict

import torchlie.options
import torch

import torchlie.options


def _CHECK_DTYPE_SUPPORTED(dtype):
if dtype not in [torch.float32, torch.float64]:
Expand Down
2 changes: 1 addition & 1 deletion theseus/theseus_layer.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
import torch.nn as nn
from torch.autograd.function import once_differentiable

from theseus.constants import __FROM_THESEUS_LAYER_TOKEN__, DeviceType
from theseus.core import (
CostFunction,
CostWeight,
Expand All @@ -18,7 +19,6 @@
Variable,
Vectorize,
)
from theseus.constants import __FROM_THESEUS_LAYER_TOKEN__, DeviceType
from theseus.geometry import LieGroup, Manifold
from theseus.optimizer import Optimizer, OptimizerInfo
from theseus.optimizer.linear import LinearSolver
Expand Down
9 changes: 4 additions & 5 deletions theseus/third_party/lml.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,14 +21,12 @@
# OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
# WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

import torch
from torch.autograd import Function, Variable, grad
from torch.nn import Module

import numpy as np
import numpy.random as npr

import torch
from semantic_version import Version
from torch.autograd import Function, Variable, grad
from torch.nn import Module

version = Version(".".join(torch.__version__.split(".")[:3]))
old_torch = version < Version("0.4.0")
Expand Down Expand Up @@ -182,6 +180,7 @@ def backward(ctx, grad_output):

if __name__ == "__main__":
import sys

from IPython.core import ultratb

sys.excepthook = ultratb.FormattedTB(
Expand Down
4 changes: 2 additions & 2 deletions theseus/utils/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,10 @@

from .sparse_matrix_utils import (
mat_vec,
random_sparse_matrix,
random_sparse_binary_matrix,
sparse_mv,
random_sparse_matrix,
sparse_mtv,
sparse_mv,
split_into_param_sizes,
tmat_vec,
)
Expand Down
2 changes: 1 addition & 1 deletion torchlie/torchlie/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@
# LICENSE file in the root directory of this source tree.
__version__ = "0.0.1.rc1"

from .types import ltype, SE3, SO3
from .lie_tensor import ( # usort: skip
LieTensor,
adj,
Expand All @@ -25,3 +24,4 @@
transform_from,
)
from .options import reset_global_options, set_global_options
from .types import SE3, SO3, ltype
2 changes: 1 addition & 1 deletion torchlie/torchlie/functional/constants.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@
#
# This source code is licensed under the MIT license found in the
# LICENSE file in the root directory of this source tree.
from typing import Optional, Union
import math
from typing import Optional, Union

import torch

Expand Down
Loading

0 comments on commit fa6fca5

Please sign in to comment.