Skip to content

Improve handling of internal nonlinear_constraints #606

@gauravmanmode

Description

@gauravmanmode
  • optimagic version used, if any:
  • Python version, if any: 3.10
  • Operating System: Linux

What would you like to enhance and why? Is it related to an issue/problem?

A user-provided nonlinear constraint a <= g(x) <= b is transformed to h(x) >= 0, where h(x) is
- h(x) = g(x), if a == 0 and b == inf
- h(x) = g(x) - a, if a != 0 and b == inf
- h(x) = (g(x) - a, -g(x) + b) >= 0, if a != 0 and b != inf.

Issue:

For example

om.NonlinearConstraint(
       selector=lambda params: params[2:4],
       func=lambda x: np.prod(x),
       upper_bound=-12,
       
   ),

when only upper_bound is mentioned, it is transformed with _transformation_type = "stack"
the internal representation is
{"type":"ineq", ...
"n_constr" : 2} and lower_bound is implicity set to zero.

Describe the solution you'd like

Improve this by handling the -inf case,
Then a <= g(x) <= b is transformed to h(x) >= 0 where h(x) is
- h(x) = g(x), if a == -inf and b == inf
- h(x) = g(x) - a, if a != 0 and b == inf
- h(x) = -g(x) + b, if a == -inf and b != inf
- h(x) = (g(x) - a, -g(x) + b) >= 0, if a != -inf and b != inf.

Describe alternatives you've considered

A clear and concise description of any alternative solutions or features you've
considered and why you have discarded them.

Metadata

Metadata

Assignees

No one assigned

    Labels

    enhancementNew feature or request

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions