Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Can't use @info in models #537

Closed
torfjelde opened this issue Sep 19, 2023 · 1 comment
Closed

Can't use @info in models #537

torfjelde opened this issue Sep 19, 2023 · 1 comment

Comments

@torfjelde
Copy link
Member

It's currently (on most recent release + Julia 1.9) not possible to use @info and any other logging inside @model:

julia> @model demo_buggy() = @info "hi"
ERROR: LoadError: deepcopy of Modules not supported
Stacktrace:
  [1] error(s::String)
    @ Base ./error.jl:35
  [2] deepcopy_internal(x::Module, stackdict::IdDict{Any, Any})
    @ Base ./deepcopy.jl:33
  [3] _deepcopy_array_t
    @ ./deepcopy.jl:105
  [4] deepcopy_internal(x::Vector{Any}, stackdict::IdDict{Any, Any})
    @ Base ./deepcopy.jl:92
  [5] deepcopy_internal(x::Any, stackdict::IdDict{Any, Any})
    @ Base ./deepcopy.jl:65
  [6] _deepcopy_array_t
    @ ./deepcopy.jl:105
  [7] deepcopy_internal(x::Vector{Any}, stackdict::IdDict{Any, Any})
    @ Base ./deepcopy.jl:92
  [8] deepcopy_internal(x::Any, stackdict::IdDict{Any, Any})
    @ Base ./deepcopy.jl:65
  [9] _deepcopy_array_t
    @ ./deepcopy.jl:105
 [10] deepcopy_internal(x::Vector{Any}, stackdict::IdDict{Any, Any})
    @ Base ./deepcopy.jl:92
 [11] deepcopy_internal(x::Any, stackdict::IdDict{Any, Any})
    @ Base ./deepcopy.jl:65
 [12] _deepcopy_array_t
    @ ./deepcopy.jl:105
 [13] deepcopy_internal(x::Vector{Any}, stackdict::IdDict{Any, Any})
    @ Base ./deepcopy.jl:92
 [14] deepcopy_internal(x::Any, stackdict::IdDict{Any, Any})
    @ Base ./deepcopy.jl:65
 [15] _deepcopy_array_t
    @ ./deepcopy.jl:105
 [16] deepcopy_internal(x::Vector{Any}, stackdict::IdDict{Any, Any})
    @ Base ./deepcopy.jl:92
 [17] deepcopy_internal(x::Any, stackdict::IdDict{Any, Any})
    @ Base ./deepcopy.jl:65
 [18] _deepcopy_array_t
    @ ./deepcopy.jl:105
 [19] deepcopy_internal(x::Vector{Any}, stackdict::IdDict{Any, Any})
    @ Base ./deepcopy.jl:92
 [20] deepcopy_internal(x::Any, stackdict::IdDict{Any, Any})
    @ Base ./deepcopy.jl:65
 [21] _deepcopy_array_t
    @ ./deepcopy.jl:105
 [22] deepcopy_internal(x::Vector{Any}, stackdict::IdDict{Any, Any})
    @ Base ./deepcopy.jl:92
 [23] deepcopy_internal(x::Any, stackdict::IdDict{Any, Any})
    @ Base ./deepcopy.jl:65
 [24] deepcopy_internal(x::Dict{Symbol, Any}, stackdict::IdDict{Any, Any})
    @ Base ./deepcopy.jl:125
 [25] deepcopy
    @ ./deepcopy.jl:26 [inlined]
 [26] build_output(modeldef::Dict{Symbol, Any}, linenumbernode::LineNumberNode)
    @ DynamicPPL ~/.julia/packages/DynamicPPL/YThRW/src/compiler.jl:605
 [27] model(mod::Module, linenumbernode::LineNumberNode, expr::Expr, warn::Bool)
    @ DynamicPPL ~/.julia/packages/DynamicPPL/YThRW/src/compiler.jl:283
 [28] var"@model"(__source__::LineNumberNode, __module__::Module, expr::Any, warn::Any)
    @ DynamicPPL ~/.julia/packages/DynamicPPL/YThRW/src/compiler.jl:274
 [29] var"@model"(__source__::LineNumberNode, __module__::Module, expr::Any)
    @ DynamicPPL ~/.julia/packages/DynamicPPL/YThRW/src/compiler.jl:274
in expression starting at REPL[6]:1

This is, as indicated by the error message, caused by us trying to deepcopy a Module.

julia> @macroexpand @info "hi"
quote
    #= logging.jl:370 =#
    let
        #= logging.jl:371 =#
        var"#132#level" = Base.CoreLogging.Info
        #= logging.jl:372 =#
        var"#133#std_level" = Base.CoreLogging.convert(Base.CoreLogging.LogLevel, var"#132#level")
        #= logging.jl:373 =#
        if var"#133#std_level" >= Base.CoreLogging._min_enabled_level[]
            #= logging.jl:374 =#
            var"#134#group" = Symbol("REPL[7]")
            #= logging.jl:375 =#
            var"#135#_module" = Main
            #= logging.jl:376 =#
            var"#136#logger" = Base.CoreLogging.current_logger_for_env(var"#133#std_level", var"#134#group", var"#135#_module")
            #= logging.jl:377 =#
            if !(var"#136#logger" === Base.CoreLogging.nothing)
                #= logging.jl:378 =#
                var"#137#id" = :Main_3867033d
                #= logging.jl:381 =#
                if Base.CoreLogging.invokelatest(Base.CoreLogging.shouldlog, var"#136#logger", var"#132#level", var"#135#_module", var"#134#group", var"#137#id")
                    #= logging.jl:382 =#
                    var"#138#file" = "REPL[7]"
                    #= logging.jl:383 =#
                    if var"#138#file" isa Base.CoreLogging.String
                        #= logging.jl:384 =#
                        var"#138#file" = (Base.CoreLogging.Base).fixup_stdlib_path(var"#138#file")
                    end
                    #= logging.jl:386 =#
                    var"#139#line" = 1
                    #= logging.jl:387 =#
                    local var"#140#msg", var"#141#kwargs"
                    #= logging.jl:388 =#
                    begin
                            #= logging.jl:328 =#
                            var"#140#msg" = "hi"
                            #= logging.jl:329 =#
                            var"#141#kwargs" = (;)
                            #= logging.jl:330 =#
                            true
                        end && Base.CoreLogging.invokelatest(Base.CoreLogging.handle_message, var"#136#logger", var"#132#level", var"#140#msg", var"#135#_module", var"#134#group", var"#137#id", var"#138#file", var"#139#line"; var"#141#kwargs"...)                end
            end
        end
        #= logging.jl:394 =#
        Base.CoreLogging.nothing
    end
end

Notice the variable var"#135#_module" in the above.

@torfjelde torfjelde mentioned this issue Sep 19, 2023
github-merge-queue bot pushed a commit that referenced this issue Sep 19, 2023
* add_return_to_statement is no longer mutating, thus fixing #537

* bumped patch version

* formatting
@yebai
Copy link
Member

yebai commented Sep 20, 2023

Fixed by #538

@yebai yebai closed this as completed Sep 20, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants