Repository navigation
Fix flattening of array dependent variables - #101
ChrisRackauckas merged 1 commit into
Conversation
|
Correction to a claim in the PR description. I wrote that
The old QA ignore existed only because PDEBase imported them from the parent That means This does not change the fix in this PR: it is verified and introduces no ignore either way. But it does open a cheaper alternative worth considering — revert Trade-off, briefly:
Happy to switch it to the restore if preferred — @ChrisRackauckas. Ignore until reviewed. |
SciML#98 rewrote `chain_flatten_array_variables` to avoid a QA ignore for `Chain` and `Prewalk`. The rewrite keyed its replacement map on the array operation alone, so every `u[i]` overwrote the previous entry and all indices collapsed onto the last one, and it built replacements with `Symbolics.variable(...; T = symtype(name))`, which yields an array-valued variable rather than a callable. The resulting `Arr` reached `get_ops`, so discretizing any `PDESystem` written against `@variables (u(..))[1:N]` failed with `MethodError: operation(::Symbolics.Arr{Num, 1})`. The ignore was avoidable without touching this code: `Chain` and `Prewalk` are public in `SymbolicUtils.Rewriters`, which owns them, and were only non-public via the parent `SymbolicUtils`. Import them from the owner and restore the previous implementation, which shipped in 0.1.30. Fixes SciML#100 Co-Authored-By: Chris Rackauckas <[email protected]> Co-Authored-By: Claude Opus 5 (1M context) <[email protected]> Claude-Session: https://claude.ai/code/session_0117aJvytDT3y2jMi5Ng6Q5m
3e94cef to
6cb4f31
Compare
|
Force-pushed 6cb4f31, replacing the previous approach. Two changes since the last review pass. 1. Rebased onto current master. The branch was based on 3ea8c85, i.e. before #99 merged. Merging it as it stood would have reverted the 2. Switched from repairing the rewrite to restoring the original implementation, per the correction above. This PR now imports I also opened JuliaSymbolics/SymbolicUtils.jl#1021 to declare the combinators public in the top-level Validation on Julia 1.12.6, all re-run after the rebase:
The 11 are MethodOfLines loads cleanly against this branch, with Ignore until reviewed by @ChrisRackauckas. |
Fixes #100. Independent of #99 — different files, either order merges.
Problem
Discretizing a
PDESystemwritten against@variables (u(..))[1:N]fails on master:Introduced by #98, which rewrote
chain_flatten_array_variablesfrom a per-index@rulelist to aDict. Two defects:fullnamevaries per index but the key did not, so each iteration overwrote the previous and everyu[i]collapsed onto whichever index came last.Symbolics.variable(fullname; T = symtype(name))does not produce a callable. It yields an array-valued variable, so the index was never resolved away and anArrpropagated throughdvs = map(safe_ch, dvs)intoget_dvs, whereget_opscalledoperationon it.Probing the function directly on master shows both:
Fix
Key the map on
(name, idxs), and build the replacement as a callable symbolic sou(x)[i]flattens tou_[i](x).The result is
safe_unwrapped: the surrounding traversal composes terms out of unwrapped arguments, so returning aNumwould leak a wrapper intomaketerm. My first attempt missed this and the new test caught it.I deliberately kept #98's manual traversal instead of restoring
Prewalk(Chain(rs)). The old form depended onChainandPrewalk, non-public SymbolicUtils names that were in the QA ignore list removed by #98 — reverting would undo that.@variablesis public Symbolics API, so no ignore is reintroduced.Tests
New
test/array_variables.jlasserts the two properties that broke:Ndistinct replacements foru[1..N], and that each result is a non-Arrcallable term in the independent variable. Both fail on unfixed master.Validation
Julia 1.12.6.
MethodOfLines.jl/test/MOL_Interface1/MOLtest1.jl:231("Array u"):MethodError→discretize OK.GROUP=Core:alloc_tests12,array_variables11,discrete_initialization18,public_api46 — all pass.GROUP=QA: 20/20 pass.MOL_Interface1(the group that surfaced this) runs clean against this branch with MOL compat locally widened. Note the parent testset reports0because SafeTestsets does not aggregate pass counts — only failures propagate, which is how the original error surfaced.Runic --checkclean.Ignore until reviewed by @ChrisRackauckas.
🤖 Generated with Claude Code
https://claude.ai/code/session_0117aJvytDT3y2jMi5Ng6Q5m