Skip to content

Treat the oxygen budget as derived under from_mantle_redox - #1190

Merged
timlichtenberg merged 65 commits into
mainfrom
tl/o-budget-from-mantle-redox
Dec 5, 2026
Merged

timlichtenberg merged 65 commits into
mainfrom
tl/o-budget-from-mantle-redox

Conversation

@timlichtenberg

Copy link
Copy Markdown
Member

Description

With planet.fO2_source = "from_mantle_redox", CALLIOPE and atmodeller hold the fO2 at the offset of the melt redox state and derive O_kg_total on every call, as they do under "user_constant". The flag that says so, outgassing_derives_o_kg_total, was true only for "user_constant". Three parts of the code read that flag, and each treated the derived oxygen under "from_mantle_redox" as an input budget:

  • Accretion added the oxygen of an impactor to the volatile budget, where the next outgassing call replaces O_kg_total. The accreted rock was short by that oxygen, and M_volatile_change held it.
  • The Zalmoxis structure target with dry_mantle = true took the derived oxygen out of the mass that sets the core.
  • The warning for a rise of the derived oxygen did not run.

The flag is now true for both sources with CALLIOPE or atmodeller. What changes for a run with "from_mantle_redox":

  • The oxygen of an impactor goes into the accreted rock; M_volatile_change takes none of it.
  • The core mass rises by core_frac times the derived oxygen (first table below).
  • The per-element closure of the trapped reservoirs leaves oxygen out, as under "user_constant".
  • The oxygen warning runs and prints the last finite fO2_shift_IW_mantle. The error of the oxygen budget check at the start, which already ran under this source, names planet.interior_chem.ferric_fraction_initial as the setting to change.

For every source, apply_impact now checks the split of the impactor volatiles per element before any mass moves: delivered plus lost, plus for oxygen the part put into the rock, must equal the impactor content within 1e-12 of it, and no part can be negative. A split that does not close stops the run with a RuntimeError.

One more change affects the dummy outgassing: the per-element closure now leaves its oxygen out under every source, because the dummy module builds its oxygen reservoirs from H2O, CO2 and SO2 and keeps O_kg_total as given. On main this was so only under "user_constant". With the dummy outgassing, "from_mantle_redox", Aragog, trap_mode = "front" and an oxygen budget of 1e21 kg (O_mode = "kg"), main stops at the closure (O_kg_total 1.000e21 kg against reservoirs of 1.342e21 kg); this branch completes the run with the same 2 values in the helpfile.

Runs with "user_constant" or "from_O_budget" and CALLIOPE do not change in the 3 pairs listed below. No config key changes. No issue is tagged.

Questions for the review:

  1. Is O_kg_total meant as a quantity that the outgassing derives under "from_mantle_redox", as under "user_constant", so that Zalmoxis must not keep that oxygen in the dry-mantle mass and accretion must move delivered oxygen into rock?
  2. The absolute fO2 of the atmosphere solve under "from_mantle_redox" is the IW buffer at max(T_magma, outgas.T_floor) plus fO2_shift_IW_mantle. Is that the intent at temperatures where atmodeller has its own buffer limits (below 1000 K and above 8148 K)? This PR only documents the limits (docs/Explanations/redox.md).
  3. The delivered oxygen is part of the accreted rock, so the core takes core_frac of it, as it does under "user_constant". Is that intended, or must impactor oxygen stay in the mantle? I have no literature check for this rule.

Validation of changes

Before and after, my runs on macOS arm64 with PYTHONPATH=<tree>/src: main a7e063ee against this branch at a72d1b33, 1 Earth mass, CALLIOPE 26.11.8, Aragog 26.11.24, Zalmoxis 26.11.22 with dry_mantle = true, core_frac = 0.325 and lowt_extension = false, H 0.5 oceans, C 2.73e20 kg. The 3 module versions are the lowest that pyproject.toml of the tip allows. Each number is from the 2 runtime_helpfile.csv files by script.

Run without impacts ("from_mantle_redox", 13 rows to 2692 yr): 138 of 1073 numeric columns differ.

Output Before (main) After (this branch) Relative change
M_core (kg), all rows 1.940470e24 1.940786e24 +1.627e-4
M_mantle (kg), all rows 4.030075e24 4.029756e24 -7.907e-5
R_int (m), all rows 7.167912e6 7.167789e6 -1.719e-5
P_surf (bar), last row 73.3057 73.3108 +6.97e-5
T_magma (K), last row 3874.082 3874.069 -3.50e-6

The core mass change is 3.158e20 kg, which is 0.32500 times the O_kg_total of the first row (9.7165e20 kg). Over 6 runs of this config with lowt_extension = true at 8f66582d, whose planet.delta_T_super differs by steps of 1e-12 of its value, the last-row spread is 0 for M_core, M_mantle and R_int, 4.2e-9 for P_surf and 1.3e-7 for T_magma. F_cmb spreads by 1.7e-2 there, more than its change of +3.3e-3 in this pair, so it is not in the table.

Run with 1 impact of 0.01 Earth masses with 1000 ppmw oxygen at 1000 yr and no atmosphere loss (the config of tests/integration/test_slow_accretion_oxygen_ledger.py, 14 rows). The impactor oxygen is 5.972e19 kg.

Output, last row Before (main) After (this branch)
M_accreted_rock (kg) 5.966028e22 5.972000e22
M_volatile_change (kg) 5.972e19 0
O_kg_total (kg) 9.725485e20 9.725479e20

The same check as a validation case on docs/Validation/accretion/wrapper.md, from that slow test:

accretion_wrapper_oxygen_ledger

Runs that must not change, 13 rows each to 2692 yr, same comparison script: with "user_constant", 0 of 1073 numeric columns differ between main and this branch; with "from_O_budget" (O budget 9.7e20 kg), 0 of 1073. The impact run above with "user_constant" (14 rows): 0 of 1073, with M_accreted_rock 5.972000e22 kg and M_volatile_change 0 on both trees. The column runtime (wall time) is left out of the count.

  • pytest -q -p no:randomly -m "not slow" on the 6 changed fast test files with the branch source at a72d1b33, in both file orders: 485 passed.
  • coverage run -m pytest on the same files: 23 changed statements in src, 0 missed (git diff -U0 a7e063ee a72d1b33 -- src against the missed lines of the coverage report).
  • Nightly on 043177b4, 25 of 25 jobs pass: https://github.com/FormingWorlds/PROTEUS/actions/runs/47505771308. The tip adds 2 merges of main: git diff --name-only 043177b4 a72d1b33 lists 9 files, those of Raise the VULCAN floor to 26.12.2 #1187 and Pass the chemical eddy diffusivity to the numpy path of Aragog #1188.
  • Edits to a copy of the branch source, same 6 files (the copy holds no stored plots, so 3 plot comparisons fail there without an edit: 482 passed, 3 failed before and after the edits). Call of the impact split check removed: 13 more tests fail (DID NOT RAISE). Its tolerance at 1e-3: 14 more (DID NOT RAISE). Its test for a negative part off: 8 more (7 DID NOT RAISE, 1 AssertionError). "from_mantle_redox" taken out of the flag: 14 more. The dummy term taken out of the closure rule: 5 more (3 AssertionError, 2 closure RuntimeError).

Not checked: a run to full solidification (the pairs above end at 2692 yr with a molten mantle); a run in which the front traps volatiles under "from_mantle_redox" (with trap_mode = "front" the 13-row pair completes on both trees, with the same 138 columns that differ, and traps nothing); atmodeller in a full run (the unit tests cover its flag; the runs use CALLIOPE); an impact with atmosphere loss in a full run (unit tests only); an impact under "from_O_budget" in a full run.

Late-time differences are not resolved. In 4 run pairs to about 8.4e5 yr (main 1571eb41 against 2 earlier commits of this branch, "from_mantle_redox", no impacts), the last T_magma of the branch differs from main by +6.7, +6.4, +2.5 and -17.6 %. The 4 main runs, whose planet.delta_T_super differs by 1e-12 of its value, spread by 6.8 % in the same quantity. M_core differs by +1.6274e-4 in all 4 pairs.

Size, from git diff --numstat a7e063ee..a72d1b33 and git ls-tree -l at both commits:

Category Files Lines added / removed Size on disk (KiB) Compressed (KiB)
plots 2 +2,424 / -0 +66.3 +16.2
tests 7 +665 / -32 +26.7 +7.4
docs text 8 +133 / -50 +13.1 +4.2
source 11 +132 / -86 +2.4 +0.6
stored data 1 +7 / -7 +0.4 +0.1
other 2 +4 / -2 +0.3 +0.1
total 31 +3,365 / -177 +109.2 +28.6

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

Under planet.fO2_source = 'from_mantle_redox' CALLIOPE and atmodeller fix the fO2 at the offset of the melt redox state and derive O_kg_total from it, as they do under user_constant. The truth table of outgassing_derives_o_kg_total now reads every source from the config validator, and a property test checks the rule for any value of the module and the source. Both fail until the rule counts from_mantle_redox.
The Zalmoxis core stays at core_frac of the planet without its kept volatiles when the outgassing derives the oxygen. The test now runs for CALLIOPE and atmodeller under user_constant and under from_mantle_redox. Under from_mantle_redox it fails until the derived oxygen leaves the kept mass: the core then falls by 0.325 of the oxygen inventory.
With the fO2 fixed by the melt redox state the next outgassing call replaces O_kg_total with the derived budget, so impactor oxygen credited to it leaves the mass ledger. The impact test now runs under from_mantle_redox for CALLIOPE and atmodeller and checks M_accreted_rock against the impact mass. Both cases fail until the oxygen goes into the rock: on the base the rock is short by the delivered oxygen.
Under from_mantle_redox the fixed fO2 is the offset of the melt redox state, fO2_shift_IW_mantle, and outgas.fO2_shift_IW is not read. The test checks that the oxygen rise warns under that source and that the message names the offset of the last row instead of the config value; under user_constant it keeps the config value. It fails until the check runs for from_mantle_redox and words the source.
Under planet.fO2_source = 'from_mantle_redox', CALLIOPE and atmodeller fix the fO2 at the offset of the melt redox state and, as under user_constant, derive O_kg_total from it on every call. outgassing_derives_o_kg_total now says so. With it, the Zalmoxis structure leaves the derived oxygen out of the kept mass, an impact puts the delivered oxygen into the rock (not into the budget, which the next outgassing call replaces), and the oxygen rise check runs. The docstring no longer claims that O_mode = 'ic_chemistry' needs user_constant; the config refuses it only with from_O_budget.

The oxygen warning names the fixed fO2 of each source: outgas.fO2_shift_IW under user_constant, and fO2_shift_IW_mantle of the last row under from_mantle_redox.

apply_impact refuses a split whose rock, delivered and lost volatiles do not add up to the impact mass, and one that credits delivered oxygen to a budget the outgassing derives. Both raise before anything moves.
…e_redox

The redox page now says that the outgassing derives O_kg_total from the fixed fO2 under from_mantle_redox, so the Zalmoxis structure counts that oxygen as mantle mass and impact oxygen goes into the rock. It also states where the atmodeller IW buffer differs from the CALLIOPE one at 1 bar: equal from 1000 to 8148 K, 0.18 log units lower at 700 K, and about 42 log units lower above 8148 K. The Deng et al. (2023) citation gets its footnote.
A short Earth run under from_mantle_redox with one dummy impact of 0.01 Earth masses and 1000 ppmw oxygen checks that the accreted rock equals the impact mass, that the impactor oxygen is in the rock, and that the derived O_kg_total moves by less than 1 % of the delivered oxygen across the impact. The test writes the validation plot of the ledger and runs in the aragog-accretion nightly shard on Linux.
The case explains the oxygen ledger of one impact under from_mantle_redox, its tolerances, the plot and the test command. The Kegerreis and Roche citations on the page use footnotes, with the definitions of the accretion reference page.
Under from_mantle_redox the outgassing derives O_kg_total as under user_constant, so the per-element closure with trapping or a seal must not hold oxygen to its reservoirs. The impact split check takes its tolerance from the clamped rock and the impact mass instead of the planet mass.
The impactor oxygen docstring and the generated config reference, the outgassing and interior reference pages, the fO2 warning module and two comments now name from_mantle_redox next to user_constant where the outgassing derives O_kg_total.
…test

O_kg_total changes by -2.96e16 kg at the impact also when the impactor oxygen goes into the volatile budget, so that clause passed on either booking. M_volatile_change takes the whole 5.972e19 kg there and none of it when the oxygen is rock. The two assertions that followed from the first are gone, and the nightly comment names the Linux-only test.
The validation case states what the volatile booking of the impactor oxygen does to M_accreted_rock and M_volatile_change, names CALLIOPE and its limit, and links from a new redox section on where the oxygen budget comes from. The atmodeller buffer gap above 8148 K is given at 8149 and 10000 K. The wrapper page cites Biersteker & Schlichting (2021) and the published Roche et al. (2026) with footnotes in the standard form, links the Zenodo data record, and names both jobs of the wrapper.
…ct mass

An event record may give a merged mass up to 1e-6 short of target plus impactor, so a small impactor can have a negative impact mass; its rock clamps to 0 and the split must still close. The trapping rule reads the source once.
The model page and the atmodeller constraint comment state the buffered oxygen of the melt redox source next to user_constant.
The atmloss_law docstring cites Roche et al. (2026), Kegerreis et al. (2020) and Biersteker & Schlichting (2021) with footnotes, and the reference page carries the published Roche et al. record.
…dox tracker

The redox page names the outgassing modules for which the oxygen budget is derived, moves the atmodeller buffer limits into their own subsection and lists giant impacts among the limits of the iron tracker. The impactor oxygen case moves its measured numbers into the reference answer, and the page title says what it checks.
The delivered and lost volatiles and the oxygen put into the rock must add up to the impactor content within 1e-12 of it. The check no longer depends on the impact mass, so an impact mass near zero and a clamped rock are checked like any other impact.
…ning conditions

Impact melting returns tracked solid iron to the melt like any rise of the melt fraction; only the iron of the impactor stays out of the reservoirs. The model page lists the 3 conditions of the oxygen rise warning, and the wrapper page restores the case layout sentence, cites Roche et al. (2026) in one form and states the numbers of the wrong booking under the tested quantities.
Each element of the impactor content must equal its delivered and lost parts, plus the rock oxygen for O, within 1e-12 of it, and no part may be negative or NaN. A transfer of mass between elements or a negative part offset elsewhere no longer closes.
Under from_mantle_redox the outgassing offset comes from the melt redox state, which planet.interior_chem.ferric_fraction_initial seeds; outgas.fO2_shift_IW has no effect there.
…gets

The slow ledger test asserts that the oxygen total of the impact row is the sum of its atmosphere, melt and solid parts, and that a row precedes the impact. The equal-to-target case uses round ppmw values that exceed the zero impact mass.
Under from_mantle_redox the offset follows the melt redox state, so it is not fixed. The config description, the docstrings and the oxygen warning name the fO2 that each outgassing call holds.
The melt redox page, the generated planet reference and the validation index give each paper its footnote with the DOI and SciX link from Crossref and ADS; the preprint links to arXiv. The validation index row of the redox case gets its plot cell.
…dry mantle

With dry_mantle the structure target leaves out all derived oxygen while the core base keeps it, since it is not a kept volatile; with a wet mantle only its atmospheric part leaves the target.
Both bookings conserve mass; the rule moves core_frac of the impactor oxygen into the core and keeps it out of the desiccation baseline, so the case names those effects and the model rule as its reference.
The fault matrix of the split test now takes 1e-9 of the impact mass from the delivered hydrogen as well, for a positive and a clamped rock, so the separate clamped deficit test goes; the deficit test with the fO2_source parametrization and an atmosphere loss stays.
The core share of impactor oxygen holds with the Zalmoxis structure, the atmodeller buffer threshold is 8148 K on every page, the fcc-hcp boundary names its temperature, and the impact page reads in shorter sentences.
…dget

The dummy outgassing builds its O reservoirs from the O of its species and keeps a user O budget as given, so the per-element closure must skip O there while it still stops a leak in another element.
The dummy O reservoirs are the stoichiometric O of its species and are not tied to O_kg_total, so the closure skips O for the dummy module as it does where the chemistry derives the total. The accretion and structure rule stays as it is.
@timlichtenberg
timlichtenberg requested a review from a team as a code owner December 5, 2026 15:59
@codecov

codecov Bot commented Dec 5, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 96.32%. Comparing base (a7e063e) to head (a72d1b3).

Additional details and impacted files
@@            Coverage Diff             @@
##             main    #1190      +/-   ##
==========================================
+ Coverage   96.13%   96.32%   +0.19%     
==========================================
  Files         174      174              
  Lines       29759    29778      +19     
  Branches     4909     4913       +4     
==========================================
+ Hits        28608    28683      +75     
+ Misses        773      756      -17     
+ Partials      378      339      -39     
Flag Coverage Δ
unit-tests 95.24% <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.

@timlichtenberg
timlichtenberg merged commit c5118bf into main Dec 5, 2026
15 checks passed
@timlichtenberg
timlichtenberg deleted the tl/o-budget-from-mantle-redox branch December 5, 2026 18:51
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