I can’t reproduce the error, and for some reason now it works fine. I didn’t even restart my computer and did exactly the same thing. Not sure what the problem was; perhaps a bug in my computer.
Maybe we should still leave this closed question up here in case this happens to anyone else.
@junpenglao, After I restart my computer and re-open my jupyter notebook, I tried loading the saved trace:
with model_1:
trace_1 = pm.load_trace(".pymc_1.trace")
But it says it doesn’t recognize the model. Do I have to re-run my model? If so, what is save_trace usually used for, considering that you have to run the whole model again?
For what it is worth, I have found this to be a good pattern in pymc3 - to separate the modelling step from the sampling step. I even will often define a model in a function, and do things like
def my_model():
with pm.Model() as model:
x = pm.Normal('x')
...
return model
with my_model():
other stuff
You can go through this thread, where I had pretty much the same problem with saving at some point. Tell me if the advice there ends up working for you.