optimagic-dev / optimagic

optimagic is a Python package for numerical optimization. It is a unified interface to optimizers from SciPy, NlOpt and other packages. optimagic's minimize function works just like SciPy's, so you don't have to adjust your code. You simply get more optimizers for free. On top you get diagnostic tools, parallel numerical derivatives and more.
https://optimagic.readthedocs.io/
MIT License
270 stars 30 forks source link

Pass bounds to numerical derivatives for nonlinear constraints #524

Open janosg opened 3 months ago

janosg commented 3 months ago

Background

The cyipopt version we used in testing caused an ImportError with the latest scipy versions; Therefore many of our tests for nonlinear constraints did not run.

Bug description

When trying to create the bounds for the numerical derivatives of nonlinear constraints, we use the user provided selector on the user provided bounds. This does not work if bounds are just specified for a subset of a pytree.

Solution

The bounds that are passed to process_nonlinear_constraints already need to be extended to have the same structure as params. To avoid similar places in other problem, this extension should already be done in create_optimization_problem.

My temporary solution was to not pass bounds to the numerical derivatives of constraints which is usually not a big problem.

After fixing this, we need to comment the following code back in:

https://github.com/OpenSourceEconomics/optimagic/blob/a2fb0e554dae3ed5eda43191004ce9bbae267451/src/optimagic/parameters/nonlinear_constraints.py#L88