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
160 changes: 134 additions & 26 deletions docs/development/integrator-contract.md

Large diffs are not rendered by default.

72 changes: 37 additions & 35 deletions docs/development/tolerance-table.md

Large diffs are not rendered by default.

62 changes: 61 additions & 1 deletion parity_checks/discontinuity/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -343,7 +343,8 @@ issue: `clock_step[a=2.5,b=0.5]` at rtol 1e-12 on offset31, #1799's before and
1,185, for 12,912, and 56 table entries (`FLIPS_2046`), for 685; its part 2
adds 2,128 rows, for 15,040, and 79 entries (`FLIPS_2046_2`), for 764; its part
3 adds 6,644 rows, for 21,684, and 199 entries (`FLIPS_2046_3`), 93 of them
moved from earlier sections, for 870.
moved from earlier sections, for 870; and #2071 (below) adds 223 rows, for
21,907, and 15 entries (`FLIPS_2071`), for 885.

- **#1912's and #1913's cases** (`FLIPS_1912`, 41 entries): 20 of the 24 kept
one outcome on every run, none near its allowance. The four clock cases did
Expand Down Expand Up @@ -1410,3 +1411,62 @@ returned.
run on the interpreter was run 24 times, not 480 (`SHORT`), each run waiting
out its time limit; each failed every run. `many_switches_3000`, a run time
more than a flip, should not be drawn 480 times again.

## #2071's pair of crossings inside one step (D14)

`_cases/pair.py` adds the cases for the contract's D14, which the maintainer
took on 2026-12-04: what the engine owes where a residual crosses its surface
and crosses back inside one CVODES step, on the same side at both of the step's
ends, so that the root finder never sees the pair. It owes a screen of every
step, on every root: each window found, and its crossings located as any
other's (G3). The contract has the options not taken and their costs.

X' = w·(V - m) and V' = -w·(X - m), a harmonic oscillator about m = 2 from
(X0, V0), runs X through the band (c1, c2) = (1.985, 2.015) twice a period,
where X is fastest: a window of 0.03 each time, 10 over the run to t = 30, and
Y grows at k inside the band. The band sits where X is fastest so that each
window is well conditioned, its edges located to the run's error in X over
|X'| as any crossing's are; at a peak, a window hidden in one step is a near
graze (`graze_close`). The reference is a closed form (`band_oscillator` in
`_closed_forms.py`): the windows' edges by the arcsine, and their derivatives
in every parameter by the dual numbers (`_D`).

| case | what | owed |
|---|---|---|
| `band_window` | the band in a `.net` rate law, which today's engine roots as a state switch's signed residual; rows of another amplitude and phase (X0 = 2.5, V0 = 2.6: 9 windows, 0.038 wide) and of a band 0.2 wide | values: Y is k times the time X spends in the band |
| `band_window_sbml` | the same band as an SBML piecewise, which today's engine roots as a boolean condition (GH #72) | values |
| `band_window_event` | an SBML event the band triggers, which adds 1 to N as each window opens | values: N = 10, and X's and V's columns in w, X0 and V0 |

**Findings.**

- **Today's engine loses whole windows, with no warning** (#2055). At rtol 1e-6
and 1e-8 CVODES's steps here often outrun a window, which opens and closes
inside one step: `band_window` loses 7 of the 10 windows at rtol 1e-6 and 6
at 1e-8, its SBML piecewise keeps only 0 to 3 of the 10, and its event fires
5 times of 10 at rtol 1e-6 (#2056). Today's look and window screen read a
step only where it takes a large enough share of what is left to the next
stop, and read only a state switch's signed residual, never a boolean
condition or an event's trigger. 54 marks, the twins' included: 30 on #2055
and 3 on #1799 in `band_window`, 12 on #2055 in `band_window_sbml`, and 8 on
#2056 and 1 on #1799 in `band_window_event`.
- **At rtol 1e-10 the loss is a flip.** `band_window`'s plain points on u4 and
u31 come back two windows short on about two thirds of 480 draws, and pass on
the rest (`pair`, 4 entries).
- **The compiled twins agree.** Each of the 60 passes on as many of the 480
draws as its interpreter point.
- **Today's screen run on every step finds every window.** On a build of main
that runs it so, `band_window` keeps all 10 windows at every rtol, within 517
times its tolerance, as D14 owes.
- **The rest are other issues' failures.** At rtol 1e-12, on 1 to 5 of 480
draws, a crossing is located off in time by about 1e-8 (#2005's kind,
`located`, 7 entries). A sensitivity run in w, X0 and V0 on aligned2 records
the row on a stop up to 1e-12 from the time asked: on every draw at rtol
1e-12 (#1799's 4 marks), and on 4 of 480 at rtol 1e-10 (a `short` entry).
Two points, and one's twin, that came within 2 times of their judge from
lower medians are left out as near misses (3 entries). The judges are 5e3,
G11's floor judge: Y is read off 20 crossing times, each located only to the
run's error in X over |X'|, so Y's error runs to some 130 times its tolerance
for each rtol of X's own.
- **The FD-Jacobian retry is not a failure.** Ten of the draws' runs met
CVODE's `CV_ERR_FAILURE` at a band edge with no root yet, retried with the
difference-quotient Jacobian (GH #176), and passed, as designed.
2 changes: 2 additions & 0 deletions parity_checks/discontinuity/_cases/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
gap,
gap2,
gap3,
pair,
parked,
pulse,
residual,
Expand All @@ -38,6 +39,7 @@
gap,
gap2,
gap3,
pair,
)

# #2046 part 3 (G12): every case with a state switch also runs its plain points
Expand Down
47 changes: 43 additions & 4 deletions parity_checks/discontinuity/_cases/_flips.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,12 @@
as the step sequence moves by an ulp or so, left out of the sweep and the slice
with their counts (issues #1914, #1915 and #2037, phase 0 of #1781). #1914's
family cases come first, #1915's below them with their own count of runs, then
#1912's and #1913's cases on #1915's runs, and #2046's parts 1, 2 and 3 last,
on #1915's runs too (part 3's section also holds the compiled code's twins of
every state-switch case's plain points, the near ties' rows, and ``ode``'s
plain points of every case that sweeps columns, on the interpreter).
#1912's and #1913's cases on #1915's runs, then #2046's parts 1, 2 and 3, on
#1915's runs too (part 3's section also holds the compiled code's twins of
every earlier state-switch case's plain points, the near ties' rows, and
``ode``'s plain points of every earlier case that sweeps columns, on the
interpreter), and #2071's band cases last, on #1915's runs, their own twins
and plain points included.

Every point of the 14 family cases was run 545 times (#2037): at the committed
atol, and at ``atol_ratio*(1 + d)`` for values of d up to 2.5e-11 in size. The
Expand Down Expand Up @@ -2467,6 +2469,42 @@
}


# ── #2071 (D14): a pair of crossings inside one step ─────────────────────────
#
# Each point of the three band cases, their compiled twins and their plain
# points on the interpreter included, was run 480 times, as #1915's were. The
# rule is #1915's part 2's, band included.
WHY.update(
{
"pair": "on the runs that failed, Y came back short by whole windows: X ran through the band and out of it again inside one step, and the band's switch read one side at both of the step's ends, where D14 owes each window found and its crossings located (#2055)",
"near_3183_1066": "passed all 480 runs, but at up to 3183 times its tolerance against a median of 1066: within 2 times of the allowance from a low median, or within 1.5 times of it",
"near_2647_591": "passed all 480 runs, but at up to 2647 times its tolerance against a median of 591: within 2 times of the allowance from a low median, or within 1.5 times of it",
}
)

#: key: (runs passed, a kind of ``WHY`` or the reason itself), over ``RUNS_1915``.
FLIPS_2071 = {
"band_window[V0=2.6,X0=2.5]|rtol=1e-10,grid=aligned2,sens=none": (480, "near_3183_1066"),
"band_window[V0=2.6,X0=2.5]|rtol=1e-10,grid=aligned2,sens=none,engine=ode-compiled": (
480,
"near_3183_1066",
),
"band_window[V0=2.6,X0=2.5]|rtol=1e-10,grid=aligned2,sens=w+X0+V0": (476, "short"),
"band_window_sbml|rtol=1e-12,grid=u31,sens=c1+c2+k": (480, "near_2647_591"),
"band_window_sbml|rtol=1e-12,grid=u31,sens=none": (476, "located"),
"band_window_sbml|rtol=1e-12,grid=u31,sens=none,engine=ode-compiled": (476, "located"),
"band_window_sbml|rtol=1e-12,grid=u4,sens=c1+c2+k": (475, "located"),
"band_window_sbml|rtol=1e-12,grid=u4,sens=none": (478, "located"),
"band_window_sbml|rtol=1e-12,grid=u4,sens=none,engine=ode-compiled": (478, "located"),
"band_window|rtol=1e-10,grid=u31,sens=none": (157, "pair"),
"band_window|rtol=1e-10,grid=u31,sens=none,engine=ode-compiled": (157, "pair"),
"band_window|rtol=1e-10,grid=u4,sens=none": (150, "pair"),
"band_window|rtol=1e-10,grid=u4,sens=none,engine=ode-compiled": (150, "pair"),
"band_window|rtol=1e-12,grid=u31,sens=w+X0+V0": (479, "located"),
"band_window|rtol=1e-12,grid=u4,sens=w+X0+V0": (479, "located"),
}


#: Part 3's points that time out were run SHORT_RUNS times, not RUNS_1915.
from _cases._flips_input import SHORT, SHORT_RUNS # noqa: E402

Expand All @@ -2478,6 +2516,7 @@
**{k: (p, w, RUNS_1915) for k, (p, w) in FLIPS_2046.items()},
**{k: (p, w, RUNS_1915) for k, (p, w) in FLIPS_2046_2.items()},
**{k: (p, w, SHORT_RUNS if k in SHORT else RUNS_1915) for k, (p, w) in FLIPS_2046_3.items()},
**{k: (p, w, RUNS_1915) for k, (p, w) in FLIPS_2071.items()},
}


Expand Down
45 changes: 40 additions & 5 deletions parity_checks/discontinuity/_cases/_flips_input.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,10 +25,12 @@
as the step sequence moves by an ulp or so, left out of the sweep and the slice
with their counts (issues #1914, #1915 and #2037, phase 0 of #1781). #1914's
family cases come first, #1915's below them with their own count of runs, then
#1912's and #1913's cases on #1915's runs, and #2046's parts 1, 2 and 3 last,
on #1915's runs too (part 3's section also holds the compiled code's twins of
every state-switch case's plain points, the near ties' rows, and ``ode``'s
plain points of every case that sweeps columns, on the interpreter).
#1912's and #1913's cases on #1915's runs, then #2046's parts 1, 2 and 3, on
#1915's runs too (part 3's section also holds the compiled code's twins of
every earlier state-switch case's plain points, the near ties' rows, and
``ode``'s plain points of every earlier case that sweeps columns, on the
interpreter), and #2071's band cases last, on #1915's runs, their own twins
and plain points included.

Every point of the 14 family cases was run 545 times (#2037): at the committed
atol, and at ``atol_ratio*(1 + d)`` for values of d up to 2.5e-11 in size. The
Expand Down Expand Up @@ -96,6 +98,8 @@ def _part3(key: str) -> bool:

row, method = key.split("|", 1)
case = BY_NAME.get(row.split("[", 1)[0])
if case is not None and _after_part3(case.name):
return False
if case is not None and any(method.endswith(f",engine={e}") for e in case.axes.plain_engines):
return True
if (
Expand All @@ -108,6 +112,13 @@ def _part3(key: str) -> bool:
return any(f"[{off}={num(d)}]" in row for off in ("dtau", "dthr") for d in (NEAR, -NEAR))


def _after_part3(name: str) -> bool:
"""Whether ``name`` is a case of a section after #2046 part 3's (#2071's
on), whose own section measures its twins and plain points."""
names = [sec.name for sec in SECTIONS]
return any(name in sec.cases for sec in SECTIONS[names.index("2046-3") + 1 :])


SECTIONS = (
Section(
name="1914",
Expand Down Expand Up @@ -521,6 +532,30 @@ def _part3(key: str) -> bool:
flips_doc="key: (runs passed, a kind of ``WHY`` or the reason itself), over ``RUNS_1915``.",
claims=_part3,
),
Section(
name="2071",
set="runs1915",
runs_name="RUNS_1915",
flips_name="FLIPS_2071",
cases=("band_window", "band_window_sbml", "band_window_event"),
band=True,
comment=(
"# ── #2071 (D14): a pair of crossings inside one step ─────────────────────────\n"
"#\n"
"# Each point of the three band cases, their compiled twins and their plain\n"
"# points on the interpreter included, was run 480 times, as #1915's were. The\n"
"# rule is #1915's part 2's, band included."
),
why={
"pair": (
"on the runs that failed, Y came back short by whole windows: X ran through the "
"band and out of it again inside one step, and the band's switch read one side at "
"both of the step's ends, where D14 owes each window found and its crossings "
"located (#2055)"
),
},
flips_doc="key: (runs passed, a kind of ``WHY`` or the reason itself), over ``RUNS_1915``.",
),
)

#: key: (runs passed, kind), for entries a record of these sets cannot measure.
Expand Down Expand Up @@ -925,4 +960,4 @@ def _part3(key: str) -> bool:
NEAR_MARK_PHRASE = {"moved": "with #1998's moved state"}

#: The table's last lines, as written.
TAIL = '#: Part 3\'s points that time out were run SHORT_RUNS times, not RUNS_1915.\nfrom _cases._flips_input import SHORT, SHORT_RUNS # noqa: E402\n\n#: Every case\'s flips, by key.\nALL = {\n **{k: (p, w, RUNS) for k, (p, w) in FLIPS.items()},\n **{k: (p, w, RUNS_1915) for k, (p, w) in FLIPS_1915.items()},\n **{k: (p, w, RUNS_1915) for k, (p, w) in FLIPS_1912.items()},\n **{k: (p, w, RUNS_1915) for k, (p, w) in FLIPS_2046.items()},\n **{k: (p, w, RUNS_1915) for k, (p, w) in FLIPS_2046_2.items()},\n **{k: (p, w, SHORT_RUNS if k in SHORT else RUNS_1915) for k, (p, w) in FLIPS_2046_3.items()},\n}\n\n\ndef for_case(name: str) -> dict[str, str]:\n """The case\'s flips as ``Case.exclude``."""\n out = {}\n for k, (passed, kind, runs) in ALL.items():\n if k.split("|", 1)[0].split("[", 1)[0] != name:\n continue\n if passed == 0:\n head = f"failed all {runs} runs"\n elif passed < runs:\n head = f"a coin flip on the step sequence: passed {passed} of {runs} runs"\n else:\n head = f"rides on the step sequence: passed all {runs} runs"\n spread = "1 part in 1e12" if runs == SHORT_RUNS else "2.5 parts in 1e11"\n out[k] = f"{head} whose atol differed by up to {spread}; {WHY.get(kind, kind)}"\n return out\n'
TAIL = '#: Part 3\'s points that time out were run SHORT_RUNS times, not RUNS_1915.\nfrom _cases._flips_input import SHORT, SHORT_RUNS # noqa: E402\n\n#: Every case\'s flips, by key.\nALL = {\n **{k: (p, w, RUNS) for k, (p, w) in FLIPS.items()},\n **{k: (p, w, RUNS_1915) for k, (p, w) in FLIPS_1915.items()},\n **{k: (p, w, RUNS_1915) for k, (p, w) in FLIPS_1912.items()},\n **{k: (p, w, RUNS_1915) for k, (p, w) in FLIPS_2046.items()},\n **{k: (p, w, RUNS_1915) for k, (p, w) in FLIPS_2046_2.items()},\n **{k: (p, w, SHORT_RUNS if k in SHORT else RUNS_1915) for k, (p, w) in FLIPS_2046_3.items()},\n **{k: (p, w, RUNS_1915) for k, (p, w) in FLIPS_2071.items()},\n}\n\n\ndef for_case(name: str) -> dict[str, str]:\n """The case\'s flips as ``Case.exclude``."""\n out = {}\n for k, (passed, kind, runs) in ALL.items():\n if k.split("|", 1)[0].split("[", 1)[0] != name:\n continue\n if passed == 0:\n head = f"failed all {runs} runs"\n elif passed < runs:\n head = f"a coin flip on the step sequence: passed {passed} of {runs} runs"\n else:\n head = f"rides on the step sequence: passed all {runs} runs"\n spread = "1 part in 1e12" if runs == SHORT_RUNS else "2.5 parts in 1e11"\n out[k] = f"{head} whose atol differed by up to {spread}; {WHY.get(kind, kind)}"\n return out\n'
Loading
Loading