Skip to content

Migrate to npt.assert_allclose #1175

Open

Description

@seanlaw

According to the NumPy docs for npt.assert_almost_equal:

It is recommended to use one of assert_allclose, assert_array_almost_equal_nulp or assert_array_max_ulp instead of this function for more consistent floating point comparisons.

Perhaps, we should migrate our tests accordingly?

To Do List

  • Each test file correctly replaces all uses of npt.assert_almost_equal or npt.assert_array_almost_equal with its equivalent npt.assert_allclose (check with grep assert*_almost tests/*)
  • When rtol=0 for npt.assert_allclose, simply omit this paramter and value since this is the default
  • Ensure that npt.assert_allclose(actual, desired) and npt.assert_array_equal(actual, desired) always has the stumpy computed value as "actual" and the naive computation as "desired"
  • Use atol=1.5e-07 rather than atol=1.5*10**-07
  • Eventually, replace the ugly 1.5*10**-config.STUMPY_TEST_PRECISION with config.STUMPY_TEST_PRECISION = 1.5e-07 (in config.py)
  • Replace comp with cmp
  • Rename naive outputs to ref_ and stumpy-computed outputs to cmp_ (applies to npt.assert_array_equal too)
  • Omit "Fixed # 1175" from PR title and initial comment (use "Related to # 1175" instead)

Activity

  1. viknesh-ai commented on Aug 9, 2026

    @viknesh-ai
    Contributor

    Agreed ,assert_almost_equal only checks absolute tolerance (abs(actual-desired) < 1.510**-decimal), while assert_allclose combines relative + absolute (atol + rtolabs(desired)), so it's more meaningful for comparisons across varying magnitudes and matches what NumPy recommends.

    I count 1283 call sites across 40 test files currently using assert_almost_equal (only 2 already use assert_allclose), so this is a fairly mechanical but wide-reaching change. Proposing two passes: first a straight swap to assert_allclose(a, b, atol=1.5*10**-decimal, rtol=0) everywhere, which preserves today's exact pass/fail behavior with no risk, then a follow-up pass to set meaningful rtol/atol case-by-case where a relative tolerance is actually the right thing to check (the rtol=1e-12, atol=1e-12 used in the #1174 MASS precision tests is a decent template for that). I can start on pass 1 if that approach sounds good to you.

  2. added 3 commits that reference this issue on Aug 9, 2026
    d6b9692
    d33405c
    eafcae4
  3. added a commit that references this issue on Aug 13, 2026
    95d0b33
  4. added a commit that references this issue on Aug 14, 2026
    699bd45
  5. seanlaw commented on Aug 15, 2026

    @seanlaw
    ContributorAuthor

    @viknesh-ai Please continue when you get a chance. Perhaps, let's do three PRs at a time?

  6. seanlaw commented on Aug 29, 2026

    @seanlaw
    ContributorAuthor

    @viknesh-ai I am ready for more! 👍

  7. 12 remaining items

  8. seanlaw commented on Nov 16, 2026

    @seanlaw
    ContributorAuthor

    @karthiksenv Please proceed. Thank you

  9. karthiksenv commented on Nov 16, 2026

    @karthiksenv
    Contributor

    Thanks, Sean! The test_mstumped.py migration passed the full Ubuntu suite with 100% coverage. I'll send it as a separate PR.

  10. karthiksenv commented on Nov 17, 2026

    @karthiksenv
    Contributor

    Hi @seanlaw, would tests/test_stumped.py be available for the next migration PR after #1228? It has 32 remaining assert_almost_equal comparisons. I’d keep the change to that file, put the computed results first, and preserve the existing tolerances. If you’d prefer I help with another issue or an open PR, I’m happy to take a look. Thanks!

  11. seanlaw commented on Nov 17, 2026

    @seanlaw
    ContributorAuthor

    @karthiksenv Grab as many that are not fixed

  12. karthiksenv commented on Nov 17, 2026

    @karthiksenv
    Contributor

    Thanks, Sean! I’m taking STUMPED, STUMPI, and Ray as separate migrations. I’ll also check whether the Ostinato and precision migrations can land cleanly alongside #1012, #907, #1174, and #1207. Austin has SCRAAMP. Once those are covered, I’ll check what’s left for the shared tolerance cleanup.

  13. karthiksenv commented on Nov 17, 2026

    @karthiksenv
    Contributor

    One question on the final tolerance cleanup, @seanlaw. The current configured tolerance converts to 1.5e-05. With the #1163 seed, the existing egress test reports one mismatch at that tolerance and two at the proposed 1.5e-07. Would you prefer converting the setting to an absolute tolerance while preserving 1.5e-05, then tightening it once the precision issues are fixed?

  14. seanlaw commented on Nov 17, 2026

    @seanlaw
    ContributorAuthor

    One question on the final tolerance cleanup, @seanlaw. The current configured tolerance converts to 1.5e-05. With the #1163 seed, the existing egress test reports one mismatch at that tolerance and two at the proposed 1.5e-07. Would you prefer converting the setting to an absolute tolerance while preserving 1.5e-05, then tightening it once the precision issues are fixed?

    @karthiksenv Please ignore issue #1163 and simply proceed as before

  15. karthiksenv commented on Nov 17, 2026

    @karthiksenv
    Contributor

    Thanks, @seanlaw. I'll keep going with the migrations as planned. The targeted tests passed for all five drafts, and the full coverage run is still going.

  16. karthiksenv commented on Nov 17, 2026

    @karthiksenv
    Contributor

    I checked the shared tolerance from the checklist, @seanlaw. On Ubuntu with JIT off and CUDA simulation on, all 255 affected cases passed at the current tolerance with seed 3559353816. At 1.5e-07, three identical-subsequence tests failed in GPU-STUMP, MSTUMP, and STUMPI.

    Once the file PRs land, would a separate PR to make the setting absolute at its current value be useful?

  17. karthiksenv commented on Nov 17, 2026

    @karthiksenv
    Contributor

    Hi @seanlaw, could you review and merge #1229, #1230, #1231, #1232, and #1233 when you get a chance? All 31 CI jobs passed on each PR. Thanks!

  18. karthiksenv commented on Nov 18, 2026

    @karthiksenv
    Contributor

    Thanks for merging the five PRs, @seanlaw. The remaining cache, chains, and SDP naming cleanup is in #1237, with the full suite running.

    On current main (dcdeeb1), the tolerance check passed all 256 cases at 1.5e-05. At the requested 1.5e-07, five cases failed across GPU-STUMP, MSTUMP, STUMP, and STUMPI with seed 3559353816 (JIT off, CUDA simulated). This also included the configured SCRAAMP comparison in a temporary copy.

    Should the shared setting wait for the precision fixes, or would you like a draft with these failures documented?

  19. seanlaw commented on Nov 19, 2026

    @seanlaw
    ContributorAuthor

    On current main (dcdeeb1), the tolerance check passed all 256 cases at 1.5e-05. At the requested 1.5e-07, five cases failed across GPU-STUMP, MSTUMP, STUMP, and STUMPI with seed 3559353816 (JIT off, CUDA simulated). This also included the configured SCRAAMP comparison in a temporary copy.

    Sorry, I'm having trouble understanding what you mean here.

  20. karthiksenv commented on Nov 19, 2026

    @karthiksenv
    Contributor

    Sorry, Sean, I was unclear. The current setting is 5, so 1.5 * 10**-5 gives an absolute tolerance of 1.5e-05. Changing it to the checklist's 1.5e-07 also makes those comparisons 100 times stricter.

    I've prepared that change in draft #1240. Rechecking on a42ca40, all 256 affected cases passed on main; with the stricter setting, 251 passed and five failed. For example, GPU-STUMP returned 4.04e-07 where the reference returned zero, which exceeds 1.5e-07.

    The draft includes the failing tests and a reproduction command using the same seed and test order. It stays in draft while we discuss those failures.

  21. seanlaw commented on Nov 19, 2026

    @seanlaw
    ContributorAuthor

    Should the shared setting wait for the precision fixes, or would you like a draft with these failures documented?

    No, we should not progress any further. I would like to wait a (long) while before making any further changes to the tests as it relates to the precision.

  22. karthiksenv commented on Nov 20, 2026

    @karthiksenv
    Contributor

    Understood, Sean. I'll hold off on further precision-related test changes and leave #1240 closed. Thanks for clarifying.

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

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions