Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

use ruff for linting and formatting, update CI #978

Merged
merged 21 commits into from
Mar 12, 2024
Merged
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
45 changes: 26 additions & 19 deletions .github/workflows/tests.yml
Original file line number Diff line number Diff line change
@@ -1,40 +1,47 @@
name: Tests
name: Continuous Integration

on:
push:
branches:
- main
pull_request:
branches:
- main
workflow_dispatch:

jobs:
build:
pre-commit:
name: ruff and hooks.
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- uses: actions/setup-python@v5
with:
python-version: '3.8'
- uses: pre-commit/[email protected]
with:
extra_args: --all-files

test:
name: Tests
runs-on: ubuntu-20.04
runs-on: ubuntu-latest
strategy:
fail-fast: false
matrix:
python-version: ["3.8"]
torch-version: ["1.11", "2.2"]

steps:
- uses: actions/checkout@v3
- uses: actions/checkout@v4
with:
lfs: true

- uses: actions/setup-python@v4
- uses: actions/setup-python@v5
with:
python-version: '3.9.13'
architecture: 'x64'
python-version: ${{ matrix.python-version }}

- name: Install dependencies
run: |
python -m pip install --upgrade pip
pip install torch==${{ matrix.torch-version }} --extra-index-url https://download.pytorch.org/whl/cpu
pip install -e .[dev]

- name: Check formatting with black
run: |
black --check sbi tests

- name: Check imports with isort
run: |
isort -c sbi tests

- name: Check types with pyright
run: |
Expand All @@ -45,7 +52,7 @@ jobs:
pip install torchtestcase
pip install pytest pytest-cov
pytest -m "not slow and not gpu" tests/ --cov=sbi --cov-report=xml

- name: Upload coverage to Codecov
uses: codecov/codecov-action@v3
with:
Expand Down
30 changes: 17 additions & 13 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
@@ -1,14 +1,18 @@
repos:
- repo: https://github.com/asottile/seed-isort-config
rev: v2.2.0
hooks:
- id: seed-isort-config
- repo: https://github.com/PyCQA/isort
rev: 5.13.2
hooks:
- id: isort
- repo: https://github.com/ambv/black
rev: 24.2.0
hooks:
- id: black
language_version: python3
- repo: https://github.com/astral-sh/ruff-pre-commit
rev: v0.2.2
hooks:
- id: ruff
- id: ruff-format
args: [--diff]
- repo: https://github.com/pre-commit/pre-commit-hooks
rev: v4.5.0
hooks:
- id: check-added-large-files
- id: check-merge-conflict
- id: check-toml
- id: check-yaml
- id: end-of-file-fixer
- id: mixed-line-ending
args: [--fix=lf]
- id: trailing-whitespace
2 changes: 1 addition & 1 deletion MANIFEST.in
Original file line number Diff line number Diff line change
Expand Up @@ -15,4 +15,4 @@ recursive-include docs *.py
recursive-include examples *.py
recursive-include sbi *.md
recursive-include tests *.md
recursive-include tests *.py
recursive-include tests *.py
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ The following algorithms are currently available. You can find a tutorial on how
### Neural Posterior Estimation: amortized (NPE) and sequential (SNPE)

* [`SNPE_A`](https://sbi-dev.github.io/sbi/reference/#sbi.inference.snpe.snpe_a.SNPE_A) (including amortized single-round `NPE`) from Papamakarios G and Murray I [_Fast ε-free Inference of Simulation Models with Bayesian Conditional Density Estimation_](https://proceedings.neurips.cc/paper/2016/hash/6aca97005c68f1206823815f66102863-Abstract.html) (NeurIPS 2016).

* [`SNPE_C`](https://sbi-dev.github.io/sbi/reference/#sbi.inference.snpe.snpe_c.SNPE_C) or `APT` from Greenberg D, Nonnenmacher M, and Macke J [_Automatic
Posterior Transformation for likelihood-free
inference_](https://arxiv.org/abs/1905.07488) (ICML 2019).
Expand Down Expand Up @@ -108,7 +108,7 @@ M. Durkan's `lfi`. `sbi` runs as a community project. See also [credits](https:/

## Citation

If you use `sbi` consider citing the [sbi software paper](https://doi.org/10.21105/joss.02505), in addition to the original research articles describing the specific sbi-algorithm(s) you are using.
If you use `sbi` consider citing the [sbi software paper](https://doi.org/10.21105/joss.02505), in addition to the original research articles describing the specific sbi-algorithm(s) you are using.

```latex
@article{tejero-cantero2020sbi,
Expand Down
2 changes: 1 addition & 1 deletion docs/docs/citation.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# Citation

If you use `sbi` consider citing the [sbi software paper](https://doi.org/10.21105/joss.02505), in addition to the original research articles describing the specific sbi-algorithm(s) you are using.
If you use `sbi` consider citing the [sbi software paper](https://doi.org/10.21105/joss.02505), in addition to the original research articles describing the specific sbi-algorithm(s) you are using.

```latex
@article{tejero-cantero2020sbi,
Expand Down
4 changes: 2 additions & 2 deletions docs/docs/faq/question_01_leakage.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ collect the remaining 10000 samples. Consider interrupting (Ctrl-C) and switchin

The reason for this issue is described in more detail
[here](https://arxiv.org/abs/2002.03712) and
[here](https://arxiv.org/abs/1905.07488). The following fixes are possible:
[here](https://arxiv.org/abs/1905.07488). The following fixes are possible:

- sample with MCMC: `samples = posterior((num_samples,), x=x_o, sample_with_mcmc=True)`.
This approach will make sampling slower, but samples will not "leak".
Expand All @@ -26,4 +26,4 @@ interface](https://sbi-dev.github.io/sbi/tutorial/03_flexible_interface/), set
statement "Using SNPE-C with non-atomic loss".

- use a different algorithm, e.g., SNRE and SNLE. Note, however, that these algorithms
can have different issues and potential pitfalls.
can have different issues and potential pitfalls.
4 changes: 2 additions & 2 deletions docs/docs/faq/question_07_custom_prior.md
Original file line number Diff line number Diff line change
Expand Up @@ -71,8 +71,8 @@ pass the bounds to the wrapper function such that `sbi` can pass them to torch
from sbi.utils import process_prior

custom_prior = CustomUniformPrior(torch.zeros(2), torch.ones(2))
prior = process_prior(custom_prior,
custom_prior_wrapper_kwargs=dict(lower_bound=torch.zeros(2),
prior = process_prior(custom_prior,
custom_prior_wrapper_kwargs=dict(lower_bound=torch.zeros(2),
janfb marked this conversation as resolved.
Show resolved Hide resolved
upper_bound=torch.ones(2)))
# use this wrapped prior in sbi...
```
Expand Down
2 changes: 1 addition & 1 deletion docs/docs/reference.md
Original file line number Diff line number Diff line change
Expand Up @@ -153,7 +153,7 @@
selection:
filters: [ "!^_", "^__", "!^__class__" ]
inherited_members: true

## Analysis

::: sbi.analysis.plot.pairplot
Expand Down
4 changes: 2 additions & 2 deletions docs/docs/static/global.css
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ a[title="Edit this page"] {
}

.md-typeset .footnote-ref:before {
border-left: none !important;
border-left: none !important;
margin-left: -0.4em !important;
}

Expand Down Expand Up @@ -62,4 +62,4 @@ td p {
/* 100% width tables */
.md-typeset__table {
width: 100%;
}
}
8 changes: 4 additions & 4 deletions docs/mkdocs.yml
Original file line number Diff line number Diff line change
Expand Up @@ -21,14 +21,14 @@ nav:
- Diagnostics:
- Posterior predictive checks: tutorial/12_diagnostics_posterior_predictive_check.md
- Simulation-based calibration: tutorial/13_diagnostics_simulation_based_calibration.md
- Density plots and MCMC diagnostics with ArviZ: tutorial/15_mcmc_diagnostics_with_arviz.md
- Density plots and MCMC diagnostics with ArviZ: tutorial/15_mcmc_diagnostics_with_arviz.md
- Analysis:
- Conditional distributions: tutorial/07_conditional_distributions.md
- Posterior sensitivity analysis: tutorial/09_sensitivity_analysis.md
- Examples:
- Hodgkin-Huxley example: examples/00_HH_simulator.md
- Decision making model: examples/01_decision_making_model.md
- Contributing:
- Contributing:
- Guide: contribute.md
- Code of Conduct: code_of_conduct.md
- API Reference: reference.md
Expand Down Expand Up @@ -70,7 +70,7 @@ markdown_extensions:
- pymdownx.critic
- pymdownx.details
- pymdownx.emoji:
emoji_generator: !!python/name:pymdownx.emoji.to_svg
emoji_generator: tag:yaml.org,2002:python/name:pymdownx.emoji.to_svg
- pymdownx.inlinehilite
- pymdownx.magiclink
- pymdownx.mark
Expand All @@ -89,7 +89,7 @@ plugins:
rendering:
show_source: true
heading_level: 3

watch:
- ../sbi

Expand Down
Loading
Loading