Skip to content

Commit 69f17c1

Browse files
authored
Move to UV (#60)
This PR moves from using `hatch` to `uv` as a build system. While Hatch is great, e.g., due to its version management, there are some things that are not particularly practical: - The envs are per default not installed locally but to some arcane location that can be hard to find for users. - Having multiple separate envs is great for larger packages, but a bit too much for a package of this size. - There is no way to automatically add packages as dependencies. `uv` on the other hand - makes it easy to replicate the exact versions that are used during development, - has only one base env containing all dependencies, - is very fast, - and is imho easier to learn and use.
1 parent 41bc24e commit 69f17c1

66 files changed

Lines changed: 9031 additions & 5528 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/ci.yaml

Lines changed: 13 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -8,75 +8,57 @@ on:
88

99
jobs:
1010
precommit:
11-
name: Pre-commit checks
1211
runs-on: ubuntu-latest
1312
steps:
1413
- uses: actions/checkout@v3
1514
- uses: actions/setup-python@v3
1615
- uses: pre-commit/action@v3.0.0
1716

18-
build:
19-
runs-on: ubuntu-latest
20-
needs:
21-
- precommit
22-
strategy:
23-
matrix:
24-
python-version: [3.11]
25-
steps:
26-
- uses: actions/checkout@v3
27-
- name: Set up Python ${{ matrix.python-version }}
28-
uses: actions/setup-python@v3
29-
with:
30-
python-version: ${{ matrix.python-version }}
31-
- name: Install dependencies
32-
run: |
33-
pip install hatch
34-
- name: Build package
35-
run: |
36-
hatch build
37-
3817
lints:
3918
runs-on: ubuntu-latest
4019
needs:
4120
- precommit
4221
strategy:
4322
matrix:
44-
python-version: [3.11]
23+
python-version: [ 3.12, 3.13 ]
4524
steps:
4625
- uses: actions/checkout@v3
4726
- name: Set up Python ${{ matrix.python-version }}
4827
uses: actions/setup-python@v3
4928
with:
5029
python-version: ${{ matrix.python-version }}
30+
- uses: astral-sh/setup-uv@v5
31+
with:
32+
version: "latest"
5133
- name: Install dependencies
5234
run: |
53-
pip install hatch
35+
uv sync --all-groups
5436
- name: Run lints
5537
run: |
56-
hatch run test:lint
38+
make lints
5739
5840
tests:
5941
runs-on: ubuntu-latest
6042
needs:
61-
- precommit
43+
- lints
6244
strategy:
6345
matrix:
64-
python-version: [3.11]
46+
python-version: [ 3.12, 3.13 ]
6547
steps:
6648
- uses: actions/checkout@v3
6749
- name: Set up Python ${{ matrix.python-version }}
6850
uses: actions/setup-python@v3
6951
with:
7052
python-version: ${{ matrix.python-version }}
53+
- uses: astral-sh/setup-uv@v5
54+
with:
55+
version: "latest"
7156
- name: Install dependencies
7257
run: |
73-
pip install hatch
74-
- name: Build package
75-
run: |
76-
pip install jaxlib jax
58+
uv sync
7759
- name: Run tests
7860
run: |
79-
hatch run test:test
61+
make tests
8062
- name: Upload coverage reports to Codecov
8163
uses: codecov/codecov-action@v3
8264
env:

.github/workflows/examples.yaml

Lines changed: 17 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -19,31 +19,30 @@ jobs:
1919
- precommit
2020
strategy:
2121
matrix:
22-
python-version: [3.11]
22+
python-version: [ 3.12, 3.13 ]
2323
steps:
2424
- uses: actions/checkout@v3
2525
- name: Set up Python ${{ matrix.python-version }}
2626
uses: actions/setup-python@v3
2727
with:
2828
python-version: ${{ matrix.python-version }}
29+
- uses: astral-sh/setup-uv@v5
30+
with:
31+
version: "latest"
2932
- name: Install dependencies
3033
run: |
31-
pip install hatch matplotlib
32-
- name: Build package
33-
run: |
34-
pip install jaxlib jax
35-
pip install .
34+
uv sync --all-groups
3635
- name: Run tests
3736
run: |
38-
python examples/gaussian_linear-aio.py --n-iter 10
39-
python examples/gaussian_linear-smcabc.py --n-rounds 1
40-
python examples/mixture_model-cmpe.py --n-iter 10
41-
python examples/mixture_model-nle.py --n-iter 10
42-
python examples/mixture_model-nle.py --n-iter 10 --use-spf
43-
python examples/mixture_model-npe.py --n-iter 10
44-
python examples/mixture_model-nre.py --n-iter 10
45-
python examples/mixture_model-npse.py --n-iter 10
46-
python examples/slcp-fmpe.py --n-iter 10
47-
python examples/slcp-nass_nle.py --n-iter 10 --n-rounds 1
48-
python examples/slcp-nass_smcabc.py --n-iter 10 --n-rounds 1
49-
python examples/slcp-snle.py --n-iter 10 --n-rounds 1
37+
uv run python examples/gaussian_linear-aio.py --n-iter 10
38+
uv run python examples/gaussian_linear-smcabc.py --n-rounds 1
39+
uv run python examples/mixture_model-cmpe.py --n-iter 10
40+
uv run python examples/mixture_model-nle.py --n-iter 10
41+
uv run python examples/mixture_model-nle.py --n-iter 10 --use-spf
42+
uv run python examples/mixture_model-npe.py --n-iter 10
43+
uv run python examples/mixture_model-nre.py --n-iter 10
44+
uv run python examples/mixture_model-npse.py --n-iter 10
45+
uv run python examples/slcp-fmpe.py --n-iter 10
46+
uv run python examples/slcp-nass_nle.py --n-iter 10 --n-rounds 1
47+
uv run python examples/slcp-nass_smcabc.py --n-iter 10 --n-rounds 1
48+
uv run python examples/slcp-snle.py --n-iter 10 --n-rounds 1

.python-version

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
3.12.10

.readthedocs.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ version: 2
33
build:
44
os: ubuntu-22.04
55
tools:
6-
python: "3.11"
6+
python: "3.12"
77

88
sphinx:
99
builder: html

Makefile

Lines changed: 8 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,14 @@
1-
.PHONY: tag
2-
.PHONY: tests
3-
.PHONY: lints
4-
.PHONY: docs
5-
.PHONY: format
6-
7-
PKG_VERSION=`hatch version`
8-
9-
tag:
10-
git tag -a v${PKG_VERSION} -m v${PKG_VERSION}
11-
git push --tag
1+
.PHONY: tests, lints, docs, format
122

133
tests:
14-
hatch run test:test
4+
uv run pytest
155

166
lints:
17-
hatch run test:lint
7+
uv run ruff check sbijax examples
188

199
format:
20-
hatch run test:format
10+
uv run ruff check --fix sbijax examples
11+
uv run ruff format sbijax examples
12+
13+
docs:
14+
cd docs && make html

README.md

Lines changed: 12 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -83,11 +83,18 @@ Contributions in the form of pull requests are more than welcome. A good way to
8383

8484
In order to contribute:
8585

86-
1) Clone `sbijax` and install `hatch` via `pip install hatch`,
87-
2) create a new branch locally `git checkout -b feature/my-new-feature` or `git checkout -b issue/fixes-bug`,
88-
3) implement your contribution and ideally a test case,
89-
4) test it by calling `make tests`, `make lints` and `make format` on the (Unix) command line,
90-
5) submit a PR 🙂
86+
1) Clone `sbijax` and install `uv` from [here](https://docs.astral.sh/uv/getting-started/installation/).
87+
2) Install all dependencies using `uv sync --all-groups`.
88+
3) Install `pre-commit` and `gitlint` via:
89+
90+
```shell
91+
pre-commit install
92+
gitlint install-hook
93+
```
94+
4) Create a new branch locally `git checkout -b feature/my-new-feature` or `git checkout -b issue/fixes-bug`.
95+
5) Implement your contribution and ideally a test case.
96+
6) Test it by calling `make tests`, `make lints` and `make format` on the (Unix) command line.
97+
7) Submit a PR 🙂.
9198

9299
## Citing sbijax
93100

docs/index.rst

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -79,11 +79,12 @@ Contributions in the form of pull requests are more than welcome. A good way to
7979

8080
In order to contribute:
8181

82-
1) Clone :code:`sbijax` and install :code:`hatch` via :code:`pip install hatch`,
83-
2) create a new branch locally :code:`git checkout -b feature/my-new-feature` or :code:`git checkout -b issue/fixes-bug`,
84-
3) implement your contribution and ideally a test case,
85-
4) test it by calling ``make tests``, ``make lints`` and ``make format`` on the (Unix) command line,
86-
5) submit a PR 🙂
82+
1) Clone :code:`sbijax` and install :code:`uv` from `here <https://docs.astral.sh/uv/getting-started/installation/>`_,
83+
2) install all dependencies using ```uv sync``,
84+
3) create a new branch locally :code:`git checkout -b feature/my-new-feature` or :code:`git checkout -b issue/fixes-bug`,
85+
4) implement your contribution and ideally a test case,
86+
5) test it by calling ``make tests``, ``make lints`` and ``make format`` on the (Unix) command line,
87+
6) submit a PR 🙂
8788

8889
Acknowledgements
8990
----------------
@@ -102,7 +103,6 @@ License
102103
:hidden:
103104

104105
🏡 Home <self>
105-
📰 News <news>
106106
📚 References <references>
107107

108108
.. toctree::

docs/news.rst

Lines changed: 0 additions & 8 deletions
This file was deleted.

examples/gaussian_linear-smcabc.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -37,13 +37,13 @@ def distance_fn(y_simulated, y_observed):
3737

3838

3939
def run(n_rounds):
40-
y_observed = jnp.array([-2.0, 1.0])
40+
y_observed = jnp.array([-1.0, 1.0])
4141

4242
fns = prior_fn, simulator_fn
4343

4444
smc = SMCABC(fns, summary_fn, distance_fn)
4545
smc_samples, _ = smc.sample_posterior(
46-
jr.PRNGKey(1), y_observed, n_rounds=n_rounds, n_particles=1000, ess_min=500
46+
jr.PRNGKey(1), y_observed, n_rounds=1, n_particles=1000, ess_min=500, eps_step=0.9
4747
)
4848
plot_posterior(smc_samples)
4949
plt.show()

examples/mixture_model-cmpe.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414

1515
def prior_fn():
1616
prior = tfd.JointDistributionNamed(dict(
17-
theta=tfd.Normal(jnp.zeros(2), 1)
17+
theta=tfd.Normal(jnp.zeros(2), jnp.array(1.0))
1818
), batch_ndims=0)
1919
return prior
2020

0 commit comments

Comments
 (0)