Skip to content

Commit a8f5ee0

Browse files
committed
Add ruff pre-commit and account for it
1 parent 0c98dc8 commit a8f5ee0

51 files changed

Lines changed: 1648 additions & 1504 deletions

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

.github/workflows/cd.yml

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,4 +38,3 @@ jobs:
3838
with:
3939
github_token: ${{ secrets.GITHUB_TOKEN }}
4040
publish_dir: docs/build
41-

.github/workflows/ci.yml

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -36,10 +36,6 @@ jobs:
3636
run: |
3737
python -c "import pytest; print('pytest', pytest.__version__)"
3838
python -c "import pydocstyle; print('pydocstyle', pydocstyle.__version__)"
39-
39+
4040
- name: Run tests
4141
run: python -m pytest --pydocstyle
42-
43-
- name: Run linting tests
44-
run: |
45-
black --check .

.github/workflows/deploy-image.yaml

Lines changed: 27 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ env:
1010

1111
jobs:
1212
build-and-push-image:
13-
runs-on:
13+
runs-on:
1414
- ubuntu-latest
1515
# - macos-latest
1616
permissions:
@@ -20,32 +20,32 @@ jobs:
2020
steps:
2121
- name: Reset Docker & Buildx
2222
run: |
23-
docker buildx rm || true
24-
docker system prune -af
25-
docker builder prune -af
23+
docker buildx rm || true
24+
docker system prune -af
25+
docker builder prune -af
2626
2727
- name: Free space
2828
run: |
29-
rm -rf /opt/hostedtoolcache
30-
echo "=============================================================================="
31-
echo "Freeing up disk space on CI system"
32-
echo "=============================================================================="
29+
rm -rf /opt/hostedtoolcache
30+
echo "=============================================================================="
31+
echo "Freeing up disk space on CI system"
32+
echo "=============================================================================="
3333
34-
echo "Listing 100 largest packages"
35-
dpkg-query -Wf '${Installed-Size}\t${Package}\n' | sort -n | tail -n 100
36-
df -h
37-
echo "Removing large packages"
38-
sudo apt-get remove -y '^dotnet-.*'
39-
sudo apt-get remove -y '^llvm-.*'
40-
sudo apt-get remove -y 'php.*'
41-
sudo apt-get remove -y azure-cli google-cloud-sdk google-chrome-stable firefox powershell mono-devel
42-
sudo apt-get autoremove -y
43-
sudo apt-get clean
44-
df -h
45-
echo "Removing large directories"
46-
# deleting 15GB
47-
rm -rf /usr/share/dotnet/
48-
df -h
34+
echo "Listing 100 largest packages"
35+
dpkg-query -Wf '${Installed-Size}\t${Package}\n' | sort -n | tail -n 100
36+
df -h
37+
echo "Removing large packages"
38+
sudo apt-get remove -y '^dotnet-.*'
39+
sudo apt-get remove -y '^llvm-.*'
40+
sudo apt-get remove -y 'php.*'
41+
sudo apt-get remove -y azure-cli google-cloud-sdk google-chrome-stable firefox powershell mono-devel
42+
sudo apt-get autoremove -y
43+
sudo apt-get clean
44+
df -h
45+
echo "Removing large directories"
46+
# deleting 15GB
47+
rm -rf /usr/share/dotnet/
48+
df -h
4949
5050
- name: Log in to the Container registry
5151
uses: docker/login-action@v3
@@ -65,8 +65,8 @@ jobs:
6565

6666
- name: Free disk space
6767
run: |
68-
docker system prune -af
69-
docker builder prune -af
68+
docker system prune -af
69+
docker builder prune -af
7070
7171
- name: Debug build context
7272
run: du -sh .
@@ -83,10 +83,10 @@ jobs:
8383

8484
- name: Test
8585
run: docker run --rm ${{ steps.meta.outputs.tags }} python -c "import jax; print(jax.__version__)"
86-
86+
8787
- name: Push
8888
uses: docker/build-push-action@v6
8989
with:
9090
push: true
9191
tags: ${{ steps.meta.outputs.tags }}
92-
labels: ${{ steps.meta.outputs.labels }}
92+
labels: ${{ steps.meta.outputs.labels }}

.gitignore

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,4 +32,4 @@ MANIFEST
3232
# Saved checkpoints
3333
*/NDE_w_Standardization/
3434
*/checkpoints*/
35-
*/sbi-logs/
35+
*/sbi-logs/

.pre-commit-config.yaml

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
exclude: ^(notebooks|logs)/
2+
repos:
3+
- repo: https://github.com/astral-sh/ruff-pre-commit
4+
rev: v0.13.0
5+
hooks:
6+
- id: ruff-check
7+
args: [--fix]
8+
- id: ruff-format
9+
- repo: https://github.com/pre-commit/mirrors-prettier
10+
rev: v3.1.0
11+
hooks:
12+
- id: prettier
13+
args: [--cache]
14+
- repo: https://github.com/pre-commit/pre-commit-hooks
15+
rev: v6.0.0
16+
hooks:
17+
- id: check-case-conflict
18+
description: Check for files that would conflict on a case-insensitive filesystem
19+
- id: check-docstring-first
20+
description: Check that the first line of a Python file is a docstring or a comment
21+
- id: check-merge-conflict
22+
description: Check for merge conflicts
23+
- id: check-toml
24+
description: Check TOML files for syntax errors
25+
- id: end-of-file-fixer
26+
description: Ensure files end with a newline character
27+
- id: mixed-line-ending
28+
args: [--fix=lf]
29+
description: Check for mixed line endings and fix them to LF
30+
- id: trailing-whitespace
31+
description: Check for trailing whitespace and fix it
32+
- id: check-added-large-files
33+
description: Check for large files added to the repository
34+
- id: check-symlinks
35+
description: Check for symbolic links which do not point to anything
36+
- id: detect-private-key
37+
description: Check for private keys in the repository

.readthedocs.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,4 +14,4 @@ python:
1414
- docs
1515

1616
sphinx:
17-
configuration: docs/source/conf.py
17+
configuration: docs/source/conf.py

Dockerfile

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ ENV SHELL /bin/bash
66
# Install system dependencies
77
RUN apt-get update -y --quiet --fix-missing && \
88
apt-get dist-upgrade -y --quiet --fix-missing && \
9-
apt-cache policy autconf && \
9+
apt-cache policy autconf && \
1010
apt-get install -y --quiet \
1111
apt-utils \
1212
autoconf \
@@ -47,4 +47,4 @@ RUN apt-get update -y --quiet --fix-missing && \
4747

4848
RUN pip install --no-cache-dir --upgrade pip && \
4949
pip install --no-cache-dir \
50-
jaxili==0.1.3
50+
jaxili==0.1.3

LICENSE

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,4 +6,4 @@ Permission is hereby granted, free of charge, to any person obtaining a copy of
66

77
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
88

9-
THE SOFTWARE IS PROVIDED “AS IS”, WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
9+
THE SOFTWARE IS PROVIDED “AS IS”, WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

README.md

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,8 @@
22

33
[![Documentation](https://readthedocs.org/projects/jaxili/badge/?version=stable)](https://jaxili.readthedocs.io/en/stable)
44
[![CI Test](https://github.com/sachaguer/jaxili/actions/workflows/ci.yml/badge.svg)]()
5-
[![black](https://img.shields.io/badge/code%20style-black-000000.svg)](https://github.com/psf/black)
6-
[![PyPI](https://img.shields.io/pypi/v/jaxili)](https://pypi.org/project/jaxili/)
5+
[![black](https://img.shields.io/badge/code%20style-black-000000.svg)](https://github.com/psf/black)
6+
[![PyPI](https://img.shields.io/pypi/v/jaxili)](https://pypi.org/project/jaxili/)
77
![[PyPI - License](https://img.shields.io/pypi/l/jaxili)](https://github.com/sachaguer/jaxili/blob/main/LICENSE)
88

99
This is a package to run Neural Density Estimation using Jax. The training is performed using `optax` (documentation available [here](https://optax.readthedocs.io/en/latest/)) and the neural network are created using `flax` (see [documentation](https://flax.readthedocs.io/en/latest/)).
@@ -59,7 +59,6 @@ observation = ... #The observation should have the shape [1, data vector size].
5959
samples = posterior.sample(x=observation, num_samples=..., key=...) #You have to give a PRNGKey and specify the number of samples.
6060
```
6161

62-
6362
## Training a conditional MAF
6463

6564
If you want to control the architecture of the network you can use the following code to train e.g. a Masked Autoregressive Flow (MAF).
@@ -129,14 +128,15 @@ trainer_maf_npe = TrainerModule(
129128
logger_params=logger_params,
130129
debug=debug,
131130
check_val_every_epoch=check_val_every_epoch,
132-
nde_class=nde_class
131+
nde_class=nde_class
133132
)
134133

135134
#Train the Neural Density Estimator
136135
metrics_maf_npe = trainer_maf_npe.train_model(
137136
train_loader, val_loader, test_loader=test_loader, num_epochs=500, patience=20
138137
)
139138
```
139+
140140
The trained model can then be used to sample from or compute the log-probability of the learned distribution:
141141

142142
```python

conda_env.yml

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,5 +3,4 @@ dependencies:
33
- python=3.12
44
- pip
55
- pip:
6-
- jaxili
7-
6+
- jaxili

0 commit comments

Comments
 (0)