From 01cff42cc383d9e4c3d980913e6375657bebfa89 Mon Sep 17 00:00:00 2001 From: ChrisRackauckas-Claude Date: Thu, 21 May 2026 16:48:58 -0400 Subject: [PATCH] Declare AbstractSystem as Enzyme inactive_type MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit The existing `inactive_noinl` rule on `getproperty(::AbstractSystem, ::Symbol)` is not enough to keep Enzyme's runtime-activity dispatch from trying to track a `System` as a differentiable value. Without `inactive_type`, `Enzyme.gradient(set_runtime_activity(Reverse), Const(loss), p)` over a closure that transitively captures an MTK-generated problem trips a `MethodError: no method matching MixedDuplicated(::System, ::System)` in `create_activity_wrapper`. The `System` type holds symbolic metadata only — never numeric derivative data — so declaring the type inactive is semantically correct and unblocks one more layer of the Enzyme-through-MTK-`remake` stack documented in SciML/SciMLSensitivity.jl#1359. Co-Authored-By: Chris Rackauckas --- lib/ModelingToolkitBase/src/ModelingToolkitBase.jl | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/lib/ModelingToolkitBase/src/ModelingToolkitBase.jl b/lib/ModelingToolkitBase/src/ModelingToolkitBase.jl index a3b2bed3da..92df029e65 100644 --- a/lib/ModelingToolkitBase/src/ModelingToolkitBase.jl +++ b/lib/ModelingToolkitBase/src/ModelingToolkitBase.jl @@ -369,6 +369,13 @@ function EnzymeCore.EnzymeRules.inactive_noinl( ) return true end +# Declare the type itself inactive so Enzyme's runtime-activity dispatch +# (e.g. `MixedDuplicated`-wrapping) never tries to track a `System` as a +# differentiable value. Without this, `Enzyme.gradient(set_runtime_activity(Reverse), +# Const(loss), p)` over a closure capturing an MTK-generated problem +# (which transitively carries the symbolic `System`) trips a +# `MethodError MixedDuplicated(::System, ::System)` in `create_activity_wrapper`. +EnzymeCore.EnzymeRules.inactive_type(::Type{<:AbstractSystem}) = true function __init__() SU.hashcons(unwrap(t_nounits), true)