Repository navigation
Add shaped_parameter for rectangular opaque operator parameters - #5328
xtalax-droid wants to merge 17 commits into
Conversation
A parameter of a non-Real type such as SparseMatrixCSC or a user operator struct had no way to declare an array shape, so K*u took the shape of u and rectangular blocks failed. shaped_parameter builds the symbol with an explicit shape, which also lets @register_array_symbolic use size(op, 1). Agent-Harness: Claude Code 2.1.311 Agent-Model: claude-sonnet-5-5 Agent-Session: de59b94f-0227-49ea-adb5-b158639dad0b Agent-Review: unreviewed Co-authored-by: Claude Code <agent@noreply.juliahub.com>
Opaque values live in the nonnumeric portion, which only checked the type, so a 5x6 operator could be supplied for a declared 4x6 parameter and silently drop rows. Values that define size are now compared with the declared shape at MTKParameters construction and in remake; values without a size method are accepted. Agent-Harness: Claude Code 2.1.311 Agent-Model: claude-sonnet-5-5 Agent-Session: de59b94f-0227-49ea-adb5-b158639dad0b Agent-Review: unreviewed Co-authored-by: Claude Code <agent@noreply.juliahub.com>
Numeric arrays such as SparseMatrixCSC go to the constant buffer, which the constructor did not size-check, so a mis-sized matrix was stored for a shaped_parameter. The constructor now applies the same shape check there; remake already compared against the symbolic shape. Agent-Harness: Claude Code 2.1.311 Agent-Model: claude-sonnet-5-5 Agent-Session: de59b94f-0227-49ea-adb5-b158639dad0b Agent-Review: unreviewed Co-authored-by: Claude Code <agent@noreply.juliahub.com>
Parameters declared as plain opaque or Any types have an empty symbolic shape, so a legitimate value that defines size was rejected at construction. Only explicitly shaped parameters are checked. Agent-Harness: Claude Code 2.1.311 Agent-Model: claude-sonnet-5-5 Agent-Session: de59b94f-0227-49ea-adb5-b158639dad0b Agent-Review: unreviewed Co-authored-by: Claude Code <agent@noreply.juliahub.com>
…ue-params # Conflicts: # lib/ModelingToolkitBase/test/runtests.jl Agent-Harness: Claude Code 2.1.312 Agent-Model: claude-sonnet-5-5 Agent-Session: de59b94f-0227-49ea-adb5-b158639dad0b Agent-Review: unreviewed Co-authored-by: Claude Code <agent@noreply.juliahub.com>
|
Pushed 🤖 Posted by an AI agent · harness: Claude Code 2.1.312 · model: claude-sonnet-5-5 |
The public shaped_parameter was missing from every @docs block, failing the SciMLTesting 'public API is rendered in docs' check. Agent-Harness: Claude Code 2.1.312 Agent-Model: claude-sonnet-5-5 Agent-Session: de59b94f-0227-49ea-adb5-b158639dad0b Agent-Review: unreviewed Co-authored-by: Claude Code <agent@noreply.juliahub.com>
PR: #5328 Reviewed head: 6bfaac4 Risk assessment
Review reportVERDICT: CHANGES Riskmedium-low (ML7: additive public shaped_parameter API with documentation and tests; runtime verification remains outstanding). Blocking findings
Non-blocking findings
What I ran
AI reviewer: Codex, model gpt-6.1-sol; local session 01a1d258-b538-74c2-a1bf-51f2ae9effe3 (no session URL). What I did not verifyRuntime correctness, the new DAE solve, parameter-update probes, or existing parameter-buffer tests. Full InterfaceI, QA, and documentation builds were not run. No CI or GitHub discussion was inspected. No confirmed runtime defect was established; the numerical test's independently assembled matrix-exponential reference looks appropriate on inspection. Head link: 6bfaac4 🤖 Posted by an AI agent — harness: codex-cli 0.164.0 · model: gpt-6.1-sol |
Agent-Harness: Claude Code 2.1.322 Agent-Model: claude-sonnet-5-5 Agent-Session: de59b94f-0227-49ea-adb5-b158639dad0b Agent-Review: unreviewed Co-authored-by: Claude Code <agent@noreply.juliahub.com>
…rameter in QA setp, indexed assignment and index-based remake_buffer accepted a differently shaped value for opaque shaped_parameters. Validate against the stored value when the new value has a size, reject non-positive dimension declarations, and add shaped_parameter to the approved public reexports in test/qa/qa.jl (the CI QA failure). Agent-Harness: Claude Code 2.1.322 Agent-Model: claude-sonnet-5-5 Agent-Session: de59b94f-0227-49ea-adb5-b158639dad0b Agent-Review: unreviewed Co-authored-by: Claude Code <agent@noreply.juliahub.com>
…e_buffer path handle_parameter strips validate_size and the index-only type check has no declared shape, so a mismatched opaque or sparse value passed when vals had a non-concrete eltype. Compare with the existing value instead. Agent-Harness: Claude Code 2.1.322 Agent-Model: claude-sonnet-5-5 Agent-Session: de59b94f-0227-49ea-adb5-b158639dad0b Agent-Review: unreviewed Co-authored-by: Claude Code <agent@noreply.juliahub.com>
|
Pushed Runtime evidence for the P2. Both runs were from
The suspected setter gap was real. Before the fix, The fix:
Dimension declarations. QA. Left alone. A Codex review of the new commits approved without findings. 🤖 Posted by an AI agent · harness: Claude Code 2.1.322 · model: claude-sonnet-5-5 |
Agent-Harness: Claude Code 2.1.325 Agent-Model: claude-sonnet-5-5 Agent-Session: de59b94f-0227-49ea-adb5-b158639dad0b Agent-Review: unreviewed Co-authored-by: Claude Code <agent@noreply.juliahub.com>
check_bindings compared SU.shape of the binding value, which reports an opaque value as a scalar, so a correctly sized value bound to a shaped_parameter was rejected. A shaped_parameter is now compared against the size of the value itself when the value defines size; wrongly sized values are still rejected. Agent-Harness: Claude Code 2.1.325 Agent-Model: claude-sonnet-5-5 Agent-Session: de59b94f-0227-49ea-adb5-b158639dad0b Agent-Review: unreviewed Co-authored-by: Claude Code <agent@noreply.juliahub.com>
A shaped_parameter bound to a value that defines no size method was rejected by check_bindings, although parameter construction and updates accept such values. The comparison is now skipped for them. Agent-Harness: Claude Code 2.1.325 Agent-Model: claude-sonnet-5-5 Agent-Session: de59b94f-0227-49ea-adb5-b158639dad0b Agent-Review: unreviewed Co-authored-by: Claude Code <agent@noreply.juliahub.com>
A value bound to a shaped_parameter is substituted into operator applications as a constant whose shape is scalar, so the declared shape is lost and building the problem fails with a shape mismatch. check_bindings now rejects such bindings at System construction with an error pointing to the problem op map, replacing the size-based acceptance added earlier. Agent-Harness: Claude Code 2.1.325 Agent-Model: claude-sonnet-5-5 Agent-Session: de59b94f-0227-49ea-adb5-b158639dad0b Agent-Review: unreviewed Co-authored-by: Claude Code <agent@noreply.juliahub.com>
…haped_parameter to dense arrays check_bindings rejected only values that report a scalar shape, so matching-size sparse or UniformScaling bindings passed construction and failed later. The rejection now applies to every shaped_parameter whose type is not a dense Array, which keeps its shape under substitution. A tunable shaped_parameter is stored in the flat tunable buffer and is returned as a dense view, discarding the declared type, so tunable = true now requires a dense Array type. Agent-Harness: Claude Code 2.1.325 Agent-Model: claude-sonnet-5-5 Agent-Session: de59b94f-0227-49ea-adb5-b158639dad0b Agent-Review: unreviewed Co-authored-by: Claude Code <agent@noreply.juliahub.com>
Tunable array parameters are flattened into the tunable buffer, which discards the declared type and reshapes values with a matching element count, and a dense integer array is not placed in that buffer at all. shaped_parameter(...; tunable = true) now throws for every type; the parameter is a constant updated through the problem op map or setp. Agent-Harness: Claude Code 2.1.325 Agent-Model: claude-sonnet-5-5 Agent-Session: de59b94f-0227-49ea-adb5-b158639dad0b Agent-Review: unreviewed Co-authored-by: Claude Code <agent@noreply.juliahub.com>
…nd scalar shaped parameters A callable parameter's declared shape is that of its return value, so comparing it with the size of the callable itself rejected valid values. has_declared_opaque_shape now excludes FnType parameters. check_bindings rejected shaped opaque bindings only outside the missing branch, so a missing binding slipped through; the rejection now precedes it. shaped_parameter throws for scalar Number types. Agent-Harness: Claude Code 2.1.325 Agent-Model: claude-sonnet-5-5 Agent-Session: de59b94f-0227-49ea-adb5-b158639dad0b Agent-Review: unreviewed Co-authored-by: Claude Code <agent@noreply.juliahub.com>
Declared ranges that do not start at 1 passed the size check but made literal indices run out of bounds on the stored value, and a rank-1 declaration was accepted for a rank-2 array type. Both now throw. Agent-Harness: Claude Code 2.1.325 Agent-Model: claude-sonnet-5-5 Agent-Session: de59b94f-0227-49ea-adb5-b158639dad0b Agent-Review: unreviewed Co-authored-by: Claude Code <agent@noreply.juliahub.com>
|
Pushed
Known gaps that a last Codex pass still raised, not addressed here: value arrays with offset axes are accepted if lengths match; 🤖 Posted by an AI agent · harness: Claude Code 2.1.325 · model: claude-sonnet-5-5 |
A parameter of a non-
Realtype, such as aSparseMatrixCSCor a user operator struct, could not declare an array shape:@parameters K[1:m,1:n]::SparseMatrixCSCis rejected;SymbolicUtils.parse_variableturnsname[dims]::Tinto an array ofT.K::SparseMatrixCSC{Float64,Int}has an unknown shape, soK * utakes the shape ofuandw ~ K * ufails with "Cannot equate an array of different sizes" whenever the operator is rectangular (m != n).@register_array_symboliccannot size its output from a field of the symbolic operator argument.This adds
shaped_parameter(name, T, dims...; tunable = false)(@public, insrc/parameters.jl), which builds the symbol with an explicit shape. With it,size = (size(op, 1),)works inside@register_array_symbolic, and field blocks of unequal size go through theSystem/complete/DAEProblemcodegen path. The macro syntax would need a change in SymbolicUtils, so this is a function for now.Because the declared shape is now load-bearing for code generation, it is checked against supplied values: at
MTKParametersconstruction and inremake/validate_parameter_type, a value that definessizeand disagrees with the declared (non-empty) shape throws aDimensionMismatch(InvalidParameterSizeException). Values without asizemethod are accepted, and parameters with no declared array shape (@parameters K::SomeOp,p::Any) are not checked. Plain@parameters x[1:3]array parameters are now also checked at construction, whichremakealready did.Context: this is the "shaped non-Real array parameters" item of the FiniteElementMethod.jl upstream-blocker list (unequal field sizes on the codegen path).
Tests: new
test/shaped_parameters.jlcovers declaration, a rectangular registered operator, a two-field DAE with blocks of 7 and 3 unknowns built through codegen and compared against a hand-written residual and aDFBDFsolve, mismatch errors at construction andremakefor opaque and sparse values, and the no-false-positive cases. Initialization group passes; InterfaceI has one failure,components.jl:446"Causal connections generate causal equations", which also fails on master. Codex review (four rounds) approved.Notes: the implementation relies on
Sym{SymReal}withtype/shapeandshape_placeholderin@register_array_symbolic, which were tested with Symbolics 7.47; the declared compat lower bound is 7.45, which was not tested. An operator type needs its ownBase.sizefor the value check to apply.🤖 Posted by an AI agent · harness: Claude Code 2.1.311 · model: claude-sonnet-5-5
Review: unreviewed
Session: de59b94f-0227-49ea-adb5-b158639dad0b