Skip to content

Commit

Permalink
More information in error message of invalid constraints.
Browse files Browse the repository at this point in the history
  • Loading branch information
janosg committed Jul 10, 2024
1 parent 977564a commit 8f78d12
Showing 1 changed file with 15 additions and 10 deletions.
25 changes: 15 additions & 10 deletions src/estimagic/parameters/check_constraints.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
from functools import partial

import numpy as np
import pandas as pd


from estimagic.exceptions import InvalidConstraintError, InvalidParamsError
Expand Down Expand Up @@ -237,17 +238,21 @@ def check_fixes_and_bounds(constr_info, transformations, parnames):
prob_msg.format(constr["type"], problematic)
)

invalid = {}
lower_bounds = constr_dict["lower_bounds"]
upper_bounds = constr_dict["upper_bounds"]
is_invalid = constr_dict["lower_bounds"] >= constr_dict["upper_bounds"]
if is_invalid.any():
df = pd.DataFrame(
{
"names": parnames[is_invalid],
"lower_bounds": constr_dict["lower_bounds"][is_invalid],
"upper_bounds": constr_dict["upper_bounds"][is_invalid],
}
)

msg = (
"lower_bound must be strictly smaller than upper_bound. "
f"This is violated for:\n{df}"
)

invalid = np.where(lower_bounds >= upper_bounds)[0]

msg = (
"lower_bound must be strictly smaller than upper_bound. "
f"This is violated for:\n{invalid}"
)
if len(invalid) > 0:
raise InvalidConstraintError(msg)


Expand Down

0 comments on commit 8f78d12

Please sign in to comment.