Error during precompilation (ERROR: LoadError: InitError: Evaluation into the closed module `Perceptron` ...)
I wanted to use BetaML.jl in a project, however when I try doing so I get the following error:
julia> using Foo
[ Info: Precompiling Foo [4817f03b-69bd-4595-9d0a-a711fd8a192f]
ERROR: LoadError: InitError: Evaluation into the closed module `Perceptron` breaks incremental compilation because the side effects will not be permanent. This is likely due to some other module mutating `Perceptron` with `eval` during precompilation - don't do this.
Stacktrace:
[1] eval
@ ./boot.jl:368 [inlined]
[2] eval(x::Expr)
@ BetaML.Perceptron ~/.julia/packages/BetaML/mqBvh/src/Perceptron/Perceptron.jl:19
[3] metadata_pkg(T::Type; name::String, uuid::String, url::String, julia::Bool, license::String, is_wrapper::Bool, package_name::String, package_uuid::String, package_url::String, is_pure_julia::Bool, package_license::String)
@ MLJModelInterface ~/.julia/packages/MLJModelInterface/wwFA9/src/metadata_utils.jl:54
[4] #41
@ ./broadcast.jl:1284 [inlined]
[5] _broadcast_getindex_evalf
@ ./broadcast.jl:670 [inlined]
[6] _broadcast_getindex
@ ./broadcast.jl:643 [inlined]
[7] #29
@ ./broadcast.jl:1075 [inlined]
[8] macro expansion
@ ./ntuple.jl:74 [inlined]
[9] ntuple
@ ./ntuple.jl:69 [inlined]
[10] copy
@ ./broadcast.jl:1075 [inlined]
[11] materialize
@ ./broadcast.jl:860 [inlined]
[12] __init__()
@ BetaML ~/.julia/packages/BetaML/mqBvh/src/BetaML.jl:63
[13] _include_from_serialized(pkg::Base.PkgId, path::String, depmods::Vector{Any})
@ Base ./loading.jl:831
[14] _require_search_from_serialized(pkg::Base.PkgId, sourcepath::String, build_id::UInt64)
@ Base ./loading.jl:1039
[15] _require(pkg::Base.PkgId)
@ Base ./loading.jl:1315
[16] _require_prelocked(uuidkey::Base.PkgId)
@ Base ./loading.jl:1200
[17] macro expansion
@ ./loading.jl:1180 [inlined]
[18] macro expansion
@ ./lock.jl:223 [inlined]
[19] require(into::Module, mod::Symbol)
@ Base ./loading.jl:1144
[20] include
@ ./Base.jl:419 [inlined]
[21] 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, UInt64}}, source::Nothing)
@ Base ./loading.jl:1554
[22] top-level scope
@ stdin:1
during initialization of module BetaML
in expression starting at /data_temp/picaud/Temp/Beta/Foo.jl/src/Foo.jl:1
in expression starting at stdin:1
ERROR: Failed to precompile Foo [4817f03b-69bd-4595-9d0a-a711fd8a192f] to /home/picaud/.julia/compiled/v1.8/Foo/jl_a1tr7Z.
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:1707
[3] compilecache
@ ./loading.jl:1651 [inlined]
[4] _require(pkg::Base.PkgId)
@ Base ./loading.jl:1337
[5] _require_prelocked(uuidkey::Base.PkgId)
@ Base ./loading.jl:1200
[6] macro expansion
@ ./loading.jl:1180 [inlined]
[7] macro expansion
@ ./lock.jl:223 [inlined]
[8] require(into::Module, mod::Symbol)
@ Base ./loading.jl:1144
The error is not present when I remove precompilation, the BetaML.jl "patch" is:
# function __init__()
# MMI.metadata_pkg.(MLJ_INTERFACED_MODELS,
# name = "BetaML",
# uuid = "024491cd-cc6b-443e-8034-08ea7eb7db2b", # see your Project.toml
# url = "https://github.com/sylvaticus/BetaML.jl", # URL to your package repo
# julia = true, # is it written entirely in Julia?
# license = "MIT", # your package license
# is_wrapper = false, # does it wrap around some other package?
# )
# end
Steps to reproduce :
Create a local package Foo (in /tmp/ by example)
cd /tmp
(@v1.8) pkg> generate Foo.jl
Generating project Foo:
Foo.jl/Project.toml
Foo.jl/src/Foo.jl
(@v1.8) pkg> activate ./Foo.jl/
Activating project at `/tmp/Foo.jl`
(Foo) pkg> add BetaML
(Foo) pkg> activate
Activating project at `~/.julia/environments/v1.8`
(@v1.8) pkg> dev ./Foo.jl/
Resolving package versions...
Then modify Foo.jl as follows :
module Foo
using BetaML # <---- here
greet() = print("Hello World!")
end # module Foo
Then from Julia type
julia> using Foo
and I (and maybe you) will get the error I mentioned at the beginning.
Thanks!
Thanks to report. I'll look into this in the next few hours/days.
Indeed... moving out from the init function the registration of the models for the MLJ interface seems to solve the issue...
@ablaom what do you think ? I see in the MLJ doc that there is no reference to define metadata_pkg within the __init__ function, and I can't recall why it was set in this way...
Replied in issue linked above.
Ok, this is now solved in master and upcoming v0.9, thanks