Repository navigation
tolerance table: an event's assigned value is differenced over kAssignedDifferenceStep, and a ratchet keeps the table whole (#2073, #2045) - #2151
Merged
Conversation
…nceStep (#2073) The three central-difference steps of an event's assigned value, in a species the value reads, in a parameter and in the time, were written as the literal 1e-6. kAssignedDifferenceStep, declared for them, was read only by the smooth test's rounding cap, which is worked out from that step, so a change to the constant would have moved the cap and not the steps. The steps read the constant now. No value changes. With the build's flags, src/cvode_simulator.cpp compiles to the same object file as on origin/main, byte for byte (Apple clang, x86-64). The tolerance table's row for the constant now describes the step it sets, and its pin is measured rather than read. Moved to 5e-7, seven tests of the two event-assignment files fail; at 2e-6, two (test_a_difference_that_rounds_by_more_than_it_resolves_is_refused at both); at 2e-7, ten; at 1e-5, five. So it is pinned both ways within a factor of two, and the counts under "What the table shows" move by one.
python/tests/test_tolerance_table_ratchet.py reads every constexpr
double named k... in the integrator's sources (cvode_simulator.cpp, the
new engine's crossing_record.hpp, and nonneg_clamp.hpp, whose constant
the table lists) and fails, in every PR's suite, on:
- such a constant with no row in docs/development/tolerance-table.md,
or with a number of rows other than its declarations;
- a row that names a test that does not exist, or that says **pinned**
or **reached only** and names none in its own cell;
- a row whose constant is gone and that is not marked removed, and a
row marked removed whose constant is still there;
- a constant whose row does not say **pinned**, unless it is one of
NOT_YET_PINNED, the 32 that had no pinning test when this landed;
- a file under src/ or include/ that declares such a constant and is
neither one of the integrator's sources nor listed, with why, in
OUTSIDE_THE_INTEGRATOR;
- a row it cannot read.
Its own tests show each failure, starting with a constant added without
a row.
The table did not read cleanly, so it is fixed rather than the reader
loosened. Seven rows named eight tests by a path that does not exist,
most of them a method of a class written as a top-level test; nine said
**pinned** or **reached only** and named their test only by pointing at
another row ("the test above") or describing it; the kTermEps row, the BNGSIM_SENS_PBAR row and the
BNGSIM_NO_WARM_CVODE row named tests in forms a reader cannot resolve
(a bare name, a glob, a bare class). How to read a row now says how a
test is named and how a removed constant's row is marked, and "Keeping
it current" says what the ratchet checks.
The table also said kClampNoiseAtols was the one constant the file
reads from a header. The integrator's two difference-quotient
Jacobians also read three of fd_jacobian.hpp's (the jump mend); the
table now says so, and #2150 asks whether they should have rows. British
spellings in the table are made American.
A row marked removed is an error only when no live row of its name is left, so one of kGolden's two declarations can go with its row marked removed. A test named with a path before its file is reported rather than passed over, prefixed literals are blanked, a row may omit its closing pipe, and the source tree is found by bngsim_source_root().
…2045) The table counts every constexpr named k..., the counts and caps among them (107 declarations, 72 doubles), and phase 3's numbers include counts, so a new constexpr int or std::array with no row now fails as a double does. A declaration's head is read to its first = { [ , ; or (, so a constexpr function, a constructor and if constexpr are not read as constants. Thirteen counts without a pinning test join NOT_YET_PINNED, nine files of non-integrator constants join OUTSIDE_THE_INTEGRATOR, and a named test must be one: a name beginning with test or Test.
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 #2073. Closes #2045. Both are phase 1 steps of #1781 (1.6 and 1.3).
#2073: an event's assigned value is differenced over
kAssignedDifferenceStepIn
apply_event_sensitivity_jump(src/cvode_simulator.cpp), the three difference steps of an event's assigned value were written as the literal1e-6: the step for a species the value reads, for a parameter, and for the fire time. They now readkAssignedDifferenceStep, which is 1e-6. Before this, that constant was read only by the smooth test's rounding cap, so the constant named the step but did not set it. The two1e-6 * fabsat the trigger's own ∂g/∂x and ∂g/∂p (lines 9463 and 9547) are outside the issue and were left as they are.No result changes.
cvode_simulator.cppwas compiled at origin/main and at the branch with the build's own flags (taken fromninja -t commands, Apple clang, x86-64), andcmpfinds the two object files identical.The pin was measured, not read. I moved the constant and ran the two event test files:
kAssignedDifferenceStep[a-species-1]and[a-parameter-1]test_event_assignment_derivative_step.py::test_a_smooth_value_that_curves_inside_every_wide_steptest_a_difference_that_rounds_by_more_than_it_resolves_is_refused[0.37]and[2.0])So the constant is pinned both ways, to (5e-7, 2e-6), within a factor of two each way.
docs/development/tolerance-table.md:#2045: a ratchet keeps the tolerance table whole
python/tests/test_tolerance_table_ratchet.pyruns in every PR's suite (python-tests.ymlhas no paths filter). It reads everyconstexprconstant namedk…in the integrator's sources:src/cvode_simulator.cpp,src/crossing_record.hppandinclude/bngsim/nonneg_clamp.hpp. It fails on:kGoldenis declared twice,kMaxNamedfive times);file.py::Class::test,::testin the file named before it,tests/file.cpp::test);`kName` (removed in PR #N);NOT_YET_PINNED. That list holds the 45 that had no pinning test when the ratchet landed, and it only shrinks: a new constant lands with a test that pins it;src/orinclude/that declares such a constant and is neither one of the integrator's sources nor listed inOUTSIDE_THE_INTEGRATORwith its reason. Phase 3 builds its engine in new files, and a new file is not a way around the table;Wider than the issue's letter. #2045 asks for the
constexprdoubles. The table counts everyconstexpr … k…declaration (107 at 1627a15, 72 of them doubles), and phase 3's new numbers include counts (D6's K), so the ratchet counts every type. Every one of those constants already had its row.Its own tests show each failure on a doctored copy of the tree or the table: a constant added without a row, in eleven forms (a new double, an array,
constbefore or after the type, a second declarator, a thirdkGolden, anint, astd::size_tin braces, astd::array, an attribute with a typedef,k2Pi). Also:kGolden's two declarations removed;kMaxNameddeclaration gone;NOT_YET_PINNEDgrowing;Comments, strings (prefixed and raw included), digit separators,
constexprfunctions,if constexprand constexpr lambdas are shown not to count. The size and file-size ratchets are phase 4's (#2068) and are not touched.What I changed in the table so a test can read it
test_event_sensitivity.py::TestStateDependentTrigger::…;TestABystanderDoesNotHideAJump::in the rows ofkStateSwitchAgreeRoundoff(twice),kStateSwitchLandingSteps,kStateSwitchRememberStepsandkStateSwitchRootSlack;::TestWhatIsMergedIsOneCrossingTime::test_coincident_crossings_that_move_apart_are_refused;::TestTheRealModels::test_the_floor_does_not_clear_a_structural_failure.kFarStartFloor,kAtPole,kEventJumpUlps,kSensFloorTauFraction,kStateSwitchNudgeTries,kStateSwitchResolveRefinements,kGolden(21823),ladder_firstandladder_ratio.kTermEpsnamestests/test_crossing_record.cpp::test_…and::test_…;BNGSIM_SENS_PBARlists its fourtest_pbar_unit_*tests by name;BNGSIM_NO_WARM_CVODEnamestest_warm_cvode.py::TestWarmColdParity.::Class::nameand C++ forms, and gains a Removed bullet.kFdJumpRatio,kFdJumpNoiseandkFdJumpParkedfromfd_jacobian.hpp, which have no rows. Whether they should is tolerance table: the integrator's difference-quotient Jacobians read three tuning constants of fd_jacobian.hpp with no rows #2150, filed during this work.Review
By AI models, two independent reviews of the whole branch.
/code-review(Claude Opus 5.5) at high effort, one round, at e150a82. Five findings, all fixed in 012debc, each with a test that fails without its fix:kGolden's two declarations and marking its row removed, which the rules ask, failed as "marked removed but is still there". The only edit that passed was deleting the row. A removed row is now an error only when no live row of its name is left.python/tests/test_x.py::test_y) was skipped without a check. It is now reported.U'"',LR"(…)") were not blanked, so aconstexpr doubleinside a string after one could be counted.__file__, where_source_root.py(run_tests.sh copies only test_*.py and conftest.py, so six test modules fail to import and the whole run aborts with zero tests executed #578, 69 test modules resolve repo paths by walking up from __file__, so run_tests.sh reports 245 false failures and 359 false skips #590) asks new code to callbngsim_source_root(). It does now, with the declared "not in this checkout" skip where there is no source tree.Fable 5.2 at medium effort, one round, at e150a82. It was given the diff, the two issues and CONTRIBUTING's review prompt, not my conclusions. Three findings:
constexpr k…(anintcount, astd::size_t, astd::array) passed with no row. The docstring also wrongly said the table does not count them. Fixed in 2dc17f8: the ratchet counts every type. 13 counts without a pinning test joinNOT_YET_PINNED, and nine files of non-integrator constants joinOUTSIDE_THE_INTEGRATOR, each with its reason.kGoldenremoval above, fixed in 012debc.::(python/tests/test_x.py) was fixed in 2dc17f8.Its notes, also fixed in 2dc17f8:
constexpr doublefunction followed by ak…name could be read as a constant;constexpr double const kX,constexpr [[maybe_unused]] double kX,constexpr sunrealtype kXandk2Pipassed with no row;testorTest.Commits after the last round of either review: 012debc (the five
/code-reviewfixes, plus two of Fable's) and 2dc17f8 (counting every type, the head reader, and requiring a named test to be a test). Each change in them comes with a test that fails without it.Left alone
[b=0.1]) are not checked, only the test they belong to.const, a macro or a bare literal, or as a direct-initializedconstexpr double kX(1.0), which reads as a function. None of these is in the table's count either. Oneconst(kMinAtolS) has a row by hand.fd_jacobian.hpphave no rows. This is a scope decision, filed as tolerance table: the integrator's difference-quotient Jacobians read three tuning constants of fd_jacobian.hpp with no rows #2150.Testing
test_event_assignment_derivative_step.py,test_event_value_time_step_sensitivity.py, and the source-census tests that readcvode_simulator.cppas text. Those aretest_jacobian_discontinuous_fallback,test_sensitivity_refusals_during_a_run,test_messages_carry_no_issue_references,test_windows_klu_ci_coverage,test_ci_source_pairing,test_changelog_fragments,test_codegen_jacobian,test_model_codegen_sensitivity,test_rhs_nonneg_clamp,test_sbml_event_chatter_biomd711,test_sbml_event_triggered_events,test_solver_stats_sens_countersandtest_expression_parser_thread_safety. All 405 tests passed on the rebuilt branch.test_tolerance_table_ratchet.py: 35 passed in about 7 s.test_ci_run_list_coverage.pyandtest_skip_audit.pypass with it.pre-commit runon the changed files,ci/changelog.py check, andsphinx -Won the docs all pass.ci/pre_push_pytest.py) passed at 2dc17f8. The SSH connection to GitHub was reset during that run, so the same commit, with the tree unchanged, was pushed again with--no-verify.benchmarks/perf_ab.py(origin/main vs HEAD)Run on an idle Mac mini (macOS 15.7, x86-64, 6 CPUs), 5 repeats plus a warmup, 3 warm runs each, wheels built from origin/main (4d590ea) and HEAD (2dc17f8). The 28 models of
benchmarks/_dev/suite_ode.jsonrange from 2 to 3,744 species.No significant slowdown: no model is flagged. That is expected, since the object file is byte-identical.