MTK -- change in `linearize`?

I have some MTK code including linearization that used to work, but doesn’t work any more. I’m trying to understand the changes by doing it differently, but I get a weird error message…

Here is a model with input `md_i` left undefined [`_noi` in the model below is supposed to mean “no input”]:

``````using ModelingToolkit
@mtkmodel Tank_noi begin
# Model parameters
@parameters begin
ρ=1,    [description = "Liquid density"]
A=5,    [description = "Cross sectional tank area"]
K=5,    [description = "Effluent valve constant"]
h_ς=3,  [description = "Scaling level in valve model"]
end
# Model variables, with initial values needed
@variables begin
m(t)=1.5*ρ*A,   [description = "Liquid mass"]
md_i(t),         [description = "Influent mass flow rate"]
md_e(t),         [description = "Effluent mass flow rate"]
V(t),           [description = "Liquid volume"]
h(t),           [description = "level"]
end
# Providing model equations
@equations begin
Dt(m) ~ md_i-md_e
m ~ ρ*V
V ~ A*h
md_e ~ K*sqrt(h/h_ς)
end
end
``````

I have another version, `Tank`, where I specify the input equation, e.g., by adding the equation `md_i ~ 2`.

I then try to linearize the model as follows:

``````> @named tank_noi = Tank_noi()
> #
> linearize(tank_noi, [md_i], [h]; op = Dict(md_i=>2))[1]
(A = [-0.2357022603955158;;], B = [1.0;;], C = [0.2;;], D = [-0.0;;])
``````

Fine, this works. But I would like to linearize the system at steady state, not at this more or less arbitrarily assigned initial state of `m(t)=1.5*ρ*A`

So I simulate the model with input, `@mtkbuild tank = Tank()`:

``````tspan = (0,1e3)
#
prob = ODEProblem(tank, [], tspan)
sol = solve(prob)
m_ss = sol(tspan[2])[1]
``````

[The value is `m_ss = 2.4000000003229878`]. Then I want to include both the specification of this steady state `m_ss` together with the chosen value of input, `md_i(t) = 2` as the operating point:

``````linearize(tank_noi, [md_i], [h]; op = Dict(m=>m_ss, md_i=>md(0)))[1]
``````

[Here, `md(0)` is a function with value = 2 at argument equal zero.]
This leads to a solid error message…

``````MethodError: no method matching parameter_values(::ModelingToolkit.MTKParameters{Tuple{Vector{Float64}}, Tuple{}, Tuple{}, Tuple{}, Tuple{}, RuntimeGeneratedFunctions.RuntimeGeneratedFunction{(:ˍ₋out, :ˍ₋arg1), ModelingToolkit.var"#_RGF_ModTag", ModelingToolkit.var"#_RGF_ModTag", (0x75594a42, 0xbfd4c1c3, 0xf1899263, 0x472d7113, 0xbef2191e), Expr}, RuntimeGeneratedFunctions.RuntimeGeneratedFunction{(:ˍ₋arg1,), ModelingToolkit.var"#_RGF_ModTag", ModelingToolkit.var"#_RGF_ModTag", (0xc3216e66, 0x27d6214a, 0x820916f4, 0x84591f82, 0x2d8b6a7c), Expr}})

Closest candidates are:
parameter_values(::ModelingToolkit.MTKParameters, !Matched::ModelingToolkit.ParameterIndex)
``````

In the past, it was possible to supply both these values as operating point.

• What has changed?

Could you provide the full stacktrace for the error?

1 Like

Here it is:

``````MethodError: no method matching parameter_values(::ModelingToolkit.MTKParameters{Tuple{Vector{Float64}}, Tuple{}, Tuple{}, Tuple{}, Tuple{}, RuntimeGeneratedFunctions.RuntimeGeneratedFunction{(:ˍ₋out, :ˍ₋arg1), ModelingToolkit.var"#_RGF_ModTag", ModelingToolkit.var"#_RGF_ModTag", (0x75594a42, 0xbfd4c1c3, 0xf1899263, 0x472d7113, 0xbef2191e), Expr}, RuntimeGeneratedFunctions.RuntimeGeneratedFunction{(:ˍ₋arg1,), ModelingToolkit.var"#_RGF_ModTag", ModelingToolkit.var"#_RGF_ModTag", (0xc3216e66, 0x27d6214a, 0x820916f4, 0x84591f82, 0x2d8b6a7c), Expr}})

Closest candidates are:

parameter_values(::ModelingToolkit.MTKParameters, !Matched::ModelingToolkit.ParameterIndex)

@ ModelingToolkit C:\Users\Bernt\.julia\packages\ModelingToolkit\353ne\src\systems\parameter_buffer.jl:318

parameter_values(::Any, !Matched::Any)

@ SymbolicIndexingInterface C:\Users\Bernt\.julia\packages\SymbolicIndexingInterface\RB8ao\src\value_provider_interface.jl:23

parameter_values(::Any, !Matched::SymbolicIndexingInterface.ParameterTimeseriesIndex, !Matched::Any)

@ SymbolicIndexingInterface C:\Users\Bernt\.julia\packages\SymbolicIndexingInterface\RB8ao\src\parameter_timeseries_collection.jl:98

...

Stacktrace:

[1] set_parameter!(sys::ModelingToolkit.MTKParameters{Tuple{Vector{Float64}}, Tuple{}, Tuple{}, Tuple{}, Tuple{}, RuntimeGeneratedFunctions.RuntimeGeneratedFunction{(:ˍ₋out, :ˍ₋arg1), ModelingToolkit.var"#_RGF_ModTag", ModelingToolkit.var"#_RGF_ModTag", (0x75594a42, 0xbfd4c1c3, 0xf1899263, 0x472d7113, 0xbef2191e), Expr}, RuntimeGeneratedFunctions.RuntimeGeneratedFunction{(:ˍ₋arg1,), ModelingToolkit.var"#_RGF_ModTag", ModelingToolkit.var"#_RGF_ModTag", (0xc3216e66, 0x27d6214a, 0x820916f4, 0x84591f82, 0x2d8b6a7c), Expr}}, val::Float64, idx::Nothing)

@ SymbolicIndexingInterface C:\Users\Bernt\.julia\packages\SymbolicIndexingInterface\RB8ao\src\value_provider_interface.jl:62

[2] (::SymbolicIndexingInterface.SetParameterIndex{Nothing})(prob::ModelingToolkit.MTKParameters{Tuple{Vector{Float64}}, Tuple{}, Tuple{}, Tuple{}, Tuple{}, RuntimeGeneratedFunctions.RuntimeGeneratedFunction{(:ˍ₋out, :ˍ₋arg1), ModelingToolkit.var"#_RGF_ModTag", ModelingToolkit.var"#_RGF_ModTag", (0x75594a42, 0xbfd4c1c3, 0xf1899263, 0x472d7113, 0xbef2191e), Expr}, RuntimeGeneratedFunctions.RuntimeGeneratedFunction{(:ˍ₋arg1,), ModelingToolkit.var"#_RGF_ModTag", ModelingToolkit.var"#_RGF_ModTag", (0xc3216e66, 0x27d6214a, 0x820916f4, 0x84591f82, 0x2d8b6a7c), Expr}}, val::Float64)

@ SymbolicIndexingInterface C:\Users\Bernt\.julia\packages\SymbolicIndexingInterface\RB8ao\src\parameter_indexing.jl:595

[3] (::SymbolicIndexingInterface.ParameterHookWrapper{SymbolicIndexingInterface.SetParameterIndex{Nothing}, Num})(prob::ModelingToolkit.MTKParameters{Tuple{Vector{Float64}}, Tuple{}, Tuple{}, Tuple{}, Tuple{}, RuntimeGeneratedFunctions.RuntimeGeneratedFunction{(:ˍ₋out, :ˍ₋arg1), ModelingToolkit.var"#_RGF_ModTag", ModelingToolkit.var"#_RGF_ModTag", (0x75594a42, 0xbfd4c1c3, 0xf1899263, 0x472d7113, 0xbef2191e), Expr}, RuntimeGeneratedFunctions.RuntimeGeneratedFunction{(:ˍ₋arg1,), ModelingToolkit.var"#_RGF_ModTag", ModelingToolkit.var"#_RGF_ModTag", (0xc3216e66, 0x27d6214a, 0x820916f4, 0x84591f82, 0x2d8b6a7c), Expr}}, args::Float64)

@ SymbolicIndexingInterface C:\Users\Bernt\.julia\packages\SymbolicIndexingInterface\RB8ao\src\parameter_indexing.jl:563

[4] (::ModelingToolkit.var"#309#324"{UnitRange{Int64}, UnitRange{Int64}, Vector{ModelingToolkit.ParameterIndex{SciMLStructures.Tunable, Tuple{Int64, Int64}}}, Vector{SymbolicUtils.BasicSymbolic{Real}}, ModelingToolkit.var"#307#322"{SymbolicIndexingInterface.MultipleGetters{Vector{SymbolicIndexingInterface.AbstractStateGetIndexer}}, Nothing, Nothing, Nothing, ModelingToolkit.MTKParameters{Tuple{Vector{Float64}}, Tuple{}, Tuple{}, Tuple{}, Tuple{}, RuntimeGeneratedFunctions.RuntimeGeneratedFunction{(:ˍ₋out, :ˍ₋arg1), ModelingToolkit.var"#_RGF_ModTag", ModelingToolkit.var"#_RGF_ModTag", (0x75594a42, 0xbfd4c1c3, 0xf1899263, 0x472d7113, 0xbef2191e), Expr}, RuntimeGeneratedFunctions.RuntimeGeneratedFunction{(:ˍ₋arg1,), ModelingToolkit.var"#_RGF_ModTag", ModelingToolkit.var"#_RGF_ModTag", (0xc3216e66, 0x27d6214a, 0x820916f4, 0x84591f82, 0x2d8b6a7c), Expr}}, SymbolicIndexingInterface.MultipleGetters{Vector{SymbolicIndexingInterface.GetStateIndex{Int64}}}}, ODEFunction{true, SciMLBase.FullSpecialize, ModelingToolkit.var"#f#740"{RuntimeGeneratedFunctions.RuntimeGeneratedFunction{(:ˍ₋arg1, :ˍ₋arg2, :t), ModelingToolkit.var"#_RGF_ModTag", ModelingToolkit.var"#_RGF_ModTag", (0x1693e76e, 0xc1c5f58d, 0xd3995334, 0x72760f7f, 0x68054973), Nothing}, RuntimeGeneratedFunctions.RuntimeGeneratedFunction{(:ˍ₋out, :ˍ₋arg1, :ˍ₋arg2, :t), ModelingToolkit.var"#_RGF_ModTag", ModelingToolkit.var"#_RGF_ModTag", (0x3128352d, 0x325aef3f, 0x55f369ce, 0x51f8a009, 0x7c5beb88), Nothing}}, UniformScaling{Bool}, Nothing, Nothing, Nothing, Nothing, Nothing, Nothing, Nothing, Nothing, Nothing, Nothing, Nothing, ModelingToolkit.ObservedFunctionCache{ODESystem}, Nothing, ODESystem, Nothing, Nothing}, NonlinearFunction{true, SciMLBase.FullSpecialize, ModelingToolkit.var"#f#564"{RuntimeGeneratedFunctions.RuntimeGeneratedFunction{(:ˍ₋arg1, :ˍ₋arg2), ModelingToolkit.var"#_RGF_ModTag", ModelingToolkit.var"#_RGF_ModTag", (0xdb662f8c, 0xa04d0075, 0x8580739c, 0xf64eb9c6, 0x2ec36ae2), Nothing}, RuntimeGeneratedFunctions.RuntimeGeneratedFunction{(:ˍ₋out, :ˍ₋arg1, :ˍ₋arg2), ModelingToolkit.var"#_RGF_ModTag", ModelingToolkit.var"#_RGF_ModTag", (0xfc23eb7e, 0x85194842, 0xc4beea70, 0x93ff1a17, 0xd9efaba5), Nothing}}, UniformScaling{Bool}, Nothing, Nothing, Nothing, Nothing, Nothing, Nothing, Nothing, Nothing, Nothing, Nothing, ModelingToolkit.var"#generated_observed#567"{NonlinearSystem, Dict{Any, Any}}, Nothing, NonlinearSystem, Vector{Float64}}, SymbolicIndexingInterface.MultipleGetters{Vector{SymbolicIndexingInterface.GetStateIndex{Int64}}}, RuntimeGeneratedFunctions.RuntimeGeneratedFunction{(Symbol("##arg#6263267626277010193"), Symbol("##arg#1612620725223230266"), :t), ModelingToolkit.var"#_RGF_ModTag", ModelingToolkit.var"#_RGF_ModTag", (0xb0c63428, 0xc3df6c9a, 0xed8eb5ad, 0x15f77e63, 0x6ee7c1f9), Nothing}, ForwardDiff.Chunk{1}, ModelingToolkit.MTKParameters{Tuple{Vector{Float64}}, Tuple{}, Tuple{}, Tuple{}, Tuple{}, RuntimeGeneratedFunctions.RuntimeGeneratedFunction{(:ˍ₋out, :ˍ₋arg1), ModelingToolkit.var"#_RGF_ModTag", ModelingToolkit.var"#_RGF_ModTag", (0x75594a42, 0xbfd4c1c3, 0xf1899263, 0x472d7113, 0xbef2191e), Expr}, RuntimeGeneratedFunctions.RuntimeGeneratedFunction{(:ˍ₋arg1,), ModelingToolkit.var"#_RGF_ModTag", ModelingToolkit.var"#_RGF_ModTag", (0xc3216e66, 0x27d6214a, 0x820916f4, 0x84591f82, 0x2d8b6a7c), Expr}}, Bool, GeneralizedFirstOrderAlgorithm{nothing, :TrustRegion, Missing, NonlinearSolve.GenericTrustRegionScheme{NonlinearSolve.RadiusUpdateSchemes.__Simple, Rational{Int64}, Rational{Int64}, Rational{Int64}, Rational{Int64}, Rational{Int64}, Nothing, Nothing, Nothing, Nothing}, Dogleg{NewtonDescent{Nothing, typeof(NonlinearSolve.DEFAULT_PRECS)}, SteepestDescent{Nothing, typeof(NonlinearSolve.DEFAULT_PRECS)}}, Nothing, Nothing, Nothing}, ODESystem})(u::Vector{Float64}, p::Dict{Num, Real}, t::Float64)

@ ModelingToolkit C:\Users\Bernt\.julia\packages\ModelingToolkit\353ne\src\systems\abstractsystem.jl:1977

[5] linearize(sys::ODESystem, lin_fun::ModelingToolkit.var"#309#324"{UnitRange{Int64}, UnitRange{Int64}, Vector{ModelingToolkit.ParameterIndex{SciMLStructures.Tunable, Tuple{Int64, Int64}}}, Vector{SymbolicUtils.BasicSymbolic{Real}}, ModelingToolkit.var"#307#322"{SymbolicIndexingInterface.MultipleGetters{Vector{SymbolicIndexingInterface.AbstractStateGetIndexer}}, Nothing, Nothing, Nothing, ModelingToolkit.MTKParameters{Tuple{Vector{Float64}}, Tuple{}, Tuple{}, Tuple{}, Tuple{}, RuntimeGeneratedFunctions.RuntimeGeneratedFunction{(:ˍ₋out, :ˍ₋arg1), ModelingToolkit.var"#_RGF_ModTag", ModelingToolkit.var"#_RGF_ModTag", (0x75594a42, 0xbfd4c1c3, 0xf1899263, 0x472d7113, 0xbef2191e), Expr}, RuntimeGeneratedFunctions.RuntimeGeneratedFunction{(:ˍ₋arg1,), ModelingToolkit.var"#_RGF_ModTag", ModelingToolkit.var"#_RGF_ModTag", (0xc3216e66, 0x27d6214a, 0x820916f4, 0x84591f82, 0x2d8b6a7c), Expr}}, SymbolicIndexingInterface.MultipleGetters{Vector{SymbolicIndexingInterface.GetStateIndex{Int64}}}}, ODEFunction{true, SciMLBase.FullSpecialize, ModelingToolkit.var"#f#740"{RuntimeGeneratedFunctions.RuntimeGeneratedFunction{(:ˍ₋arg1, :ˍ₋arg2, :t), ModelingToolkit.var"#_RGF_ModTag", ModelingToolkit.var"#_RGF_ModTag", (0x1693e76e, 0xc1c5f58d, 0xd3995334, 0x72760f7f, 0x68054973), Nothing}, RuntimeGeneratedFunctions.RuntimeGeneratedFunction{(:ˍ₋out, :ˍ₋arg1, :ˍ₋arg2, :t), ModelingToolkit.var"#_RGF_ModTag", ModelingToolkit.var"#_RGF_ModTag", (0x3128352d, 0x325aef3f, 0x55f369ce, 0x51f8a009, 0x7c5beb88), Nothing}}, UniformScaling{Bool}, Nothing, Nothing, Nothing, Nothing, Nothing, Nothing, Nothing, Nothing, Nothing, Nothing, Nothing, ModelingToolkit.ObservedFunctionCache{ODESystem}, Nothing, ODESystem, Nothing, Nothing}, NonlinearFunction{true, SciMLBase.FullSpecialize, ModelingToolkit.var"#f#564"{RuntimeGeneratedFunctions.RuntimeGeneratedFunction{(:ˍ₋arg1, :ˍ₋arg2), ModelingToolkit.var"#_RGF_ModTag", ModelingToolkit.var"#_RGF_ModTag", (0xdb662f8c, 0xa04d0075, 0x8580739c, 0xf64eb9c6, 0x2ec36ae2), Nothing}, RuntimeGeneratedFunctions.RuntimeGeneratedFunction{(:ˍ₋out, :ˍ₋arg1, :ˍ₋arg2), ModelingToolkit.var"#_RGF_ModTag", ModelingToolkit.var"#_RGF_ModTag", (0xfc23eb7e, 0x85194842, 0xc4beea70, 0x93ff1a17, 0xd9efaba5), Nothing}}, UniformScaling{Bool}, Nothing, Nothing, Nothing, Nothing, Nothing, Nothing, Nothing, Nothing, Nothing, Nothing, ModelingToolkit.var"#generated_observed#567"{NonlinearSystem, Dict{Any, Any}}, Nothing, NonlinearSystem, Vector{Float64}}, SymbolicIndexingInterface.MultipleGetters{Vector{SymbolicIndexingInterface.GetStateIndex{Int64}}}, RuntimeGeneratedFunctions.RuntimeGeneratedFunction{(Symbol("##arg#6263267626277010193"), Symbol("##arg#1612620725223230266"), :t), ModelingToolkit.var"#_RGF_ModTag", ModelingToolkit.var"#_RGF_ModTag", (0xb0c63428, 0xc3df6c9a, 0xed8eb5ad, 0x15f77e63, 0x6ee7c1f9), Nothing}, ForwardDiff.Chunk{1}, ModelingToolkit.MTKParameters{Tuple{Vector{Float64}}, Tuple{}, Tuple{}, Tuple{}, Tuple{}, RuntimeGeneratedFunctions.RuntimeGeneratedFunction{(:ˍ₋out, :ˍ₋arg1), ModelingToolkit.var"#_RGF_ModTag", ModelingToolkit.var"#_RGF_ModTag", (0x75594a42, 0xbfd4c1c3, 0xf1899263, 0x472d7113, 0xbef2191e), Expr}, RuntimeGeneratedFunctions.RuntimeGeneratedFunction{(:ˍ₋arg1,), ModelingToolkit.var"#_RGF_ModTag", ModelingToolkit.var"#_RGF_ModTag", (0xc3216e66, 0x27d6214a, 0x820916f4, 0x84591f82, 0x2d8b6a7c), Expr}}, Bool, GeneralizedFirstOrderAlgorithm{nothing, :TrustRegion, Missing, NonlinearSolve.GenericTrustRegionScheme{NonlinearSolve.RadiusUpdateSchemes.__Simple, Rational{Int64}, Rational{Int64}, Rational{Int64}, Rational{Int64}, Rational{Int64}, Nothing, Nothing, Nothing, Nothing}, Dogleg{NewtonDescent{Nothing, typeof(NonlinearSolve.DEFAULT_PRECS)}, SteepestDescent{Nothing, typeof(NonlinearSolve.DEFAULT_PRECS)}}, Nothing, Nothing, Nothing}, ODESystem}; t::Float64, op::Dict{Num, Real}, allow_input_derivatives::Bool, p::SciMLBase.NullParameters)

@ ModelingToolkit C:\Users\Bernt\.julia\packages\ModelingToolkit\353ne\src\systems\abstractsystem.jl:2269

[6] linearize(sys::ODESystem, inputs::Vector{Num}, outputs::Vector{Num}; op::Dict{Num, Real}, t::Float64, allow_input_derivatives::Bool, zero_dummy_der::Bool, kwargs::@Kwargs{})

@ ModelingToolkit C:\Users\Bernt\.julia\packages\ModelingToolkit\353ne\src\systems\abstractsystem.jl:2320

[7] top-level scope

@ c:\Users\Bernt\OneDrive\Documents\booksBLSOL\Julia\Notebooks\J6_ModelingToolkit-intro.ipynb:1
``````

Thanks for reporting the bug. It is fixed in fix: fix unknowns not present in initialization system in linearization by AayushSabharwal · Pull Request #2809 · SciML/ModelingToolkit.jl · GitHub

2 Likes

Ah. A bug? I thought it was a breaking change

OK – your fix, could it also be the answer to linearization of a more complex system I look into?

I try to do linearization from variable `of_noi.dm.ṁ_i` to `of_noi.dm.p`, where I want to specify the initial unknowns (steady state values; there are 16 of them) and a single input (`of_noi.dm.ṁ_i`).

So I find the steady state by simulating a system `of` [oil field] until steady state, and then pick out the final value of the solution `sol`:

``````x0 = sol(tspan[2])
``````

I can query some values from the solution:

``````> sol(0; idxs=of.dm.ṁ_i), sol(0; idxs=of.dm.p)
(9.222222222222221, 1.1485330911824014e7)
``````

Then I create a new model, `of_noi`, by just commenting out the equation in `of` where `of.dm.ṁ_i` is given a value, + I instantiate `of_noi`.

Then I try to do the linearization:

``````linearize(of_noi, [of_noi.dm.ṁ_i], [of_noi.dm.p])
``````

NOTICE: I don’t even try to specify the operating point `op` here – still it fails:

``````{
"name": "ErrorException",
"message": "Some specified inputs were not found in system. The following variables were not found Any[of_noi₊dm₊ṁ_i(t)]",
"stack": "Some specified inputs were not found in system. The following variables were not found Any[of_noi₊dm₊ṁ_i(t)]\n\nStacktrace:\n  [1] error(::String, ::Base.KeySet{Any, Dict{Any, Bool}})\n    @ Base .\\error.jl:44\n  [2] markio!(state::TearingState{ODESystem}, orig_inputs::Set{Any}, inputs::Vector{Num}, outputs::Vector{Num}; check::Bool)\n    @ ModelingToolkit C:\\Users\\Bernt\\.julia\\packages\\ModelingToolkit\\353ne\\src\\systems\\abstractsystem.jl:2141\n  [3] markio!\n    @ C:\\Users\\Bernt\\.julia\\packages\\ModelingToolkit\\353ne\\src\\systems\\abstractsystem.jl:2112 [inlined]\n  [4] _structural_simplify!(state::TearingState{ODESystem}, io::Tuple{Vector{Num}, Vector{Num}}; simplify::Bool, check_consistency::Bool, fully_determined::Bool, warn_initialize_determined::Bool, dummy_derivative::Bool, kwargs::@Kwargs{})\n    @ ModelingToolkit C:\\Users\\Bernt\\.julia\\packages\\ModelingToolkit\\353ne\\src\\systems\\systemstructure.jl:682\n  [5] structural_simplify!(state::TearingState{ODESystem}, io::Tuple{Vector{Num}, Vector{Num}}; simplify::Bool, check_consistency::Bool, fully_determined::Bool, warn_initialize_determined::Bool, kwargs::@Kwargs{})\n    @ ModelingToolkit C:\\Users\\Bernt\\.julia\\packages\\ModelingToolkit\\353ne\\src\\systems\\systemstructure.jl:634\n  [6] __structural_simplify(sys::ODESystem, io::Tuple{Vector{Num}, Vector{Num}}; simplify::Bool, kwargs::@Kwargs{})\n    @ ModelingToolkit C:\\Users\\Bernt\\.julia\\packages\\ModelingToolkit\\353ne\\src\\systems\\systems.jl:81\n  [7] structural_simplify(sys::ODESystem, io::Tuple{Vector{Num}, Vector{Num}}; simplify::Bool, split::Bool, kwargs::@Kwargs{})\n    @ ModelingToolkit C:\\Users\\Bernt\\.julia\\packages\\ModelingToolkit\\353ne\\src\\systems\\systems.jl:22\n  [8] structural_simplify\n    @ C:\\Users\\Bernt\\.julia\\packages\\ModelingToolkit\\353ne\\src\\systems\\systems.jl:19 [inlined]\n  [9] io_preprocessing(sys::ODESystem, inputs::Vector{Num}, outputs::Vector{Num}; simplify::Bool, kwargs::@Kwargs{})\n    @ ModelingToolkit C:\\Users\\Bernt\\.julia\\packages\\ModelingToolkit\\353ne\\src\\systems\\abstractsystem.jl:1812\n [10] linearization_function(sys::ODESystem, inputs::Vector{Num}, outputs::Vector{Num}; simplify::Bool, initialize::Bool, op::Dict{Any, Any}, p::SciMLBase.NullParameters, zero_dummy_der::Bool, initialization_solver_alg::GeneralizedFirstOrderAlgorithm{nothing, :TrustRegion, Missing, NonlinearSolve.GenericTrustRegionScheme{NonlinearSolve.RadiusUpdateSchemes.__Simple, Rational{Int64}, Rational{Int64}, Rational{Int64}, Rational{Int64}, Rational{Int64}, Nothing, Nothing, Nothing, Nothing}, Dogleg{NewtonDescent{Nothing, typeof(NonlinearSolve.DEFAULT_PRECS)}, SteepestDescent{Nothing, typeof(NonlinearSolve.DEFAULT_PRECS)}}, Nothing, Nothing, Nothing}, kwargs::@Kwargs{})\n    @ ModelingToolkit C:\\Users\\Bernt\\.julia\\packages\\ModelingToolkit\\353ne\\src\\systems\\abstractsystem.jl:1866\n [11] linearization_function\n    @ C:\\Users\\Bernt\\.julia\\packages\\ModelingToolkit\\353ne\\src\\systems\\abstractsystem.jl:1856 [inlined]\n [12] linearize(sys::ODESystem, inputs::Vector{Num}, outputs::Vector{Num}; op::Dict{Any, Any}, t::Float64, allow_input_derivatives::Bool, zero_dummy_der::Bool, kwargs::@Kwargs{})\n    @ ModelingToolkit C:\\Users\\Bernt\\.julia\\packages\\ModelingToolkit\\353ne\\src\\systems\\abstractsystem.jl:2314\n [13] linearize(sys::ODESystem, inputs::Vector{Num}, outputs::Vector{Num})\n    @ ModelingToolkit C:\\Users\\Bernt\\.julia\\packages\\ModelingToolkit\\353ne\\src\\systems\\abstractsystem.jl:2310\n [14] top-level scope\n    @ c:\\Users\\Bernt\\OneDrive\\Documents\\researchUSN\\Supervisor\\PhD\\Kushila_Jayamanne\\Notebooks\\gas-lifted_oil-field_DAE_components.ipynb:1"
}
``````

Any ideas? Is this related to the previous bug?

If I were to specify the operating point… , could I do, e.g.,

``````my_op = merge(Dict(unknowns(of).=>x0), Dict(of_noi.dm.ṁ_i=>1e3))
linearize(of_noi, [of_noi.dm.ṁ_i], [of_noi.dm.p], op=my_op)
``````

This feels like a namespacing thing. Try calling `complete` on `of_noi` before calling `linearize`. If that doesn’t work, please provide a code example. It’s difficult to debug with a textual description of what you’re doing, since there are many ways of doing the same thing and subtleties matter.

OK. I did

``````@named of_noi = OilField()
of_noi = complete(of_noi)
``````

[Don’t know if the renaming of `of_noi`, i.e., using the same name for in the argument of `complete()` and the result is a problem…]

I now get another error message:

``````BoundsError: attempt to access 302-element Vector{Vector{Int64}} at index [303]
``````

or with some more details:

``````{
"name": "BoundsError",
"message": "BoundsError: attempt to access 302-element Vector{Vector{Int64}} at index [303]",
"stack": "BoundsError: attempt to access 302-element Vector{Vector{Int64}} at index [303]\n\nStacktrace:\n  [1] getindex\n    @ .\\essentials.jl:13 [inlined]\n  [2] 𝑑neighbors\n    @ C:\\Users\\Bernt\\.julia\\packages\\ModelingToolkit\\353ne\\src\\bipartite_graph.jl:369 [inlined]\n  [3] 𝑑neighbors\n    @ C:\\Users\\Bernt\\.julia\\packages\\ModelingToolkit\\353ne\\src\\bipartite_graph.jl:368 [inlined]\n  [4] check_consistency(state::TearingState{ODESystem}, orig_inputs::Set{Any})\n    @ ModelingToolkit.StructuralTransformations C:\\Users\\Bernt\\.julia\\packages\\ModelingToolkit\\353ne\\src\\structural_transformation\\utils.jl:96\n  [5] _structural_simplify!(state::TearingState{ODESystem}, io::Tuple{Vector{Num}, Vector{Num}}; simplify::Bool, check_consistency::Bool, fully_determined::Bool, warn_initialize_determined::Bool, dummy_derivative::Bool, kwargs::@Kwargs{})\n    @ ModelingToolkit C:\\Users\\Bernt\\.julia\\packages\\ModelingToolkit\\353ne\\src\\systems\\systemstructure.jl:691\n  [6] structural_simplify!(state::TearingState{ODESystem}, io::Tuple{Vector{Num}, Vector{Num}}; simplify::Bool, check_consistency::Bool, fully_determined::Bool, warn_initialize_determined::Bool, kwargs::@Kwargs{})\n    @ ModelingToolkit C:\\Users\\Bernt\\.julia\\packages\\ModelingToolkit\\353ne\\src\\systems\\systemstructure.jl:634\n  [7] __structural_simplify(sys::ODESystem, io::Tuple{Vector{Num}, Vector{Num}}; simplify::Bool, kwargs::@Kwargs{})\n    @ ModelingToolkit C:\\Users\\Bernt\\.julia\\packages\\ModelingToolkit\\353ne\\src\\systems\\systems.jl:81\n  [8] structural_simplify(sys::ODESystem, io::Tuple{Vector{Num}, Vector{Num}}; simplify::Bool, split::Bool, kwargs::@Kwargs{})\n    @ ModelingToolkit C:\\Users\\Bernt\\.julia\\packages\\ModelingToolkit\\353ne\\src\\systems\\systems.jl:22\n  [9] structural_simplify\n    @ C:\\Users\\Bernt\\.julia\\packages\\ModelingToolkit\\353ne\\src\\systems\\systems.jl:19 [inlined]\n [10] io_preprocessing(sys::ODESystem, inputs::Vector{Num}, outputs::Vector{Num}; simplify::Bool, kwargs::@Kwargs{})\n    @ ModelingToolkit C:\\Users\\Bernt\\.julia\\packages\\ModelingToolkit\\353ne\\src\\systems\\abstractsystem.jl:1812\n [11] linearization_function(sys::ODESystem, inputs::Vector{Num}, outputs::Vector{Num}; simplify::Bool, initialize::Bool, op::Dict{Any, Any}, p::SciMLBase.NullParameters, zero_dummy_der::Bool, initialization_solver_alg::GeneralizedFirstOrderAlgorithm{nothing, :TrustRegion, Missing, NonlinearSolve.GenericTrustRegionScheme{NonlinearSolve.RadiusUpdateSchemes.__Simple, Rational{Int64}, Rational{Int64}, Rational{Int64}, Rational{Int64}, Rational{Int64}, Nothing, Nothing, Nothing, Nothing}, Dogleg{NewtonDescent{Nothing, typeof(NonlinearSolve.DEFAULT_PRECS)}, SteepestDescent{Nothing, typeof(NonlinearSolve.DEFAULT_PRECS)}}, Nothing, Nothing, Nothing}, kwargs::@Kwargs{})\n    @ ModelingToolkit C:\\Users\\Bernt\\.julia\\packages\\ModelingToolkit\\353ne\\src\\systems\\abstractsystem.jl:1866\n [12] linearization_function\n    @ C:\\Users\\Bernt\\.julia\\packages\\ModelingToolkit\\353ne\\src\\systems\\abstractsystem.jl:1856 [inlined]\n [13] linearize(sys::ODESystem, inputs::Vector{Num}, outputs::Vector{Num}; op::Dict{Any, Any}, t::Float64, allow_input_derivatives::Bool, zero_dummy_der::Bool, kwargs::@Kwargs{})\n    @ ModelingToolkit C:\\Users\\Bernt\\.julia\\packages\\ModelingToolkit\\353ne\\src\\systems\\abstractsystem.jl:2314\n [14] linearize(sys::ODESystem, inputs::Vector{Num}, outputs::Vector{Num})\n    @ ModelingToolkit C:\\Users\\Bernt\\.julia\\packages\\ModelingToolkit\\353ne\\src\\systems\\abstractsystem.jl:2310\n [15] top-level scope\n    @ c:\\Users\\Bernt\\OneDrive\\Documents\\researchUSN\\Supervisor\\PhD\\Kushila_Jayamanne\\Notebooks\\gas-lifted_oil-field_DAE_components.ipynb:1"
}
``````

If you need a code example, I can e-mail you my notebook with the code… it is a little involved, but would also be time consuming to created a minimal example.