Skip to content

Commit

Permalink
make debugging easier by saying which constraint is bad (facebook#2737)
Browse files Browse the repository at this point in the history
Summary:
Pull Request resolved: facebook#2737

Would have made debugging this problem way easier https://fb.workplace.com/groups/ae.feedback/posts/8591041154263824/?comment_id=8591648994203040&reply_comment_id=8591748957526377

Generally if there are a bunch of constraints, it's helpful to let the user know which constraint we have a problem with.

Reviewed By: eonofrey

Differential Revision: D62154912

fbshipit-source-id: c6cb6bbfdfb77192aaa46999794a105efb8c94e8
  • Loading branch information
Daniel Cohen authored and facebook-github-bot committed Sep 4, 2024
1 parent ec2b535 commit e105438
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 2 deletions.
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

0 comments on commit e105438

Please sign in to comment.