{"id":9993,"library":"nutpie","title":"Nutpie for Stan or PyMC Models","description":"Nutpie is a Python library designed to sample Stan or PyMC models efficiently, leveraging JAX for high-performance computation. It provides an alternative MCMC sampler for probabilistic programming models, aiming for speed and robustness. The current version is 0.16.8, and it maintains a frequent release cadence, often with minor bug fixes, dependency updates, and feature enhancements.","status":"active","version":"0.16.8","language":"en","source_language":"en","source_url":"https://github.com/pymc-devs/nutpie","tags":["MCMC","sampling","Bayesian inference","PyMC","JAX","probabilistic programming"],"install":[{"cmd":"pip install nutpie","lang":"bash","label":"Install stable version"}],"dependencies":[{"reason":"Required for defining probabilistic models; Nutpie acts as an alternative sampler for PyMC models.","package":"pymc","optional":false},{"reason":"Used as the backend for high-performance computation and compilation.","package":"jax","optional":false}],"imports":[{"symbol":"sample","correct":"import nutpie; nutpie.sample(...)"},{"symbol":"compile_pymc_model","correct":"import nutpie; nutpie.compile_pymc_model(...)"}],"quickstart":{"code":"import pymc as pm\nimport nutpie as np\n\n# Define a simple PyMC model\nwith pm.Model() as model:\n    # Priors\n    mu = pm.Normal('mu', mu=0, sigma=1)\n    sigma = pm.HalfNormal('sigma', sigma=1)\n    \n    # Likelihood\n    obs = pm.Normal('obs', mu=mu, sigma=sigma, observed=[1.0, 2.0, 3.0])\n\n# Sample the model using Nutpie\nprint(\"Starting Nutpie sampling...\")\nidata = np.sample(model)\n\nprint(\"Sampling complete. InferenceData:\\n\", idata)","lang":"python","description":"This example demonstrates how to define a basic PyMC model and then use `nutpie.sample()` to perform MCMC sampling. The results are returned in an `arviz.InferenceData` object."},"warnings":[{"fix":"Upgrade Nutpie to version 0.16.7 or newer: `pip install --upgrade nutpie`","message":"Older versions of Nutpie (pre-0.16.7) might encounter compatibility issues when sampling PyMC models that heavily utilize `pymc.dims`. Ensure you are on a recent version for full `pymc.dims` support.","severity":"gotcha","affected_versions":"<0.16.7"},{"fix":"Upgrade Nutpie to version 0.16.5 or newer: `pip install --upgrade nutpie`","message":"Nutpie versions prior to 0.16.5 had a bug affecting compatibility with pandas 3.0 for string coordinates. If you use pandas 3.0 or later with models containing string coordinates, you might encounter errors.","severity":"gotcha","affected_versions":"<0.16.5"},{"fix":"Upgrade Nutpie to version 0.16.3 or newer to ensure correct `mindepth` behavior: `pip install --upgrade nutpie`","message":"The `mindepth` parameter when `check_turning=True` was misbehaving in versions before 0.16.3. This could lead to incorrect or inefficient sampling behavior under specific configurations.","severity":"gotcha","affected_versions":"<0.16.3"},{"fix":"If you rely on the previous behavior without step size jitter, you can explicitly disable it by passing appropriate arguments to `nutpie.sample()` (e.g., `init_strategy='advi_map'` or setting `step_size_jitter` to 0 if an option is exposed, refer to docs).","message":"Starting from v0.16.0, step size jitter is enabled by default during NUTS sampling. This changes the default behavior, potentially leading to slightly different sampling paths compared to previous versions where it was disabled by default.","severity":"breaking","affected_versions":">=0.16.0"}],"env_vars":null,"last_verified":"2026-04-17T00:00:00.000Z","next_check":"2026-07-16T00:00:00.000Z","problems":[{"fix":"Install it using pip: `pip install nutpie`","cause":"The 'nutpie' library is not installed in your Python environment.","error":"ModuleNotFoundError: No module named 'nutpie'"},{"fix":"Ensure PyMC is installed and meets the version requirement: `pip install 'pymc>=5.0'`","cause":"Nutpie relies on PyMC version 5 or higher to define models. Either PyMC is not installed, or an incompatible older version is present.","error":"RuntimeError: PyMC >= 5 is required but was not found."},{"fix":"Carefully review the `shape` and `dims` arguments in your PyMC model's variable definitions, ensuring they correctly align with your observed data and other priors/likelihoods.","cause":"This error typically indicates an inconsistency in the shape or dimensions of data within your PyMC model definition, which Nutpie's JAX compilation cannot resolve.","error":"ValueError: Dimensions mismatch for variable 'your_variable_name'"},{"fix":"Ensure all inputs to your PyMC model (especially observed data) are standard numerical NumPy arrays (e.g., float32, int64) and avoid object arrays or other complex types that JAX cannot directly convert.","cause":"This error can occur if you're attempting to pass unsupported Python objects or NumPy arrays with incompatible dtypes (e.g., object dtype) into a JAX-compiled context, which Nutpie uses.","error":"TypeError: 'numpy.ndarray' object has no attribute '__jax_array__'"}]}