slimgroup / JUDI.jl

Julia Devito inversion.
https://slimgroup.github.io/JUDI.jl
MIT License
96 stars 30 forks source link

can't show judiVector in jupyter notebook #109

Closed ziyiyin97 closed 2 years ago

ziyiyin97 commented 2 years ago

I am now at version 3.0.1. This errors when doing

q

in a single cell in jupyter notebook (it works totally find in Julia's REPL in terminal) where q is a judiVector as source. Seems to be an error about something here https://github.com/slimgroup/JUDI.jl/blob/30fb30f90c09f8a3256a189f9134027af2dc93f8/src/TimeModeling/Types/abstract.jl#L12 any thought?

StackOverflowError:

Stacktrace:
     [1] make_typealias(x::Type)
       @ Base ./show.jl:562
     [2] show_typealias(io::IOBuffer, x::Type)
       @ Base ./show.jl:723
     [3] _show_type(io::IOBuffer, x::Type)
       @ Base ./show.jl:886
     [4] show(io::IOBuffer, x::Type)
       @ Base ./show.jl:881
     [5] show_typeparams(io::IOBuffer, env::Core.SimpleVector, orig::Core.SimpleVector, wheres::Vector{TypeVar})
       @ Base ./show.jl:640
     [6] show_datatype(io::IOBuffer, x::DataType, wheres::Vector{TypeVar})
       @ Base ./show.jl:1011
     [7] show_datatype
       @ ./show.jl:989 [inlined]
     [8] _show_type(io::IOBuffer, x::Type)
       @ Base ./show.jl:889
     [9] show(io::IOBuffer, x::Type)
       @ Base ./show.jl:881
    [10] print(io::IOBuffer, x::Type)
       @ Base ./strings/io.jl:35
    [11] print_to_string(xs::Type)
       @ Base ./strings/io.jl:144
    [12] string
       @ ./strings/io.jl:185 [inlined]
    [13] show(io::IOContext{IOBuffer}, ms::judiVector{Float32, Matrix{Float32}})
       @ JUDI ~/.julia/dev/JUDI/src/TimeModeling/Types/abstract.jl:12
    [14] sprint(f::Function, args::judiVector{Float32, Matrix{Float32}}; context::IOContext{IOBuffer}, sizehint::Int64)
       @ Base ./strings/io.jl:112
    [15] alignment(io::IOContext{IOBuffer}, x::judiVector{Float32, Matrix{Float32}})
       @ Base ./show.jl:2730
    [16] alignment(io::IOContext{IOBuffer}, X::AbstractVecOrMat, rows::Vector{Int64}, cols::Vector{Int64}, cols_if_complete::Int64, cols_otherwise::Int64, sep::Int64)
       @ Base ./arrayshow.jl:68
    [17] _print_matrix(io::IOContext{IOBuffer}, X::AbstractVecOrMat, pre::String, sep::String, post::String, hdots::String, vdots::String, ddots::String, hmod::Int64, vmod::Int64, rowsA::UnitRange{Int64}, colsA::UnitRange{Int64})
       @ Base ./arrayshow.jl:204
    [18] print_matrix(io::IOContext{IOBuffer}, X::judiVector{Float32, Matrix{Float32}}, pre::String, sep::String, post::String, hdots::String, vdots::String, ddots::String, hmod::Int64, vmod::Int64) (repeats 2 times)
       @ Base ./arrayshow.jl:169
    [19] print_array
       @ ./arrayshow.jl:355 [inlined]
    [20] show(io::IOContext{IOBuffer}, #unused#::MIME{Symbol("text/plain")}, X::judiVector{Float32, Matrix{Float32}})
       @ Base ./arrayshow.jl:396
    [21] show(io::IOContext{IOBuffer}, m::String, x::judiVector{Float32, Matrix{Float32}})
       @ Base.Multimedia ./multimedia.jl:111
    [22] sprint(::Function, ::String, ::Vararg{Any}; context::IOContext{IOBuffer}, sizehint::Int64)
       @ Base ./strings/io.jl:112
    [23] print_matrix_row(io::IOContext{IOBuffer}, X::AbstractVecOrMat, A::Vector{Tuple{Int64, Int64}}, i::Int64, cols::Vector{Int64}, sep::String)
       @ Base ./arrayshow.jl:106
    [24] _print_matrix(io::IOContext{IOBuffer}, X::AbstractVecOrMat, pre::String, sep::String, post::String, hdots::String, vdots::String, ddots::String, hmod::Int64, vmod::Int64, rowsA::UnitRange{Int64}, colsA::UnitRange{Int64})
       @ Base ./arrayshow.jl:210
--- the last 7 lines are repeated 1488 more times ---
 [10441] print_matrix(io::IOContext{IOBuffer}, X::judiVector{Float32, Matrix{Float32}}, pre::String, sep::String, post::String, hdots::String, vdots::String, ddots::String, hmod::Int64, vmod::Int64) (repeats 2 times)
       @ Base ./arrayshow.jl:169
 [10442] print_array
       @ ./arrayshow.jl:355 [inlined]
 [10443] show(io::IOContext{IOBuffer}, #unused#::MIME{Symbol("text/plain")}, X::judiVector{Float32, Matrix{Float32}})
       @ Base ./arrayshow.jl:396
 [10444] limitstringmime(mime::MIME{Symbol("text/plain")}, x::judiVector{Float32, Matrix{Float32}})
       @ IJulia ~/.julia/packages/IJulia/AQu2H/src/inline.jl:43
 [10445] display_mimestring
       @ ~/.julia/packages/IJulia/AQu2H/src/display.jl:71 [inlined]
 [10446] display_dict(x::judiVector{Float32, Matrix{Float32}})
       @ IJulia ~/.julia/packages/IJulia/AQu2H/src/display.jl:102
 [10447] #invokelatest#2
       @ ./essentials.jl:716 [inlined]
 [10448] invokelatest
       @ ./essentials.jl:714 [inlined]
 [10449] execute_request(socket::ZMQ.Socket, msg::IJulia.Msg)
       @ IJulia ~/.julia/packages/IJulia/AQu2H/src/execute_request.jl:112
 [10450] #invokelatest#2
       @ ./essentials.jl:716 [inlined]
 [10451] invokelatest
       @ ./essentials.jl:714 [inlined]
 [10452] eventloop(socket::ZMQ.Socket)
       @ IJulia ~/.julia/packages/IJulia/AQu2H/src/eventloop.jl:8
mloubout commented 2 years ago
show(io::IOContext{IOBuffer}, #unused#::MIME{Symbol("text/plain")}, X::judiVector{Float32, Matrix{Float32}})
       @ Base ./arrayshow.jl:396

Looks lik you are in Weave, and you can check in the doc's make.jl that need few extra overload for it. But they are ambiguous so would break code quality in JUDI so can't be added there.

ziyiyin97 commented 2 years ago

I did install Weave but I didn't using Weave in the current notebook that is erroring.

ziyiyin97 commented 2 years ago

So I need to uninstall Weave?

mloubout commented 2 years ago

No looks like is some weird path of show

ziyiyin97 commented 2 years ago

I've double checked: show(q) still works but q itself doesn't work

mloubout commented 2 years ago

Looks like probably need to define

show(io::IO, ::MIME{Symbol("text/plain")}, ms::judiMulti
ziyiyin97 commented 2 years ago

Like this?

show(io::IO, ::MIME{Symbol("text/plain")}, ms::JUDI.judiMultiSourceVector) = println(io, "$(typeof(ms)) with $(ms.nsrc) sources")
q

it throws the same error

mloubout commented 2 years ago

Where did you define it

ziyiyin97 commented 2 years ago

adding to abstract.jl works

mloubout commented 2 years ago

Yes because Base.show is imported in JUDI you always have to import function you extens