World age problem from a package

Hi,
I’m having a world age problem in a very weird way, or at least weird enough that I can’t see the similarities with other examples.
I have a file simulationFns.jl that defines a few functions such as:

using LiiBRA
function sim_degradation!(args...)
 # bunch of things that work
end

function simulate_storage!(args...)
   # unpacking the data and so on 
   # initialization and data extraction as in the example from LiiBRA
    SList = collect(1.0:-0.1:0) # List of SOC points for model generation
    SoC0 = 0.8; # Starting SOC
    Sₑ = 4 # Spatial points in electrolyte
    Sₛ = 2 # Spatial point in solid
    Base.invokelatest(LiiBRA.Spatial!, Cell, Sₑ, Sₛ) <-- this works
    A, B, C, D = LiiBRA.Realise(Cell, SList) <--- error here
   # rest of the function
end

function simTransitionFun(args...)
  # first, a bunch of things that work
  # here we call the prev defined function
  simulate_storage!(args...)
  return println("foo")
end

then in a script file I’m doing

using Revise
includet(".../simulationFns.jl")
## load a bunch of data to use the functions
# First try
simulate_storage_asset!(args...) # <--- works pass by the LiiBRA.Realise() line
# Second try
simTransitionFun!(args...) # <--- crashes in the LiiBRA.Realise() line

Full stacktrace

LoadError: MethodError: no method matching (::LiiBRA.var"#308#312")(::Int64, ::Int64)
The applicable method may be too new: running in world age 32311, while current world is 32430.

Closest candidates are:
  (::LiiBRA.var"#308#312")(::Any, ::Any) (method too new to be called from this world context.)
   @ LiiBRA C:\Users\user\.julia\packages\LiiBRA\DNSWZ\src\Data\Chen_2020\LG_M50.jl:160

Stacktrace:
   [1] Realise(Cell::LiiBRA.Params, SList::Vector{Float64})
    @ LiiBRA C:\Users\user\.julia\packages\LiiBRA\DNSWZ\src\Functions\LiiBRA.jl:31
  [2] simulate_storage_asset!(stgAsset::BESSData, results::Dict{String, Any}, key::String)
    @ Main c:\Users\user\OneDrive folder\simulationFuns.jl:128
  [3] simTransitionFun!(results::Dict{String, Any}, data::Dict{String, Any}, s::modelSettings; typeOpt::String)
    @ Main c:\Users\user\OneDrive folder\simulationFuns.jl:227
  [4] top-level scope
    @ c:\Users\user\OneDrive folder\dbgTest1.jl:43
  [5] eval
    @ .\boot.jl:385 [inlined]
  [6] include_string(mapexpr::typeof(REPL.softscope), mod::Module, code::String, filename::String)
    @ Base .\loading.jl:2070
  [7] invokelatest(::Any, ::Any, ::Vararg{Any}; kwargs::@Kwargs{})
    @ Base .\essentials.jl:887
  [8] invokelatest(::Any, ::Any, ::Vararg{Any})
    @ Base .\essentials.jl:884
  [9] inlineeval(m::Module, code::String, code_line::Int64, code_column::Int64, file::String; softscope::Bool)
    @ VSCodeServer c:\Users\user\.vscode\extensions\julialang.language-julia-1.66.2\scripts\packages\VSCodeServer\src\eval.jl:263 
 [10] (::VSCodeServer.var"#67#72"{Bool, Bool, Bool, Module, String, Int64, Int64, String, VSCodeServer.ReplRunCodeRequestParams})()
    @ VSCodeServer c:\Users\user\.vscode\extensions\julialang.language-julia-1.66.2\scripts\packages\VSCodeServer\src\eval.jl:181 
 [11] withpath(f::VSCodeServer.var"#67#72"{Bool, Bool, Bool, Module, String, Int64, Int64, String, VSCodeServer.ReplRunCodeRequestParams}, path::String)
    @ VSCodeServer c:\Users\user\.vscode\extensions\julialang.language-julia-1.66.2\scripts\packages\VSCodeServer\src\repl.jl:274 
 [12] (::VSCodeServer.var"#66#71"{Bool, Bool, Bool, Module, String, Int64, Int64, String, VSCodeServer.ReplRunCodeRequestParams})()      
    @ VSCodeServer c:\Users\user\.vscode\extensions\julialang.language-julia-1.66.2\scripts\packages\VSCodeServer\src\eval.jl:179 
 [13] hideprompt(f::VSCodeServer.var"#66#71"{Bool, Bool, Bool, Module, String, Int64, Int64, String, VSCodeServer.ReplRunCodeRequestParams})
    @ VSCodeServer c:\Users\user\.vscode\extensions\julialang.language-julia-1.66.2\scripts\packages\VSCodeServer\src\repl.jl:38  
 [14] (::VSCodeServer.var"#65#70"{Bool, Bool, Bool, Module, String, Int64, Int64, String, VSCodeServer.ReplRunCodeRequestParams})()      
    @ VSCodeServer c:\Users\user\.vscode\extensions\julialang.language-julia-1.66.2\scripts\packages\VSCodeServer\src\eval.jl:150 
 [15] with_logstate(f::Function, logstate::Any)
    @ Base.CoreLogging .\logging.jl:515
 [16] with_logger
    @ .\logging.jl:627 [inlined]
 [17] (::VSCodeServer.var"#64#69"{VSCodeServer.ReplRunCodeRequestParams})()
    @ VSCodeServer c:\Users\user\.vscode\extensions\julialang.language-julia-1.66.2\scripts\packages\VSCodeServer\src\eval.jl:255 
 [18] #invokelatest#2
    @ Base .\essentials.jl:887 [inlined]
 [19] invokelatest(::Any)
    @ Base .\essentials.jl:884
 [20] (::VSCodeServer.var"#62#63")()
    @ VSCodeServer c:\Users\user\.vscode\extensions\julialang.language-julia-1.66.2\scripts\packages\VSCodeServer\src\eval.jl:34  
in expression starting at c:\Users\user\OneDrive folder\dbgTest1.jl:43

What is going on, then? Why can’t I use functions from a package layered in 2 functions?
Why can I call any function from LiiBRA.jl in the REPL but I can’t use them like this?
This has never happened to me before with any other packages.

Can you post the full error stack-trace that gets output when the issue occurs?

Have you tried running this script without Revise.jl? My understanding is that Revise is primarily intended for REPL usage to enable things like structs to be re-defined on the fly, but this shouldn’t be necessary for a script and probably complicates reasoning about the actual issue.

1 Like

yeah sure.
I’ve edited the original post to add the stacktrace.
here’s the error without Revise.jl

LoadError: MethodError: no method matching (::LiiBRA.var"#154#158")(::Int64, ::Int64)
The applicable method may be too new: running in world age 32028, while current world is 32147.

Closest candidates are:
  (::LiiBRA.var"#154#158")(::Any, ::Any) (method too new to be called from this world context.)
   @ LiiBRA C:\Users\user\.julia\packages\LiiBRA\DNSWZ\src\Data\Chen_2020\LG_M50.jl:160

Stacktrace:
  [1] Realise(Cell::LiiBRA.Params, SList::Vector{Float64})
    @ LiiBRA C:\Users\user\.julia\packages\LiiBRA\DNSWZ\src\Functions\Simulate.jl:31
  [2] simulate_storage_asset!(stgAsset::BESSData, results::Dict{String, Any}, key::String)
    @ Main c:\Users\user\OneDrive folder\simulationFuns.jl:128
  [3] simTransitionFun!(results::Dict{String, Any}, data::Dict{String, Any}, s::modelSettings; typeOpt::String)
    @ Main c:\Users\user\OneDrive folder\simEMS.jl:227
  [4] top-level scope
    @ c:\Users\user\OneDrive folder\dbgTest1.jl:46
  [5] eval
    @ .\boot.jl:385 [inlined]
  [6] include_string(mapexpr::typeof(REPL.softscope), mod::Module, code::String, filename::String)
    @ Base .\loading.jl:2070
  [7] invokelatest(::Any, ::Any, ::Vararg{Any}; kwargs::@Kwargs{})
    @ Base .\essentials.jl:887
  [8] invokelatest(::Any, ::Any, ::Vararg{Any})
    @ Base .\essentials.jl:884
  [9] inlineeval(m::Module, code::String, code_line::Int64, code_column::Int64, file::String; softscope::Bool)
    @ VSCodeServer c:\Users\user\.vscode\extensions\julialang.language-julia-1.66.2\scripts\packages\VSCodeServer\src\eval.jl:263 
 [10] (::VSCodeServer.var"#67#72"{Bool, Bool, Bool, Module, String, Int64, Int64, String, VSCodeServer.ReplRunCodeRequestParams})()
    @ VSCodeServer c:\Users\user\.vscode\extensions\julialang.language-julia-1.66.2\scripts\packages\VSCodeServer\src\eval.jl:181 
 [11] withpath(f::VSCodeServer.var"#67#72"{Bool, Bool, Bool, Module, String, Int64, Int64, String, VSCodeServer.ReplRunCodeRequestParams}, path::String)
    @ VSCodeServer c:\Users\user\.vscode\extensions\julialang.language-julia-1.66.2\scripts\packages\VSCodeServer\src\repl.jl:274 
 [12] (::VSCodeServer.var"#66#71"{Bool, Bool, Bool, Module, String, Int64, Int64, String, VSCodeServer.ReplRunCodeRequestParams})()      
    @ VSCodeServer c:\Users\user\.vscode\extensions\julialang.language-julia-1.66.2\scripts\packages\VSCodeServer\src\eval.jl:179 
 [13] hideprompt(f::VSCodeServer.var"#66#71"{Bool, Bool, Bool, Module, String, Int64, Int64, String, VSCodeServer.ReplRunCodeRequestParams})
    @ VSCodeServer c:\Users\user\.vscode\extensions\julialang.language-julia-1.66.2\scripts\packages\VSCodeServer\src\repl.jl:38  
 [14] (::VSCodeServer.var"#65#70"{Bool, Bool, Bool, Module, String, Int64, Int64, String, VSCodeServer.ReplRunCodeRequestParams})()      
    @ VSCodeServer c:\Users\user\.vscode\extensions\julialang.language-julia-1.66.2\scripts\packages\VSCodeServer\src\eval.jl:150 
 [15] with_logstate(f::Function, logstate::Any)
    @ Base.CoreLogging .\logging.jl:515
 [16] with_logger
    @ .\logging.jl:627 [inlined]
 [17] (::VSCodeServer.var"#64#69"{VSCodeServer.ReplRunCodeRequestParams})()
    @ VSCodeServer c:\Users\user\.vscode\extensions\julialang.language-julia-1.66.2\scripts\packages\VSCodeServer\src\eval.jl:255 
 [18] #invokelatest#2
    @ Base .\essentials.jl:887 [inlined]
 [19] invokelatest(::Any)
    @ Base .\essentials.jl:884
 [20] (::VSCodeServer.var"#62#63")()
    @ VSCodeServer c:\Users\user\.vscode\extensions\julialang.language-julia-1.66.2\scripts\packages\VSCodeServer\src\eval.jl:34  
in expression starting at c:\Users\user\OneDrive folder\dbgTest1.jl:46

Is that run from within VS Code? It seems to dominate the stack trace and it’s not clear, at least to me, where the error actually spawned from. If possible, can you run direct from a command line like PowerShell, e.g. julia myscript.jl?

Also, it would help to know what versions of everything you’re running. What does versioninfo() inside of Julia report? What does ] status report (status call from within Pkg mode)?

1 Like

Also try with the --startup-file=no option, julia --startup-file=no myscript.jl.

1 Like

Is it necessary to use Base.invokelatest in the code?

1 Like

It is, otherwise I get the same error but calling that function. I also put it to show that it works but it is not the desired behaviour.

Yes, it is from VS Code.
here’s the versioninfo()

julia> versioninfo()
Julia Version 1.10.0
Commit 3120989f39 (2023-12-25 18:01 UTC)
Build Info:
  Official https://julialang.org/ release
Platform Info:
  OS: Windows (x86_64-w64-mingw32)
  CPU: 8 × 11th Gen Intel(R) Core(TM) i7-1185G7 @ 3.00GHz
  WORD_SIZE: 64
  LIBM: libopenlibm
  LLVM: libLLVM-15.0.7 (ORCJIT, tigerlake)
  Threads: 5 on 8 virtual cores
Environment:
  JULIA_NUM_THREADS = 4
  JULIA_EDITOR = code

and my env. packages

(projEnv) pkg> status
Status `C:\Users\user\OneDrive - folder\Project.toml`
  [336ed68f] CSV v0.10.12
  [13f3f980] CairoMakie v0.11.5
  [35d6a980] ColorSchemes v3.24.0
  [a93c6f00] DataFrames v1.6.1
  [31c24e10] Distributions v0.25.107
  [e9467ef8] GLMakie v0.9.5
  [cc18c42c] GaussianMixtures v0.3.8
  [87dc4568] HiGHS v1.7.5
  [20393b10] InfiniteOpt v0.5.8
⌅ [a98d9a8b] Interpolations v0.14.7
  [b6b21f68] Ipopt v1.6.0
  [c8e1da08] IterTools v1.10.0
  [0f8b85d8] JSON3 v1.14.0
  [4076af6c] JuMP v1.18.1
  [67920dd8] KNITRO v0.14.1
  [b964fa9f] LaTeXStrings v1.3.1
  [a5b28938] LiiBRA v0.3.4
  [23992714] MAT v0.10.6
  [ee78f7c6] Makie v0.20.4
  [b8f27783] MathOptInterface v1.25.1
  [01bcebdf] Nonconvex v2.1.3
  [bf347577] NonconvexIpopt v0.4.2
  [b43a31b8] NonconvexNLopt v0.1.8
  [d96e819e] Parameters v0.12.3
  [ccf2f8ad] PlotThemes v3.1.0
  [995b91a9] PlotUtils v1.4.0
  [f0f68f2c] PlotlyJS v0.18.12
  [91a5bcdd] Plots v1.39.0
  [c46f51b8] ProfileView v1.7.2
  [295af30f] Revise v3.5.13
  [99342f36] StateSpaceModels v0.6.7
⌅ [2913bbd2] StatsBase v0.33.21
  [f3b207a7] StatsPlots v0.15.6
  [9e3dc215] TimeSeries v0.24.1
  [fdbf4ff8] XLSX v0.10.1
  [37e2e46d] LinearAlgebra
  [9a3f8284] Random
  [10745b16] Statistics v1.10.0
Info Packages marked with ⌅ have new versions available but compatibility constraints restrict them from upgrading. To see why use `status --outdated`

I tried running the file from PowerShell but I don’t seem to have my project’s env activated. So when I call using Revise for example its telling me that it is not installed, that I had to run Pkg.add(Revise)
do you know how to do that?

In PowerShell you can cd to the directory where your environment information is stored, then julia —project=. will use that one by default.

Again, I’m not sure there’s any actual intended usage here of Revise when running a script (vs experimenting in a REPL) so if you could leave that package out of your example it would significantly reduce some of the complexity involved and answer whether Revise is at least contributing to this issue.

Edit: Also, I’d reiterate the suggestion above to disable the startup file option, so you’d really want to run something like julia --startup-file=no --project=. myscript.jl from within the project directory.

2 Likes

Nono, that for sure Revise.jl is for my own taste, so I’m not restarting the julia REPL everytime I make a change in a function definition while working on VS Code.
Thanks for the help on the powershell run, here’s is the stacktrace there:

PS C:\Users\user\OneDrive folder> julia --startup-file=no --project=. .\src\dbgTest1.jl
ERROR: LoadError: MethodError: no method matching (::LiiBRA.var"#89#101")(::Float64)
The applicable method may be too new: running in world age 32061, while current world is 32180.

Closest candidates are:
  (::LiiBRA.var"#89#101")(::Any) (method too new to be called from this world context.)
   @ LiiBRA C:\Users\user\.julia\packages\LiiBRA\DNSWZ\src\Data\Chen_2020\LG_M50.jl:20

Stacktrace:
 [1] Realise(Cell::LiiBRA.Params, Ŝ::Vector{Float64})
   @ LiiBRA C:\Users\user\.julia\packages\LiiBRA\DNSWZ\src\LiiBRA.jl:31
 [2] simulate_storage_asset!(stgAsset::BESSData, results::Dict{String, Any}, key::String)
   @ Main C:\Users\user\OneDrive folder\functions\simulationFns.jl:123
 [3] simTransitionFun!(results::Dict{String, Any}, data::Dict{String, Any}, s::modelSettings; typeOpt::String)
   @ Main C:\Users\user\OneDrive folder\simulationFns.jl:228
 [4] top-level scope
   @ C:\Users\user\OneDrive folder\src\dbgTest1.jl:42

This line doesn’t look right to me:

Generally include should be at top-level, not inside a function. I believe this could cause the world-age errors you are seeing.

2 Likes

That seems like a bizarre architectural choice. I looked up what’s contained in those files for context and, e.g., LiiBRA.jl/Data/Doyle_94/Doyle_94.jl mostly just contains a bunch of data structure definitions. Why not just define them all in the first place and then generate instances as required?