Skip to content

Serialization of ODEProblemExpr based models broke in 5.7 #841

@andreasnoack

Description

@andreasnoack

The code below works in version 5.6 but not in 5.7 (and more recent versions).

using ModelingToolkit, SciMLBase, Serialization

@parameters t
@variables x(t)
D = Differential(t)

sys = ODESystem([D(x) ~ -0.5*x])
prob = eval(ModelingToolkit.ODEProblemExpr{false}(sys, nothing, nothing, SciMLBase.NullParameters()))

_fn = tempname()

open(_fn, "w") do f
    serialize(f, prob)
end

_cmd = "using ModelingToolkit, Serialization; deserialize(\"$_fn\")"

run(`$(Base.julia_cmd()) -e $(_cmd)`)

The failure is

ERROR: UndefVarError: ###f#261 not defined
Stacktrace:
  [1] deserialize_datatype(s::Serializer{IOStream}, full::Bool)
    @ Serialization ~/julia/usr/share/julia/stdlib/v1.6/Serialization/src/Serialization.jl:1278
...

which is the type of the ODE closure

julia> typeof(prob.f.f)
var"###f#261"

Notice that if I construct the problem via the ODEProblem constructor then I don't get the error and the closure type is different

julia> typeof(prob.f.f)
ModelingToolkit.var"#f#251"{RuntimeGeneratedFunctions.RuntimeGeneratedFunction{(Symbol("##arg#273"), Symbol("##arg#274"), :t), ModelingToolkit.var"#_RGF_ModTag", ModelingToolkit.var"#_RGF_ModTag", (0xcfab6c31, 0x4234d024, 0xc8d24f26, 0x00e8741b, 0xdef727f3)}, RuntimeGeneratedFunctions.RuntimeGeneratedFunction{(Symbol("##out#275"), Symbol("##arg#273"), Symbol("##arg#274"), :t), ModelingToolkit.var"#_RGF_ModTag", ModelingToolkit.var"#_RGF_ModTag", (0x1649a627, 0x3083de65, 0x3aff2680, 0x103a1319, 0xebfbfbe8)}}

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions