Load trace doesn't load variables passed "shape" parameter

Hi all,
I’m sampling a model in one script, saving it, and loading it elsewhere for posterior checks and analysis. However, I’m finding that variables that are arrays aren’t loaded properly.

For example, my model has parameters:

α1 = pm.Normal("α",mu=1, sigma=1, shape=30)
α2 = pm.Normal("α2", mu=3, sigma=1)

I sample this,

with model:
    db = pm.backends.Text('../models/team_trace')
    trace = pm.sample(1000, return_inferencedata=True, trace=db)

And then in a separate script, I load the model (explicitly loading the same model def’n):

trace = pm.backends.text.load("../models/team_trace/", model)

and find that the only variable that exists is the non-array variable

(Pdb) model.trace['α']
*** KeyError: 'Unknown variable α'
(Pdb) model.trace[33]
{'α2': array(3.87896845)}

If I go look into the .csv files where the trace has been saved/loaded from there’s many variables like α__0,α__1,α__2, so the variables exist, I’m just not sure if there’s a correct approach to load them?

Hi Tyler,
Those backends are gonna get deprecated soon in favor of ArviZ’ netcdf capabilities, so I encourage to use az.to_netcdf to save your trace :wink:

1 Like

Ah, perfect! Thanks for the info, Alex.