Repository navigation
Build critter output after integration; apply forcings to diagnostics - #59
Merged
Merged
Conversation
Roessler, Daisyworld and EBM0D recorded their output by appending to state_variables inside dydt. Switch them to uses_post_history = True (as done for Lorenz63 in #56): dydt is now side-effect free, RK45 output equals the solver's accepted states (was off by up to 2e-2), euler keeps its final time point, rk4 works, and Roessler RK45 to t=200 drops from 5.35 s to 0.15 s. Daisyworld/EBM0D diagnostics move to populate_diagnostics_from_history via a shared _evaluate helper. Diagnostics computed after integration ignored registered parameter forcings: forcings are patched into param_values only inside the solver's dydt wrapper (e.g. Stommel's q used the unforced k). Factor that patching into Model.forcings_applied(t) (context manager, restores on exceptions) plus Model.call_with_forcings, use it in the solver wrapper and in all 13 populate_diagnostics_from_history methods. Melcher25 also skipped its per-time threshold path when alpha was forced. g24.Model3 is left for #58 (its regime k is hidden dynamical state). Closes #57 Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
|
Check out this pull request on See visual diffs & provide feedback on Jupyter Notebooks. Powered by ReviewNB |
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
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
Closes #57. g24 is split out to #58.
1. Roessler, Daisyworld, EBM0D: output built after integration (#57)
These three critters recorded output by appending to
state_variablesinsidedydt. They now setuses_post_history = True(asLorenz63does since #56), anddydtis side-effect free. Daisyworld and EBM0D compute their diagnostics inpopulate_diagnostics_from_history, through a shared_evaluate(t, x)helper, so the tendencies and diagnostics come from one code path.Compared with a baseline recorded on
mainbefore the change:Under RK45, the diagnostics now correspond to the accepted states, so their values shift slightly (e.g. EBM0D
OLRby up to 7e-3).method='rk4'now works for all three.2. Diagnostics ignored registered parameter forcings (already on
main)Parameter forcings are patched into
param_valuesonly inside the solver'sdydtwrapper. Diagnostics computed after integration therefore used unforced values. For example, Stommel'sqwas 0.5 where the forcedkgives 1.0. This affected every critter withpopulate_diagnostics_from_historywhenever a forced parameter fed a diagnostic.Model.forcings_applied(t)context manager, factored out of_build_forced_dydt(same replace-then-additive semantics; it now also restoresparam_valuesif an exception is raised), plus aModel.call_with_forcings(t, fn, ...)convenience. The solver wrapper uses it too.populate_diagnostics_from_historyimplementations evaluate each row inside it: Stommel, DampedSpring, Simple/Driven/Double/MultiPendulumBeta, both Stocker seesaws, TwoBoxCarbon, GenericBoxModel, Melcher25, Daisyworld, EBM0D. DoublePendulum read its parameters once, outside the loop; they are now read per row.alphawas forced viaregister_forcing.Tests (454 passed)
test_core_forcing_diagnostics.py: for each of the 13 critters, a model built withp = vand a default model with a constant forcingp → vmust give identical trajectories and diagnostics. With the fix monkeypatched out, all 13 cases fail, so none passes trivially. Also covers restore-on-exception and additive forcings.test_core_post_history_critters.py(Lorenz63, Roessler, Daisyworld, EBM0D):dydtpurity, RK45 output == independentsolve_ivp(model.dydt), euler includes the final time, rk4 agrees with RK45, and diagnostics are evaluated at the accepted states.Docs
Re-executed the affected demo notebooks: roessler, ebm0d, stommel, pendulums_and_spring, double_pendulum, melcher25, box_models_carbon. All run. Fixed the Roessler notebook's now-false "
t_spanmust start at 0" note.Not included
g24.Model3keeps its regimekas hidden dynamical state read back insidedydt, so it can't be converted mechanically. See #58.🤖 Generated with Claude Code