From bd7ff0080da109c0b77bc37fe9efeddccb5f3608 Mon Sep 17 00:00:00 2001 From: Jammy2211 Date: Sat, 14 Nov 2026 12:29:25 +0000 Subject: [PATCH] fix: drop stale enable_pytrees/register_model advice from searches/mcmc.py Fitness.__init__ registers the model as a JAX pytree internally, so the BlackJAXNUTS example no longer tells users to call enable_pytrees() / register_model(model), which are not on the af namespace. The prose now names use_jax=True as the only requirement, matching searches/mle.py. Notebook regenerated with PyAutoHands generate.py. Closes #184 Co-Authored-By: Claude Opus 5.5 --- notebooks/searches/mcmc.ipynb | 18 ++++-------------- scripts/searches/mcmc.py | 18 ++++-------------- 2 files changed, 8 insertions(+), 28 deletions(-) diff --git a/notebooks/searches/mcmc.ipynb b/notebooks/searches/mcmc.ipynb index e0fcb98b..4b6bf1d7 100644 --- a/notebooks/searches/mcmc.ipynb +++ b/notebooks/searches/mcmc.ipynb @@ -367,15 +367,10 @@ "hand-tune the leapfrog step count. Because it uses gradients, the run is typically much more\n", "sample-efficient than the ensemble samplers above on smooth, unimodal posteriors.\n", "\n", - "Two requirements distinguish it from `Emcee` / `Zeus`:\n", - "\n", - " 1) The analysis must be built with `use_jax=True` so the log-likelihood is JAX-traceable end to\n", - " end (`jax.grad` of it has to be takeable). Below we construct a separate `analysis_jax` to\n", - " keep the existing `analysis` (used by Emcee / Zeus) on its NumPy path.\n", - " 2) The user's model must be registered as a JAX pytree so `model.instance_from_vector` flows\n", - " through `jax.jit`. `enable_pytrees()` is a one-shot process-level call; `register_model(model)`\n", - " walks the user's model and registers each concrete class it finds (here, `af.ex.Gaussian`).\n", - " This is the same mechanism the `Nautilus_jax` example uses.\n", + "Unlike `Emcee` / `Zeus`, the analysis must be built with `use_jax=True` so the log-likelihood is\n", + "JAX-traceable end to end (`jax.grad` of it has to be takeable). Below we construct a separate\n", + "`analysis_jax` to keep the existing `analysis` (used by Emcee / Zeus) on its NumPy path. Nothing\n", + "else is needed: the model is registered as a JAX pytree automatically when the fit starts.\n", "\n", "The fit itself runs in two phases:\n", "\n", @@ -416,11 +411,6 @@ " )\n", " sys.exit(0)\n", "\n", - "from autofit.jax.pytrees import enable_pytrees, register_model\n", - "\n", - "enable_pytrees()\n", - "register_model(model)\n", - "\n", "analysis_jax = af.ex.Analysis(data=data, noise_map=noise_map, use_jax=True)\n", "\n", "search = af.BlackJAXNUTS(\n", diff --git a/scripts/searches/mcmc.py b/scripts/searches/mcmc.py index 76bddb79..4b0ae9ef 100644 --- a/scripts/searches/mcmc.py +++ b/scripts/searches/mcmc.py @@ -236,15 +236,10 @@ hand-tune the leapfrog step count. Because it uses gradients, the run is typically much more sample-efficient than the ensemble samplers above on smooth, unimodal posteriors. -Two requirements distinguish it from `Emcee` / `Zeus`: - - 1) The analysis must be built with `use_jax=True` so the log-likelihood is JAX-traceable end to - end (`jax.grad` of it has to be takeable). Below we construct a separate `analysis_jax` to - keep the existing `analysis` (used by Emcee / Zeus) on its NumPy path. - 2) The user's model must be registered as a JAX pytree so `model.instance_from_vector` flows - through `jax.jit`. `enable_pytrees()` is a one-shot process-level call; `register_model(model)` - walks the user's model and registers each concrete class it finds (here, `af.ex.Gaussian`). - This is the same mechanism the `Nautilus_jax` example uses. +Unlike `Emcee` / `Zeus`, the analysis must be built with `use_jax=True` so the log-likelihood is +JAX-traceable end to end (`jax.grad` of it has to be takeable). Below we construct a separate +`analysis_jax` to keep the existing `analysis` (used by Emcee / Zeus) on its NumPy path. Nothing +else is needed: the model is registered as a JAX pytree automatically when the fit starts. The fit itself runs in two phases: @@ -280,11 +275,6 @@ ) sys.exit(0) -from autofit.jax.pytrees import enable_pytrees, register_model - -enable_pytrees() -register_model(model) - analysis_jax = af.ex.Analysis(data=data, noise_map=noise_map, use_jax=True) search = af.BlackJAXNUTS(