From 27942d24979d18f353f26d0fa36a156469f60c8f Mon Sep 17 00:00:00 2001 From: Alexander Plavin Date: Mon, 1 Jul 2024 15:20:29 -0400 Subject: [PATCH 1/2] add Makie integration --- Project.toml | 9 ++++++++- ext/MakieExt.jl | 16 ++++++++++++++++ test/runtests.jl | 22 ++++++++++++++++++++-- 3 files changed, 44 insertions(+), 3 deletions(-) create mode 100644 ext/MakieExt.jl diff --git a/Project.toml b/Project.toml index c40241c..ad41161 100644 --- a/Project.toml +++ b/Project.toml @@ -19,11 +19,18 @@ Statistics = "10745b16-79ce-11e8-11f9-7d13ad32a3b2" StatsBase = "2913bbd2-ae8a-5f71-8c99-4fb6c76f3a91" Test = "8dfed614-e22c-5e08-85e1-65c5234f0b40" +[weakdeps] +Makie = "ee78f7c6-11fb-53f2-987a-cfe4a2b5a57a" + +[extensions] +MakieExt = "Makie" + [compat] Distributions = "0.17,0.18,0.19,0.20,0.21, 0.22, 0.23, 0.24, 0.25" ForwardDiff = "0.10" GenericSchur = "0.5" MacroTools = "<0.6" +Makie = "0.21" RecipesBase = "<0.8, 0.8, 1.0" Requires = "<0.6, 1.0" SLEEFPirates = "0.4, 0.5, 0.6" @@ -40,4 +47,4 @@ Test = "8dfed614-e22c-5e08-85e1-65c5234f0b40" Unitful = "1986cc42-f94f-5a68-af5c-568840ba703d" [targets] -test = ["ControlSystemsBase", "Measurements", "Test", "Plots", "Unitful"] +test = ["ControlSystemsBase", "Makie", "Measurements", "Test", "Plots", "Unitful"] diff --git a/ext/MakieExt.jl b/ext/MakieExt.jl new file mode 100644 index 0000000..0665666 --- /dev/null +++ b/ext/MakieExt.jl @@ -0,0 +1,16 @@ +module MakieExt + +using Makie +using MonteCarloMeasurements + +Makie.used_attributes(::Type{<:Series}, ::AbstractVector, ::AbstractVector{<:Particles}) = (:N,) +Makie.used_attributes(::Type{<:Series}, ::AbstractVector{<:Tuple{<:Real,<:Particles}}) = (:N,) +Makie.convert_arguments(ct::Type{<:Series}, x::AbstractVector, y::AbstractVector{<:Particles}; N=7) = convert_arguments(ct, x, Matrix(y)[1:min(N, end), :]) +Makie.used_attributes(::Type{<:Union{Rangebars,Band}}, ::AbstractVector, ::AbstractVector{<:Particles}) = (:q,) +Makie.used_attributes(::Type{<:Union{Rangebars,Band}}, ::AbstractVector{<:Tuple{<:Real,<:Particles}}) = (:q,) +Makie.convert_arguments(p::Type{<:Union{Hist,Density}}, x::Particles) = convert_arguments(p, Vector(x)) +Makie.convert_arguments(ct::Type{<:Union{Rangebars,Band}}, x::AbstractVector, y::AbstractVector{<:Particles}; q=0.16) = convert_arguments(ct, x, pquantile.(y, q), pquantile.(y, 1-q)) +Makie.convert_arguments(ct::Type{<:AbstractPlot}, X::AbstractVector{<:Tuple{<:Real,<:Particles}}; kwargs...) = convert_arguments(ct, first.(X), last.(X); kwargs...) +Makie.convert_arguments(ct::PointBased, x::AbstractVector{<:Real}, y::AbstractVector{<:Particles}) = convert_arguments(ct, x, pmean.(y)) + +end diff --git a/test/runtests.jl b/test/runtests.jl index 76c7a37..6dc5ab8 100644 --- a/test/runtests.jl +++ b/test/runtests.jl @@ -2,9 +2,10 @@ using MonteCarloMeasurements, Distributions using Test, LinearAlgebra, Statistics, Random, GenericSchur import MonteCarloMeasurements: ⊗, gradient, optimize, DEFAULT_NUM_PARTICLES -@info "import Plots" +@info "import Plots, Makie" import Plots -@info "import Plots done" +import Makie +@info "import plotting packages done" Random.seed!(0) @@ -655,6 +656,23 @@ Random.seed!(0) @test_nowarn MonteCarloMeasurements.print_functions_to_extend() end + @time @testset "Makie" begin + p1 = Particles(10^2) + Makie.hist(p1) + Makie.density(p1) + + xs = 1:20 + ys = Particles.(Normal.(sqrt.(1:20), sqrt.(1:20)./5)) + + Makie.scatter(xs, ys) + Makie.scatter(tuple.(xs, ys)) + Makie.band(xs, ys) + Makie.band(tuple.(xs, ys); q=0.01) + Makie.rangebars(tuple.(xs, ys); q=0.16) + Makie.series(xs, ys) + Makie.series(tuple.(xs, ys); N=5) + end + @time @testset "optimize" begin @info "Testing optimization" function rosenbrock2d(x) From 13278e2ea9116b19b547e5c3446b1651b993f13d Mon Sep 17 00:00:00 2001 From: Alexander Plavin Date: Mon, 1 Jul 2024 15:48:38 -0400 Subject: [PATCH 2/2] fix for earlier julia versions --- .github/workflows/main.yml | 2 +- Project.toml | 1 + test/runtests.jl | 2 +- 3 files changed, 3 insertions(+), 2 deletions(-) diff --git a/.github/workflows/main.yml b/.github/workflows/main.yml index e98edc3..007585b 100644 --- a/.github/workflows/main.yml +++ b/.github/workflows/main.yml @@ -5,7 +5,7 @@ jobs: runs-on: ${{ matrix.os }} strategy: matrix: - julia-version: ['1.6'] + julia-version: ['1.6', '1'] os: [ubuntu-latest] steps: - uses: actions/checkout@v2 diff --git a/Project.toml b/Project.toml index ad41161..556f3b8 100644 --- a/Project.toml +++ b/Project.toml @@ -41,6 +41,7 @@ julia = "1.6" [extras] ControlSystemsBase = "aaaaaaaa-a6ca-5380-bf3e-84a91bcd477e" +Makie = "ee78f7c6-11fb-53f2-987a-cfe4a2b5a57a" Measurements = "eff96d63-e80a-5855-80a2-b1b0885c5ab7" Plots = "91a5bcdd-55d7-5caf-9e0b-520d859cae80" Test = "8dfed614-e22c-5e08-85e1-65c5234f0b40" diff --git a/test/runtests.jl b/test/runtests.jl index 6dc5ab8..a652aed 100644 --- a/test/runtests.jl +++ b/test/runtests.jl @@ -656,7 +656,7 @@ Random.seed!(0) @test_nowarn MonteCarloMeasurements.print_functions_to_extend() end - @time @testset "Makie" begin + VERSION ≥ v"1.9" && @time @testset "Makie" begin p1 = Particles(10^2) Makie.hist(p1) Makie.density(p1)