Skip to content

FullSpecialize: discontinuity problems hold the zero function, not a FunctionWrapper - #5013

Open
pankgeorg wants to merge 4 commits into
SciML:masterfrom
pankgeorg:fullspec-disco
Open

pankgeorg wants to merge 4 commits into
SciML:masterfrom
pankgeorg:fullspec-disco

Conversation

@pankgeorg

@pankgeorg pankgeorg commented Nov 18, 2026 •

Copy link
Copy Markdown
Contributor

Supersedes #4917.

Under FullSpecialize, the discontinuity problems hold the zero function itself instead of a FunctionWrapper when the callback types give a concrete problem type: concrete for a tuple of one callback type or a vector with a concrete element type, a small Union (split at the calls) for a tuple of a few types. maybe_discontinuity is only known at run time, so the types come from all callbacks in the set. A vector whose element type gives no concrete type keeps the FunctionWrapper, in concrete storage, as before; so do other specializations. The zero function converts to and from Float64, as the wrapper did.

Why: the wrapper calls through a function pointer set at run time, which --trim and WasmCodegen can't resolve. The Vector bracket's splat is fixed separately in SciML/NonlinearSolve.jl#1397.

Tested:

🤖 Generated with Claude Code

…FunctionWrapper

Under FullSpecialize the discontinuity problems hold the zero function itself in an
IntervalNonlinearFunction{false, FullSpecialize}; other specializations keep the
FunctionWrapper. The problem type is concrete when the continuous callbacks share one
type; mixed or type-erased sets use Vector{IntervalNonlinearProblem}. The zero function
converts its argument and result to Float64, as the wrapper does.

The wrapper calls through a function pointer set at run time, which --trim and
WasmCodegen cannot resolve.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@ChrisRackauckas

Copy link
Copy Markdown
Member

🤖 Automated comment from an AI agent running as @ChrisRackauckas — not written or reviewed by Chris.

PR: #5013

Reviewed head: 69dbbbb
Raw SHA-256: d1657c08b53f22632b9fd4fb2f63b74d040dc602536365ae058b27d9faf84b2a
Source SHA-256: 423a186ef5485df2ee3406eb8aa4896fdd1f8cfe5c37cc0c958aa4a8061d919f
Source: standard-review-v1 (harness-log)
Reviewer session: 01a1ef6f-dd9a-7213-9fe1-b94c1fc5e585
Slot: 1
Confidence: unknown
Own risk fixed before author rating/discussion: yes
Redaction: ran (substitutions=0)

Risk assessment

  • Risk: medium (M3)
  • Verdict: CHANGES
  • Reviewed head: 69dbbbb

Review report

VERDICT: CHANGES
Round: 1
Head: 69dbbbb
Slot: 1
CI: CI is not green
Session: 01a1ef6f-dd9a-7213-9fe1-b94c1fc5e585
Reviewer: codex-cli 0.169.0; model: gpt-6.2-sol

Risk

medium (M3: the opt-in discontinuity scan allocates more with mixed callback types under FullSpecialize)

Blocking findings

  • Blocking priorities: P2
  • [P2] lib/OrdinaryDiffEqCore/src/solve.jl:1001 — The type of the entire callback set determines cache storage. A FullSpecialize Tsit5 solve with a scalar callback marked maybe_discontinuity=false and one eligible vector callback stores its only root problem in an abstract vector. In two warmed runs with vector roots at 3/8 and 1/4, find_discontinuity allocated 928 bytes per call on the base and 1,168 bytes on this head. With two eligible scalar callbacks and the same vector callback, allocation rose from 1,904 to 2,400 bytes per call. Both revisions selected 1/4. Determine storage from the eligible callbacks and retain a concrete element type when possible. Cover the single eligible callback case and genuinely mixed eligible types with an allocation regression check.

Non-blocking findings

  • lib/OrdinaryDiffEqCore/test/disco_scalar_state_tests.jl:7 — The new Float32 fixture replaces the existing Float64-time root check. The independent probe passed with both precisions. Keep both in the regression test and express the Float32 allowance in units of eps(0.3f0) so its relationship to the time precision is explicit.

What I ran

  • julia --version reported Julia 1.13.2. The test environment resolved SciMLBase 3.58.0 and BracketingNonlinearSolve 1.12.8. The base and head probes used the same resolved dependency versions.
  • GROUP=Core julia --startup-file=no --project=../scratch/head/lib/OrdinaryDiffEqCore -e 'using Pkg; Pkg.instantiate(); Pkg.test()' printed OrdinaryDiffEqCore tests passed with 424 passes across 18 testsets. The changed test file passed 22/22 on the head. Running that file against the base yielded 21 passes and one failure at line 22, where the FullSpecialize cache still held a FunctionWrapper.
  • Ran test/Integrators_I/disco_tests.jl as a testset in each resolved environment with julia --startup-file=no --project="$TMPDIR/review-<revision>-env". Both revisions passed 38/38.
  • Ran disco_probe.jl on the head and disco_correctness.jl on the base with the same correctness assertions. Both passed 162/162. The probes used analytic results for forward and reverse roots, scalar and in-place vector states, Float32 through BigFloat times, four specialization modes, and mixed callbacks. The piecewise ODE probes produced identical sampled solutions and rejection counts on both revisions with detection enabled and disabled.
  • Ran disco_perf_probe.jl twice per revision using the resolved environments, with nine samples of 50,000 warmed scans per configuration. The mixed-case allocation counts above repeated exactly. A single eligible scalar callback by itself improved from 368 to 128 bytes per scan.
  • Ran disco_ad_probe.jl with Enzyme 0.13.221. The FullSpecialize bouncing-ball callback Jacobian with the default controller differed from the closed form by at most 1.7763568394002505e-15 on both revisions.
  • git diff --check origin/master...HEAD, Runic --check, and typos --format brief passed for the change. The checkout was clean. There were no repository-root AGENTS.md or CLAUDE.md files.
  • uv run --locked python --version printed Python 3.15.0 and warned that --locked had no effect outside a project. The checkout has no uv.lock.

What I did not verify

I did not inspect remote CI or run GPU jobs, other Julia versions, the full Integrators_I group, or the full AD group. The Enzyme probe covered ordinary callback handling with the default controller. Scan wall times varied between runs, so the performance finding rests on the reproduced allocation counts.

AUTHOR_GRADE: {"task":"perf","score":3,"difficulty":3,"rounds":1,"author_harness":"unknown","author_model":"unknown","note":"The typed singleton cut allocations and passed the numerical and Enzyme checks. Mixed callback sets reproducibly increased scan allocations."}

Head link: 69dbbbb


🤖 Posted by an AI agent — harness: codex-cli 0.169.0 · model: gpt-6.2-sol
Conversation: local session 01a1ef6f-dd9a-7213-9fe1-b94c1fc5e585 (no session URL)

…solves

`maybe_discontinuity` is a run-time field, so the element type of the
discontinuity problems now covers each callback type in the set: one
type gives a concrete vector, a few give a small `Union` that calls
split on, instead of an abstract `IntervalNonlinearProblem` vector.
The solve returns only the root and the return code, so a `Union` of
problem types does not box the solution.

Tests: the Float64 root check is back next to the Float32 one (with
the tolerance in units of `eps(0.3f0)`), and each root solve of a scan
allocates as much as one for a single scalar callback, for one vector
callback and for mixed callback types (nothing once the bracketing
solver does not splat the bracket, SciML/NonlinearSolve.jl#1397).

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@ChrisRackauckas

Copy link
Copy Markdown
Member

🤖 Automated comment from an AI agent running as @ChrisRackauckas — not written or reviewed by Chris.

PR: #5013

Reviewed head: 50bb67c
Raw SHA-256: 847533797dea6b533f97e68583ff56587f8b8fbd37adbf719d66c08fb4c03421
Source SHA-256: e5c2dc19252ce6c0b80d04c2058022d9113c76027e59a5490b8c07196bbea2f9
Source: standard-review-v1 (harness-log)
Reviewer session: 01a1f0ab-34ec-7753-8b9b-f4fb2ed5c02f
Slot: 1
Confidence: unknown
Own risk fixed before author rating/discussion: yes
Redaction: ran (substitutions=0)

Risk assessment

  • Risk: medium (M3)
  • Verdict: CHANGES
  • Reviewed head: 50bb67c

Review report

VERDICT: CHANGES
Round: 2
Head: 50bb67c
Slot: 1
CI: CI is not green
Session: 01a1f0ab-34ec-7753-8b9b-f4fb2ed5c02f
Reviewer: codex-cli 0.169.0; model: gpt-6.2-sol

Risk

medium (M3: measured allocation regression in the opt-in discontinuity scan for FullSpecialize)

Blocking findings

  • Blocking priorities: P2
  • [P2] lib/OrdinaryDiffEqCore/src/solve.jl:1007 — The non-tuple fallback drops concrete cache storage for homogeneous callback vectors. With CallbackSet([vcb], DiscreteCallback[]), a FullSpecialize Tsit5 integrator keeps the vector-backed set, but its one cached root problem now sits in a vector with abstract element type. For an eligible vector callback with roots at 3/8 and 1/4 in a unit step, two warmed probe runs measured 688 bytes per scan here, 560 on the PR base, and 256 on the prior head. All three selected 1/4. Infer the problem type from eltype(cbs) when the callback vector has a concrete element type, and cover the vector-backed set in the allocation regression test.

Non-blocking findings

None.

What I ran

  • julia --startup-file=no --version reported Julia 1.13.2. The resolved test environment used SciMLBase 3.58.0 and BracketingNonlinearSolve 1.12.8. The revision comparisons held dependency versions fixed.
  • GROUP=Core julia --startup-file=no --project=lib/OrdinaryDiffEqCore -e 'using Pkg; Pkg.test(; allow_reresolve = true)' in a scratch copy ended with OrdinaryDiffEqCore tests passed and 449 passes across 18 testsets. The changed test file passed 47/47. With the same file and the prior head's package source, the two mixed-tuple allocation assertions failed as 720 == 256 and 1488 == 512, with 45 other assertions passing.
  • test/Integrators_I/disco_tests.jl passed 38/38 when included under SafeTestsets in the resolved environment.
  • julia --startup-file=no --project=<resolved test environment> disco_union_probe.jl passed 77/77 on each revision. The probe checked analytic roots after callback reordering and a narrower second scan, and exercised mixed eligibility, tuples of up to eight distinct callback types, and homogeneous callback vectors. The repeated allocation measurements reproduced the vector regression above. The tuple with an eligible vector callback and an ineligible scalar callback improved from 1,184 bytes on the prior head to 656 bytes here.
  • git diff --check origin/master...HEAD, Runic --check, and typos --format brief on the changed files passed. The checkout was clean and had no root AGENTS.md or CLAUDE.md.
  • uv run --locked python --version printed Python 3.15.0 and warned that --locked had no effect outside a project. The checkout had no uv.lock or Python project configuration.

What I did not verify

Remote CI classification, GPU execution, the remainder of Integrators_I, and Julia versions other than 1.13.2.

AUTHOR_GRADE: {"task":"perf","score":4,"difficulty":3,"rounds":2,"author_harness":"unknown","author_model":"unknown","note":"The new tests catch the prior mixed-tuple allocation regressions. The non-tuple fallback increases scan allocations for a homogeneous callback vector compared with the base."}

Head link: 50bb67c


🤖 Posted by an AI agent — harness: codex-cli 0.169.0 · model: gpt-6.2-sol
Conversation: local session 01a1f0ab-34ec-7753-8b9b-f4fb2ed5c02f (no session URL)

A vector-backed callback set, such as `CallbackSet([vcb], DiscreteCallback[])`, takes its
problem type from the element type again when that is concrete, so its scan does not
allocate. Other non-tuple sets stay type-erased. The allocation test covers the case.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@ChrisRackauckas

Copy link
Copy Markdown
Member

🤖 Automated comment from an AI agent running as @ChrisRackauckas — not written or reviewed by Chris.

PR: #5013

Reviewed head: 89d8e53
Raw SHA-256: 46d9382c0f844f577b96d350cc4c3a8585fb6916ba8f15a8646e6c7022c5543b
Source SHA-256: 3a0216a651be3883f9e53ae3f067fca1028fd9434fde08a94cb609038fc55ad6
Source: standard-review-v1 (harness-log)
Reviewer session: 01a1f36e-a680-7d20-8bdf-a5f20f7a1a3e
Slot: 1
Confidence: unknown
Own risk fixed before author rating/discussion: yes
Redaction: ran (substitutions=0)

Risk assessment

  • Risk: medium (M3)
  • Verdict: CHANGES
  • Reviewed head: 89d8e53

Review report

VERDICT: CHANGES
Round: 3
Head: 89d8e53
Slot: 1
CI: CI unreadable; review only; merge gates unchanged
Session: 01a1f36e-a680-7d20-8bdf-a5f20f7a1a3e
Reviewer: codex-cli 0.169.0; model: gpt-6.2-sol

Risk

medium (M3: measured slowdown in opt-in discontinuity detection with nonconcrete callback-vector element types)

Blocking findings

  • Blocking priorities: P2
  • [P2] lib/OrdinaryDiffEqCore/src/solve.jl:75 — The allocation regression remains for callback vectors with an abstract element type. The fallback returns an abstract problem type, while _ode_init still stores direct zero functions. With FullSpecialize and CallbackSet(VectorContinuousCallback[cb], DiscreteCallback[]), a warmed unit-step scan for roots at 3/8 and 1/4 went from 560 to 688 bytes and from 0.766 to 0.876 µs versus base. A vector containing two distinct callback types went from 1,072 to 1,328 bytes per scan. The end-to-end Tsit5 solve with the first callback set went from 24,080 to 28,544 bytes, with identical results and step counts. The repeat reproduced all allocation counts and the scan slowdown. Keep the concrete wrapper-backed problem storage for callback vectors whose element type cannot give a concrete problem type, and add an allocation regression test for that fallback.

Non-blocking findings

None.

What I ran

  • julia --version reported Julia 1.13.2. The scratch manifests kept dependency versions fixed across the three revisions, including SciMLBase 3.58.0 and BracketingNonlinearSolve 1.12.8. uv run --locked python --version reported Python 3.15.0 and warned that --locked had no effect outside a project. The checkout has no Python lockfile or project configuration.
  • Included lib/OrdinaryDiffEqCore/test/disco_scalar_state_tests.jl in an isolated module with julia --startup-file=no --project=head -e 'module AffectedCoreTests; include(ARGS[1]); end'. The current file passed 52/52. Using the same file with --project=prior gave 51 passes and one failure, 624 == 256, at the new vector-backed allocation assertion. The merge base's own file passed 14/14.
  • Included test/Integrators_I/disco_tests.jl with julia --startup-file=no --project=head -e 'module AffectedIntegratorTests; using Test; @testset "Discontinuity integration" include(ARGS[1]); end'. All 38 assertions passed.
  • Ran julia --startup-file=no --project=base vector_probe.jl and repeated with --project=head and --project=prior. All 74 behavioral assertions passed on each revision, covering callback order, an ineligible callback, narrower trial steps, and empty vectors. The piecewise ODE solves all ended at 1.3750000259406705 versus the analytic 1.375, with 30 accepted and 19 rejected steps. The no-callback solve matched the base exactly.
Warmed workload Base bytes, µs Previous head bytes, µs Current head bytes, µs
Tsit5 solve without callbacks 2,512, 1.005 2,512, 1.004 2,512, 0.984
Homogeneous callback vector, root scan 560, 0.729 688, 0.811 256, 0.222
Homogeneous callback vector, complete solve with detection enabled 27,648, 44.044 32,288, 48.027 21,808, 31.912

Timings are per-call medians over 11 warmed batches. A head-first repeat pinned to one logical CPU reproduced the allocation counts and the homogeneous-vector speedup versus the base.

  • git diff --check origin/master...HEAD, typos --format brief, and julia --startup-file=no --project=@runic -m Runic --check passed on the changed files. The checkout remained clean and had no root AGENTS.md or CLAUDE.md.

What I did not verify

Other Julia versions, compilation latency, tests outside the two discontinuity suites, and remote CI.

AUTHOR_GRADE: {"task":"perf","score":3,"difficulty":4,"rounds":3,"author_harness":"unknown","author_model":"unknown","note":"The concrete-vector regression is fixed and the numerical probes match the base. Abstract callback vectors still allocate more than the base in both scans and full solves."}

Head link: 89d8e53


🤖 Posted by an AI agent — harness: codex-cli 0.169.0 · model: gpt-6.2-sol
Conversation: local session 01a1f36e-a680-7d20-8bdf-a5f20f7a1a3e (no session URL)

… no concrete type

Under `FullSpecialize`, a callback vector whose element type gives no concrete problem type
(for example `VectorContinuousCallback[cb]`, or a vector of two callback types) keeps the
`FunctionWrapper`-backed problems, in concrete storage, as on master. Tuples and vectors with
a concrete element type still hold the zero function directly. The test covers the fallback.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@ChrisRackauckas

Copy link
Copy Markdown
Member

🤖 Automated comment from an AI agent running as @ChrisRackauckas — not written or reviewed by Chris.

PR: #5013

Reviewed head: c0c62bf
Raw SHA-256: 7ae1b282eae0d1c2a53f29ab0fec7f8a61122d413afd59c7878707c0fbb60106
Source SHA-256: 8817b7fc6f73ad0cf31de5be35a5e3d73f0f4fc791940bd0c068c253a1d7d4c4
Source: standard-review-v1 (harness-log)
Reviewer session: 01a1f3b0-b131-7332-a5da-a77300a707b1
Slot: 1
Confidence: unknown
Own risk fixed before author rating/discussion: yes
Redaction: ran (substitutions=0)

Risk assessment

  • Risk: medium-high (MH1)
  • Verdict: MERGE
  • Reviewed head: c0c62bf

Review report

VERDICT: MERGE
Round: 4
Head: c0c62bf
Slot: 1
CI: CI is not green
Session: 01a1f3b0-b131-7332-a5da-a77300a707b1
Reviewer: codex-cli 0.169.0; model: gpt-6.2-sol

Risk

medium-high (MH1: ordinary callback initialization allocates more even with discontinuity detection disabled, and downstream validation is unverified)

Blocking findings

  • Blocking priorities: none
  • The previous per-scan allocation regression is resolved. Under FullSpecialize, all tested callback vectors with nonconcrete element types use concrete wrapper-backed problem storage again and match the merge base's scan allocation.

Non-blocking findings

  • lib/OrdinaryDiffEqCore/src/solve.jl:1025 — The mixed abstract-vector case allocates 5,232 bytes in init, up from 5,168 on the merge base. The subsequent solve! uses 23,680 bytes on both with discontinuity detection enabled. With detection disabled, the difference is also confined to initialization. The ordinary single-callback control allocates 32 bytes more in init at both round heads than at the merge base. Profile the wrapper-backed problem construction to remove the remaining setup allocation.

What I ran

  • julia --version reported Julia 1.13.2. Scratch manifests used the same dependencies for the merge base, previous head and current head, including SciMLBase 3.58.0 and BracketingNonlinearSolve 1.12.8. uv run --locked python --version reported Python 3.15.0 and warned that --locked has no effect outside a project. The checkout has no Python lockfile.
  • GROUP=Core julia --startup-file=no --project=head lib/OrdinaryDiffEqCore/test/runtests.jl passed all 460 assertions across 18 testsets. Including lib/OrdinaryDiffEqCore/test/disco_scalar_state_tests.jl in isolation passed 58/58 at head. Running that same test file against the previous head passed 54/58. The four failures were the concrete-storage and wrapper assertions for the two abstract-vector cases.
  • Included test/Integrators_I/disco_tests.jl in an isolated test module with julia --startup-file=no --project=head and repeated with --project=base. Each passed 38/38 and emitted two non-enclosing-interval warnings.
  • Ran julia --startup-file=no --project=base abstract_callback_probe.jl and repeated with the previous and current head projects. All 53 assertions passed on each revision. The probes checked analytic roots, skipped callbacks, an empty vector and complete Tsit5 solves against the analytic endpoint of 2.375. The endpoint values and accepted and rejected step counts matched exactly across revisions. A head-first repeat reproduced the allocation counts. In that repeat, the concrete-vector scan median went from 0.827 to 0.249 microseconds. The mixed abstract-vector solve median went from 57.6 to 57.2 microseconds.
Warmed workload Merge base bytes Previous head bytes Current head bytes
Concrete callback-vector scan 496 256 256
Vector{VectorContinuousCallback} scan 496 624 496
Mixed abstract callback-vector scan 816 1,008 816
Union-element callback-vector scan 752 944 752
Vector{VectorContinuousCallback} full solve 23,376 27,840 23,232
Mixed abstract callback-vector full solve 28,848 32,864 28,912
  • Ran julia --startup-file=no --project=base default_callback_control.jl with the same two head comparisons. The default Tsit5 solve with one continuous callback used 20,032 bytes on the merge base and 20,064 on both heads. The endpoint was identical. The no-callback control in the allocation probe used 3,216 bytes on all three revisions.
  • git diff --check origin/master...HEAD, typos --format brief and julia --startup-file=no --project=@runic -m Runic --check passed on the changed files. The supplied delta matched the Git diff and the checkout remained clean.

What I did not verify

Other Julia versions, compilation latency, downstream test suites and remote CI.

AUTHOR_GRADE: {"task":"perf","score":4,"difficulty":4,"rounds":4,"author_harness":"unknown","author_model":"unknown","note":"The delta restores baseline allocation in the abstract-vector scans and adds tests that fail on the previous head. A small setup allocation remains in full solves."}

Head link: c0c62bf


🤖 Posted by an AI agent — harness: codex-cli 0.169.0 · model: gpt-6.2-sol
Conversation: local session 01a1f3b0-b131-7332-a5da-a77300a707b1 (no session URL)

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants