Cannot precompile ReinforcementLearning

I am trying to run a project that uses ReinforcementLearning but cannot get it to precompile. The error message I get is:

ERROR: The following 1 direct dependency failed to precompile:

ReinforcementLearning [158674fc-8238-5cab-b5ba-03dfc80d1318]

Failed to precompile ReinforcementLearning [158674fc-8238-5cab-b5ba-03dfc80d1318] to "C:\\Users\\Me\\.julia\\compiled\\v1.10\\ReinforcementLearning\\jl_ED8E.tmp".
ERROR: LoadError: UndefVarError: `@layer` not defined
Stacktrace:
  [1] include(mod::Module, _path::String)
    @ Base .\Base.jl:495
  [2] include(x::String)
    @ ReinforcementLearningCore C:\Users\Me\.julia\packages\ReinforcementLearningCore\8dBkN\src\ReinforcementLearningCore.jl:1
  [3] top-level scope
    @ C:\Users\Me\.julia\packages\ReinforcementLearningCore\8dBkN\src\policies\agent\agent.jl:1
  [4] include(mod::Module, _path::String)
    @ Base .\Base.jl:495
  [5] include(x::String)
    @ ReinforcementLearningCore C:\Users\Me\.julia\packages\ReinforcementLearningCore\8dBkN\src\ReinforcementLearningCore.jl:1
  [6] top-level scope
    @ C:\Users\Me\.julia\packages\ReinforcementLearningCore\8dBkN\src\policies\policies.jl:1
  [7] include(mod::Module, _path::String)
    @ Base .\Base.jl:495
  [8] include(x::String)
    @ ReinforcementLearningCore C:\Users\Me\.julia\packages\ReinforcementLearningCore\8dBkN\src\ReinforcementLearningCore.jl:1
  [9] top-level scope
    @ C:\Users\Me\.julia\packages\ReinforcementLearningCore\8dBkN\src\ReinforcementLearningCore.jl:14
 [10] include
    @ .\Base.jl:495 [inlined]
 [11] include_package_for_output(pkg::Base.PkgId, input::String, depot_path::Vector{String}, dl_load_path::Vector{String}, load_path::Vector{String}, concrete_deps::Vector{Pair{Base.PkgId, UInt128}}, source::String)
    @ Base .\loading.jl:2222
 [12] top-level scope
    @ stdin:3
in expression starting at C:\Users\Me\.julia\packages\ReinforcementLearningCore\8dBkN\src\policies\agent\agent_base.jl:43
in expression starting at C:\Users\Me\.julia\packages\ReinforcementLearningCore\8dBkN\src\policies\agent\agent_base.jl:43
in expression starting at C:\Users\Me\.julia\packages\ReinforcementLearningCore\8dBkN\src\policies\agent\agent.jl:1
in expression starting at C:\Users\Me\.julia\packages\ReinforcementLearningCore\8dBkN\src\policies\policies.jl:1
in expression starting at C:\Users\Me\.julia\packages\ReinforcementLearningCore\8dBkN\src\ReinforcementLearningCore.jl:1
in expression starting at stdin:3
ERROR: LoadError: Failed to precompile ReinforcementLearningCore [de1b191a-4ae0-4afa-a27b-92d07f46b2d6] to "C:\\Users\\Me\\.julia\\compiled\\v1.10\\ReinforcementLearningCore\\jl_F2B8.tmp".
Stacktrace:
  [1] error(s::String)
    @ Base .\error.jl:35
  [2] compilecache(pkg::Base.PkgId, path::String, internal_stderr::IO, internal_stdout::IO, keep_loaded_modules::Bool)
    @ Base .\loading.jl:2468
  [3] compilecache
    @ .\loading.jl:2340 [inlined]
  [4] (::Base.var"#968#969"{Base.PkgId})()
    @ Base .\loading.jl:1974
  [5] mkpidlock(f::Base.var"#968#969"{Base.PkgId}, at::String, pid::Int32; kwopts::@Kwargs{stale_age::Int64, wait::Bool})
    @ FileWatching.Pidfile C:\Users\Me\AppData\Local\Programs\Julia-1.10.1\share\julia\stdlib\v1.10\FileWatching\src\pidfile.jl:93
  [6] #mkpidlock#6
    @ C:\Users\Me\AppData\Local\Programs\Julia-1.10.1\share\julia\stdlib\v1.10\FileWatching\src\pidfile.jl:88 [inlined]
  [7] trymkpidlock(::Function, ::Vararg{Any}; kwargs::@Kwargs{stale_age::Int64})
    @ FileWatching.Pidfile C:\Users\Me\AppData\Local\Programs\Julia-1.10.1\share\julia\stdlib\v1.10\FileWatching\src\pidfile.jl:111
  [8] #invokelatest#2
    @ .\essentials.jl:894 [inlined]
  [9] invokelatest
    @ .\essentials.jl:889 [inlined]
 [10] maybe_cachefile_lock(f::Base.var"#968#969"{Base.PkgId}, pkg::Base.PkgId, srcpath::String; stale_age::Int64)
    @ Base .\loading.jl:2983
 [11] maybe_cachefile_lock
    @ .\loading.jl:2980 [inlined]
 [12] _require(pkg::Base.PkgId, env::String)
    @ Base .\loading.jl:1970
 [13] __require_prelocked(uuidkey::Base.PkgId, env::String)
    @ Base .\loading.jl:1812
 [14] #invoke_in_world#3
    @ .\essentials.jl:926 [inlined]
 [15] invoke_in_world
    @ .\essentials.jl:923 [inlined]
 [16] _require_prelocked(uuidkey::Base.PkgId, env::String)
    @ Base .\loading.jl:1803
 [17] macro expansion
    @ .\loading.jl:1790 [inlined]
 [18] macro expansion
    @ .\lock.jl:267 [inlined]
 [19] __require(into::Module, mod::Symbol)
    @ Base .\loading.jl:1753
 [20] #invoke_in_world#3
    @ .\essentials.jl:926 [inlined]
 [21] invoke_in_world
    @ .\essentials.jl:923 [inlined]
 [22] require(into::Module, mod::Symbol)
    @ Base .\loading.jl:1746
 [23] include
    @ .\Base.jl:495 [inlined]
 [24] include_package_for_output(pkg::Base.PkgId, input::String, depot_path::Vector{String}, dl_load_path::Vector{String}, load_path::Vector{String}, concrete_deps::Vector{Pair{Base.PkgId, UInt128}}, source::Nothing)
    @ Base .\loading.jl:2222
 [25] top-level scope
    @ stdin:3
in expression starting at C:\Users\Me\.julia\packages\ReinforcementLearning\gDSex\src\ReinforcementLearning.jl:1
in expression starting at stdin:
Stacktrace:
  [1] pkgerror(msg::String)
    @ Pkg.Types C:\Users\Me\AppData\Local\Programs\Julia-1.10.1\share\julia\stdlib\v1.10\Pkg\src\Types.jl:70
  [2] precompile(ctx::Pkg.Types.Context, pkgs::Vector{…}; internal_call::Bool, strict::Bool, warn_loaded::Bool, already_instantiated::Bool, timing::Bool, 
_from_loading::Bool, kwargs::@Kwargs{…})
    @ Pkg.API C:\Users\Me\AppData\Local\Programs\Julia-1.10.1\share\julia\stdlib\v1.10\Pkg\src\API.jl:1659
  [3] precompile(pkgs::Vector{Pkg.Types.PackageSpec}; io::Base.TTY, kwargs::@Kwargs{_from_loading::Bool})
    @ Pkg.API C:\Users\Me\AppData\Local\Programs\Julia-1.10.1\share\julia\stdlib\v1.10\Pkg\src\API.jl:159
  [4] precompile
    @ C:\Users\Me\AppData\Local\Programs\Julia-1.10.1\share\julia\stdlib\v1.10\Pkg\src\API.jl:147 [inlined]
  [5] #precompile#114
    @ C:\Users\Me\AppData\Local\Programs\Julia-1.10.1\share\julia\stdlib\v1.10\Pkg\src\API.jl:146 [inlined]
  [6] #invokelatest#2
    @ .\essentials.jl:894 [inlined]
  [7] invokelatest
    @ .\essentials.jl:889 [inlined]
  [8] _require(pkg::Base.PkgId, env::String)
    @ Base .\loading.jl:1963
  [9] __require_prelocked(uuidkey::Base.PkgId, env::String)
    @ Base .\loading.jl:1812
 [10] #invoke_in_world#3
    @ .\essentials.jl:926 [inlined]
 [11] invoke_in_world
    @ .\essentials.jl:923 [inlined]
 [12] _require_prelocked(uuidkey::Base.PkgId, env::String)
    @ Base .\loading.jl:1803
 [13] macro expansion
    @ .\loading.jl:1790 [inlined]
 [14] macro expansion
    @ .\lock.jl:267 [inlined]
 [15] __require(into::Module, mod::Symbol)
    @ Base .\loading.jl:1753
 [16] #invoke_in_world#3
    @ .\essentials.jl:926 [inlined]
 [17] invoke_in_world
    @ .\essentials.jl:923 [inlined]
 [18] require(into::Module, mod::Symbol)
    @ Base .\loading.jl:1746
 [19] eval
    @ .\boot.jl:385 [inlined]
 [20] include_string(mapexpr::typeof(identity), mod::Module, code::String, filename::String)
    @ Base .\loading.jl:2076
 [21] include_string(m::Module, txt::String, fname::String)
    @ Base .\loading.jl:2086
 [22] invokelatest(::Any, ::Any, ::Vararg{Any}; kwargs::@Kwargs{})
    @ Base .\essentials.jl:892
 [23] invokelatest(::Any, ::Any, ::Vararg{Any})
    @ Base .\essentials.jl:889
 [24] inlineeval(m::Module, code::String, code_line::Int64, code_column::Int64, file::String; softscope::Bool)
    @ VSCodeServer c:\Users\Me\.vscode\extensions\julialang.language-julia-1.76.2\scripts\packages\VSCodeServer\src\eval.jl:263
 [25] (::VSCodeServer.var"#69#74"{…})()
    @ VSCodeServer c:\Users\Me\.vscode\extensions\julialang.language-julia-1.76.2\scripts\packages\VSCodeServer\src\eval.jl:181
 [26] withpath(f::VSCodeServer.var"#69#74"{…}, path::String)
    @ VSCodeServer c:\Users\Me\.vscode\extensions\julialang.language-julia-1.76.2\scripts\packages\VSCodeServer\src\repl.jl:274
 [27] (::VSCodeServer.var"#68#73"{…})()
    @ VSCodeServer c:\Users\Me\.vscode\extensions\julialang.language-julia-1.76.2\scripts\packages\VSCodeServer\src\eval.jl:179
 [28] hideprompt(f::VSCodeServer.var"#68#73"{…})
    @ VSCodeServer c:\Users\Me\.vscode\extensions\julialang.language-julia-1.76.2\scripts\packages\VSCodeServer\src\repl.jl:38
 [29] (::VSCodeServer.var"#67#72"{…})()
    @ VSCodeServer c:\Users\Me\.vscode\extensions\julialang.language-julia-1.76.2\scripts\packages\VSCodeServer\src\eval.jl:150
 [30] with_logstate(f::Function, logstate::Any)
    @ Base.CoreLogging .\logging.jl:515
 [31] with_logger
    @ .\logging.jl:627 [inlined]
 [32] (::VSCodeServer.var"#66#71"{VSCodeServer.ReplRunCodeRequestParams})()
    @ VSCodeServer c:\Users\Me\.vscode\extensions\julialang.language-julia-1.76.2\scripts\packages\VSCodeServer\src\eval.jl:255
 [33] #invokelatest#2
    @ .\essentials.jl:892 [inlined]
 [34] invokelatest(::Any)
    @ Base .\essentials.jl:889
 [35] (::VSCodeServer.var"#64#65")()
    @ VSCodeServer c:\Users\Me\.vscode\extensions\julialang.language-julia-1.76.2\scripts\packages\VSCodeServer\src\eval.jl:34

I have tried removing and reinstalling the package using Pkg.rm(“ReinforcementLearning”) and Pkg.add(“ReinforcementLearning”) but it doesn’t work.

Hi welcome to the discourse :slight_smile:

Please wrap code/error messages in ``` code here ``` so we can read it better.

Please also post the the output of julia> Pkg.status() and julia> versioninfo().

Thanks for the suggestion, I have done that. The output is:

julia> Pkg.status()
Status `C:\Users\Me\Project.toml`
  [158674fc] ReinforcementLearning v0.11.0  

julia> versioninfo()
Julia Version 1.10.1
Commit 7790d6f064 (2024-02-13 20:41 UTC)
Build Info:
  Official https://julialang.org/ release
Platform Info:
  OS: Windows (x86_64-w64-mingw32)
  CPU: 8 × Intel(R) Core(TM) i7-1065G7 CPU @ 1.30GHz
  WORD_SIZE: 64
  LIBM: libopenlibm
  LLVM: libLLVM-15.0.7 (ORCJIT, icelake-client)
Threads: 1 default, 0 interactive, 1 GC (on 8 virtual cores)
Environment:
  JULIA_EDITOR = code
  JULIA_NUM_THREADS =

Weird. This is the current version and for me it precompiles just fine. Was this the full stacktrace or did anything else fail to precompile as well? Could you perhaps just restart Julia and then remove/add the package again and post everything if the error persists?

How did you install Julia?

That’s the error I get when I just type using ReinforcementLearning.

I just tried restarting Julia and removing and adding the package again, but get an error again. The message seems to be a little different this time:


ERROR: The following 1 direct dependency failed to precompile:

ReinforcementLearning [158674fc-8238-5cab-b5ba-03dfc80d1318]

Failed to precompile ReinforcementLearning [158674fc-8238-5cab-b5ba-03dfc80d1318] to "C:\\Users\\Me\\.julia\\compiled\\v1.10\\ReinforcementLearning\\jl_AA33.tmp".
ERROR: LoadError: UndefVarError: `@layer` not defined
Stacktrace:
  [1] include(mod::Module, _path::String)
    @ Base .\Base.jl:495
  [2] include(x::String)
    @ ReinforcementLearningCore C:\Users\Me\.julia\packages\ReinforcementLearningCore\8dBkN\src\ReinforcementLearningCore.jl:1
  [3] top-level scope
    @ C:\Users\Me\.julia\packages\ReinforcementLearningCore\8dBkN\src\policies\agent\agent.jl:1
  [4] include(mod::Module, _path::String)
    @ Base .\Base.jl:495
  [5] include(x::String)
    @ ReinforcementLearningCore C:\Users\Me\.julia\packages\ReinforcementLearningCore\8dBkN\src\ReinforcementLearningCore.jl:1
  [6] top-level scope
    @ C:\Users\Me\.julia\packages\ReinforcementLearningCore\8dBkN\src\policies\policies.jl:1
  [7] include(mod::Module, _path::String)
    @ Base .\Base.jl:495
  [8] include(x::String)
    @ ReinforcementLearningCore C:\Users\Me\.julia\packages\ReinforcementLearningCore\8dBkN\src\ReinforcementLearningCore.jl:1
  [9] top-level scope
    @ C:\Users\Me\.julia\packages\ReinforcementLearningCore\8dBkN\src\ReinforcementLearningCore.jl:14
 [10] include
    @ .\Base.jl:495 [inlined]
 [11] include_package_for_output(pkg::Base.PkgId, input::String, depot_path::Vector{String}, dl_load_path::Vector{String}, load_path::Vector{String}, concrete_deps::Vector{Pair{Base.PkgId, UInt128}}, source::String)
    @ Base .\loading.jl:2222
 [12] top-level scope
    @ stdin:3
in expression starting at C:\Users\Me\.julia\packages\ReinforcementLearningCore\8dBkN\src\policies\agent\agent_base.jl:43
in expression starting at C:\Users\Me\.julia\packages\ReinforcementLearningCore\8dBkN\src\policies\agent\agent_base.jl:43
in expression starting at C:\Users\Me\.julia\packages\ReinforcementLearningCore\8dBkN\src\policies\agent\agent.jl:1
in expression starting at C:\Users\Me\.julia\packages\ReinforcementLearningCore\8dBkN\src\policies\policies.jl:1
in expression starting at C:\Users\Me\.julia\packages\ReinforcementLearningCore\8dBkN\src\ReinforcementLearningCore.jl:1
in expression starting at stdin:3
ERROR: LoadError: Failed to precompile ReinforcementLearningCore [de1b191a-4ae0-4afa-a27b-92d07f46b2d6] to "C:\\Users\\Me\\.julia\\compiled\\v1.10\\ReinforcementLearningCore\\jl_B1F3.tmp".
Stacktrace:
  [1] error(s::String)
    @ Base .\error.jl:35
  [2] compilecache(pkg::Base.PkgId, path::String, internal_stderr::IO, internal_stdout::IO, keep_loaded_modules::Bool)
    @ Base .\loading.jl:2468
  [3] compilecache
    @ .\loading.jl:2340 [inlined]
  [4] (::Base.var"#968#969"{Base.PkgId})()
    @ Base .\loading.jl:1974
  [5] mkpidlock(f::Base.var"#968#969"{Base.PkgId}, at::String, pid::Int32; kwopts::@Kwargs{stale_age::Int64, wait::Bool})
    @ FileWatching.Pidfile C:\Users\Me\AppData\Local\Programs\Julia-1.10.1\share\julia\stdlib\v1.10\FileWatching\src\pidfile.jl:93
  [6] #mkpidlock#6
    @ C:\Users\Me\AppData\Local\Programs\Julia-1.10.1\share\julia\stdlib\v1.10\FileWatching\src\pidfile.jl:88 [inlined]
  [7] trymkpidlock(::Function, ::Vararg{Any}; kwargs::@Kwargs{stale_age::Int64})
    @ FileWatching.Pidfile C:\Users\Me\AppData\Local\Programs\Julia-1.10.1\share\julia\stdlib\v1.10\FileWatching\src\pidfile.jl:111
  [8] #invokelatest#2
    @ .\essentials.jl:894 [inlined]
  [9] invokelatest
    @ .\essentials.jl:889 [inlined]
 [10] maybe_cachefile_lock(f::Base.var"#968#969"{Base.PkgId}, pkg::Base.PkgId, srcpath::String; stale_age::Int64)
    @ Base .\loading.jl:2983
 [11] maybe_cachefile_lock
    @ .\loading.jl:2980 [inlined]
 [12] _require(pkg::Base.PkgId, env::String)
    @ Base .\loading.jl:1970
 [13] __require_prelocked(uuidkey::Base.PkgId, env::String)
    @ Base .\loading.jl:1812
 [14] #invoke_in_world#3
    @ .\essentials.jl:926 [inlined]
 [15] invoke_in_world
    @ .\essentials.jl:923 [inlined]
 [16] _require_prelocked(uuidkey::Base.PkgId, env::String)
    @ Base .\loading.jl:1803
 [17] macro expansion
    @ .\loading.jl:1790 [inlined]
 [18] macro expansion
    @ .\lock.jl:267 [inlined]
 [19] __require(into::Module, mod::Symbol)
    @ Base .\loading.jl:1753
 [20] #invoke_in_world#3
    @ .\essentials.jl:926 [inlined]
 [21] invoke_in_world
    @ .\essentials.jl:923 [inlined]
 [22] require(into::Module, mod::Symbol)
    @ Base .\loading.jl:1746
 [23] include
    @ .\Base.jl:495 [inlined]
 [24] include_package_for_output(pkg::Base.PkgId, input::String, depot_path::Vector{String}, dl_load_path::Vector{String}, load_path::Vector{String}, concrete_deps::Vector{Pair{Base.PkgId, UInt128}}, source::Nothing)
    @ Base .\loading.jl:2222
 [25] top-level scope
    @ stdin:3
in expression starting at C:\Users\Me\.julia\packages\ReinforcementLearning\gDSex\src\ReinforcementLearning.jl:1
in expression starting at stdin:
Stacktrace:
  [1] pkgerror(msg::String)
    @ Pkg.Types C:\Users\Me\AppData\Local\Programs\Julia-1.10.1\share\julia\stdlib\v1.10\Pkg\src\Types.jl:70
  [2] precompile(ctx::Pkg.Types.Context, pkgs::Vector{…}; internal_call::Bool, strict::Bool, warn_loaded::Bool, already_instantiated::Bool, timing::Bool, _from_loading::Bool, kwargs::@Kwargs{…})
    @ Pkg.API C:\Users\Me\AppData\Local\Programs\Julia-1.10.1\share\julia\stdlib\v1.10\Pkg\src\API.jl:1659
  [3] precompile(pkgs::Vector{Pkg.Types.PackageSpec}; io::Base.TTY, kwargs::@Kwargs{_from_loading::Bool})
    @ Pkg.API C:\Users\Me\AppData\Local\Programs\Julia-1.10.1\share\julia\stdlib\v1.10\Pkg\src\API.jl:159
  [4] precompile
    @ C:\Users\Me\AppData\Local\Programs\Julia-1.10.1\share\julia\stdlib\v1.10\Pkg\src\API.jl:147 [inlined]
  [5] #precompile#114
    @ C:\Users\Me\AppData\Local\Programs\Julia-1.10.1\share\julia\stdlib\v1.10\Pkg\src\API.jl:146 [inlined]
  [6] #invokelatest#2
    @ .\essentials.jl:894 [inlined]
  [7] invokelatest
    @ .\essentials.jl:889 [inlined]
  [8] _require(pkg::Base.PkgId, env::String)
    @ Base .\loading.jl:1963
  [9] __require_prelocked(uuidkey::Base.PkgId, env::String)
    @ Base .\loading.jl:1812
 [10] #invoke_in_world#3
    @ .\essentials.jl:926 [inlined]
 [11] invoke_in_world
    @ .\essentials.jl:923 [inlined]
 [12] _require_prelocked(uuidkey::Base.PkgId, env::String)
    @ Base .\loading.jl:1803
 [13] macro expansion
    @ .\loading.jl:1790 [inlined]
 [14] macro expansion
    @ .\lock.jl:267 [inlined]
 [15] __require(into::Module, mod::Symbol)
    @ Base .\loading.jl:1753
 [16] #invoke_in_world#3
    @ .\essentials.jl:926 [inlined]
 [17] invoke_in_world
    @ .\essentials.jl:923 [inlined]
 [18] require(into::Module, mod::Symbol)
    @ Base .\loading.jl:1746

I wonder if there’s a problem doing this in your home folder, since all of the .julia stuff is there too. Can you try to make a new directory (or just cd("Documents") or something), activate that directory, and try again?

Thanks for the suggestions. I ended up uninstalling and reinstalling Julia, which has fixed the issue.