Skip to content

Replace prepare_for_sbi with separate calls to for prior and simulator in all tutorials #752

Closed

Description

@jecampagne

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

Activity

  1. changed the title [-]Related to #746[/-] [+]Related to #746: prepare_for_sbi with process_prior[/+] on Oct 21, 2022
  2. michaeldeistler commented on Oct 23, 2022

    @michaeldeistler
    Contributor

    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)
    
  3. michaeldeistler commented on Oct 23, 2022

    @michaeldeistler
    Contributor

    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

  4. changed the title [-]Related to #746: prepare_for_sbi with process_prior[/-] [+]Split `prepare_for_sbi` into separate functions for prior and simulator[/+] on Oct 23, 2022
  5. janfb commented on Oct 24, 2022

    @janfb
    Contributor

    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.

  6. janfb commented on Oct 28, 2022

    @janfb
    Contributor

    Hi, is this solved?

  7. michaeldeistler commented on Oct 28, 2022

    @michaeldeistler
    Contributor

    I would keep it open because I think we should really split prepare_for_sbi.

  8. added
    API changes
    on Nov 2, 2022
  9. janfb commented on Nov 9, 2022

    @janfb
    Contributor

    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)
  10. changed the title [-]Split `prepare_for_sbi` into separate functions for prior and simulator[/-] [+]Replace `prepare_for_sbi` with separate calls to for prior and simulator in all tutorials[/+] on Nov 9, 2022
  11. added
    beginner friendly
    on Nov 9, 2022
  12. added
    hackathon
    on Jan 30, 2024
  13. removed
    API changes
    on Feb 16, 2024
  14. jsvetter commented on Mar 5, 2024

    @jsvetter
    Contributor

    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 tutorial folder 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)
  15. zinaStef commented on Mar 14, 2024

    @zinaStef
    Collaborator

    Happy to take care of it.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

beginner friendlyhackathon

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions