diff --git a/ax/service/tests/test_instantiation_utils.py b/ax/service/tests/test_instantiation_utils.py index aa9c9d1105c..bfa75db3f79 100644 --- a/ax/service/tests/test_instantiation_utils.py +++ b/ax/service/tests/test_instantiation_utils.py @@ -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( diff --git a/ax/service/utils/instantiation.py b/ax/service/utils/instantiation.py index ba5965a64df..afcbcbd292a 100644 --- a/ax/service/utils/instantiation.py +++ b/ax/service/utils/instantiation.py @@ -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]] @@ -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],