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