Skip to content

str(CAGrad(c=10)) returns "CAGrad1" #809

Closed

Description

@ValerianRey

CAGrad.__str__ builds its suffix with str(self.c).rstrip("0"), which also strips significant zeros:

def __str__(self) -> str:
c_str = str(self.c).rstrip("0")
return f"CAGrad{c_str}"

>>> from torchjd.aggregation import CAGrad
>>> str(CAGrad(c=10)), str(CAGrad(c=100)), str(CAGrad(c=0)), str(CAGrad(c=1.0))
('CAGrad1', 'CAGrad1', 'CAGrad', 'CAGrad1.')

So CAGrad(c=10) and CAGrad(c=100) get the same name, which is wrong for both. This matters when str(aggregator) is used to name experiments or plot curves.

Suggested fix

def __str__(self) -> str:
    return f"CAGrad{self.c:g}"

This gives CAGrad10, CAGrad100, CAGrad0, CAGrad1 and CAGrad0.5, so the existing assertion str(CAGrad(c=0.5)) == "CAGrad0.5" still holds.

Checklist

  • Fix CAGrad.__str__ in src/torchjd/aggregation/_cagrad.py.

See CONTRIBUTING.md to set up the development environment.

Activity

  1. adityawaghamare commented on Oct 8, 2026

    @adityawaghamare
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    good first issueIssue that should be easy to solve for new contributors

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions