@@ -11,25 +11,27 @@ mandatory, we only provide installation steps with this tool. You can install it
1111suggest to use VSCode with the ` Python ` , ` ty ` and ` ruff ` extensions (without ` Pylance ` ).
1212
13131 ) Pre-requisites: Use ` uv ` to install a Python version compatible with TorchJD and to pin it to the
14- ` torchjd ` folder. From the root of the ` torchjd ` repo, run:
14+ ` TorchJD ` folder. From the root of the ` TorchJD ` repo, run:
1515 ``` bash
1616 uv python install 3.14.0
1717 uv python pin 3.14.0
1818 ```
1919
20- 2 ) Create a virtual environment and install the project in it. From the root of ` torchjd ` , run:
20+ 2 ) Create a virtual environment and install the project in it. From the root of ` TorchJD ` , run:
2121 ``` bash
2222 uv venv
2323 CC=gcc uv pip install --python-version=3.14 -e ' .[full]' --group check --group doc --group test --group plot
2424 ```
2525 If you want to install PyTorch with a different CUDA version (this could be required depending on
26- your GPU), you'll need to specify and extra index. For instance, for CUDA 12.6, run:
26+ your GPU), you'll need to specify an extra index. For instance, for CUDA 12.6, run:
2727 ``` bash
2828 uv venv
2929 CC=gcc uv pip install --python-version=3.14 -e ' .[full]' --group check --group doc --group test --group plot --index-strategy unsafe-best-match --extra-index-url https://download.pytorch.org/whl/cu126
3030 ```
3131
32- We also advise using ` UV_NO_SYNC=1 ` to prevent ` uv ` from syncing all the time. This is because by
32+ 3 ) Set environment variables:
33+
34+ We need to use ` UV_NO_SYNC=1 ` to prevent ` uv ` from syncing all the time. This is because by
3335 default, it tries to resolve libraries compatible with the whole range of Python versions
3436 supported by TorchJD, but in reality, we just need an installation compatible with the currently
3537 used Python version. That's also why we specify ` --python-version=3.14 ` when running
@@ -40,7 +42,14 @@ suggest to use VSCode with the `Python`, `ty` and `ruff` extensions (without `Py
4042 and start a new terminal. The alternative is to use the ` --no-sync ` flag whenever you run a pip
4143 command that would normally sync (like ` uv run ` ).
4244
43- 3 ) Install pre-commit:
45+ Lastly, to run some scripts from the ` tests ` folder, you'll have to add the ` TorchJD/tests `
46+ folder to your ` PYTHONPATH ` . For that, you should add the following line to your ` .bashrc ` :
47+ ``` bash
48+ export PYTHONPATH=" $PYTHONPATH :<path_to_TorchJD>/tests"
49+ ```
50+ where ` <path_to_TorchJD> ` is the absolute path to your ` TorchJD ` repo.
51+
52+ 4 ) Install pre-commit:
4453 ``` bash
4554 uv run pre-commit install
4655 ```
@@ -52,36 +61,38 @@ suggest to use VSCode with the `Python`, `ty` and `ruff` extensions (without `Py
5261> [ here] ( https://pypi.org/project/ecos/#files ) ).
5362
5463> [ !TIP]
55- > The Python version that you should specify in your IDE is ` <path-to-torchjd >/.venv/bin/python ` .
64+ > The Python version that you should specify in your IDE is ` <path-to-TorchJD >/.venv/bin/python ` .
5665
5766> [ !TIP]
5867> In the following commands, you can get rid of the ` uv run ` prefix if you activate the ` venv `
59- > created by ` uv ` , using ` source .venv/bin/activate ` from the root of ` torchjd ` . This will, however,
68+ > created by ` uv ` , using ` source .venv/bin/activate ` from the root of ` TorchJD ` . This will, however,
6069> only work in the current terminal until it is closed.
6170
6271
63- ## Clean reinstallation
72+ ### Clean reinstallation
6473
6574If you want to update all dependencies or just reinstall from scratch, run the following command
66- from the root of ` torchjd ` :
75+ from the root of ` TorchJD ` :
6776``` bash
6877rm -rf .venv
69- rm uv.lock
78+ rm -f uv.lock
7079uv venv
7180CC=gcc uv pip install --python-version=3.14 -e ' .[full]' --group check --group doc --group test --group plot
7281uv run pre-commit install
7382```
7483
75- ## Running tests
84+ ## Checks
85+
86+ ### Running tests
7687 - To verify that your installation was successful, and that unit tests pass, run:
7788 ``` bash
7889 uv run pytest tests/unit
7990 ```
8091
8192 - To also run the unit tests that are marked as slow, add the ` --runslow` flag:
82- ` ` ` bash
83- uv run pytest tests/unit --runslow
84- ` ` `
93+ ` ` ` bash
94+ uv run pytest tests/unit --runslow
95+ ` ` `
8596
8697 - If you have access to a cuda-enabled GPU, you should also check that the unit tests pass on it:
8798 ` ` ` bash
@@ -100,7 +111,11 @@ uv run pre-commit install
100111 uv run pytest tests/unit tests/doc --cov=src
101112 ` ` `
102113
103- # # Building the documentation locally
114+ > [! TIP]
115+ > The code coverage value reported locally is lower than the value that our CI obtains, because
116+ > the CI runs the tests in several different environments.
117+
118+ # ## Building the documentation locally
104119 - From the ` docs` folder, run:
105120 ` ` ` bash
106121 uv run make html
@@ -112,7 +127,7 @@ uv run pre-commit install
112127 uv run make clean
113128 ` ` `
114129
115- # # Type checking
130+ # ## Type checking
116131
117132We use [ty](https://docs.astral.sh/ty/) for type-checking. If you' re on VSCode, we recommend using
118133the `ty` extension. You can also run it from the root of the repo with:
@@ -139,10 +154,10 @@ should create it.
139154
140155We ask contributors to implement the unit tests necessary to check the correctness of their
141156implementations. Besides, whenever usage examples are provided, we require the example' s code to be
142- tested in ` tests/doc` . We require a very high code coverage for newly introduced sources (~95-100%).
143- To ensure that the tensors generated during the tests are on the right device, you have to use the
144- partial functions defined in ` tests/utils/tensors.py` to instantiate tensors. For instance, instead
145- of
157+ tested in ` tests/doc` . We aim for 100% code coverage, but we greatly appreciate any PR, even with
158+ insufficient code coverage. To ensure that the tensors generated during the tests are on the right
159+ device and dtype, you have to use the partial functions defined in ` tests/utils/tensors.py` to
160+ instantiate tensors. For instance, instead of
146161` ` ` python
147162import torch
148163a = torch.ones(3, 4)
@@ -153,21 +168,23 @@ from utils.tensors import ones_
153168a = ones_(3, 4)
154169` ` `
155170
156- This will automatically call ` torch.ones` with ` device=DEVICE` .
171+ This will automatically call ` torch.ones` with ` device=DEVICE` . This way, your test will
172+ automatically be run on cuda when running it with the ` PYTEST_TORCH_DEVICE=cuda:0` environment
173+ variable, and will automatically be run on ` float64` with ` PYTEST_TORCH_DTYPE=float64` .
157174If the function you need does not exist yet as a partial function in ` tensors.py` , add it.
158175Lastly, when you create a model or a random generator, you have to move them manually to the right
159- device (the ` DEVICE` defined in ` device .py` ).
176+ device (the ` DEVICE` defined in ` settings .py` ).
160177` ` ` python
161178import torch
162179from torch.nn import Linear
163- from device import DEVICE
180+ from settings import DEVICE
164181
165182model = Linear(3, 4).to(device=DEVICE)
166183rng = torch.Generator(device=DEVICE)
167184` ` `
168185You may also use a ` ModuleFactory` to make the modules on ` DEVICE` automatically.
169186
170- # ## Coding
187+ # ## Coding style
171188
172189We try to keep the quality of the codebase as high as possible. Even if this slows down development
173190in the short term, it helps a lot in the long term. To make the code easy to understand and to
@@ -177,7 +194,7 @@ of the library when adding new sources. Also, please make sure that new modules
177194` __init__.py` file of the package they are located into. This makes them easier to import for the
178195user.
179196
180- # # Adding a new aggregator
197+ # ## Adding a new aggregator
181198
182199Mathematically, an aggregator is a mapping $\m athcal A: \m athbb R^{m \t imes n} \t o \m athbb R^n$. In
183200the context of Jacobian descent, it is used to reduce a Jacobian matrix into a vector that can be
@@ -192,21 +209,22 @@ implementation of a mathematical aggregator.
192209> Before working on the implementation of a new aggregator, please contact us via an issue or a
193210> discussion: in many cases, we have already thought about it, or even started an implementation.
194211
195- # # Deprecation
212+ # ## Deprecation
196213
197214To deprecate some public functionality, make it raise a ` DeprecationWarning` . A test should also be
198- added in ` tests/units /test_deprecations.py` , ensuring that this warning is issued.
215+ added in ` tests/unit /test_deprecations.py` , ensuring that this warning is issued.
199216
200217# # Release
201218
202219* This section is addressed to maintainers.*
203220
204221To release a new ` torchjd` version, you have to:
222+ - If the release introduces changes to the interface, make sure that ` README.md` reflects those
223+ changes.
205224- Make sure that all tests, including those on cuda, pass (for this, you need access to a machine
206225 that has a cuda-enabled GPU).
207226- Make sure that all important changes since the last release have been reported in the
208- ` [Unreleased]`
209- section at the top of the changelog.
227+ ` [Unreleased]` section at the top of the changelog.
210228- Add a ` [X.Y.Z] - yyyy-mm-dd` header in the changelog just below the ` [Unreleased]` header.
211229- Change the version in ` pyproject.toml` .
212230- Make a pull request with those changes and merge it.
0 commit comments