Skip to content

TST: seed the starting point in test_rotated_hyper_ellipsoid #993

Open

Description

@mmcky

TestMaximization.test_rotated_hyper_ellipsoid in quantecon/optimize/tests/test_nelder_mead.py draws its starting point from the unseeded global random number generator:

def test_rotated_hyper_ellipsoid(self):
d = 5
x0 = np.random.normal(size=d)
bounds = np.array([[-65.536, 65.536]] * d)
sol = np.zeros(d)
fun = 0.
results = nelder_mead(rotated_hyper_ellipsoid, x0, bounds=bounds,
tol_x=1e-30, tol_f=1e-30)
assert_allclose(results.x, sol, atol=1e-6)
assert_allclose(results.fun, fun, atol=1e-7)

Each CI run therefore starts Nelder–Mead from a different point, and occasionally it stops short of the optimum. It failed on #983, in the tests (ubuntu-latest, 3.13) job of run 38883722176 (attempt 1), with x[4] = -1.9e-4 against atol=1e-6, and passed on re-run. Locally, 13 of 30,000 random starting points fail (about 0.04%), with errors up to 1.6e-3. With about a dozen test jobs per push, that is roughly one red run in 200 pushes.

Seeding the draw, or fixing x0, would make the test deterministic. The seed should be one from which the test passes. This is the only unseeded draw in the file.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions