diff --git a/docs/development/integrator-contract.md b/docs/development/integrator-contract.md index e71fa2591..7d7a17fee 100644 --- a/docs/development/integrator-contract.md +++ b/docs/development/integrator-contract.md @@ -180,7 +180,7 @@ What G1 retires (from #1781): the restart placed δt past the surface (#82, #187), the kept time and its column terms (#1455, #1776), the stall carries and their ulp reaches (#928, #1229), the zero holds and the landing ladders (the retries of a restart at other distances from the surface; #1279, #763), -the numerical judgement of jump against bend (#763), and the slide detector's +the numerical judgment of jump against bend (#763), and the slide detector's band (#926, #1331, #1452, #1634). **Today.** Every evaluation of the right-hand side compares each condition @@ -199,7 +199,7 @@ root on its signed residual (`Model.state_switch_root_conditions`, the species a residual reads by 16 ulp, then 64, then 256; - the zero hold, which reports a residual that is exactly 0.0 as 2⁻⁴⁹ on the old side (#897), and the hold after 4 declined crossings (`StateSwitchHold`, #908); -- the judgement of jump against bend, for each reaction that reads the switch, +- the judgment of jump against bend, for each reaction that reads the switch, against a set of roundoff and slack constants (`kStateSwitch*`, #763); - the slide band (`refuse_slide_along_state_switch`, #926, #1452). @@ -675,7 +675,7 @@ owed (#2055 at the start, #2056 after an event), except on the slide, which owes none, and after an event at `park_o`, where they are refused as owed, read as a crossing within about 5 times rtol of the event; and so does a flow's column (a's or b's) on a border of the kinds, which sorts the state -into a neighbouring kind; where W's flow carries the state to O's side, te's +into a neighboring kind; where W's flow carries the state to O's side, te's column, which has a value, is refused (#2056). `joint_pair`: two switches located together, classified together; `joint_corner`, the same pair where that classification has two solutions, which owes a refusal by name (D16): on main @@ -686,7 +686,7 @@ AMICI fails the parked states, reading equalities as true after the state leaves, so it gives no second opinion here. -### G10. Chattering and Zeno behaviour end in a named refusal +### G10. Chattering and Zeno behavior end in a named refusal **Owed (D6).** A run never spends its budget flipping one switch back and forth. That happens two ways: @@ -694,7 +694,7 @@ That happens two ways: - **chattering**: a slide that is not followed, so the branch flips at every step. Under G8 that is a slide the record misread: a curved surface, or a flow nearly tangent on one side; -- **Zeno behaviour**: one switch's crossings accumulate toward an instant, each +- **Zeno behavior**: one switch's crossings accumulate toward an instant, each gap a fraction of the last, so that infinitely many fall before it. The engine counts each switch's crossings. When they accumulate by D6's rule, @@ -708,14 +708,14 @@ slide band are the only defence, and a slide they miss chatters until the run's budget runs out, as a `SimulationTimeout` or too much work. Events have two guards. An event that fires 50 times as a clamp goes dormant (`CHATTER_LIMIT`, GH #95), and 100,000 batches in a row, each within CVODES's root tolerance of the -last, raise a `SimulationError` that names Zeno behaviour (`CASCADE_LIMIT`, +last, raise a `SimulationError` that names Zeno behavior (`CASCADE_LIMIT`, #1158). The steady-state solver drops its roots after 1,000 restarts (`MAX_ROOT_RESTARTS`). **Checked by.** The chattering slides: `slide_curved` (#2021), `slide_species_sbml` (#2023: 45.6 million steps at rtol 1e-6), `slide_species` (#2030: 1.6 million steps on some step sequences, where others take 50), -`slide_pair` and `slide_pair_joint` (#1634). Zeno behaviour: `zeno_time`, whose +`slide_pair` and `slide_pair_joint` (#1634). Zeno behavior: `zeno_time`, whose `sin(1/(T - t))` crossings accumulate at T (refused today as `run.failed` in plain runs and its k column as unsupported, #2082, where D6 owes `solver.chattering`). It is a time switch, and its gaps go as 1/(πn²), so their @@ -859,14 +859,14 @@ the narrower classes below (D12). | a column of a grazing jump that it moves (`ġ⁻` zero) | owed | `SensitivityRefusedForParametersError`, D12 | G5 | `graze_exact` (its columns are returned today, or refused as come to rest: #2079) | | a column of a jump at the edge of a slide that it moves (`ġ⁺` zero) | permitted | `SensitivityRefusedForParametersError` | G5 | none yet | | a column of a parameter that moves a state across a surface more than one solution leaves | owed | `SensitivityRefusedForParametersError`, D12 | G9, D13 | `surface_start` and `surface_event`, D13's rows (returned one-sided: #2055, #2056) | -| a column that moves a state on its surface (at the start, or where an event leaves it) off it, at G9's other kinds, whose one-sided derivatives differ: a kink, which the suite owes a refusal at as at any other (#2046); and a flow's column on a border of the kinds, which sorts the state into a neighbouring kind | owed | `SensitivityRefusedForParametersError`, D12 | G9 | `surface_start` and `surface_event` (returned one-sided: #2055, #2056; refused as owed after an event at `park_o`); on the slide the columns have values, and their refusal is permitted (D4) | +| a column that moves a state on its surface (at the start, or where an event leaves it) off it, at G9's other kinds, whose one-sided derivatives differ: a kink, which the suite owes a refusal at as at any other (#2046); and a flow's column on a border of the kinds, which sorts the state into a neighboring kind | owed | `SensitivityRefusedForParametersError`, D12 | G9 | `surface_start` and `surface_event` (returned one-sided: #2055, #2056; refused as owed after an event at `park_o`); on the slide the columns have values, and their refusal is permitted (D4) | | a column an ulp from such a tie, where it has a value | permitted (D2) | `SensitivityRefusedForParametersError` | G7 | `coincident_and`, `coincident_state`, `switch_event` | | a column whose value two crossings' order decides, where a state crossing falls within the run's own accuracy of an event's or a time switch's instant but not on it; a column returned must be the true order's | permitted (D15) | `SensitivityRefusedForParametersError` | G7 | `state_event_tie` and `state_time_and`, their rows a millionth either side of t* (refused at rtol 1e-6, the true order's from 1e-8) | | the columns of a slide, until the engine computes them | permitted (D4) | `SensitivityRefusedDuringRunError` (`sens.refused_during_run`) | G8 | `slide_constant`, `slide_species`, `slide_species_sbml`, `slide_time`, `slide_exit`, `slide_curved` | | a flow that reads two slides' joint branch | owed (D5) | a plain run: a `SimulationError` with a code of its own; the columns: `SensitivityRefusedDuringRunError` | G8 | `slide_pair_joint` (its columns owe a refusal today) | | the columns of a parked stretch whose exit lies inside the run | permitted | `SensitivityRefusedForParametersError` (`parked_on_surface`), or `SensitivityRefusedDuringRunError` naming the branch it holds (`parked_event_onto`) | G9 | `parked_on_surface`, `parked_event_onto` | | a state at rest within the tolerance of a step | permitted | `SimulationError`, its message saying it came to rest on the surface (#1548) | G9 | `parked_asymptote` (refusing a slow approach that is not at rest is #1991's bug: `slow_threshold_run`) | -| chattering or Zeno behaviour | owed (D6) | `SimulationError` with the code `solver.chattering`, naming the switch, the instant and the count | G10 | the chattering slides, `zeno_time` (today `run.failed` in plain runs, and its k column refused as unsupported: #2082), `zeno_state` (today `run.failed`, come to rest on the surface, or at rtol 1e-12 a's and b's columns refused by parameters: #2057) | +| chattering or Zeno behavior | owed (D6) | `SimulationError` with the code `solver.chattering`, naming the switch, the instant and the count | G10 | the chattering slides, `zeno_time` (today `run.failed` in plain runs, and its k column refused as unsupported: #2082), `zeno_state` (today `run.failed`, come to rest on the surface, or at rtol 1e-12 a's and b's columns refused by parameters: #2057) | | two switches located together whose joint classification has more than one solution | owed (D16) | `SimulationError` with the code `solver.branch_not_unique`, naming the switches and the instant | G9 | `joint_corner` (today it chatters to its budget, or returns one answer with no warning: #2055) | | a branch that is not finite on its own surface, so that evaluating it there cannot help (a log, or a division by what vanishes there) | owed (D8) | a `SimulationError` with the code `solver.branch_not_finite`, naming the switch | G1 | `log_surface` (its plain runs return a value today) | | a switch a path cannot follow | owed | that path's refusal (D9) | G12 | `diffrax_state` (the JAX path's `UsageError`, `usage.method_unsupported`, which it gives today) | @@ -1051,7 +1051,7 @@ answers. *Decided: (a), with (b) as the later child.* Piecewise-linear gene-network models, built from steep switches on several thresholds, slide along the -intersections of their thresholds: a real modelling style, if rare in rule-based +intersections of their thresholds: a real modeling style, if rare in rule-based models. **D6. The chattering and Zeno guard** (G10). The rule's shape: @@ -1060,7 +1060,7 @@ models. the sliding mode; the run is refused only if the slide cannot hold either. This needs D4's sliding mode; under D4 (c), such a re-crossing is refused; - (b) K crossings of one switch whose gaps shrink geometrically, or fall under a - floor scaled to the run's time resolution, are Zeno behaviour, and refused. + floor scaled to the run's time resolution, are Zeno behavior, and refused. The refusal's type: - (i) a `SimulationError` with a code of its own (`solver.chattering`), and the @@ -1069,7 +1069,7 @@ The refusal's type: And the events' own guards, apart from it: an event that fires 50 times as a clamp goes dormant (GH #95), and 100,000 batches at one instant are refused as -Zeno behaviour (#1158). +Zeno behavior (#1158). *Decided: (a) and (b), with (i), and the events' guards kept as they are.* bngsim's codes already tell failures apart without a class for each; the @@ -1240,8 +1240,8 @@ the order in which the switches were declared. Its case is `joint_corner` Nothing, since #2046 added a case for each line this list held: -- Zeno behaviour whose gaps shrink geometrically, each a fraction of the last - (D6 (b)'s first clause), and Zeno behaviour on a state switch (G10): +- Zeno behavior whose gaps shrink geometrically, each a fraction of the last + (D6 (b)'s first clause), and Zeno behavior on a state switch (G10): `zeno_state`, the twisting oscillator; - the compiled and interpreted paths side by side, beyond `cube_switch` (G12): every case with a state switch runs its plain points on the compiled code diff --git a/docs/development/tolerance-table.md b/docs/development/tolerance-table.md index ace2235af..6140a88dc 100644 --- a/docs/development/tolerance-table.md +++ b/docs/development/tolerance-table.md @@ -149,8 +149,9 @@ then. No test checks that today, and it stays open. **Read, not run.** Each row was found by reading the constant's code, its comment, the commit that added it, its issue and the tests. No constant was moved and no test was run, so a pin is a judgment from the test's assertion and -its own numbers. The one exception is `kAssignedDifferenceStep`, whose pin -#2073 measured by moving it. Most margins ("against a rise past about 400") are +its own numbers. The exceptions are `kAssignedDifferenceStep`, whose pin #2073 +measured by moving it, and #1002's three jump-mend constants, measured the same +way in #2150. Most margins ("against a rise past about 400") are worked out from those numbers rather than stated by the test, so they are approximate, and three cells say they rest on arithmetic alone. Moving each constant and running its tests would settle every pin; that is not done here. @@ -325,18 +326,25 @@ one step (PR #1604, #1623), #908's hold, the slides stepped along their surfaces ## Named constants outside the count -Not of the form `constexpr … k…`, so not among the 107, but tuning numbers the -same: the event guards in `run`, three defaults the environment variables below -override, one `const`, and `kClampNoiseAtols`, from a header the file reads. +Not among the 107, which are `constexpr … k…` declarations of this file, but +tuning numbers the same: the event guards in `run`, three defaults the environment variables below +override, one `const`, `kClampNoiseAtols`, from a header the file reads, and +#1002's three jump-mend constants, from a header its Jacobians read. The file's two difference-quotient Jacobians, the dense one of `dq_jacobian.hpp` and the colored one of `sparse_jacobian.hpp`, also read three `constexpr` doubles of `include/bngsim/fd_jacobian.hpp`: `kFdJumpRatio`, `kFdJumpNoise` and `kFdJumpParked`, which set #1002's mend of a column whose step crosses a -jump, a mend that goes in phase 3 (G1). They have no rows here; #2150 asks -whether they should. That file's other seven are the step rule of the -steady-state solver and of `Model.jacobian()`, which the integrator does not -read. +jump, a mend that goes in phase 3 (G1). Their rows are the last three below +(#2150). Their pins were measured, by moving each constant, rebuilding and +running the mend's tests (`test_difference_quotient_jump.py`, +`test_differenced_jacobian_agreement.py`, `test_colored_fd_jacobian_steps.py`, +`test_differential_shapes.py`, `test_jacobian_discontinuous_fallback.py`, +`test_net_state_switch_stepping.py` and `test_steady_state_stagnation_escape.py`, +1,277 tests): every test passes at each value tried from a tenth of each +constant to more than 9,000 times it, and the rows give the values. That file's other seven, above the mend's banner, are the step +rule of the steady-state solver and of `Model.jacobian()`, which the integrator +does not read. | constant (line) | value and scale | what it guards | how it was set | first needed by | pinned by | phase 3 | |---|---|---|---|---|---|---| @@ -348,6 +356,9 @@ read. | `ladder_ratio` (21093, in `run`) | 2.0 | The spacing of the ladder's rungs | **measured**: 14 of Smith2013's 16 columns finish at 10, all 16 at 3.16, 2 and 1.5 | #183 | **reached only**: `test_sensitivity_unresolvable_rows.py::test_smith_sensitivity_column_finishes` runs 4 of the 16 columns; which 2 a ratio of 10 loses is not recorded | stays; `BNGSIM_SENS_FLOOR_LADDER_RATIO` overrides it | | `kMinAtolS` (7079, `const`, not `constexpr`) | the smallest normal double | Floors each sensitivity tolerance that is not above 0, since CVODES rejects a zero error weight | **derived**: nothing in a sensitivity lives at 1e-308 | #326: MODEL1703150000's infinite flux bounds | **pinned** against removal: `test_sensitivity_nonfinite_scale.py::test_a_tolerance_that_underflows_to_zero_is_floored` | stays | | `kClampNoiseAtols` (`include/bngsim/nonneg_clamp.hpp`) | 1e6 of a slot's own atol | How far below 0 a step must have started for GH #135's retry to stop reading the slot at 0 (the mark behind `kAtPole` and `kCarriedToOverflow`) | **measured**: the RoadRunner corpus's rescued states sit 80 to 1.3e4 atols below 0, BIOMD0000000338's pole 1e9 | PR #1354 | **pinned** against a rise past about 1e9, by those numbers: `test_clamp_far_below_zero.py::test_338_carried_to_its_pole_raises_rather_than_returning_it` | stays | +| `kFdJumpRatio` (`include/bngsim/fd_jacobian.hpp`) | 16 times the larger change of the row over the outer steps, f(y + 2h) − f(y + h) and f(y − h) − f(y − 2h) | A difference-quotient column reads a jump in a row, not a slope, where the row's change over the quotient's own step is more than this many times its change over each outer step, plus the floor below; the backward quotient that takes the entry's place is used only where it passes the same test. Without the test, beside X = 5 `if(X > 5, 0.04, 0.02)·X` read −1.3e6 for −0.02, and the run followed its predictor, 166% off at t = 60 | **none stated** for 16: the comment's argument (a slope, kink, extremum or inflection moves the row over one step by no more than a small factor of what it moves over the steps beside it; a jump moves it by the jump) puts it above a small factor and below any jump's size, which the measured range bears out | #1002, PR #1302 | **pinned** both ways, loosely, to (1, 1e8), measured in #2150: every test passes from 1.5 to 1e7. At 1 three tests fail, `test_difference_quotient_jump.py::test_a_sum_parked_on_its_threshold_is_not_mended` (two cases) and `test_net_state_switch_stepping.py::test_a_residual_on_an_unstable_surface_steps_on`; at 1e8, 13 tests fail, the mend's own tests of a jump read, among them `test_difference_quotient_jump.py::test_a_run_that_starts_on_a_threshold` and `::test_a_stiff_run_that_starts_on_a_threshold` | **goes**, with the mend (G1: the Jacobian is the branch in force's, so no column steps across a jump) | +| `kFdJumpNoise` (`include/bngsim/fd_jacobian.hpp`) | 1024 ε of the sum of the row's terms' sizes, the terms being the row's value and each entry times its species, from the matrix the solver formed | The floor under the jump test (`fd_jump_floor`): a row whose terms cancel answers a short step in counts of their last bit, which is a jump at that grain and none in the model | **none stated** for 1024. The floor's scale, the row's terms rather than its value, was **set by a case**: against a floor of the row's value BIOMD0000000091, mass action alone, had two entries taken for jumps | #1002, PR #1302 (ea1bcbca) | **pinned** against a rise past 1e7, measured in #2150: at 1e8 the floor hides the jumps and 14 tests fail, among them `test_difference_quotient_jump.py::test_a_run_that_starts_on_a_threshold` and `::test_a_run_that_starts_on_a_step_of_ceil`. Nothing holds it from below: at 0 every test passes. The case of a floor of the row's value is in `test_difference_quotient_jump.py::test_a_model_with_no_jump_has_nothing_mended`, on MODEL1812040006 (two false mends; b7a5d311 put it in BIOMD0000000091's place), and PR #1302 found that the own-row rule now also undoes those mends | **goes**, with the mend (G1) | +| `kFdJumpParked` (`include/bngsim/fd_jacobian.hpp`) | 1e-6 of the terms of the species' own row in the mended matrix | Whether a tested column's species moves away, and keeps its mends where its own row is among them and the run came from across the jump, or is parked at its own balance, where its rate is the solver's noise and its mends are undone (`fd_jump_unparked`) | **set by a case**: with V's asymptote 9e-11 under the #176 step and tolerances of 1e-8, the steady-state march read V moving away at t = 27.7 and, mended, never converged (residual 18 where main reaches 5e-10) | #1002, PR #1302 (7a6e7062) | **pinned** against a rise past 0.1, measured in #2150: at 0.5 three moving species are read as parked and their mends undone, and `test_difference_quotient_jump.py::test_a_run_that_leaves_the_threshold_it_starts_on`, `::test_a_run_that_starts_on_a_threshold_between_basins` and `::test_a_stiff_run_that_starts_on_a_threshold` fail; at 1, 14 tests. 0.5 is the share of a decaying fixture's own rate in its row's terms (0.1 of 0.2), so which tests fail there rides on rounding and may differ by platform; the 14 at 1 do not. Nothing holds it from below: at 0, the parked rule off, every test passes, as PR #1302 found, since the own-row rule now also excludes the #176 marches that set it | **goes**, with the mend (G1) | ## The new engine's constants @@ -480,7 +491,8 @@ constants". `python/tests/test_tolerance_table_ratchet.py` (#2045) holds the table to that in every PR's suite. It reads every `constexpr` named `k…`, of any type, as the counts above do, in the integrator's sources, `INTEGRATOR_SOURCES` there: this file, the new engine's -files and `nonneg_clamp.hpp`. It fails on such a constant with no row, or with +files and `nonneg_clamp.hpp`; and in `fd_jacobian.hpp` from the mend's banner +on, `INTEGRATOR_PARTS` there. It fails on such a constant with no row, or with a number of rows other than its declarations; on a row that names a test that does not exist, or that says **pinned** or **reached only** and names none; on a row whose constant is gone and that is not marked removed; and on a constant diff --git a/python/tests/test_tolerance_table_ratchet.py b/python/tests/test_tolerance_table_ratchet.py index af29a9f73..66c5386aa 100644 --- a/python/tests/test_tolerance_table_ratchet.py +++ b/python/tests/test_tolerance_table_ratchet.py @@ -8,7 +8,8 @@ ratchet that keeps the table whole. It fails when: * a ``constexpr`` constant named ``k…``, of any type, in one of the - integrator's sources has no row, or has a different number of rows from its + integrator's sources, or in the part of a file the integrator reads + (``INTEGRATOR_PARTS``), has no row, or has a different number of rows from its declarations (``kGolden`` is declared twice, and has a row for each); * a row names a test that does not exist, or a name that is not a test's (one that begins with neither ``test`` nor ``Test``): a ``python/tests`` file, a @@ -83,6 +84,23 @@ "include/bngsim/nonneg_clamp.hpp", ) +#: Files the integrator reads part of, each with the line its part starts at: +#: every ``constexpr`` named ``k…`` from that line to the file's end needs a +#: row, and those above it are outside, but for a name of the part's own +#: (``INTEGRATOR_PART_NAMES``), which needs its row wherever it is declared. +#: The integrator's two difference-quotient Jacobians (``dq_jacobian.hpp``, +#: ``sparse_jacobian.hpp``) read #1002's jump mend from ``fd_jacobian.hpp`` +#: (#2150); the file's step rule above it is the steady-state solver's and +#: ``Model.jacobian()``'s. +INTEGRATOR_PARTS: Mapping[str, str] = { + "include/bngsim/fd_jacobian.hpp": ("// ─── A quotient that steps across a jump (issue #1002)"), +} + +#: For each file of ``INTEGRATOR_PARTS``, the names its part's constants take. +INTEGRATOR_PART_NAMES: Mapping[str, str] = { + "include/bngsim/fd_jacobian.hpp": r"kFdJump\w*", +} + #: Files under ``src/`` and ``include/`` that declare ``constexpr`` constants #: named ``k…`` and are not the integrator's, each with why. OUTSIDE_THE_INTEGRATOR: Mapping[str, str] = { @@ -105,12 +123,6 @@ "src/model_builder.cpp": "the model builder's bound on a scan", "src/net_file_loader.cpp": "the .net loader's cap on a message's length", "src/nfsim_simulator.cpp": "the network-free simulator's message cap and seed range", - "include/bngsim/fd_jacobian.hpp": ( - "the step rule of the steady-state solver's and Model.jacobian()'s difference " - "quotient; the integrator's quotients read only its three jump-mend constants, " - "which the table names, without rows, under 'Named constants outside the count' " - "(#2150 asks whether they should have rows)" - ), } #: The ``constexpr`` constants whose row did not say **pinned** when this @@ -420,14 +432,38 @@ def audit( root: Path = ROOT, not_yet_pinned: frozenset[str] = NOT_YET_PINNED, outside: Mapping[str, str] = OUTSIDE_THE_INTEGRATOR, + parts: Mapping[str, str] = INTEGRATOR_PARTS, + part_names: Mapping[str, str] = INTEGRATOR_PART_NAMES, ) -> list[str]: """What keeps the table from being whole, a line each; empty when it is. - ``integrator`` maps each of the integrator's sources to its text, and - ``elsewhere`` every other C or C++ file under ``src/`` and ``include/``. + ``integrator`` maps each of the integrator's sources, and each file of + ``parts``, to its text, and ``elsewhere`` every other C or C++ file under + ``src/`` and ``include/``. Of a file of ``parts`` only what follows its + line is read. """ rows, problems = read_table(table_md) - code = {path: strip_cpp(text) for path, text in integrator.items()} + code: dict[str, str] = {} + for path, text in integrator.items(): + if path in parts: + start = text.find(parts[path]) + if start < 0: + problems.append( + f"{path} no longer has the line {parts[path]!r}, where the part of it " + "the integrator reads starts: mark that part again in INTEGRATOR_PARTS" + ) + continue + above = strip_cpp(text[:start]) + text = text[start:] + # A constant of the part's own name, declared above its line, is its too. + own = part_names.get(path) + for name in named_constants(above) if own else []: + if re.fullmatch(own, name): + problems.append( + f"`{name}` ({path}) is declared above the line its part starts at: " + "declare it in the part, with its row" + ) + code[path] = strip_cpp(text) declared: dict[str, list[str]] = {} # name -> the file of each declaration for path, text in code.items(): for name in named_constants(text): @@ -462,7 +498,9 @@ def audit( "removed, with the PR that removed it, rather than deleting it" ) if row.declared_in and row.declared_in not in code: - problems.append(f"{at}: {row.declared_in} is not one of INTEGRATOR_SOURCES") + problems.append( + f"{at}: {row.declared_in} is not one of INTEGRATOR_SOURCES or INTEGRATOR_PARTS" + ) elif row.declared_in and not re.search(rf"\b{row.name}\b", code[row.declared_in]): problems.append(f"{at}: `{row.name}` is not in {row.declared_in}, which its row names") @@ -522,7 +560,9 @@ def audit( @lru_cache(maxsize=1) def _tree() -> tuple[dict[str, str], dict[str, str]]: - integrator = {p: (ROOT / p).read_text(encoding="utf-8") for p in INTEGRATOR_SOURCES} + integrator = { + p: (ROOT / p).read_text(encoding="utf-8") for p in (*INTEGRATOR_SOURCES, *INTEGRATOR_PARTS) + } elsewhere = { path.relative_to(ROOT).as_posix(): path.read_text(encoding="utf-8") for top in ("src", "include") @@ -821,3 +861,46 @@ def test_a_row_the_reader_cannot_read_fails(old, new, says): def test_a_row_is_read_with_or_without_its_closing_pipe(): assert _cells("| `a|b` | stays |") == ["`a|b`", "stays"] assert _cells("| `a|b` | stays") == ["`a|b`", "stays"] + + +_MEND = "include/bngsim/fd_jacobian.hpp" + + +@pytest.mark.parametrize("name", ["kFdJumpSlack", "kTwoSteps"]) +def test_a_constant_added_to_the_jump_mend_without_a_row_fails(name): + # Any name, at the end of fd_jacobian.hpp: inside the part the integrator reads. + integrator, elsewhere = _tree() + added = dict(integrator, **{_MEND: integrator[_MEND] + f"\nconstexpr int {name} = 2;\n"}) + assert audit(added, elsewhere, TABLE.read_text(encoding="utf-8")) == [ + f"`{name}` ({_MEND}) has no row in the tolerance table: " + "give it one, with the test that pins it" + ] + + +def test_a_constant_of_the_step_rule_above_the_mend_needs_no_row(): + integrator, elsewhere = _tree() + text = integrator[_MEND] + at = text.index(INTEGRATOR_PARTS[_MEND]) + above = text[:at] + "constexpr double kFdNewStepRule = 1e-8;\n" + text[at:] + md = TABLE.read_text(encoding="utf-8") + assert audit(dict(integrator, **{_MEND: above}), elsewhere, md) == [] + + +def test_a_constant_of_the_mends_name_above_its_line_fails(): + integrator, elsewhere = _tree() + text = integrator[_MEND] + at = text.index(INTEGRATOR_PARTS[_MEND]) + above = text[:at] + "constexpr double kFdJumpSlack = 4.0;\n" + text[at:] + md = TABLE.read_text(encoding="utf-8") + assert audit(dict(integrator, **{_MEND: above}), elsewhere, md) == [ + f"`kFdJumpSlack` ({_MEND}) is declared above the line its part starts at: " + "declare it in the part, with its row" + ] + + +def test_the_line_the_mend_starts_at_gone_fails(): + integrator, elsewhere = _tree() + text = integrator[_MEND].replace(INTEGRATOR_PARTS[_MEND], "// ─── The jump mend") + md = TABLE.read_text(encoding="utf-8") + problems = audit(dict(integrator, **{_MEND: text}), elsewhere, md) + assert any(p.startswith(f"{_MEND} no longer has the line") for p in problems), problems