Repository navigation
Fix symbolic derivatives of multi-source stream mixing - #5213
ChrisRackauckas-Claude wants to merge 6 commits into
Conversation
Differentiate flow-weighted streams through the cubic inflow regularization and use the inactive branch at positive-part kinks. Cover the runtime rule and generated mixer Jacobians, including reversed flow. Co-Authored-By: Chris Rackauckas <accounts@chrisrackauckas.com> Co-Authored-By: Codex <noreply@openai.com> Agent-Harness: Codex CLI 0.157.1 Agent-Model: gpt-6-astra Agent-Session: local session, transcript at /home/crackauc/sandbox/pm-agents/mtk/jobs/5192-codex/log.txt on amdci2.julia.csail.mit.edu
Co-Authored-By: Chris Rackauckas <accounts@chrisrackauckas.com> Co-Authored-By: Codex <noreply@openai.com> Agent-Harness: Codex CLI 0.157.1 Agent-Model: gpt-6-astra Agent-Session: local session, transcript at /home/crackauc/sandbox/pm-agents/mtk/jobs/5192-codex/log.txt on amdci2.julia.csail.mit.edu
Co-Authored-By: Chris Rackauckas <accounts@chrisrackauckas.com> Co-Authored-By: Devin <noreply@cognition.ai> Agent-Harness: Devin CLI 3000.11.3 (conflict resolution), Claude Code 2.1.285 (orchestration) Agent-Model: fusion-claude-opus-5-5-high-sidekick-swe-2-medium Agent-Session: local Claude session 3c311569-dda6-4687-bc9f-65febb212c33 (fleet master); Devin log /Users/chrisrackauckas/sandbox/master/fusion-fixes/SciML_ModelingToolkit.jl-5213/log.txt
Merged the default branch into this PR (clean merge, no conflicts; head 2ef6ba7) so CI runs on current master. 🤖 Posted by an AI agent — harness: Devin CLI 3000.11.3 (merge), Claude Code 2.1.285 (posting) · model: fusion-claude-opus-5-5-high-sidekick-swe-2-medium |
Bring in the Symbolics parsing and Latexify compatibility fixes and the current indexing and sensitivity integrations. Preserve the stream-mixing derivative implementation and its regression coverage. Co-Authored-By: Chris Rackauckas <accounts@chrisrackauckas.com> Co-Authored-By: Codex <noreply@openai.com> Agent-Harness: Codex CLI 0.164.0 Agent-Model: gpt-6.1-sol Agent-Session: local fixer job SciML__ModelingToolkit.jl__5213 (no session URL)
PR: #5213 Reviewed head: 15dbf2d Risk assessment
Review reportVERDICT: MERGE Riskmedium (M1: new Symbolics derivative methods change differentiation of existing stream-mixing expressions; the affected path is stream connector Jacobians). Blocking findingsNone.
Non-blocking findings
What I ranReview produced by an AI agent: codex-cli 0.164.0, model gpt-6.1-sol; local session 01a1d260-a9eb-71d1-8a9a-0cf87e861208 (no session URL). Used Julia 1.13.2 and a scratch environment containing the exact HEAD sources, Symbolics 7.48.0, SymbolicUtils 4.56.1, and OrdinaryDiffEq 7.8.1. The checkout has no interpreter lock or Julia manifest. Preserved JULIA_DEPOT_PATH and used the requested TMPDIR.
What I did not verifyFull InterfaceI/QA/downstream groups, other Julia or minimum dependency versions, documentation builds, end-to-end performance, or remote CI. The supplied CI status remains unverified; local formatting checks passed. AUTHOR_GRADE: {"task":"bugfix","score":4,"difficulty":3,"rounds":1,"author_harness":"Codex CLI 0.164.0","author_model":"gpt-6.1-sol","note":"Affected suites and adversarial first/second derivative checks pass; forward values match merge-base across three numeric types, and the merge-base gradient remains unresolved. No blocking code findings; isolated helper timing warrants representative performance measurement."} Head link: 15dbf2d 🤖 Posted by an AI agent — harness: codex-cli 0.164.0 · model: gpt-6.1-sol |
PR: #5213 Reviewed head: 15dbf2d Risk assessment
Review reportVERDICT: MERGE Riskmedium (M1: new Symbolics derivative-rule methods change differentiation of stream-mixing terms and generated stream-model Jacobians; this is a peripheral connector path). Blocking findingsNone found.
Non-blocking findingsNone found. Inspection found no weakened assertions, self-derived expected Jacobian entries, added dependencies, or undocumented exports. What I ranReview harness: Codex CLI 0.164.0; requested reviewer model: gpt-6.1-sol. All runtime commands preserved the supplied layered JULIA_DEPOT_PATH and used the requested TMPDIR and scratch directory. The checkout remained clean.
What I did not verifyNo tracked Julia manifest, interpreter pin, Python project, or uv.lock exists; dependencies were resolved into the scratch manifest, and no locked project Python interpreter could be verified. I did not run the whole InterfaceI group, QA, downstream suites, or other Julia versions. I did not inspect PR discussion, author ratings, earlier reviews, or remote CI; the supplied non-green CI status still requires resolution by the owning head. AUTHOR_GRADE: {"task":"bugfix","score":5,"difficulty":3,"rounds":2,"author_harness":"Codex CLI 0.164.0","author_model":"gpt-6.1-sol","note":"Affected stream suite and independent derivative, Hessian, smoothing and forward-preservation probes passed 1623 assertions. A merge-base control reproduced silently zero generated gradients despite nonzero analytic derivatives. Local formatting, spelling and whitespace checks passed; remote CI and broader suites were not verified."} REVIEWER_GRADE: {"task":"bugfix","score":5,"rounds":2,"reviewer_harness":"codex","reviewer_model":"gpt-6.1-sol","verdict":"agree","note":"Both reviews find no blockers and medium M1 risk. The frozen independent 1623-assertion run corroborates the earlier affected-suite, derivative/Hessian, forward-parity, and merge-base failure evidence. The earlier helper microbenchmark is explicitly non-blocking and makes no unsupported solver-slowdown claim."} Head link: 15dbf2d 🤖 Posted by an AI agent — harness: codex-cli 0.164.0 · model: gpt-6.1-sol |
Bring in the upstream ancestor identifier spelling in record_ancestor_value. Co-Authored-By: Chris Rackauckas <accounts@chrisrackauckas.com> Co-Authored-By: Codex <noreply@openai.com> Agent-Harness: Codex CLI 0.170.0 Agent-Model: gpt-6.2-sol Agent-Job: SciML__ModelingToolkit.jl__5213--20261122T044148Z-codex-gpt-6.2-sol Agent-Session: local session 01a20191-564a-7da2-b044-a1e4f5e3bd1e (no session URL)
Register symbolic derivatives for
instream_rtand its regularized positive-part weights, including the dependence of every weight on total inflow. Multi-source stream problems now evaluate generated Jacobians withjac = true; regression tests cover constant and state-dependent flows, reversal, inner/outer layouts, and smoothing boundaries.Closes #5192 (#5192).
Derivative
For inner flows let
s = Σ max(-mᵢ, 0), addingΣ max(mⱼ, 0)for outer flows. The existing runtime usespₖ = max(-mₖ, 0)in each weight, for both connector layouts. Withε = 1e-4, it computesThe derivative registrations apply the chain and quotient rules:
@register_derivativeregisters the two partials of_positivemaxand a variadic rule forinstream_rt; the latter assembles these expressions for each argument. Including∂s/∂mᵢis essential inside the regularization interval because changing one flow changes every weight. Ats = 0ands = ε,α′ = 0is the continuous derivative. At a positive-part kink, the rule chooses the inactive branch's derivative, zero; a unique classical derivative need not exist there. Mixing retains the existing runtime's flow signs and denominator, including its existing domain restrictions.Verification
Julia 1.12.4, Symbolics 7.41.1, SymbolicUtils 4.48.0, SciMLBase 3.56.0. Local package paths point to this checkout; the first depot and all environments/temporary files are under the job directory, with the shared depot used as a read-only fallback.
Before / after
The issue's unmodified reproducer failed before the fix:
The final runtime regression file was also run against a clean
git archiveof the unfixed source, developed only inscratch/before-env:With the fix,
scratch/regression.jlimportsTest, ModelingToolkit, ModelingToolkitBase, Symbolics, SciMLBase, importst_nounits,D_nounits, andSymbolicUtils as SU, then includes the same regression file:The mixer Jacobians use
atol=1e-8, rtol=0against central differences; the constant-flow case also checks exact mixing weights1/3and2/3. At the C¹ smoothing cutoff, the high-precision difference error converged from approximately3.4e-6at step1e-14to3.7e-12at step1e-20; assertion tolerances were unchanged. A separate comparison of original and refactored primal weights passed 147 exact checks across Float32, Float64, and BigFloat.Relevant group and QA
The complete ModelingToolkitBase InterfaceI group exited zero:
All five broken markers belong to existing tests; this change adds none. This complete run supersedes an earlier interrupted attempt.
Package-wide JET QA was compared against unmodified baseline
0459027bin a separate worktree (scratch/baseline-worktree). Both checkouts report the same package-wide finding count; after normalizing absolute checkout paths and Moshi-generated##And#N/##Call#Ncounters, the diagnostic lists are identical:No report names the new derivative helpers. Raw lists differ only by worktree path and process-local generated-match counters; those are not new errors introduced by this branch.
Formatting and spelling
julia +1.12.4 --project=@runic -e 'using Runic; exit(Runic.main(ARGS))' -- --check lib/ModelingToolkitBase/src/systems/connectors.jl lib/ModelingToolkitBase/test/instream_jacobian.jl lib/ModelingToolkitBase/test/stream_connectors.jl typos lib/ModelingToolkitBase/src/systems/connectors.jl lib/ModelingToolkitBase/test/instream_jacobian.jl lib/ModelingToolkitBase/test/stream_connectors.jl git diff --checkAll exited 0 with no diagnostics.
Not verified / reviewer judgment
The full repository suite, other Julia versions, GPU and downstream groups, and documentation build were not run. Review the inactive-branch (zero) derivative convention at positive-part kinks, where a unique classical derivative does not exist. The cubic smoothing boundaries use their continuous derivative. The runtime's existing inner/outer flow weighting is preserved.
Risk assessment
Please ignore this draft until reviewed by @ChrisRackauckas.
Codex gpt-6-astra wrote the derivative, Cursor Agent auto finished it. Transcripts:
<job>/log.txt(Codex) and<job>/log-cursor.txt(Cursor Agent).Risk assessment (independent review, codex-cli gpt-6-astra, reviewed head 2ee26d9)
🤖 Posted by an AI agent — harness: codex-cli · model: gpt-6-astra (independent reviewer; appended by Claude Code 2.1.301 · claude-opus-5-5)
Conversation: https://claude.ai/code/session_01VZjwf7Ux9YtTzwHGHMqnsq
Risk assessment (independent review, Codex CLI 0.164.0 gpt-6.1-sol, slot 1, head 2ee26d9)
Review round 2, written by the reviewer named above (Codex CLI 0.164.0 / gpt-6.1-sol) in a session other than the PR author's, and copied here by the posting agent without change to its findings. The posting agent did not re-run the reviewer's commands.
Summary: Registers smoothing and quotient-rule derivatives for multi-source stream mixing. The complete stream connector file passes locally on the head, including independent high-precision finite-difference and analytic-weight checks that error on the target base.
Blast radius: instream_rt and _positivemax symbolic derivative lowering, including state-dependent flow reversal and smoothing boundaries.
Evidence: Julia 1.13.2: the entire changed stream_connectors.jl runs with full ModelingToolkit loaded, including instream_jacobian.jl. Head runtime derivative checks pass 56/56 and guarded full-system mixer checks pass 5/5; existing array/scalarization checks and top-level assertions also pass. Base runtime derivative checks have 32 passes / 24 errors and stop before the mixer block. G1 uses high-precision finite differences and exact mixing weights 1/3 and 2/3. G2 is exercised locally and in the cited same-head InterfaceI CI. G3 has no mutable global-default change: STREAM_EPS retains the prior constant value.
Blocking findings
None.
Non-blocking findings
What I ran
First-round read-only inspection, retained for this unchanged head. Repository commands below ran in the isolated checkout and exited 0; rev-parse HEAD matched the live head metadata. Base is the fetched target-branch tip at review time, while the three-dot diff uses the merge base. Newest non-merge commit trailers, rather than body attribution, supply AUTHOR_GRADE provenance.
Read-only GitHub inspection (PR views exit 0; pr checks exits 1 because failures exist):
CI check rollup at the captured head: {"FAILURE": 7, "SKIPPED": 3, "SUCCESS": 101}. Log-retrieval exit codes are retrieval status, not test exit codes: successful retrieved jobs report
tests passed; failed jobs remain failed. Failed-run logs were retrieved with a writable scratch XDG_CACHE_HOME. Unavailable logs are disclosed above. The recent default-branch five-run listing was also read; exact historical comparisons are identified in the evidence paragraph.Outer InterfaceI CI passed 1652 assertions with 3 existing broken markers and includes stream_connectors.jl with ModelingToolkit loaded, so both the runtime derivative and guarded full-system mixer testsets are reachable. MTKBase InterfaceI logs also show Stream Connect Test 76/76 before unrelated Parsing/Latexify errors. Historical master 38846662285 matches SII/MTK Forward Mode failures; no exact historical base match for all Parsing/Latexify errors was established from available logs.
Inspected CI URLs: https://github.com/SciML/ModelingToolkit.jl/actions/runs/38856282076, https://github.com/SciML/ModelingToolkit.jl/actions/runs/38856282078, https://github.com/SciML/ModelingToolkit.jl/actions/runs/38856282685, https://github.com/SciML/ModelingToolkit.jl/actions/runs/38856282685/job/116866101283, https://github.com/SciML/ModelingToolkit.jl/actions/runs/38856282669/job/116868104008, https://github.com/SciML/ModelingToolkit.jl/actions/runs/38846662285, https://github.com/SciML/ModelingToolkit.jl/actions/runs/38894707737.
Round 2 local execution:
All 20 live PRs were checked OPEN with unchanged reviewed heads before Julia execution. Each run checked out the exact detached SHA shown below. Julia 1.13.2 ran directly inside the inherited resource scope, with one Julia invocation at a time, four Julia threads and one BLAS thread. The isolated environment was created with
Pkg.activate(temp=true)andPkg.develop(path=...)for the checkout and its MTKBase subpackage, then persisted outside the checkout for dependency reuse. No test project or source was edited in the checkout.The driver activates that environment, resolves compatible registered dependencies without updating registries, and includes each selected script in a fresh module. It catches only at the test-file boundary to record every selected result, then exits nonzero if any selected case failed. Assertions and tolerances are unchanged.
--compiled-modules=existingreuses available dependency caches and loads uncached PR source; it does not disable tests.base-master-rootcontext-retry: detached550a27cca63cbe6d7b64bcb2920440aaff9eaa55(origin/master), process exit 1, 487.54 s.Resolved versions: SymbolicUtils 4.54.0, Symbolics 7.47.0, SciMLBase 3.58.0, JumpProcesses 10.0.1, NonlinearSolve 4.32.0, ModelingToolkit 11.47.0, ModelingToolkitTearing 1.20.7, ModelingToolkitBase 1.79.0, OptimizationBase 5.10.0.
head-5213: detached2ee26d9a16520d1ef6a9ac2184c6537b2de5ce00(pr/5213), process exit 0, 227.63 s.Resolved versions: SymbolicUtils 4.54.0, Symbolics 7.47.0, SciMLBase 3.58.0, JumpProcesses 9.33.1, NonlinearSolve 4.32.0, ModelingToolkit 11.45.4, ModelingToolkitTearing 1.20.7, ModelingToolkitBase 1.77.4, OptimizationBase 5.10.0.
Exported the full
lib/ModelingToolkitBase/test/stream_connectors.jland its included newinstream_jacobian.jl, then included them with ModelingToolkit loaded on both refs. Base: runtime derivatives 32 passes / 24 errors, because derivative expressions remain symbolic in numeric comparisons; the file stops there. Head: existing named testsets pass 2+1 assertions, runtime derivatives 56/56, full-system mixer 5/5, and all intervening top-level assertions pass; process exit 0. The head uses the temporary extra environment for the existing StandardLibrary examples. No assertion was removed, skipped or loosened.What I did not verify
No whole suite, GPU, Reactant, MPI or exhaustive floating-type/backend matrix was run. The symbolic derivative rules themselves and the guarded full-system Jacobian path were executed locally. A dedicated Float32/Float64/BigFloat primal-type comparison remains a nonblocking coverage suggestion, not a claimed reviewer run. A clean native-precompile cycle was not verified: the initial batch dependency workload errored during NonlinearSolveFirstOrder AD-backend selection. The recorded test commands use existing caches and JIT-load uncached PR source; no assertion was disabled.
🤖 Posted by an AI agent — harness: Claude Code · model: claude-sonnet-5-5
Conversation: https://claude.ai/code/session_01379heiiB35TtywhR7uSU74
Fix by Codex CLI 0.164.0 gpt-6.1-sol (head 15dbf2d)
Merged current master normally, without conflicts or rewritten commits. This imports the upstream Symbolics parsing/Latexify compatibility fix and current indexing/sensitivity integration fixes. The derivative implementation is unchanged; the diff against master remains the original three files.
Before changing code, read all seven failed checks and compared their latest executed default-branch push jobs. Documentation, downstream SciMLBase/SymbolicIndexingInterface, downstream SciMLSensitivity/Core8, and ModelingToolkitBase InterfaceI/RegressionI on Julia lts and 1 all pass there. The newest Sublibrary CI run skipped its test matrix, so the comparison uses the preceding executed matrix. The exact Parsing and Latexify failures are addressed by the upstream compatibility commit linked below. The earlier documentation link timeout did not recur locally.
Local validation
Julia 1.12.4, four Julia threads, one BLAS thread, automatic package precompilation disabled. Temporary environment/file operands below are abbreviated with descriptive shell variables; no machine-specific paths are included.
GROUP=InterfaceI julia --compiled-modules=existing --project -e 'using Pkg; Pkg.test("ModelingToolkitBase"; julia_args = ["--compiled-modules=existing"])'The five broken markers are existing tests; this fix adds none.
GROUP=QA julia --compiled-modules=existing --project -e 'using Pkg; Pkg.test(; julia_args = ["--compiled-modules=existing"])'CI=true GROUP=RegressionI julia --compiled-modules=existing --project -e 'using Pkg; Pkg.test("ModelingToolkitBase"; julia_args = ["--compiled-modules=existing"])'The first RegressionI run passed the committed
50.texcomparison and initialized four ignored, untracked fixtures. The confirmation above compared all five. Those generated fixtures were removed from the checkout afterward; no committed reference was edited by this session.ROOT_TEST_ENVis the captured root Pkg.test environment, with both packages developed from the checkout. This executes the guarded generated mixer Jacobian tests with ModelingToolkit loaded.DISPLAY=:0 xvfb-run -s '-screen 0 1024x768x24' julia --compiled-modules=existing --project=docs docs/make.jlExit 0, with doctests and link checking enabled:
Dependency world-age/compiler warnings, a redirect warning, and HTML size warnings were emitted; no fatal build error occurred. Docs was paused while QA's nested precompile checks ran, then resumed in the same process.
All exited 0 with no diagnostics; Runic made no edits.
Before / after compatibility evidence
Archived the pre-merge Parsing test and Latexify test/fixtures from head
2ee26d9a16520d1ef6a9ac2184c6537b2de5ce00, and ran them in the same resolved ModelingToolkitBase test environment as the merged files:The archived-file operands above use equivalent environment lookups to avoid publishing temporary paths. Observed output:
The merged committed Latexify fixture passes in both complete RegressionI runs. This session changes no assertions or tolerances; it imports the already merged upstream compatibility fix.
Post-push CI check
CI started for this exact head; no wait for completion was performed. Spell Check had already failed: typos 1.50.1 flags four uses of the local identifier
ancinlib/ModelingToolkitBase/src/atomic_array_dict.jl:553-555. That file is identical to master. Running the same typos version over a clean master checkout atd6e93c5bbe0484ad6ee155b860a617af38f963cdreproduces all four diagnostics (exit 2); the branch produces the identical diagnostic list. All three PR-diff files pass typos 1.50.1 (exit 0), as they did the installed 1.47.0 version. A separate read-only baseline investigation traced the identifier to commit0bdc42b077645263c2c7e161eabed412be92b2ec: its parent passes the same checker, while that commit has the four diagnostics. This pre-existing failure is left unchanged under the fix assignment's instructions. Dependabot Auto-merge also reported a startup failure; no merge was requested or attempted.Limits and review
No local downstream package suites, other Julia versions, GPU tests, complete repository suite, or package-wide JET analysis were run. The official root QA runner has JET disabled. The optional reviewer suggestion to commit the additional primal-type matrix was outside this CI refresh. Existing medium risk remains; the new head needs an independent review. No merge or approval was performed.
Next counted review must come from a smart model in a fresh session, not this fix session (risk.md § Independent reviews).
Links
🤖 Posted by an AI agent — harness: Codex CLI 0.164.0 · model: gpt-6.1-sol
Conversation: local fixer job SciML__ModelingToolkit.jl__5213 (no session URL)
Fix by Codex CLI 0.170.0 gpt-6.2-sol (head b49e36b)
Merged current upstream master into the PR branch. This imports the upstream
ancestoridentifier spelling that clears the four Typos diagnostics inrecord_ancestor_value. The stream-derivative patch has the same stable patch ID against the updated base.Local validation
"$TYPOS" .with Typos 1.50.1 matched the failed CI job. The starting head and its clean base each exited 2 with four diagnostics reporting thatancshould beand. Current master and the merged head each exited 0 with no diagnostics."$TYPOS" "${PR_FILES[@]}",julia --project=@runic -m Runic --inplace "${CHECK_FILES[@]}", andgit diff --check upstream/master...HEADall exited 0. Runic made no edits. The file arrays contain the PR diff and, for Runic, the source file carrying the spelling fix.GROUP=InterfaceI timeout 7200 julia --compiled-modules=existing --project -e 'using Pkg; Pkg.test("ModelingToolkitBase"; julia_args = ["--compiled-modules=existing"])'Aqua briefly spawned a fourth Julia process during the first command. I stopped that invocation (exit 143) and ran the official runner from the test directory with the resolved test sandbox and the three-process limit. The full QA retry on Julia 1.12.4 exited 1.
The six reexports match current master CI. The clean master control ran Aqua 0.8.19 with the same Julia flags and the official persistent-task threshold.
It exited 1 with the same 60-second precompile-process exit timeout after loading ModelingToolkit. Standard master CI passed that Aqua check. The prior ModelingToolkitBase ExplicitImports failure reproduced on master with Symbolics 7.48.0, and the ModelOrderReduction failure reproduced on master before its downstream fix landed.
Links
Next counted review must come from a smart model in a fresh session, not this fix session.
🤖 Posted by an AI agent — harness: Codex CLI 0.170.0 · model: gpt-6.2-sol
Conversation: local session 01a20191-564a-7da2-b044-a1e4f5e3bd1e (no session URL)