Skip to content

v0.28.0

Latest

Choose a tag to compare

@janfb janfb released this 05 Dec 15:00
d5d8899

sbi 0.28 brings the Simformer, typed per-model configs for every network, save() and load() for trainers and posteriors, parallel simulation with simulate_from_theta, and the bind() API for potentials. Most of the release is a large correctness sweep: about 100 bug-fix PRs across training, sampling, diagnostics and plotting, many of them found and fixed by 25 new contributors. It also removes the aliases deprecated in v0.27.0 (SNPE, SNLE, SNRE and friends) and the deprecations due in this release, and requires Python 3.11, torch 2.5 and zuko 1.3. Please read the breaking changes before you upgrade: several fixes change numbers you may have saved, e.g. z-scoring, the default zuko networks, the TARP p-value and multi-round NPE-A.

Thanks to everyone who contributed to this release: @AndreIsraelAO, @Abhinav3499, @aniketpandey05, @AryanRG, @Ashwini8686, @BHARATH0153, @bmalezieux, @CaptainAni187, @clarkf19, @dgedon, @dhruvb2028, @G26karthik, @janfb, @Jocho-Smith, @JoeyTan21, @mayuriphad, @mmporong, @Mohit-Ak, @nMaax, @patelshivani2283-lab, @pawank925, @Rohan-Dedhia, @SahilKumar75, @satwiksps, @shivansh023023, @ShreyanshGoyal, @soujasK, @studentarijitpaul, @tanmayBeginsJourney, @ThomasGesseyJonesPX, @varunikarai, @vitorbborges and @YashDoesCode.

✨ Highlights

⚠️ Breaking Changes

Requirements

  • sbi requires Python 3.11 or newer (#2068 by @janfb)
  • sbi requires torch 2.5 or newer (#2245 by @janfb): LRUEmbedding(mode="scan") needs torch 2.8; use mode="loop" below.
  • sbi requires zuko 1.3 or newer (#2289 by @janfb)
  • sbi requires joblib 1.3 or newer (#1738 by @bmalezieux)

Removed names and arguments

  • The aliases deprecated in v0.27.0 are removed (#2164 by @dgedon): use NPE, NLE, NRE, MCABC, SMCABC and their variants.
  • VectorFieldPosterior.sample() no longer takes sample_with (#2164 by @dgedon): pass it to build_posterior().
  • mixed_likelihood_estimator_based_potential and MixedLikelihoodBasedPotential are removed (#2249 by @janfb): use likelihood_estimator_based_potential.
  • Trainers no longer take summary_writer (#2249 by @janfb): pass tracker=TensorBoardTracker(summary_writer).
  • FMPE and NPSE no longer take density_estimator, and NPSE no longer takes score_estimator (#2249 by @janfb): pass the estimator as vf_estimator.
  • The flat vector field builders and their config classes are removed (#1996 by @satwiksps): use FlowMatchingConfig or the score configs from sbi.neural_nets.
  • ConditionalFlowConfig, ClassifierConfig and the model_builders dictionaries are removed (#1997 by @satwiksps): use the per-model configs from sbi.neural_nets.
  • build_zuko_cnf and the "CNF" option of build_zuko_flow are removed (#2162 by @dgedon): use flow matching (FMPE) for a continuous flow.
  • FlowMatchingEstimator no longer takes num_freqs or other unknown keyword arguments (#2249 by @janfb): unknown arguments raise a TypeError.
  • plot_summary no longer takes inference or disable_tensorboard_prompt (#2249 by @janfb): use trainer, and verbose=False.
  • LC2ST and LC2ST_NF no longer take thetas, and their get_scores() and get_statistics_under_null_hypothesis() no longer take return_probs (#2249 by @janfb): use prior_samples and the returned LC2STScores.
  • Posteriors no longer take x_shape (#2249 by @janfb)
  • potential.x_o = ... no longer works (#1989): use potential = potential.bind(x_o).
  • NPE-A no longer accepts an arbitrary object with get_mog_params() as a proposal (#2103 by @janfb): use an NPE_A_Posterior, a one-component MoG or a MultivariateNormal.

Changed results and behaviour

  • DirectPosterior.sample() returns the requested sample_shape (#2019 by @janfb): sample() now returns (D,) instead of (1, D).
  • Posteriors check the shape of x, and those that support iid data combine several observations as trials (#2140 by @janfb)
  • Posteriors check the width of theta (#2194 by @Ashwini8686)
  • Amortized VI sample() and log_prob() take one observation (#2193 by @BHARATH0153): use sample_batched() and log_prob_batched().
  • Amortized VI raises for objectives other than "rKL" (#2074 by @BHARATH0153)
  • Multi-round NPE-A trains one Gaussian per round and needs train(final_round=...) (#2110 by @janfb)
  • The conditioned MNLE potential includes the prior (#2084 by @janfb)
  • Guided and iid sampling of vector field posteriors gives different samples (#2111 by @janfb)
  • sample() raises for ODE sampling with iid data or guidance (#2111 by @janfb): build the posterior with sample_with="sde".
  • simulate_for_sbi runs on simulate_from_theta (#1738 by @bmalezieux): with num_workers > 1, simulators receive CPU tensors.
  • A prior that returns numpy arrays passes numpy arrays to the simulator (#2224 by @BHARATH0153)
  • sample_batched() and log_prob_batched() raise for NaN or Inf in x (#1988 by @janfb): NaN padding passes when the embedding net accepts it.
  • The log_prob() normalizer of NPE always stops, and FMPE and NPSE get one (#2239 by @janfb, #2015 by @janfb, #2216 by @BHARATH0153)
  • RestrictedPrior uses the device of its prior, and its device argument is deprecated (#2234 by @janfb): use .to(device); device goes in v0.29.0.
  • RestrictedPrior.log_prob() follows the caller's grad mode (#2298 by @dgedon)
  • NPE_PFN.build_posterior picks the posterior from a typed posterior_parameters (#2249 by @janfb): DirectPosteriorParameters() now builds a DirectPosterior; use FilteredDirectPosteriorParameters() to keep filtering.
  • Potentials follow the caller's grad mode (#2127 by @janfb): pass track_gradients=True where you need gradients inside torch.no_grad().

Changed networks

These changes alter networks built with this version. Networks saved with save() or pickled whole keep their old layers unless noted.

  • Zuko flows get two hidden layers for an int hidden_features (#2115 by @janfb)
  • Unconditional zuko flows z-score their input before the flow transforms (#2105 by @aniketpandey05)
  • Marginal NSF and NCSF flows use the num_bins you set (#1975 by @satwiksps): the default is now 10 bins instead of 8.
  • Embedding nets end in a linear layer (#2118 by @janfb)
  • PermutationInvariantEmbedding passes log(1 + N) instead of the trial count N (#2113 by @janfb): this also changes networks saved with older sbi; retrain them.
  • Structured z-scoring uses the std over all values (#2240 by @janfb, #2171 by @G26karthik)
  • z-scoring leaves constant features unscaled (#2240 by @janfb)
  • z-scoring keeps float32 precision for data with a large mean and a small spread (#2246 by @janfb)
  • The NPSE loss averages over parameter dimensions (#2083 by @BHARATH0153)

Changed diagnostics and metrics

  • check_tarp returns a p-value that tests calibration, and needs num_tarp_samples for it (#2156 by @janfb): pass num_tarp_samples.
  • wasserstein_2_squared and ABC's Distance("wasserstein") scale the regularization with the mean cost and warn when they do not converge, and epsilon becomes relative_epsilon (#2078 by @G26karthik): relative_epsilon is relative to the mean cost (default 1e-2), so choose a new value.
  • sbi.utils.metrics.l1 is the sum of absolute differences (#1998 by @SahilKumar75): scale ABC's eps by the number of features for the old behaviour.
  • c2st subsamples unequal sample counts and accepts integer samples (#2263 by @janfb)

⚠️ Deprecations

  • set_x() and passing x_o to a potential warn, and go in v0.29.0 (#1989, #2248 by @janfb): use potential = potential.bind(x_o).
  • The old build_posterior arguments warn whenever they are passed, and go in v0.29.0 (#2249 by @janfb): pass posterior_parameters instead.
  • MCMCPosterior.log_prob() and RejectionPosterior.log_prob() warn with a FutureWarning and go in v0.29.0 (#2249 by @janfb): use .potential(theta, x).
  • The trainers' logging_level warns and goes in v0.29.0 (#2249 by @janfb): set the level of the sbi logger instead.
  • ConditionalEstimatorBuilder is renamed ConditionalEstimatorBuildFn (#1957, #2249 by @janfb): the old name goes in v0.29.0.
  • A ZukoFlowType as density_estimator of MarginalTrainer goes in v0.29.0, a string in v0.30.0 (#1975, #2249): use a marginal config, e.g. MarginalNSFConfig().
  • Passing a string as density_estimator, classifier or vf_estimator goes in v0.30.0 (#1957, #1921, #2249): use a per-model config, e.g. MAFConfig().
  • Old-style pairplot and marginal_plot keyword arguments warn visibly and go in v0.29.0 (#2160 by @dgedon): pass them in fig_kwargs or in the *_kwargs that the warning names, and offdiag as upper.
  • The per-call effective_t_max argument of the flow matching SDE functions goes in v0.29.0 (#2111 by @janfb): set effective_t_max on the estimator instead.
  • unbiased=True of alpha VI warns and goes in v0.30.0 (#2207 by @janfb): use unbiased=False.

⭐ New Features

🐛 Bug Fixes

Inference and posteriors

  • Posteriors of NPE, FMPE and NPSE trained without a prior (#2308 by @janfb)
  • NPE-A posteriors apply the proposal correction in all methods (#2035, #2045 by @janfb)
  • Multi-round NPE-A and NPE-C with an MDN map the prior and proposal into the network's z-scored space (#2103 by @janfb)
  • Multi-round NPE-C with an MDN uses the full Gaussian prior (#2081 by @aniketpandey05)
  • NPE_B with chunked appends, proposal=None and high-dimensional parameters (#2200 by @aniketpandey05)
  • posterior.to(device) keeps the posterior's state and returns it (#2104 by @janfb)
  • Posteriors loaded with torch.load(..., map_location=...) work on the new device (#1972 by @BHARATH0153)
  • Direct posteriors accept an explicit x and theta on another device (#2033 by @janfb, #2057 by @YashDoesCode)
  • Posteriors use the max_sampling_batch_size given to their constructor (#2077 by @mayuriphad)
  • set_default_x() resets the saved leakage correction (#2015 by @janfb)
  • ImportanceSamplingPosterior.log_prob() uses the right normalization for each x (#2107 by @aniketpandey05)
  • map() returns the right estimate when no optimization step improves on the best initialization (#2072 by @BHARATH0153)
  • map() lists the init_method options each posterior supports (#2106 by @SahilKumar75)
  • 1-D priors with batch shape (1,) give one log prob per sample (#2116 by @janfb)
  • Rejection sampling with a DirectPosterior or VIPosterior proposal finds the right envelope (#2249 by @janfb)
  • Clear errors in importance sampling and SIR (#2223 by @patelshivani2283-lab)
  • sample((0,)) returns an empty tensor (#2216 by @BHARATH0153)
  • EnsemblePosterior uses new weights, works on the GPU and returns samples in random order (#2094 by @AryanRG, #2129 by @aniketpandey05)
  • MCMCPosterior.set_mcmc_method() changes the sampler, and serial slice_np thins once (#2158 by @dgedon)
  • MCMC sample_batched() with init_strategy="latest_sample" continues each observation's own chains (#2233 by @aniketpandey05)
  • RestrictedPrior with sample_with="sir" respects the restriction and the prior (#2101 by @shivansh023023)
  • NPE-PFN sampling works with tabpfn 9.1 (#2051 by @janfb)

Variational inference

  • VI with vi_method="IW" trains the importance-weighted ELBO (#2067 by @SahilKumar75)
  • VI quality control retrains once, at your observation and settings (#2149 by @janfb)
  • The PSIS check of VI fits the right tail (#2223 by @patelshivani2283-lab)
  • Amortized VI works with bounded priors (#2139 by @AndreIsraelAO)
  • Importance-weighted and alpha VI train with a RestrictedPrior or a hard constraint (#2207 by @janfb)
  • Forward-KL VI and the VI convergence check with particles outside the support (#2172 by @janfb)

Vector field methods

Networks, priors and simulators

ABC

  • SMCABC keeps particles and simulations paired, and the linear regression adjustment stays within the prior (#2087 by @janfb)
  • SMCABC with distance_based_decay=True picks the epsilon quantile (#2123 by @BHARATH0153)
  • SMCABC starts fresh on every call (#2128 by @aniketpandey05)
  • ABC with distance_batch_size no longer accepts uninitialized distances (#2020 by @janfb)
  • get_kde(bandwidth="cv") finds the cross-validated bandwidth (#2061 by @JoeyTan21)

Diagnostics and metrics

Plotting

  • marginal_plot draws each panel from its own dimension (#2219 by @dgedon)
  • pairplot draws the lower triangle with the column dimension on x, and sbc_rank_plot bins ranks over [0, N] (#2119 by @dgedon)
  • Legends and the uniformity band of sbc_rank_plot with several rank sets (#2173 by @janfb)
  • Plotting functions accept GPU tensors, tensors that require gradients and numpy limits (#2055 by @YashDoesCode, #2000 by @dhruvb2028)
  • pairplot warns about unknown keys in diag_kwargs, upper_kwargs and lower_kwargs (#2006 by @BHARATH0153)
  • pp_plot and pp_plot_lc2st take arrays (#2215 by @Rohan-Dedhia)
  • pairplot with fig_kwargs=dict(legend=True) and an empty lower triangle no longer draws a stray x-label under the legend (#2160 by @dgedon).
  • sbi.analysis imports with python-dateutil 4 (#2154 by @Mohit-Ak)

Messages

  • NPE leakage is explained where it shows up (#2217 by @janfb)
  • The low-acceptance warning of rejection sampling no longer fires after sampling has finished (#2164 by @dgedon)

🚀 Performance

  • The batched NPE normalizer draws at most rejection_sampling_batch_size samples at once over all observations (#2239 by @janfb)
  • MDN precision indices are device buffers (#2048 by @YashDoesCode)

📖 Documentation

  • New how-to guides on estimator configs (#1987 by @satwiksps) and on running simulations in parallel (#1738 by @bmalezieux), a Simformer tutorial (#1621 by @nMaax), and a section on truncated proposals in the multi-round guide (#2217 by @janfb).
  • The L-C2ST how-to guide is a short task guide, and the tutorial explains the method without true posterior samples (#2206 by @janfb).
  • The leakage FAQ quotes the current warning and the current MCMC API, and no longer recommends an MDN to avoid leakage (#2192 by @aniketpandey05, #2217 by @janfb).
  • The API reference has an Estimators page, working links, and class pages that list only sbi's own members (#1990 by @pawank925, #1991 by @janfb).
  • Docstring and tutorial fixes: #1973 by @vitorbborges, #2009 by @tanmayBeginsJourney, #2112 by @mmporong, #2120 by @Ashwini8686, #2144, #2145, #2147 and #2174 by @aniketpandey05.
  • The ArviZ how-to guide works with ArviZ 1, which PyMC 6 installs, and shows the samples of every MCMC sampler in parameter space; the PyMC and Pyro examples showed them in the unconstrained space of the prior. The estimator configs guide runs again.
  • Enhancement proposals EP-02 (a standalone training loop) and EP-03 (training on datasets larger than memory), and EP-01 marked as completed (#2286, #2287 by @janfb).

🛠️ Maintenance

🎉 New Contributors

Full Changelog: v0.27.0...v0.28.0