Repository navigation
Conversation
ambujone
left a comment
There was a problem hiding this comment.
This will conflict now (the Enzyme extension landed after you branched), and more importantly it breaks it. ModelingToolkitTearingEnzymeCoreExt.jl is written against numeric_ldiv! overwriting b: the forward rule returns b.val as the primal, augmented_primal returns b.val and snapshots it as x, and the reverse rule solves in place into db. With this change b.val still holds the RHS.
I merged current main into this branch (src merges cleanly) and ran test/enzyme.jl: 13 failures. For instance enzyme_test_loss(x0) returns 193.74 where the reference is 2.3305, and the reverse rule leaves dupb.val == [1, 2, 2.7] (the RHS) instead of the solution.
The shared-b bug is real, but #192 fixes it in safe_ldiv by solving a copy, which leaves numeric_ldiv!'s in-place contract and the Enzyme rules alone and does not add an allocation inside the solve. It may be simplest to let #192 cover the shared-b case; or, if you prefer the "return a new array" contract, updating the Enzyme rules and enzyme.jl in the same PR and adding a ForwardDiff check to the new test.
#160 copies the solution back into
b, but codegen emits identical expressions once, so inline linear SCCs with the samebshare that buffer and the second solve uses the first one's solution as its right-hand side. The solution now goes into a new array, and theLinearCacheis still reused: a 2x2 block's RHS call takes 135 ns vs 122 ns on main (151 ns on 1.20.6).