Improve interface, add random walk and reduction implementations, add tests
This commit is contained in:
@@ -3,10 +3,10 @@ import MetagraphOptimization.interaction_result
|
||||
|
||||
using QEDbase
|
||||
using AccurateArithmetic
|
||||
|
||||
include("../examples/profiling_utilities.jl")
|
||||
using Random
|
||||
|
||||
const RTOL = sqrt(eps(Float64))
|
||||
RNG = Random.default_rng()
|
||||
|
||||
function check_particle_reverse_moment(p1::SFourMomentum, p2::SFourMomentum)
|
||||
@test isapprox(abs(p1.E), abs(p2.E))
|
||||
@@ -83,7 +83,7 @@ end
|
||||
@testset "AB->AB after random walk" begin
|
||||
for i in 1:200
|
||||
graph = parse_dag(joinpath(@__DIR__, "..", "input", "AB->AB.txt"), ABCModel())
|
||||
random_walk!(graph, 50)
|
||||
optimize!(RandomWalkOptimizer(RNG), graph, 50)
|
||||
|
||||
@test is_valid(graph)
|
||||
|
||||
@@ -115,7 +115,7 @@ end
|
||||
@testset "AB->ABBB after random walk" begin
|
||||
for i in 1:50
|
||||
graph = parse_dag(joinpath(@__DIR__, "..", "input", "AB->ABBB.txt"), ABCModel())
|
||||
random_walk!(graph, 100)
|
||||
optimize!(RandomWalkOptimizer(RNG), graph, 100)
|
||||
@test is_valid(graph)
|
||||
|
||||
@test isapprox(execute(graph, process_2_4, machine, particles_2_4), expected_result; rtol = RTOL)
|
||||
|
@@ -1,18 +1,42 @@
|
||||
using Random
|
||||
|
||||
RNG = Random.default_rng()
|
||||
|
||||
@testset "Unit Tests Optimization" begin
|
||||
graph = parse_dag(joinpath(@__DIR__, "..", "input", "AB->AB.txt"), ABCModel())
|
||||
graph = parse_dag(joinpath(@__DIR__, "..", "input", "AB->ABBB.txt"), ABCModel())
|
||||
|
||||
@testset "Greedy Optimizer" begin
|
||||
estimator = GlobalMetricEstimator()
|
||||
optimizer = GreedyOptimizer(estimator)
|
||||
# create the optimizers
|
||||
FIXPOINT_OPTIMIZERS = [GreedyOptimizer(GlobalMetricEstimator()), ReductionOptimizer()]
|
||||
NO_FIXPOINT_OPTIMIZERS = [RandomWalkOptimizer(RNG)]
|
||||
|
||||
optimize_step!(optimizer, graph)
|
||||
@testset "Optimizer $optimizer" for optimizer in vcat(NO_FIXPOINT_OPTIMIZERS, FIXPOINT_OPTIMIZERS)
|
||||
@test operation_stack_length(graph) == 0
|
||||
@test optimize_step!(optimizer, graph)
|
||||
|
||||
@test length(graph.operationsToApply) + length(graph.appliedOperations) == 1
|
||||
@test !fixpoint_reached(optimizer, graph)
|
||||
@test operation_stack_length(graph) == 1
|
||||
|
||||
optimize!(optimizer, graph, 10)
|
||||
@test optimize!(optimizer, graph, 10)
|
||||
|
||||
@test length(graph.operationsToApply) + length(graph.appliedOperations) == 11
|
||||
@test !fixpoint_reached(optimizer, graph)
|
||||
|
||||
reset_graph!(graph)
|
||||
end
|
||||
|
||||
@testset "Fixpoint optimizer $optimizer" for optimizer in FIXPOINT_OPTIMIZERS
|
||||
@test operation_stack_length(graph) == 0
|
||||
|
||||
optimize_to_fixpoint!(optimizer, graph)
|
||||
|
||||
@test fixpoint_reached(optimizer, graph)
|
||||
@test !optimize_step!(optimizer, graph)
|
||||
@test !optimize!(optimizer, graph, 10)
|
||||
|
||||
reset_graph!(graph)
|
||||
end
|
||||
|
||||
@testset "No fixpoint optimizer $optimizer" for optimizer in NO_FIXPOINT_OPTIMIZERS
|
||||
@test_throws MethodError optimize_to_fixpoint!(optimizer, graph)
|
||||
end
|
||||
end
|
||||
println("Optimization Unit Tests Complete!")
|
||||
|
Reference in New Issue
Block a user