What Happened to az.from_pymc?

I am trying to learn PyMC from the book Bayesian Modeling and Computation in Python. Unfortunately, the book’s example code is quite out-of-date (PyMC3)! Some of the code does not work with today’s package versions.

I’m struggling to adapt this one example. It looks like az.from_pymc no longer exists. Interestingly, I see az still has lots of “other” from_{library_name} methods, just not one for pymc.

Can someone please provide best practice recommendation for packaging up all the different little inference objects into a single az object? I just went through PyMC’s own documentation examples and don’t see any examples of packaging up multiple objects for simplicity.

1 Like

PyMC’s pm.sample() now returns an arviz InferenceData object by default. So your trace variable is already what you want. Of course, this assumes you are running a recent version of PyMC (e.g., > 5.0).

Thanks! But I guess what I really want is both {prior} and {trace} packaged into a single object. In current state, they both have different components:

But I know that it’s possible to have a single object with everything consolidated inside. For example, here is a single InferenceData object that has everything together.

Maybe this question has nothing to do with az.from_pymc.

If you check out the Prior/Posterior Predictive notebook you’ll see the conventional workflow. Something along these lines:

with pm.Model() as model:
    a = pm.Normal("a", 0.0, 0.5)
    b = pm.Normal("b", 0.0, 1.0)
    sigma = pm.Exponential("sigma", 1.0)
    obs = pm.Normal("obs", mu=a+b, sigma=sigma, observed=outcome_scaled)

    # sample from the prior
    idata = pm.sample_prior_predictive()

with model:
    # sample from the posterior and add to the existing idata object

Nice! .extend() looks very useful. Thanks for the link.

1 Like

Worked through that notebook; very helpful thanks.

Updating for future readers. My {idata} object now has its powers combined!!!

1 Like