Skip to content

Support known_disturbance_inputs in symbol-based generate_control_function - #4230

Open
ChrisRackauckas-Claude wants to merge 11 commits into
SciML:masterfrom
ChrisRackauckas-Claude:fix-4215-known-disturbance-inputs-ap
Open

ChrisRackauckas-Claude wants to merge 11 commits into
SciML:masterfrom
ChrisRackauckas-Claude:fix-4215-known-disturbance-inputs-ap

Conversation

@ChrisRackauckas-Claude

@ChrisRackauckas-Claude ChrisRackauckas-Claude commented Jan 27, 2026 •

Copy link
Copy Markdown
Member

Summary

  • Adds known_disturbance_inputs keyword to the symbol/analysis-point override of generate_control_function in analysis_points.jl, opening the corresponding loops and forwarding the variables to the base function.
  • Re-enables the disabled doc example in disturbance_modeling.md using the symbol-based API ([:d1, :d2] instead of compiled system variables).
  • Adds a test in test_disturbance_model.jl exercising the new keyword path.

Fixes #4215

Test plan

  • Existing test/downstream/test_disturbance_model.jl passes
  • New test block verifies known_disturbance_inputs with symbol API (input count, zero/nonzero disturbance behavior)
  • Doc example builds successfully

🤖 Generated with Claude Code

CI triage (2026-09-24)

Head commit at triage start: 93dd2fb813. Logs for that run were expired (HTTP 410); classifications use check durations/conclusions, annotations, and comparison against latest master runs. After merge + fixes, new CI is on 9241451537.

check classification evidence
runic / format-check PR-caused (fixed) Failed on PR head; master format-check green (run 35977707462). Fixed via Runic on changed kwargs (6bb58c91f1).
Tests (*, ModelingToolkit/Downstream) PR-caused (fixed) Downstream green on master (job 107109419541); PR added an assertion that mismatched the PI fixture. Local Julia 1.12 Downstream disturbance test now passes after 9241451537.
build (Documentation) PR-caused (likely fixed by merge+API) Docs green on latest master (run 35977706990). PR re-enables the symbol/known_disturbance_inputs example; verified locally against Integrator model.
Spell Check with Typos master-red / unrelated Annotations pointed at pre-existing missings spelling in systemstructure.jl (not in PR diff). Typos clean on PR-touched files.
Tests (pre, *) ~30s–1m failures infra Extremely short runtimes on pre matrix; consistent with nightly resolve/start failure rather than test logic.
Benchmarks (1) cancelled; Benchmarks (lts) fail infra Cancelled / unrelated to PR surface.
SciMLBase.jl/Downstream, SciMLBase.jl/SymbolicIndexingInterface master-red Same IntegrationTest failures present on latest master (run 35977707000).
ModelingToolkitStandardLibrary.jl/Core, ModelingToolkitNeuralNets.jl/All, Neuroblox.jl/All master-red / unrelated Downstream integration packages; PR only touches analysis-point generate_control_function + docs/test.
Tests (lts, ModelingToolkit/Downstream) PR-caused (fixed) Same Downstream assertion issue as above.
Tests (lts/1, ModelingToolkitBase/InterfaceII, Extensions, …) master-red / stale Large master drift since Jan head; several Base groups green on recent master Downstream/InterfaceII/Extensions. Re-check on post-merge CI.
test (alldeps, 1.10, InterfaceI) Downgrade infra / stale 3s failure before meaningful work; Downgrade green on recent master (run 35838707817).

Risk assessment

  • Risk: Low–medium. Adds keyword forwarding on the analysis-point generate_control_function overload; merges eight months of master into the branch.
  • Blast radius: Callers using symbol/analysis-point generate_control_function with known_disturbance_inputs; disturbance-modeling docs example; Downstream disturbance tests.
  • Evidence: Local Julia 1.12 test/downstream/test_disturbance_model.jl passes; Integrator doc snippet reproduces [0,0,0,1,2]; Runic + typos clean on touched files.
  • Independent review: none yet
  • Merge: needs review

🤖 Posted by an AI agent — harness: cursor-agent 2026.09.23-86fc751 · model: Composer
Conversation:

Independent review (Codex CLI 0.162.1 gpt-6.1-sol, head df245ee)

🤖 Automated review section from an AI agent running as Chris Rackauckas's account — not written or reviewed by Chris.

VERDICT: CHANGES
The new analysis-point disturbance path works, but it breaks an existing, documented symbolic-variable input form. Preserve that form and add a regression test before merging. The supplied failing CI checks also lack sufficient evidence to establish no regressions against master.

  1. [P1] lib/ModelingToolkitBase/src/systems/analysis_points.jl:936 — confirmed by running: symbolic known disturbances now throw when the control input is an analysis point. canonicalize_ap wraps an ordinary symbolic variable unchanged, and line 938 then calls open_loop on that Num, which has no matching method. The base wrapper forwards these symbolic variables directly to the underlying generator, where they are supported. This affects both Symbol and AnalysisPoint control-input overloads. Transform analysis-point disturbances while continuing to forward symbolic-variable disturbances, and test both forms.

    Standalone reproducer used for the comparison:

    using ModelingToolkit, Test
    using ModelingToolkit: t_nounits as t, D_nounits as D
    @variables x(t)=0.0 source(t) [output=true] control(t) [input=true] w(t) [input=true]
    @named sys = System([source ~ 0, connect(source, :u, control), D(x) ~ -x + control + w], t)
    r = ModelingToolkit.generate_control_function(sys, sys.u; known_disturbance_inputs=[w], split=false)
    op = ModelingToolkit.inputs(r.io_sys) .=> 0.0
    p = ModelingToolkit.get_p(r.io_sys, op)
    @test r.f[1]([0.0], [0.0], p, 0.0, [2.0]) == [2.0]
    

    Julia 1.12.7, identical resolved dependencies: merge base b5a7653 passes 1/1; head df245ee errors with "MethodError: no method matching open_loop(::System, ::Num)" at line 938. This is a newly rejected input, not merely missing coverage for the added feature.

Verification: read the full three-file diff, linked issue, supplied comments and reviews, and applicable criteria. Ran with JULIA_NUM_THREADS=4, JULIA_NUM_PRECOMPILE_TASKS=4, --startup-file=no, and timeout 3600 in isolated environments using the respective local package sources. test/downstream/test_disturbance_model.jl passes 20/20 at head. The identical head test file on the merge base reaches the added call at test/downstream/test_disturbance_model.jl:206 and errors during compilation with symbol-valued known disturbances, after two earlier assertions pass. Thus the added test distinguishes the original bug. Additional scalar-model checks for Symbol/AnalysisPoint controls and known disturbances, with and without unknown disturbances, pass 12/12 at head. The restored tutorial's plant definition, integrating-disturbance wrapper, and generated-function assertions pass 3/3; the scratch extraction uses OrdinaryDiffEqTsit5 instead of the OrdinaryDiffEq umbrella import. Tracked repository files remain unchanged.

Gates: G1 has independent equation-based checks for the generated dynamics; no numerical solver algorithm or tolerance changes occur. G2 introduces no GPU, AD, Reactant, or MPI paths. G3 introduces no shared state, cache, threading, or global-default changes. These gates do not excuse the confirmed compatibility regression.

Not verified: full documentation build, complete Downstream group, QA, other test groups, and downstream integration suites were not run locally. An initial standalone test attempt lacked the direct ControlSystemsBase dependency; after adding that already-resolved dependency to the scratch environment, the test file passed. An initial extra scalar-model probe used colliding variable/analysis-point names; the corrected probe produced the 12/12 result above. GitHub CLI could not retrieve CI jobs because authentication is unavailable; no credentials were sought and nothing was posted. Consequently, comparison with master is UNVERIFIED for every supplied failing check: Benchmarks (lts); Benchmarks (1); NeuralPDE.jl/NNPDE2/1/; SciMLBase.jl/SymbolicIndexingInterface/1/; SciMLSensitivity.jl/Core8/1/; downgrade-mtkbase (Optimization); ModelingToolkitBase InterfaceII on Julia 1 and lts; ModelingToolkitBase Optimization on Julia 1 and lts; ModelingToolkitBase QA on Julia 1; root Optimization on Julia 1 and lts; and root QA on Julia 1. The historical classifications in the PR body concern earlier heads and do not establish the status of these failures. No failure is classified as pre-existing or PR-caused from duration alone.

🤖 Posted by an AI agent — harness: Codex CLI 0.162.1 · model: gpt-6.1-sol
Conversation: Codex exec session 01a14b4f-eed5-7763-a520-7a9900a20e1c (no public URL)

Codex CLI gpt-6.1-sol rated it high (H1: rejects previously working public inputs) at head df245ee

🤖 Automated review section from an AI agent running as Chris Rackauckas's account — not written or reviewed by Chris.

Fix by Codex CLI 0.170.0 gpt-6.2-sol (head ff18c46)

  • generate_control_function now forwards symbolic-variable disturbances and opens the loops for analysis-point disturbances. The regression tests exercise both Symbol and AnalysisPoint controls and both forms of specifying an analysis point.
  • The tutorial uses analysis-point properties and derives input sizes from its declarations.
  • Incorporated upstream fixes for the historical Optimization, Jacobian sparsity, benchmark, and QA failures. Comparing the failed jobs with master CI also reproduced the historical SciMLBase, SciMLSensitivity, and NeuralPDE failures on master.

Validation on Julia 1.12.7

  • Same regression test and dependency versions before and after applying the source patch. Before: MethodError: no method matching open_loop(::System, ::Num) for both control forms, 2 errors out of 2. After: Symbolic known disturbances with an analysis point | 2 2 8.9s.
  • julia --project=@runic -m Runic --inplace lib/ModelingToolkitBase/src/systems/analysis_points.jl test/downstream/test_disturbance_model.jl, git diff --name-only -z upstream/master | xargs -0 -r typos --, and git diff --check upstream/master exited 0.
  • GROUP=Downstream julia --project -e 'using Pkg; Pkg.test()' exited 0 with Downstream | 39 39 33m57.8s and Testing ModelingToolkit tests passed.
  • GROUP=QA julia --project -e 'using Pkg; Pkg.test()' reported 39 passed, 1 failed, 0 errored, 0 broken. It found the same six unapproved public reexports as the master QA job.
  • julia --project=docs -e 'using Pkg; Pkg.instantiate()' exited 0. The tutorial examples ran directly with Generated disturbance-model dynamics and observations | 3 3 5.2s. The first full docs build timed out. The retry, OPENBLAS_NUM_THREADS=1 julia --project=docs docs/make.jl, completed doctests and example expansion, then exited 1 with makedocs encountered an error [:linkcheck] -- terminating build before rendering after GitHub returned HTTP 429 for an unchanged PDEBase link.

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 01a20014-d6c7-73b2-a90a-c82f52ddebc1 (no session URL)

🤖 Automated review section from an AI agent running as Chris Rackauckas's account — not written or reviewed by Chris.

Fix by Codex CLI 0.170.0 gpt-6.2-sol (head e7a8f55)

  • Explicitly known disturbances stay out of the implicit unknown disturbance set, even when the receiving variable is marked disturbance = true.
  • Array-valued disturbance points supply individual elements in compiled input order through the keyword and positional interfaces. The downstream fixture checks each derivative against its state symbol for individual and combined disturbances.

Validation on Julia 1.12.4

  • Ran the two new testsets with identical resolved dependencies before and after the source fix using julia --startup-file=no --project -e 'using Pkg; Pkg.instantiate(; allow_autoprecomp=false); include(ARGS[1])' with the extracted test script as its argument.
    • Before, exit 1: Review regression tests | 9 failed, 9 total | 13.3s. The marked scalar derivative was [13.0] versus [1.0]. Both array interfaces retained the elements in ps and returned [13.0] for every tested w.
    • After, exit 0: Review regression tests | 9 9 10.4s. The scalar derivative is [1.0] and the array derivatives are [36.0], [33.0], and [43.0] with fixed operating-point parameters.
  • GROUP=Downstream julia --project -e 'using Pkg; Pkg.test()' exited 0 with Downstream | 52 52 15m41.4s and Testing ModelingToolkit tests passed.
  • GROUP=QA julia --project -e 'using Pkg; Pkg.test()' exited 1 with 39 passed, 1 failed, 0 errored, 0 broken. The six unapproved reexports match the master root QA failure.
  • julia --project=@runic -m Runic --inplace lib/ModelingToolkitBase/src/systems/analysis_points.jl test/downstream/test_disturbance_model.jl, git diff --name-only -z upstream/master | xargs -0 -r typos --, and git diff --check upstream/master all exited 0.
  • The reviewed-head InterfaceII and ModelingToolkitBase QA failures match master sublibrary CI and master downgrade QA. The full Documenter build, other Julia versions, and ModelingToolkitBase CI variants remain unverified locally for this fix.

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 01a2018d-ea45-70e1-98d9-ab3af32c56a2 (no session URL)

🤖 Automated review section from an AI agent running as Chris Rackauckas's account — not written or reviewed by Chris.

Fix by Codex CLI 0.170.0 gpt-6.2-sol (head 483c3f3)

  • Unknown array disturbances substitute shape-correct zeros for the parent array and its elements. The regression uses a registered whole-vector consumer with split and unsplit generation.
  • The returned parameter list excludes array disturbance parents for both keyword and legacy positional inputs.
  • Compilation groups complete disturbance arrays in index order. The generated disturbance argument retains the caller's order, including when one array element is known and when both are supplied in reverse order.

Validation on Julia 1.12.4

  • julia --startup-file=no --compiled-modules=existing -O1 --project="$project" "$regression_driver" ran the same extracted test cases with identical resolved dependencies on both heads.
    • Before, exit 1: Disturbance regressions | 19 passed, 2 failed, 6 errored, 27 total. The whole-array case reported UndefVarError: w not defined in ModelingToolkitBase in both split modes. The keyword and positional isempty(ps) assertions found [w(t)] with split generation. Selecting element 1 alone or supplying elements in reverse order reported Elements of scalarized array variables must be in sorted order in both split modes.
    • After, exit 0: Disturbance regressions | 27 27 1m16.5s. The generated functions returned [15.0] for the unknown array and [17.0], [-23.0], and [-5.0] for the mixed and reversed-order cases. Both parameter assertions passed.
  • GROUP=Downstream timeout 3600 julia --project -e 'using Pkg; Pkg.test()' exited 0 with Downstream | 68 68 14m03.5s and Testing ModelingToolkit tests passed.
  • GROUP=QA timeout 3600 julia --project -e 'using Pkg; Pkg.test()' exited 1 with 39 passed, 1 failed, 0 errored, 0 broken. The sole failure was the six unapproved public reexports also reported by master at the PR merge base. Current master root QA still fails on the five Symbolics operator reexports.
  • julia --project=@runic -m Runic --inplace lib/ModelingToolkitBase/src/inputoutput.jl test/downstream/test_disturbance_model.jl, git diff --name-only -z "$(git merge-base upstream/master HEAD)" | xargs -0 -r typos --, and git diff --check upstream/master...HEAD all exited 0.
  • The reviewed-head InterfaceII and Base QA failures also occur on current master sublibrary CI and current master downgrade QA. The historical downgrade Optimization failure reproduced on historical master, and both current runs pass it. Full Documenter and other Julia versions were outside local verification.

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 01a20463-6835-7a93-b50e-977ae6e112d9 (no session URL)

…ction

The symbol/analysis-point override of generate_control_function did not
forward the known_disturbance_inputs keyword to the base function. This
adds the keyword, opens the corresponding loops, and passes the
resulting variables through. The disabled doc example in
disturbance_modeling.md is re-enabled using the symbol API, and a test
is added for the new keyword path.

Fixes SciML#4215

Co-Authored-By: Chris Rackauckas <accounts@chrisrackauckas.com>
Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
op = ModelingToolkit.inputs(io_sys) .=> 0
x0 = ModelingToolkit.get_u0(io_sys, op)
p = MTKParameters(io_sys, op)
u = zeros(1) # Control input

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

please don't remove comments like this

w = zeros(length(disturbance_inputs)) # Disturbance input (known disturbances are provided as arguments)
@test f_oop(x0, u, p, t, w) == zeros(5)
u = zeros(1)
w = zeros(2)

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please don't hardcode numbers when the existing code had a better solution


g = ModelingToolkit.build_explicit_observed_function(
io_sys, outputs; inputs)
io_sys, outputs; inputs = ModelingToolkit.inputs(io_sys)[1:1])

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

the existing code was better

Address review feedback: keep descriptive comments from the original
example, use `length(disturbance_inputs)` instead of hardcoded `2`,
and restore the multi-line formatting style.

Co-Authored-By: Chris Rackauckas <accounts@chrisrackauckas.com>
Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
@ChrisRackauckas-Claude

Copy link
Copy Markdown
Member Author

Addressed all three review comments in 2cb0c23:

  1. Restored comments — Put back # Control input, # Disturbance input (known disturbances are provided as arguments), and # Non-zero disturbance inputs... comment.
  2. No hardcoded numbers — Changed zeros(2) back to zeros(length(disturbance_inputs)).
  3. ; inputs on build_explicit_observed_function — I kept inputs = ModelingToolkit.inputs(io_sys)[1:1] rather than the original ; inputs shorthand. The reason is that in the symbol-based API, inputs is [:u] (symbols), not compiled variable references, so passing it directly as a keyword wouldn't work. The [1:1] indexing selects only the control input from the compiled io_sys, excluding the known disturbance inputs. If there's a preferred alternative, happy to change it.

@ChrisRackauckas

Copy link
Copy Markdown
Member

@baggepinnen more comments?

P = ssys.system_model
```@example DISTURBANCE_MODELING
inputs = [:u]
disturbance_inputs = [:d1, :d2]

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is the old syntax of providing analysis points, the tutorial should keep using the new syntax.

@baggepinnen

Copy link
Copy Markdown
Contributor

I kept inputs = ModelingToolkit.inputs(io_sys)[1:1] rather than the original ; inputs shorthand. The reason is that in the symbol-based API, inputs is [:u] (symbols), not compiled variable references, so passing it directly as a keyword wouldn't work.

The problem is that you should not use the legacy symbol-based API.

Pass symbols inline to generate_control_function instead of
creating intermediate variables with the old analysis-point syntax.

Co-Authored-By: Chris Rackauckas <accounts@chrisrackauckas.com>
Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
@ChrisRackauckas-Claude

Copy link
Copy Markdown
Member Author

Fixed in 93dd2fb: symbols are now passed inline directly to generate_control_function (:u, :d1, :d2) instead of creating intermediate inputs/disturbance_inputs variables. The inputs variable now refers to ModelingToolkit.inputs(io_sys) (compiled system inputs) used for build_explicit_observed_function and zeros(length(inputs) - 1).

ChrisRackauckas and others added 6 commits September 24, 2026 15:01
Resolve conflict in analysis_points.jl by keeping known_disturbance_inputs
forwarding from the PR while adopting master's SymbolicT[]/append! style
for disturbance open-loop handling.

Co-Authored-By: Chris Rackauckas <accounts@chrisrackauckas.com>
Agent-Harness: cursor-agent 2026.09.23-86fc751
Agent-Model: Composer
Agent-Session: /home/crackauc/.cursor/projects/home-crackauc-sandbox-fleet-master-jobs-nw-modelingtoolkit-4230/agent-transcripts/1bf513c6-064f-4439-b8ff-0e7e29694beb
Co-authored-by: Cursor <cursoragent@cursor.com>
Co-Authored-By: Chris Rackauckas <accounts@chrisrackauckas.com>
Agent-Harness: cursor-agent 2026.09.23-86fc751
Agent-Model: Composer
Agent-Session: /home/crackauc/.cursor/projects/home-crackauc-sandbox-fleet-master-jobs-nw-modelingtoolkit-4230/agent-transcripts/1bf513c6-064f-4439-b8ff-0e7e29694beb
Co-authored-by: Cursor <cursoragent@cursor.com>
The new assertion copied Integrator-model expected derivatives from the
docs, but the Downstream fixture uses ss(1+10/s) with feedthrough. Align
with the existing disturbance_argument cases for the same model.

Co-Authored-By: Chris Rackauckas <accounts@chrisrackauckas.com>
Agent-Harness: cursor-agent 2026.09.23-86fc751
Agent-Model: Composer
Agent-Session: /home/crackauc/.cursor/projects/home-crackauc-sandbox-fleet-master-jobs-nw-modelingtoolkit-4230/agent-transcripts/1bf513c6-064f-4439-b8ff-0e7e29694beb
Co-authored-by: Cursor <cursoragent@cursor.com>
Prefer model.u / model.d1 over Symbol names, matching the current
analysis-point API guidance from review.

Co-Authored-By: Chris Rackauckas <accounts@chrisrackauckas.com>
Agent-Harness: cursor-agent 2026.09.23-86fc751
Agent-Model: Composer
Agent-Session: /home/crackauc/.cursor/projects/home-crackauc-sandbox-fleet-master-jobs-nw-modelingtoolkit-4230/agent-transcripts/1bf513c6-064f-4439-b8ff-0e7e29694beb
Co-authored-by: Cursor <cursoragent@cursor.com>
Bring in the upstream fixes for the sparse Jacobian, benchmark setup, and the Optimization and QA checks.

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__4230--20261121T214552Z-codex-gpt-6.2-sol
Agent-Session: local session 01a20014-d6c7-73b2-a90a-c82f52ddebc1 (no session URL)
Open loops for analysis-point disturbances and forward symbolic variables as known inputs. Keep default unknown disturbances and exercise both control input forms.

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__4230--20261121T214552Z-codex-gpt-6.2-sol
Agent-Session: local session 01a20014-d6c7-73b2-a90a-c82f52ddebc1 (no session URL)
@ChrisRackauckas-Claude

Copy link
Copy Markdown
Member Author

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

PR: #4230

Reviewed head: ff18c46
Raw SHA-256: 4d1eb7ce495c2365240fb40e6bdbd51a88ee5f4b7ab811c053dd1ee7ae284354
Source SHA-256: 59f21524ef7f65a0c3e89fe65688c09b6885e9b85d3c9a690669de39c5a44480
Source: standard-review-v1 (harness-log)
Reviewer session: 01a20161-e76d-7d23-96dc-d774c6629842
Slot: 1
Confidence: unknown
Own risk fixed before author rating/discussion: yes
Redaction: ran (substitutions=0)

Risk assessment

  • Risk: low (L8)
  • Verdict: CHANGES
  • Reviewed head: ff18c46

Review report

VERDICT: CHANGES
Round: 1
Head: ff18c46
Slot: 1
CI: noregress
Session: 01a20161-e76d-7d23-96dc-d774c6629842
Reviewer: codex-cli 0.170.0; model: gpt-6.2-sol

Risk

low (L8: opt-in analysis-point support for an existing keyword on the control-function path)

Blocking findings

  • Blocking priorities: P1, P1
  • [P1] lib/ModelingToolkitBase/src/systems/analysis_points.jl:980 silently zeros a known disturbance when its receiving variable has disturbance = true. For D(x) ~ -x + 5u - 3w, the generated function returned [13.0] at x=2, u=3, w=4, where the equation gives [1.0]. The same keyword call gave [1.0] with the marker cleared, and the legacy positional call with disturbance_argument=true gave [1.0] with the marker set. The fallback collects the marked variable as an implicit unknown disturbance and substitutes zero into the generated equations. Exclude explicitly known inputs from that implicit set and add a regression test with a marked receiving variable.
  • [P1] lib/ModelingToolkitBase/src/systems/analysis_points.jl:972 forwards an array-valued disturbance point as a whole symbolic variable, while the compiled system registers its elements. The probe for D(x) ~ -x + 5u - 3w[1] + 7w[2] at x=2, u=3, w=[4,5] returned [13.0] with zero operating-point disturbance parameters, against an analytic [36.0]. Flat and nested w arguments both had no effect. Both elements appeared in the returned ps, and changing the operating-point parameters changed the derivative to [90.0]. The positional compatibility path showed the same issue. Normalize the known analysis-point outputs to the same elements used by compilation and verify that changing w with fixed p changes the corresponding derivatives.

Non-blocking findings

  • test/downstream/test_disturbance_model.jl:230 compares sorted derivatives. By inspection, a permutation of state slots can pass this check. Use the returned dvs to test the intended state slots and perturb each disturbance separately.

What I ran

  • GROUP=Downstream julia --startup-file=no --project -e 'using Pkg; Pkg.test()' on Julia 1.12.4. Downstream | 39 39 in 14m40.8s. The checkout was clean after validation.
  • Ran the same scalar analysis-point probe on the diff base and the PR head with the same resolved manifest. The base reported The following disturbance inputs provided to mtkcompile were not found in the system. The head returned the analytic [1.0] and exited 0.
  • Ran the marked-variable and array probes on the PR head. Each exposed the wrong derivative above. A separate probe passed 23 assertions for mixed disturbance ordering, unknown disturbance suppression, split and unsplit in-place and out-of-place calls, a symbolic view, and legacy positional calls.
  • julia --startup-file=no --project=docs ../tutorial-example.jl on the extracted state-estimation example and its prerequisites. All four assertions passed.
  • Runic 1.10.0 in check mode, typos on changed files, and git diff --check origin/master...HEAD all exited 0.
  • uv run --locked python --version reported Python 3.13.13. The checkout has no Python project or uv.lock, and uv reported that --locked had no effect.

What I did not verify

Full Documenter build, QA, other Julia versions, and remote CI.

AUTHOR_GRADE: {"task":"bugfix","score":2,"difficulty":3,"rounds":1,"author_harness":"Codex CLI 0.170.0","author_model":"gpt-6.2-sol","note":"The scalar probe distinguishes the fix from the base. Marked and array-valued known disturbances can silently produce incorrect derivatives."}

Head link: ff18c46


🤖 Posted by an AI agent — harness: codex-cli 0.170.0 · model: gpt-6.2-sol
Conversation: local session 01a20161-e76d-7d23-96dc-d774c6629842 (no session URL)

Keep explicitly known disturbances out of the inferred unknown list and
flatten array disturbances in compiled input order. Test the keyword and
positional interfaces and assert the affected state slots.

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__4230--20261122T043814Z-codex-gpt-6.2-sol
Agent-Session: local session 01a2018d-ea45-70e1-98d9-ab3af32c56a2 (no session URL)
@ChrisRackauckas

Copy link
Copy Markdown
Member

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

PR: #4230

Reviewed head: e7a8f55
Raw SHA-256: e083fcda383b419252a95f1bac80ae90c1b5c36428a27a2308ab1ccfa202d1ae
Source SHA-256: 3bbe1920e5646c0d1c8718793d66513820dadefc85d97ef6c35d1a98cf03d4ae
Source: standard-review-v1 (harness-log)
Reviewer session: 01a20449-d26f-7991-bed8-abfd32e6f56d
Slot: 1
Confidence: unknown
Own risk fixed before author rating/discussion: yes
Redaction: ran (substitutions=0)

Risk assessment

  • Risk: high (H1)
  • Verdict: CHANGES
  • Reviewed head: e7a8f55

Review report

VERDICT: CHANGES
Round: 1
Head: e7a8f55
Slot: 1
CI: noregress
Session: 01a20449-d26f-7991-bed8-abfd32e6f56d
Reviewer: codex-cli 0.169.0; model: gpt-6.2-astra

Risk

high (H1: a previously working positional call now generates dynamics that throw for an array-valued unknown disturbance)

Blocking findings

  • [P1] lib/ModelingToolkitBase/src/systems/analysis_points.jl:998 scalarizes an unknown disturbance before zero substitution. I tested D(x) ~ 5c + energy(w) with a two-element disturbance, energy(v) = sum(abs2, v), and @register_symbolic energy(v::AbstractVector). With generate_control_function(sys, sys.control_ap, sys.load_ap) and control c = 3, the merge base returned [15.0] for both split settings. The head threw UndefVarError: w not defined in ModelingToolkitBase for both. Substituting the indexed elements leaves the whole-vector reference in energy(w) unbound. Preserve a shape-correct zero substitution for the parent array as well as its elements, and exercise the generated function with a whole-vector consumer.

  • [P2] lib/ModelingToolkitBase/src/systems/analysis_points.jl:977 passes only the scalarized known inputs onward. With default split=true, a parameter-free model with a two-element known disturbance returned ps = [w(t)], even though the generated function took both values from its final argument. With split=false, the same model returned ps = []. The final filter in lib/ModelingToolkitBase/src/inputoutput.jl:365 misses the parent array. Use the parent-aware exclusion set already built for code generation and run the existing isempty(ps) assertion under both split settings.

  • [P2] lib/ModelingToolkitBase/src/systems/analysis_points.jl:984 leaves automatically detected unknown elements ahead of known elements in the list passed to compilation. I marked w[1:2] as a disturbance and opened one analysis point on one element. For D(x) ~ 5c + 3w[1] - 7w[2], control 1 and measured disturbance 4, selecting w[2] returned the expected [-23.0]. Selecting w[1] should return [17.0] but threw “Elements of scalarized array variables must be in sorted order”. The caller supplied just one point. Canonicalize the combined list for compilation while preserving the caller's order in the generated disturbance argument.

  • Blocking priorities: P1, P2, P2

Non-blocking findings

None.

What I ran

  • Julia 1.13.2, --compiled-modules=existing -O1, with both checkout packages developed in a scratch copy of the downstream project. The first group invocation lacked the root test imports. After adding those dependencies, include("test/group_downstream.jl") passed all 52 assertions (3 linearization, 11 inverse models, 38 disturbance model).
  • Executed the tutorial's model definitions and newly enabled example. All three numerical assertions passed. Mixed symbolic and analysis-point probes returned the expected derivative [-19.0] in both channel orders, in place and out of place, with both split settings and both implicit and explicit unknown disturbances.
  • Ran the array probes on the head and in a fresh Julia process against a clean archive of git merge-base origin/master HEAD with the same dependency versions. The legacy known-disturbance probe improved to the expected [28.0] on the head. The positional unknown-disturbance regression above reproduced in the same model.
  • git diff --check origin/master...HEAD passed. uv run --locked python --version printed Python 3.15.0 and warned that --locked had no effect outside a project. The checkout has no Python lockfile.

What I did not verify

The full documentation build, other test groups and other Julia versions remain unverified.

AUTHOR_GRADE: {"task":"bugfix","score":3,"difficulty":3,"rounds":1,"author_harness":"Codex CLI 0.170.0","author_model":"gpt-6.2-sol","note":"The tutorial and downstream suite pass. Independent probes reproduced a regression for whole-array unknown disturbances, an incorrect parameter list and an element-order failure."}

Head link: e7a8f55


🤖 Posted by an AI agent — harness: codex-cli 0.169.0 · model: gpt-6.2-astra
Conversation: local session 01a20449-d26f-7991-bed8-abfd32e6f56d (no session URL)

Group complete disturbance arrays for compilation and substitute shaped
zeros for unknown arrays. Exclude disturbance parents from the returned
parameters and test the ordering of the generated disturbance argument.

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__4230--20261122T175041Z-codex-gpt-6.2-sol
Agent-Session: local session 01a20463-6835-7a93-b50e-977ae6e112d9 (no session URL)
@ChrisRackauckas

Copy link
Copy Markdown
Member

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

PR: #4230

Reviewed head: 483c3f3
Raw SHA-256: 405c338185858ec82f82eb278c3a23edd34a9f2403ea6ae47c00ac1af2e211aa
Source SHA-256: 1be377942ed2e36abdd1290bfee32f8ff33937607b51719effee2b4fc2c72a9b
Source: standard-review-v1 (harness-log)
Reviewer session: 01a204e9-e99c-7311-96b5-a3fa3549e52b
Slot: 1
Confidence: unknown
Own risk fixed before author rating/discussion: yes
Redaction: ran (substitutions=0)

Risk assessment

  • Risk: medium-low (ML1)
  • Verdict: CHANGES
  • Reviewed head: 483c3f3

Review report

VERDICT: CHANGES
Round: 2
Head: 483c3f3
Slot: 1
CI: CI is not green
Session: 01a204e9-e99c-7311-96b5-a3fa3549e52b
Reviewer: codex-cli 0.169.0; model: gpt-6.2-astra

Risk

medium-low (ML1: corrects the parameter list returned by control-function generation for array disturbances)

Blocking findings

  • [P2] lib/ModelingToolkitBase/src/inputoutput.jl:346 leaves the parent array unbound when only some disturbance elements are known. I used the two-element marked disturbance from the new mixed-input test with D(x) ~ 5c + energy(w), where energy(v) = sum(abs2, v) is registered for AbstractVector. With control 3 and either element supplied as 4 through its analysis point, the other element is unknown and contributes zero. The expected derivative is 31. Both generated functions threw UndefVarError: w not defined in ModelingToolkitBase for either element and both split settings. The substitution loop replaces the unknown element, but energy(w) still refers to the parent. Reconstruct that parent from the measured elements in the caller's argument order and zeros at the unknown indices. Add the whole-vector consumer to the mixed-input regression test.

  • Blocking priorities: P2

Non-blocking findings

None.

What I ran

  • Julia 1.13.2 with --compiled-modules=existing -O1, using a scratch copy of the downstream project with its root test imports and both checkout packages developed locally. include("test/group_downstream.jl") passed 68/68. lib/ModelingToolkitBase/test/input_output_handling.jl passed 134/134 with ModelingToolkit loaded. The tutorial model definitions, simulation and estimator example passed 4/4 assertions.
  • Compared the same probes against the previous head and the reviewed head with identical dependency versions. The previous head returned an extra w(t) parameter with split=true, rejected the first measured element on ordering grounds, and left the wholly unknown vector unbound with split=false. On the reviewed head the three original regression cases passed. A model with one physical parameter returned ps = [k] under both split settings. Whole-unknown, whole-known and reverse-order all-known probes matched their hand-computed derivatives in place and out of place. The mixed whole-vector probe above failed all eight combinations.
  • On a clean archive of the merge base, the legacy positional whole-unknown energy(w) example returned [15.0] in place and out of place with both split settings. The reviewed head also produced [15.0] in the downstream regression test.
  • git diff --check origin/master...HEAD passed. uv run --locked python --version printed Python 3.15.0 and warned that --locked had no effect outside a project. The checkout contains neither a Python lockfile nor a Julia manifest.

What I did not verify

I did not run the full documentation build, unrelated test groups or other Julia versions. An offset-indexed disturbance probe raised a BoundsError on the merge base, previous head and reviewed head, so its generated derivative remains unverified.

AUTHOR_GRADE: {"task":"bugfix","score":4,"difficulty":3,"rounds":2,"author_harness":"Codex CLI 0.170.0","author_model":"gpt-6.2-sol","note":"The three earlier reproductions pass individually. A whole-vector consumer still fails when one disturbance element is measured and the other is unknown."}

Head link: 483c3f3


🤖 Posted by an AI agent — harness: codex-cli 0.169.0 · model: gpt-6.2-astra
Conversation: local session 01a204e9-e99c-7311-96b5-a3fa3549e52b (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.

Fix disturbance_modeling.md: generate_control_function with analysis points

4 participants