Skip to content

Commit

Permalink
Deflake the benchmarks tests.
Browse files Browse the repository at this point in the history
PiperOrigin-RevId: 612560615
  • Loading branch information
qiuyiz authored and copybara-github committed Mar 4, 2024
1 parent 9cafb44 commit d6bc3f4
Showing 1 changed file with 22 additions and 8 deletions.
30 changes: 22 additions & 8 deletions vizier/_src/benchmarks/analyzers/convergence_curve_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -294,7 +294,9 @@ def test_convert_with_origin_reference(self):

curve = generator.convert(pytrials)
np.testing.assert_array_equal(curve.xs, [1, 2, 3])
np.testing.assert_array_almost_equal(curve.ys, [[0.0, 3.0, 8.0]], decimal=1)
np.testing.assert_array_almost_equal(
curve.ys, [[0.0, 3.0, 8.0]], decimal=0.5
)

def test_convert_with_reference(self):
generator = convergence.HypervolumeCurveConverter(
Expand Down Expand Up @@ -327,7 +329,9 @@ def test_convert_with_reference(self):

curve = generator.convert(pytrials)
np.testing.assert_array_equal(curve.xs, [1, 2, 3])
np.testing.assert_array_almost_equal(curve.ys, [[0.0, 0.0, 2.0]], decimal=1)
np.testing.assert_array_almost_equal(
curve.ys, [[0.0, 0.0, 2.0]], decimal=0.5
)

def test_convert_with_none_reference(self):
generator = convergence.HypervolumeCurveConverter([
Expand Down Expand Up @@ -357,7 +361,9 @@ def test_convert_with_none_reference(self):

curve = generator.convert(pytrials)
np.testing.assert_array_equal(curve.xs, [1, 2, 3])
np.testing.assert_array_almost_equal(curve.ys, [[0.0, 0.0, 1.0]], decimal=1)
np.testing.assert_array_almost_equal(
curve.ys, [[0.0, 0.0, 1.0]], decimal=0.5
)

def test_convert_with_inf_none_reference(self):
generator = convergence.HypervolumeCurveConverter([
Expand Down Expand Up @@ -433,7 +439,7 @@ def test_convert_with_state(self):

curve = generator.convert(pytrials)
np.testing.assert_array_equal(curve.xs, [4, 5])
np.testing.assert_array_almost_equal(curve.ys, [[9.0, 10.0]], decimal=1)
np.testing.assert_array_almost_equal(curve.ys, [[9.0, 10.0]], decimal=0.5)

def test_convert_factor_with_inf(self):
generator = convergence.HypervolumeCurveConverter(
Expand Down Expand Up @@ -466,7 +472,9 @@ def test_convert_factor_with_inf(self):

curve = generator.convert(pytrials)
np.testing.assert_array_equal(curve.xs, [1, 2, 3])
np.testing.assert_array_almost_equal(curve.ys, [[0.0, 1.0, 4.0]], decimal=1)
np.testing.assert_array_almost_equal(
curve.ys, [[0.0, 1.0, 4.0]], decimal=0.5
)


class MultiMetricCurveConverterTest(parameterized.TestCase):
Expand Down Expand Up @@ -544,7 +552,9 @@ def test_convert_multiobjective(self):

curve = generator.convert(pytrials)
np.testing.assert_array_equal(curve.xs, [1, 2, 3])
np.testing.assert_array_almost_equal(curve.ys, [[4.0, 4.0, 8.0]], decimal=1)
np.testing.assert_array_almost_equal(
curve.ys, [[4.0, 4.0, 8.0]], decimal=0.5
)


class RestartingCurveConverterTest(absltest.TestCase):
Expand Down Expand Up @@ -584,7 +594,9 @@ def converter_factory():

curve = restart_converter.convert(pytrials)
np.testing.assert_array_equal(curve.xs, [1, 2, 3])
np.testing.assert_array_almost_equal(curve.ys, [[0.0, 5.0, 9.0]], decimal=1)
np.testing.assert_array_almost_equal(
curve.ys, [[0.0, 5.0, 9.0]], decimal=0.5
)

pytrials = []
pytrials.append(
Expand Down Expand Up @@ -638,7 +650,9 @@ def converter_factory():

curve = converter.convert(pytrials)
np.testing.assert_array_equal(curve.xs, [1, 2, 3])
np.testing.assert_array_almost_equal(curve.ys, [[0.0, 5.0, 9.0]], decimal=1)
np.testing.assert_array_almost_equal(
curve.ys, [[0.0, 5.0, 9.0]], decimal=0.5
)

pytrials = []
pytrials.append(
Expand Down

0 comments on commit d6bc3f4

Please sign in to comment.