DARPA-ASKEM / terarium

https://app.terarium.ai
Apache License 2.0
13 stars 2 forks source link

[BUG]: Sciml error generating latex after model-edit #4092

Open bigglesandginger opened 1 month ago

bigglesandginger commented 1 month ago

Describe the issue After saving the edited model and seeing that it was in the list of resources, I opened it and got a LaTeX error. Error from sciml:

[ Info: amr_get ODESystem
[ Info: 2024-07-10T13:55:13+0000 - 10.244.9.1:39922 - "GET /health HTTP/1.1" 200
┌ Error: ERROR:
│   exception =
│    ExtraVariablesSystemException: The system is unbalanced. There are 7 highest order derivative variables and 5 equations.
│    More variables than equations, here are the potential extra variable(s):
│     S(t)
│     I(t)
│     R(t)
│     B2(t)
│     B3(t)
│     var"|β|"
│     var"|γ|"
│    Stacktrace:
│      [1] error_reporting(state::ModelingToolkit.TearingState{ModelingToolkit.ODESystem}, bad_idxs::Vector{Int64}, n_highest_vars::Int64, iseqs::Bool, orig_inputs::Set{Any})
│        @ ModelingToolkit.StructuralTransformations ~/.julia/packages/ModelingToolkit/w72sG/src/structural_transformation/utils.jl:50
│      [2] check_consistency(state::ModelingToolkit.TearingState{ModelingToolkit.ODESystem}, orig_inputs::Set{Any})
│        @ ModelingToolkit.StructuralTransformations ~/.julia/packages/ModelingToolkit/w72sG/src/structural_transformation/utils.jl:85
│      [3] _structural_simplify!(state::ModelingToolkit.TearingState{ModelingToolkit.ODESystem}, io::Nothing; simplify::Bool, check_consistency::Bool, fully_determined::Bool, warn_initialize_determined::Bool, dummy_derivative::Bool, kwargs::@Kwargs{})
│        @ ModelingToolkit ~/.julia/packages/ModelingToolkit/w72sG/src/systems/systemstructure.jl:689
│      [4] structural_simplify!(state::ModelingToolkit.TearingState{ModelingToolkit.ODESystem}, io::Nothing; simplify::Bool, check_consistency::Bool, fully_determined::Bool, warn_initialize_determined::Bool, kwargs::@Kwargs{})
│        @ ModelingToolkit ~/.julia/packages/ModelingToolkit/w72sG/src/systems/systemstructure.jl:635
│      [5] __structural_simplify(sys::ModelingToolkit.ODESystem, io::Nothing; simplify::Bool, kwargs::@Kwargs{})
│        @ ModelingToolkit ~/.julia/packages/ModelingToolkit/w72sG/src/systems/systems.jl:74
│      [6] __structural_simplify
│        @ ~/.julia/packages/ModelingToolkit/w72sG/src/systems/systems.jl:55 [inlined]
│      [7] structural_simplify(sys::ModelingToolkit.ODESystem, io::Nothing; simplify::Bool, split::Bool, kwargs::@Kwargs{})
│        @ ModelingToolkit ~/.julia/packages/ModelingToolkit/w72sG/src/systems/systems.jl:22
│      [8] structural_simplify (repeats 2 times)
│        @ ~/.julia/packages/ModelingToolkit/w72sG/src/systems/systems.jl:19 [inlined]
│      [9] amr_get_petrinet(amr::JSON3.Object{Vector{UInt8}, Vector{UInt64}})
│        @ SimulationService /sciml-service/src/operations.jl:85
│     [10] amr_get(amr::JSON3.Object{Vector{UInt8}, Vector{UInt64}}, ::Type{ModelingToolkit.ODESystem})
│        @ SimulationService /sciml-service/src/operations.jl:12
│     [11] modelEquation(::HTTP.Messages.Request, id::String)
│        @ SimulationService /sciml-service/src/SimulationService.jl:228
│     [12] #5
│        @ ~/.julia/packages/Oxygen/LWjgB/src/handlers.jl:36 [inlined]
│     [13] #14#15
│        @ ~/.julia/packages/Oxygen/LWjgB/src/handlers.jl:54 [inlined]
│     [14] #14
│        @ ~/.julia/packages/Oxygen/LWjgB/src/handlers.jl:53 [inlined]
│     [15] (::Oxygen.Core.var"#56#58"{typeof(SimulationService.modelEquation), @NamedTuple{info::@NamedTuple{name::Symbol, args::Vector{Oxygen.Core.Types.Param}, kwargs::Vector{Oxygen.Core.Types.Param}, sig::Vector{Oxygen.Core.Types.Param}, sig_map::Dict{Symbol, Oxygen.Core.Types.Param}}, pathparams::Vector{Symbol}, queryparams::Vector{Symbol}}, Oxygen.Core.Handlers.var"#14#16"{Oxygen.Core.Handlers.var"#14#15#17"{Oxygen.Core.Handlers.var"#5#11"}}})(req::HTTP.Messages.Request)
│        @ Oxygen.Core ~/.julia/packages/Oxygen/LWjgB/src/core.jl:577
│     [16] (::HTTP.Handlers.Router{typeof(HTTP.Handlers.default404), typeof(HTTP.Handlers.default405), Nothing})(req::HTTP.Messages.Request)
│        @ HTTP.Handlers ~/.julia/packages/HTTP/sJD5V/src/Handlers.jl:439
│     [17] (::Oxygen.Core.var"#35#38"{HTTP.Messages.Request, HTTP.Handlers.Router{typeof(HTTP.Handlers.default404), typeof(HTTP.Handlers.default405), Nothing}})()
│        @ Oxygen.Core ~/.julia/packages/Oxygen/LWjgB/src/core.jl:347
│     [18] handlerequest(getresponse::Oxygen.Core.var"#35#38"{HTTP.Messages.Request, HTTP.Handlers.Router{typeof(HTTP.Handlers.default404), typeof(HTTP.Handlers.default405), Nothing}}, catch_errors::Bool; show_errors::Bool)
│        @ Oxygen.Core.Util ~/.julia/packages/Oxygen/LWjgB/src/utilities/misc.jl:37
│     [19] handlerequest
│        @ ~/.julia/packages/Oxygen/LWjgB/src/utilities/misc.jl:32 [inlined]
│     [20] #34
│        @ ~/.julia/packages/Oxygen/LWjgB/src/core.jl:346 [inlined]
│     [21] #41
│        @ ~/.julia/packages/Oxygen/LWjgB/src/core.jl:361 [inlined]
│     [22] handlerequest(getresponse::Oxygen.Core.var"#41#45"{HTTP.Messages.Request, Oxygen.Core.var"#34#37"{HTTP.Handlers.Router{typeof(HTTP.Handlers.default404), typeof(HTTP.Handlers.default405), Nothing}, Bool, Bool}, Oxygen.Core.AppContext.Service}, catch_errors::Bool; show_errors::Bool)
│        @ Oxygen.Core.Util ~/.julia/packages/Oxygen/LWjgB/src/utilities/misc.jl:37
│     [23] handlerequest
│        @ ~/.julia/packages/Oxygen/LWjgB/src/utilities/misc.jl:32 [inlined]
│     [24] #40
│        @ ~/.julia/packages/Oxygen/LWjgB/src/core.jl:358 [inlined]
│     [25] (::Oxygen.Core.var"#29#31"{Oxygen.Core.var"#40#44"{Oxygen.Core.var"#34#37"{HTTP.Handlers.Router{typeof(HTTP.Handlers.default404), typeof(HTTP.Handlers.default405), Nothing}, Bool, Bool}, Oxygen.Core.AppContext.Service, Bool}, HTTP.Handlers.Router{typeof(HTTP.Handlers.default404), typeof(HTTP.Handlers.default405), Nothing}, String})(req::HTTP.Messages.Request)
│        @ Oxygen.Core ~/.julia/packages/Oxygen/LWjgB/src/core.jl:331
│     [26] #12
│        @ ~/.julia/packages/Oxygen/LWjgB/src/core.jl:191 [inlined]
│     [27] (::HTTP.Handlers.var"#1#2"{Oxygen.Core.var"#12#14"{Oxygen.Core.var"#29#31"{Oxygen.Core.var"#40#44"{Oxygen.Core.var"#34#37"{HTTP.Handlers.Router{typeof(HTTP.Handlers.default404), typeof(HTTP.Handlers.default405), Nothing}, Bool, Bool}, Oxygen.Core.AppContext.Service, Bool}, HTTP.Handlers.Router{typeof(HTTP.Handlers.default404), typeof(HTTP.Handlers.default405), Nothing}, String}, Sockets.IPv4, HTTP.Streams.Stream{HTTP.Messages.Request, HTTP.Connections.Connection{Sockets.TCPSocket}}}})(stream::HTTP.Streams.Stream{HTTP.Messages.Request, HTTP.Connections.Connection{Sockets.TCPSocket}})
│        @ HTTP.Handlers ~/.julia/packages/HTTP/sJD5V/src/Handlers.jl:58
│     [28] #15
│        @ ~/.julia/packages/Oxygen/LWjgB/src/core.jl:208 [inlined]
│     [29] (::Oxygen.Core.var"#19#22"{HTTP.Streams.Stream{HTTP.Messages.Request, HTTP.Connections.Connection{Sockets.TCPSocket}}, Oxygen.Core.var"#15#16"{Oxygen.Core.var"#29#31"{Oxygen.Core.var"#40#44"{Oxygen.Core.var"#34#37"{HTTP.Handlers.Router{typeof(HTTP.Handlers.default404), typeof(HTTP.Handlers.default405), Nothing}, Bool, Bool}, Oxygen.Core.AppContext.Service, Bool}, HTTP.Handlers.Router{typeof(HTTP.Handlers.default404), typeof(HTTP.Handlers.default405), Nothing}, String}}})()
│        @ Oxygen.Core ~/.julia/packages/Oxygen/LWjgB/src/core.jl:222
└ @ Oxygen.Core.Util ~/.julia/packages/Oxygen/LWjgB/src/utilities/misc.jl:40
mwdchang commented 1 month ago

Looking a the AMR, there is something odd-looking with the mathMLs:

  "properties": {},
  "semantics": {
    "ode": {
      "rates": [
        {
          "target": "t0",
          "expression": "I*S*β",
          "expression_mathml": "<apply><times/><ci>I</ci><ci>S</ci><ci>|&#946;|</ci></apply>"
        },
        {
          "target": "t1",
          "expression": "I*γ",
          "expression_mathml": "<apply><times/><ci>I</ci><ci>|&#947;|</ci></apply>"
        },
        {
          "target": "Natural conversion2",
...

Note |&#946;| and |&#947;| in place of beta and gamma respectively, it seems like somewhere they became the reference codes. Not sure where it went bad though, could be a MIRA bug or we may have a weird escape/unescape things going on.