Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
37 changes: 37 additions & 0 deletions .github/workflows/tests.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
name: tests

on:
push:
branches: [main]
pull_request:

concurrency:
group: tests-${{ github.ref }}
cancel-in-progress: true

jobs:
pytest:
runs-on: ubuntu-latest
timeout-minutes: 30
steps:
- uses: actions/checkout@v4

- name: Install uv
uses: astral-sh/setup-uv@v6
with:
enable-cache: true
# uv.lock is not tracked, so key the cache on pyproject.toml
cache-dependency-glob: pyproject.toml

- name: Install dependencies (CPU)
run: uv sync --extra cpu

- name: Run tests
run: uv run pytest -n auto --junitxml=report.xml

- name: Upload test report
if: always()
uses: actions/upload-artifact@v4
with:
name: pytest-report
path: report.xml
18 changes: 17 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,23 @@ This will create a Python virtual environment at `./.venv`, install the pinned P
./run_tests.sh
```

### Testing

Tests are written with [pytest](https://pytest.org) and live in `tests/`. Each network has a single test file (e.g. `test_plnet.py`, `test_bilipschitz_ren.py`) whose tests run against both the JAX/Flax and PyTorch implementations through the `backend` fixture (see `tests/backends.py`). Tests for networks or features that only exist in JAX use the `jax_backend` fixture, and the PyTorch side is skipped with a `TODO(torch)` note in the file. `./run_tests.sh` is a thin wrapper around `uv run pytest`, so any pytest arguments work:

```bash
./run_tests.sh # everything
./run_tests.sh -m torch # PyTorch tests only (or -m jax)
./run_tests.sh -n auto # run in parallel
./run_tests.sh -k plnet # select by name
```

Besides property tests (output shapes, inverse round-trips, Lipschitz bounds, gradients, error handling), every network is checked against **golden input/output files** in `tests/golden/<network>.json`. Each case stores the constructor arguments, the (unconstrained) parameters, some inputs, and the expected outputs. The JAX and PyTorch tests both load the same file, so if both pass, the two implementations agree with each other. Networks that only exist in JAX (e.g. `LBDN`, the contracting/Lipschitz/general RENs, the linear RENs and the R2DN) are checked against their golden files too, which guards against regressions when refactoring.

Golden files are generated from the JAX implementation with `uv run python tests/generate_golden.py [network ...]`. Only regenerate them deliberately (a new case, or an intended change to a network) and review the diff.

The same suite runs on every push to `main` and every pull request through GitHub Actions (`.github/workflows/tests.yml`, CPU only).

### A Note on Dependencies

Dependencies are declared in `pyproject.toml` and are split into two sets:
Expand All @@ -46,7 +63,6 @@ By default, the `install.sh` script installs both the core and extra dependencie
```bash
uv sync --extra cpu # CPU only
uv sync --extra cuda13 # GPU with CUDA 13
```

## Running an Example

Expand Down
17 changes: 17 additions & 0 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,13 @@ examples = [
"cycler>=0.12.1",
]

[dependency-groups]
dev = [
"pytest>=8",
"pytest-xdist>=3",
"optax>=0.2.8",
]

[build-system]
requires = ["uv_build>=0.12.5,<0.13"]
build-backend = "uv_build"
Expand Down Expand Up @@ -82,3 +89,13 @@ torch = [
{ index = "pytorch-cpu", extra = "cpu" },
{ index = "pytorch-cu130", extra = "cuda13"},
]

[tool.pytest.ini_options]
testpaths = ["tests"]
pythonpath = ["tests"]
addopts = "-ra --strict-markers --import-mode=importlib"
markers = [
"jax: tests for the JAX/Flax implementations",
"torch: tests for the PyTorch implementations",
"slow: slow tests (e.g. optimisation-based Lipschitz estimates)",
]
10 changes: 4 additions & 6 deletions run_tests.sh
Original file line number Diff line number Diff line change
@@ -1,9 +1,7 @@
#!/bin/bash
# Run the test suite. Extra arguments are passed to pytest, e.g.
# ./run_tests.sh -k torch
# ./run_tests.sh -m jax -n auto
set -euo pipefail

uv run python test/test_lbdn.py
uv run python test/test_linren.py
uv run python test/test_ren.py
uv run python test/test_r2dn.py
uv run python test/test_bilipren.py
uv run python test/test_bilipren_torch.py
uv run pytest "$@"
89 changes: 0 additions & 89 deletions test/plnet/bilipnet_test.py

This file was deleted.

67 changes: 0 additions & 67 deletions test/plnet/monlipnet_test.py

This file was deleted.

39 changes: 0 additions & 39 deletions test/plnet/orthogonal_test.py

This file was deleted.

Loading
Loading