Skip to content

Set equity and risk-aversion test tolerances from the measured spread - #488

Open
C1587S wants to merge 2 commits into
ClimateImpactLab:mainfrom
C1587S:ci-pin-numpy-cpu-dispatch
Open

C1587S wants to merge 2 commits into
ClimateImpactLab:mainfrom
C1587S:ci-pin-numpy-cpu-dispatch

Conversation

@C1587S

@C1587S C1587S commented Nov 14, 2026 •

Copy link
Copy Markdown
Member

Six tests in tests/test_equity.py and tests/test_risk_aversion.py fail on CI hosts with AVX512 and pass on the rest. numpy 1.26.4 sends np.power to its bundled SVML kernels on those hosts and to a generic path elsewhere, and the two differ in the last bit. Damages are the difference of two nearly equal certainty equivalents read from float32 stores, so that last bit gets amplified. 30 parametrizations fail.

This sets the tolerances from a measurement of that spread, instead of pinning numpy's dispatch path in CI. Nothing in src/ changes.

Measured on an Intel Xeon Gold 6448Y with numpy 1.26.4, over every recipe, discount type and product the tests compare, once with AVX512 dispatch on and once with NPY_DISABLE_CPU_FEATURES set on the same host as the control.

test before now measured margin
equity points rtol 1e-4, atol 1e-4 rtol 3e-4, atol 2e7 3.0e-5 16.6
risk aversion points rtol 1e-4, atol 1e-4 rtol 6e-4, atol 1e7 5.4e-5 10.1
equity coefficients rtol 1e-5, atol 1e-8 rtol 5e-6, atol 8e5 4.8e-7 12.3
risk aversion coefficients rtol 1e-5, atol 1e-8 rtol 9e-6, atol 1e6 8.2e-7 10.6
equity fit rtol 1e-5, atol 1e-8 rtol 3e-5, atol 2e8 2.0e-6 11.5
risk aversion fit rtol 1e-5, atol 1e-8 rtol 7e-5, atol 4e8 6.4e-6 14.2

rtol is ten times the largest relative deviation, atol ten times the largest absolute one on values below the median, both rounded up. Each atol works out to a small share of the median it is compared against, from 7.6e-4 of the median damage down to 9.6e-6 of the median coefficient. The old atol=1e-4 meant nothing against damages of order 1e10. Both coefficients tests end up with a tighter rtol than they had.

The spread does not reach the SCC. On the same host the SCC moves by 5.8e-7 with dispatch on and 6.6e-12 with it off, while the points it is built from move by up to 3.0e-5. test_equity_scc and test_risk_scc pass there with their existing rtol of 1e-4.

Both workflow jobs move from ubuntu-latest, which now resolves to 26.04, to ubuntu-24.04, so the toolchain stays the same between runs.

With the old tolerances the six assertions applied to that host's outputs fail on exactly the 30 parametrizations that fail in CI. With the new ones none fail, and both pass on the control.

On an Intel Xeon Gold 6448Y, with numpy dispatching through AVX512_ICL and no environment variables set, both test modules pass three times in a row, 72 tests each.

@C1587S
C1587S requested a review from brews November 14, 2026 05:04
@codecov

codecov Bot commented Nov 14, 2026 •

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 68.94%. Comparing base (e900e00) to head (82a25b1).

Additional details and impacted files
@@           Coverage Diff           @@
##             main     #488   +/-   ##
=======================================
  Coverage   68.94%   68.94%           
=======================================
  Files          15       15           
  Lines        1755     1755           
=======================================
  Hits         1210     1210           
  Misses        545      545           

☔ View full report in Codecov by Harness.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@brews

brews commented Nov 17, 2026 •

Copy link
Copy Markdown
Member

(moved this reply into a review comment)

@brews brews left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hey @C1587S, my immediate reaction is to consider that if the test is sensitive enough to be influenced by this kind of low level implementation choice, might this be more of a code smell? It might also mean that the tests are "wound too tight", so to speak.

For example, rather than asserting for exact matches as part of the test, instead use np.testing.assert_allclose and have it check for a precision that is practically significant, but not so tight that it gets caught up on hardware differences.

It might also be that you're asking for a level of precision that float point math cannot legitimately sustain and we need to find an alternative way of doing things.

Part of the purpose of tests is to check that you get consistent and replaceable behavior across multiple machines and users. Are we sure you're not masking a deeper methods problem by forcing this?

It also feels like something that is a pain to maintain. It makes it hard for users to clone the repo on their local machines and run tests to ensure things just run correctly. We really should avoid this as much as possible. Smells like trouble.

Again, this is my immediate reaction. I don't know the problem space as well as you so please feel free to tell me if I'm off.

On hosts where numpy 1.26.4 dispatches its AVX512 code paths, np.power runs
through the SVML bundled with numpy and the float32 certainty equivalents
differ from the AVX2 path in the last bits. Damages are the difference of two
nearly equal certainty equivalents, so this reaches 5.9e-2 relative on the
smallest damage values and 3.0e-5 on values at or above the median. With the
old tolerances six test functions fail on such hosts, 30 parametrizations:
equity points, coefficients and fit for all seven discount types, and
risk-aversion points, coefficients and fit for the three gwr types.

Each of the six asserts now sets rtol and atol to ten times the largest
deviation from the fixture measured on an Intel Xeon Gold 6448Y with AVX512
dispatch on, pooled over the seven discount types and rounded up to one
significant figure: rtol from values at or above the median, atol from values
below it. Each atol is stated in the test as a fraction of the median absolute
value it applies to.

  test                              rtol   atol   atol / median
  test_equity_points                3e-4   2e7    7.6e-4
  test_risk_aversion_points         6e-4   1e7    5.1e-4
  test_equity_coefficients          5e-6   8e5    9.6e-6 to 1.2e-5
  test_risk_aversion_coefficients   9e-6   1e6    2.0e-5 to 2.8e-5
  test_equity_fit                   3e-5   2e8    4.1e-5
  test_risk_aversion_fit            7e-5   4e8    1.1e-4

Both coefficients tests end up with a tighter rtol than the xarray default of
1e-5 they used before. Nothing in src/ changes.
ubuntu-latest now resolves to ubuntu-26.04. Pinning the image keeps the
toolchain the same from one run to the next. The host CPU is still assigned
by the runner pool; the test tolerances no longer depend on it.
@C1587S
C1587S force-pushed the ci-pin-numpy-cpu-dispatch branch from 1f7a0fb to 82a25b1 Compare November 20, 2026 18:20
@C1587S C1587S changed the title Pin the numpy CPU dispatch path in CI Set equity and risk-aversion test tolerances from the measured spread Nov 20, 2026
@C1587S

C1587S commented Nov 20, 2026 •

Copy link
Copy Markdown
Member Author

hi @brews! agreed, and thanks for pushing back on it!!!

I went and measured it, and two things came out. The tolerance turned out to be the problem rather than the comparison, since the points tests already allowed rtol 1e-4 and their atol of 1e-4 means nothing against damages of order 1e10. And the noise floor is real in the damage function points, since damages is the difference of two nearly equal certainty equivalents read from float32 stores, so it does show up there, but it doesn't reach the SCC. The regression attenuates it, so the SCC tests pass on an AVX512 host under the tolerance they already had.

So what I did was modify the tests instead. Each tolerance comes from the measured spread, ten times the deviation, one pair per test, measured with numpy's AVX512 path on and off on the same node. Two of the six end up stricter than before. The env variable and the guard step are gone, so the only workflow change left is pinning the runner image, which i think is worth having on its own.

The six tests pass three times in a row on an AVX512 node with nothing set in the env

PS: I retitled the PR and rewrote the description to match the new approach, and force-pushed the branch rather than stacking revert commits on top, so your line comments will show up as outdated.

@kemccusker

Copy link
Copy Markdown
Member

I'm not totally following this, but why is atol so huge now?

This branch has not been deployed

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

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants