Replace `prepare_for_sbi` with separate calls to for prior and simulator in all tutorials
Sorry to reopen on a different issue
If have 3 independents priors
prior = process_prior([prior_oc, prior_s8, prior_w0] )
leading to (MultipleIndependent(), 3, False) , what about this error when I try to use the usual prepare_for_sbi
#adapt/check the prior & simulator for SBI
simulator, prior = prepare_for_sbi(simulator, prior)
AssertionError: Nesting of combined distributions is not possible.
how should I proceed? Thanks
Hi, no need to run prepare_for_sbi after you have run process_prior. You can simply pass a dummy to prepare_for_sbi if you only want to prepare your simulator:
from sbi.utils import BoxUniform
dummy_prior = BoxUniform(torch.zeros(3), torch.ones(3))
simulator, dumm_prior = prepare_for_sbi(simulator, dummy_prior)
I agree that this is not elegant and we should probably split prepare_for_sbi into separate functions for the prior and the simulator, so let's keep this issue open until this is implemented
Hey!
Regarding the API it should be possible to directly use prepare_for_sbi:
simulator, prior, = prepare_for_sbi(simulator, [prior1, prior2, ...])
Regarding the error: it seems one of your priors was already processed to be a MultipleIndependent. The priors passed as list should all the native torch.distributions, e.g., Uniform, MultivariateNormal etc.
Regarding splitting prepare_for_sbi: What Michael said :) prepare_for_sbi is just a wrapper that calls process_prior and process_simulator.
process_simulator checks the return type and ensures that the simulator returns a batch dimension.
process_prior returns a tuple (processed_prior, num_parametes, whether_the_prior_returns_numpy). Thus, when using it, make sure to pass on only the processed prior, not the entire tuple.
Hi, is this solved?
I would keep it open because I think we should really split prepare_for_sbi.
as discussed, we will promote using process_prior and process_simulator separately instead of using prepare_for_sbi, e.g., by changing it in all the tutorials:
replace
simulator, prior = prepare_for_sbi(custom_simulator, custom_prior)
by
prior, num_parameters, prior_returns_numpy = process_prior(custom_prior)
simulator = process_simulator(simulator, prior, prior_returns_numpy)
TODO for the hackathon:
As described by @janfb above, this issue is not concerned with the core codebase, but only with the tutorial notebooks.
- [ ] Go through all notebooks in the
tutorialfolder and indentify the relevant ones - [ ] Replace
simulator, prior = prepare_for_sbi(custom_simulator, custom_prior)by
prior, num_parameters, prior_returns_numpy = process_prior(custom_prior)
simulator = process_simulator(simulator, prior, prior_returns_numpy)
Happy to take care of it.