modelcols() "world age problem" with "deserialized types"

Open
#217 1 comment 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Assessment

Difficulty
4/5
Estimated time
3-5 days
Newbie friendliness
35/100
Issue type
Bug
Clarity
Needs clarification
Activity status
Stale
Tech stack
julia
Domain
data

Research direction

Reproduce the serialized-model case using BSON.jl or JLSO.jl, then call predict() inside a function and inspect the failure at src/terms.jl:491 in modelcols(). Compare the REPL and function contexts; done means the deserialized formula involving ^ no longer raises the world-age MethodError.

Written by the indexing model from the issue text.

Description

I tried to save a fitted model of type:

julia> typeof(mod)
StatsModels.TableRegressionModel{LinearModel{GLM.LmResp{Array{Float64,1}},GLM.DensePredChol{Float64,LinearAlgebra.Cholesky{Float64,Array{Float64,2}}}},Array{Float64,2}}

which has a modelframe as:

julia> mod.mf.f
FormulaTerm
Response:
  v0(continuous)
Predictors:
  1
  x1(continuous)
  x2(continuous)
  (x1)->x1 ^ 2
  (x2)->x2 ^ 2
  (x1)->x1 ^ 3
  (x2)->x2 ^ 3
  (x1)->x1 ^ 4
  (x2)->x2 ^ 4
  x1(continuous) & x2(continuous)

into files using BSON.jl or JLSO.jl.

then, I load the file and call functions like predict() and everything is fine under REPL. However, they fail when I load the file and call predict() inside a function:

with the model saved via JLSO.save(;format = :julia_serialize):

ERROR: MethodError: no method matching (::Serialization.__deserialized_types__.var"#85#92")(::Float64)
The applicable method may be too new: running in world age 27958, while current world is 28007.
Closest candidates are:
  #85(::Any) at none:0 (method too new to be called from this world context.)
Stacktrace:
 [1] _broadcast_getindex_evalf at ./broadcast.jl:648 [inlined]
 [2] _broadcast_getindex at ./broadcast.jl:621 [inlined]
 [3] getindex at ./broadcast.jl:575 [inlined]
 [4] copy at ./broadcast.jl:876 [inlined]
 [5] materialize at ./broadcast.jl:837 [inlined]
 [6] modelcols(::FunctionTerm{typeof(^),Serialization.__deserialized_types__.var"#85#92",(:zx1,)}, ::NamedTuple{(:zx1, :zx2, :zx3, :zx4),NTuple{4,Array{Float64,1}}}) at /Users/Thomas/.julia/packages/StatsModels/FJnLj/src/terms.jl:491

with the model saved via BSON.bson():

ERROR: MethodError: no method matching (::BSON.__deserialized_types__.var"#85#92")(::Float64)
The applicable method may be too new: running in world age 28011, while current world is 28060.
Closest candidates are:
  #85(::Any) at none:0 (method too new to be called from this world context.)
Stacktrace:
 [1] _broadcast_getindex_evalf at ./broadcast.jl:648 [inlined]
 [2] _broadcast_getindex at ./broadcast.jl:621 [inlined]
 [3] getindex at ./broadcast.jl:575 [inlined]
 [4] copy at ./broadcast.jl:876 [inlined]
 [5] materialize at ./broadcast.jl:837 [inlined]
 [6] modelcols(::FunctionTerm{typeof(^),BSON.__deserialized_types__.var"#85#92",(:zx1,)}, ::NamedTuple{(:zx1, :zx2, :zx3, :zx4),NTuple{4,Array{Float64,1}}}) at /Users/Thomas/.julia/packages/StatsModels/FJnLj/src/terms.jl:491

seems like modelcols() has a "world age problem" dealing with ^ formulas, (e.g. @formula(y ~ x ^ 2)).

please kindly advise.
thanks.

Dominant language
Julia
Stars
252
Forks
36
Avg merge
3h 14m
Merged PRs (30d)
4

Getting set up

This project ships no dev container, Dockerfile or contributing guide, so setting up is up to you: start from its README, and see our first-contribution guide for the general steps.

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

More from JuliaStats/StatsModels.jl

All issues in JuliaStats/StatsModels.jl

Similar issues

More Julia issues

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.