Possible to save fitted covariate model in file?


I wonder if it is possible to save your fitted covariate model in a file so that you can reopen it and do the analysis at another time?
For example:
If I fit a model with
fitted_model = fit(model, population, init_params, FOCEI()),
can I save my fitted model -object in a file so that I can get the same object (with the same state) when I read the file?

I could not find anything about this in the documentation.

Similarly , if I have a trained neural network in Flux.jl, I can save my model with for example BSON.jl in a json file.

(I am new to pharmacometric modeling so I don’t know how this is usually dealt with).


Hi Ylva,

It is possible to save the fitted model, i.e. FittedPumasModel, to disk in binary form such that it can be loaded and reused later. Most Julia objects can be stored in this way. To do so, you can use the serialize function from the Serialization stdlib. If ft is your fitted model then you can save it with

using Serialization
serialize("filename_Pumas2.5.jls", ft)

and you can then recover the object with

ft_from_disk = deserialize("filename_Pumas2.5.jls")

The filename can be chosen freely, but it is a good idea to include the Pumas version for the following reason: when saving the fitted model in this way, the complete state is included. The state includes struct layout from Pumas as well as Pumas’ dependencies. Hence, if any of these struct definitions change then it might break the jls file. This way of storing objects is therefore only recommended for short term model storage as it is likely that you won’t be able to load the results in a future version of Pumas.

Yes, that works. Thank you!