I’m sorry - I’ve only just realised that you explicitly requested the error message and stack trace. I have reduced the sample code to the following:
module SD
using DynamicalSystems
function demo()
builder = eval(Expr(:(->),:(p,u),:(+(p[1] * u[1]))))
dynamical_rule! = function (du,u,p,t)
du[1] = Float64(eval(builder(p,u)))
nothing
end
CoupledODEs(dynamical_rule!, [2.0], [0.3])
end
end
Calling SD.demo()
leads to an error message whose essence is: The applicable method may be too new: running in world age 33731, while current world is 33732.
(I list the entire stack trace below)
I now understand the reasons for this error in terms of julia ensuring type stability of dynamical_rule!
, however I’m starting to suspect that solving this problem is impossible, since it would presumably involve DynamicalSystems internally calling dynamical_rule!
using invokelatest()
, which would then hugely impact performance.
So my final question is: Is there any way at all of constructing an anonymous function at runtime which can then be passed as a dynamical rule to DynamicalSystems? I realise that one fix is to pull the first line of demo()
(the definition of builder
) out into the module’s global scope, but I don’t see that as viable in the context of dynamically parsing users’ function specifications.
The complete trace from the call to SD.demo()
is:
ERROR: MethodError: no method matching (::Main.SD.var"#3#4")(::Vector{Float64}, ::Vector{Float64})
The applicable method may be too new: running in world age 33731, while current world is 33732.
Closest candidates are:
(::Main.SD.var"#3#4")(::Any, ::Any) (method too new to be called from this world context.)
@ Main.SD none:0
Stacktrace:
[1] (::Main.SD.var"#1#2"{Main.SD.var"#3#4"})(du::Vector{Float64}, u::Vector{Float64}, p::Vector{Float64}, t::Float64)
@ Main.SD c:\Users\hswt136nia\OneDrive\Documents\Rock Dene Cottage\Courses\LEAP\Projects\Anatta\src\Development\SD\SD.jl:9
[2] (::SciMLBase.ODEFunction{true, SciMLBase.AutoSpecialize, Main.SD.var"#1#2"{Main.SD.var"#3#4"}, LinearAlgebra.UniformScaling{Bool}, Nothing, Nothing, Nothing, Nothing, Nothing, Nothing, Nothing, Nothing, Nothing, Nothing, Nothing, Nothing, Nothing, Nothing, typeof(SciMLBase.DEFAULT_OBSERVED), Nothing, Nothing})(::Vector{Float64}, ::Vararg{Any})
@ SciMLBase C:\Users\hswt136nia\.julia\packages\SciMLBase\eK30d\src\scimlfunctions.jl:2407
[3] initialize!(integrator::OrdinaryDiffEq.ODEIntegrator{OrdinaryDiffEq.Tsit5{typeof(OrdinaryDiffEq.trivial_limiter!), typeof(OrdinaryDiffEq.trivial_limiter!), Static.False}, true, Vector{Float64}, Nothing, Float64, Vector{Float64}, Float64, Float64, Float64, Float64, Vector{Vector{Float64}}, SciMLBase.ODESolution{Float64, 2, Vector{Vector{Float64}}, Nothing, Nothing, Vector{Float64}, Vector{Vector{Vector{Float64}}},
SciMLBase.ODEProblem{Vector{Float64}, Tuple{Float64, Float64}, true, Vector{Float64}, SciMLBase.ODEFunction{true, SciMLBase.AutoSpecialize, Main.SD.var"#1#2"{Main.SD.var"#3#4"}, LinearAlgebra.UniformScaling{Bool}, Nothing, Nothing, Nothing, Nothing, Nothing, Nothing, Nothing, Nothing, Nothing, Nothing, Nothing, Nothing, Nothing, Nothing, typeof(SciMLBase.DEFAULT_OBSERVED), Nothing, Nothing}, Base.Pairs{Symbol, Union{},
Tuple{}, NamedTuple{(), Tuple{}}}, SciMLBase.StandardODEProblem}, OrdinaryDiffEq.Tsit5{typeof(OrdinaryDiffEq.trivial_limiter!), typeof(OrdinaryDiffEq.trivial_limiter!), Static.False}, OrdinaryDiffEq.InterpolationData{SciMLBase.ODEFunction{true, SciMLBase.AutoSpecialize, Main.SD.var"#1#2"{Main.SD.var"#3#4"}, LinearAlgebra.UniformScaling{Bool}, Nothing, Nothing, Nothing, Nothing, Nothing, Nothing, Nothing, Nothing, Nothing, Nothing, Nothing, Nothing, Nothing, Nothing, typeof(SciMLBase.DEFAULT_OBSERVED), Nothing, Nothing}, Vector{Vector{Float64}}, Vector{Float64}, Vector{Vector{Vector{Float64}}}, OrdinaryDiffEq.Tsit5Cache{Vector{Float64}, Vector{Float64}, Vector{Float64}, typeof(OrdinaryDiffEq.trivial_limiter!), typeof(OrdinaryDiffEq.trivial_limiter!), Static.False}}, SciMLBase.DEStats, Nothing}, SciMLBase.ODEFunction{true, SciMLBase.AutoSpecialize, Main.SD.var"#1#2"{Main.SD.var"#3#4"}, LinearAlgebra.UniformScaling{Bool}, Nothing, Nothing, Nothing, Nothing, Nothing, Nothing,
Nothing, Nothing, Nothing, Nothing, Nothing, Nothing, Nothing, Nothing, typeof(SciMLBase.DEFAULT_OBSERVED), Nothing, Nothing}, OrdinaryDiffEq.Tsit5Cache{Vector{Float64}, Vector{Float64}, Vector{Float64}, typeof(OrdinaryDiffEq.trivial_limiter!), typeof(OrdinaryDiffEq.trivial_limiter!), Static.False}, OrdinaryDiffEq.DEOptions{Float64, Float64, Float64, Float64, OrdinaryDiffEq.PIController{Rational{Int64}}, typeof(DiffEqBase.ODE_DEFAULT_NORM), typeof(LinearAlgebra.opnorm), Bool, SciMLBase.CallbackSet{Tuple{}, Tuple{}}, typeof(DiffEqBase.ODE_DEFAULT_ISOUTOFDOMAIN), typeof(DiffEqBase.ODE_DEFAULT_PROG_MESSAGE), typeof(DiffEqBase.ODE_DEFAULT_UNSTABLE_CHECK), DataStructures.BinaryHeap{Float64, DataStructures.FasterForward}, DataStructures.BinaryHeap{Float64, DataStructures.FasterForward}, Nothing, Nothing, Float64, Tuple{}, Tuple{}, Tuple{}}, Vector{Float64}, Float64, Nothing, OrdinaryDiffEq.DefaultInit}, cache::OrdinaryDiffEq.Tsit5Cache{Vector{Float64}, Vector{Float64}, Vector{Float64}, typeof(OrdinaryDiffEq.trivial_limiter!), typeof(OrdinaryDiffEq.trivial_limiter!), Static.False})
@ OrdinaryDiffEq C:\Users\hswt136nia\.julia\packages\OrdinaryDiffEq\JJd6g\src\perform_step\low_order_rk_perform_step.jl:792
[4] __init(prob::SciMLBase.ODEProblem{Vector{Float64}, Tuple{Float64, Float64}, true, Vector{Float64}, SciMLBase.ODEFunction{true, SciMLBase.AutoSpecialize, Main.SD.var"#1#2"{Main.SD.var"#3#4"}, LinearAlgebra.UniformScaling{Bool}, Nothing, Nothing, Nothing, Nothing, Nothing, Nothing, Nothing, Nothing, Nothing, Nothing, Nothing, Nothing, Nothing, Nothing, typeof(SciMLBase.DEFAULT_OBSERVED), Nothing, Nothing}, Base.Pairs{Symbol, Union{}, Tuple{}, NamedTuple{(), Tuple{}}}, SciMLBase.StandardODEProblem}, alg::OrdinaryDiffEq.Tsit5{typeof(OrdinaryDiffEq.trivial_limiter!), typeof(OrdinaryDiffEq.trivial_limiter!), Static.False}, timeseries_init::Tuple{}, ts_init::Tuple{}, ks_init::Tuple{}, recompile::Type{Val{true}}; saveat::Tuple{}, tstops::Tuple{}, d_discontinuities::Tuple{}, save_idxs::Nothing, save_everystep::Bool, save_on::Bool, save_start::Bool, save_end::Bool, callback::Nothing, dense::Bool, calck::Bool, dt::Float64, dtmin::Nothing, dtmax::Float64, force_dtmin::Bool, adaptive::Bool, gamma::Rational{Int64}, abstol::Float64, reltol::Float64, qmin::Rational{Int64}, qmax::Int64, qsteady_min::Int64, qsteady_max::Int64, beta1::Nothing, beta2::Nothing, qoldinit::Rational{Int64}, controller::Nothing, fullnormalize::Bool, failfactor::Int64, maxiters::Float64, internalnorm::typeof(DiffEqBase.ODE_DEFAULT_NORM), internalopnorm::typeof(LinearAlgebra.opnorm), isoutofdomain::typeof(DiffEqBase.ODE_DEFAULT_ISOUTOFDOMAIN), unstable_check::typeof(DiffEqBase.ODE_DEFAULT_UNSTABLE_CHECK), verbose::Bool, timeseries_errors::Bool, dense_errors::Bool, advance_to_tstop::Bool, stop_at_next_tstop::Bool, initialize_save::Bool, progress::Bool, progress_steps::Int64, progress_name::String, progress_message::typeof(DiffEqBase.ODE_DEFAULT_PROG_MESSAGE), progress_id::Symbol, userdata::Nothing, allow_extrapolation::Bool, initialize_integrator::Bool, alias_u0::Bool, alias_du0::Bool, initializealg::OrdinaryDiffEq.DefaultInit, kwargs::Base.Pairs{Symbol, Union{}, Tuple{}, NamedTuple{(), Tuple{}}})
@ OrdinaryDiffEq C:\Users\hswt136nia\.julia\packages\OrdinaryDiffEq\JJd6g\src\solve.jl:502
[5] __init (repeats 4 times)
@ C:\Users\hswt136nia\.julia\packages\OrdinaryDiffEq\JJd6g\src\solve.jl:10 [inlined]
[6] DynamicalSystemsBase.CoupledODEs(prob::SciMLBase.ODEProblem{Vector{Float64}, Tuple{Float64, Float64}, true, Vector{Float64}, SciMLBase.ODEFunction{true, SciMLBase.AutoSpecialize, Main.SD.var"#1#2"{Main.SD.var"#3#4"}, LinearAlgebra.UniformScaling{Bool}, Nothing, Nothing, Nothing, Nothing, Nothing, Nothing, Nothing, Nothing, Nothing, Nothing, Nothing, Nothing, Nothing, Nothing, typeof(SciMLBase.DEFAULT_OBSERVED), Nothing, Nothing}, Base.Pairs{Symbol, Union{}, Tuple{}, NamedTuple{(), Tuple{}}}, SciMLBase.StandardODEProblem}, diffeq::NamedTuple{(:alg, :abstol, :reltol), Tuple{OrdinaryDiffEq.Tsit5{typeof(OrdinaryDiffEq.trivial_limiter!), typeof(OrdinaryDiffEq.trivial_limiter!), Static.False}, Float64, Float64}}; special_kwargs::Base.Pairs{Symbol, Union{}, Tuple{}, NamedTuple{(), Tuple{}}})
@ DynamicalSystemsBase C:\Users\hswt136nia\.julia\packages\DynamicalSystemsBase\Dx8Dp\src\core_systems\continuous_time_ode.jl:93
[7] DynamicalSystemsBase.CoupledODEs(prob::SciMLBase.ODEProblem{Vector{Float64}, Tuple{Float64, Float64}, true, Vector{Float64}, SciMLBase.ODEFunction{true, SciMLBase.AutoSpecialize, Main.SD.var"#1#2"{Main.SD.var"#3#4"}, LinearAlgebra.UniformScaling{Bool}, Nothing, Nothing, Nothing, Nothing, Nothing, Nothing, Nothing, Nothing, Nothing, Nothing, Nothing, Nothing, Nothing, Nothing, typeof(SciMLBase.DEFAULT_OBSERVED), Nothing, Nothing}, Base.Pairs{Symbol, Union{}, Tuple{}, NamedTuple{(), Tuple{}}}, SciMLBase.StandardODEProblem}, diffeq::NamedTuple{(:alg, :abstol, :reltol), Tuple{OrdinaryDiffEq.Tsit5{typeof(OrdinaryDiffEq.trivial_limiter!), typeof(OrdinaryDiffEq.trivial_limiter!), Static.False}, Float64, Float64}})
@ DynamicalSystemsBase C:\Users\hswt136nia\.julia\packages\DynamicalSystemsBase\Dx8Dp\src\core_systems\continuous_time_ode.jl:88
[8] DynamicalSystemsBase.CoupledODEs(f::Function, u0::Vector{Float64}, p::Vector{Float64}; t0::Int64, diffeq::NamedTuple{(:alg, :abstol, :reltol), Tuple{OrdinaryDiffEq.Tsit5{typeof(OrdinaryDiffEq.trivial_limiter!), typeof(OrdinaryDiffEq.trivial_limiter!), Static.False}, Float64,
Float64}})
@ DynamicalSystemsBase C:\Users\hswt136nia\.julia\packages\DynamicalSystemsBase\Dx8Dp\src\core_systems\continuous_time_ode.jl:84
[9] CoupledODEs
@ C:\Users\hswt136nia\.julia\packages\DynamicalSystemsBase\Dx8Dp\src\core_systems\continuous_time_ode.jl:79 [inlined]
[10] demo()
@ Main.SD c:\Users\hswt136nia\OneDrive\Documents\Rock Dene Cottage\Courses\LEAP\Projects\Anatta\src\Development\SD\SD.jl:13
[11] top-level scope
@ REPL[1]:1