Repository navigation
Bind array variables read by the output of optimize rules - #5417
singhharsh1708 wants to merge 28 commits into
Conversation
PR: #5417 Reviewed head: 74aeb9d Risk assessment
Review reportVERDICT: CHANGES Riskmedium (M2: opt-in optimization silently changes a previously correct preface result) Blocking findings
Non-blocking findings
What I ran
What I did not verify
AUTHOR_GRADE: {"task":"bugfix","score":2,"difficulty":3,"rounds":2,"author_harness":"unknown","author_model":"unknown","note":"The added ODE regression distinguishes base and head. All three prior blockers reproduce, including the silent preface result regression."} Head link: 74aeb9d 🤖 Posted by an AI agent — harness: codex-cli 0.170.0 · model: gpt-6.2-sol |
|
Fixed: rule-read arrays are now bound before |
PR: #5417 Reviewed head: 6f9ef68 Risk assessment
Review reportVERDICT: CHANGES Risklow (L6: opt-in array rewrites that errored on the merge base now return the expected values. The preface result and the generated code in the no-rule control match the base.) Blocking findings
Non-blocking findings
What I ran
What I did not verifyI did not rerun other test groups, test minimum supported versions, benchmark code generation, or independently inspect remote CI. AUTHOR_GRADE: {"task":"bugfix","score":4,"difficulty":3,"rounds":3,"author_harness":"unknown","author_model":"unknown","note":"The preface and tuple reproducers now pass, and the new regression distinguishes base from head. The post-rule scan and tests still use private dependency names."} Head link: 6f9ef68 🤖 Posted by an AI agent — harness: codex-cli 0.169.0 · model: gpt-6.2-astra |
…ut and IR-only rewrites
…es and IR-only constants
|
Switched the scan to one public |
Thanks @singhharsh1708. At head 14a3e54 the job The ForwardDiff gradient blows up to about -6e165 where the finite difference gives -1.15. Could you check whether the new binding of array variables read by 🤖 Posted by an AI agent — harness: Claude Code 2.1.325 · model: claude-sonnet-5-5 |
|
It doesn't reproduce here: |
|
Could you show the generated code beforethese changes to motivate what the error is. This seems like a lot of machinery. |
|
A rule that rewrites local var"##cse#2" = x
local var"##cse#4" = var"##cse#2"(t)
local var"##cse#5" = mapreduce(identity, Base.add_sum, var"##cse#4")
# f throws UndefVarError: `x` not definedAfter, it binds x = reshape(view(___mtkunknowns___, 4:-1:1), (4,))
local var"##cse#3" = mapreduce(identity, Base.add_sum, x)Agreed it was too much machinery. Most of it came from following the automated review round by round, which I've stopped doing. I've cut it down to binding every array the arguments can rebuild whenever rules are given, which the existing helpers already do with |
Fixes #5416.
An
optimizerule whose output reads a whole array variable, for examplesum(x)on a scalarizedx, gave anfthat throwsUndefVarError: x:build_function_wrapperonly binds the arrays the expressions read before the rules run, and the rules run later insideSymbolics.codegen_function. When rules are given it now binds every array variable the arguments can rebuild. Without rules the generated code is unchanged. With rules a function carries a few unused bindings, and those bindings become requirements: a state passed as a tuple can't be viewed into, and the cached parameter-array layout of a system is reused even when a later call passes different parameters. An array split between the state and a cache buffer still isn't rebuilt, as before.Binding those arrays exposed two gaps in the cache-array reconstruction: the multi-buffer branch read from the wrong arguments (missing
buffer_offset), and merging the cache buffers shifted missing elements so an incomplete array was no longer skipped. Both are fixed. The new tests fail on master with theUndefVarError, give 12.0 instead of 62.0 without the offset fix, and throw aBoundsErrorwithout the merge fix.