Skip to content

Commit 4fbe3e5

Browse files
committed
Merge remote-tracking branch 'upstream/dev' into dev
2 parents 47f72ab + 46c3c46 commit 4fbe3e5

File tree

181 files changed

+8835
-2340
lines changed

Some content is hidden

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

181 files changed

+8835
-2340
lines changed

.github/workflows/multiversion-docs.yaml

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,6 @@
33
name: multiversion-docs
44

55
on:
6-
pull_request:
7-
branches:
8-
- dev
96
workflow_dispatch:
107
push:
118
branches:
@@ -43,12 +40,12 @@ jobs:
4340
- name: Create local branches
4441
run: |
4542
cd ./dev
46-
git branch master remotes/origin/master
43+
git branch main remotes/origin/main
4744
- name: Make the Sphinx docs
4845
run: |
4946
cd ./dev/docsrc
5047
make clean
51-
make github
48+
make docs-sequential
5249
- name: Commit changes to docs
5350
run: |
5451
cd ./gh-pages-dev

.github/workflows/test-docs.yaml

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
2+
name: test-docs
3+
4+
on:
5+
pull_request:
6+
branches:
7+
- dev
8+
9+
jobs:
10+
build_docs:
11+
runs-on: ubuntu-latest
12+
env:
13+
KERAS_BACKEND: "jax"
14+
15+
steps:
16+
- name: Checkout code
17+
uses: actions/checkout@v4
18+
19+
- name: Set up Python
20+
uses: actions/setup-python@v4
21+
with:
22+
python-version: 3.11
23+
cache: "pip"
24+
25+
- name: Install dependencies
26+
run: |
27+
python -m pip install .[docs]
28+
python -m pip install jax
29+
- name: Make docs from local state
30+
run: |
31+
cd ./docsrc
32+
make clean
33+
make local
34+
- name: Clean up
35+
run: |
36+
cd ./docsrc
37+
make clean-all

.github/workflows/tests.yaml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ on:
55
pull_request:
66
push:
77
branches:
8-
- master
8+
- main
99
- dev
1010
- streamlined-backend
1111

@@ -95,7 +95,7 @@ jobs:
9595
9696
- name: Run Tests
9797
run: |
98-
pytest
98+
pytest -x
9999
100100
- name: Create Coverage Report
101101
run: |

.gitignore

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,10 +6,11 @@ projects/
66
*/bayesflow.egg-info
77
docsrc/_build/
88
docsrc/_build_polyversion
9-
docsrc/.bf_doc_gen_venv
9+
docsrc/.docs_venvs
1010
docsrc/source/api
1111
docsrc/source/_examples
1212
docsrc/source/contributing.md
13+
examples/checkpoints/
1314
build
1415
docs/
1516

.pre-commit-config.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414
repos:
1515
- repo: https://github.com/astral-sh/ruff-pre-commit
1616
# Ruff version.
17-
rev: v0.9.6
17+
rev: v0.9.10
1818
hooks:
1919
# Run the linter.
2020
- id: ruff

CONTRIBUTING.md

Lines changed: 17 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -145,23 +145,37 @@ pip install .[docs]
145145
```
146146

147147
The overall *structure* of the documentation is manually designed, but the API documentation is auto-generated.
148+
New top-level modules (i.e., `bayesflow.mynewmodule`) have to be manually added to the list in `docsrc/source/api/bayesflow.rst` to be included.
148149

149-
You can re-build the current documentation with
150+
You can re-build the for your local state with:
150151

151152
```bash
152153
cd docsrc
153-
make clean && make dev
154+
make clean && make local
154155
# in case of issues, try `make clean-all`
155156
```
156157

158+
Note that files ignored by git (i.e., listed in `.gitignore`) are not included in the documentation.
159+
157160
We also provide a multi-version documentation. To generate it, run
158161

159162
```bash
160163
cd docsrc
161-
make clean && make github
164+
make clean && make docs
162165
```
163166

167+
This will create and cache virtual environments for the build at `docsrc/.docs_venvs`.
168+
To remove them, run `make clean-all` in the `docsrc` directory.
169+
164170
The entry point of the rendered documentation will be at `docs/index.html`.
171+
To view the docs in the browser (which ensures correct redirects), run:
172+
173+
```bash
174+
cd docsrc
175+
make view-docs
176+
```
177+
178+
See `docsrc/README.md` for more details.
165179

166180
Note that undocumented changes will likely be rejected.
167181

README.md

Lines changed: 38 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -4,12 +4,12 @@
44
[![DOI](https://img.shields.io/badge/DOI-10.21105%2Fjoss.05702-blue?style=for-the-badge)](https://doi.org/10.21105/joss.05702)
55
![PyPI - License](https://img.shields.io/pypi/l/bayesflow?style=for-the-badge)
66

7-
BayesFlow is a Python library for simulation-based **Amortized Bayesian Inference** with neural networks.
8-
It provides users with:
7+
BayesFlow 2 is a Python library for simulation-based **Amortized Bayesian Inference** with neural networks.
8+
It provides users and researchers with:
99

1010
- A user-friendly API for rapid Bayesian workflows
1111
- A rich collection of neural network architectures
12-
- Multi-Backend Support via [Keras3](https://keras.io/keras_3/): You can use [PyTorch](https://github.com/pytorch/pytorch), [TensorFlow](https://github.com/tensorflow/tensorflow), or [JAX](https://github.com/google/jax)
12+
- Multi-backend support via [Keras3](https://keras.io/keras_3/): You can use [PyTorch](https://github.com/pytorch/pytorch), [TensorFlow](https://github.com/tensorflow/tensorflow), or [JAX](https://github.com/google/jax)
1313

1414
BayesFlow is designed to be a flexible and efficient tool that enables rapid statistical inference
1515
fueled by continuous progress in generative AI and Bayesian inference.
@@ -29,11 +29,35 @@ neural networks for parameter estimation, model comparison, and model validation
2929
when working with intractable simulators whose behavior as a whole is too
3030
complex to be described analytically.
3131

32-
## Disclaimer
32+
## Getting Started
3333

34-
This is the current dev version of BayesFlow, which constitutes a complete refactor of the library built on Keras 3. This way, you can now use any of the major deep learning libraries as backend for BayesFlow. The refactor is still work in progress with some of the advanced features not yet implemented. We are actively working on them and promise to catch up soon.
34+
Using the high-level interface is easy, as demonstrated by the minimal working example below:
3535

36-
If you encounter any issues, please don't hesitate to open an issue here on [Github](https://github.com/bayesflow-org/bayesflow/issues) or ask questions on our [Discourse Forums](https://discuss.bayesflow.org/).
36+
```python
37+
import bayesflow as bf
38+
39+
workflow = bf.BasicWorkflow(
40+
inference_network=bf.networks.FlowMatching(),
41+
summary_network=bf.networks.TimeSeriesTransformer(),
42+
inference_variables=["parameters"],
43+
summary_variables=["observables"],
44+
simulator=bf.simulators.SIR()
45+
)
46+
47+
history = workflow.fit_online(epochs=50, batch_size=32, num_batches_per_epoch=500)
48+
49+
diagnostics = workflow.plot_default_diagnostics(test_data=300)
50+
```
51+
52+
For an in-depth exposition, check out our walkthrough notebooks below. More tutorials are always welcome!
53+
54+
1. [Linear regression starter example](examples/Linear_Regression_Starter.ipynb)
55+
2. [From ABC to BayesFlow](examples/From_ABC_to_BayesFlow.ipynb)
56+
3. [Two moons starter example](examples/Two_Moons_Starter.ipynb)
57+
4. [Rapid iteration with point estimators](examples/Lotka_Volterra_point_estimation_and_expert_stats.ipynb)
58+
5. [SIR model with custom summary network](examples/SIR_Posterior_Estimation.ipynb)
59+
6. [Bayesian experimental design](examples/Bayesian_Experimental_Design.ipynb)
60+
7. [Simple model comparison example](examples/One_Sample_TTest.ipynb)
3761

3862
## Install
3963

@@ -89,18 +113,9 @@ cd <local-path-to-bayesflow-repository>
89113
conda env create --file environment.yaml --name bayesflow
90114
```
91115

92-
## Getting Started
93-
94-
Check out some of our walk-through notebooks below. We are actively working on porting all notebooks to the new interface so more will be available soon!
116+
## Reporting Issues
95117

96-
1. [Linear regression starter example](examples/Linear_Regression_Starter.ipynb)
97-
2. [From ABC to BayesFlow](examples/From_ABC_to_BayesFlow.ipynb)
98-
3. [Two moons starter example](examples/Two_Moons_Starter.ipynb)
99-
4. [SIR model with custom summary network](examples/SIR_Posterior_Estimation.ipynb)
100-
5. [Hyperparameter optimization](examples/Hyperparameter_Optimization.ipynb)
101-
6. [Bayesian experimental design](examples/Bayesian_Experimental_Design.ipynb)
102-
7. [Simple model comparison example (One-Sample T-Test)](examples/One_Sample_TTest.ipynb)
103-
8. More coming soon...
118+
If you encounter any issues, please don't hesitate to open an issue here on [Github](https://github.com/bayesflow-org/bayesflow/issues) or ask questions on our [Discourse Forums](https://discuss.bayesflow.org/).
104119

105120
## Documentation \& Help
106121

@@ -110,9 +125,8 @@ Documentation is available at https://bayesflow.org. Please use the [BayesFlow F
110125

111126
You can cite BayesFlow along the lines of:
112127

113-
- We approximated the posterior with neural posterior estimation and learned summary statistics (NPE; Radev et al., 2020), as implemented in the BayesFlow software for amortized Bayesian workflows (Radev et al., 2023a).
114-
- We approximated the likelihood with neural likelihood estimation (NLE; Papamakarios et al., 2019) without hand-crafted summary statistics, as implemented in the BayesFlow software for amortized Bayesian workflows (Radev et al., 2023b).
115-
- We performed simultaneous posterior and likelihood estimation with jointly amortized neural approximation (JANA; Radev et al., 2023a), as implemented in the BayesFlow software for amortized Bayesian workflows (Radev et al., 2023b).
128+
- We approximated the posterior using neural posterior estimation (NPE) with learned summary statistics (Radev et al., 2020), as implemented in the BayesFlow framework for amortized Bayesian inference (Radev et al., 2023a).
129+
- We approximated the likelihood using neural likelihood estimation (NLE) without hand-crafted summary statistics (Papamakarios et al., 2019), leveraging its implementation in BayesFlow for efficient and flexible inference.
116130

117131
1. Radev, S. T., Schmitt, M., Schumacher, L., Elsemüller, L., Pratz, V., Schälte, Y., Köthe, U., & Bürkner, P.-C. (2023a). BayesFlow: Amortized Bayesian workflows with neural networks. *The Journal of Open Source Software, 8(89)*, 5702.([arXiv](https://arxiv.org/abs/2306.16015))([JOSS](https://joss.theoj.org/papers/10.21105/joss.05702))
118132
2. Radev, S. T., Mertens, U. K., Voss, A., Ardizzone, L., Köthe, U. (2020). BayesFlow: Learning complex stochastic models with invertible neural networks. *IEEE Transactions on Neural Networks and Learning Systems, 33(4)*, 1452-1466. ([arXiv](https://arxiv.org/abs/2003.06281))([IEEE TNNLS](https://ieeexplore.ieee.org/document/9298920))
@@ -153,6 +167,10 @@ You can cite BayesFlow along the lines of:
153167
}
154168
```
155169

170+
## Awesome Amortized Inference
171+
172+
If you are interested in a curated list of resources, including reviews, software, papers, and other resources related to amortized inference, feel free to explore our [community-driven list](https://github.com/bayesflow-org/awesome-amortized-inference).
173+
156174
## Acknowledgments
157175

158176
This project is currently managed by researchers from Rensselaer Polytechnic Institute, TU Dortmund University, and Heidelberg University. It is partially funded by the Deutsche Forschungsgemeinschaft (DFG, German Research Foundation, Project 528702768). The project is further supported by Germany's Excellence Strategy -- EXC-2075 - 390740016 (Stuttgart Cluster of Excellence SimTech) and EXC-2181 - 390900948 (Heidelberg Cluster of Excellence STRUCTURES), as well as the Informatics for Life initiative funded by the Klaus Tschira Foundation.

assets/benchmark_network_architectures.py

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

bayesflow/__init__.py

Lines changed: 3 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,18 @@
11
from . import (
22
approximators,
3-
benchmarks,
43
adapters,
54
datasets,
65
diagnostics,
76
distributions,
7+
experimental,
88
networks,
99
simulators,
1010
workflows,
1111
utils,
1212
)
13+
1314
from .adapters import Adapter
14-
from .approximators import ContinuousApproximator
15+
from .approximators import ContinuousApproximator, PointApproximator
1516
from .datasets import OfflineDataset, OnlineDataset, DiskDataset
1617
from .simulators import make_simulator
1718
from .workflows import BasicWorkflow
@@ -29,12 +30,6 @@ def setup():
2930
logger = logging.getLogger(__name__)
3031
logger.setLevel(logging.INFO)
3132

32-
if keras.backend.backend() == "torch":
33-
# turn off gradients by default
34-
import torch
35-
36-
torch.autograd.set_grad_enabled(False)
37-
3833
from bayesflow.utils import logging
3934

4035
logging.debug(f"Using backend {keras.backend.backend()!r}")

0 commit comments

Comments
 (0)