Skip to content

Commit d62e73d

Browse files
committed
Merge branch 'dev' of https://github.com/bayesflow-org/bayesflow into dev
2 parents 045df8e + bc4fac9 commit d62e73d

File tree

100 files changed

+2045
-634
lines changed

Some content is hidden

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

100 files changed

+2045
-634
lines changed

.github/workflows/multiversion-docs.yaml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ jobs:
4343
run: |
4444
cd ./repo/docsrc
4545
make clean
46-
make docs-sequential
46+
make production-docs-sequential
4747
4848
- name: Checkout gh-pages-dev
4949
uses: actions/checkout@v3
@@ -55,7 +55,7 @@ jobs:
5555
run: |
5656
cd ./gh-pages-dev
5757
git rm --quiet -rf .
58-
cp -R ../repo/docs/* ./
58+
cp -r ../repo/docs/. ./
5959
git config --local user.email ""
6060
git config --local user.name "github-actions"
6161
git add -A

.github/workflows/style.yaml

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
name: Check Code Style
2+
3+
on:
4+
workflow_dispatch:
5+
pull_request:
6+
branches:
7+
- main
8+
- dev
9+
- update-workflows
10+
push:
11+
branches:
12+
- main
13+
- dev
14+
- update-workflows
15+
16+
jobs:
17+
check-code-style:
18+
name: Check Code Style
19+
20+
runs-on: ubuntu-latest
21+
22+
steps:
23+
- name: Checkout Repository
24+
uses: actions/checkout@v4
25+
26+
- name: Set up Python
27+
uses: actions/setup-python@v5
28+
with:
29+
python-version: "3.10"
30+
31+
- name: Install Ruff
32+
run: |
33+
pip install -U pip setuptools wheel
34+
pip install ruff
35+
36+
- name: Run Linter
37+
run: ruff check --config pyproject.toml --verbose
38+
39+
- name: Run Formatter
40+
run: ruff format --config pyproject.toml --check --verbose

.github/workflows/test-docs.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ jobs:
3131
run: |
3232
cd ./docsrc
3333
make clean
34-
make local
34+
make local-docs
3535
- name: Clean up
3636
run: |
3737
cd ./docsrc

.github/workflows/tests.yaml

Lines changed: 34 additions & 57 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11

2-
name: Tests
2+
name: Multi-Backend Tests
33

44
on:
55
workflow_dispatch:
@@ -12,105 +12,82 @@ on:
1212
- main
1313
- dev
1414

15+
defaults:
16+
run:
17+
shell: bash
1518

16-
jobs:
17-
lint:
18-
runs-on: ubuntu-latest
19-
defaults:
20-
run:
21-
shell: bash -el {0}
22-
23-
steps:
24-
- name: Checkout code
25-
uses: actions/checkout@v4
26-
27-
- name: Set up Conda
28-
uses: conda-incubator/setup-miniconda@v3
29-
with:
30-
environment-file: environment.yaml
31-
python-version: "3.10"
32-
33-
- name: Show Environment Info
34-
run: |
35-
conda info
36-
conda list
37-
conda config --show-sources
38-
conda config --show
39-
printenv | sort
40-
41-
- name: Run Linter
42-
run: |
43-
ruff check --config pyproject.toml --verbose
44-
45-
- name: Run Formatter
46-
run: |
47-
ruff format --check --config pyproject.toml --verbose
4819

20+
jobs:
4921
test:
50-
runs-on: ${{ matrix.os }}
22+
name: Run Multi-Backend Tests
23+
5124
strategy:
52-
fail-fast: false
5325
matrix:
5426
os: [ubuntu-latest, windows-latest]
5527
python-version: ["3.10", "3.11"]
5628
backend: ["jax", "tensorflow", "torch"]
57-
defaults:
58-
run:
59-
shell: bash -el {0}
29+
30+
runs-on: ${{ matrix.os }}
31+
6032
env:
6133
KERAS_BACKEND: ${{ matrix.backend }}
6234

6335
steps:
64-
- name: Checkout code
36+
- name: Checkout Repository
6537
uses: actions/checkout@v4
6638

67-
- name: Set up Conda
68-
uses: conda-incubator/setup-miniconda@v3
39+
- name: Set up Python
40+
uses: actions/setup-python@v5
6941
with:
70-
environment-file: environment.yaml
7142
python-version: ${{ matrix.python-version }}
7243

44+
- name: Install Dependencies
45+
run: |
46+
pip install -U pip setuptools wheel
47+
pip install .[test]
48+
7349
- name: Install JAX
7450
if: ${{ matrix.backend == 'jax' }}
7551
run: |
7652
pip install -U jax
77-
- name: Install NumPy
78-
if: ${{ matrix.backend == 'numpy' }}
79-
run: |
80-
conda install numpy
81-
- name: Install Tensorflow
53+
54+
- name: Install TensorFlow
8255
if: ${{ matrix.backend == 'tensorflow' }}
8356
run: |
8457
pip install -U tensorflow
58+
8559
- name: Install PyTorch
8660
if: ${{ matrix.backend == 'torch' }}
8761
run: |
88-
pip install torch torchvision torchaudio --index-url https://download.pytorch.org/whl/cpu
62+
pip install -U torch torchvision torchaudio --index-url https://download.pytorch.org/whl/cpu
8963
9064
- name: Show Environment Info
9165
run: |
92-
conda info
93-
conda list
94-
conda config --show-sources
95-
conda config --show
66+
python --version
67+
pip --version
9668
printenv | sort
97-
conda env export
9869
pip list
9970
10071
- name: Run Tests
10172
run: |
102-
pytest -x
73+
pytest -x -m "not slow"
10374
104-
- name: Create Coverage Report
75+
- name: Run Slow Tests
76+
# run all slow tests only on manual trigger
77+
if: github.event_name == 'workflow_dispatch'
10578
run: |
106-
coverage xml
79+
pytest -m "slow"
10780
10881
- name: Upload test results to Codecov
10982
if: ${{ !cancelled() }}
110-
uses: codecov/test-results-action@v1
83+
uses: codecov/codecov-action@v4
11184
with:
11285
token: ${{ secrets.CODECOV_TOKEN }}
11386

87+
- name: Create Coverage Report
88+
run: |
89+
coverage xml
90+
11491
- name: Upload Coverage Reports to CodeCov
11592
uses: codecov/codecov-action@v4
11693
with:

CONTRIBUTING.md

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -171,17 +171,17 @@ You can re-build the for your local state with:
171171

172172
```bash
173173
cd docsrc
174-
make clean && make local
174+
make clean && make local-docs
175175
# in case of issues, try `make clean-all`
176176
```
177177

178178
Note that files ignored by git (i.e., listed in `.gitignore`) are not included in the documentation.
179179

180-
We also provide a multi-version documentation. To generate it, run
180+
We also provide a multi-version documentation, which renders the branches `main` and `stable-legacy`. To generate it, run
181181

182182
```bash
183183
cd docsrc
184-
make clean && make docs
184+
make clean && make production-docs
185185
```
186186

187187
This will create and cache virtual environments for the build at `docsrc/.docs_venvs`.

README.md

Lines changed: 11 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ fueled by continuous progress in generative AI and Bayesian inference.
2020
<picture>
2121
<source media="(prefers-color-scheme: dark)" srcset="./img/bayesflow_landing_dark.jpg">
2222
<source media="(prefers-color-scheme: light)" srcset="./img/bayesflow_landing_light.jpg">
23-
<img alt="dsd" src="./img/bayesflow_landing_dark.jpg">
23+
<img alt="Overview graphic on using BayesFlow. It is split in three columns: 1. Choose your backend: BayesFlow is based on Keras, so you can choose PyTorch, TensorFlow or JAX. 2. Define your simulator: You specify your simulator in Python, and use it to generate simulated data. 3. Choose your algorithm: You define a generative neural network that you can use for estimation after training." src="./img/bayesflow_landing_dark.jpg">
2424
</picture>
2525
</div>
2626

@@ -37,14 +37,14 @@ Using the high-level interface is easy, as demonstrated by the minimal working e
3737
import bayesflow as bf
3838

3939
workflow = bf.BasicWorkflow(
40-
inference_network=bf.networks.FlowMatching(),
41-
summary_network=bf.networks.TimeSeriesTransformer(),
40+
inference_network=bf.networks.CouplingFlow(),
41+
summary_network=bf.networks.TimeSeriesNetwork(),
4242
inference_variables=["parameters"],
4343
summary_variables=["observables"],
4444
simulator=bf.simulators.SIR()
4545
)
4646

47-
history = workflow.fit_online(epochs=50, batch_size=32, num_batches_per_epoch=500)
47+
history = workflow.fit_online(epochs=15, batch_size=32, num_batches_per_epoch=200)
4848

4949
diagnostics = workflow.plot_default_diagnostics(test_data=300)
5050
```
@@ -54,7 +54,7 @@ For an in-depth exposition, check out our walkthrough notebooks below.
5454
1. [Linear regression starter example](examples/Linear_Regression_Starter.ipynb)
5555
2. [From ABC to BayesFlow](examples/From_ABC_to_BayesFlow.ipynb)
5656
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)
57+
4. [Rapid iteration with point estimators](examples/Lotka_Volterra_Point_Estimation_and_Expert_Stats.ipynb)
5858
5. [SIR model with custom summary network](examples/SIR_Posterior_Estimation.ipynb)
5959
6. [Bayesian experimental design](examples/Bayesian_Experimental_Design.ipynb)
6060
7. [Simple model comparison example](examples/One_Sample_TTest.ipynb)
@@ -63,12 +63,16 @@ More tutorials are always welcome! Please consider making a pull request if you
6363

6464
## Install
6565

66-
BayesFlow is available to install via pip:
66+
BayesFlow v2 is not yet installable via PyPI, but you can use the following command to install the latest version of the `main` branch:
6767

6868
```bash
69-
pip install bayesflow
69+
pip install git+https://github.com/bayesflow-org/bayesflow.git
7070
```
7171

72+
If you encounter problems with this or require more control, please refer to the instructions to install from source below.
73+
74+
Note: `pip install bayesflow` will install the v1 version of BayesFlow.
75+
7276
### Backend
7377

7478
To use BayesFlow, you will also need to install one of the following machine learning backends.

bayesflow/__init__.py

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -40,9 +40,13 @@ def setup():
4040
torch.autograd.set_grad_enabled(False)
4141

4242
logging.warning(
43-
"Autograd is disabled by default to avoid excessive memory usage. "
44-
"If you need gradients (e.g., custom training loops), use\n"
45-
"with torch.enable_grad():"
43+
"\n"
44+
"When using torch backend, we need to disable autograd by default to avoid excessive memory usage. Use\n"
45+
"\n"
46+
"with torch.enable_grad():\n"
47+
" ...\n"
48+
"\n"
49+
"in contexts where you need gradients (e.g. custom training loops)."
4650
)
4751

4852

bayesflow/adapters/__init__.py

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,8 @@
1+
"""
2+
A collection of :py:class:`~bayesflow.adapters.Adapter` transforms, which tell BayesFlow how to interpret your
3+
:py:class:`~bayesflow.simulators.Simulator` output and plug it into neural networks for training and inference.
4+
"""
5+
16
from . import transforms
27
from .adapter import Adapter
38

0 commit comments

Comments
 (0)