Saving functions with JLD2

Hi all,

I am currently engaged in modelling/forecasting SARS-CoV-2 transmission (like everyone else it feels like…).

My current work flow involves parameter inference, and I contain all the relevant information about what I’ve inferred about various parameters in a struct. I then save these structs using JLD2.

One of the fields of the struct is the log-prior function and another is the log-likelihood function. Therefore, each of these struct contains all the data, transmission model, and statistical model information I need to replicate the analysis.

This was not a problem, since JLD2 saves (or saved?) the names of each function; each function name corresponds to a defined option in my TransmissionModels Module e.g. one function might be TransmissionModel.negative_binomial_PCR_model, and another might be TransmissionModel.beta_binomial_PCR_model. So long as TransmissionModels was imported before loading the saved structs this was not a problem.

However, now JLD2 is throwing an error:

typeof(TransmissionModel.negative_binomial_PCR_model)() not defined.

I’ve ‘solved’ the problem by pinning back to JLD2 0.2.0, but I was wondering if anyone had a suggestion for saving functions as a field in a struct using JLD2 (or whatever other IO package).

There is an open issue for this problem. So far now workaround for JLD2 0.3 has been suggested, but 0.2.4 works.

2 Likes

Thanks for letting me know.

Should have checked JuliaIO/JLD2 issue (or created one) before whinging on here, I blame working into the night…