text:
"""
    LagrangeDual

Lagrangian dual method for dual decomposition. This `mutable struct` constains:
    - `block_model::BlockModel` object
    - `var_to_index` mapping coupling variable to the index wrt the master problem
    - `masiter::Int` sets the maximum number of iterations
    - `tol::Float64` sets the relative tolerance for termination
"""

mutable struct LagrangeDual <: AbstractLagrangeDual
    block_model::BlockModel
    var_to_index::Dict{Tuple{Int,Any},Int} # maps coupling variable to the index wrt the master problem
    heuristics::Vector{Type}
    subsolve_time::Vector{Dict{Int,Float64}}
    subcomm_time::Vector{Float64}
    subobj_value::Vector{Float64}
    master_time::Vector{Float64}

    function LagrangeDual()
        LD = new()
        LD.block_model = BlockModel()
        LD.var_to_index = Dict()
        LD.heuristics = []
        LD.subsolve_time = []
        LD.subcomm_time = []
        LD.subobj_value = []
        LD.master_time = []

        return LD
    end
end

"""
Wrappers of the functions defined for `BlockModel`
"""

add_block_model!(LD::AbstractLagrangeDual, block_id::Integer, model::JuMP.Model) = add_block_model!(LD.block_model, block_id, model)
num_blocks(LD::AbstractLagrangeDual) = num_blocks(LD.block_model)
block_model(LD::AbstractLagrangeDual, block_id::Integer) = block_model(LD.block_model, block_id)
block_model(LD::AbstractLagrangeDual) = block_model(LD.block_model)
has_block_model(LD::AbstractLagrangeDual, block_id::Integer) = has_block_model(LD.block_model, block_id)
num_coupling_variables(LD::AbstractLagrangeDual) = num_coupling_variables(LD.block_model)
coupling_variables(LD::AbstractLagrangeDual) = coupling_variables(LD.block_model)

function set_coupling_variables!(LD::AbstractLagrangeDual, variables::Vector{CouplingVariableRef})
    set_coupling_variables!(LD.block_model, variables)
    variable_keys = [v.key for v in variables]
    # collect all coupling variables
    all_variable_keys = parallel.allcollect(variable_keys)
    set_variables_by_couple!(LD.block_model, all_variable_keys)
    LD.var_to_index = Dict((v.block_id,v.coupling_id) => i for (i,v) in enumerate(all_variable_keys))
end

dual_objective_value(LD::AbstractLagrangeDual) = dual_objective_value(LD.block_model)
dual_solution(LD::AbstractLagrangeDual) = dual_solution(LD.block_model)
primal_objective_value(LD::AbstractLagrangeDual) = primal_objective_value(LD.block_model)
primal_solution(LD::AbstractLagrangeDual) = primal_solution(LD.block_model)

"""
    run!

This runs the Lagrangian dual method for solving the block model.
"""
function run!(LD::AbstractLagrangeDual, LM::AbstractLagrangeMaster, initial_λ = nothing)

    # We assume that the block models are distributed.
    num_all_blocks = parallel.sum(num_blocks(LD))
    num_all_coupling_variables = parallel.sum(num_coupling_variables(LD))

    # initialize λ if it is nothing
    if isnothing(initial_λ)
        initial_λ = zeros(num_all_coupling_variables)
    end
    @assert length(initial_λ) == num_all_coupling_variables

    # check the validity of LagrangeDual
    if num_all_blocks <= 0 || num_all_coupling_variables == 0
        println("Invalid LagrangeDual structure.")
        return
    end

    function solveLagrangeDual(λ::Array{Float64,1})
        @assert length(λ) == num_all_coupling_variables

        # broadcast λ
        if parallel.is_root()
            parallel.bcast(λ)
        end

        # output
        objvals = Dict{Int,Float64}()
        subgrads = Dict{Int,SparseVector{Float64}}()
        subsolve_time = Dict{Int,Float64}()

        # Adjust block objective function
        for var in coupling_variables(LD)
            adjust_objective_function!(LD, var, λ[index_of_λ(LD, var)])
        end

        for (id,m) in block_model(LD)
            # Initialize subgradients
            subgrads[id] = sparsevec(Dict{Int,Float64}(), length(λ))

            # Solver the Lagrange dual
            stime = time()
            solve_sub_block!(m)
            subsolve_time[id] = time() - stime

            status = JuMP.termination_status(m)
            # @assert status in [MOI.OPTIMAL, MOI.LOCALLY_SOLVED]

            # We may want consider other statuses.
            if status in [MOI.OPTIMAL, MOI.LOCALLY_SOLVED]
                try
                    objvals[id] = -JuMP.dual_objective_value(m)
                catch e
                    objvals[id] = -JuMP.objective_value(m)
                end
            else
                @error "Unexpected solution status: $(status)"
            end
        end

        push!(LD.subsolve_time, subsolve_time)

        # Get subgradients
        for var in coupling_variables(LD)
            # @assert has_block_model(LD, var.key.block_id)
            subgrads[var.key.block_id][index_of_λ(LD, var)] = -JuMP.value(var.ref)
        end

        #run heuristics
        if length(LD.heuristics) > 0
            #get the values of all coupling variables
            opt_coupling_val = Dict{Int,SparseVector{Float64}}()
            coupling_ub = Dict{Int,SparseVector{Float64}}()
            coupling_lb = Dict{Int,SparseVector{Float64}}()
            for (id,m) in block_model(LD)
                opt_coupling_val[id] = sparsevec(Dict{Int,Float64}(), num_all_coupling_variables)
                coupling_ub[id] = sparsevec(Dict{Int,Float64}(), num_all_coupling_variables)
                coupling_lb[id] = sparsevec(Dict{Int,Float64}(), num_all_coupling_variables)
            end
            #get variable values and bounds
            for var in coupling_variables(LD)
                opt_coupling_val[var.key.block_id][index_of_λ(LD, var)] = JuMP.value(var.ref)
                if JuMP.has_lower_bound(var.ref)
                    coupling_lb[var.key.block_id][index_of_λ(LD, var)] = JuMP.lower_bound(var.ref)
                else
                    coupling_lb[var.key.block_id][index_of_λ(LD, var)] = - Inf
                end
                if JuMP.has_upper_bound(var.ref)
                    coupling_ub[var.key.block_id][index_of_λ(LD, var)] = JuMP.upper_bound(var.ref)
                else
                    coupling_ub[var.key.block_id][index_of_λ(LD, var)] = + Inf
                end
            end

            opt_coupling_val_combined = parallel.combine_dict(opt_coupling_val)
            coupling_ub_combined = parallel.combine_dict(coupling_ub)
            coupling_lb_combined = parallel.combine_dict(coupling_lb)

            for htype in LD.heuristics
                run!(htype, LD, opt_coupling_val_combined, coupling_ub_combined, coupling_lb_combined)
            end
        end

        # Reset objective coefficients
        for var in coupling_variables(LD)
            reset_objective_function!(LD, var, λ[index_of_λ(LD, var)])
        end

        parallel.barrier()
        comm_time = time()

        # Collect objvals, subgrads
        objvals_combined = parallel.combine_dict(objvals)
        objvals_vec = Vector{Float64}(undef, length(objvals_combined))
        if parallel.is_root()
            for (k,v) in objvals_combined
                objvals_vec[k] = v
            end
            push!(LD.subobj_value, sum(objvals_vec))
        end

        subgrads_combined = parallel.combine_dict(subgrads)

        if parallel.is_root()
            push!(LD.subcomm_time, time() - comm_time)
            # @printf("Subproblem sommunication time: %6.1f sec.\n", time() - comm_time)
        end

        return objvals_vec, subgrads_combined
    end

    if parallel.is_root()
        load!(LM, num_all_coupling_variables, num_all_blocks, solveLagrangeDual, initial_λ)

        # Add bounding constraints to the Lagrangian master
        add_constraints!(LD, LM)

        # This runs the bundle method.
        run!(LM)

        # Copy master solution time
        LD.master_time = get_times(LM)

        # get dual objective value
        LD.block_model.dual_bound = get_objective(LM)

        # get dual solution
        LD.block_model.dual_solution = get_solution(LM)

        # broadcast we are done.
        parallel.bcast(Float64[])
    else
        λ = parallel.bcast(nothing)
        while length(λ) > 0
            solveLagrangeDual(λ)
            λ = parallel.bcast(nothing)
        end
    end
end

"""
This adjusts the objective function of each Lagrangian subproblem.
"""
function adjust_objective_function!(LD::AbstractLagrangeDual, var::CouplingVariableRef, λ::Float64)
    @assert has_block_model(LD, var.key.block_id)
    affobj = objective_function(LD, var.key.block_id)
    @assert typeof(affobj) == AffExpr
    coef = haskey(affobj.terms, var.ref) ? affobj.terms[var.ref] + λ : λ
    JuMP.set_objective_coefficient(block_model(LD, var.key.block_id), var.ref, coef)
end

"""
This resets the objective function of each Lagrangian subproblem.
"""
function reset_objective_function!(LD::AbstractLagrangeDual, var::CouplingVariableRef, λ::Float64)
    @assert has_block_model(LD, var.key.block_id)
    affobj = objective_function(LD, var.key.block_id)
    @assert typeof(affobj) == AffExpr
    coef = haskey(affobj.terms, var.ref) ? affobj.terms[var.ref] - λ : -λ
    JuMP.set_objective_coefficient(block_model(LD, var.key.block_id), var.ref, coef)
end

"""
This wraps the steps to optimize a block problem.
"""
function solve_sub_block!(model::JuMP.Model)
    JuMP.optimize!(model)
    # FIXME (KK): why do we need to do this?
    # reoptimize!(model)
end

"""
This re-optimizes block models if not solved to local optimality
"""
function reoptimize!(model::JuMP.Model)
    solve_itr = 0
    while !(JuMP.termination_status(model) in [MOI.OPTIMAL, MOI.LOCALLY_SOLVED]) && solve_itr < 10
        JuMP.set_start_value.(all_variables(model), rand())
        JuMP.optimize!(model)
        solve_itr += 1
    end
end

"""
Wrappers of other functions
"""
objective_function(LD::AbstractLagrangeDual, block_id::Integer) = JuMP.objective_function(block_model(LD, block_id), QuadExpr).aff

index_of_λ(LD::AbstractLagrangeDual, var::CouplingVariableKey) = LD.var_to_index[var.block_id,var.coupling_id]
index_of_λ(LD::AbstractLagrangeDual, var::CouplingVariableRef) = index_of_λ(LD, var.key)

function write_times(LD::AbstractLagrangeDual; dir = ".")
    write_file!(LD.subsolve_time, "subsolve_time.txt", dir)
    write_file!(LD.master_time, "subcomm_time.txt", dir)
    write_file!(LD.master_time, "master_time.txt", dir)
end

function write_all(LD::AbstractLagrangeDual; dir = ".")
    write_times(LD, dir = dir)
    write_file!(LD.subobj_value, "subobj_value.txt", dir)
end

function get_solution!(LD::AbstractLagrangeDual, method::BM.AbstractMethod)
    LD.block_model.dual_solution = copy(BM.get_solution(method))
end

include("PrimalHeuristics.jl")


text:
const LAYERSKELETON = 64

checklayer(J::Int) = J÷LAYERSKELETON == J/LAYERSKELETON

struct ThinSphericalHarmonicPlan{T} <: SphericalHarmonicPlan{T}
    RP::RotationPlan{T}
    BF::Vector{Butterfly{T}}
    p1::NormalizedLegendreToChebyshevPlan{T}
    p2::NormalizedLegendre1ToChebyshev2Plan{T}
    p1inv::ChebyshevToNormalizedLegendrePlan{T}
    p2inv::Chebyshev2ToNormalizedLegendre1Plan{T}
    B::Matrix{T}
end

function ThinSphericalHarmonicPlan(A::Matrix{T}, L::Int; opts...) where T
    M, N = size(A)
    n = (N+1)÷2
    RP = RotationPlan(T, M-1)
    p1 = plan_normleg2cheb(A)
    p2 = plan_normleg12cheb2(A)
    p1inv = plan_cheb2normleg(A)
    p2inv = plan_cheb22normleg1(A)
    B = zero(A)
    Ce = Matrix{T}(I, M, M)
    Co = Matrix{T}(I, M, M)
    BF = Vector{Butterfly{T}}(undef, n-2)
    P = Progress(n-2, 0.1, "Pre-computing...", 43)
    for J = 1:2:n-2
        mul!(Ce, RP.layers[J])
        checklayer(J+1) && (BF[J] = Butterfly(Ce, L; isorthogonal = true, opts...))
        next!(P)
    end
    for J = 2:2:n-2
        mul!(Co, RP.layers[J])
        checklayer(J) && (BF[J] = Butterfly(Co, L; isorthogonal = true, opts...))
        next!(P)
    end
    ThinSphericalHarmonicPlan(RP, BF, p1, p2, p1inv, p2inv, B)
end

ThinSphericalHarmonicPlan(A::Matrix; opts...) = ThinSphericalHarmonicPlan(A, floor(Int, log2(size(A, 1)+1)-6); opts...)

if VERSION ≥ v"0.7-"
    adjoint(P::ThinSphericalHarmonicPlan) = Adjoint(P)
    transpose(P::ThinSphericalHarmonicPlan) = Transpose(P)
end

function LAmul!(Y::Matrix, TP::ThinSphericalHarmonicPlan, X::Matrix)
    RP, BF, p1, p2, B = TP.RP, TP.BF, TP.p1, TP.p2, TP.B
    copyto!(B, X)
    M, N = size(X)

    @stepthreads for J = 3:2:N÷2
        if checklayer(J-1)
            mul_col_J!(Y, BF[J-1], B, 2J)
            2J < N && mul_col_J!(Y, BF[J-1], B, 2J+1)
        else
            ℓ = round(Int, (J-1)÷LAYERSKELETON)*LAYERSKELETON
            mul_col_J!(RP, B, 2J, ℓ+1, J-1)
            2J < N && mul_col_J!(RP, B, 2J+1, ℓ+1, J-1)
            if ℓ > LAYERSKELETON-2
                mul_col_J!(Y, BF[ℓ], B, 2J)
                2J < N && mul_col_J!(Y, BF[ℓ], B, 2J+1)
            else
                copyto!(Y, 1+M*(2J-1), B, 1+M*(2J-1), 2M)
            end
        end
    end

    @stepthreads for J = 2:2:N÷2
        if checklayer(J)
            mul_col_J!(Y, BF[J-1], B, 2J)
            2J < N && mul_col_J!(Y, BF[J-1], B, 2J+1)
        else
            ℓ = round(Int, J÷LAYERSKELETON)*LAYERSKELETON
            mul_col_J!(RP, B, 2J, ℓ, J-1)
            2J < N && mul_col_J!(RP, B, 2J+1, ℓ, J-1)
            if ℓ > LAYERSKELETON-2
                mul_col_J!(Y, BF[ℓ-1], B, 2J)
                2J < N && mul_col_J!(Y, BF[ℓ-1], B, 2J+1)
            else
                copyto!(Y, 1+M*(2J-1), B, 1+M*(2J-1), 2M)
            end
        end
    end

    copyto!(Y, 1, X, 1, 3M)
    copyto!(B, Y)
    fill!(Y, zero(eltype(Y)))

    mul_col_J!!(Y, p1, B, 1)
    @stepthreads for J = 2:4:N
        mul_col_J!!(Y, p2, B, J)
        J < N && mul_col_J!!(Y, p2, B, J+1)
    end
    @stepthreads for J = 4:4:N
        mul_col_J!!(Y, p1, B, J)
        J < N && mul_col_J!!(Y, p1, B, J+1)
    end
    Y
end

if VERSION < v"0.7-"
    function Base.At_mul_B!(Y::Matrix, TP::ThinSphericalHarmonicPlan, X::Matrix)
        RP, BF, p1inv, p2inv, B = TP.RP, TP.BF, TP.p1inv, TP.p2inv, TP.B
        copyto!(B, X)
        M, N = size(X)
        mul_col_J!!(Y, p1inv, B, 1)
        @stepthreads for J = 2:4:N
            mul_col_J!!(Y, p2inv, B, J)
            J < N && mul_col_J!!(Y, p2inv, B, J+1)
        end
        @stepthreads for J = 4:4:N
            mul_col_J!!(Y, p1inv, B, J)
            J < N && mul_col_J!!(Y, p1inv, B, J+1)
        end

        copyto!(B, Y)
        fill!(Y, zero(eltype(Y)))
        copyto!(Y, 1, B, 1, 3M)

        @stepthreads for J = 3:2:N÷2
            if checklayer(J-1)
                At_mul_B_col_J!(Y, BF[J-1], B, 2J)
                2J < N && At_mul_B_col_J!(Y, BF[J-1], B, 2J+1)
            else
                ℓ = round(Int, (J-1)÷LAYERSKELETON)*LAYERSKELETON
                if ℓ > LAYERSKELETON-2
                    At_mul_B_col_J!(Y, BF[ℓ], B, 2J)
                    2J < N && At_mul_B_col_J!(Y, BF[ℓ], B, 2J+1)
                else
                    copyto!(Y, 1+M*(2J-1), B, 1+M*(2J-1), 2M)
                end
                At_mul_B_col_J!(RP, Y, 2J, ℓ+1, J-1)
                2J < N && At_mul_B_col_J!(RP, Y, 2J+1, ℓ+1, J-1)
            end
        end

        @stepthreads for J = 2:2:N÷2
            if checklayer(J)
                At_mul_B_col_J!(Y, BF[J-1], B, 2J)
                2J < N && At_mul_B_col_J!(Y, BF[J-1], B, 2J+1)
            else
                ℓ = round(Int, J÷LAYERSKELETON)*LAYERSKELETON
                if ℓ > LAYERSKELETON-2
                    At_mul_B_col_J!(Y, BF[ℓ-1], B, 2J)
                    2J < N && At_mul_B_col_J!(Y, BF[ℓ-1], B, 2J+1)
                else
                    copyto!(Y, 1+M*(2J-1), B, 1+M*(2J-1), 2M)
                end
                At_mul_B_col_J!(RP, Y, 2J, ℓ, J-1)
                2J < N && At_mul_B_col_J!(RP, Y, 2J+1, ℓ, J-1)
            end
        end

        sph_zero_spurious_modes!(Y)
    end

    Base.Ac_mul_B!(Y::Matrix, TP::ThinSphericalHarmonicPlan, X::Matrix) = At_mul_B!(Y, TP, X)
else
    function LinearAlgebra.mul!(Y::Matrix, TPt::Transpose{T,<:ThinSphericalHarmonicPlan}, X::Matrix) where T
        TP = parent(TPt)
        RP, BF, p1inv, p2inv, B = TP.RP, TP.BF, TP.p1inv, TP.p2inv, TP.B
        copyto!(B, X)
        M, N = size(X)
        mul_col_J!!(Y, p1inv, B, 1)
        @stepthreads for J = 2:4:N
            mul_col_J!!(Y, p2inv, B, J)
            J < N && mul_col_J!!(Y, p2inv, B, J+1)
        end
        @stepthreads for J = 4:4:N
            mul_col_J!!(Y, p1inv, B, J)
            J < N && mul_col_J!!(Y, p1inv, B, J+1)
        end

        copyto!(B, Y)
        fill!(Y, zero(eltype(Y)))
        copyto!(Y, 1, B, 1, 3M)

        @stepthreads for J = 3:2:N÷2
            if checklayer(J-1)
                At_mul_B_col_J!(Y, BF[J-1], B, 2J)
                2J < N && At_mul_B_col_J!(Y, BF[J-1], B, 2J+1)
            else
                ℓ = round(Int, (J-1)÷LAYERSKELETON)*LAYERSKELETON
                if ℓ > LAYERSKELETON-2
                    At_mul_B_col_J!(Y, BF[ℓ], B, 2J)
                    2J < N && At_mul_B_col_J!(Y, BF[ℓ], B, 2J+1)
                else
                    copyto!(Y, 1+M*(2J-1), B, 1+M*(2J-1), 2M)
                end
                At_mul_B_col_J!(RP, Y, 2J, ℓ+1, J-1)
                2J < N && At_mul_B_col_J!(RP, Y, 2J+1, ℓ+1, J-1)
            end
        end

        @stepthreads for J = 2:2:N÷2
            if checklayer(J)
                At_mul_B_col_J!(Y, BF[J-1], B, 2J)
                2J < N && At_mul_B_col_J!(Y, BF[J-1], B, 2J+1)
            else
                ℓ = round(Int, J÷LAYERSKELETON)*LAYERSKELETON
                if ℓ > LAYERSKELETON-2
                    At_mul_B_col_J!(Y, BF[ℓ-1], B, 2J)
                    2J < N && At_mul_B_col_J!(Y, BF[ℓ-1], B, 2J+1)
                else
                    copyto!(Y, 1+M*(2J-1), B, 1+M*(2J-1), 2M)
                end
                At_mul_B_col_J!(RP, Y, 2J, ℓ, J-1)
                2J < N && At_mul_B_col_J!(RP, Y, 2J+1, ℓ, J-1)
            end
        end

        sph_zero_spurious_modes!(Y)
    end

    LinearAlgebra.mul!(Y::Matrix, TPc::Adjoint{T,<:ThinSphericalHarmonicPlan}, X::Matrix) where T =
        mul!(Y, transpose(parent(TPc)), X)
end
allranks(TP::ThinSphericalHarmonicPlan) = mapreduce(i->allranks(TP.BF[i]),vcat,sort!([LAYERSKELETON-1:LAYERSKELETON:length(TP.BF);LAYERSKELETON:LAYERSKELETON:length(TP.BF)]))

function mul_col_J!(P::RotationPlan, A::AbstractMatrix, J::Int, L1::Int, L2::Int)
    M, N = size(A)
    @inbounds for m = L2-1:-2:L1
        layer = P.layers[m+1]
        @simd for i = 1:length(layer)
            G = layer[i]
            a1, a2 = A[G.i1,J], A[G.i2,J]
            A[G.i1,J] = G.c*a1 + G.s*a2
            A[G.i2,J] = G.c*a2 - G.s*a1
        end
    end
    A
end

function At_mul_B_col_J!(P::RotationPlan, A::AbstractMatrix, J::Int, L1::Int, L2::Int)
    M, N = size(A)
    @inbounds for m = L1:2:L2-1
        layer = P.layers[m+1]
        @simd for i = length(layer):-1:1
            G = layer[i]
            a1, a2 = A[G.i1,J], A[G.i2,J]
            A[G.i1,J] = G.c*a1 - G.s*a2
            A[G.i2,J] = G.c*a2 + G.s*a1
        end
    end
    A
end

ext: jl


text: const RigidMotion{N,T} = AffineMap{R,SVector{N,T}} where {R<:Rotation{N,T}}


text:
using Test
using MPI
using ClimateMachine
using ClimateMachine.MPIStateArrays
using ClimateMachine.Mesh.BrickMesh
using Pkg
using KernelAbstractions

ClimateMachine.init()
const ArrayType = ClimateMachine.array_type()
const comm = MPI.COMM_WORLD

function main()

    crank = MPI.Comm_rank(comm)
    csize = MPI.Comm_size(comm)

    @assert csize == 3

    if crank == 0
        numreal = 4
        numghost = 3

        nabrtorank = [1, 2]

        sendelems = [1, 2, 3, 4, 1, 4]
        nabrtorecv = [1:2, 3:3]
        nabrtosend = [1:4, 5:6]

        vmaprecv = [
            37,
            38,
            39,
            40,
            42,
            43,
            44,
            45,
            46,
            49,
            52,
            53,
            54,
            57,
            60,
            61,
            62,
            63,
        ]
        vmapsend =
            [3, 6, 9, 10, 11, 12, 19, 22, 25, 34, 35, 36, 1, 2, 3, 28, 31, 34]

        nabrtovmaprecv = [1:13, 14:18]
        nabrtovmapsend = [1:12, 13:18]

        expectedghostdata = [
            1001,
            1002,
            1003,
            1004,
            1006,
            1007,
            1008,
            1009,
            1010,
            1013,
            1016,
            1017,
            1018,
            2003,
            2006,
            2007,
            2008,
            2009,
        ]
    elseif crank == 1
        numreal = 2
        numghost = 4

        nabrtorank = [0]

        sendelems = [1, 2]
        nabrtorecv = [1:4]
        nabrtosend = [1:2]

        vmaprecv = [21, 24, 27, 28, 29, 30, 37, 40, 43, 52, 53, 54]
        vmapsend = [1, 2, 3, 4, 6, 7, 8, 9, 10, 13, 16, 17, 18]

        nabrtovmaprecv = [1:length(vmaprecv)]
        nabrtovmapsend = [1:length(vmapsend)]

        expectedghostdata = [3, 6, 9, 10, 11, 12, 19, 22, 25, 34, 35, 36]
    elseif crank == 2
        numreal = 1
        numghost = 2

        nabrtorank = [0]

        sendelems = [1]
        nabrtorecv = [1:2]
        nabrtosend = [1:1]

        vmaprecv = [10, 11, 12, 19, 22, 25]
        vmapsend = [3, 6, 7, 8, 9]

        nabrtovmaprecv = [1:length(vmaprecv)]
        nabrtovmapsend = [1:length(vmapsend)]

        expectedghostdata = [1, 2, 3, 28, 31, 34]
    end

    numelem = numreal + numghost

    realelems = 1:numreal
    ghostelems = numreal .+ (1:numghost)

    weights = Array{Int64}(undef, (0, 0, 0))

    A = MPIStateArray{Int64}(
        comm,
        ArrayType,
        9,
        2,
        numelem,
        realelems,
        ghostelems,
        ArrayType(vmaprecv),
        ArrayType(vmapsend),
        nabrtorank,
        nabrtovmaprecv,
        nabrtovmapsend,
        ArrayType(weights),
    )

    Q = Array(A.data)
    Q .= -1
    shift = 100
    Q[:, 1, realelems] .=
        reshape((crank * 1000) .+ (1:(9 * numreal)), 9, numreal)
    Q[:, 2, realelems] .=
        reshape((crank * 1000) .+ shift .+ (1:(9 * numreal)), 9, numreal)
    copyto!(A.data, Q)

    event = Event(array_device(A))
    event = MPIStateArrays.begin_ghost_exchange!(A; dependencies = event)
    event = MPIStateArrays.end_ghost_exchange!(A; dependencies = event)
    wait(array_device(A), event)

    Q = Array(A.data)
    @test all(expectedghostdata .== Q[:, 1, :][:][vmaprecv])
    @test all(shift .+ expectedghostdata .== Q[:, 2, :][:][vmaprecv])

end

main()


text:
@testset "Continous Weight" begin
    T = Float64

    ## known set of modified moments
    P = ShiftedLegendre{T}
    f(x) = -log(x)
    q0 = ContinuousWeight(P, f, [1], :x)
    WW = typeof(q0)
    function SpecialPolynomials.modified_moment(w::W, j) where {W<:WW}
        iszero(j) && return 1.0
        (-1)^j * gamma(j + 1)^2 / (j * (j + 1) * gamma(2j + 1))
    end

    q0 = ContinuousWeight(P, f, [1], :x)
    q1 = ContinuousWeight(P, f, [0, 1], :x)
    q2 = ContinuousWeight(P, f, [0, 0, 1], :x)
    q3 = ContinuousWeight(P, f, [0, 0, 0, 1], :x)
    q4 = ContinuousWeight(P, f, [0, 0, 0, 0, 1], :x)
    q5 = ContinuousWeight(P, f, [0, 0, 0, 0, 0, 1], :x)
    qs = convert.(Polynomial, (q0, q1, q2, q3, q4, q5))
    a, b = first(domain(q0)), last(domain(q0))
    for i in eachindex(qs)
        for j in eachindex(qs)
            j <= i && continue
            @test abs(
                SpecialPolynomials._quadgk(
                    x -> qs[i](x) * qs[j](x) * f(x),
                    first(domain(q0)),
                    last(domain(q0)),
                ),
            ) <= 100 * sqrt(eps(T))
        end
    end

    ## non-known set
    T = Float64
    P = Chebyshev{T}
    f(x) = SpecialPolynomials.weight_function(ChebyshevU{T})(x)
    q0 = ContinuousWeight(P, f, [1], :x)
    q1 = ContinuousWeight(P, f, [0, 1], :x)
    q2 = ContinuousWeight(P, f, [0, 0, 1], :x)
    q3 = ContinuousWeight(P, f, [0, 0, 0, 1], :x)
    q4 = ContinuousWeight(P, f, [0, 0, 0, 0, 1], :x)
    q5 = ContinuousWeight(P, f, [0, 0, 0, 0, 0, 1], :x)
    qs = convert.(Polynomial, (q0, q1, q2, q3, q4, q5))
    a, b = first(domain(q0)), last(domain(q0))
    for qi in qs
        for qj in qs
            j <= i && continue
            @test abs(SpecialPolynomials._quadgk(x -> qi(x) * qj(x) * f(x), a, b)) <=
                  100 * sqrt(eps(T))
        end
    end
end


text:
export setpolymodule!

setdefault!(m::JuMP.Model, S::Type, T::Type) = setdefault!(getpolydata(m), S, T)
setdefault!(data::Data, ::Type{NonNegPoly}, S::Type) = data.nonnegpoly_default = S
setdefault!(data::Data, ::Type{PosDefPolyMatrix}, S::Type) = data.posdefpolymatrix_default = S

getdefault(m::JuMP.Model, s) = getdefault(getpolydata(m), s)

# includes Poly but also custom types defined by other modules
getdefault(data::Data, p) = p
getdefault(data::Data, s::Union{NonNegPoly, PosDefPolyMatrix}) = getdefault(data, typeof(s))()
getdefault(data::Data, ::Type{NonNegPoly}) = get_default(data.nonnegpoly_default)
getdefault(data::Data, ::Type{PosDefPolyMatrix}) = get_default(data.posdefpolymatrix_default)

setpolymodule!(m::JuMP.Model, pm::Module) = setpolymodule!(getpolydata(m), pm)
setpolymodule!(data::Data, pm::Module) = pm.setdefaults!(data)

get_default(d) = d
function get_default(::Nothing)
    error("PolyJuMP is just a JuMP extension for modelling Polynomial Optimization: it does not implement any reformulation. To use automatic sums of squares (SOS) reformulations, install the SumOfSquares Julia package and try \`using SumOfSquares\` and \`setpolymodule!(SumOfSquares)\` or use \`SOSModel\` instead of \`Model\`.")
end


text:
### A Pluto.jl notebook ###
# v0.18.0

using Markdown
using InteractiveUtils

# ╔═╡ 74ec70b2-52db-11ec-308e-0b507febe03e
begin
	using NCDatasets, Downloads, PlutoUI, CairoMakie
	"Done with packages."
end

# ╔═╡ edf5fb5f-cb8d-47d1-bd6f-be4605686a67
md"""# NetCDF : Basics Demo

Here we first open a NetCDF file, extract a slice of data, and visualize it as a heatmap.

We then look at commands for downloading and creating files.

To finish is a short list of NetCDF related software.
"""

# ╔═╡ b7cef3ea-da3d-496d-bd01-2cfb5d931777
TableOfContents()

# ╔═╡ 6e56775b-c730-4739-9964-0056b5d8260a
md"""## Reading From File

The three commands in the code cells below accomplish this sequence :

1. open file using `NCDatasets.Dataset`; return lazy view of the file content (`ds`)
1. access one variable from the data set file; return a lazy view (`v`)
1. retrieve the data by indexing / slicing the data; return an Array (`A`)
"""

# ╔═╡ 213c15be-2e66-430f-b522-744ed4d55094
md"""## Visualizing Content

One of the common methods to visualize an array liek `A` is a heatmap.
"""

# ╔═╡ 5afe78bb-fda0-48a0-bee6-9543d89819e8
md"""## Downloading Files

There are various ways to access files via the internet. Sometimes it is necessary to download files to access their content; sometimes it isn't. Here are a couple examples:

1. data from the WHOTS program, acessed via a thredds server
2. data from the Argo program, accessed via https or ftp

These examples are from the [OceanRobots.jl](https://github.com/gaelforget/OceanRobots.jl) which provides additional information on these data sets.
"""

# ╔═╡ 240851bb-6b44-4ffc-a7da-4c9640c79fb1
let
	fil="http://tds0.ifremer.fr/thredds/dodsC/CORIOLIS-OCEANSITES-GDAC-OBS/long_timeseries/WHOTS/OS_WHOTS_200408-201809_D_MLTS-1H.nc"

	NCDataset(fil)
end

# ╔═╡ baa6b7b8-e4bf-4a54-8341-0ccce0a65e9f
let
	url="https://data-argo.ifremer.fr/dac/coriolis/6900900/6900900_prof.nc"
	fil=Downloads.download(url)

	NCDataset(fil)
end

# ╔═╡ d6da99a1-423a-4c85-8f43-8811c09c4595
md"""## Creating Files

Below is the code that generates the file used in this notebook.

The pattern represented as a `heatmap` earlier in this notebook is of the data found in the generated file.

This pattern comes from the [Makie.jl](https://makie.juliaplots.org/stable/) documentation, where you can learn more on visualizing data.

"""

# ╔═╡ ec6e1fad-602c-465b-b54c-eeb45f5d70fe
begin
	N = 60

	function xy_data(x, y)
	           r = sqrt(x^2 + y^2)
	           r == 0.0 ? 1f0 : (sin(r)/r)
	end

	l = range(-10, stop = 10, length = N)
	z = Float32[xy_data(x, y) for x in l, y in l]
end

# ╔═╡ e4f7d5fd-0f79-4f61-8b28-562e7c87f542
begin
	function create_file(data)
	    sz = size(data)

	    filename = tempname()*".nc"
	    ds = NCDataset(filename,"c") do ds
	        defDim(ds,"lon",sz[1])
	        defDim(ds,"lat",sz[2])
	        v = defVar(ds,"var",Float64,("lon","lat"))
	        v[:,:] = data
	    end
		return filename
	end

	filename=create_file(z)

	isfile(filename) ? "File created is found @ $(filename)" : "File is missing !!"
end

# ╔═╡ cf5ea7f7-35be-4756-bcfa-5fad09148e69
ds = Dataset(filename)

# ╔═╡ a8f1eae9-3c9f-4f0e-8b10-726127b7933f
v=ds["var"]

# ╔═╡ ce1f0e37-2d41-4648-9bcd-2d21079fac39
A=v[:,:,1,1]

# ╔═╡ dd4c4491-203f-421f-8617-93f525fe377d
heatmap(A)

# ╔═╡ a8524123-f78c-4c6d-b455-872c3fcf7f7f
md"""## Software Links

The [OceanStateEstimation.jl](https://gaelforget.github.io/OceanStateEstimation.jl/dev/), [OceanRobots.jl](https://gaelforget.github.io/OceanRobots.jl/dev), and [ClimateModels.jl](https://gaelforget.github.io/ClimateModels.jl/dev/) package documentations provide complementary examples that cover not only [NetCDF](https://www.unidata.ucar.edu/software/netcdf/) but also formats like `CSV` and `Zarr`.

One option to try out these notebooks online is provided in the [JuliaClimate notebooks](https://juliaclimate.github.io/Notebooks/#page-top) page ([here](https://juliaclimate.github.io/Notebooks/#more)).

In relation to this tutorial, useful software on NetCDF and Visualization may include:

- NetCDF in Julia
  - <https://github.com/Alexander-Barth/NCDatasets.jl>
  - <https://github.com/JuliaGeo/NetCDF.jl>
  - <https://github.com/JuliaClimate>
- Visualization
  - <https://makie.juliaplots.org/stable/>
  - <https://github.com/JuliaPlots/>
- Other NetCDF interfaces, beyond Julia
  - <https://www.giss.nasa.gov/tools/panoply/>
  - <https://xarray.pydata.org/en/stable/index.html>
"""

# ╔═╡ ed5bdc8d-d3e2-40fd-9924-b9dcc5dd7e6d
md"""## Appendix"""

# ╔═╡ 00000000-0000-0000-0000-000000000001
PLUTO_PROJECT_TOML_CONTENTS = """
[deps]
CairoMakie = "13f3f980-e62b-5c42-98c6-ff1f3baf88f0"
Downloads = "f43a241f-c20a-4ad4-852c-f6b1247861c6"
NCDatasets = "85f8d34a-cbdd-5861-8df4-14fed0d494ab"
PlutoUI = "7f904dfe-b85e-4ff6-b463-dae2292396a8"

[compat]
CairoMakie = "~0.7.4"
NCDatasets = "~0.11.9"
PlutoUI = "~0.7.35"
"""

# ╔═╡ 00000000-0000-0000-0000-000000000002
PLUTO_MANIFEST_TOML_CONTENTS = """
# This file is machine-generated - editing it directly is not advised

julia_version = "1.7.2"
manifest_format = "2.0"

[[deps.AbstractFFTs]]
deps = ["ChainRulesCore", "LinearAlgebra"]
git-tree-sha1 = "6f1d9bc1c08f9f4a8fa92e3ea3cb50153a1b40d4"
uuid = "621f4979-c628-5d54-868e-fcf4e3e8185c"
version = "1.1.0"

[[deps.AbstractPlutoDingetjes]]
deps = ["Pkg"]
git-tree-sha1 = "8eaf9f1b4921132a4cff3f36a1d9ba923b14a481"
uuid = "6e696c72-6542-2067-7265-42206c756150"
version = "1.1.4"

[[deps.AbstractTrees]]
git-tree-sha1 = "03e0550477d86222521d254b741d470ba17ea0b5"
uuid = "1520ce14-60c1-5f80-bbc7-55ef81b5835c"
version = "0.3.4"

[[deps.Adapt]]
deps = ["LinearAlgebra"]
git-tree-sha1 = "af92965fb30777147966f58acb05da51c5616b5f"
uuid = "79e6a3ab-5dfb-504d-930d-738a2a938a0e"
version = "3.3.3"

[[deps.Animations]]
deps = ["Colors"]
git-tree-sha1 = "e81c509d2c8e49592413bfb0bb3b08150056c79d"
uuid = "27a7e980-b3e6-11e9-2bcd-0b925532e340"
version = "0.4.1"

[[deps.ArgTools]]
uuid = "0dad84c5-d112-42e6-8d28-ef12dabb789f"

[[deps.ArrayInterface]]
deps = ["Compat", "IfElse", "LinearAlgebra", "Requires", "SparseArrays", "Static"]
git-tree-sha1 = "745233d77146ad221629590b6d82fe7f1ddb478f"
uuid = "4fba245c-0d91-5ea0-9b3e-6abc04ee57a9"
version = "4.0.3"

[[deps.Artifacts]]
uuid = "56f22d72-fd6d-98f1-02f0-08ddc0907c33"

[[deps.Automa]]
deps = ["Printf", "ScanByte", "TranscodingStreams"]
git-tree-sha1 = "d50976f217489ce799e366d9561d56a98a30d7fe"
uuid = "67c07d97-cdcb-5c2c-af73-a7f9c32a568b"
version = "0.8.2"

[[deps.AxisAlgorithms]]
deps = ["LinearAlgebra", "Random", "SparseArrays", "WoodburyMatrices"]
git-tree-sha1 = "66771c8d21c8ff5e3a93379480a2307ac36863f7"
uuid = "13072b0f-2c55-5437-9ae7-d433b7a33950"
version = "1.0.1"

[[deps.Base64]]
uuid = "2a0f44e3-6c83-55bd-87e4-b1978d98bd5f"

[[deps.Bzip2_jll]]
deps = ["Artifacts", "JLLWrappers", "Libdl", "Pkg"]
git-tree-sha1 = "19a35467a82e236ff51bc17a3a44b69ef35185a2"
uuid = "6e34b625-4abd-537c-b88f-471c36dfa7a0"
version = "1.0.8+0"

[[deps.CEnum]]
git-tree-sha1 = "215a9aa4a1f23fbd05b92769fdd62559488d70e9"
uuid = "fa961155-64e5-5f13-b03f-caf6b980ea82"
version = "0.4.1"

[[deps.CFTime]]
deps = ["Dates", "Printf"]
git-tree-sha1 = "bca6cb6ee746e6485ca4535f6cc29cf3579a0f20"
uuid = "179af706-886a-5703-950a-314cd64e0468"
version = "0.1.1"

[[deps.Cairo]]
deps = ["Cairo_jll", "Colors", "Glib_jll", "Graphics", "Libdl", "Pango_jll"]
git-tree-sha1 = "d0b3f8b4ad16cb0a2988c6788646a5e6a17b6b1b"
uuid = "159f3aea-2a34-519c-b102-8c37f9878175"
version = "1.0.5"

[[deps.CairoMakie]]
deps = ["Base64", "Cairo", "Colors", "FFTW", "FileIO", "FreeType", "GeometryBasics", "LinearAlgebra", "Makie", "SHA", "StaticArrays"]
git-tree-sha1 = "aedc7c910713eb616391cf95218277b714a7913f"
uuid = "13f3f980-e62b-5c42-98c6-ff1f3baf88f0"
version = "0.7.4"

[[deps.Cairo_jll]]
deps = ["Artifacts", "Bzip2_jll", "Fontconfig_jll", "FreeType2_jll", "Glib_jll", "JLLWrappers", "LZO_jll", "Libdl", "Pixman_jll", "Pkg", "Xorg_libXext_jll", "Xorg_libXrender_jll", "Zlib_jll", "libpng_jll"]
git-tree-sha1 = "4b859a208b2397a7a623a03449e4636bdb17bcf2"
uuid = "83423d85-b0ee-5818-9007-b63ccbeb887a"
version = "1.16.1+1"

[[deps.Calculus]]
deps = ["LinearAlgebra"]
git-tree-sha1 = "f641eb0a4f00c343bbc32346e1217b86f3ce9dad"
uuid = "49dc2e85-a5d0-5ad3-a950-438e2897f1b9"
version = "0.5.1"

[[deps.ChainRulesCore]]
deps = ["Compat", "LinearAlgebra", "SparseArrays"]
git-tree-sha1 = "c9a6160317d1abe9c44b3beb367fd448117679ca"
uuid = "d360d2e6-b24c-11e9-a2a3-2a2ae2dbcce4"
version = "1.13.0"

[[deps.ChangesOfVariables]]
deps = ["ChainRulesCore", "LinearAlgebra", "Test"]
git-tree-sha1 = "bf98fa45a0a4cee295de98d4c1462be26345b9a1"
uuid = "9e997f8a-9a97-42d5-a9f1-ce6bfc15e2c0"
version = "0.1.2"

[[deps.ColorBrewer]]
deps = ["Colors", "JSON", "Test"]
git-tree-sha1 = "61c5334f33d91e570e1d0c3eb5465835242582c4"
uuid = "a2cac450-b92f-5266-8821-25eda20663c8"
version = "0.4.0"

[[deps.ColorSchemes]]
deps = ["ColorTypes", "Colors", "FixedPointNumbers", "Random"]
git-tree-sha1 = "12fc73e5e0af68ad3137b886e3f7c1eacfca2640"
uuid = "35d6a980-a343-548e-a6ea-1d62b119f2f4"
version = "3.17.1"

[[deps.ColorTypes]]
deps = ["FixedPointNumbers", "Random"]
git-tree-sha1 = "024fe24d83e4a5bf5fc80501a314ce0d1aa35597"
uuid = "3da002f7-5984-5a60-b8a6-cbb66c0b333f"
version = "0.11.0"

[[deps.ColorVectorSpace]]
deps = ["ColorTypes", "FixedPointNumbers", "LinearAlgebra", "SpecialFunctions", "Statistics", "TensorCore"]
git-tree-sha1 = "3f1f500312161f1ae067abe07d13b40f78f32e07"
uuid = "c3611d14-8923-5661-9e6a-0046d554d3a4"
version = "0.9.8"

[[deps.Colors]]
deps = ["ColorTypes", "FixedPointNumbers", "Reexport"]
git-tree-sha1 = "417b0ed7b8b838aa6ca0a87aadf1bb9eb111ce40"
uuid = "5ae59095-9a9b-59fe-a467-6f913c188581"
version = "0.12.8"

[[deps.Compat]]
deps = ["Base64", "Dates", "DelimitedFiles", "Distributed", "InteractiveUtils", "LibGit2", "Libdl", "LinearAlgebra", "Markdown", "Mmap", "Pkg", "Printf", "REPL", "Random", "SHA", "Serialization", "SharedArrays", "Sockets", "SparseArrays", "Statistics", "Test", "UUIDs", "Unicode"]
git-tree-sha1 = "44c37b4636bc54afac5c574d2d02b625349d6582"
uuid = "34da2185-b29b-5c13-b0c7-acf172513d20"
version = "3.41.0"

[[deps.CompilerSupportLibraries_jll]]
deps = ["Artifacts", "Libdl"]
uuid = "e66e0078-7015-5450-92f7-15fbd957f2ae"

[[deps.Contour]]
deps = ["StaticArrays"]
git-tree-sha1 = "9f02045d934dc030edad45944ea80dbd1f0ebea7"
uuid = "d38c429a-6771-53c6-b99e-75d170b6e991"
version = "0.5.7"

[[deps.DataAPI]]
git-tree-sha1 = "cc70b17275652eb47bc9e5f81635981f13cea5c8"
uuid = "9a962f9c-6df0-11e9-0e5d-c546b8b5ee8a"
version = "1.9.0"

[[deps.DataStructures]]
deps = ["Compat", "InteractiveUtils", "OrderedCollections"]
git-tree-sha1 = "3daef5523dd2e769dad2365274f760ff5f282c7d"
uuid = "864edb3b-99cc-5e75-8d2d-829cb0a9cfe8"
version = "0.18.11"

[[deps.DataValueInterfaces]]
git-tree-sha1 = "bfc1187b79289637fa0ef6d4436ebdfe6905cbd6"
uuid = "e2d170a0-9d28-54be-80f0-106bbe20a464"
version = "1.0.0"

[[deps.Dates]]
deps = ["Printf"]
uuid = "ade2ca70-3891-5945-98fb-dc099432e06a"

[[deps.DelimitedFiles]]
deps = ["Mmap"]
uuid = "8bb1440f-4735-579b-a4ab-409b98df4dab"

[[deps.DensityInterface]]
deps = ["InverseFunctions", "Test"]
git-tree-sha1 = "80c3e8639e3353e5d2912fb3a1916b8455e2494b"
uuid = "b429d917-457f-4dbc-8f4c-0cc954292b1d"
version = "0.4.0"

[[deps.Distributed]]
deps = ["Random", "Serialization", "Sockets"]
uuid = "8ba89e20-285c-5b6f-9357-94700520ee1b"

[[deps.Distributions]]
deps = ["ChainRulesCore", "DensityInterface", "FillArrays", "LinearAlgebra", "PDMats", "Printf", "QuadGK", "Random", "SparseArrays", "SpecialFunctions", "Statistics", "StatsBase", "StatsFuns", "Test"]
git-tree-sha1 = "9d3c0c762d4666db9187f363a76b47f7346e673b"
uuid = "31c24e10-a181-5473-b8eb-7969acd0382f"
version = "0.25.49"

[[deps.DocStringExtensions]]
deps = ["LibGit2"]
git-tree-sha1 = "b19534d1895d702889b219c382a6e18010797f0b"
uuid = "ffbed154-4ef7-542d-bbb7-c09d3a79fcae"
version = "0.8.6"

[[deps.Downloads]]
deps = ["ArgTools", "LibCURL", "NetworkOptions"]
uuid = "f43a241f-c20a-4ad4-852c-f6b1247861c6"

[[deps.DualNumbers]]
deps = ["Calculus", "NaNMath", "SpecialFunctions"]
git-tree-sha1 = "84f04fe68a3176a583b864e492578b9466d87f1e"
uuid = "fa6b7ba4-c1ee-5f82-b5fc-ecf0adba8f74"
version = "0.6.6"

[[deps.EarCut_jll]]
deps = ["Artifacts", "JLLWrappers", "Libdl", "Pkg"]
git-tree-sha1 = "3f3a2501fa7236e9b911e0f7a588c657e822bb6d"
uuid = "5ae413db-bbd1-5e63-b57d-d24a61df00f5"
version = "2.2.3+0"

[[deps.EllipsisNotation]]
deps = ["ArrayInterface"]
git-tree-sha1 = "d7ab55febfd0907b285fbf8dc0c73c0825d9d6aa"
uuid = "da5c29d0-fa7d-589e-88eb-ea29b0a81949"
version = "1.3.0"

[[deps.Expat_jll]]
deps = ["Artifacts", "JLLWrappers", "Libdl", "Pkg"]
git-tree-sha1 = "ae13fcbc7ab8f16b0856729b050ef0c446aa3492"
uuid = "2e619515-83b5-522b-bb60-26c02a35a201"
version = "2.4.4+0"

[[deps.FFMPEG]]
deps = ["FFMPEG_jll"]
git-tree-sha1 = "b57e3acbe22f8484b4b5ff66a7499717fe1a9cc8"
uuid = "c87230d0-a227-11e9-1b43-d7ebe4e7570a"
version = "0.4.1"

[[deps.FFMPEG_jll]]
deps = ["Artifacts", "Bzip2_jll", "FreeType2_jll", "FriBidi_jll", "JLLWrappers", "LAME_jll", "Libdl", "Ogg_jll", "OpenSSL_jll", "Opus_jll", "Pkg", "Zlib_jll", "libass_jll", "libfdk_aac_jll", "libvorbis_jll", "x264_jll", "x265_jll"]
git-tree-sha1 = "d8a578692e3077ac998b50c0217dfd67f21d1e5f"
uuid = "b22a6f82-2f65-5046-a5b2-351ab43fb4e5"
version = "4.4.0+0"

[[deps.FFTW]]
deps = ["AbstractFFTs", "FFTW_jll", "LinearAlgebra", "MKL_jll", "Preferences", "Reexport"]
git-tree-sha1 = "463cb335fa22c4ebacfd1faba5fde14edb80d96c"
uuid = "7a1cc6ca-52ef-59f5-83cd-3a7055c09341"
version = "1.4.5"

[[deps.FFTW_jll]]
deps = ["Artifacts", "JLLWrappers", "Libdl", "Pkg"]
git-tree-sha1 = "c6033cc3892d0ef5bb9cd29b7f2f0331ea5184ea"
uuid = "f5851436-0d7a-5f13-b9de-f02708fd171a"
version = "3.3.10+0"

[[deps.FileIO]]
deps = ["Pkg", "Requires", "UUIDs"]
git-tree-sha1 = "80ced645013a5dbdc52cf70329399c35ce007fae"
uuid = "5789e2e9-d7fb-5bc7-8068-2c6fae9b9549"
version = "1.13.0"

[[deps.FillArrays]]
deps = ["LinearAlgebra", "Random", "SparseArrays", "Statistics"]
git-tree-sha1 = "4c7d3757f3ecbcb9055870351078552b7d1dbd2d"
uuid = "1a297f60-69ca-5386-bcde-b61e274b549b"
version = "0.13.0"

[[deps.FixedPointNumbers]]
deps = ["Statistics"]
git-tree-sha1 = "335bfdceacc84c5cdf16aadc768aa5ddfc5383cc"
uuid = "53c48c17-4a7d-5ca2-90c5-79b7896eea93"
version = "0.8.4"

[[deps.Fontconfig_jll]]
deps = ["Artifacts", "Bzip2_jll", "Expat_jll", "FreeType2_jll", "JLLWrappers", "Libdl", "Libuuid_jll", "Pkg", "Zlib_jll"]
git-tree-sha1 = "21efd19106a55620a188615da6d3d06cd7f6ee03"
uuid = "a3f928ae-7b40-5064-980b-68af3947d34b"
version = "2.13.93+0"

[[deps.Formatting]]
deps = ["Printf"]
git-tree-sha1 = "8339d61043228fdd3eb658d86c926cb282ae72a8"
uuid = "59287772-0a20-5a39-b81b-1366585eb4c0"
version = "0.4.2"

[[deps.FreeType]]
deps = ["CEnum", "FreeType2_jll"]
git-tree-sha1 = "cabd77ab6a6fdff49bfd24af2ebe76e6e018a2b4"
uuid = "b38be410-82b0-50bf-ab77-7b57e271db43"
version = "4.0.0"

[[deps.FreeType2_jll]]
deps = ["Artifacts", "Bzip2_jll", "JLLWrappers", "Libdl", "Pkg", "Zlib_jll"]
git-tree-sha1 = "87eb71354d8ec1a96d4a7636bd57a7347dde3ef9"
uuid = "d7e528f0-a631-5988-bf34-fe36492bcfd7"
version = "2.10.4+0"

[[deps.FreeTypeAbstraction]]
deps = ["ColorVectorSpace", "Colors", "FreeType", "GeometryBasics", "StaticArrays"]
git-tree-sha1 = "770050893e7bc8a34915b4b9298604a3236de834"
uuid = "663a7486-cb36-511b-a19d-713bb74d65c9"
version = "0.9.5"

[[deps.FriBidi_jll]]
deps = ["Artifacts", "JLLWrappers", "Libdl", "Pkg"]
git-tree-sha1 = "aa31987c2ba8704e23c6c8ba8a4f769d5d7e4f91"
uuid = "559328eb-81f9-559d-9380-de523a88c83c"
version = "1.0.10+0"

[[deps.GeometryBasics]]
deps = ["EarCut_jll", "IterTools", "LinearAlgebra", "StaticArrays", "StructArrays", "Tables"]
git-tree-sha1 = "58bcdf5ebc057b085e58d95c138725628dd7453c"
uuid = "5c1252a2-5f33-56bf-86c9-59e7332b4326"
version = "0.4.1"

[[deps.Gettext_jll]]
deps = ["Artifacts", "CompilerSupportLibraries_jll", "JLLWrappers", "Libdl", "Libiconv_jll", "Pkg", "XML2_jll"]
git-tree-sha1 = "9b02998aba7bf074d14de89f9d37ca24a1a0b046"
uuid = "78b55507-aeef-58d4-861c-77aaff3498b1"
version = "0.21.0+0"

[[deps.Glib_jll]]
deps = ["Artifacts", "Gettext_jll", "JLLWrappers", "Libdl", "Libffi_jll", "Libiconv_jll", "Libmount_jll", "PCRE_jll", "Pkg", "Zlib_jll"]
git-tree-sha1 = "a32d672ac2c967f3deb8a81d828afc739c838a06"
uuid = "7746bdde-850d-59dc-9ae8-88ece973131d"
version = "2.68.3+2"

[[deps.Graphics]]
deps = ["Colors", "LinearAlgebra", "NaNMath"]
git-tree-sha1 = "1c5a84319923bea76fa145d49e93aa4394c73fc2"
uuid = "a2bd30eb-e257-5431-a919-1863eab51364"
version = "1.1.1"

[[deps.Graphite2_jll]]
deps = ["Artifacts", "JLLWrappers", "Libdl", "Pkg"]
git-tree-sha1 = "344bf40dcab1073aca04aa0df4fb092f920e4011"
uuid = "3b182d85-2403-5c21-9c21-1e1f0cc25472"
version = "1.3.14+0"

[[deps.GridLayoutBase]]
deps = ["GeometryBasics", "InteractiveUtils", "Observables"]
git-tree-sha1 = "169c3dc5acae08835a573a8a3e25c62f689f8b5c"
uuid = "3955a311-db13-416c-9275-1d80ed98e5e9"
version = "0.6.5"

[[deps.Grisu]]
git-tree-sha1 = "53bb909d1151e57e2484c3d1b53e19552b887fb2"
uuid = "42e2da0e-8278-4e71-bc24-59509adca0fe"
version = "1.0.2"

[[deps.HDF5_jll]]
deps = ["Artifacts", "JLLWrappers", "LibCURL_jll", "Libdl", "OpenSSL_jll", "Pkg", "Zlib_jll"]
git-tree-sha1 = "bab67c0d1c4662d2c4be8c6007751b0b6111de5c"
uuid = "0234f1f7-429e-5d53-9886-15a909be8d59"
version = "1.12.1+0"

[[deps.HarfBuzz_jll]]
deps = ["Artifacts", "Cairo_jll", "Fontconfig_jll", "FreeType2_jll", "Glib_jll", "Graphite2_jll", "JLLWrappers", "Libdl", "Libffi_jll", "Pkg"]
git-tree-sha1 = "129acf094d168394e80ee1dc4bc06ec835e510a3"
uuid = "2e76f6c2-a576-52d4-95c1-20adfe4de566"
version = "2.8.1+1"

[[deps.HypergeometricFunctions]]
deps = ["DualNumbers", "LinearAlgebra", "SpecialFunctions", "Test"]
git-tree-sha1 = "65e4589030ef3c44d3b90bdc5aac462b4bb05567"
uuid = "34004b35-14d8-5ef3-9330-4cdb6864b03a"
version = "0.3.8"

[[deps.Hyperscript]]
deps = ["Test"]
git-tree-sha1 = "8d511d5b81240fc8e6802386302675bdf47737b9"
uuid = "47d2ed2b-36de-50cf-bf87-49c2cf4b8b91"
version = "0.0.4"

[[deps.HypertextLiteral]]
git-tree-sha1 = "2b078b5a615c6c0396c77810d92ee8c6f470d238"
uuid = "ac1192a8-f4b3-4bfe-ba22-af5b92cd3ab2"
version = "0.9.3"

[[deps.IOCapture]]
deps = ["Logging", "Random"]
git-tree-sha1 = "f7be53659ab06ddc986428d3a9dcc95f6fa6705a"
uuid = "b5f81e59-6552-4d32-b1f0-c071b021bf89"
version = "0.2.2"

[[deps.IfElse]]
git-tree-sha1 = "debdd00ffef04665ccbb3e150747a77560e8fad1"
uuid = "615f187c-cbe4-4ef1-ba3b-2fcf58d6d173"
version = "0.1.1"

[[deps.ImageCore]]
deps = ["AbstractFFTs", "ColorVectorSpace", "Colors", "FixedPointNumbers", "Graphics", "MappedArrays", "MosaicViews", "OffsetArrays", "PaddedViews", "Reexport"]
git-tree-sha1 = "9a5c62f231e5bba35695a20988fc7cd6de7eeb5a"
uuid = "a09fc81d-aa75-5fe9-8630-4744c3626534"
version = "0.9.3"

[[deps.ImageIO]]
deps = ["FileIO", "JpegTurbo", "Netpbm", "OpenEXR", "PNGFiles", "QOI", "Sixel", "TiffImages", "UUIDs"]
git-tree-sha1 = "464bdef044df52e6436f8c018bea2d48c40bb27b"
uuid = "82e4d734-157c-48bb-816b-45c225c6df19"
version = "0.6.1"

[[deps.Imath_jll]]
deps = ["Artifacts", "JLLWrappers", "Libdl", "Pkg"]
git-tree-sha1 = "87f7662e03a649cffa2e05bf19c303e168732d3e"
uuid = "905a6f67-0a94-5f89-b386-d35d92009cd1"
version = "3.1.2+0"

[[deps.IndirectArrays]]
git-tree-sha1 = "012e604e1c7458645cb8b436f8fba789a51b257f"
uuid = "9b13fd28-a010-5f03-acff-a1bbcff69959"
version = "1.0.0"

[[deps.Inflate]]
git-tree-sha1 = "f5fc07d4e706b84f72d54eedcc1c13d92fb0871c"
uuid = "d25df0c9-e2be-5dd7-82c8-3ad0b3e990b9"
version = "0.1.2"

[[deps.IntelOpenMP_jll]]
deps = ["Artifacts", "JLLWrappers", "Libdl", "Pkg"]
git-tree-sha1 = "d979e54b71da82f3a65b62553da4fc3d18c9004c"
uuid = "1d5cc7b8-4909-519e-a0f8-d0f5ad9712d0"
version = "2018.0.3+2"

[[deps.InteractiveUtils]]
deps = ["Markdown"]
uuid = "b77e0a4c-d291-57a0-90e8-8db25a27a240"

[[deps.Interpolations]]
deps = ["AxisAlgorithms", "ChainRulesCore", "LinearAlgebra", "OffsetArrays", "Random", "Ratios", "Requires", "SharedArrays", "SparseArrays", "StaticArrays", "WoodburyMatrices"]
git-tree-sha1 = "b15fc0a95c564ca2e0a7ae12c1f095ca848ceb31"
uuid = "a98d9a8b-a2ab-59e6-89dd-64a1c18fca59"
version = "0.13.5"

[[deps.IntervalSets]]
deps = ["Dates", "EllipsisNotation", "Statistics"]
git-tree-sha1 = "3cc368af3f110a767ac786560045dceddfc16758"
uuid = "8197267c-284f-5f27-9208-e0e47529a953"
version = "0.5.3"

[[deps.InverseFunctions]]
deps = ["Test"]
git-tree-sha1 = "a7254c0acd8e62f1ac75ad24d5db43f5f19f3c65"
uuid = "3587e190-3f89-42d0-90ee-14403ec27112"
version = "0.1.2"

[[deps.IrrationalConstants]]
git-tree-sha1 = "7fd44fd4ff43fc60815f8e764c0f352b83c49151"
uuid = "92d709cd-6900-40b7-9082-c6be49f344b6"
version = "0.1.1"

[[deps.Isoband]]
deps = ["isoband_jll"]
git-tree-sha1 = "f9b6d97355599074dc867318950adaa6f9946137"
uuid = "f1662d9f-8043-43de-a69a-05efc1cc6ff4"
version = "0.1.1"

[[deps.IterTools]]
git-tree-sha1 = "fa6287a4469f5e048d763df38279ee729fbd44e5"
uuid = "c8e1da08-722c-5040-9ed9-7db0dc04731e"
version = "1.4.0"

[[deps.IteratorInterfaceExtensions]]
git-tree-sha1 = "a3f24677c21f5bbe9d2a714f95dcd58337fb2856"
uuid = "82899510-4779-5014-852e-03e436cf321d"
version = "1.0.0"

[[deps.JLLWrappers]]
deps = ["Preferences"]
git-tree-sha1 = "abc9885a7ca2052a736a600f7fa66209f96506e1"
uuid = "692b3bcd-3c85-4b1f-b108-f13ce0eb3210"
version = "1.4.1"

[[deps.JSON]]
deps = ["Dates", "Mmap", "Parsers", "Unicode"]
git-tree-sha1 = "3c837543ddb02250ef42f4738347454f95079d4e"
uuid = "682c06a0-de6a-54ab-a142-c8b1cf79cde6"
version = "0.21.3"

[[deps.JpegTurbo]]
deps = ["CEnum", "FileIO", "ImageCore", "JpegTurbo_jll", "TOML"]
git-tree-sha1 = "a77b273f1ddec645d1b7c4fd5fb98c8f90ad10a5"
uuid = "b835a17e-a41a-41e7-81f0-2f016b05efe0"
version = "0.1.1"

[[deps.JpegTurbo_jll]]
deps = ["Artifacts", "JLLWrappers", "Libdl", "Pkg"]
git-tree-sha1 = "b53380851c6e6664204efb2e62cd24fa5c47e4ba"
uuid = "aacddb02-875f-59d6-b918-886e6ef4fbf8"
version = "2.1.2+0"

[[deps.KernelDensity]]
deps = ["Distributions", "DocStringExtensions", "FFTW", "Interpolations", "StatsBase"]
git-tree-sha1 = "591e8dc09ad18386189610acafb970032c519707"
uuid = "5ab0869b-81aa-558d-bb23-cbf5423bbe9b"
version = "0.6.3"

[[deps.LAME_jll]]
deps = ["Artifacts", "JLLWrappers", "Libdl", "Pkg"]
git-tree-sha1 = "f6250b16881adf048549549fba48b1161acdac8c"
uuid = "c1c5ebd0-6772-5130-a774-d5fcae4a789d"
version = "3.100.1+0"

[[deps.LZO_jll]]
deps = ["Artifacts", "JLLWrappers", "Libdl", "Pkg"]
git-tree-sha1 = "e5b909bcf985c5e2605737d2ce278ed791b89be6"
uuid = "dd4b983a-f0e5-5f8d-a1b7-129d4a5fb1ac"
version = "2.10.1+0"

[[deps.LaTeXStrings]]
git-tree-sha1 = "f2355693d6778a178ade15952b7ac47a4ff97996"
uuid = "b964fa9f-0449-5b57-a5c2-d3ea65f4040f"
version = "1.3.0"

[[deps.LazyArtifacts]]
deps = ["Artifacts", "Pkg"]
uuid = "4af54fe1-eca0-43a8-85a7-787d91b784e3"

[[deps.LibCURL]]
deps = ["LibCURL_jll", "MozillaCACerts_jll"]
uuid = "b27032c2-a3e7-50c8-80cd-2d36dbcbfd21"

[[deps.LibCURL_jll]]
deps = ["Artifacts", "LibSSH2_jll", "Libdl", "MbedTLS_jll", "Zlib_jll", "nghttp2_jll"]
uuid = "deac9b47-8bc7-5906-a0fe-35ac56dc84c0"

[[deps.LibGit2]]
deps = ["Base64", "NetworkOptions", "Printf", "SHA"]
uuid = "76f85450-5226-5b5a-8eaa-529ad045b433"

[[deps.LibSSH2_jll]]
deps = ["Artifacts", "Libdl", "MbedTLS_jll"]
uuid = "29816b5a-b9ab-546f-933c-edad1886dfa8"

[[deps.Libdl]]
uuid = "8f399da3-3557-5675-b5ff-fb832c97cbdb"

[[deps.Libffi_jll]]
deps = ["Artifacts", "JLLWrappers", "Libdl", "Pkg"]
git-tree-sha1 = "0b4a5d71f3e5200a7dff793393e09dfc2d874290"
uuid = "e9f186c6-92d2-5b65-8a66-fee21dc1b490"
version = "3.2.2+1"

[[deps.Libgcrypt_jll]]
deps = ["Artifacts", "JLLWrappers", "Libdl", "Libgpg_error_jll", "Pkg"]
git-tree-sha1 = "64613c82a59c120435c067c2b809fc61cf5166ae"
uuid = "d4300ac3-e22c-5743-9152-c294e39db1e4"
version = "1.8.7+0"

[[deps.Libgpg_error_jll]]
deps = ["Artifacts", "JLLWrappers", "Libdl", "Pkg"]
git-tree-sha1 = "c333716e46366857753e273ce6a69ee0945a6db9"
uuid = "7add5ba3-2f88-524e-9cd5-f83b8a55f7b8"
version = "1.42.0+0"

[[deps.Libiconv_jll]]
deps = ["Artifacts", "JLLWrappers", "Libdl", "Pkg"]
git-tree-sha1 = "42b62845d70a619f063a7da093d995ec8e15e778"
uuid = "94ce4f54-9a6c-5748-9c1c-f9c7231a4531"
version = "1.16.1+1"

[[deps.Libmount_jll]]
deps = ["Artifacts", "JLLWrappers", "Libdl", "Pkg"]
git-tree-sha1 = "9c30530bf0effd46e15e0fdcf2b8636e78cbbd73"
uuid = "4b2f31a3-9ecc-558c-b454-b3730dcb73e9"
version = "2.35.0+0"

[[deps.Libuuid_jll]]
deps = ["Artifacts", "JLLWrappers", "Libdl", "Pkg"]
git-tree-sha1 = "7f3efec06033682db852f8b3bc3c1d2b0a0ab066"
uuid = "38a345b3-de98-5d2b-a5d3-14cd9215e700"
version = "2.36.0+0"

[[deps.LinearAlgebra]]
deps = ["Libdl", "libblastrampoline_jll"]
uuid = "37e2e46d-f89d-539d-b4ee-838fcccc9c8e"

[[deps.LogExpFunctions]]
deps = ["ChainRulesCore", "ChangesOfVariables", "DocStringExtensions", "InverseFunctions", "IrrationalConstants", "LinearAlgebra"]
git-tree-sha1 = "e5718a00af0ab9756305a0392832c8952c7426c1"
uuid = "2ab3a3ac-af41-5b50-aa03-7779005ae688"
version = "0.3.6"

[[deps.Logging]]
uuid = "56ddb016-857b-54e1-b83d-db4d58db5568"

[[deps.MKL_jll]]
deps = ["Artifacts", "IntelOpenMP_jll", "JLLWrappers", "LazyArtifacts", "Libdl", "Pkg"]
git-tree-sha1 = "5455aef09b40e5020e1520f551fa3135040d4ed0"
uuid = "856f044c-d86e-5d09-b602-aeab76dc8ba7"
version = "2021.1.1+2"

[[deps.Makie]]
deps = ["Animations", "Base64", "ColorBrewer", "ColorSchemes", "ColorTypes", "Colors", "Contour", "Distributions", "DocStringExtensions", "FFMPEG", "FileIO", "FixedPointNumbers", "Formatting", "FreeType", "FreeTypeAbstraction", "GeometryBasics", "GridLayoutBase", "ImageIO", "IntervalSets", "Isoband", "KernelDensity", "LaTeXStrings", "LinearAlgebra", "MakieCore", "Markdown", "Match", "MathTeXEngine", "Observables", "OffsetArrays", "Packing", "PlotUtils", "PolygonOps", "Printf", "Random", "RelocatableFolders", "Serialization", "Showoff", "SignedDistanceFields", "SparseArrays", "StaticArrays", "Statistics", "StatsBase", "StatsFuns", "StructArrays", "UnicodeFun"]
git-tree-sha1 = "cd0fd02ab0d129f03515b7b68ca77fb670ef2e61"
uuid = "ee78f7c6-11fb-53f2-987a-cfe4a2b5a57a"
version = "0.16.5"

[[deps.MakieCore]]
deps = ["Observables"]
git-tree-sha1 = "c5fb1bfac781db766f9e4aef96adc19a729bc9b2"
uuid = "20f20a25-4f0e-4fdf-b5d1-57303727442b"
version = "0.2.1"

[[deps.MappedArrays]]
git-tree-sha1 = "e8b359ef06ec72e8c030463fe02efe5527ee5142"
uuid = "dbb5928d-eab1-5f90-85c2-b9b0edb7c900"
version = "0.4.1"

[[deps.Markdown]]
deps = ["Base64"]
uuid = "d6f4376e-aef5-505a-96c1-9c027394607a"

[[deps.Match]]
git-tree-sha1 = "1d9bc5c1a6e7ee24effb93f175c9342f9154d97f"
uuid = "7eb4fadd-790c-5f42-8a69-bfa0b872bfbf"
version = "1.2.0"

[[deps.MathTeXEngine]]
deps = ["AbstractTrees", "Automa", "DataStructures", "FreeTypeAbstraction", "GeometryBasics", "LaTeXStrings", "REPL", "RelocatableFolders", "Test"]
git-tree-sha1 = "70e733037bbf02d691e78f95171a1fa08cdc6332"
uuid = "0a4f8689-d25c-4efe-a92b-7142dfc1aa53"
version = "0.2.1"

[[deps.MbedTLS_jll]]
deps = ["Artifacts", "Libdl"]
uuid = "c8ffd9c3-330d-5841-b78e-0817d7145fa1"

[[deps.Missings]]
deps = ["DataAPI"]
git-tree-sha1 = "bf210ce90b6c9eed32d25dbcae1ebc565df2687f"
uuid = "e1d29d7a-bbdc-5cf2-9ac0-f12de2c33e28"
version = "1.0.2"

[[deps.Mmap]]
uuid = "a63ad114-7e13-5084-954f-fe012c677804"

[[deps.MosaicViews]]
deps = ["MappedArrays", "OffsetArrays", "PaddedViews", "StackViews"]
git-tree-sha1 = "b34e3bc3ca7c94914418637cb10cc4d1d80d877d"
uuid = "e94cdb99-869f-56ef-bcf0-1ae2bcbe0389"
version = "0.3.3"

[[deps.MozillaCACerts_jll]]
uuid = "14a3606d-f60d-562e-9121-12d972cd8159"

[[deps.NCDatasets]]
deps = ["CFTime", "DataStructures", "Dates", "NetCDF_jll", "Printf"]
git-tree-sha1 = "17e39eb5bbe564f48bdbefbd103bd3f49fcfcb9b"
uuid = "85f8d34a-cbdd-5861-8df4-14fed0d494ab"
version = "0.11.9"

[[deps.NaNMath]]
git-tree-sha1 = "b086b7ea07f8e38cf122f5016af580881ac914fe"
uuid = "77ba4419-2d1f-58cd-9bb1-8ffee604a2e3"
version = "0.3.7"

[[deps.NetCDF_jll]]
deps = ["Artifacts", "HDF5_jll", "JLLWrappers", "LibCURL_jll", "LibSSH2_jll", "Libdl", "MbedTLS_jll", "Pkg", "Zlib_jll", "nghttp2_jll"]
git-tree-sha1 = "598f1a5e9829b3e57f233f98b34a22b376dff373"
uuid = "7243133f-43d8-5620-bbf4-c2c921802cf3"
version = "400.702.402+0"

[[deps.Netpbm]]
deps = ["FileIO", "ImageCore"]
git-tree-sha1 = "18efc06f6ec36a8b801b23f076e3c6ac7c3bf153"
uuid = "f09324ee-3d7c-5217-9330-fc30815ba969"
version = "1.0.2"

[[deps.NetworkOptions]]
uuid = "ca575930-c2e3-43a9-ace4-1e988b2c1908"

[[deps.Observables]]
git-tree-sha1 = "fe29afdef3d0c4a8286128d4e45cc50621b1e43d"
uuid = "510215fc-4207-5dde-b226-833fc4488ee2"
version = "0.4.0"

[[deps.OffsetArrays]]
deps = ["Adapt"]
git-tree-sha1 = "043017e0bdeff61cfbb7afeb558ab29536bbb5ed"
uuid = "6fe1bfb0-de20-5000-8ca7-80f57d26f881"
version = "1.10.8"

[[deps.Ogg_jll]]
deps = ["Artifacts", "JLLWrappers", "Libdl", "Pkg"]
git-tree-sha1 = "887579a3eb005446d514ab7aeac5d1d027658b8f"
uuid = "e7412a2a-1a6e-54c0-be00-318e2571c051"
version = "1.3.5+1"

[[deps.OpenBLAS_jll]]
deps = ["Artifacts", "CompilerSupportLibraries_jll", "Libdl"]
uuid = "4536629a-c528-5b80-bd46-f80d51c5b363"

[[deps.OpenEXR]]
deps = ["Colors", "FileIO", "OpenEXR_jll"]
git-tree-sha1 = "327f53360fdb54df7ecd01e96ef1983536d1e633"
uuid = "52e1d378-f018-4a11-a4be-720524705ac7"
version = "0.3.2"

[[deps.OpenEXR_jll]]
deps = ["Artifacts", "Imath_jll", "JLLWrappers", "Libdl", "Pkg", "Zlib_jll"]
git-tree-sha1 = "923319661e9a22712f24596ce81c54fc0366f304"
uuid = "18a262bb-aa17-5467-a713-aee519bc75cb"
version = "3.1.1+0"

[[deps.OpenLibm_jll]]
deps = ["Artifacts", "Libdl"]
uuid = "05823500-19ac-5b8b-9628-191a04bc5112"

[[deps.OpenSSL_jll]]
deps = ["Artifacts", "JLLWrappers", "Libdl", "Pkg"]
git-tree-sha1 = "648107615c15d4e09f7eca16307bc821c1f718d8"
uuid = "458c3c95-2e84-50aa-8efc-19380b2a3a95"
version = "1.1.13+0"

[[deps.OpenSpecFun_jll]]
deps = ["Artifacts", "CompilerSupportLibraries_jll", "JLLWrappers", "Libdl", "Pkg"]
git-tree-sha1 = "13652491f6856acfd2db29360e1bbcd4565d04f1"
uuid = "efe28fd5-8261-553b-a9e1-b2916fc3738e"
version = "0.5.5+0"

[[deps.Opus_jll]]
deps = ["Artifacts", "JLLWrappers", "Libdl", "Pkg"]
git-tree-sha1 = "51a08fb14ec28da2ec7a927c4337e4332c2a4720"
uuid = "91d4177d-7536-5919-b921-800302f37372"
version = "1.3.2+0"

[[deps.OrderedCollections]]
git-tree-sha1 = "85f8e6578bf1f9ee0d11e7bb1b1456435479d47c"
uuid = "bac558e1-5e72-5ebc-8fee-abe8a469f55d"
version = "1.4.1"

[[deps.PCRE_jll]]
deps = ["Artifacts", "JLLWrappers", "Libdl", "Pkg"]
git-tree-sha1 = "b2a7af664e098055a7529ad1a900ded962bca488"
uuid = "2f80f16e-611a-54ab-bc61-aa92de5b98fc"
version = "8.44.0+0"

[[deps.PDMats]]
deps = ["LinearAlgebra", "SparseArrays", "SuiteSparse"]
git-tree-sha1 = "7e2166042d1698b6072352c74cfd1fca2a968253"
uuid = "90014a1f-27ba-587c-ab20-58faa44d9150"
version = "0.11.6"

[[deps.PNGFiles]]
deps = ["Base64", "CEnum", "ImageCore", "IndirectArrays", "OffsetArrays", "libpng_jll"]
git-tree-sha1 = "eb4dbb8139f6125471aa3da98fb70f02dc58e49c"
uuid = "f57f5aa1-a3ce-4bc8-8ab9-96f992907883"
version = "0.3.14"

[[deps.Packing]]
deps = ["GeometryBasics"]
git-tree-sha1 = "1155f6f937fa2b94104162f01fa400e192e4272f"
uuid = "19eb6ba3-879d-56ad-ad62-d5c202156566"
version = "0.4.2"

[[deps.PaddedViews]]
deps = ["OffsetArrays"]
git-tree-sha1 = "03a7a85b76381a3d04c7a1656039197e70eda03d"
uuid = "5432bcbf-9aad-5242-b902-cca2824c8663"
version = "0.5.11"

[[deps.Pango_jll]]
deps = ["Artifacts", "Cairo_jll", "Fontconfig_jll", "FreeType2_jll", "FriBidi_jll", "Glib_jll", "HarfBuzz_jll", "JLLWrappers", "Libdl", "Pkg"]
git-tree-sha1 = "3a121dfbba67c94a5bec9dde613c3d0cbcf3a12b"
uuid = "36c8627f-9965-5494-a995-c6b170f724f3"
version = "1.50.3+0"

[[deps.Parsers]]
deps = ["Dates"]
git-tree-sha1 = "13468f237353112a01b2d6b32f3d0f80219944aa"
uuid = "69de0a69-1ddd-5017-9359-2bf0b02dc9f0"
version = "2.2.2"

[[deps.Pixman_jll]]
deps = ["Artifacts", "JLLWrappers", "Libdl", "Pkg"]
git-tree-sha1 = "b4f5d02549a10e20780a24fce72bea96b6329e29"
uuid = "30392449-352a-5448-841d-b1acce4e97dc"
version = "0.40.1+0"

[[deps.Pkg]]
deps = ["Artifacts", "Dates", "Downloads", "LibGit2", "Libdl", "Logging", "Markdown", "Printf", "REPL", "Random", "SHA", "Serialization", "TOML", "Tar", "UUIDs", "p7zip_jll"]
uuid = "44cfe95a-1eb2-52ea-b672-e2afdf69b78f"

[[deps.PkgVersion]]
deps = ["Pkg"]
git-tree-sha1 = "a7a7e1a88853564e551e4eba8650f8c38df79b37"
uuid = "eebad327-c553-4316-9ea0-9fa01ccd7688"
version = "0.1.1"

[[deps.PlotUtils]]
deps = ["ColorSchemes", "Colors", "Dates", "Printf", "Random", "Reexport", "Statistics"]
git-tree-sha1 = "6f1b25e8ea06279b5689263cc538f51331d7ca17"
uuid = "995b91a9-d308-5afd-9ec6-746e21dbc043"
version = "1.1.3"

[[deps.PlutoUI]]
deps = ["AbstractPlutoDingetjes", "Base64", "ColorTypes", "Dates", "Hyperscript", "HypertextLiteral", "IOCapture", "InteractiveUtils", "JSON", "Logging", "Markdown", "Random", "Reexport", "UUIDs"]
git-tree-sha1 = "85bf3e4bd279e405f91489ce518dedb1e32119cb"
uuid = "7f904dfe-b85e-4ff6-b463-dae2292396a8"
version = "0.7.35"

[[deps.PolygonOps]]
git-tree-sha1 = "77b3d3605fc1cd0b42d95eba87dfcd2bf67d5ff6"
uuid = "647866c9-e3ac-4575-94e7-e3d426903924"
version = "0.1.2"

[[deps.Preferences]]
deps = ["TOML"]
git-tree-sha1 = "de893592a221142f3db370f48290e3a2ef39998f"
uuid = "21216c6a-2e73-6563-6e65-726566657250"
version = "1.2.4"

[[deps.Printf]]
deps = ["Unicode"]
uuid = "de0858da-6303-5e67-8744-51eddeeeb8d7"

[[deps.ProgressMeter]]
deps = ["Distributed", "Printf"]
git-tree-sha1 = "afadeba63d90ff223a6a48d2009434ecee2ec9e8"
uuid = "92933f4c-e287-5a05-a399-4b506db050ca"
version = "1.7.1"

[[deps.QOI]]
deps = ["ColorTypes", "FileIO", "FixedPointNumbers"]
git-tree-sha1 = "18e8f4d1426e965c7b532ddd260599e1510d26ce"
uuid = "4b34888f-f399-49d4-9bb3-47ed5cae4e65"
version = "1.0.0"

[[deps.QuadGK]]
deps = ["DataStructures", "LinearAlgebra"]
git-tree-sha1 = "78aadffb3efd2155af139781b8a8df1ef279ea39"
uuid = "1fd47b50-473d-5c70-9696-f719f8f3bcdc"
version = "2.4.2"

[[deps.REPL]]
deps = ["InteractiveUtils", "Markdown", "Sockets", "Unicode"]
uuid = "3fa0cd96-eef1-5676-8a61-b3b8758bbffb"

[[deps.Random]]
deps = ["SHA", "Serialization"]
uuid = "9a3f8284-a2c9-5f02-9a11-845980a1fd5c"

[[deps.Ratios]]
deps = ["Requires"]
git-tree-sha1 = "01d341f502250e81f6fec0afe662aa861392a3aa"
uuid = "c84ed2f1-dad5-54f0-aa8e-dbefe2724439"
version = "0.4.2"

[[deps.Reexport]]
git-tree-sha1 = "45e428421666073eab6f2da5c9d310d99bb12f9b"
uuid = "189a3867-3050-52da-a836-e630ba90ab69"
version = "1.2.2"

[[deps.RelocatableFolders]]
deps = ["SHA", "Scratch"]
git-tree-sha1 = "cdbd3b1338c72ce29d9584fdbe9e9b70eeb5adca"
uuid = "05181044-ff0b-4ac5-8273-598c1e38db00"
version = "0.1.3"

[[deps.Requires]]
deps = ["UUIDs"]
git-tree-sha1 = "838a3a4188e2ded87a4f9f184b4b0d78a1e91cb7"
uuid = "ae029012-a4dd-5104-9daa-d747884805df"
version = "1.3.0"

[[deps.Rmath]]
deps = ["Random", "Rmath_jll"]
git-tree-sha1 = "bf3188feca147ce108c76ad82c2792c57abe7b1f"
uuid = "79098fc4-a85e-5d69-aa6a-4863f24498fa"
version = "0.7.0"

[[deps.Rmath_jll]]
deps = ["Artifacts", "JLLWrappers", "Libdl", "Pkg"]
git-tree-sha1 = "68db32dff12bb6127bac73c209881191bf0efbb7"
uuid = "f50d1b31-88e8-58de-be2c-1cc44531875f"
version = "0.3.0+0"

[[deps.SHA]]
uuid = "ea8e919c-243c-51af-8825-aaa63cd721ce"

[[deps.SIMD]]
git-tree-sha1 = "39e3df417a0dd0c4e1f89891a281f82f5373ea3b"
uuid = "fdea26ae-647d-5447-a871-4b548cad5224"
version = "3.4.0"

[[deps.ScanByte]]
deps = ["Libdl", "SIMD"]
git-tree-sha1 = "9cc2955f2a254b18be655a4ee70bc4031b2b189e"
uuid = "7b38b023-a4d7-4c5e-8d43-3f3097f304eb"
version = "0.3.0"

[[deps.Scratch]]
deps = ["Dates"]
git-tree-sha1 = "0b4b7f1393cff97c33891da2a0bf69c6ed241fda"
uuid = "6c6a2e73-6563-6170-7368-637461726353"
version = "1.1.0"

[[deps.Serialization]]
uuid = "9e88b42a-f829-5b0c-bbe9-9e923198166b"

[[deps.SharedArrays]]
deps = ["Distributed", "Mmap", "Random", "Serialization"]
uuid = "1a1011a3-84de-559e-8e89-a11a2f7dc383"

[[deps.Showoff]]
deps = ["Dates", "Grisu"]
git-tree-sha1 = "91eddf657aca81df9ae6ceb20b959ae5653ad1de"
uuid = "992d4aef-0814-514b-bc4d-f2e9a6c4116f"
version = "1.0.3"

[[deps.SignedDistanceFields]]
deps = ["Random", "Statistics", "Test"]
git-tree-sha1 = "d263a08ec505853a5ff1c1ebde2070419e3f28e9"
uuid = "73760f76-fbc4-59ce-8f25-708e95d2df96"
version = "0.4.0"

[[deps.Sixel]]
deps = ["Dates", "FileIO", "ImageCore", "IndirectArrays", "OffsetArrays", "REPL", "libsixel_jll"]
git-tree-sha1 = "8fb59825be681d451c246a795117f317ecbcaa28"
uuid = "45858cf5-a6b0-47a3-bbea-62219f50df47"
version = "0.1.2"

[[deps.Sockets]]
uuid = "6462fe0b-24de-5631-8697-dd941f90decc"

[[deps.SortingAlgorithms]]
deps = ["DataStructures"]
git-tree-sha1 = "b3363d7460f7d098ca0912c69b082f75625d7508"
uuid = "a2af1166-a08f-5f64-846c-94a0d3cef48c"
version = "1.0.1"

[[deps.SparseArrays]]
deps = ["LinearAlgebra", "Random"]
uuid = "2f01184e-e22b-5df5-ae63-d93ebab69eaf"

[[deps.SpecialFunctions]]
deps = ["ChainRulesCore", "IrrationalConstants", "LogExpFunctions", "OpenLibm_jll", "OpenSpecFun_jll"]
git-tree-sha1 = "5ba658aeecaaf96923dce0da9e703bd1fe7666f9"
uuid = "276daf66-3868-5448-9aa4-cd146d93841b"
version = "2.1.4"

[[deps.StackViews]]
deps = ["OffsetArrays"]
git-tree-sha1 = "46e589465204cd0c08b4bd97385e4fa79a0c770c"
uuid = "cae243ae-269e-4f55-b966-ac2d0dc13c15"
version = "0.1.1"

[[deps.Static]]
deps = ["IfElse"]
git-tree-sha1 = "65068e4b4d10f3c31aaae2e6cb92b6c6cedca610"
uuid = "aedffcd0-7271-4cad-89d0-dc628f76c6d3"
version = "0.5.6"

[[deps.StaticArrays]]
deps = ["LinearAlgebra", "Random", "Statistics"]
git-tree-sha1 = "74fb527333e72ada2dd9ef77d98e4991fb185f04"
uuid = "90137ffa-7385-5640-81b9-e52037218182"
version = "1.4.1"

[[deps.Statistics]]
deps = ["LinearAlgebra", "SparseArrays"]
uuid = "10745b16-79ce-11e8-11f9-7d13ad32a3b2"

[[deps.StatsAPI]]
deps = ["LinearAlgebra"]
git-tree-sha1 = "c3d8ba7f3fa0625b062b82853a7d5229cb728b6b"
uuid = "82ae8749-77ed-4fe6-ae5f-f523153014b0"
version = "1.2.1"

[[deps.StatsBase]]
deps = ["DataAPI", "DataStructures", "LinearAlgebra", "LogExpFunctions", "Missings", "Printf", "Random", "SortingAlgorithms", "SparseArrays", "Statistics", "StatsAPI"]
git-tree-sha1 = "8977b17906b0a1cc74ab2e3a05faa16cf08a8291"
uuid = "2913bbd2-ae8a-5f71-8c99-4fb6c76f3a91"
version = "0.33.16"

[[deps.StatsFuns]]
deps = ["ChainRulesCore", "HypergeometricFunctions", "InverseFunctions", "IrrationalConstants", "LogExpFunctions", "Reexport", "Rmath", "SpecialFunctions"]
git-tree-sha1 = "25405d7016a47cf2bd6cd91e66f4de437fd54a07"
uuid = "4c63d2b9-4356-54db-8cca-17b64c39e42c"
version = "0.9.16"

[[deps.StructArrays]]
deps = ["Adapt", "DataAPI", "StaticArrays", "Tables"]
git-tree-sha1 = "57617b34fa34f91d536eb265df67c2d4519b8b98"
uuid = "09ab397b-f2b6-538f-b94a-2f83cf4a842a"
version = "0.6.5"

[[deps.SuiteSparse]]
deps = ["Libdl", "LinearAlgebra", "Serialization", "SparseArrays"]
uuid = "4607b0f0-06f3-5cda-b6b1-a6196a1729e9"

[[deps.TOML]]
deps = ["Dates"]
uuid = "fa267f1f-6049-4f14-aa54-33bafae1ed76"

[[deps.TableTraits]]
deps = ["IteratorInterfaceExtensions"]
git-tree-sha1 = "c06b2f539df1c6efa794486abfb6ed2022561a39"
uuid = "3783bdb8-4a98-5b6b-af9a-565f29a5fe9c"
version = "1.0.1"

[[deps.Tables]]
deps = ["DataAPI", "DataValueInterfaces", "IteratorInterfaceExtensions", "LinearAlgebra", "TableTraits", "Test"]
git-tree-sha1 = "bb1064c9a84c52e277f1096cf41434b675cd368b"
uuid = "bd369af6-aec1-5ad0-b16a-f7cc5008161c"
version = "1.6.1"

[[deps.Tar]]
deps = ["ArgTools", "SHA"]
uuid = "a4e569a6-e804-4fa4-b0f3-eef7a1d5b13e"

[[deps.TensorCore]]
deps = ["LinearAlgebra"]
git-tree-sha1 = "1feb45f88d133a655e001435632f019a9a1bcdb6"
uuid = "62fd8b95-f654-4bbd-a8a5-9c27f68ccd50"
version = "0.1.1"

[[deps.Test]]
deps = ["InteractiveUtils", "Logging", "Random", "Serialization"]
uuid = "8dfed614-e22c-5e08-85e1-65c5234f0b40"

[[deps.TiffImages]]
deps = ["ColorTypes", "DataStructures", "DocStringExtensions", "FileIO", "FixedPointNumbers", "IndirectArrays", "Inflate", "OffsetArrays", "PkgVersion", "ProgressMeter", "UUIDs"]
git-tree-sha1 = "991d34bbff0d9125d93ba15887d6594e8e84b305"
uuid = "731e570b-9d59-4bfa-96dc-6df516fadf69"
version = "0.5.3"

[[deps.TranscodingStreams]]
deps = ["Random", "Test"]
git-tree-sha1 = "216b95ea110b5972db65aa90f88d8d89dcb8851c"
uuid = "3bb67fe8-82b1-5028-8e26-92a6c54297fa"
version = "0.9.6"

[[deps.UUIDs]]
deps = ["Random", "SHA"]
uuid = "cf7118a7-6976-5b1a-9a39-7adc72f591a4"

[[deps.Unicode]]
uuid = "4ec0a83e-493e-50e2-b9ac-8f72acf5a8f5"

[[deps.UnicodeFun]]
deps = ["REPL"]
git-tree-sha1 = "53915e50200959667e78a92a418594b428dffddf"
uuid = "1cfade01-22cf-5700-b092-accc4b62d6e1"
version = "0.4.1"

[[deps.WoodburyMatrices]]
deps = ["LinearAlgebra", "SparseArrays"]
git-tree-sha1 = "de67fa59e33ad156a590055375a30b23c40299d3"
uuid = "efce3f68-66dc-5838-9240-27a6d6f5f9b6"
version = "0.5.5"

[[deps.XML2_jll]]
deps = ["Artifacts", "JLLWrappers", "Libdl", "Libiconv_jll", "Pkg", "Zlib_jll"]
git-tree-sha1 = "1acf5bdf07aa0907e0a37d3718bb88d4b687b74a"
uuid = "02c8fc9c-b97f-50b9-bbe4-9be30ff0a78a"
version = "2.9.12+0"

[[deps.XSLT_jll]]
deps = ["Artifacts", "JLLWrappers", "Libdl", "Libgcrypt_jll", "Libgpg_error_jll", "Libiconv_jll", "Pkg", "XML2_jll", "Zlib_jll"]
git-tree-sha1 = "91844873c4085240b95e795f692c4cec4d805f8a"
uuid = "aed1982a-8fda-507f-9586-7b0439959a61"
version = "1.1.34+0"

[[deps.Xorg_libX11_jll]]
deps = ["Artifacts", "JLLWrappers", "Libdl", "Pkg", "Xorg_libxcb_jll", "Xorg_xtrans_jll"]
git-tree-sha1 = "5be649d550f3f4b95308bf0183b82e2582876527"
uuid = "4f6342f7-b3d2-589e-9d20-edeb45f2b2bc"
version = "1.6.9+4"

[[deps.Xorg_libXau_jll]]
deps = ["Artifacts", "JLLWrappers", "Libdl", "Pkg"]
git-tree-sha1 = "4e490d5c960c314f33885790ed410ff3a94ce67e"
uuid = "0c0b7dd1-d40b-584c-a123-a41640f87eec"
version = "1.0.9+4"

[[deps.Xorg_libXdmcp_jll]]
deps = ["Artifacts", "JLLWrappers", "Libdl", "Pkg"]
git-tree-sha1 = "4fe47bd2247248125c428978740e18a681372dd4"
uuid = "a3789734-cfe1-5b06-b2d0-1dd0d9d62d05"
version = "1.1.3+4"

[[deps.Xorg_libXext_jll]]
deps = ["Artifacts", "JLLWrappers", "Libdl", "Pkg", "Xorg_libX11_jll"]
git-tree-sha1 = "b7c0aa8c376b31e4852b360222848637f481f8c3"
uuid = "1082639a-0dae-5f34-9b06-72781eeb8cb3"
version = "1.3.4+4"

[[deps.Xorg_libXrender_jll]]
deps = ["Artifacts", "JLLWrappers", "Libdl", "Pkg", "Xorg_libX11_jll"]
git-tree-sha1 = "19560f30fd49f4d4efbe7002a1037f8c43d43b96"
uuid = "ea2f1a96-1ddc-540d-b46f-429655e07cfa"
version = "0.9.10+4"

[[deps.Xorg_libpthread_stubs_jll]]
deps = ["Artifacts", "JLLWrappers", "Libdl", "Pkg"]
git-tree-sha1 = "6783737e45d3c59a4a4c4091f5f88cdcf0908cbb"
uuid = "14d82f49-176c-5ed1-bb49-ad3f5cbd8c74"
version = "0.1.0+3"

[[deps.Xorg_libxcb_jll]]
deps = ["Artifacts", "JLLWrappers", "Libdl", "Pkg", "XSLT_jll", "Xorg_libXau_jll", "Xorg_libXdmcp_jll", "Xorg_libpthread_stubs_jll"]
git-tree-sha1 = "daf17f441228e7a3833846cd048892861cff16d6"
uuid = "c7cfdc94-dc32-55de-ac96-5a1b8d977c5b"
version = "1.13.0+3"

[[deps.Xorg_xtrans_jll]]
deps = ["Artifacts", "JLLWrappers", "Libdl", "Pkg"]
git-tree-sha1 = "79c31e7844f6ecf779705fbc12146eb190b7d845"
uuid = "c5fb5394-a638-5e4d-96e5-b29de1b5cf10"
version = "1.4.0+3"

[[deps.Zlib_jll]]
deps = ["Libdl"]
uuid = "83775a58-1f1d-513f-b197-d71354ab007a"

[[deps.isoband_jll]]
deps = ["Artifacts", "JLLWrappers", "Libdl", "Pkg"]
git-tree-sha1 = "51b5eeb3f98367157a7a12a1fb0aa5328946c03c"
uuid = "9a68df92-36a6-505f-a73e-abb412b6bfb4"
version = "0.2.3+0"

[[deps.libass_jll]]
deps = ["Artifacts", "Bzip2_jll", "FreeType2_jll", "FriBidi_jll", "HarfBuzz_jll", "JLLWrappers", "Libdl", "Pkg", "Zlib_jll"]
git-tree-sha1 = "5982a94fcba20f02f42ace44b9894ee2b140fe47"
uuid = "0ac62f75-1d6f-5e53-bd7c-93b484bb37c0"
version = "0.15.1+0"

[[deps.libblastrampoline_jll]]
deps = ["Artifacts", "Libdl", "OpenBLAS_jll"]
uuid = "8e850b90-86db-534c-a0d3-1478176c7d93"

[[deps.libfdk_aac_jll]]
deps = ["Artifacts", "JLLWrappers", "Libdl", "Pkg"]
git-tree-sha1 = "daacc84a041563f965be61859a36e17c4e4fcd55"
uuid = "f638f0a6-7fb0-5443-88ba-1cc74229b280"
version = "2.0.2+0"

[[deps.libpng_jll]]
deps = ["Artifacts", "JLLWrappers", "Libdl", "Pkg", "Zlib_jll"]
git-tree-sha1 = "94d180a6d2b5e55e447e2d27a29ed04fe79eb30c"
uuid = "b53b4c65-9356-5827-b1ea-8c7a1a84506f"
version = "1.6.38+0"

[[deps.libsixel_jll]]
deps = ["Artifacts", "JLLWrappers", "Libdl", "Pkg"]
git-tree-sha1 = "78736dab31ae7a53540a6b752efc61f77b304c5b"
uuid = "075b6546-f08a-558a-be8f-8157d0f608a5"
version = "1.8.6+1"

[[deps.libvorbis_jll]]
deps = ["Artifacts", "JLLWrappers", "Libdl", "Ogg_jll", "Pkg"]
git-tree-sha1 = "b910cb81ef3fe6e78bf6acee440bda86fd6ae00c"
uuid = "f27f6e37-5d2b-51aa-960f-b287f2bc3b7a"
version = "1.3.7+1"

[[deps.nghttp2_jll]]
deps = ["Artifacts", "Libdl"]
uuid = "8e850ede-7688-5339-a07c-302acd2aaf8d"

[[deps.p7zip_jll]]
deps = ["Artifacts", "Libdl"]
uuid = "3f19e933-33d8-53b3-aaab-bd5110c3b7a0"

[[deps.x264_jll]]
deps = ["Artifacts", "JLLWrappers", "Libdl", "Pkg"]
git-tree-sha1 = "4fea590b89e6ec504593146bf8b988b2c00922b2"
uuid = "1270edf5-f2f9-52d2-97e9-ab00b5d0237a"
version = "2021.5.5+0"

[[deps.x265_jll]]
deps = ["Artifacts", "JLLWrappers", "Libdl", "Pkg"]
git-tree-sha1 = "ee567a171cce03570d77ad3a43e90218e38937a9"
uuid = "dfaa095f-4041-5dcd-9319-2fabd8486b76"
version = "3.5.0+0"
"""

# ╔═╡ Cell order:
# ╟─edf5fb5f-cb8d-47d1-bd6f-be4605686a67
# ╟─b7cef3ea-da3d-496d-bd01-2cfb5d931777
# ╟─6e56775b-c730-4739-9964-0056b5d8260a
# ╠═cf5ea7f7-35be-4756-bcfa-5fad09148e69
# ╠═a8f1eae9-3c9f-4f0e-8b10-726127b7933f
# ╠═ce1f0e37-2d41-4648-9bcd-2d21079fac39
# ╟─213c15be-2e66-430f-b522-744ed4d55094
# ╠═dd4c4491-203f-421f-8617-93f525fe377d
# ╟─5afe78bb-fda0-48a0-bee6-9543d89819e8
# ╠═240851bb-6b44-4ffc-a7da-4c9640c79fb1
# ╠═baa6b7b8-e4bf-4a54-8341-0ccce0a65e9f
# ╟─d6da99a1-423a-4c85-8f43-8811c09c4595
# ╟─ec6e1fad-602c-465b-b54c-eeb45f5d70fe
# ╠═e4f7d5fd-0f79-4f61-8b28-562e7c87f542
# ╟─a8524123-f78c-4c6d-b455-872c3fcf7f7f
# ╟─ed5bdc8d-d3e2-40fd-9924-b9dcc5dd7e6d
# ╠═74ec70b2-52db-11ec-308e-0b507febe03e
# ╟─00000000-0000-0000-0000-000000000001
# ╟─00000000-0000-0000-0000-000000000002

max_stars_repo_name: gaelforget/Notebooks

max_issues_repo_name: gaelforget/Notebooks

max_forks_repo_name: gaelforget/Notebooks


text:
# plotPose functions

"""
    $SIGNATURES

Plot pose belief as contour information on visually sensible manifolds.

Example:

```julia
fg = generateCanonicalFG_Hexagonal()
solveTree!(fg);
plotPose(fg, :x6)
```

Related

[`plotSLAM2D`](@ref), [`plotSLAM2DPoses`](@ref), [`plotKDE`](@ref), `plotKDECircular`
"""
function plotPose(pt::Pose2,
                  pp::Vector{BallTreeDensity},
                  title="plotPose2";
                  levels=3,
                  c=nothing,
                  legend=nothing,
                  axis=nothing,
                  scale::Real=0.2,
                  overlay=nothing,
                  hdl=[]  )
  #
  # ops = buildHybridManifoldCallbacks(pt.manifolds)
  # @show ran = getKDERange(p, addop=ops[1], diffop=ops[2])
  ran = axis === nothing ? getKDERange(pp) : axis

  p1 = plotKDE(pp, dims=[1;2], levels=levels, c=c, axis=ran )
  # p2 = plotKDE(bels, dims=[3], c=c)

  cc = c === nothing ? getColorsByLength(length(pp)) : c

  GG = BallTreeDensity[]
  for ppc in pp
    gg = marginal(ppc,[3])
    # gg = (x)->pc(reshape([x], :,1))[1]
    push!(GG, gg)
  end
  # p2 = AMP.plotCircBeliefs(GG, c=cc)
  p2 = AMP.plotKDECircular(GG, scale=scale, c=cc, legend=legend, title=title)

  # deal with overlay

  push!(hdl, p1)
  push!(hdl, p2)

  Gadfly.hstack(p1,p2)
end

function plotPose(pt::Pose2,
                  pp::Union{<:BallTreeDensity,<:ManifoldKernelDensity},
                  title="plotPose2";
                  levels=3,
                  c=nothing,
                  axis=nothing,
                  scale::Real=0.2,
                  overlay=nothing,
                  hdl=[]  )
  #
  plotPose(pt, [pp;],title,levels=levels,c=c,axis=axis,scale=scale, overlay=overlay, hdl=hdl )
end

function plotPose(::DynPose2,
                  bels::Union{<:AbstractVector{<:BallTreeDensity},<:AbstractVector{<:ManifoldKernelDensity}},
                  title;
                  levels::Int=5,
                  c=nothing,
                  axis=nothing,
                  hdl=[],
                  scale::Real=0.2 )
  #
  p1 = plotKDE(bels, dims=[1;2], levels=levels, c=c, title=title)
  p2 = plotKDE(bels, dims=[3], c=c)
  p3 = plotKDE(bels, dims=[4;5], levels=levels, c=c)

  push!(hdl, p1)
  push!(hdl, p2)
  push!(hdl, p3)

  Gadfly.vstack(p1,p2,p3)
end

# import RoMEPlotting: plotPose

function plotPose(::Pose3,
                  bels::Union{<:AbstractVector{<:BallTreeDensity},<:AbstractVector{<:ManifoldKernelDensity}},
                  title;
                  levels::Int=5,
                  c=nothing,
                  axis=nothing,
                  hdl=[],
                  scale::Real=0.2  )
  #
  @show title
  p1 = plotKDE(bels, dims=[1;2], levels=levels, c=c, title=title)
  p2 = plotKDE(bels, dims=[3], c=c)
  p3 = plotKDE(bels, dims=[4;5], levels=levels, c=c)
  p4 = plotKDE(bels, dims=[6], c=c)

  push!(hdl, p1)
  push!(hdl, p2)
  push!(hdl, p3)
  push!(hdl, p4)

  Gadfly.vstack(p1,p2,p3,p4)
end

"""
    $(SIGNATURES)

Example: pl = plotPose(fg, [:x1; :x2; :x3])
"""
function plotPose(fgl::AbstractDFG,
                  syms::Vector{Symbol};
                  solveKey::Symbol=:default,
                  levels::Int=5,
                  c=nothing,
                  axis=nothing,
                  scale::Real=0.2,
                  show::Bool=false,
                  filepath::AbstractString="/tmp/tempposeplot.svg",
                  app::AbstractString="eog",
                  hdl=[]  )
  #
  typ = getSolverData(getVariable(fgl, syms[1]), solveKey).softtype
  pt = string(string.(syms)...)
  getvertsgg = (sym) -> getKDE(getVariable(fgl, sym), solveKey)
  pl = plotPose(typ, getvertsgg.(syms), pt, levels=levels, c=c, axis=axis, scale=scale, hdl=hdl )

  if length(filepath) > 0
    ext = split(filepath, '.')[end]
    cmd = getfield(Gadfly,Symbol(uppercase(ext)))

    h = 1*7Gadfly.cm
    if typ == DynPose2
        h *= 1.5
    end
    Gadfly.draw(cmd(filepath,15Gadfly.cm,h),pl)

    @async !show ? nothing : run(`$app $filepath`)
  end
  return pl
end

function plotPose(fgl::AbstractDFG,
                  sym::Symbol;
                  levels::Int=5,
                  c=nothing,
                  axis=nothing,
                  scale::Real=0.2,
                  show::Bool=false,
                  filepath::AbstractString="/tmp/tempposeplot.svg",
                  app::AbstractString="eog",
                  hdl=[]  )
  #
  plotPose(fgl, [sym;], levels=levels, axis=axis, show=show, filepath=filepath, app=app, hdl=hdl )
end


text:
# Autogenerated wrapper script for libnabo_jll for i686-linux-gnu-cxx03
export libnabo

using CompilerSupportLibraries_jll
JLLWrappers.@generate_wrapper_header("libnabo")
JLLWrappers.@declare_library_product(libnabo, "libnabo.so.1")
function __init__()
    JLLWrappers.@generate_init_header(CompilerSupportLibraries_jll)
    JLLWrappers.@init_library_product(
        libnabo,
        "lib/libnabo.so",
        RTLD_LAZY | RTLD_DEEPBIND,
    )

    JLLWrappers.@generate_init_footer()
end  # __init__()


text:
const exptestdir = dirname(@__FILE__)
tests = ["isomorphism", "shortestpaths"]

@testset "Experimental" begin
    @test length(description()) > 1

    for t in tests
        tp = joinpath(exptestdir, "$(t).jl")
        include(tp)
    end
end


text:
conn = RedisConnection()

flushall(conn)

# some random key names
testkey = "Redis_Test_"*randstring()
testkey2 = "Redis_Test_"*randstring()
testkey3 = "Redis_Test_"*randstring()
testkey4 = "Redis_Test_"*randstring()
testhash = "Redis_Test_"*randstring()

# some random strings
s1 = randstring(); s2 = randstring(); s3 = randstring()
s4 = randstring(); s5 = randstring(); s6 = randstring()
s7 = randstring(); s8 = randstring(); s9 = randstring()

# constants for code legibility
const REDIS_PERSISTENT_KEY =  -1
const REDIS_EXPIRED_KEY =  -2

@testset "Strings" begin
    @test set(conn, testkey, s1)
    @test get(conn, testkey) == s1
    @test exists(conn, testkey)
    @test keys(conn, testkey) == Set([testkey])
    @test del(conn, testkey, "notakey", "notakey2") == 1  # only 1 of 3 key exists

    # 'NIL'
    @test get(conn, "notakey") == nothing

    set(conn, testkey, s1)
    set(conn, testkey2, s2)
    set(conn, testkey3, s3)
    # RANDOMKEY can return 'NIL', so it returns Union{Nothing, T}.  KEYS * always returns empty Set when Redis is empty
    @test randomkey(conn) in keys(conn, "*")
    @test getrange(conn, testkey, 0, 3) == s1[1:4]

    @test set(conn, testkey, 2)
    @test incr(conn, testkey) == 3
    @test incrby(conn, testkey, 3) == 6
    @test incrbyfloat(conn, testkey, 1.5) == "7.5"
    @test mget(conn, testkey, testkey2, testkey3) == ["7.5", s2, s3]
    @test strlen(conn, testkey2) == length(s2)
    @test rename(conn, testkey2, testkey4) == "OK"
    @test testkey4 in keys(conn,"*")
    del(conn, testkey, testkey2, testkey3, testkey4)

    @test append(conn, testkey, s1) == length(s1)
    @test append(conn, testkey, s2) == length(s1) + length(s2)
    get(conn, testkey) == string(s1, s2)
    del(conn, testkey)
end

@testset "Bits" begin
    @test setbit(conn,testkey, 0, 1) == 0
    @test setbit(conn,testkey, 2, 1) == 0
    @test getbit(conn, testkey, 0) == 1
    @test getbit(conn, testkey, 1) == 0  # default is 0
    @test getbit(conn, testkey, 2) == 1
    @test bitcount(conn, testkey) == 2
    del(conn, testkey)

    for i=0:3
        setbit(conn, testkey, i, 1)
        setbit(conn, testkey2, i, 1)
    end
    @test bitop(conn, "AND", testkey3, testkey, testkey2) == 1

    for i=0:3
        setbit(conn, testkey, i, 1)
        setbit(conn, testkey2, i, 0)
    end
    bitop(conn, "AND", testkey3, testkey, testkey2)
    @test [getbit(conn, testkey3, i) for i in 0:3] == zeros(4)

    @test bitop(conn, "OR", testkey3, testkey, testkey2) == 1
    @test [getbit(conn, testkey3, i) for i in 0:3] == ones(4)

    setbit(conn, testkey, 0, 0)
    setbit(conn, testkey, 1, 0)
    setbit(conn, testkey2, 1, 1)
    setbit(conn, testkey2, 3, 1)
    @test bitop(conn, "XOR", testkey3, testkey, testkey2) == 1
    @test [getbit(conn, testkey3, i) for i in 0:3] == [0; 1; 1; 0]

    @test bitop(conn, "NOT", testkey3, testkey3) == 1
    @test [getbit(conn, testkey3, i) for i in 0:3] == [1; 0; 0; 1]
    del(conn, testkey, testkey2, testkey3)
end

@testset "Dump" begin
    # TODO: DUMP AND RESTORE HAVE ISSUES
    #=
    set(conn, testkey, "10")
    # this line passes test when a client is available:
    @test [UInt8(x) for x in Redis.dump(r, testkey)] == readbytes(`redis-cli dump t`)[1:end-1]
    =#

    #= this causes 'ERR DUMP payload version or checksum are wrong', a TODO:  need to
    translate the return value and send it back correctly
    set(conn, testkey, 1)
    redisdump = Redis.dump(conn, testkey)
    del(conn, testkey)
    restore(conn, testkey, 0, redisdump)
    =#
end

@testset "Migrate" begin
    # TODO: test of `migrate` requires 2 server instances in Travis
    set(conn, testkey, s1)
    @test move(conn, testkey, 1)
    @test exists(conn, testkey) == false
    @test Redis.select(conn, 1) == "OK"
    @test get(conn, testkey) == s1
    del(conn, testkey)
    Redis.select(conn, 0)
end

@testset "Expiry" begin
    set(conn, testkey, s1)
    expire(conn, testkey, 1)
    sleep(1)
    @test exists(conn, testkey) == false

    set(conn, testkey, s1)
    expireat(conn, testkey,  round(Int, Dates.datetime2unix(time(conn)+Dates.Second(1))))
    sleep(2) # only passes test with 2 second delay
    @test exists(conn, testkey) == false

    set(conn, testkey, s1)
    @test pexpire(conn, testkey, 1)
    @test ttl(conn, testkey) == REDIS_EXPIRED_KEY

    set(conn, testkey, s1)
    @test pexpire(conn, testkey, 2000)
    @test pttl(conn, testkey) > 100
    @test persist(conn, testkey)
    @test ttl(conn, testkey) == REDIS_PERSISTENT_KEY
    del(conn, testkey, testkey2, testkey3)
end

@testset "Lists" begin
    @test lpush(conn, testkey, s1, s2, "a", "a", s3, s4) == 6
    @test lpop(conn, testkey) == s4
    @test rpop(conn, testkey) == s1
    @test lpop(conn, "non_existent_list") == nothing
    @test rpop(conn, "non_existent_list") == nothing
    @test llen(conn, testkey) == 4
    @test lindex(conn, "non_existent_list", 1) == nothing
    @test lindex(conn, testkey, 0) == s3
    @test lindex(conn, testkey, 10) == nothing
    @test lrem(conn, testkey, 0, "a") == 2
    @test lset(conn, testkey, 0, s5) == "OK"
    @test lindex(conn, testkey, 0) == s5
    @test linsert(conn, testkey, "BEFORE", s2, s3) == 3
    @test linsert(conn, testkey, "AFTER", s3, s6) == 4
    @test lpushx(conn, testkey2, "nothing")  == false
    @test rpushx(conn, testkey2, "nothing")  == false
    @test ltrim(conn, testkey, 0, 1) == "OK"
    @test lrange(conn, testkey, 0, -1) == [s5; s3]
    @test brpop(conn, testkey, 0) == [testkey, s3]
    lpush(conn, testkey, s3)
    @test blpop(conn, testkey, 0) == [testkey, s3]
    lpush(conn, testkey, s4)
    lpush(conn, testkey, s3)
    listvals = [s3; s4; s5]
    for i in 1:3
        @test rpoplpush(conn, testkey, testkey2) == listvals[4-i]  # rpop
    end
    @test rpoplpush(conn, testkey, testkey2) == nothing
    @test llen(conn, testkey) == 0
    @test llen(conn, testkey2) == 3
    @test lrange(conn, testkey2, 0, -1) == listvals
    for i in 1:3
        @test brpoplpush(conn, testkey2, testkey, 0) == listvals[4-i]  # rpop
    end
    @test lrange(conn, testkey, 0, -1) == listvals

    # the following command can only be applied to lists containing numeric values
    sortablelist = [pi, 1, 2]
    lpush(conn, testkey3, sortablelist)
    @test Redis.sort(conn, testkey3) == ["1.0", "2.0", "3.141592653589793"]
    del(conn, testkey, testkey2, testkey3)
end

@testset "Hashes" begin
    @test hmset(conn, testhash, Dict(1 => 2, "3" => 4, "5" => "6"))
    @test hscan(conn,  testhash, 0) == (0, Dict("1" => "2", "3" => "4", "5" => "6"))
    @test hexists(conn, testhash, 1) == true
    @test hexists(conn, testhash, "1") == true
    @test hget(conn, testhash, 1) == "2"
    @test hgetall(conn, testhash) == Dict("1" => "2", "3" => "4", "5" => "6")

    @test hget(conn, testhash, "non_existent_field") == nothing
    @test hmget(conn, testhash, 1, 3) == ["2", "4"]
    a = hmget(conn, testhash, "non_existent_field1", "non_existent_field2")
    @test a[1] == nothing
    @test a[2] == nothing

    @test Set(hvals(conn, testhash)) == Set(["2", "4", "6"]) # use Set for comp as hash ordering is random
    @test Set(hkeys(conn, testhash)) == Set(["1", "3", "5"])
    @test hset(conn, testhash, "3", 10) == false # if the field already hset returns false
    @test hget(conn, testhash, "3") == "10" # but still sets it to the new value
    @test hset(conn, testhash, "10", "10") == true # new field hset returns true
    @test hget(conn, testhash, "10") == "10" # correctly set new field
    @test hsetnx(conn, testhash, "1", "10") == false # field exists
    @test hsetnx(conn, testhash, "11", "10") == true # field doesn't exist
    @test hlen(conn, testhash) == 5  # testhash now has 5 fields
    @test hincrby(conn, testhash, "1", 1) == 3
    @test parse(Float64, hincrbyfloat(conn, testhash, "1", 1.5)) == 4.5

    del(conn, testhash)

    N = 1500
    @test hmset(conn, testhash, Dict(i=>i for i=1:N))
    (cursor, d) = hscan(conn, testhash, 0)
    while cursor != 0
        (cursor, d_new) = hscan(conn, testhash, cursor)
        merge!(d, d_new)
    end
    @test d == Dict(string(i)=>string(i) for i=1:N)
    del(conn, testhash)
end

@testset "Sets" begin
    @test sadd(conn, testkey, s1) == true
    @test sadd(conn, testkey, s1) == false  # already exists
    @test sadd(conn, testkey, s2) == true
    @test smembers(conn, testkey) == Set([s1, s2])
    @test scard(conn, testkey) == 2
    sadd(conn, testkey, s3)
    @test smove(conn, testkey, testkey2, s3) == true
    @test sismember(conn, testkey2, s3) == true
    sadd(conn, testkey2, s2)
    @test sunion(conn, testkey, testkey2) == Set([s1, s2, s3])
    @test sunionstore(conn, testkey3, testkey, testkey2) == 3
    @test srem(conn, testkey3, s1, s2, s3) == 3
    @test smembers(conn, testkey3) == Set([])
    @test sinterstore(conn, testkey3, testkey, testkey2) == 1
    # only the following method returns 'nil' if the Set does not exist
    @test srandmember(conn, testkey3) in Set([s1, s2, s3])
    @test srandmember(conn, "empty_set") == nothing
    # this method returns an emtpty Set if the the Set is empty
    @test issubset(srandmember(conn, testkey2, 2), Set([s1, s2, s3]))
    @test srandmember(conn, "non_existent_set", 10) == Set{AbstractString}()
    @test sdiff(conn, testkey, testkey2) == Set([s1])
    @test spop(conn, testkey) in Set([s1, s2, s3])
    @test spop(conn, "empty_set") == nothing
    del(conn, testkey, testkey2, testkey3)
end

@testset "Sorted Sets" begin
    @test zadd(conn, testkey, 0, s1) == true
    @test zadd(conn, testkey, 1., s1) == false
    @test zadd(conn, testkey, 1., s2) == true
    @test zrange(conn, testkey, 0, -1) == OrderedSet([s1, s2])
    @test zcard(conn, testkey) == 2
    zadd(conn, testkey, 1.5, s3)
    @test zcount(conn, testkey, 0, 1) == 2   # range as int
    @test zcount(conn, testkey, "-inf", "+inf") == 3 # range as string
    @test zincrby(conn, testkey, 1, s1) == "2"
    @test parse(Float64, zincrby(conn, testkey, 1.2, s1)) == 3.2
    @test zrem(conn, testkey, s1, s2) == 2
    del(conn, testkey)

    @test zadd(conn, testkey, zip(zeros(3), [s1, s2, s3])...) == 3
    del(conn, testkey)

    vals = ["a", "b", "c", "d", "e", "f", "g", "h", "i", "j"]

    # tests where all scores == 0
    zadd(conn, testkey, zip(zeros(length(vals)), vals)...)
    @test zlexcount(conn, testkey, "-", "+") == length(vals)
    @test zlexcount(conn, testkey, "[b", "[f") == 5
    @test zrangebylex(conn, testkey, "-", "[c") == OrderedSet(["a", "b", "c"])
    @test zrangebylex(conn, testkey, "[aa", "(g") == OrderedSet(["b", "c", "d", "e", "f"])
    @test zrangebylex(conn, testkey, "[a", "(g") == OrderedSet(["a", "b", "c", "d", "e", "f"])
    @test zremrangebylex(conn, testkey, "[a", "[h") == 8
    @test zrange(conn, testkey, 0, -1) == OrderedSet(["i", "j"])
    del(conn, testkey)

    # tests where scores are sequence 1:10
    zadd(conn, testkey, zip(1:length(vals), vals)...)
    @test zrangebyscore(conn, testkey, "(1", "2") == OrderedSet(["b"])
    @test zrangebyscore(conn, testkey, "1", "2") == OrderedSet(["a", "b"])
    @test zrangebyscore(conn, testkey, "(1", "(2") == OrderedSet([])
    @test zrank(conn, testkey, "d") == 3 # redis arrays 0-base

    # 'NIL'
    @test zrank(conn, testkey, "z") == nothing
    del(conn, testkey)

    zadd(conn, testkey, zip(1:length(vals), vals)...)
    @test zremrangebyrank(conn, testkey, 0, 1) == 2
    @test zrange(conn, testkey, 0, -1, "WITHSCORES") == OrderedSet(["c", "3", "d", "4", "e", "5", "f", "6", "g", "7", "h", "8", "i", "9", "j", "10"])
    @test zremrangebyscore(conn, testkey, "-inf", "(5") == 2
    @test zrange(conn, testkey, 0, -1, "WITHSCORES") == OrderedSet(["e", "5", "f", "6", "g", "7", "h", "8", "i", "9", "j", "10"])
    @test zrevrange(conn, testkey, 0, -1) == OrderedSet(["j", "i", "h", "g", "f", "e"])
    @test zrevrangebyscore(conn, testkey, "+inf", "-inf") == OrderedSet(["j", "i", "h", "g", "f", "e"])
    @test zrevrangebyscore(conn, testkey, "+inf", "-inf", "WITHSCORES", "LIMIT", 2, 3) == OrderedSet(["h", "8", "g", "7", "f", "6"])
    @test zrevrangebyscore(conn, testkey, 7, 5) == OrderedSet(["g", "f", "e"])
    @test zrevrangebyscore(conn, testkey, "(6", "(5") == OrderedSet{AbstractString}()
    @test zrevrank(conn, testkey, "e") == 5
    @test zrevrank(conn, "ordered_set", "non_existent_member") == nothing
    @test zscore(conn, testkey, "e") == "5"
    @test zscore(conn, "ordered_set", "non_existent_member") == nothing
    del(conn, testkey)

    vals2 = ["a", "b", "c", "d"]
    zadd(conn, testkey, zip(1:length(vals), vals)...)
    zadd(conn, testkey2, zip(1:length(vals2), vals2)...)
    @test zunionstore(conn, testkey3, 2, [testkey, testkey2]) == 10
    @test zrange(conn, testkey3, 0, -1) == OrderedSet(vals)
    del(conn, testkey3)

    zunionstore(conn, testkey3, 2, [testkey, testkey2], [2; 3])
    @test zrange(conn, testkey3, 0, -1) == OrderedSet(["a", "b", "e", "f", "g", "c", "h", "i", "d", "j"])
    zunionstore(conn, testkey3, 2, [testkey, testkey2], [2; 3], aggregate=Aggregate.Max)
    @test zrange(conn, testkey3, 0, -1) == OrderedSet(["a", "b", "c", "e", "d", "f", "g", "h", "i", "j"])
    zunionstore(conn, testkey3, 2, [testkey, testkey2], [2; 3], aggregate=Aggregate.Min)
    @test zrange(conn, testkey3, 0, -1) == OrderedSet(["a", "b", "c", "d", "e", "f", "g", "h", "i", "j"])
    del(conn, testkey3)

    vals2 = ["a", "b", "c", "d"]
    @test zinterstore(conn, testkey3, 2, [testkey, testkey2]) == 4
    del(conn, testkey, testkey2, testkey3)
end

@testset "Scan" begin

end

@testset "Scripting" begin
    script = "return {KEYS[1], KEYS[2], ARGV[1], ARGV[2]}"
    args = ["key1", "key2", "first", "second"]
    resp = evalscript(conn, script, 2, args)
    @test resp == args
    del(conn, "key1")

    script = "return redis.call('set', KEYS[1], 'bar')"
    ky = "foo"
    resp = evalscript(conn, script, 1, [ky])
    @test resp == "OK"
    del(conn, ky)

#@test evalscript(conn, "return {'1','2',{'3','Hello World!'}}", 0, []) == ["1"; "2"; ["3","Hello World!"]]

# NOTE the truncated float, and truncated array in the response
# as per http://redis.io/commands/eval
#       Lua has a single numerical type, Lua numbers. There is
#       no distinction between integers and floats. So we always
#       convert Lua numbers into integer replies, removing the
#       decimal part of the number if any. If you want to return
#       a float from Lua you should return it as a string, exactly
#       like Redis itself does (see for instance the ZSCORE command).
#
#       There is no simple way to have nils inside Lua arrays,
#       this is a result of Lua table semantics, so when Redis
#       converts a Lua array into Redis protocol the conversion
#       is stopped if a nil is encountered.
#@test evalscript(conn, "return {1, 2, 3.3333, 'foo', nil, 'bar'}",  0, []) == [1, 2, 3, "foo"]
end

@testset "Transactions" begin
    trans = open_transaction(conn)
    @test set(trans, testkey, "foobar") == "QUEUED"
    @test get(trans, testkey) == "QUEUED"
    @test exec(trans) == ["OK", "foobar"]
    @test del(trans, testkey) == "QUEUED"
    @test exec(trans) == [true]
    disconnect(trans)
end

@testset "Pipelines" begin
    pipe = open_pipeline(conn)
    set(pipe, testkey3, "anything")
    @test length(read_pipeline(pipe)) == 1
    get(pipe, testkey3)
    set(pipe, testkey4, "testing")
    result = read_pipeline(pipe)
    @test length(result) == 2
    @test result == ["anything", "OK"]
    @test del(pipe, testkey3) == 1
    @test del(pipe, testkey4) == 2
    @test result ==  ["anything", "OK"]
    disconnect(pipe)
end

@testset "Pub/Sub" begin
    function handleException(ex)
        io = IOBuffer()
        showerror(io, ex, catch_backtrace())
        err = String(take!(io))
        @warn "Error while processing subscription: $err"
        return nothing
    end
    x = Any[]
    function f(y::String)
        push!(x, y)
    end
    subs = open_subscription(conn, handleException) #handleException is called when an exception occurs
    subscribe(subs, "channel", f)
    subscribe(subs, "duplicate", f)
    @test publish(conn, "channel", "hello, world!") > 0 #Number of connected clients returned
    @test publish(conn, "channel", "Okay, bye!") > 0 #Number of connected clients returned
    sleep(2)
    @test x == ["hello, world!", "Okay, bye!"]

    # following command prints ("Invalid response received: ")
    disconnect(subs)
    @info "This error is expected - to be addressed once the library is stable."
end

disconnect(conn)


text:
"""
    swap_betas(chain_index, k)

Swaps the `k`th and `k + 1`th temperatures.
Use `sortperm()` to convert the `chain_index` to a `Δ_index` to be used in tempering moves.
"""
function swap_betas(chain_index, k)
    chain_index[k], chain_index[k + 1] = chain_index[k + 1], chain_index[k]
    return sortperm(chain_index), chain_index
end

function make_tempered_loglikelihood end
function get_params end

"""
    get_tempered_loglikelihoods_and_params(model, sampler, states, k, Δ, chain_index)

Temper the `model`'s density using the `k`th and `k + 1`th temperatures
selected via `Δ` and `chain_index`. Then retrieve the parameters using the chains'
current transitions extracted from the collection of `states`.
"""
function get_tempered_loglikelihoods_and_params(
    model,
    sampler::AbstractMCMC.AbstractSampler,
    states,
    k::Integer,
    Δ::Vector{Real},
    chain_index::Vector{<:Integer}
)

    logπk = make_tempered_loglikelihood(model, Δ[k])
    logπkp1 = make_tempered_loglikelihood(model, Δ[k + 1])

    θk = get_params(states[chain_index[k]][1])
    θkp1 = get_params(states[chain_index[k + 1]][1])

    return logπk, logπkp1, θk, θkp1
end

"""
    swap_acceptance_pt(logπk, logπkp1, θk, θkp1)

Calculates and returns the swap acceptance ratio for swapping the temperature
of two chains. Using tempered likelihoods `logπk` and `logπkp1` at the chains'
current state parameters `θk` and `θkp1`.
"""
function swap_acceptance_pt(logπk, logπkp1, θk, θkp1)
    return min(
        1,
        exp(logπkp1(θk) + logπk(θkp1)) / exp(logπk(θk) + logπkp1(θkp1))
        # exp(abs(βk - βkp1) * abs(AdvancedMH.logdensity(model, samplek) - AdvancedMH.logdensity(model, samplekp1)))
    )
end

"""
    swap_attempt(model, sampler, states, k, Δ, Δ_index)

Attempt to swap the temperatures of two chains by tempering the densities and
calculating the swap acceptance ratio; then swapping if it is accepted.
"""
function swap_attempt(model, sampler, ts, k, adapt, n)

    logπk, logπkp1, θk, θkp1 = get_tempered_loglikelihoods_and_params(model, sampler, ts.states, k, ts.Δ, ts.chain_index)

    swap_ar = swap_acceptance_pt(logπk, logπkp1, θk, θkp1)
    U = rand(Distributions.Uniform(0, 1))

    # If the proposed temperature swap is accepted according to swap_ar and U, swap the temperatures for future steps
    if U ≤ swap_ar
        ts.Δ_index, ts.chain_index = swap_betas(ts.chain_index, k)
    end

    # Adaptation steps affects Ρ and Δ, as the Ρ is adapted before a new Δ is generated and returned
    if adapt
        ts.Ρ, ts.Δ = adapt_ladder(ts.Ρ, ts.Δ, k, swap_ar, n)
    end
    return ts
end


text:
function mutual_information_contingency(probs::AbstractMatrix{Float64}; normalize::Bool=false)
    ee = entropy(ProbabilityWeights(probs[:]))
    ex = entropy(ProbabilityWeights(sum(probs, dims=1)[:]))
    ey = entropy(ProbabilityWeights(sum(probs, dims=2)[:]))

    mi = ex + ey - ee
    return normalize ? min(mi / min(ex, ey), 1.) : mi
end

function mutual_information(
    x::AbstractVector, y::AbstractVector, ex::Float64, ey::Float64; method=:Naive, adjusted=false, normalize=false)

    # Compute the joint entropy without adjustment nor normalization
    ee = estimate_joint_entropy(x, y; method=method)

    if adjusted
        ee_shuffle = estimate_joint_entropy(x, shuffle(y); method=method)
        mi_shuffle = ex + ey - ee_shuffle
        mi = ee_shuffle - ee
        normalize ? mi / (min(ex, ey) - mi_shuffle) : mi
    else
        mi = ex + ey - ee
        normalize ? min(mi / min(ex, ey), 1.) : mi
    end
end

function mutual_information(
    x::AbstractVector, y::AbstractVector;
    method=:Naive, adjusted=false, normalize=false)

    ex = estimate_entropy(x)
    ey = estimate_entropy(y)
    mutual_information(
        x, y, ex, ey; method=method, adjusted=adjusted, normalize=normalize)
end

function mutual_information(data::AbstractMatrix; method::Symbol=:Naive, adjusted::Bool=false, normalize::Bool=false)
    M = size(data, 2)
    mi_sym = Array{Float64, 2}(undef, M, M)

    for i =1:M
        mi_sym[i,i] = estimate_entropy(@view data[:,i]; method=method)
    end

    for i = 1:M, j=i+1:M
        ex = mi_sym[i,i]
        ey = mi_sym[j,j]

        x = @view data[:,i]
        y = @view data[:,j]

        mi_sym[i, j] = mutual_information(
            x, y, ex, ey;
            method=method, adjusted=adjusted, normalize=normalize)

        # Drop null or negative values
        if mi_sym[i, j] < Base.eps()
            mi_sym[i, j] = 0.
        end

        mi_sym[j,i] = mi_sym[i,j]  # tbr
    end
    mi_sym
end