# Saving functions with JLD2

**URL:** <https://discourse.julialang.org/t/saving-functions-with-jld2/50717>\
**Category:** Data\
**Tags:** question\
**Created:** [November 24, 2020, 10:02pm UTC](https://discourse.julialang.org/t/saving-functions-with-jld2/50717 "2020-11-24T22:02:45Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![SamBrand](https://avatars.discourse-cdn.com/v4/letter/s/c37758/32.png) [@SamBrand](https://discourse.julialang.org/u/SamBrand)\
**Post date:** [November 24, 2020, 10:02pm UTC](https://discourse.julialang.org/t/saving-functions-with-jld2/50717/1 "2020-11-24T22:02:45Z")

</div>

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).

---

<div class="post-metadata">

**Author:** ![hendri54](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/hendri54/32/9621_2.png) [@hendri54](https://discourse.julialang.org/u/hendri54)\
**Post date:** [November 24, 2020, 10:53pm UTC](https://discourse.julialang.org/t/saving-functions-with-jld2/50717/2 "2020-11-24T22:53:02Z")

</div>

There is an [open issue](https://github.com/JuliaIO/JLD2.jl/issues/258) for this problem. So far now workaround for JLD2 0.3 has been suggested, but 0.2.4 works.

---

<div class="post-metadata">

**Author:** ![SamBrand](https://avatars.discourse-cdn.com/v4/letter/s/c37758/32.png) [@SamBrand](https://discourse.julialang.org/u/SamBrand)\
**Post date:** [November 25, 2020, 8:01am UTC](https://discourse.julialang.org/t/saving-functions-with-jld2/50717/3 "2020-11-25T08:01:43Z")

</div>

Thanks for letting me know.

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