How to solve the GLMakie Precompiling error in Julia? - julia

I was plotting my heatmap using Makie. It was working fine but suddenly I get this error trying to run the GLMakie package. CairoMakie worked fine.
using GLMakie
[ Info: [e9467ef8-e4e7-5192-8a1a-b1aee30e663a] ERROR: LoadError: KeyError: key :colormap not found
Stacktrace:
[1] getindex(h::Dict{Symbol, Observables.Observable}, key::Symbol)
# Base ./dict.jl:481
[2] getindex
# ~/.julia/packages/MakieCore/8YGMv/src/attributes.jl:96 [inlined]
[3] getindex(x::MakieCore.Mesh{Tuple{GeometryBasics.Mesh{2, Float32, GeometryBasics.Ngon{2, Float32, 3, GeometryBasics.Point{2, Float32}}, GeometryBasics.SimpleFaceView{2, Float32, 3, GeometryBasics.OffsetInteger{-1, UInt32}, GeometryBasics.Point{2, Float32}, GeometryBasics.NgonFace{3, GeometryBasics.OffsetInteger{-1, UInt32}}}}}}, key::Symbol)
# MakieCore ~/.julia/packages/MakieCore/8YGMv/src/attributes.jl:192
*<skipping abundant error messages>*
ERROR: Failed to precompile GLMakie [e9467ef8-e4e7-5192-8a1a-b1aee30e663a] to /home/mikheev/.julia/compiled/v1.7/GLMakie/jl_OWtvbO.
while my heatmap code gave me this error:
let
ix = sortperm([a[1] for a in argmax(dat_e[28,:,:], dims=1)][1,:])
ix = ix[2000:6000]
f, ax, hm = CairoMakie.heatmap((dat_e[28,:,ix]), colormap=Reverse("RdBu"), colorrange = (-40, 40))
ax = current_axis()
ax.xlabel = "Time [sec]"
ax.ylabel = "Sorted trials"
CairoMakie.Colorbar(f[:, end+1], hm, label = "Voltage [µV]")
hidespines!(ax, :t, :r)
f
end
MethodError: no method matching to_color(::MakieCore.Automatic)
Closest candidates are:
to_color(!Matched::Number) at ~/.julia/packages/Makie/bwZTV/src/conversions.jl:763
to_color(!Matched::Colorant) at ~/.julia/packages/Makie/bwZTV/src/conversions.jl:764
to_color(!Matched::Makie.AbstractPattern) at ~/.julia/packages/Makie/bwZTV/src/conversions.jl:769
Any ideas how to solve it? Both problems occured simultaneously after I restarted my VSCode.

Pkg.update() solved the problem.
The problem was in the outdated version of the GLMakie.

If you get any error loading GLMakie, it likely means, you don't have an OpenGL capable Graphic Card, or you don't have an OpenGL 3.3 capable video driver installed. Note, that most GPUs, even 8 year old integrated ones, support OpenGL 3.3.
https://github.com/MakieOrg/Makie.jl/tree/master/GLMakie#troubleshooting-opengl

Related

TypeError: in typeassert in Julia 1.6.3

I am new to Julia. I am working on a Julia package which the writer is not available.
This is the part of the code where I have a problem with:
function find_partition(model::Model, ms)
ps = Dict{Z3Expr,Vector{Int}}()
for (i, m) in enumerate(ms)
mval = Z3.eval(model, m, false)
println(ps)
println(mval)
println(typeof(mval))
if haskey(ps, mval)
push!(ps[mval], i)
else
push!(ps, mval=>Int[i])
end
end
values(ps)
end
Here is the output:
Dict{Z3.Expr, Vector{Int64}}()
1.0
Z3.ExprAllocated
ERROR: TypeError: in typeassert, expected UInt64, got a value of type UInt32
Stacktrace:
[1] hashindex(key::Z3.ExprAllocated, sz::Int64)
# Base ./dict.jl:169
[2] ht_keyindex(h::Dict{Z3.Expr, Vector{Int64}}, key::Z3.ExprAllocated)
# Base ./dict.jl:284
[3] haskey(h::Dict{Z3.Expr, Vector{Int64}}, key::Z3.ExprAllocated)
# Base ./dict.jl:550
[4] find_partition(model::Z3.ModelAllocated, ms::Vector{Z3.ExprAllocated})
# Absynth.NLSat ~/Desktop/faoc/Absynth/src/nlsat/cfinitesolver.jl:101
I tried following it and found out that somewhere inside dict.jl in Julia, there are such lines
sz = length(h.keys)
...
index = hashindex(key, sz)
And this is the hashindex written somewhere in dict.jl:
hashindex(key, sz) = (((hash(key)::UInt % Int) & (sz-1)) + 1)::Int
It seems that the version of Z3 used in this package is not compatible with the current version of Julia. I am not sure if this package was working in the beginning at all.
Is there any quick fix to this? Like rewriting this part of the code:
if haskey(ps, mval)
push!(ps[mval], i)
else
push!(ps, mval=>Int[i])
in a way that this won't happen? I tried writing like merge!(ps,Dict(mval=>Int[i])) but it's eventually reaching this hashindex function again.
If I install the older versions of Julia, would it be possible to solve this issue or the problem is somewhere else?

In Julia Flux, I keep getting the error LoadError: Mutating arrays is not supported, but I don't see where I am mutating an array

I am new to Julia and for some reason I can't get this very simple code to work. No matter what I try, I get the error LoadError: Mutating arrays is not supported. I understand that this error occurs when I mutate an array during the course of optimization so that the code is no longer differentiable. I clearly do not understand Julia enough to see where I am doing this.
If it helps the error seems to be occurring in the line for d in dataset.
using Statistics
using Flux: onehotbatch, onehot, onecold, crossentropy, throttle
using Flux
using Base.Iterators:repeated
using Plots:heatmap
using ImageView:imshow
images = Flux.Data.MNIST.images()[1:10]
labels = Flux.Data.MNIST.labels()[1:10]
heatmap(images[4], color=:grays, aspect_ratio=1)
X = float.(reshape.(images, :))
encode(x) = onehot(x, 0:9)
Y = encode.(labels)
m = Chain(Dense(28^2, 32, relu), Dense(32, 10), softmax)
loss(x, y) = crossentropy(m(x), y)
opt = ADAM()
accuracy(x, y) = mean(onecold(m(x)) .== onecold(y))
dataset = zip(X, Y)
print(size(X))
evalcb = () -> #show(loss(X, Y))
print("Training...")
# Flux.train!(loss, params(m), dataset, opt, cb=throttle(evalcb, 5));
for d in dataset
print(d[2])
gs = gradient(params(m)) do
l = loss(d...)
end
update!(opt, params(m), gs)
end
It looks like I did have an old version of Flux (but not that old). I had to uninstall and reinstall Julia to install the new version of Flux.

In Julia, creating a Weights vector in statsbase

I am playing a bit with Julia.
Consider this function:
function drawValues(fromDistribution, byCount)
#=
inputs:
fromDistribution :
A 2D array
Each element is an array with two elements
The first one is a value, and the second one is the probability of that value
We will draw a value out of this distribution from a random number generator
byCount :
An integer
We draw that many values from the source distribution
=#
values = []
wts = []
for i = 1:length(fromDistribution)
push!(values, fromDistribution[i][1])
push!(wts , fromDistribution[i][2])
end
w = Weights(wts)
res = []
for i = 1:byCount
r = sample(values, w)
push!(res, r)
end
plot(values, wts)
print(res)
end
This throws the error :
ERROR: MethodError: no method matching Weights(::Array{Any,1},
::Float64) Closest candidates are: Weights(::var"#18#V",
::var"#16#S") where {var"#16#S"<:Real, var"#17#T"<:Real,
var"#18#V"<:AbstractArray{var"#17#T",1}} at
/home/hedgehog/.julia/packages/StatsBase/EA8Mh/src/weights.jl:13
Weights(::Any) at
/home/hedgehog/.julia/packages/StatsBase/EA8Mh/src/weights.jl:16
Stacktrace: [1] Weights(::Array{Any,1}) at
/home/hedgehog/.julia/packages/StatsBase/EA8Mh/src/weights.jl:16 [2]
drawValues(::Array{Array{Float64,1},1}, ::Int64) at
/home/hedgehog/LASER.jl:51 [3] top-level scope at REPL[13]:1 [4]
run_repl(::REPL.AbstractREPL, ::Any) at
/build/julia/src/julia-1.5.3/usr/share/julia/stdlib/v1.5/REPL/src/REPL.jl:288
It seems, that the second definition ( Weights(::Array{Any,1})) whould fit. But somehow Julia sees two input arguments?
Please help.
Version details :
Julia Version 1.5.3
Commit 788b2c77c1* (2020-11-09 13:37 UTC)
Platform Info:
OS: Linux (x86_64-pc-linux-gnu)
CPU: AMD Ryzen 7 3700X 8-Core Processor
WORD_SIZE: 64
LIBM: libopenlibm
LLVM:
libLLVM-10.0.1 (ORCJIT, znver2)
Your Vectors have elements of type any.
It should be:
wts = Float64[]
When you write wts=[] it is an equivalent of wts=Any[].
Have a look at the weight methods:
julia> methods(weights)
# 3 methods for generic function "weights":
[1] weights(vs::AbstractArray{T,1} where T<:Real) in StatsBase at c:\JuliaPkg\Julia1.5.3\packages\StatsBase\EA8Mh\src\weights.jl:76
[2] weights(vs::AbstractArray{T,N} where N where T<:Real) in StatsBase at c:\JuliaPkg\Julia1.5.3\packages\StatsBase\EA8Mh\src\weights.jl:77
[3] weights(model::StatisticalModel) in StatsBase at c:\JuliaPkg\Julia1.5.3\packages\StatsBase\EA8Mh\src\statmodels.jl:143
A container having elements of subtype of Real is required.
Similarly for the other containers providing the types is recommended as well:
value = Float64[]
res = Float64[] # or maybe Int[] depending on what your code does

error generator in Julia JuMP optimization error

I am converting a code in julia 0.6 to 1.2.
Here is the old version:
#variable(model, use[i=eachindex(n), j=1:m], Bin)
Used = [indmax(getvalue(use[i,j])
for j=1:m) for i=eachindex(n)]
I converted to the following,
#variable(model, use[i=eachindex(n), j=1:m], Bin)
JuMP.optimize!(model)
Used = [argmax(JuMP.value(use[i,j])
for j=1:m) for i=eachindex(n)]
but with error:
MethodError: no method matching keys(::Base.Generator{UnitRange{Int64},getfield(Main, Symbol("##261#266")){Int64,JuMP.Containers.SparseAxisArray{VariableRef,2,Tuple{Any,Any}}}})
Closest candidates are:
keys(!Matched::Core.SimpleVector) at essentials.jl:606
keys(!Matched::Cmd) at process.jl:963
keys(!Matched::BenchmarkTools.BenchmarkGroup) at /Users/shuaiwang/.julia/packages/BenchmarkTools/7aqwe/src/groups.jl:31
...
pairs(::Base.Generator{UnitRange{Int64},getfield(Main, Symbol("##261#266")){Int64,JuMP.Containers.SparseAxisArray{VariableRef,2,Tuple{Any,Any}}}}) at abstractdict.jl:132
_findmax(::Base.Generator{UnitRange{Int64},getfield(Main, Symbol("##261#266")){Int64,JuMP.Containers.SparseAxisArray{VariableRef,2,Tuple{Any,Any}}}}, ::Colon) at array.jl:2068
findmax(::Base.Generator{UnitRange{Int64},getfield(Main, Symbol("##261#266")){Int64,JuMP.Containers.SparseAxisArray{VariableRef,2,Tuple{Any,Any}}}}) at array.jl:2065
argmax(::Base.Generator{UnitRange{Int64},getfield(Main, Symbol("##261#266")){Int64,JuMP.Containers.SparseAxisArray{VariableRef,2,Tuple{Any,Any}}}}) at array.jl:2153
(::getfield(Main, Symbol("##260#265")){ScenarioGraph,JuMP.Containers.SparseAxisArray{VariableRef,2,Tuple{Any,Any}}})(::Int64) at none:0
iterate at generator.jl:47 [inlined]
collect at array.jl:606 [inlined]
The problem seems to be unrelated to JuMP. The fix to your code is:
Used = [argmax([JuMP.value(use[i,j]) for j=1:m]) for i=eachindex(n)]
(I have not tested the whole code as it was not complete)
And the core of the issue is that you are not allowed to use argmax on generators, you have to pass a collection that supports pairs to it, e.g.:
julia> argmax(i for i in 1:3)
ERROR: MethodError: no method matching keys(::Base.Generator{UnitRange{Int64},getfield(Main, Symbol("##15#16"))})
fails, but
julia> argmax([i for i in 1:3])
3
julia> argmax((1,2,3))
3
julia> argmax((a=1,b=2,c=3))
:c
julia> argmax(Dict(:a=>1,:b=>2,:c=>3))
:c
work

UndefVarError in Julia

Very new to Julia and trying to work through some code. I keep getting this error: "ERROR: LoadError: LoadError: UndefVarError: #defVar not defined". The start of the code is below where I define the #defVar. Julia Version 1.1.1 (2019-05-16). Here is the code I am using:
using DataFrames
using GLPKMathProgInterface
using JuMP
num_lineups = 6
num_overlap = 4
path_data = "/users/matt/desktop/example_players.csv"
path_data2 = "/users/matt/desktop/example_players2.csv"
path_to_output= "/users/matt/desktop/output.csv"
m = Model(solver=GLPKSolverMIP())
#defVar(m, players_a_lineup[i=1:num_players_a], Bin)
#defVar(m, players_b_lineup[i=1:num_players_b], Bin)
You are using an old syntax (#defvar has been used up to version 0.12). For the latest Julia/JuMP version 19, your code could should read
using DataFrames
using GLPK
using JuMP
...
m = Model(with_optimizer(GLPK.Optimizer))
#variable(m, players_a_lineup[i=1:num_players_a], Bin)
#variable(m, players_b_lineup[i=1:num_players_b], Bin)

Resources