Skip to content

v2.0.3 #460

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

Merged
merged 55 commits into from
May 5, 2025
Merged

v2.0.3 #460

merged 55 commits into from
May 5, 2025

Conversation

LarsKue
Copy link
Contributor

@LarsKue LarsKue commented May 5, 2025

Important Note:

Due to changes in the serialization pipeline, this release is not backward-compatible with v2.0.2. You will likely not be able to load models created in v2.0.2 or lower.


This pull request introduces significant updates to the BayesFlow library, focusing on API enhancements, backward compatibility considerations, and improved functionality for transforms. The changes include updates to the documentation to guide users transitioning to version 2.0+, adjustments to the initialization process, and the addition of new features to various transform classes, such as support for log-determinant Jacobian calculations.

Documentation Updates

  • Added detailed notes in README.md to inform users about breaking changes introduced in BayesFlow 2.0+, missing features (e.g., hierarchical models, MCMC), and guidance for migrating from version 1.x. [1] [2]

Core Enhancements

  • Simplified the __version__ attribute initialization in bayesflow/__init__.py by dynamically assigning it using importlib.metadata.version. Removed exception handling for unsupported packages.

Transform Enhancements

  • Added support for log_det_jac (log-determinant of the Jacobian) calculations to several transform classes, including Constrain, Concatenate, and Drop. This enables better handling of transformations in probabilistic models. [1] [2] [3]
  • Updated the forward and inverse methods in Adapter to optionally return the log-determinant Jacobian alongside transformed data. [1] [2]

Serialization Improvements

  • Updated the @serializable decorator across multiple transform classes (e.g., AsSet, Broadcast, Constrain) to include a namespace argument ("bayesflow.adapters"), improving serialization consistency. [1] [2] [3]

These changes collectively improve the usability, extensibility, and robustness of the BayesFlow library, particularly for users transitioning to version 2.0+ and those working with advanced transformations.

vpratz and others added 30 commits April 22, 2025 11:01
Raise awareness regarding missing features and incompatibility between
the versions. Similar changes can be made for the docs.
…ent code

Torch is very slow, so I had to increase the timeout accordingly.
* summary networks: add tests for using functional API

* fix build functions for use with functional API
* fix docs of coupling flow

* add additional tests
In addition, this PR limits the slow test to Windows and Python 3.10.
The choices are somewhat arbitrary, my thought was to test the setup not
covered as much through use by the devs.
…move update-workflows branch from workflow style tests, add __init__ and conftest to test_point_approximators (#443)
* implement compile_from_config and get_compile_config

* add optimizer build to compile_from_config
* remove the is_symbolic_tensor check because this would otherwise skip the whole function for compiled contexts

* skip pyabc test

* fix sinkhorn and log_sinkhorn message formatting for jax by making the warning message worse
* Hotfix Version 2.0.1 (#431)

* fix optimal transport config (#429)

* run linter

* [skip-ci] bump version to 2.0.1

* Update issue templates
stefanradev93 and others added 22 commits April 25, 2025 20:18
- use torch as default backend
- reduce range of N so users of jax won't be stuck with a slow notebook
- use BayesFlow built-in MLP instead of keras.Sequential solution
- general code cleanup
* one place less to update
* fix one link to a notebook
Add advice regarding moving from v1 to v2 to README.
* minimal working case (.scale)

* concatenate

* keep, drop, rename

* scale, log, sqrt

* standardize

* constraint transforms

* continuous approximator returns log_prob with volume correction

* loop for inverse jacobian

* inverse for elementwise

* inverse for Transforms

* raise error with numpy transform (for now)

* do not fail if no transform is used

* take care of log1p as well

* fix filter transforms, boundary condition

* add tests for adapter jacobians

* document jacobian arg

* jacobian -> log_det_jac

* add test for inverse concatenation

* fix standardize

* correct nesting in map_transform
…eveloper docs (#450)

* document and expose serialization module

* add functools.wraps call to allow_kwargs decorator, as before it was
  breaking the autodoc functionality

* restructure and update developer docs

* move content to separate pages
* update section on serialization

* ci: update pip via python -m pip

pip install -U pip setuptools wheel leads to an error:
https://github.com/bayesflow-org/bayesflow/actions/runs/14692655483/job/41230057180?pr=449

* serializable: increase depth in sys._getframe

The functools.wrap decorator adds a frame object to the call stack

* deprecate (de)serialize_value_or_type

- add deprecation warning, remove functionality
- replace all occurences with the corresponding new functions
- add `bootstrap_comparison` and `summary_space_comparison` to enable comparisons of two domains in the data space or the summary space via bootstrapping
- add `.summaries()` function for easy access to summaries to `ContinuousApproximator` and `ModelComparisonApproximator`
- add tests for the added functionality

---------

Co-authored-by: Valentin Pratz <git@valentinpratz.de>
* v2.0.2 (#447)

* [no ci] notebook tests: increase timeout, fix platform/backend dependent code

Torch is very slow, so I had to increase the timeout accordingly.

* Enable use of summary networks with functional API again (#434)

* summary networks: add tests for using functional API

* fix build functions for use with functional API

* [no ci] docs: add GitHub and Discourse links, reorder navbar

* [no ci] docs: acknowledge scikit-learn website

* [no ci] docs: capitalize navigation headings

* More tests (#437)

* fix docs of coupling flow

* add additional tests

* Automatically run slow tests when main is involved. (#438)

In addition, this PR limits the slow test to Windows and Python 3.10.
The choices are somewhat arbitrary, my thought was to test the setup not
covered as much through use by the devs.

* Update dispatch

* Update dispatching distributions

* Improve workflow tests with multiple summary nets / approximators

* Fix zombie find_distribution import

* Add readme entry [no ci]

* Update README: NumFOCUS affiliation, awesome-abi list (#445)

* fix is_symbolic_tensor

* remove multiple batch sizes, remove multiple python version tests, remove update-workflows branch from workflow style tests, add __init__ and conftest to test_point_approximators (#443)

* implement compile_from_config and get_compile_config (#442)

* implement compile_from_config and get_compile_config

* add optimizer build to compile_from_config

* Fix Optimal Transport for Compiled Contexts (#446)

* remove the is_symbolic_tensor check because this would otherwise skip the whole function for compiled contexts

* skip pyabc test

* fix sinkhorn and log_sinkhorn message formatting for jax by making the warning message worse

* update dispatch tests for more coverage

* Update issue templates (#448)

* Hotfix Version 2.0.1 (#431)

* fix optimal transport config (#429)

* run linter

* [skip-ci] bump version to 2.0.1

* Update issue templates

* Robustify kwargs passing inference networks, add class variables

* fix convergence method to debug for non-log sinkhorn

* Bump optimal transport default to False

* use logging.info for backend selection instead of logging.debug

* fix model comparison approximator

* improve docs and type hints

* improve One-Sample T-Test Notebook:
- use torch as default backend
- reduce range of N so users of jax won't be stuck with a slow notebook
- use BayesFlow built-in MLP instead of keras.Sequential solution
- general code cleanup

* remove backend print

* [skip ci] turn all single-quoted strings into double-quoted strings

* turn all single-quoted strings into double-quoted strings

amend to trigger workflow

---------

Co-authored-by: Valentin Pratz <git@valentinpratz.de>
Co-authored-by: Valentin Pratz <112951103+vpratz@users.noreply.github.com>
Co-authored-by: stefanradev93 <stefan.radev93@gmail.com>
Co-authored-by: Marvin Schmitt <35921281+marvinschmitt@users.noreply.github.com>

* drafting feature

* Initialize projectors for invariant and equivariant DeepSet layers

* implement requested changes and improve activation

---------

Co-authored-by: Lars <lars@kuehmichel.de>
Co-authored-by: Valentin Pratz <git@valentinpratz.de>
Co-authored-by: Valentin Pratz <112951103+vpratz@users.noreply.github.com>
Co-authored-by: stefanradev93 <stefan.radev93@gmail.com>
Co-authored-by: Marvin Schmitt <35921281+marvinschmitt@users.noreply.github.com>
* serialization: apply new scheme for `package` (breaking)

- introduces new policy for consistent naming for serilization (see #451
  for a discussion): standard is the path of a module a class resides
  in, trucated at depth to. So for all class in bayesflow.networks, we
  set package="bayesflow.networks", even if the live in the
  bayesflow.networks.mlp submodule.
- The `serializable` decorator checks this and errors if this is not
  followed. The check can be disabled for certain cases (e.g., classes
  in the experimental module, that might eventually live somewhere
  else).
- After this commit, previously saved models will not be loadable. As we
  introduced a bug regarding this anyway (#451), we will accept this and
  should inform users about it.
- usage of direct calls to `keras.saving.register_keras_serializable`
  were replaced with our custom decorator.

* update serilization policy in dev docs

* README: add not regarding breaking changes until 2.1 release

* standardize use of serializable decorator

* [no ci] change (de)serialize to new pipeline in transform

* serialization check: exempt classes not in bayesflow module

This should ensure that users that try to use our decorator with
external classes do not encounter the error. Possible edge case: they
also name their module "bayesflow".

---------

Co-authored-by: LarsKue <lars@kuehmichel.de>
# Conflicts:
#	bayesflow/links/ordered.py
#	bayesflow/metrics/maximum_mean_discrepancy.py
#	bayesflow/metrics/root_mean_squard_error.py
#	tests/test_workflows/conftest.py
@LarsKue LarsKue requested review from vpratz and stefanradev93 May 5, 2025 14:45
Copy link

codecov bot commented May 5, 2025

Codecov Report

Attention: Patch coverage is 92.90123% with 23 lines in your changes missing coverage. Please review.

Files with missing lines Patch % Lines
bayesflow/approximators/continuous_approximator.py 71.42% 4 Missing ⚠️
bayesflow/utils/serialization.py 77.77% 4 Missing ⚠️
bayesflow/adapters/transforms/filter_transform.py 85.71% 3 Missing ⚠️
bayesflow/adapters/transforms/map_transform.py 87.50% 3 Missing ⚠️
bayesflow/adapters/transforms/drop.py 66.66% 1 Missing ⚠️
...sflow/adapters/transforms/elementwise_transform.py 66.66% 1 Missing ⚠️
bayesflow/adapters/transforms/keep.py 66.66% 1 Missing ⚠️
bayesflow/adapters/transforms/numpy_transform.py 66.66% 1 Missing ⚠️
bayesflow/adapters/transforms/transform.py 66.66% 1 Missing ⚠️
bayesflow/experimental/resnet/dense_resnet.py 0.00% 1 Missing ⚠️
... and 3 more
Files with missing lines Coverage Δ
bayesflow/__init__.py 100.00% <100.00%> (+7.40%) ⬆️
bayesflow/adapters/adapter.py 84.68% <100.00%> (+0.95%) ⬆️
bayesflow/adapters/transforms/as_set.py 92.30% <100.00%> (ø)
bayesflow/adapters/transforms/as_time_series.py 92.30% <100.00%> (ø)
bayesflow/adapters/transforms/broadcast.py 82.97% <100.00%> (ø)
bayesflow/adapters/transforms/concatenate.py 90.76% <100.00%> (+3.07%) ⬆️
bayesflow/adapters/transforms/constrain.py 83.49% <100.00%> (ø)
bayesflow/adapters/transforms/convert_dtype.py 100.00% <100.00%> (ø)
bayesflow/adapters/transforms/expand_dims.py 100.00% <100.00%> (ø)
bayesflow/adapters/transforms/log.py 100.00% <100.00%> (ø)
... and 82 more

... and 10 files with indirect coverage changes

@vpratz
Copy link
Collaborator

vpratz commented May 5, 2025

I think it would be good to add that the new release is not compatible serialization-wise with the 2.0.2 release, so loading models trained with a previous version will not work and one has to re-train after the update.

@stefanradev93
Copy link
Contributor

I think it would be good to add that the new release is not compatible serialization-wise with the 2.0.2 release, so loading models trained with a previous version will not work and one has to re-train after the update.

I would add it to the release note.

@LarsKue
Copy link
Contributor Author

LarsKue commented May 5, 2025

I added a note to the PR comment too, nonetheless.

@LarsKue LarsKue merged commit afc1af1 into main May 5, 2025
16 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

7 participants