Skip to content

Commit d016302

Browse files
mpolson64meta-codesync[bot]
authored andcommitted
Fix flaky floating point comparison in PowerTransformY test (facebook#5044)
Summary: Pull Request resolved: facebook#5044 `test_transform_optimization_config` is flaky because it uses strict equality to compare `OutcomeConstraint` objects after a `transform` -> `untransform` round-trip. The round-trip through `PowerTransformer` (which uses numerical optimization in `fit()`) can introduce small floating point errors in the constraint bound (e.g., `2.345` -> `2.3449999999999998`). Since `OutcomeConstraint.__eq__` ultimately compares string representations of bounds, even tiny differences cause assertion failures. Replace the strict `assertEqual` with component-wise assertions that use `assertAlmostEqual` for the bound (tolerating FP error to 5 decimal places) while still checking all structural properties exactly. See https://github.com/facebook/Ax/actions/runs/23172998708/job/67328952469 for an example failing job. Reviewed By: Balandat Differential Revision: D96855312 fbshipit-source-id: d75b56cb9a9bf3c2311c990a756d2a37f15f925b
1 parent 0c35431 commit d016302

File tree

1 file changed

+6
-1
lines changed

1 file changed

+6
-1
lines changed

ax/adapter/transforms/tests/test_power_y_transform.py

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -251,7 +251,12 @@ def test_transform_optimization_config(self) -> None:
251251
cons = tf.untransform_outcome_constraints(
252252
outcome_constraints=oc_tf.outcome_constraints, fixed_features=None
253253
)
254-
self.assertEqual(cons, oc.outcome_constraints)
254+
self.assertEqual(len(cons), len(oc.outcome_constraints))
255+
for c_actual, c_expected in zip(cons, oc.outcome_constraints):
256+
self.assertEqual(c_actual.metric_names, c_expected.metric_names)
257+
self.assertEqual(c_actual.op, c_expected.op)
258+
self.assertEqual(c_actual.relative, c_expected.relative)
259+
self.assertAlmostEqual(c_actual.bound, c_expected.bound, places=5)
255260
# Relative constraints aren't supported
256261
oc = OptimizationConfig(
257262
objective=objective_m2,

0 commit comments

Comments
 (0)