-
-
Notifications
You must be signed in to change notification settings - Fork 209
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
MTK -- linearization bug (?) #2888
Comments
This is a bug / poor error message in structural simplify BoundsError: attempt to access 302-element Vector{Vector{Int64}} at index [303]
[2] 𝑑neighbors
@ C:\Users\Bernt\.julia\packages\ModelingToolkit\7em8Z\src\bipartite_graph.jl:369 [inlined]
[3] 𝑑neighbors
@ C:\Users\Bernt\.julia\packages\ModelingToolkit\7em8Z\src\bipartite_graph.jl:368 [inlined]
[4] check_consistency(state::TearingState{ODESystem}, orig_inputs::Set{Any}) looks similar to This issue can probably be closed in favor of other similar ones, this one does not have a reproducer |
I'm not explicitly using |
yes, structural simplification is required also for linearization, so that happens internally. |
Can we isolate this? |
Hm. OK. In case I have no statements equating parameters. However, I do "reuse" parameters in different components: I have created a component of physical data: @mtkmodel GasLift_Properties begin
# Model parameters
@parameters begin
g = 9.81, [description = "Acceleration of gravity, m/s^2"]
R = 8.3145, [description = "Ideal gas constant, J/(K*mol)"]
T = 280, [description = "Temperature, assumed constant, K"]
M = 20.2511e-3, [description = "Molar mas,s kg/mol"]
ρ_ℓ = 780, [description = "Liquid density, kg/m^3"]
z = 0.7, [description = "Gas compressibility, assumed constant, -"]
zRT = z*R*T
p_c = 45.5e5,[description = "Critical pressure, Pa"]
T_c = 215, [description = "Critical temperature, K"]
Ṽ_qc = T_c*R/p_c, [description = "Quasi-critical molar volume, m^3/mol"]
end
end which I used as components in various other models in order to ensure consistency. Could that be the problem? |
Even though the example is not the same, the error is similar to what happened to me in #2870, where I got ERROR: BoundsError: attempt to access 2-element Vector{Any} at index [3] Are the bugs related somehow? I was also using |
That's completely unrelated. The other one is just that you didn't define derivatives on your registered function. |
Oh, I'll review it again. I'm sorry. |
I just haven't gotten to answering that one because I want to make it give a better error message, but you can see your stack trace is in |
When I try to linearize my model, I get an "BoundsError: attempt to access 302-element Vector{Vector{Int64}} at index [303]" error🐞
Here is my Julia/MTK statement with partial error message:
Expected behavior
I expected Julia to respond with a collection of linearized matrices A, B, C, D, etc.
Minimal Reproducible Example 👇
I have not been able to create a minimal reproducible example (MRE). I tried to make a couple of similar examples, but in both of those cases, my code works.
Still, to illustrate what I do, I include a similar but slightly simpler example. In this simplified example, I consider a Telegraph Line module:
which I then cascade into a Telegraph Line system:
I then instantiate this model + run the simulation successfully:
This works fine.
Next, I want to linearize the model. To do so, without using
ModelingToolkitStandardLibrary
and Analysis Points, I create a copy of the system model where I comment out the definition of input(s), i.e., I create a version with "no inputs" (_noi
):which I then instantiate and do the linearization:
This works (as expected).
My problem is that when I do the exactly same thing for my other, slightly more complex model, (i) doing simulation with the balanced model works, but (ii) when creating a model with inputs commented out, linearization leads to the error message with BoundsError.
Error & Stacktrace⚠️
Environment (please complete the following information):
using Pkg; Pkg.status()
using Pkg; Pkg.status(; mode = PKGMODE_MANIFEST)
versioninfo()
Additional context
The problem where I get an error message is somewhat too complex to include here. Also, it is part of a research project, and I'd prefer to not include it in public. However, if some MTK developers need to get access to my code, I can provide it via e-mail.
The text was updated successfully, but these errors were encountered: