Skip to content

Fix unit validation MethodError on causal variable connect - #5233

Merged
AayushSabharwal merged 2 commits into
SciML:masterfrom
ChrisRackauckas-Claude:agent/5118-unit-validate-var-connect
Oct 6, 2026
Merged

AayushSabharwal merged 2 commits into
SciML:masterfrom
ChrisRackauckas-Claude:agent/5118-unit-validate-var-connect

Conversation

@ChrisRackauckas-Claude

@ChrisRackauckas-Claude ChrisRackauckas-Claude commented Sep 30, 2026 •

Copy link
Copy Markdown
Member

Please ignore until reviewed by @ChrisRackauckas.

Summary

MTK._validate(conn::Connection) in MTKDynamicQuantitiesExt assumed every connection payload was a vector of systems and called unknowns on each element. Causal variable connect(a.y, b.u) stores a Vector{SymbolicT}, which triggered MethodError: unknowns(::BasicSymbolic). This adds a branch via is_causal_variable_connection that compares connected variables' units with safe_get_unit/equivalent, and regression tests in dq_units.jl.

Fixes #5118

Fail before / pass after

Negative control (src fix reverted; same scratch/test_5118.jl):

Error During Test at .../test_5118.jl:29
  Test threw exception
  Expression: MT.validate(var_eqs)
  MethodError: no method matching unknowns(::SymbolicUtils.BasicSymbolicImpl.var"typeof(BasicSymbolicImpl)"{SymReal})
  ...
    [1] _validate(conn::Connection; info::String)
      @ MTKDynamicQuantitiesExt .../ext/MTKDynamicQuantitiesExt.jl:262

Positive control (fix restored):

LOADED
MATCHING_CONNECT_OK
MISMATCH_REJECTED_OK
ALL_PASS

(exit 0; mismatched V↔A connection warns and throws ValidationError as expected)

Verification

export TMPDIR=.../5118-cursor/tmp JULIA_NUM_THREADS=1
export JULIA_DEPOT_PATH=.../5118-cursor/scratch/depot
julia +1.12 --project=scratch/env scratch/test_5118.jl   # fail-before / pass-after above
julia +1.12 --project=scratch/env -e 'using Test; include("lib/ModelingToolkitBase/test/dq_units.jl")'
# => DQ_UNITS_ALL_PASS (exit 0)

cd lib/ModelingToolkitBase && GROUP=InterfaceI julia +1.12 --project=. -e 'using Pkg; Pkg.test()'

InterfaceI tail:

Test Summary: | Pass  Broken  Total      Time
InterfaceI    | 1763       5   1768  64m06.8s
     Testing ModelingToolkitBase tests passed
GROUP_EXIT=0

Runic --check and typos clean on the two touched files.

What was NOT verified

Risk assessment

  • Risk: Low — additive branch for Vector{SymbolicT} connections; connector-system path unchanged
  • Blast radius: Only DynamicQuantities unit checking of causal variable connect
  • Evidence: Fail-before / pass-after on issue reproducer; full dq_units.jl; InterfaceI green
  • Independent review: Claude Code + Opus 5.5 (claude-opus-5-5, a different harness from the Cursor author) rated it low, verdict MERGE. The new branch only runs for bare-variable payloads that previously always threw. The reviewer probed n-ary connections and they are correct. The one extra red CI job, downgrade-mtkbase (Initialization), is a pre-existing flake: the same garbage gradient appears at initializationsystem.jl:2556 on a version-bump-only PR. Non-blocking: add a 3-member connection test; open PR Add multiconnect: graph-based connections over node arrays #5117 must keep this branch when it lands.
  • Merge: auto-merge candidate: low/low; CI adds no failure beyond master's plus the documented downgrade flake.

Please ignore this draft until reviewed by @ChrisRackauckas.

Harness: Cursor Agent CLI 2026.09.28-64d2043 | Model: auto | Transcript: /home/crackauc/sandbox/goals/issue-backlog/orch-ibmtk/jobs/5118-cursor/log.txt on amdci2.julia.csail.mit.edu

Head orchestration and review routing: Claude Code (model: claude-opus-5-5[1m]), https://claude.ai/code/session_01H4fXBChQshAwfpLMCpEvAX

ChrisRackauckas and others added 2 commits September 30, 2026 08:16
_validate(conn::Connection) assumed get_systems returned systems and called
unknowns; bare-variable connect stores Vector{SymbolicT}, so compare units
on the variables directly instead.

Co-Authored-By: Chris Rackauckas <[email protected]>
Co-Authored-By: Cursor Agent <[email protected]>
Agent-Harness: Cursor Agent CLI 2026.09.28-64d2043
Agent-Model: auto
Agent-Session: local session, transcript at /home/crackauc/sandbox/goals/issue-backlog/orch-ibmtk/jobs/5118-cursor/log.txt on amdci2.julia.csail.mit.edu
Covers matching units constructing a system and mismatched units rejecting
validation (SciML#5118).

Co-Authored-By: Chris Rackauckas <[email protected]>
Co-Authored-By: Cursor Agent <[email protected]>
Agent-Harness: Cursor Agent CLI 2026.09.28-64d2043
Agent-Model: auto
Agent-Session: local session, transcript at /home/crackauc/sandbox/goals/issue-backlog/orch-ibmtk/jobs/5118-cursor/log.txt on amdci2.julia.csail.mit.edu
@AayushSabharwal
AayushSabharwal marked this pull request as ready for review October 6, 2026 14:20
@AayushSabharwal
AayushSabharwal merged commit 157efa9 into SciML:master Oct 6, 2026
99 of 109 checks passed
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.

Unit validation crashes on causal variable connect: unknowns(::BasicSymbolic) MethodError in MTKDynamicQuantitiesExt

3 participants