Haven’t tried this, but it should work (give it a shot with very few samples first!):
import cPickle as pickle # if python2
import pickle # if python3
...
trace = pm.sample(5e4, njobs=4, step=[pm.Metropolis(vars=[Y, Yp]), pm.NUTS()], tune=1000)
with open('trace.pkl', 'wb') as buff:
pickle.dump(trace, buff)
You can then recover the trace with
with open('trace.pkl', 'rb') as buff:
trace = pickle.load(buff)
This is great for local development on your computer. A few “gotchas” that probably won’t matter:
- You cannot pickle in python2 and unpickle in python3
- Do not unpickle a file from an untrusted source, as it can run arbitrary code