# World age problem from a package

**URL:** <https://discourse.julialang.org/t/world-age-problem-from-a-package/109104>\
**Category:** General Usage\
**Tags:** world\_age\
**Created:** [January 22, 2024, 3:39pm UTC](https://discourse.julialang.org/t/world-age-problem-from-a-package/109104 "2024-01-22T15:39:16Z")\
**Posts on this page:** 12\
**Page:** 1

<div class="post-metadata">

**Author:** ![daro.slai](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/daro.slai/32/48757_2.png) [@daro.slai](https://discourse.julialang.org/u/daro.slai)\
**Post date:** [January 22, 2024, 3:39pm UTC](https://discourse.julialang.org/t/world-age-problem-from-a-package/109104/1 "2024-01-22T15:39:16Z")

</div>

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:

```julia
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

```julia
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

```julia
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.

---

<div class="post-metadata">

**Author:** ![mike.ingold](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/mike.ingold/32/203749_2.png) [@mike.ingold](https://discourse.julialang.org/u/mike.ingold)\
**Post date:** [January 22, 2024, 3:51pm UTC](https://discourse.julialang.org/t/world-age-problem-from-a-package/109104/2 "2024-01-22T15:51:25Z")

</div>

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 `struct`s to be re-defined on the fly, but this shouldn’t be necessary for a script and probably complicates reasoning about the actual issue.

---

<div class="post-metadata">

**Author:** ![daro.slai](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/daro.slai/32/48757_2.png) [@daro.slai](https://discourse.julialang.org/u/daro.slai)\
**Post date:** [January 22, 2024, 4:11pm UTC](https://discourse.julialang.org/t/world-age-problem-from-a-package/109104/3 "2024-01-22T16:11:15Z")

</div>

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

```julia
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

```

---

<div class="post-metadata">

**Author:** ![mike.ingold](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/mike.ingold/32/203749_2.png) [@mike.ingold](https://discourse.julialang.org/u/mike.ingold)\
**Post date:** [January 22, 2024, 4:36pm UTC](https://discourse.julialang.org/t/world-age-problem-from-a-package/109104/4 "2024-01-22T16:36:14Z")

</div>

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)?

---

<div class="post-metadata">

**Author:** ![nsajko](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/nsajko/32/221187_2.png) [@nsajko](https://discourse.julialang.org/u/nsajko)\
**Post date:** [January 22, 2024, 5:08pm UTC](https://discourse.julialang.org/t/world-age-problem-from-a-package/109104/5 "2024-01-22T17:08:42Z")

</div>

> [@mike.ingold](#):
>
> `julia myscript.jl`

Also try with the [`--startup-file=no`](https://docs.julialang.org/en/v1/manual/command-line-interface) option, `julia --startup-file=no myscript.jl`.

---

<div class="post-metadata">

**Author:** ![mikkoku](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/mikkoku/32/16274_2.png) [@mikkoku](https://discourse.julialang.org/u/mikkoku)\
**Post date:** [January 22, 2024, 7:35pm UTC](https://discourse.julialang.org/t/world-age-problem-from-a-package/109104/6 "2024-01-22T19:35:07Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![daro.slai](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/daro.slai/32/48757_2.png) [@daro.slai](https://discourse.julialang.org/u/daro.slai)\
**Post date:** [January 23, 2024, 10:01am UTC](https://discourse.julialang.org/t/world-age-problem-from-a-package/109104/7 "2024-01-23T10:01:43Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![daro.slai](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/daro.slai/32/48757_2.png) [@daro.slai](https://discourse.julialang.org/u/daro.slai)\
**Post date:** [January 23, 2024, 12:19pm UTC](https://discourse.julialang.org/t/world-age-problem-from-a-package/109104/8 "2024-01-23T12:19:59Z")

</div>

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

```julia
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

```julia
(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?

---

<div class="post-metadata">

**Author:** ![mike.ingold](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/mike.ingold/32/203749_2.png) [@mike.ingold](https://discourse.julialang.org/u/mike.ingold)\
**Post date:** [January 23, 2024, 2:31pm UTC](https://discourse.julialang.org/t/world-age-problem-from-a-package/109104/9 "2024-01-23T14:31:50Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![daro.slai](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/daro.slai/32/48757_2.png) [@daro.slai](https://discourse.julialang.org/u/daro.slai)\
**Post date:** [January 23, 2024, 2:54pm UTC](https://discourse.julialang.org/t/world-age-problem-from-a-package/109104/10 "2024-01-23T14:54:14Z")

</div>

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:

```powershell
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

```

---

<div class="post-metadata">

**Author:** ![ericphanson](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/ericphanson/32/215186_2.png) [@ericphanson](https://discourse.julialang.org/u/ericphanson)\
**Post date:** [January 23, 2024, 2:58pm UTC](https://discourse.julialang.org/t/world-age-problem-from-a-package/109104/11 "2024-01-23T14:58:20Z")

</div>

This line doesn’t look right to me:

> <https://github.com/BradyPlanden/LiiBRA.jl/blob/7bad220b57f49ba95d1632c3a1160de50de311d5/src/LiiBRA.jl#L150>

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

---

<div class="post-metadata">

**Author:** ![mike.ingold](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/mike.ingold/32/203749_2.png) [@mike.ingold](https://discourse.julialang.org/u/mike.ingold)\
**Post date:** [January 23, 2024, 3:24pm UTC](https://discourse.julialang.org/t/world-age-problem-from-a-package/109104/12 "2024-01-23T15:24:54Z")

</div>

> [@ericphanson](#):
>
> This line doesn’t look right to me

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?
