Skip to content

Keep a non-physical AGNI column out of the energy balance - #1168

Open
timlichtenberg wants to merge 33 commits into
mainfrom
tl/nonconv-fatm-carry
Open

timlichtenberg wants to merge 33 commits into
mainfrom
tl/nonconv-fatm-carry

Conversation

@timlichtenberg

Copy link
Copy Markdown
Member

Description

An AGNI column can come back without radiative transfer: where SOCRATES returns a non-finite flux, AGNI stores 1 W m-2 per band. In a constructed pure-H2O state at 270 bar (temperatures from a minimal.toml row at 124 kyr) with Proudspire 64, every band is filled, so F_olr = 64 W m-2 and F_atm = -129.86 W m-2, and on main the interior takes that as its flux. This PR keeps such a column out of the energy balance.

  • run_agni checks every column, converged or not. A column is non-physical when any upward longwave or shortwave band at the top holds the fill value, when F_atm, F_olr, F_sct or T_surf is not finite, or when F_olr or T_surf is not positive.
  • A non-physical column takes the fluxes of the last converged solve (F_atm, F_olr, F_sct, the albedo and the boundary layer); the surface temperature keeps the offset to T_magma that the last converged solve had under a skin, or the input surface otherwise. The row is marked with the new helpfile column atm_fluxes_carried.
  • The new column atm_nonphysical_iters counts the flagged columns since the last converged solve. The 3rd stops the run with status 22. On resume the count is read from the last committed row, and the carried fluxes come from the last converged row whose fluxes are finite and whose F_olr and T_surf are positive.
  • On a row with carried fluxes the adaptive time step does not grow (it stays at the previous step, or at the floor if that is larger), and the radiative-equilibrium stop is not checked. Rows with their own fluxes keep the behaviour of main.
  • Docs: a section of the Explanation page on the coupling loop ("Fluxes from a column that cannot set the energy balance"), the Validation page Validation/atmos_clim/wrapper.md with 2 cases, and the output reference for the 2 columns and status 22.

Known limits: the carried fluxes have no age limit, and nothing clears them at a giant impact; under a saturation skin whose thickness changes between the record and the unusable column, or under a live lid, the carried row is off the skin balance (the offset is kept, so the surface stays continuous); the hold acts on the adaptive step method only; only the upward bands at the top are checked for the fill value. The first 2 are on the Explanation page.

Validation of changes

  • Validation case 1, tests/atmos_clim/test_slow_steam_fill_column.py (real AGNI and SOCRATES, stored steam column): all 64 top bands at the fill value, a control column with 0, and the carried fluxes and surface written to the row.
  • Validation case 2, tests/atmos_clim/test_slow_carried_flux_coupled.py: a coupled run with filled columns injected at fixed loops: the carried rows, the held steps, and the stop with status 22 at the 3rd flagged column; the expected rows are derived from the run's own helpfile.

atmos_clim_steam_fill_column

atmos_clim_carried_flux_coupled

  • Before and after, in a coupled run with filled columns injected at loops 8, 9, 14, 15 and 16 (a copy of minimal.toml on both sides, at the default solution_rtol of 0.15 of both commits). Rows 0 to 7 are equal on both sides, apart from the wall-clock time.
Row Time main (yr) F_atm main (W m-2) T_magma main (K) Time branch (yr) F_atm branch (W m-2) T_magma branch (K) atm_fluxes_carried branch
7 162 275,959 4234.03 162 275,959 4234.03 0
8 (filled) 322 -130 4207.61 322 275,959 4207.61 1
9 (filled) 422 -130 4208.46 482 275,959 4181.26 1
10 522 231,628 4209.10 642 206,672 4154.92 0

On main the interior takes -130 W m-2 on the next step, T_magma rises, and the run goes on. On this branch the step stays at 160 yr after the carried rows, and the run stops with status 22 at loop 16, the 3rd unusable column after the converged row 13.

  • 5 starts of the same injected run on this branch with planet.mass_tot scaled by 1 + k·1e-12 (k = 1 to 5): each has the same carried rows, the same time steps and the same stop at loop 16 with status 22. The spread of T_magma over the 5 starts is 0.015 K at row 9 (482 yr) and 0.68 K at row 14 (1132 yr); at the same times, main (interpolated in time) is 27.6 K and 52.1 K hotter.
  • coverage run with the 6 changed test files outside the slow tier, against the lines of git diff 0566ee45 f73b890a -- src: 91 of 91 changed statements covered.
  • pytest -m 'not slow' on the 6 changed test files outside the slow tier: 946 pass on this branch; against main's source 54 fail (in each of the 6 files) and 892 pass.
  • pytest -m 'unit and not skip and not slow and not integration' tests in 1 process with the real juliacall at f73b890 (macOS, Python 3.12): 10846 passed, 14 skipped.
  • Nightly on the tip: https://github.com/FormingWorlds/PROTEUS/actions/runs/46737008674 (the 2 macOS slow jobs ran in attempt 2 after a runner shortage).
  • docs-check --base 0566ee45: 1 fault, a row of the Validation index that comes from main (the Schaefer et al. 2024 link of the redox page), not from this branch.

Added lines (pr-breakdown 0566ee45 f73b890a):

Category Files Lines added / removed Size on disk (KiB) Compressed (KiB)
plots 4 +5,320 / -0 +154.2 +34.9
tests 9 +1,238 / -25 +53.4 +15.1
source 7 +285 / -20 +10.6 +2.7
docs text 4 +155 / -14 +14.2 +4.7
stored data 2 +42 / -3 +6.7 +2.8
other 2 +6 / -2 +0.3 +0.1
total 28 +7,046 / -64 +239.4 +60.3

Checklist

  • I have followed the contributing guidelines
  • My code follows the style guidelines of this project
  • I have performed a self-review of my code
  • My changes generate no new warnings or errors
  • I have checked that the tests still pass on my computer
  • I have updated the docs, as appropriate
  • I have added tests for these changes, as appropriate
  • I have checked that all dependencies have been updated, as required

Where SOCRATES returns a non-finite flux, AGNI stores 1 W m-2 per band, so a failed column at the pure-steam 270 bar state returns F_olr equal to the band count and a negative F_atm. run_agni now names such a column (non-finite fluxes or surface temperature, T_surf or F_olr not positive, a top band at FILL_FINITE_FLUX read from AGNI), for converged and rejected solves alike.

The row then takes F_atm, F_olr, F_sct and the albedo of the last converged solve; under a skin surface T_surf follows the skin balance at this step's T_magma, under a fixed surface it stays the input. After a resume the fluxes come from the last row with atm_converged = 1. With no converged solve to take them from, or after ATMOS_NONPHYSICAL_MAX = 3 such columns in a row, the run stops with status 22. A rejected column with usable fluxes keeps its own, as before.

A row whose solve did not converge no longer grows the adaptive time step (it is held) and no longer ends the run through the radeqm check.
The coupling loop page gets a section on the column check, the fluxes taken from the last converged solve, the stop after 3 such columns, and the held time step and radeqm stop on rows with atm_converged = -1. The output reference lists the new readers of atm_converged and bond_albedo.
A converged AGNI solve at the default solution_rtol can sit well off the skin balance, so a surface set from the skin balance with the carried flux jumps against its converged neighbours (by 465 K in a coupled minimal run with Proudspire 64). A carried row now keeps T_magma - T_surf of the recorded solve at this step's T_magma; after a resume the offset comes from the last row with atm_converged = 1.
A slow-tier test runs run_atmosphere with the real AGNI, SOCRATES and the Proudspire 64-band file on the column that a failed solve leaves at pure steam and 270 bar (stored in tests/data/atmos_clim/), with the solver iteration replaced by that column and 1 radiative-transfer call. All 64 longwave bands at the top hold the AGNI fill value, the row takes the fluxes of the last converged solve, and a control column with the starting mixing ratios holds no fill value. The test runs in the agni shard of the nightly slow tier.

A new Validation page shows this case and a coupled run with filled columns, with and without the check, and the coupling loop page links to it.
…only under a skin

The stop now counts the columns that cannot set the energy balance since the last converged physical solve, so a rejected column with usable fluxes between them no longer restarts the count. A carried row takes the recorded offset T_magma - T_surf only when this step has a conductive skin and the record came from a skin solve, and only where the result is positive; otherwise it keeps the input surface. A held time step no longer uses up the gentler growth after a slow-down, and a missing reason from a module no longer flags a column.

The resume test now tells the last converged row from an earlier one, the slow test checks the carried surface, the transparent-limit test has its physics_invariant marker back, and the docs follow the new count and surface rule.
The count of columns that could not set the energy balance since the last converged solve is now the helpfile column atm_nonphysical_iters, written every row and restored on a resume like atm_levels_stale, so each job of a chain keeps it; a helpfile without the column reads it as 0. After a resume the surface offset comes only from a row with a skin, as for a live solve. The slow test now runs the carried row 3 K below the recorded state, so the carried and input surfaces differ.
A row that took F_atm, F_olr, F_sct and the albedo from the last converged solve is now marked in the new helpfile column atm_fluxes_carried, and the adaptive controller holds dt only when the last committed row has that mark. A rejected solve that keeps its own fluxes lets dt grow again, so a run with many rejected rows is not held for most of its length. Older helpfiles read the column as 0.

After a resume, the row that the fluxes come from must also have T_surf > 0 and F_olr > 0, as a live column must. The counts of a resumed run are set by restore_atmos_counts. The hysteresis counter is decremented inside the speed-up branch.
With prevent_warming the clamp turns a NaN F_atm into 1e-8, so the column check must read the flux before the clamp. The run_agni tests share one stand-in for the AGNI energy module.
The second validation case is now a slow reference test in the agni shard. It runs input/minimal.toml with the Proudspire 64 file, the real AGNI and Aragog, and replaces the output of loops 8, 9, 14, 15 and 16 with the filled steam column. It asserts that each filled row holds the F_atm of the last converged row, its mark and count, that the step after it does not grow, that T_magma falls from row 7, and that the run stops with status 22 at loop 16. The plot holds only values that are exact by construction, since T_magma of a coupled run differs between machines by more than the stored-plot tolerance. The run takes about 16 minutes on an M2 Ultra.

The steam column test reads the mixing ratios of the other gases from the stored column and checks the carried mark.
F_atm is the net upward flux, so the -130 W m-2 of the filled column heats the planet; both pages now say so. The check covers AGNI columns only, the surface falls back to the input when no skin offset is recorded or the result is not positive, and the termination table lists the stop and the radeqm skip. The Validation page describes the coupled case as a test.
A resumed run takes the carried fluxes from the last committed +1 row that passes the checks of a live column, so a later unusable +1 row of an older helpfile no longer stops the run while an earlier usable row exists. The time step reads atm_fluxes_carried by column, so the output reference lists the time-step controller as its consumer.

Tests: the resume source with a good earlier row, restore_atmos_counts on stored, non-finite and absent counts, a row written by run_atmosphere read by next_step, the input surface of the live and resumed carried row, and the resume after the last committed row in the property test. The coupled test bounds the held step by the step floor and counts the hold records in the run log.
The plot pair of the coupled validation case shows the ratio of F_atm to the last converged row and the count of unusable columns with the stop at 3. The test docstring names the machine of the stated runtime as an Apple M1 Ultra.
A row that took its fluxes from the last converged solve cannot show a balance, so the radeqm stop skips it; a rejected row that keeps the fluxes of its own solve is now checked like a converged one. The Explanation page states this and that the flux record has no age limit, including across a giant impact.
The coupled validation test runs input/minimal.toml offline, and its default star reads a PHOENIX spectrum that the agni shard does not hold. The test now fetches that one grid first and fails with a clear message when it cannot.
The nightly AGNI shard fetches the Proudspire 64-band file into AGNI/res only, so the coupled run stopped at its first AGNI solve with no spectral file under FWL_DATA. The test now points the run at the AGNI/res file, as the steam column test does, and fails when that file is missing.
The golden run is recorded again on the merged code. It holds the 8 melt-redox tracker columns from main and the atm_fluxes_carried and atm_nonphysical_iters columns of this branch; no stored value changes against either side. The validation navigation keeps both new pages.
run_atmosphere names the stellar spectrum file by star_spec_time of the row. The steam column test copies the spectrum to data/0.sflux, so its stored row now gets star_spec_time = 0.
A carried row applies a stored negative offset (a converged skin solve with a heating column), so its surface stays above T_magma; a new test pins that case. A rejected row with its own fluxes now has a test for the hysteresis window: the step grows by the gentler factor and the counter counts down by 1.

Asserts that restated their own setup now check a result that can change: the logged step decision, the window armed by a slow-down on a carried row, the carried mark, and a frozen-interior control in the deadlock test.

The coupled slow test reads the converged rows and the logged step decisions from the run, so the expected stop loop and hold rows follow the convergence of the real AGNI on the machine that runs it. Both slow tests fail when the AGNI data is missing, since the slow shard fetches it.
…plies them

A carried row does not let the step grow: where the controller would grow it, the next step keeps the previous size, or the time-step floor if that is larger, and it can still shrink. The pages said the step stopped at the floor.

A rejected column that passes the check keeps its own fluxes, also with a negative F_atm; the pages and the flux_source docstring said the fluxes had to be positive. The surface of a carried row keeps the stored skin offset with its sign, so after a heating column it stays above T_magma.

The section on unusable columns is split into which columns are unusable, what such a row takes, the time step on a carried row, and a list of limits, which now also names the older rows a resume cannot reject. The Validation page uses one term for these columns and describes the stop and the hold rows as the test derives them from the run.
@timlichtenberg
timlichtenberg requested a review from a team as a code owner December 2, 2026 06:19
@codecov

codecov Bot commented Dec 2, 2026 •

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 95.96%. Comparing base (a28930b) to head (67d9215).

Additional details and impacted files
@@            Coverage Diff             @@
##             main    #1168      +/-   ##
==========================================
- Coverage   96.27%   95.96%   -0.31%     
==========================================
  Files         168      168              
  Lines       28951    29036      +85     
  Branches     4778     4797      +19     
==========================================
- Hits        27872    27865       -7     
+ Misses        770      763       -7     
- Partials      309      408      +99     
Flag Coverage Δ
nightly 95.95% <100.00%> (+0.19%) ⬆️
unit-tests 95.17% <100.00%> (+0.01%) ⬆️

Flags with carried forward coverage won't be shown. Click here to find out more.

☔ 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.

The golden run is recorded again on the merged code. It holds the 12 new columns from main and the atm_fluxes_carried and atm_nonphysical_iters columns of this branch; no stored value changes against either side. Atmos_t keeps the flux record of this branch and the escape column from main. In run_atmosphere the flux carry runs before the escape column is stored, so a column that takes the carried fluxes counts as not converged and escape keeps the previous column. The validation navigation and index keep both new pages.
The default atmos_clim.p_top is now 1e-10 bar. The control column of the plot reads it from input/minimal.toml, so its smallest band flux moves from 10^-6.9786 to 10^-6.9798 W m-2 and the committed plot no longer matches. The failed column and every assertion are unchanged.
A column that holds the AGNI fill value is marked not converged by the flux check, and only then is the escape column stored. The test runs run_atmosphere over a physical solve and then a filled solve that AGNI reports as converged, and checks that the column of the physical solve stays in place and is not current. With the 2 calls in the other order the filled column is stored and the test fails.

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.

1 participant