From fe7d957be371bb4a2ee3551edb2b87c64263d82c Mon Sep 17 00:00:00 2001 From: t-bltg Date: Thu, 22 Jul 2021 11:49:31 +0200 Subject: [PATCH 1/3] use a stable RNG in fakedata --- Project.toml | 4 ++-- src/Plots.jl | 3 ++- src/examples.jl | 3 +-- src/utils.jl | 4 ++-- test/imgcomp.jl | 2 +- test/runtests.jl | 7 +++---- 6 files changed, 11 insertions(+), 12 deletions(-) diff --git a/Project.toml b/Project.toml index cc5cf012..cc4e7afe 100644 --- a/Project.toml +++ b/Project.toml @@ -31,6 +31,7 @@ SparseArrays = "2f01184e-e22b-5df5-ae63-d93ebab69eaf" Statistics = "10745b16-79ce-11e8-11f9-7d13ad32a3b2" StatsBase = "2913bbd2-ae8a-5f71-8c99-4fb6c76f3a91" UUIDs = "cf7118a7-6976-5b1a-9a39-7adc72f591a4" +StableRNGs = "860ef19b-820b-49d6-a774-d7a799459cd3" [compat] Contour = "0.5" @@ -65,7 +66,6 @@ OffsetArrays = "6fe1bfb0-de20-5000-8ca7-80f57d26f881" PGFPlotsX = "8314cec4-20b6-5062-9cdb-752b83310925" PlotlyJS = "f0f68f2c-4968-5e81-91da-67840de0976a" RDatasets = "ce6b1742-4840-55fa-b093-852dadbb1d8b" -StableRNGs = "860ef19b-820b-49d6-a774-d7a799459cd3" StaticArrays = "90137ffa-7385-5640-81b9-e52037218182" StatsPlots = "f3b207a7-027a-5e70-b257-86293d7955fd" Test = "8dfed614-e22c-5e08-85e1-65c5234f0b40" @@ -74,4 +74,4 @@ UnicodePlots = "b8865327-cd53-5732-bb35-84acbb429228" VisualRegressionTests = "34922c18-7c2a-561c-bac1-01e79b2c4c92" [targets] -test = ["Distributions", "FileIO", "Gtk", "ImageMagick", "Images", "LibGit2", "OffsetArrays", "PGFPlotsX", "PlotlyJS", "HDF5", "RDatasets", "StableRNGs", "StaticArrays", "StatsPlots", "Test", "TestImages", "UnicodePlots", "VisualRegressionTests"] +test = ["Distributions", "FileIO", "Gtk", "ImageMagick", "Images", "LibGit2", "OffsetArrays", "PGFPlotsX", "PlotlyJS", "HDF5", "RDatasets", "StaticArrays", "StatsPlots", "Test", "TestImages", "UnicodePlots", "VisualRegressionTests"] diff --git a/src/Plots.jl b/src/Plots.jl index e7a71878..e79a0752 100644 --- a/src/Plots.jl +++ b/src/Plots.jl @@ -11,6 +11,7 @@ using Reexport import GeometryBasics using Dates, Printf, Statistics, Base64, LinearAlgebra, Random using SparseArrays +using StableRNGs using FFMPEG @@ -118,7 +119,6 @@ export scalefontsizes, resetfontsizes - # --------------------------------------------------------- import NaNMath # define functions that ignores NaNs. To overcome the destructive effects of https://github.com/JuliaLang/julia/pull/12563 @@ -250,6 +250,7 @@ end # --------------------------------------------------------- const CURRENT_BACKEND = CurrentBackend(:none) +const PLOTS_SEED = 1234 include("precompile_includer.jl") diff --git a/src/examples.jl b/src/examples.jl index 838af274..03d4ae4f 100644 --- a/src/examples.jl +++ b/src/examples.jl @@ -128,8 +128,7 @@ const _examples = PlotExample[ :( begin import FileIO - path = - download("http://juliaplots.org/PlotReferenceImages.jl/Plots/pyplot/0.7.0/ref1.png") + path = download("http://juliaplots.org/PlotReferenceImages.jl/Plots/pyplot/0.7.0/ref1.png") img = FileIO.load(path) plot(img) end diff --git a/src/utils.jl b/src/utils.jl index 4ebdc01e..68471a16 100644 --- a/src/utils.jl +++ b/src/utils.jl @@ -303,10 +303,10 @@ function convert_to_polar(theta, r, r_extrema = ignorenan_extrema(r)) x, y end -function fakedata(sz...) +function fakedata(sz...; rng=StableRNG(PLOTS_SEED)) y = zeros(sz...) for r in 2:size(y,1) - y[r,:] = 0.95 * vec(y[r-1,:]) + randn(size(y,2)) + y[r,:] = 0.95 * vec(y[r-1,:]) + randn(rng, size(y,2)) end y end diff --git a/test/imgcomp.jl b/test/imgcomp.jl index 3a0af3ca..f77c0b3a 100644 --- a/test/imgcomp.jl +++ b/test/imgcomp.jl @@ -13,7 +13,7 @@ function replace_rand!(ex::Expr) end function fix_rand!(ex) replace_rand!(ex) - pushfirst!(ex.args[1].args, :(rng = StableRNG(1234))) + pushfirst!(ex.args[1].args, :(rng = StableRNG(PLOTS_SEED))) end function image_comparison_tests( diff --git a/test/runtests.jl b/test/runtests.jl index 5b280508..5d8c3690 100644 --- a/test/runtests.jl +++ b/test/runtests.jl @@ -1,9 +1,8 @@ -using Plots: guidefont, series_annotations +using Plots: guidefont, series_annotations, PLOTS_SEED import ImageMagick using VisualRegressionTests using Plots using Random -using StableRNGs using Test using TestImages using FileIO @@ -12,7 +11,7 @@ using LibGit2 import GeometryBasics using Dates using RecipesBase - +using StableRNGs @testset "Plotly standalone" begin @test_nowarn Plots._init_ijulia_plotting() @@ -68,7 +67,7 @@ end include("imgcomp.jl") # don't actually show the plots -Random.seed!(1234) +Random.seed!(PLOTS_SEED) default(show=false, reuse=true) is_ci() = get(ENV, "CI", "false") == "true" const PLOTS_IMG_TOL = parse( From cd06648ec3d7470ac9d91a1f9a52425c999c4273 Mon Sep 17 00:00:00 2001 From: t-bltg <13423344+t-bltg@users.noreply.github.com> Date: Fri, 23 Jul 2021 11:02:22 +0200 Subject: [PATCH 2/3] Switch to Random.GLOBAL_RNG Co-authored-by: Simon Christ --- src/utils.jl | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/utils.jl b/src/utils.jl index 68471a16..36c6d340 100644 --- a/src/utils.jl +++ b/src/utils.jl @@ -303,7 +303,7 @@ function convert_to_polar(theta, r, r_extrema = ignorenan_extrema(r)) x, y end -function fakedata(sz...; rng=StableRNG(PLOTS_SEED)) +function fakedata(sz...; rng=Random.GLOBAL_RNG(PLOTS_SEED)) y = zeros(sz...) for r in 2:size(y,1) y[r,:] = 0.95 * vec(y[r-1,:]) + randn(rng, size(y,2)) From f3aa61293b44532cddc31d5e6812124afc0b939f Mon Sep 17 00:00:00 2001 From: t-bltg Date: Fri, 23 Jul 2021 11:31:30 +0200 Subject: [PATCH 3/3] change fakedata rng in tests --- Project.toml | 4 ++-- src/Plots.jl | 1 - src/utils.jl | 4 +++- test/imgcomp.jl | 3 ++- test/runtests.jl | 2 +- 5 files changed, 8 insertions(+), 6 deletions(-) diff --git a/Project.toml b/Project.toml index cc4e7afe..cc5cf012 100644 --- a/Project.toml +++ b/Project.toml @@ -31,7 +31,6 @@ SparseArrays = "2f01184e-e22b-5df5-ae63-d93ebab69eaf" Statistics = "10745b16-79ce-11e8-11f9-7d13ad32a3b2" StatsBase = "2913bbd2-ae8a-5f71-8c99-4fb6c76f3a91" UUIDs = "cf7118a7-6976-5b1a-9a39-7adc72f591a4" -StableRNGs = "860ef19b-820b-49d6-a774-d7a799459cd3" [compat] Contour = "0.5" @@ -66,6 +65,7 @@ OffsetArrays = "6fe1bfb0-de20-5000-8ca7-80f57d26f881" PGFPlotsX = "8314cec4-20b6-5062-9cdb-752b83310925" PlotlyJS = "f0f68f2c-4968-5e81-91da-67840de0976a" RDatasets = "ce6b1742-4840-55fa-b093-852dadbb1d8b" +StableRNGs = "860ef19b-820b-49d6-a774-d7a799459cd3" StaticArrays = "90137ffa-7385-5640-81b9-e52037218182" StatsPlots = "f3b207a7-027a-5e70-b257-86293d7955fd" Test = "8dfed614-e22c-5e08-85e1-65c5234f0b40" @@ -74,4 +74,4 @@ UnicodePlots = "b8865327-cd53-5732-bb35-84acbb429228" VisualRegressionTests = "34922c18-7c2a-561c-bac1-01e79b2c4c92" [targets] -test = ["Distributions", "FileIO", "Gtk", "ImageMagick", "Images", "LibGit2", "OffsetArrays", "PGFPlotsX", "PlotlyJS", "HDF5", "RDatasets", "StaticArrays", "StatsPlots", "Test", "TestImages", "UnicodePlots", "VisualRegressionTests"] +test = ["Distributions", "FileIO", "Gtk", "ImageMagick", "Images", "LibGit2", "OffsetArrays", "PGFPlotsX", "PlotlyJS", "HDF5", "RDatasets", "StableRNGs", "StaticArrays", "StatsPlots", "Test", "TestImages", "UnicodePlots", "VisualRegressionTests"] diff --git a/src/Plots.jl b/src/Plots.jl index e79a0752..5b067f0a 100644 --- a/src/Plots.jl +++ b/src/Plots.jl @@ -11,7 +11,6 @@ using Reexport import GeometryBasics using Dates, Printf, Statistics, Base64, LinearAlgebra, Random using SparseArrays -using StableRNGs using FFMPEG diff --git a/src/utils.jl b/src/utils.jl index 36c6d340..f07945a2 100644 --- a/src/utils.jl +++ b/src/utils.jl @@ -303,7 +303,9 @@ function convert_to_polar(theta, r, r_extrema = ignorenan_extrema(r)) x, y end -function fakedata(sz...; rng=Random.GLOBAL_RNG(PLOTS_SEED)) +fakedata(sz::Int...) = fakedata(Random.seed!(PLOTS_SEED), sz...) + +function fakedata(rng::AbstractRNG, sz...) y = zeros(sz...) for r in 2:size(y,1) y[r,:] = 0.95 * vec(y[r-1,:]) + randn(rng, size(y,2)) diff --git a/test/imgcomp.jl b/test/imgcomp.jl index f77c0b3a..879a87ea 100644 --- a/test/imgcomp.jl +++ b/test/imgcomp.jl @@ -6,7 +6,7 @@ function replace_rand!(ex::Expr) for arg in ex.args replace_rand!(arg) end - if ex.head === :call && ex.args[1] ∈ (:rand, :randn) + if ex.head === :call && ex.args[1] ∈ (:rand, :randn, :(Plots.fakedata)) pushfirst!(ex.args, ex.args[1]) ex.args[2] = :rng end @@ -35,6 +35,7 @@ function image_comparison_tests( fn = "ref$idx.png" reffn = reference_file(pkg, idx, _current_plots_version) newfn = joinpath(reference_path(pkg, _current_plots_version), fn) + @debug example.exprs # test function func = (fn, idx) -> begin diff --git a/test/runtests.jl b/test/runtests.jl index 5d8c3690..4bea6dd0 100644 --- a/test/runtests.jl +++ b/test/runtests.jl @@ -3,6 +3,7 @@ import ImageMagick using VisualRegressionTests using Plots using Random +using StableRNGs using Test using TestImages using FileIO @@ -11,7 +12,6 @@ using LibGit2 import GeometryBasics using Dates using RecipesBase -using StableRNGs @testset "Plotly standalone" begin @test_nowarn Plots._init_ijulia_plotting()