Saving and loading traces in PYMC4

Is there a simple example showing how to save a trace, load it the next day, and then extract values for specific variables? There probably is - but I just can’t find it.

The way I am now saving a trace is:
with Model:

  •  yada, yada*
    

with Model:

  • step = pm.NUTS()*
  • trace=pm.sample(10000,n_init=10000,cores=1,random_seed=(RANDOM_SEED))*
  • trace.posterior.to_netcdf(FileName)*

Then I think I am missing some steps for loading the model. It’s probably best if I don’t show what I have.

Any direction is much appreciated,
Wayne Hajas

You can load InferenceData objects using arviz.from_netcdf()

2 Likes

note you should also use trace.to_netcdf() not trace.posterior.to_netcdf (with this you’ll only save the posterior samples, and ArviZ expects data to be in groups: posterior for posterior samples, sample_stats for sampling info and diagnostics like divergences…

2 Likes