Skip to main content

save

save(obj, f, /)

Write a posterior (or any @pytree object) to a file, without its model.

lk.save(post, "post.pt")

A function inside the likelihood that is not registered with lk.core.serializable (a lambda as mask_fn, say) is left out; lk.load then needs the likelihood back as likelihood=.

Parameters

Name Type Description Default
obj object The object to save, usually a posterior from lk.laplace. required
f str | os.PathLike[str] | IO[bytes] A path or a binary file object. required

Raises

Name Type Description
TypeError The object holds a class that is not a registered @pytree class or a function outside the likelihood that is not registered. The message names the field.