Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

make debugging easier by saying which constraint is bad #2737

Closed
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions ax/service/tests/test_instantiation_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,9 @@ def test_constraint_from_str(self) -> None:
},
)

with self.assertRaisesRegex(AssertionError, "Outcome constraint 'm1"):
InstantiationBase.outcome_constraint_from_str("m1 == 2*m2")

self.assertEqual(three_val_constaint.bound, 3.0)
with self.assertRaisesRegex(ValueError, "Parameter constraint should"):
InstantiationBase.constraint_from_str(
Expand Down
7 changes: 5 additions & 2 deletions ax/service/utils/instantiation.py
Original file line number Diff line number Diff line change
Expand Up @@ -477,7 +477,8 @@ def outcome_constraint_from_str(
"""Parse string representation of an outcome constraint."""
tokens = representation.split()
assert len(tokens) == 3 and tokens[1] in COMPARISON_OPS, (
"Outcome constraint should be of form `metric_name >= x`, where x is a "
f"Outcome constraint '{representation}' should be of "
"form `metric_name >= x`, where x is a "
"float bound and comparison operator is >= or <=."
)
op = COMPARISON_OPS[tokens[1]]
Expand All @@ -489,7 +490,9 @@ def outcome_constraint_from_str(
bound_repr = bound_repr[:-1]
bound = float(bound_repr)
except ValueError:
raise ValueError("Outcome constraint bound should be a float.")
raise ValueError(
f"Outcome constraint bound should be a float for '{representation}'."
)
return OutcomeConstraint(
cls._make_metric(
name=tokens[0],
Expand Down