basf/doe

Design does not satisfy constraint

jsdiazpo opened this issue · 1 comments

When a design does not satisfy a constraint it is returned as if everything went well, it would be nice to warn the user about this.
Example: a simple three-input linear design with a formulation constraint (x1+x2+x3=1). If all inputs have the domain [0.5,1], then the formulation constraint cannot be satisfied

import pandas as pd
import opti
import doe

inputs = ['x1', 'x2', 'x3']
# formulation constraint
constr1 = opti.LinearEquality(names=inputs, rhs=1)
problem = opti.Problem(
                      inputs=[opti.Continuous(x, domain=[0.5, 1]) for x in inputs],
                      outputs=[opti.Continuous("y")],
                      constraints=[constr1],
)
df = doe.find_local_max_ipopt(problem=problem,
                              model_type="linear")

constr1.satisfied(df).values
# array([False, False, False, False, False, False, False])

The last output shows that the formulation constraint is not satisfied; nonetheless, the (incorrect) design is generated and returned with no warnings to the user.

Hi @jsdiazpo :) the PR above is a suggestion on how to warn the user in the cases you described. The code is longer than one would think it has to, because the implementations of satisfies() for opti.Constraints and contains() for opti.Parameters have a zero tolerance. However, it is expected that IPOPT only respects the problem domain and constraints up to a very small (~ 1e-9) number. This had to be considered here, otherwise the user would also be warned when actually everything is ok.