From 15259c1ba3a9d4d678b6028364f2d78fdefef826 Mon Sep 17 00:00:00 2001 From: SausageMan99 Date: Wed, 7 Oct 2026 18:17:05 +0200 Subject: [PATCH 1/2] fix(aggregation): Place CAGradWeighting docstring before class attributes _REQUIRED_DEPS and _INSTALL_HINT were defined before the docstring, so the string literal was not the class docstring and CAGradWeighting.__doc__ was None, leaving its documentation entry empty. The same issue affected the private _NashMTLWeighting. Fixes #807 Co-Authored-By: Claude Opus 5.5 --- src/torchjd/aggregation/_cagrad.py | 5 +++-- src/torchjd/aggregation/_nash_mtl.py | 5 +++-- tests/unit/aggregation/test_cagrad.py | 4 ++++ 3 files changed, 10 insertions(+), 4 deletions(-) diff --git a/src/torchjd/aggregation/_cagrad.py b/src/torchjd/aggregation/_cagrad.py index b2da3efe6..40a5d5b0e 100644 --- a/src/torchjd/aggregation/_cagrad.py +++ b/src/torchjd/aggregation/_cagrad.py @@ -19,8 +19,6 @@ # Non-differentiable: the cvxpy solver operates on numpy arrays, breaking the autograd graph. class CAGradWeighting(_WithOptionalDeps, _GramianWeighting, _NonDifferentiable): - _REQUIRED_DEPS = ["numpy", "cvxpy", "clarabel"] - _INSTALL_HINT = 'Install them with: pip install "torchjd[cagrad]"' """ :class:`~torchjd.aggregation.Weighting` [:class:`~torchjd.linalg.PSDMatrix`] giving the weights of :class:`~torchjd.aggregation.CAGrad`. @@ -37,6 +35,9 @@ class CAGradWeighting(_WithOptionalDeps, _GramianWeighting, _NonDifferentiable): function. """ + _REQUIRED_DEPS = ["numpy", "cvxpy", "clarabel"] + _INSTALL_HINT = 'Install them with: pip install "torchjd[cagrad]"' + def __init__(self, c: float, norm_eps: float = 0.0001) -> None: super().__init__() self.c = c diff --git a/src/torchjd/aggregation/_nash_mtl.py b/src/torchjd/aggregation/_nash_mtl.py index d3f11a9cc..a4583e6c5 100644 --- a/src/torchjd/aggregation/_nash_mtl.py +++ b/src/torchjd/aggregation/_nash_mtl.py @@ -22,8 +22,6 @@ # Non-differentiable: the cvxpy solver operates on numpy arrays, breaking the autograd graph. class _NashMTLWeighting(_WithOptionalDeps, _MatrixWeighting, Stateful, _NonDifferentiable): - _REQUIRED_DEPS = ["numpy", "cvxpy", "ecos"] - _INSTALL_HINT = 'Install them with: pip install "torchjd[nash_mtl]"' """ :class:`~torchjd.Stateful` :class:`~torchjd.aggregation.Weighting` [:class:`~torchjd.linalg.Matrix`] that @@ -45,6 +43,9 @@ class _NashMTLWeighting(_WithOptionalDeps, _MatrixWeighting, Stateful, _NonDiffe affects the shape of the cached state). """ + _REQUIRED_DEPS = ["numpy", "cvxpy", "ecos"] + _INSTALL_HINT = 'Install them with: pip install "torchjd[nash_mtl]"' + def __init__( self, n_tasks: int, diff --git a/tests/unit/aggregation/test_cagrad.py b/tests/unit/aggregation/test_cagrad.py index 6cb5e9684..2b4a247c1 100644 --- a/tests/unit/aggregation/test_cagrad.py +++ b/tests/unit/aggregation/test_cagrad.py @@ -96,3 +96,7 @@ def test_weighting_norm_eps_setter_rejects_negative() -> None: W = CAGradWeighting(c=0.5) with raises(ValueError, match="norm_eps"): W.norm_eps = -1e-9 + + +def test_weighting_has_docstring() -> None: + assert CAGradWeighting.__doc__ is not None From d89970c0f8099eecaef1f8aa0cc13e21047a3d56 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Val=C3=A9rian=20Rey?= <31951177+ValerianRey@users.noreply.github.com> Date: Wed, 7 Oct 2026 18:29:34 +0200 Subject: [PATCH 2/2] Apply suggestion from @ValerianRey --- tests/unit/aggregation/test_cagrad.py | 4 ---- 1 file changed, 4 deletions(-) diff --git a/tests/unit/aggregation/test_cagrad.py b/tests/unit/aggregation/test_cagrad.py index 2b4a247c1..6cb5e9684 100644 --- a/tests/unit/aggregation/test_cagrad.py +++ b/tests/unit/aggregation/test_cagrad.py @@ -96,7 +96,3 @@ def test_weighting_norm_eps_setter_rejects_negative() -> None: W = CAGradWeighting(c=0.5) with raises(ValueError, match="norm_eps"): W.norm_eps = -1e-9 - - -def test_weighting_has_docstring() -> None: - assert CAGradWeighting.__doc__ is not None