Skip to content

Commit b9f39b4

Browse files
committed
Fix pydocstyle linting in new PR; clean up pyproject.toml
1 parent 8ae1122 commit b9f39b4

File tree

5 files changed

+85
-35
lines changed

5 files changed

+85
-35
lines changed

.github/workflows/test.yml

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -40,10 +40,10 @@ jobs:
4040
4141
# Code quality checks
4242
- name: Check code formatting with Black
43-
run: black --check manify/ --line-length 120
43+
run: black --check manify/
4444

4545
- name: Check import ordering with isort
46-
run: isort --check-only --diff manify/
46+
run: isort --check-only manify/
4747

4848
- name: Run pylint
4949
run: pylint manify/
@@ -54,11 +54,11 @@ jobs:
5454

5555
# Unit testing
5656
- name: Run unit tests & collect coverage
57-
run: BEARTYPE_ENABLE=true pytest tests --cov=manify --cov-report=xml:coverage.xml
57+
run: BEARTYPE_ENABLE=true pytest tests --cov --cov-report=xml
5858

5959
# Check docstrings are in Google style
6060
- name: Check docstrings are in Google style
61-
run: pydocstyle --add-ignore=D107 --convention=google manify/
61+
run: pydocstyle manify/
6262
continue-on-error: true
6363

6464
# Code coverage

manify/clustering/fuzzy_kmeans.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,6 @@
1-
"""The Riemannian Fuzzy K-Means algorithm is a clustering algorithm that operates on Riemannian manifolds.
1+
"""Riemannian Fuzzy K-Means.
2+
3+
The Riemannian Fuzzy K-Means algorithm is a clustering algorithm that operates on Riemannian manifolds.
24
Compared to a straightforward extension of K-Means or Fuzzy K-Means to Riemannian manifolds,
35
it offers significant acceleration while achieving lower loss. For more details,
46
please refer to the paper: https://openreview.net/forum?id=9VmOgMN4Ie

manify/optimizers/_adan.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,6 @@
1-
"""This file contains code adapted from the Adan optimizer implementation in PyTorch:
1+
"""Adaptive Nesterov Momentum Algorithm (Adan) Optimizer.
2+
3+
This file contains code adapted from the Adan optimizer implementation in PyTorch:
24
https://github.com/sail-sg/Adan
35
46
The remainder of this file is unmodified from the original source, including the license:

manify/optimizers/radan.py

Lines changed: 29 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,6 @@
1-
"""Radan is the Riemannian version of the Adaptive Nesterov Momentum algorithm.
1+
"""Riemannian Adan (Radan).
2+
3+
Radan is the Riemannian version of the Adaptive Nesterov Momentum algorithm.
24
This code is compatible with both Geoopt and Manify libraries, and is designed for Riemannian Fuzzy K-Means.
35
We recommend using the parameters `[0.7, 0.99, 0.99]` for best performance.**
46
@@ -50,23 +52,29 @@
5052

5153

5254
class RiemannianAdan(OptimMixin, _adan.Adan):
53-
"""
54-
Riemannian Adan with the same API as :class:`adan.Adan`.
55+
"""Riemannian Adan with the same API as :class:`adan.Adan`.
56+
57+
Attributes:
58+
param_groups: iterable of parameter groups, each containing parameters to optimize and optimization options
59+
_default_manifold: the default manifold used for optimization if not specified in parameters
5560
5661
Args:
57-
params : iterable
58-
iterable of parameters to optimize or dicts defining parameter groups
59-
lr : float (optional)
60-
learning rate (default: 1e-3)
61-
betas : Tuple[float, float, float] (optional)
62-
coefficients used for computing (default: (0.98, 0.92, 0.99))
63-
eps : float (optional)
64-
term added to the denominator to improve numerical stability (default: 1e-8)
65-
weight_decay : float (optional)
66-
weight decay (L2 penalty) (default: 0)
62+
params: iterable of parameters to optimize or dicts defining parameter groups
63+
lr: learning rate (default: 1e-3)
64+
betas: coefficients used for computing (default: (0.98, 0.92, 0.99))
65+
eps: term added to the denominator to improve numerical stability (default: 1e-8)
66+
weight_decay: weight decay (L2 penalty) (default: 0)
6767
"""
6868

6969
def step(self, closure: Callable | None = None) -> Float[torch.Tensor, ""] | None:
70+
"""Performs a single optimization step.
71+
72+
Args:
73+
closure: A closure that reevaluates the model and returns the loss.
74+
75+
Returns:
76+
The loss value if closure is provided, otherwise None.
77+
"""
7078
loss = None
7179
if closure is not None:
7280
loss = closure()
@@ -152,6 +160,14 @@ def step(self, closure: Callable | None = None) -> Float[torch.Tensor, ""] | Non
152160

153161
@torch.no_grad() # type: ignore
154162
def stabilize_group(self, group: dict[str, Any]) -> None:
163+
"""Stabilizes the parameters in the group by projecting them onto their respective manifolds.
164+
165+
Args:
166+
group: A dictionary containing the parameters and their states.
167+
168+
Returns:
169+
None
170+
"""
155171
for p in group["params"]:
156172
if not isinstance(p, (ManifoldParameter, ManifoldTensor)):
157173
continue

pyproject.toml

Lines changed: 46 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,7 @@
1+
# =============================================================================
2+
# Project Configuration
3+
# =============================================================================
4+
15
[build-system]
26
requires = ["setuptools", "wheel"]
37
build-backend = "setuptools.build_meta"
@@ -17,7 +21,6 @@ dependencies = [
1721
"tqdm",
1822
"cvxpy",
1923
"scikit-learn==1.5.1",
20-
"geoopt",
2124
"datasets"
2225
]
2326

@@ -48,7 +51,22 @@ packages = ["manify"]
4851
[tool.setuptools.package-data]
4952
"manify" = ["../data/**/*"]
5053

51-
# Pylint configuration
54+
# =============================================================================
55+
# CI/CD Tool Configuration
56+
# =============================================================================
57+
58+
# Code formatting with Black
59+
[tool.black]
60+
line-length = 120
61+
target-version = ["py310"]
62+
63+
# Import sorting with isort
64+
[tool.isort]
65+
profile = "black"
66+
line_length = 120
67+
skip = ["manify/optimizers/_adan.py"] # Use unmodified adan.py code from original repo
68+
69+
# Static analysis with Pylint
5270
[tool.pylint.master]
5371
init-hook = "import sys; sys.path.append('.')"
5472
fail-under = 8.0
@@ -74,18 +92,10 @@ module-rgx = "([a-z_][a-z0-9_]*)"
7492
[tool.pylint.typecheck]
7593
generated-members = "torch.*,nn.*"
7694

77-
[tool.pytest.ini_options]
78-
testpaths = ["tests"]
79-
addopts = "--jaxtyping-packages=beartype.beartype"
80-
python_files = "test_*.py"
81-
95+
# Type checking with MyPy
8296
[tool.mypy]
83-
# Specify the packages to check
8497
packages = ["manify"]
85-
disable_error_code = ["name-defined"] # Needed for jaxtyping compatibility - else vector annotations fail
86-
exclude = ["manify/optimizers/_adan.py"] # Use unmodified adan.py code from original repo
87-
88-
# Ignore missing imports for external libraries
98+
exclude = ["manify/optimizers/_adan.py"] # Use unmodified adan.py code from original repo
8999
python_version = "3.10"
90100
disallow_untyped_defs = true
91101
disallow_incomplete_defs = true
@@ -97,8 +107,28 @@ warn_return_any = true
97107
warn_unused_ignores = false
98108
follow_imports = "skip"
99109
ignore_missing_imports = true
110+
disable_error_code = ["name-defined"] # Needed for jaxtyping compatibility - else vector annotations fail
100111

101-
[tool.isort]
102-
profile = "black"
103-
line_length = 120
104-
skip = ["manify/optimizers/_adan.py"] # Use unmodified adan.py code from original repo
112+
# Unit testing with pytest
113+
[tool.pytest.ini_options]
114+
testpaths = ["tests"]
115+
addopts = "--jaxtyping-packages=beartype.beartype"
116+
python_files = "test_*.py"
117+
118+
# Code coverage
119+
[tool.coverage.run]
120+
source = ["manify"]
121+
branch = true
122+
omit = ["manify/optimizers/_adan.py"] # Exclude from coverage reporting
123+
124+
[tool.coverage.report]
125+
fail_under = 80
126+
127+
[tool.coverage.xml]
128+
output = "coverage.xml"
129+
130+
# Docstring style checking with pydocstyle
131+
[tool.pydocstyle]
132+
convention = "google"
133+
add_ignore = ["D107"]
134+
match = "(?!_adan).*\\.py$" # Exclude _adan.py from docstring checks

0 commit comments

Comments
 (0)