LSSTDESC / firecrown

DESC Cosmology Likelihood Framework
BSD 3-Clause "New" or "Revised" License
29 stars 7 forks source link

API for passing sacc data to `load_likelihood` and `build_likelihood` #394

Open tilmantroester opened 6 months ago

tilmantroester commented 6 months ago

For blinding (@arthurmloureiro) we need to be able to pass sacc objects to the likelihood creation entry point. At the moment, load_likelihood and build_likelihood expect a NamedParameters argument. This precludes passing a sacc object (as opposed to a filename string) and also gives no indication if the build_likelihood implementation actually looks for a sacc object or file in the build_parameters argument.

A possible solution would be to add an optional sacc_data keyword argument to load_likelihood that gets passed to build_likelihood. If the latter doesn't implement this argument, it will cause an error, which informs the caller that the likelihood factory doesn't support external sacc files.

sacc_data could be either a string or Sacc object and it would be up to the likelihood factory to deal with this.

arthurmloureiro commented 6 months ago

To explain a bit further: blinding will run as a part of a data-vector measurement pipeline.

The blinding library needs to call the theory-vector calculation from the firecrown likelihood that will be used in the cosmological inference to ensure consistency. This likelihood must be build with different data-vectors as the blinding is a part of a the data-vector calculation pipeline.

We also have a requirement to blind sacc files directly.

In both cases, we need to be able to pass different sacc objects to the build_likelihood instance.

At the moment, there's a .read()method but this is protected, it cannot be called twice (we need to call it once, to build the likelihood and obtain a theory vector).

Does that make sense?

arthurmloureiro commented 6 months ago

I found this trick here based on what is done for TXPipe and adapted the cosmic shear firecrown example to it: https://github.com/LSSTDESC/Blinding/blob/TST-likelihood_examples/examples/cosmic_shear/cosmicshear_likelihood.py

How much of a bad idea is this?

If this is the proper way of passing a sacc file to a likelihood, potentially would be good (if possible) to fix this to the likelihood data-model such that we impose this method exists and so every built likelihood is compatible with blinding.

If not possible, I will just make sure to document this method in the documentation on how to build likelihoods that can be used with the blinding library 😄

arthurmloureiro commented 2 months ago

@marcpaterno @vitenti happy to help pushing development here... how do you recommend we tackle this?

It will also be important for new developments planned for Augur