"log_likelihood" not found in InferenceData

The arviz documentation suggests that PyMC3 should be storing a log-likelihood with the InferenceData when “log_likelihood = True” is one of the `idata_kwargs.

step_func = pm.DEMetropolisZ(vars = params_list)
trace = pm.sample(
    draws = NUM_DRAWS, step = step_func, cores = NUM_CORES,
    chains = NUM_CORES, return_inferencedata = True,
    idata_kwargs = {'log_likelihood': True})

However, the output trace (InferenceData`) does not contain a “log_likelihood” group.

>>> trace
Inference data with groups:
	> posterior
	> sample_stats

Am I missing something? Thanks!

So, thankfully, there is a way to:

These are sufficient for now, but better support for InferenceData might be worth pursuing. From the PyMC3 trunk, it’s apparent that:

which versions of pymc and arviz are you using?

Yes, when converting to InferenceData the log likelihood data is automatically computed and included in the resulting InferenceData if possible. I think there should be a warning printed if that fails, but I might be wrong. You can see that this works in most of the example notebooks, for example: Model comparison — PyMC3 documentation

That being the default also means that using idata_kwargs={"log_likelihood": True} is equivalent to not using any arguments.

If either of these options has worked, then it seems like the auto conversion should work too, provided you have relatively new versions of both pymc and arviz. If so, could you share a minimal example in which it fails?

Here you are wrong, which is not strange given the actual change and large updates happening to the codebase as version 4.x approaches.

The to_inference_data you mention is a method of the converter class, not a function. The function that is actually called from the sample method in the 2nd link you provided is a few lines below that. And it does have keyword arguments. However, those are only used for >=4 versions, which you’ll only have if you have installed from github as it has not been released yet. You can also see how in the methods above there is code similar to the answers you shared above that automatically store pointwise log likelihood values.

If you are using pymc3 installed from pip or from conda, the conversion is then being done with an ArviZ function instead of with this one, which is why you originally found that info in the ArviZ docs. Both are similar and both store log likelihood by default, but there are some important differences.