# How to interact with \`pm.Model().logp()\`?

**URL:** <https://discourse.pymc.io/t/how-to-interact-with-pm-model-logp/10000>\
**Category:** v5\
**Created:** [July 24, 2022, 11:52pm UTC](https://discourse.pymc.io/t/how-to-interact-with-pm-model-logp/10000 "2022-07-24T23:52:27Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![conorhassan](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.pymc.io/conorhassan/32/4909_2.png) [@conorhassan](https://discourse.pymc.io/u/conorhassan)\
**Post date:** [July 24, 2022, 11:52pm UTC](https://discourse.pymc.io/t/how-to-interact-with-pm-model-logp/10000/1 "2022-07-24T23:52:27Z")

</div>

Trying to get the log probability for a PyMC model evaluated at a particular set of parameter values. I am attempting to follow this documentation webpage: [behind\_the\_scenes\_of\_the\_logp\_function](https://www.pymc.io/projects/docs/en/stable/contributing/developer_guide.html#behind-the-scenes-of-the-logp-function) .

The following code chuck is from the above webpage:

```auto
with pm.Model() as model:
    z = pm.Normal('z', mu=0., sigma=5.) # ==> aesara.tensor.var.TensorVariable
    x = pm.Normal('x', mu=z, sigma=1., observed=5.) # ==> aesara.tensor.var.TensorVariable
# The log-prior of z=2.5
pm.logp(z, 2.5).eval() # ==> -2.65337645
# ???????
x.logp({'z': 2.5}) # ==> -4.0439386
# ???????
model.logp({'z': 2.5}) # ==> -6.6973152

```

The line `model.logp({'z': 2.5}) ` returns the following error: `TypeError: unhashable type: 'dict'`.

Any help would be appreciated; thanks!

---

<div class="post-metadata">

**Author:** ![cluhmann](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.pymc.io/cluhmann/32/3083_2.png) [@cluhmann](https://discourse.pymc.io/u/cluhmann)\
**Post date:** [July 25, 2022, 12:29am UTC](https://discourse.pymc.io/t/how-to-interact-with-pm-model-logp/10000/2 "2022-07-25T00:29:29Z")

</div>

I think you need the [`compile_logp()` method](https://www.pymc.io/projects/docs/en/latest/api/generated/classmethods/pymc.Model.compile_logp.html) of `pm.Model`:

```python
model.compile_logp()({'z': 2.5}) 

```

---

<div class="post-metadata">

**Author:** ![conorhassan](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.pymc.io/conorhassan/32/4909_2.png) [@conorhassan](https://discourse.pymc.io/u/conorhassan)\
**Post date:** [July 25, 2022, 3:50am UTC](https://discourse.pymc.io/t/how-to-interact-with-pm-model-logp/10000/3 "2022-07-25T03:50:20Z")

</div>

Hi Christian,

`compile.logp()` works great! Maybe I can help update the current docs when I am a little more knowledgeable about what is going on under the hood!

---

<div class="post-metadata">

**Author:** ![cluhmann](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.pymc.io/cluhmann/32/3083_2.png) [@cluhmann](https://discourse.pymc.io/u/cluhmann)\
**Post date:** [July 25, 2022, 3:54am UTC](https://discourse.pymc.io/t/how-to-interact-with-pm-model-logp/10000/4 "2022-07-25T03:54:43Z")

</div>

Absolutely! Documentation-related PRs are always appreciated, but particularly now that v4 is out and the documentation is lagging a bit behind.

---

<div class="post-metadata">

**Author:** ![OriolAbril](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.pymc.io/oriolabril/32/2497_2.png) [@OriolAbril](https://discourse.pymc.io/u/OriolAbril)\
**Post date:** [July 25, 2022, 12:40pm UTC](https://discourse.pymc.io/t/how-to-interact-with-pm-model-logp/10000/5 "2022-07-25T12:40:28Z")

</div>

I think this is covered in this notebook: [PyMC and Aesara — PyMC 4.1.3 documentation](https://www.pymc.io/projects/docs/en/stable/learn/core_notebooks/pymc_aesara.html#pymc). There are still challenges though like `pm.logp` not being in the API docs (tracked in [Review and update API docs · Issue #5282 · pymc-devs/pymc · GitHub](https://github.com/pymc-devs/pymc/issues/5282)); if it were, it could have a “See Also” section linking to `compile_logp` method (also same could be done in `model.logp` method too)
