Skip to content

Improve _transform package structure#298

Merged
ValerianRey merged 7 commits intomainfrom
improve-transform-package-structure
Apr 4, 2025
Merged

Improve _transform package structure#298
ValerianRey merged 7 commits intomainfrom
improve-transform-package-structure

Conversation

@ValerianRey
Copy link
Copy Markdown
Contributor

@ValerianRey ValerianRey commented Apr 3, 2025

The goal here is to get rid of an overused utils.py file, to stop having factorized code when it's used only in a single Transform and to fix protection issues. This should not have any impact on anything for the user, as it's (supposedly) just moving code around and renaming internal things.

  • Move _A, _B and _C to tensor_dict.py
  • Move _union to Conjunction.call
  • Move dicts_union to _stack
  • Move _KeyType to ordered_set.py
  • Rename _utils.py to _materialize.py
  • Rename _materialize to materialize
  • Rename _Differentiate to Differentiate

Since `_union` is only used in `Conjunction.__call__`, it makes sence to define it in `base.py` (where `Conjunction` is defined). Further, since `base.py` contains several classes, it makes sence to make `_union` a static method of specifically the `Conjunction` class. Lastly, since `Conjunction.__call__` is almost a trivial call to `_union`, it makes sense to have no `_union` method but to directly compute this union in the `__call__` method of `Conjunction`. This is kind of the opposite of a factorization, but it should enhance code readability since it limits the back-and-forth required to understand a piece of code.
- Since `dict_union` is only used in `stacks.py`, I think it's better to define it there. It makes less back-and-forth when reading the code, and it reduces the number of things that `_utils.py` has to contain.
- Also remove _ValueType from _utils.py since it is now unused
- It now only contains the _materialize function, which can hardly be moved to another file since grad, jac and stack depend on it.
- materialize is in a protected file _materialize.py, which means that only members of the local transform package can import from it. There is thus no point in make the materialize function itself protected. In fact, this would mean that the materialize function should not be used outside _materialize.py, while in fact, it has to be used in grad.py, jac.py, and stack.py.
@ValerianRey ValerianRey added package: autojac cc: refactor Conventional commit type for any refactoring, not user-facing, and not typing or perf improvements labels Apr 3, 2025
@ValerianRey ValerianRey self-assigned this Apr 3, 2025
This was referenced Apr 3, 2025
@codecov
Copy link
Copy Markdown

codecov bot commented Apr 3, 2025

Codecov Report

All modified and coverable lines are covered by tests ✅

Files with missing lines Coverage Δ
src/torchjd/autojac/_transform/_differentiate.py 100.00% <100.00%> (ø)
src/torchjd/autojac/_transform/_materialize.py 100.00% <100.00%> (ø)
src/torchjd/autojac/_transform/base.py 100.00% <100.00%> (ø)
src/torchjd/autojac/_transform/grad.py 100.00% <100.00%> (ø)
src/torchjd/autojac/_transform/jac.py 100.00% <100.00%> (ø)
src/torchjd/autojac/_transform/ordered_set.py 100.00% <100.00%> (ø)
src/torchjd/autojac/_transform/select.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%> (ø)
🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@ValerianRey ValerianRey merged commit fe1686b into main Apr 4, 2025
14 checks passed
@ValerianRey ValerianRey deleted the improve-transform-package-structure branch April 4, 2025 09:39
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

cc: refactor Conventional commit type for any refactoring, not user-facing, and not typing or perf improvements package: autojac

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants