From f8137c08366d52034248bd1b3b5d92fa9eaced82 Mon Sep 17 00:00:00 2001 From: Anton Reinhard Date: Wed, 8 May 2024 14:00:57 +0200 Subject: [PATCH] Use seeded randomness everywhere --- test/known_graphs.jl | 16 +++++++++------- test/unit_tests_execution.jl | 2 +- test/unit_tests_optimization.jl | 2 +- test/unit_tests_qedmodel.jl | 2 +- 4 files changed, 12 insertions(+), 10 deletions(-) diff --git a/test/known_graphs.jl b/test/known_graphs.jl index 7c3bd67..07035e9 100644 --- a/test/known_graphs.jl +++ b/test/known_graphs.jl @@ -1,6 +1,8 @@ using MetagraphOptimization using Random +RNG = Random.MersenneTwister(321) + function test_known_graph(name::String, n, fusion_test = true) @testset "Test $name Graph ($n)" begin graph = parse_dag(joinpath(@__DIR__, "..", "input", "$name.txt"), ABCModel()) @@ -9,7 +11,7 @@ function test_known_graph(name::String, n, fusion_test = true) if (fusion_test) test_node_fusion(graph) end - test_random_walk(graph, n) + test_random_walk(RNG, graph, n) end end @@ -43,7 +45,7 @@ function test_node_fusion(g::DAG) end end -function test_random_walk(g::DAG, n::Int64) +function test_random_walk(RNG, g::DAG, n::Int64) @testset "Test Random Walk ($n)" begin # the purpose here is to do "random" operations and reverse them again and validate that the graph stays the same and doesn't diverge reset_graph!(g) @@ -54,18 +56,18 @@ function test_random_walk(g::DAG, n::Int64) for i in 1:n # choose push or pop - if rand(Bool) + if rand(RNG, Bool) # push opt = get_operations(g) # choose one of fuse/split/reduce - option = rand(1:3) + option = rand(RNG, 1:3) if option == 1 && !isempty(opt.nodeFusions) - push_operation!(g, rand(collect(opt.nodeFusions))) + push_operation!(g, rand(RNG, collect(opt.nodeFusions))) elseif option == 2 && !isempty(opt.nodeReductions) - push_operation!(g, rand(collect(opt.nodeReductions))) + push_operation!(g, rand(RNG, collect(opt.nodeReductions))) elseif option == 3 && !isempty(opt.nodeSplits) - push_operation!(g, rand(collect(opt.nodeSplits))) + push_operation!(g, rand(RNG, collect(opt.nodeSplits))) else i = i - 1 end diff --git a/test/unit_tests_execution.jl b/test/unit_tests_execution.jl index 6c8b43f..e41388f 100644 --- a/test/unit_tests_execution.jl +++ b/test/unit_tests_execution.jl @@ -9,7 +9,7 @@ import MetagraphOptimization.ABCParticle import MetagraphOptimization.interaction_result const RTOL = sqrt(eps(Float64)) -RNG = Random.default_rng() +RNG = Random.MersenneTwister(0) function check_particle_reverse_moment(p1::SFourMomentum, p2::SFourMomentum) @test isapprox(abs(p1.E), abs(p2.E)) diff --git a/test/unit_tests_optimization.jl b/test/unit_tests_optimization.jl index f216a65..7c1280e 100644 --- a/test/unit_tests_optimization.jl +++ b/test/unit_tests_optimization.jl @@ -1,7 +1,7 @@ using MetagraphOptimization using Random -RNG = Random.default_rng() +RNG = Random.MersenneTwister(0) graph = parse_dag(joinpath(@__DIR__, "..", "input", "AB->ABBB.txt"), ABCModel()) diff --git a/test/unit_tests_qedmodel.jl b/test/unit_tests_qedmodel.jl index 14a03ac..8126605 100644 --- a/test/unit_tests_qedmodel.jl +++ b/test/unit_tests_qedmodel.jl @@ -15,7 +15,7 @@ import MetagraphOptimization.QED_vertex def_momentum = SFourMomentum(1.0, 0.0, 0.0, 0.0) -RNG = Random.default_rng() +RNG = Random.MersenneTwister(0) testparticleTypes = [ PhotonStateful{Incoming, PolX},