-
Notifications
You must be signed in to change notification settings - Fork 14
feat(regression): stabilise committed-bundle bytes, fix docs & lint coverage #744
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
7 commits
Select commit
Hold shift + click to select a range
8f9b8e5
feat(regression): quantise committed-bundle floats to 7 significant f…
lewisjared 866ab7c
docs(regression): correct testing-diagnostics and regression-baseline…
lewisjared 96ad66f
ci: narrow pre-commit regression exclude to baseline data only
lewisjared 5920f40
docs(changelog): add news fragments for #744
lewisjared 619d3aa
docs(regression): use ASCII arrow (->) in CMIP7 facet example
lewisjared d242079
Merge branch 'main' into chore/regression-bundle-stability
lewisjared 6529884
style(regression): apply semantic line breaks to docs and code comments
lewisjared File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1 @@ | ||
| Corrected and expanded the regression-testing documentation, fixing inaccuracies in the diagnostic testing guide and filling gaps in the regression baselines reference. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1 @@ | ||
| Committed regression baseline bundles (`series.json` and `diagnostic.json`) now round floating-point values to seven significant figures when written, giving stable, reviewable bytes that no longer churn between local and CI runs while staying well within the regression comparison tolerance. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1 @@ | ||
| The pre-commit configuration now lints the `climate_ref_core.regression` source package and its tests; only the committed baseline data under `test-data/` remains excluded. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
66 changes: 66 additions & 0 deletions
66
packages/climate-ref-core/src/climate_ref_core/regression/_quantise.py
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,66 @@ | ||
| """ | ||
| Float quantisation for committed regression bundles. | ||
|
|
||
| Committed regression JSON (``series.json`` / ``diagnostic.json`` / ``output.json``) | ||
| records full-precision floats whose least-significant digits are platform-dependent | ||
| (CPU, BLAS, library versions). | ||
| Those last digits churn byte-for-byte between CI and local runs even when the result is numerically identical, | ||
| producing noisy, unreviewable diffs in the committed bundle. | ||
|
|
||
| Rounding every float to a fixed number of significant figures at write time gives | ||
| stable, reviewable committed bytes. | ||
| We round to seven significant figures: one digit finer than the regression compare | ||
| tolerance (``rtol=1e-6`` in :mod:`climate_ref_core.regression.compare`), | ||
| so the rounding error stays an order of magnitude under tolerance and can never flip a boundary gate verdict. | ||
|
|
||
| This affects only the committed bundle. | ||
| The native blobs (``.nc`` / ``.png``) and their content-addressed digests are never touched. | ||
| """ | ||
|
|
||
| from __future__ import annotations | ||
|
|
||
| from typing import Any | ||
|
|
||
| DEFAULT_SIG_FIGS: int = 7 | ||
| """Default significant figures for committed-bundle floats. | ||
|
|
||
| Deliberately one digit finer than the ``rtol=1e-6`` regression compare tolerance, | ||
| so rounding never flips a boundary gate verdict. | ||
| """ | ||
|
|
||
|
|
||
| def round_floats(obj: Any, sig_figs: int = DEFAULT_SIG_FIGS) -> Any: | ||
| """ | ||
| Recursively round every ``float`` in a JSON-like structure to ``sig_figs`` figures. | ||
|
|
||
| Walks dicts, lists and tuples, rounding each ``float`` via the ``g`` format | ||
| (``float(f"{x:.{sig_figs}g}")``) and leaving ``int``, ``bool``, ``str`` and ``None`` untouched. | ||
| ``bool`` is a subclass of ``int`` (and not of ``float``), so booleans are never rounded. | ||
| The operation is idempotent: rounding an already-rounded value is a no-op. | ||
|
|
||
| Tuples are returned as lists, matching JSON serialisation semantics | ||
| (JSON has no tuple type; the standard library serialises tuples as arrays). | ||
|
|
||
| Parameters | ||
| ---------- | ||
| obj | ||
| A JSON-like object: a scalar, or an arbitrarily nested dict / list / tuple. | ||
| sig_figs | ||
| The number of significant figures to round each float to. | ||
|
|
||
| Returns | ||
| ------- | ||
| : | ||
| A copy of ``obj`` with every float rounded to ``sig_figs`` significant figures. | ||
| """ | ||
| # ``bool`` is a subclass of ``int``; | ||
| # check it explicitly so booleans are preserved rather than being coerced through the float branch. | ||
| if isinstance(obj, bool): | ||
| return obj | ||
| if isinstance(obj, float): | ||
| return float(f"{obj:.{sig_figs}g}") | ||
| if isinstance(obj, dict): | ||
| return {key: round_floats(value, sig_figs) for key, value in obj.items()} | ||
| if isinstance(obj, (list, tuple)): | ||
| return [round_floats(item, sig_figs) for item in obj] | ||
| return obj |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.