PyMC3 for physics

Hi team,

After a brief chat with @fonnesbeck in Southampton, UK a few months back, I thought I would try using the pm.Potential function to help teach MCMC in physics and it seems to work excellently.

I’d be keen to write up a notebook for the documentation if you think it would fit?

Here’s a notebook I produced for our group link. It would need adapting a little but I think an example of the Heisenberg model would be a nice example of how pm.Potential can be used.

I think the important concepts for those looking to use PyMC3 for physics problems would be:

  • Showing how energy and the probability distribution link
  • Explaining the necessity of the prior distributions
  • Plotting the energy and probability surfaces

Any other suggestions?


This looks awesome! Yes definitely PR a notebook.
My only nitpick: you should rewrite the tot function using theano ops for the sampling in PyMC3.

One problem that could come up here is that the sampler might get stuck in one of the local minima. So I would add a traceplot and also run several chains and check the rhat (pm.gelman_rubin). Our current hamiltonian methods don’t deal with multimodal posteriors particularly well. SMC might help with that, but I don’t know much about it.
Also, with nuts you don’t usually need that many samples (that is, as long as the sampler doesn’t get stuck around one mode for long time)

Very nice example of using PyMC3 (and pm.Potential) to simulate physical systems!

I think one nice extension to your example will be to include a “kT- term” and suggest the student/user to test values like 0.1, 1 and 10 to explore the role of temperature in the system.

Regarding @aseyboldt comment I want to add that I am using PyMC3 with the SMC sampler to simulate (small) biomolecules with very good results so far :slight_smile: Maybe the energy barrier in your example is relatively low, but for the systems I am using SMC is crucial to avoid getting trapped in local minima.


All, thanks for suggestions so far (keep them coming!) - I’ll get to work on these.

I haven’t used the sequential MC step in PyMC3 and I couldn’t find any documentation other than the docstring. Is there an example of smc in recent docs build?

This is awesome, thanks for writing it up!

Take a look at this notebook

1 Like