BUG: find_MAP raises ImportError with better-optimize 0.4.3, the version pip installs
Describe the issue:
On current main, pm.find_MAP fails with an ImportError for anyone who installs PyMC with pip. pm.sample(init="map"), "jitter+map" and "advi_map" fail the same way, because they go through the same code.
The new find_MAP (#8429) reads the per-method capabilities from better_optimize.constants.MINIMIZE_MODE_KWARGS, in pymc/tuning/starting.py and pymc/tuning/scipy_interface.py. better-optimize 0.4.3 (released 2026-10-18) replaced that table with per-method configuration classes and removed the constant. Our pin is better-optimize>=0.4.2,<0.5, so pip resolves to 0.4.3. 0.5.0 doesn't have the constant either. 0.5.1 restored it, but only as a deprecated shim (jessegrabowski/better_optimize#76) that points to better_optimize.configuration.MINIMIZE_CONFIGS[method].uses_grad, and our <0.5 cap excludes it anyway.
CI doesn't catch this because the conda envs come from conda-forge, which never got 0.4.3 and still resolves to 0.4.2. With pip and 0.4.3, tests/tuning gives 48 failed, 22 passed.
find_MAP changed after 6.3.2, so no release is affected yet. The next one would be broken for pip users unless the pin or the import changes.
Reproduceable code example:
# python -m venv env && env/bin/pip install "git+https://github.com/pymc-devs/pymc"
# (resolves better-optimize==0.4.3)
import numpy as np
import pymc as pm
with pm.Model():
mu = pm.Normal("mu")
pm.Normal("y", mu, 1, observed=np.array([0.5, 1.0, 1.5]))
pm.find_MAP(progressbar=False)
Error message:
Traceback (most recent call last):
...
File ".../pymc/tuning/starting.py", line 72, in _canonical_method
from better_optimize.constants import MINIMIZE_MODE_KWARGS
ImportError: cannot import name 'MINIMIZE_MODE_KWARGS' from 'better_optimize.constants' (.../site-packages/better_optimize/constants.py)
PyMC version information:
PyMC: main @ 31aed52
PyTensor: 3.3.4
better-optimize: 0.4.3 (fails), 0.5.0 (fails), 0.4.2 (works), 0.5.1 (works, but emits DeprecationWarnings and is excluded by the <0.5 pin)
Python: 3.13.5
OS: Linux
Installed with pip (editable install of main)
Context for the issue:
The fix is to read the flags from better_optimize.configuration.MINIMIZE_CONFIGS, which better-optimize now points to, and move the pin to >=0.5.1,<0.6. conda-forge has 0.5.1, so pip and conda would end up on the same version again. With that change, tests/tuning plus the init="map" / advi_map sampling tests pass on 0.5.1 with the deprecated constants turned into errors. I can open a PR for this.
]
:tada: Welcome to PyMC! :tada: We're really excited to have your input into the project! :sparkling_heart:
If you haven't done so already, please make sure you check out our Contributing Guidelines and Code of Conduct.
I'm working on this. I'll open a PR that switches to better_optimize.configuration.MINIMIZE_CONFIGS and bumps the pin to >=0.5.1,<0.6.
Fixed by #8584