From 21f7b7e5618fb0b98394c9d507f20b3662d552ff Mon Sep 17 00:00:00 2001 From: Fredrik Bagge Carlson Date: Fri, 24 Jul 2026 06:47:55 +0000 Subject: [PATCH] Fix named_ss(sys, linfun, outputs) on ModelingToolkit 11.36 MTK 11.36 removed the `inputs` field from LinearizationFunction (replaced by `inputs_getter`/`num_inputs`), breaking the precompiled-linfun `named_ss` method with a FieldError. Recover the input variables from the simplified system instead, which the operating-point extraction in the same method already does. Co-Authored-By: Claude Fable 5 Claude-Session: https://claude.ai/code/session_014QR4FuuvxZU9a3UrTJjg5X --- Project.toml | 2 +- src/ode_system.jl | 5 ++++- test/test_ODESystem.jl | 6 ++++++ 3 files changed, 11 insertions(+), 2 deletions(-) diff --git a/Project.toml b/Project.toml index 9cd1753..57dd372 100644 --- a/Project.toml +++ b/Project.toml @@ -1,7 +1,7 @@ name = "ControlSystemsMTK" uuid = "687d7614-c7e5-45fc-bfc3-9ee385575c88" authors = ["Fredrik Bagge Carlson"] -version = "2.8.0" +version = "2.8.1" [deps] ControlSystemsBase = "aaaaaaaa-a6ca-5380-bf3e-84a91bcd477e" diff --git a/src/ode_system.jl b/src/ode_system.jl index 93e8f63..a19c0ed 100644 --- a/src/ode_system.jl +++ b/src/ode_system.jl @@ -153,7 +153,10 @@ function RobustAndOptimalControl.named_ss( ) ssys = sys matrices, xpt = ModelingToolkit.linearize(sys, linfun; kwargs...) - inputs = linfun.inputs + # ModelingToolkit 11.36 removed the `inputs` field from LinearizationFunction; + # the input variables are recovered from the simplified system instead, which + # is what the operating-point extraction below already relies on. + inputs = ModelingToolkit.inputs(ssys) nu = length(inputs) unames = symstr.(inputs) if nu > 0 && size(matrices.B, 2) == 2nu diff --git a/test/test_ODESystem.jl b/test/test_ODESystem.jl index a828205..90a12d9 100644 --- a/test/test_ODESystem.jl +++ b/test/test_ODESystem.jl @@ -54,6 +54,12 @@ P02_named = named_ss(P, [input.u], [output.u]; op) P02 = ss(P02_named) @test P02 == P0 # verify that we get back what we started with +# named_ss from a precompiled LinearizationFunction (hot path) +lin_fun, sslin = ModelingToolkit.linearization_function(P, [input.u], [output.u]; op) +P02_linfun = named_ss(sslin, lin_fun, [output.u]; op) +@test P02_linfun.u == [Symbol("input₊u(t)")] +@test ss(P02_linfun) == P0 + # same for controller x = unknowns(C) @nonamespace C02 = named_ss(C, [C.input], [C.output]; op)