igmhub / LaCE

Emulator for the one-dimensional Lyman-alpha flux power spectrum. It was used to generate the results shown in https://arxiv.org/abs/2011.15127, https://arxiv.org/abs/2209.09895, and https://arxiv.org/abs/2305.19064.
1 stars 3 forks source link

Check consistency when reading a NN emulator trained from file #19

Closed andreufont closed 1 year ago

andreufont commented 1 year ago

It is often convenient to read a pre-trained emulator from file, particularly if it might take a while to train. Something like: emulator = NNEmulator(archive,emuparams,save_path=None, model_path='NNmodels/NNEmulator_LaCEHC.pt', train=False)

However, what happens if some of the parameters provided (here emuparams, or the archive) are not consistent with the ones that were used to train the emulator that we are reading from file? Ideally, the code would crash in this case.

One option is to add this test when reading emulator from file, if it is not difficult to implement.

The other option is to do not admit any other parameter when providing a file, i.e., if you provide model_path!=None, you should not specify anything else or the code would crash.

Another way to look at it, is that reading the emulator from file or not should not change the behavior of the emulator object, it should just be a speed up. So you should get the same result if you run emulator = NNEmulator(archive, many_options, model_path='NNmodels/NNEmulator_LaCEHC.pt', train=False) or if you run emulator = NNEmulator(archive, many_options, model_path=None, train=True)

lauracabayol commented 1 year ago

Using the emulator's interface, the only parameters that can vary are kmax, zmax, emu_typ, emu_algorithm and ndeg. The easiest thing could be to define and overwrite these arguments of the function is a predefined emulator (e.g. Pedersen+21) is defined and print a warning message.

Example:

if emulator_label=='Pedersen23':
    print('Select emulator used in Pedersen et al. 2023')
    emuparams = ['Delta2_p', 'n_p', 'mF', 'sigT_Mpc', 'gamma', 'kF_Mpc']
    zmax, kmax_Mpc, ndeg, emu_type = 4.5, 3, 4, 'polyfit'

    print(r'Gaussian Process emulator predicting the optimal P1D fitting coefficients to a 4th degree polynomial. It goes to scales of 3Mpc^{-1} and z<4.5. The parameters passed to the emulator will be overwritten to match these ones') 

What do you think?

andreufont commented 1 year ago

@lauracabayol - we can close this issue, right?

lauracabayol commented 1 year ago

Yes