Skip to content

test_discrepancy is flaky due to unseeded latin.sample call #681

Closed

Description

@ConnectedSystems

test_discrepancy fails intermittently in CI, seemingly unrelated to whatever PR triggers it. Ran into it on PR #678:

FAILED tests/test_discrepancy.py::test_discrepancy - AssertionError:
Not equal to tolerance rtol=1e-07, atol=0.005

Mismatched elements: 1 / 3 (33.3%)
Mismatch at index:
 [0]: 0.33506401670122105 (ACTUAL), 0.33 (DESIRED)
Max absolute difference among violations: 0.00506402
Max relative difference among violations: 0.01534551
 ACTUAL: array([0.335064, 0.333022, 0.331914])
 DESIRED: array([0.33, 0.33, 0.33])

Looks like the test calls latin.sample(problem, 1_000) without passing a seed (tests/test_discrepancy.py:15), and latin.sample defaults to an unseeded numpy.random.Generator when seed=None. So the samples differ every run, and the resulting discrepancy values drift enough to occasionally fall outside the atol=5e-3 check against [0.33, 0.33, 0.33].

Saw this on CI run https://github.com/SALib/SALib/actions/runs/28939656687 on the fix/sobol-partial-constant-output branch. That same branch had passed on earlier runs with no changes anywhere near discrepancy or sampling code, so this looks like sampling variance rather than an actual regression.

Probably just needs a fixed seed passed into the latin.sample call in the test (or a looser tolerance if some spread is expected), so it stops failing PRs that have nothing to do with it.

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

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions