From 142ff2f7510e2572823dc7d41fc0699aacca8f28 Mon Sep 17 00:00:00 2001 From: Valentin Pratz Date: Tue, 22 Apr 2025 10:53:55 +0000 Subject: [PATCH 1/7] [no ci] Add advice regarding moving from v1 to v2 to README. Raise awareness regarding missing features and incompatibility between the versions. Similar changes can be made for the docs. --- README.md | 27 +++++++++++++++++++++++++++ 1 file changed, 27 insertions(+) diff --git a/README.md b/README.md index 3f3269754..64bccaff0 100644 --- a/README.md +++ b/README.md @@ -14,6 +14,33 @@ It provides users and researchers with: BayesFlow (version 2+) is designed to be a flexible and efficient tool that enables rapid statistical inference fueled by continuous progress in generative AI and Bayesian inference. +## Migrating from BayesFlow 1.x to BayesFlow 2.0+ + +You are currently looking at BayesFlow 2.0+, which is a complete rewrite of the library. +While it shares the same overall goals with the 1.x versions, the API is not compatible. +You can find the most recent version of BayesFlow 1.x on the `stable-legacy` branch. +The latest [BayesFlow 1.x documentation](https://bayesflow.org/stable-legacy/index.html) can be accessed by selecting the "stable-legacy" entry in the version picker of the documentation. + +> [!CAUTION] +> You should not upgrade (yet) if one of the following applies: +> +> - You have an ongoing project that uses BayesFlow 1.x, and you do not want to allocate time for migrating to the new API. +> - You require a feature that was not ported to BayesFlow 2.0+ yet. To our knowledge, this applies to: +> * Two-level/Hierarchical models: `TwoLevelGenerativeModel`, `TwoLevelPrior`. +> * Sensitivity analysis: functionality from the `bayesflow.sensitivity` module. +> * MCMC (discontinued): The `bayesflow.mcmc` module. We are considering other options to enable the use of BayesFlow in an MCMC setting. +> * Networks: `EvidentialNetwork`. +> * Model misspecification detection: MMD test in the summary space (see #384). +> - You have already trained models in BayesFlow 1.x, that you do not want to re-train with the new version. Loading models from version 1.x in version 2.0+ is not supported. +> +> If you encounter any functionality that is missing and not listed here, please let us know by opening an issue. + +The new version brings many features, like multi-backend support via Keras3, and improved modularity and extensibility. +We recommend to upgrade if none of the above conditions apply. +Continue reading below for installation instructions and examples to get started. +The [Moving from BayesFlow v1.1 to v2.0](examples/From_BayesFlow_1.1_to_2.0.ipynb) guide highlights how concepts and classes relate between the two versions. +For additional information, please refer to the [FAQ](#faq) below. + ## Conceptual Overview
From 9a2f338fcd012fddd33a6e1b923d8b2dd451f496 Mon Sep 17 00:00:00 2001 From: Valentin Pratz Date: Tue, 22 Apr 2025 11:20:22 +0000 Subject: [PATCH 2/7] [no ci] Add link to migration advice to docs, add info about v1 --- docsrc/source/index.md | 3 +++ 1 file changed, 3 insertions(+) diff --git a/docsrc/source/index.md b/docsrc/source/index.md index 36387c8fd..1dd1d5869 100644 --- a/docsrc/source/index.md +++ b/docsrc/source/index.md @@ -10,6 +10,9 @@ It provides users and researchers with: BayesFlow (version 2+) is designed to be a flexible and efficient tool that enables rapid statistical inference fueled by continuous progress in generative AI and Bayesian inference. +To access the documentation for [BayesFlow version 1.x](https://github.com/bayesflow-org/bayesflow/tree/stable-legacy), select `stable-legacy` in the version picker above. +For advice on the migration from version 1.x to version 2+, please refer to the [README](https://github.com/bayesflow-org/bayesflow/blob/main/README.md). + ## Conceptual Overview
From 546f8127e09a39430496b0a96bfd9a3d2a37969f Mon Sep 17 00:00:00 2001 From: Lars Date: Tue, 22 Apr 2025 10:37:51 -0400 Subject: [PATCH 3/7] Hotfix Version 2.0.1 (#431) * fix optimal transport config (#429) * run linter * [skip-ci] bump version to 2.0.1 --- bayesflow/networks/flow_matching/flow_matching.py | 6 +++--- bayesflow/utils/optimal_transport/log_sinkhorn.py | 6 +----- pyproject.toml | 2 +- 3 files changed, 5 insertions(+), 9 deletions(-) diff --git a/bayesflow/networks/flow_matching/flow_matching.py b/bayesflow/networks/flow_matching/flow_matching.py index 65aa25e3f..7a097d340 100644 --- a/bayesflow/networks/flow_matching/flow_matching.py +++ b/bayesflow/networks/flow_matching/flow_matching.py @@ -39,11 +39,11 @@ class FlowMatching(InferenceNetwork): } OPTIMAL_TRANSPORT_DEFAULT_CONFIG = { - "method": "sinkhorn", - "cost": "euclidean", + "method": "log_sinkhorn", "regularization": 0.1, "max_steps": 100, - "tolerance": 1e-4, + "atol": 1e-5, + "rtol": 1e-4, } INTEGRATE_DEFAULT_CONFIG = { diff --git a/bayesflow/utils/optimal_transport/log_sinkhorn.py b/bayesflow/utils/optimal_transport/log_sinkhorn.py index 95ea69eb7..2a65d039e 100644 --- a/bayesflow/utils/optimal_transport/log_sinkhorn.py +++ b/bayesflow/utils/optimal_transport/log_sinkhorn.py @@ -1,7 +1,6 @@ import keras from .. import logging -from ..tensor_utils import is_symbolic_tensor from .euclidean import euclidean @@ -27,9 +26,6 @@ def log_sinkhorn_plan(x1, x2, regularization: float = 1.0, rtol=1e-5, atol=1e-8, log_plan = cost / -(regularization * keras.ops.mean(cost) + 1e-16) - if is_symbolic_tensor(log_plan): - return log_plan - def contains_nans(plan): return keras.ops.any(keras.ops.isnan(plan)) @@ -59,7 +55,7 @@ def do_nothing(): def log_steps(): msg = "Log-Sinkhorn-Knopp converged after {:d} steps." - logging.info(msg, steps) + logging.debug(msg, steps) def warn_convergence(): marginals = keras.ops.logsumexp(log_plan, axis=0) diff --git a/pyproject.toml b/pyproject.toml index 33fdc2786..bdb61fcca 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -4,7 +4,7 @@ build-backend = "setuptools.build_meta" [project] name = "bayesflow" -version = "2.0.0" +version = "2.0.1" authors = [{ name = "The BayesFlow Team" }] classifiers = [ "Development Status :: 5 - Production/Stable", From e590a4313896864c75d6e6e9712a4cc8022970fc Mon Sep 17 00:00:00 2001 From: Valentin Pratz Date: Fri, 25 Apr 2025 11:15:52 +0200 Subject: [PATCH 4/7] [no ci] README: move details on migration to FAQ --- README.md | 62 +++++++++++++++++++++++++++++++++++++------------------ 1 file changed, 42 insertions(+), 20 deletions(-) diff --git a/README.md b/README.md index 64bccaff0..12162dfa3 100644 --- a/README.md +++ b/README.md @@ -18,28 +18,14 @@ fueled by continuous progress in generative AI and Bayesian inference. You are currently looking at BayesFlow 2.0+, which is a complete rewrite of the library. While it shares the same overall goals with the 1.x versions, the API is not compatible. -You can find the most recent version of BayesFlow 1.x on the `stable-legacy` branch. -The latest [BayesFlow 1.x documentation](https://bayesflow.org/stable-legacy/index.html) can be accessed by selecting the "stable-legacy" entry in the version picker of the documentation. > [!CAUTION] -> You should not upgrade (yet) if one of the following applies: -> -> - You have an ongoing project that uses BayesFlow 1.x, and you do not want to allocate time for migrating to the new API. -> - You require a feature that was not ported to BayesFlow 2.0+ yet. To our knowledge, this applies to: -> * Two-level/Hierarchical models: `TwoLevelGenerativeModel`, `TwoLevelPrior`. -> * Sensitivity analysis: functionality from the `bayesflow.sensitivity` module. -> * MCMC (discontinued): The `bayesflow.mcmc` module. We are considering other options to enable the use of BayesFlow in an MCMC setting. -> * Networks: `EvidentialNetwork`. -> * Model misspecification detection: MMD test in the summary space (see #384). -> - You have already trained models in BayesFlow 1.x, that you do not want to re-train with the new version. Loading models from version 1.x in version 2.0+ is not supported. -> -> If you encounter any functionality that is missing and not listed here, please let us know by opening an issue. - -The new version brings many features, like multi-backend support via Keras3, and improved modularity and extensibility. -We recommend to upgrade if none of the above conditions apply. -Continue reading below for installation instructions and examples to get started. -The [Moving from BayesFlow v1.1 to v2.0](examples/From_BayesFlow_1.1_to_2.0.ipynb) guide highlights how concepts and classes relate between the two versions. -For additional information, please refer to the [FAQ](#faq) below. +> A few features, most notably hierarchical models, have not been ported to BayesFlow 2.0+ +> yet. We are working on those features and plan to add them soon. You can find the complete +> list in the [FAQ](#faq) below. + +The [Moving from BayesFlow v1.1 to v2.0](examples/From_BayesFlow_1.1_to_2.0.ipynb) guide +highlights how concepts and classes relate between the two versions. ## Conceptual Overview @@ -242,11 +228,47 @@ while the old version was based on TensorFlow. ------------- +**Question:** +Should I switch to BayesFlow 2.0+ now? Are there features that are still missing? + +**Answer:** +In general, we recommend to switch, as the new version is easier to use and will continue +to receive improvements and new features. However, a few features are still missing, so you +might want to wait until everything you need has been ported to BayesFlow 2.0+. + +Depending on your needs, you might not want to upgrade yet if one of the following applies: + +- You have an ongoing project that uses BayesFlow 1.x, and you do not want to allocate + time for migrating it to the new API. +- You have already trained models in BayesFlow 1.x, that you do not want to re-train + with the new version. Loading models from version 1.x in version 2.0+ is not supported. +- You require a feature that was not ported to BayesFlow 2.0+ yet. To our knowledge, + this applies to: + * Two-level/Hierarchical models: `TwoLevelGenerativeModel`, `TwoLevelPrior`. + * Sensitivity analysis: functionality from the `bayesflow.sensitivity` module. + * MCMC (discontinued): The `bayesflow.mcmc` module. We are considering other options + to enable the use of BayesFlow in an MCMC setting. + * Networks: `EvidentialNetwork`. + * Model misspecification detection: MMD test in the summary space (see #384). + +If you encounter any functionality that is missing and not listed here, please let us +know by opening an issue. + +------------- + **Question:** I still need the old BayesFlow for some of my projects. How can I install it? **Answer:** You can find and install the old Bayesflow version via the `stable-legacy` branch on GitHub. +The corresponding [documentation](https://bayesflow.org/stable-legacy/index.html) can be +accessed by selecting the "stable-legacy" entry in the version picker of the documentation. + +You can also install the latest version of BayesFlow v1.x from PyPI using + +``` +$ pip install "bayesflow<2.0" +``` ------------- From 076ceafe8049f127bc132355e4baf763eb95779f Mon Sep 17 00:00:00 2001 From: Valentin Pratz Date: Fri, 25 Apr 2025 09:19:25 +0000 Subject: [PATCH 5/7] [no ci] Change heading on migration section --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index 12162dfa3..68ea950da 100644 --- a/README.md +++ b/README.md @@ -14,7 +14,7 @@ It provides users and researchers with: BayesFlow (version 2+) is designed to be a flexible and efficient tool that enables rapid statistical inference fueled by continuous progress in generative AI and Bayesian inference. -## Migrating from BayesFlow 1.x to BayesFlow 2.0+ +## Important Note for Existing Users You are currently looking at BayesFlow 2.0+, which is a complete rewrite of the library. While it shares the same overall goals with the 1.x versions, the API is not compatible. From 53dda82c7849b1ccfa21431ad1d440f9b7d01b39 Mon Sep 17 00:00:00 2001 From: Valentin Pratz Date: Fri, 25 Apr 2025 09:20:58 +0000 Subject: [PATCH 6/7] [no ci] docs: remove $ prefix from v1 install command --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index 68ea950da..a147dbf4d 100644 --- a/README.md +++ b/README.md @@ -267,7 +267,7 @@ accessed by selecting the "stable-legacy" entry in the version picker of the doc You can also install the latest version of BayesFlow v1.x from PyPI using ``` -$ pip install "bayesflow<2.0" +pip install "bayesflow<2.0" ``` ------------- From 86f2f5b31cb2f62847b0f5322bc4730ef8344c01 Mon Sep 17 00:00:00 2001 From: LarsKue Date: Fri, 25 Apr 2025 14:18:12 -0400 Subject: [PATCH 7/7] reintroduce symbolic tensor check in log_sinkhorn --- bayesflow/utils/optimal_transport/log_sinkhorn.py | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/bayesflow/utils/optimal_transport/log_sinkhorn.py b/bayesflow/utils/optimal_transport/log_sinkhorn.py index 2a65d039e..3538eaeff 100644 --- a/bayesflow/utils/optimal_transport/log_sinkhorn.py +++ b/bayesflow/utils/optimal_transport/log_sinkhorn.py @@ -1,6 +1,7 @@ import keras from .. import logging +from ..tensor_utils import is_symbolic_tensor from .euclidean import euclidean @@ -26,6 +27,9 @@ def log_sinkhorn_plan(x1, x2, regularization: float = 1.0, rtol=1e-5, atol=1e-8, log_plan = cost / -(regularization * keras.ops.mean(cost) + 1e-16) + if is_symbolic_tensor(log_plan): + return log_plan + def contains_nans(plan): return keras.ops.any(keras.ops.isnan(plan))