8000 Add `mypy` by ValerianRey · Pull Request #364 · TorchJD/torchjd · GitHub
[go: up one dir, main page]
More Web Proxy on the site http://driver.im/
Skip to content

Add mypy #364

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 18 commits into from
Closed

Add mypy #364

wants to merge 18 commits into from

Conversation

ValerianRey
Copy link
Contributor
@ValerianRey ValerianRey commented May 28, 2025

This PR is just to give an overview of the changes related to the addition of mypy. I will probably break this into smaller PRs when it's completed. To install mypy and run it locally, do:

uv pip install mypy
uv run mypy src/torchjd --follow-untyped-imports

#365: Add mypy action

#366: Fix type of _check_losses_are_scalar

#367:

  • Add type hint to union in _stack
  • Add type hint to result in _get_descendant_accumulate_grads
  • Be more specific about the type of Select when instantiating it

#368: Use new variables in backward and mtl_backward when changing type

#369:

  • Make _B contravariant and _C covariant
  • Fix generic parametrization in Composition and Conjunction

#372:

  • Add cast in get_leaf_tensors
  • Add cast of w_opt to np.ndarray in _CAGradWeighting.forward
  • Add cast to type[TensorDict] in _least_common_ancestor

#370:

  • Add comment to ignore mypy errors in _nash_mtl.py
  • Add comment to ignore type error in mgda
  • Add type: ignore[assignment] when needed in TensorDict immutability tricks, and add a comment

#371: Ignore type error in get_leaf_tensors and add comment

#374: Update Conjunction.call to make its typing correct (#379 is better)

#375: Change OrderedSet to compose with OrderedDict instead of inheriting from it

Copy link
codecov bot commented May 28, 2025

Codecov Report

All modified and coverable lines are covered by tests ✅

Files with missing lines Coverage Δ
src/torchjd/_autojac/_backward.py 100.00% <100.00%> (ø)
src/torchjd/_autojac/_mtl_backward.py 100.00% <100.00%> (ø)
src/torchjd/_autojac/_transform/_base.py 100.00% <100.00%> (ø)
src/torchjd/_autojac/_transform/_ordered_set.py 100.00% <100.00%> (ø)
src/torchjd/_autojac/_transform/_stack.py 100.00% <100.00%> (ø)
src/torchjd/_autojac/_transform/_tensor_dict.py 100.00% <100.00%> (ø)
src/torchjd/_autojac/_utils.py 100.00% <100.00%> (ø)
src/torchjd/aggregation/_cagrad.py 100.00% <100.00%> (ø)
src/torchjd/aggregation/_mgda.py 100.00% <100.00%> (ø)
src/torchjd/aggregation/_nash_mtl.py 100.00% <ø> (ø)
🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@ValerianRey
Copy link
Contributor Author

@PierreQuinton you can already look at some of these, but for the most complex ones, I would love to discuss them in a live coding session with you.

@ValerianRey
Copy link
Contributor Author

Closing this now that all the PRs have been extracted for individual review and merging.

@ValerianRey ValerianRey deleted the add-mypy branch June 3, 2025 22:52
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant
0