Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
28 changes: 14 additions & 14 deletions docs/development/integrator-contract.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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).

Expand Down Expand Up @@ -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
Expand All @@ -686,15 +686,15 @@ 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:

- **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,
Expand All @@ -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
Expand Down Expand Up @@ -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) |
Expand Down Expand Up @@ -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:
Expand All @@ -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
Expand All @@ -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
Expand Down Expand Up @@ -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
Expand Down
32 changes: 22 additions & 10 deletions docs/development/tolerance-table.md
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down Expand Up @@ -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 |
|---|---|---|---|---|---|---|
Expand All @@ -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

Expand Down Expand Up @@ -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
Expand Down
Loading
Loading