Use SafeTestsets for testing
This commit is contained in:
parent
b7560685d4
commit
3c979b3d34
@ -2,4 +2,5 @@
|
||||
AccurateArithmetic = "22286c92-06ac-501d-9306-4abd417d9753"
|
||||
QEDbase = "10e22c08-3ccb-4172-bfcf-7d7aa3d04d93"
|
||||
Random = "9a3f8284-a2c9-5f02-9a11-845980a1fd5c"
|
||||
SafeTestsets = "1bc83da4-3b8d-516f-aca4-4fe02f6d838f"
|
||||
Test = "8dfed614-e22c-5e08-85e1-65c5234f0b40"
|
||||
|
@ -1,3 +1,4 @@
|
||||
using MetagraphOptimization
|
||||
using Random
|
||||
|
||||
function test_known_graph(name::String, n, fusion_test = true)
|
||||
@ -88,9 +89,6 @@ end
|
||||
|
||||
Random.seed!(0)
|
||||
|
||||
@testset "Test Known ABC-Graphs" begin
|
||||
test_known_graph("AB->AB", 10000)
|
||||
test_known_graph("AB->ABBB", 10000)
|
||||
test_known_graph("AB->ABBBBB", 1000, false)
|
||||
end
|
||||
println("Known Graph Testing Complete!")
|
||||
test_known_graph("AB->AB", 10000)
|
||||
test_known_graph("AB->ABBB", 10000)
|
||||
test_known_graph("AB->ABBBBB", 1000, false)
|
||||
|
@ -1,99 +1,98 @@
|
||||
using MetagraphOptimization
|
||||
|
||||
import MetagraphOptimization.insert_node!
|
||||
import MetagraphOptimization.insert_edge!
|
||||
import MetagraphOptimization.make_node
|
||||
|
||||
@testset "Unit Tests Node Reduction" begin
|
||||
graph = MetagraphOptimization.DAG()
|
||||
graph = MetagraphOptimization.DAG()
|
||||
|
||||
d_exit = insert_node!(graph, make_node(DataTask(10)), track = false)
|
||||
d_exit = insert_node!(graph, make_node(DataTask(10)), track = false)
|
||||
|
||||
s0 = insert_node!(graph, make_node(ComputeTaskS2()), track = false)
|
||||
s0 = insert_node!(graph, make_node(ComputeTaskS2()), track = false)
|
||||
|
||||
ED = insert_node!(graph, make_node(DataTask(3)), track = false)
|
||||
FD = insert_node!(graph, make_node(DataTask(3)), track = false)
|
||||
ED = insert_node!(graph, make_node(DataTask(3)), track = false)
|
||||
FD = insert_node!(graph, make_node(DataTask(3)), track = false)
|
||||
|
||||
EC = insert_node!(graph, make_node(ComputeTaskV()), track = false)
|
||||
FC = insert_node!(graph, make_node(ComputeTaskV()), track = false)
|
||||
EC = insert_node!(graph, make_node(ComputeTaskV()), track = false)
|
||||
FC = insert_node!(graph, make_node(ComputeTaskV()), track = false)
|
||||
|
||||
A1D = insert_node!(graph, make_node(DataTask(4)), track = false)
|
||||
B1D_1 = insert_node!(graph, make_node(DataTask(4)), track = false)
|
||||
B1D_2 = insert_node!(graph, make_node(DataTask(4)), track = false)
|
||||
C1D = insert_node!(graph, make_node(DataTask(4)), track = false)
|
||||
A1D = insert_node!(graph, make_node(DataTask(4)), track = false)
|
||||
B1D_1 = insert_node!(graph, make_node(DataTask(4)), track = false)
|
||||
B1D_2 = insert_node!(graph, make_node(DataTask(4)), track = false)
|
||||
C1D = insert_node!(graph, make_node(DataTask(4)), track = false)
|
||||
|
||||
A1C = insert_node!(graph, make_node(ComputeTaskU()), track = false)
|
||||
B1C_1 = insert_node!(graph, make_node(ComputeTaskU()), track = false)
|
||||
B1C_2 = insert_node!(graph, make_node(ComputeTaskU()), track = false)
|
||||
C1C = insert_node!(graph, make_node(ComputeTaskU()), track = false)
|
||||
A1C = insert_node!(graph, make_node(ComputeTaskU()), track = false)
|
||||
B1C_1 = insert_node!(graph, make_node(ComputeTaskU()), track = false)
|
||||
B1C_2 = insert_node!(graph, make_node(ComputeTaskU()), track = false)
|
||||
C1C = insert_node!(graph, make_node(ComputeTaskU()), track = false)
|
||||
|
||||
AD = insert_node!(graph, make_node(DataTask(5)), track = false)
|
||||
BD = insert_node!(graph, make_node(DataTask(5)), track = false)
|
||||
CD = insert_node!(graph, make_node(DataTask(5)), track = false)
|
||||
AD = insert_node!(graph, make_node(DataTask(5)), track = false)
|
||||
BD = insert_node!(graph, make_node(DataTask(5)), track = false)
|
||||
CD = insert_node!(graph, make_node(DataTask(5)), track = false)
|
||||
|
||||
insert_edge!(graph, s0, d_exit, track = false)
|
||||
insert_edge!(graph, ED, s0, track = false)
|
||||
insert_edge!(graph, FD, s0, track = false)
|
||||
insert_edge!(graph, EC, ED, track = false)
|
||||
insert_edge!(graph, FC, FD, track = false)
|
||||
insert_edge!(graph, s0, d_exit, track = false)
|
||||
insert_edge!(graph, ED, s0, track = false)
|
||||
insert_edge!(graph, FD, s0, track = false)
|
||||
insert_edge!(graph, EC, ED, track = false)
|
||||
insert_edge!(graph, FC, FD, track = false)
|
||||
|
||||
insert_edge!(graph, A1D, EC, track = false)
|
||||
insert_edge!(graph, B1D_1, EC, track = false)
|
||||
insert_edge!(graph, A1D, EC, track = false)
|
||||
insert_edge!(graph, B1D_1, EC, track = false)
|
||||
|
||||
insert_edge!(graph, B1D_2, FC, track = false)
|
||||
insert_edge!(graph, C1D, FC, track = false)
|
||||
insert_edge!(graph, B1D_2, FC, track = false)
|
||||
insert_edge!(graph, C1D, FC, track = false)
|
||||
|
||||
insert_edge!(graph, A1C, A1D, track = false)
|
||||
insert_edge!(graph, B1C_1, B1D_1, track = false)
|
||||
insert_edge!(graph, B1C_2, B1D_2, track = false)
|
||||
insert_edge!(graph, C1C, C1D, track = false)
|
||||
insert_edge!(graph, A1C, A1D, track = false)
|
||||
insert_edge!(graph, B1C_1, B1D_1, track = false)
|
||||
insert_edge!(graph, B1C_2, B1D_2, track = false)
|
||||
insert_edge!(graph, C1C, C1D, track = false)
|
||||
|
||||
insert_edge!(graph, AD, A1C, track = false)
|
||||
insert_edge!(graph, BD, B1C_1, track = false)
|
||||
insert_edge!(graph, BD, B1C_2, track = false)
|
||||
insert_edge!(graph, CD, C1C, track = false)
|
||||
insert_edge!(graph, AD, A1C, track = false)
|
||||
insert_edge!(graph, BD, B1C_1, track = false)
|
||||
insert_edge!(graph, BD, B1C_2, track = false)
|
||||
insert_edge!(graph, CD, C1C, track = false)
|
||||
|
||||
@test is_valid(graph)
|
||||
@test is_valid(graph)
|
||||
|
||||
@test is_exit_node(d_exit)
|
||||
@test is_entry_node(AD)
|
||||
@test is_entry_node(BD)
|
||||
@test is_entry_node(CD)
|
||||
@test is_exit_node(d_exit)
|
||||
@test is_entry_node(AD)
|
||||
@test is_entry_node(BD)
|
||||
@test is_entry_node(CD)
|
||||
|
||||
opt = get_operations(graph)
|
||||
opt = get_operations(graph)
|
||||
|
||||
@test length(opt) == (nodeFusions = 6, nodeReductions = 1, nodeSplits = 1)
|
||||
@test length(opt) == (nodeFusions = 6, nodeReductions = 1, nodeSplits = 1)
|
||||
|
||||
#println("Initial State:\n", opt)
|
||||
#println("Initial State:\n", opt)
|
||||
|
||||
nr = first(opt.nodeReductions)
|
||||
@test Set(nr.input) == Set([B1C_1, B1C_2])
|
||||
push_operation!(graph, nr)
|
||||
opt = get_operations(graph)
|
||||
nr = first(opt.nodeReductions)
|
||||
@test Set(nr.input) == Set([B1C_1, B1C_2])
|
||||
push_operation!(graph, nr)
|
||||
opt = get_operations(graph)
|
||||
|
||||
@test length(opt) == (nodeFusions = 4, nodeReductions = 1, nodeSplits = 1)
|
||||
#println("After 1 Node Reduction:\n", opt)
|
||||
@test length(opt) == (nodeFusions = 4, nodeReductions = 1, nodeSplits = 1)
|
||||
#println("After 1 Node Reduction:\n", opt)
|
||||
|
||||
nr = first(opt.nodeReductions)
|
||||
@test Set(nr.input) == Set([B1D_1, B1D_2])
|
||||
push_operation!(graph, nr)
|
||||
opt = get_operations(graph)
|
||||
nr = first(opt.nodeReductions)
|
||||
@test Set(nr.input) == Set([B1D_1, B1D_2])
|
||||
push_operation!(graph, nr)
|
||||
opt = get_operations(graph)
|
||||
|
||||
@test is_valid(graph)
|
||||
@test is_valid(graph)
|
||||
|
||||
@test length(opt) == (nodeFusions = 4, nodeReductions = 0, nodeSplits = 1)
|
||||
#println("After 2 Node Reductions:\n", opt)
|
||||
@test length(opt) == (nodeFusions = 4, nodeReductions = 0, nodeSplits = 1)
|
||||
#println("After 2 Node Reductions:\n", opt)
|
||||
|
||||
pop_operation!(graph)
|
||||
pop_operation!(graph)
|
||||
|
||||
opt = get_operations(graph)
|
||||
@test length(opt) == (nodeFusions = 4, nodeReductions = 1, nodeSplits = 1)
|
||||
#println("After reverting the second Node Reduction:\n", opt)
|
||||
opt = get_operations(graph)
|
||||
@test length(opt) == (nodeFusions = 4, nodeReductions = 1, nodeSplits = 1)
|
||||
#println("After reverting the second Node Reduction:\n", opt)
|
||||
|
||||
reset_graph!(graph)
|
||||
reset_graph!(graph)
|
||||
|
||||
opt = get_operations(graph)
|
||||
@test length(opt) == (nodeFusions = 6, nodeReductions = 1, nodeSplits = 1)
|
||||
#println("After reverting to the initial state:\n", opt)
|
||||
opt = get_operations(graph)
|
||||
@test length(opt) == (nodeFusions = 6, nodeReductions = 1, nodeSplits = 1)
|
||||
#println("After reverting to the initial state:\n", opt)
|
||||
|
||||
@test is_valid(graph)
|
||||
end
|
||||
println("Node Reduction Unit Tests Complete!")
|
||||
@test is_valid(graph)
|
||||
|
@ -1,17 +1,35 @@
|
||||
using MetagraphOptimization
|
||||
using Test
|
||||
using SafeTestsets
|
||||
|
||||
@testset "MetagraphOptimization Tests" begin
|
||||
@safetestset "Utility Unit Tests" begin
|
||||
include("unit_tests_utility.jl")
|
||||
end
|
||||
@safetestset "Task Unit Tests" begin
|
||||
include("unit_tests_tasks.jl")
|
||||
end
|
||||
@safetestset "Node Unit Tests" begin
|
||||
include("unit_tests_nodes.jl")
|
||||
end
|
||||
@safetestset "Properties Unit Tests" begin
|
||||
include("unit_tests_properties.jl")
|
||||
end
|
||||
@safetestset "Estimation Unit Tests" begin
|
||||
include("unit_tests_estimator.jl")
|
||||
end
|
||||
@safetestset "ABC-Model Unit Tests" begin
|
||||
include("unit_tests_abcmodel.jl")
|
||||
end
|
||||
@safetestset "Node Reduction Unit Tests" begin
|
||||
include("node_reduction.jl")
|
||||
end
|
||||
@safetestset "Graph Unit Tests" begin
|
||||
include("unit_tests_graph.jl")
|
||||
end
|
||||
@safetestset "Execution Unit Tests" begin
|
||||
include("unit_tests_execution.jl")
|
||||
end
|
||||
@safetestset "Optimization Unit Tests" begin
|
||||
include("unit_tests_optimization.jl")
|
||||
|
||||
end
|
||||
@safetestset "Known Graph Tests" begin
|
||||
include("known_graphs.jl")
|
||||
end
|
||||
|
@ -8,19 +8,16 @@ def_momentum = SFourMomentum(1.0, 0.0, 0.0, 0.0)
|
||||
testparticleTypes = [ParticleA, ParticleB, ParticleC]
|
||||
testparticles = [ParticleA(def_momentum), ParticleB(def_momentum), ParticleC(def_momentum)]
|
||||
|
||||
@testset "Unit Tests ABC-Model" begin
|
||||
@testset "Interaction Result" begin
|
||||
for p1 in testparticleTypes, p2 in testparticleTypes
|
||||
if (p1 == p2)
|
||||
@test_throws AssertionError interaction_result(p1, p2)
|
||||
else
|
||||
@test interaction_result(p1, p2) == setdiff(testparticleTypes, [p1, p2])[1]
|
||||
end
|
||||
@testset "Interaction Result" begin
|
||||
for p1 in testparticleTypes, p2 in testparticleTypes
|
||||
if (p1 == p2)
|
||||
@test_throws AssertionError interaction_result(p1, p2)
|
||||
else
|
||||
@test interaction_result(p1, p2) == setdiff(testparticleTypes, [p1, p2])[1]
|
||||
end
|
||||
end
|
||||
|
||||
@testset "Vertex" begin
|
||||
@test isapprox(MetagraphOptimization.vertex(), 1 / 137.0)
|
||||
end
|
||||
end
|
||||
println("ABC-Model Unit Tests Complete!")
|
||||
|
||||
@testset "Vertex" begin
|
||||
@test isapprox(MetagraphOptimization.vertex(), 1 / 137.0)
|
||||
end
|
||||
|
@ -1,3 +1,5 @@
|
||||
using MetagraphOptimization
|
||||
|
||||
function test_op_specific(estimator, graph, nf::NodeFusion)
|
||||
estimate = operation_effect(estimator, graph, nf)
|
||||
data_reduce = data(nf.input[2].task)
|
||||
@ -54,39 +56,36 @@ function test_op(estimator, graph, op)
|
||||
return nothing
|
||||
end
|
||||
|
||||
@testset "Unit Tests Estimator" begin
|
||||
@testset "Global Metric Estimator" for (graph_string, exp_data, exp_computeEffort) in
|
||||
zip(["AB->AB", "AB->ABBB"], [976, 10944], [53, 1075])
|
||||
estimator = GlobalMetricEstimator()
|
||||
@testset "Global Metric Estimator" for (graph_string, exp_data, exp_computeEffort) in
|
||||
zip(["AB->AB", "AB->ABBB"], [976, 10944], [53, 1075])
|
||||
estimator = GlobalMetricEstimator()
|
||||
|
||||
@test cost_type(estimator) == CDCost
|
||||
@test cost_type(estimator) == CDCost
|
||||
|
||||
graph = parse_dag(joinpath(@__DIR__, "..", "input", "$(graph_string).txt"), ABCModel())
|
||||
graph = parse_dag(joinpath(@__DIR__, "..", "input", "$(graph_string).txt"), ABCModel())
|
||||
|
||||
@testset "Graph Cost" begin
|
||||
estimate = graph_cost(estimator, graph)
|
||||
@testset "Graph Cost" begin
|
||||
estimate = graph_cost(estimator, graph)
|
||||
|
||||
@test estimate.data == exp_data
|
||||
@test estimate.computeEffort == exp_computeEffort
|
||||
@test isapprox(estimate.computeIntensity, exp_computeEffort / exp_data)
|
||||
@test estimate.data == exp_data
|
||||
@test estimate.computeEffort == exp_computeEffort
|
||||
@test isapprox(estimate.computeIntensity, exp_computeEffort / exp_data)
|
||||
end
|
||||
|
||||
@testset "Operation Cost" begin
|
||||
ops = get_operations(graph)
|
||||
nfs = copy(ops.nodeFusions)
|
||||
nrs = copy(ops.nodeReductions)
|
||||
nss = copy(ops.nodeSplits)
|
||||
|
||||
for nf in nfs
|
||||
test_op(estimator, graph, nf)
|
||||
end
|
||||
|
||||
@testset "Operation Cost" begin
|
||||
ops = get_operations(graph)
|
||||
nfs = copy(ops.nodeFusions)
|
||||
nrs = copy(ops.nodeReductions)
|
||||
nss = copy(ops.nodeSplits)
|
||||
|
||||
for nf in nfs
|
||||
test_op(estimator, graph, nf)
|
||||
end
|
||||
for nr in nrs
|
||||
test_op(estimator, graph, nr)
|
||||
end
|
||||
for ns in nss
|
||||
test_op(estimator, graph, ns)
|
||||
end
|
||||
for nr in nrs
|
||||
test_op(estimator, graph, nr)
|
||||
end
|
||||
for ns in nss
|
||||
test_op(estimator, graph, ns)
|
||||
end
|
||||
end
|
||||
end
|
||||
println("Estimator Unit Tests Complete!")
|
||||
|
@ -1,10 +1,11 @@
|
||||
import MetagraphOptimization.ABCParticle
|
||||
import MetagraphOptimization.interaction_result
|
||||
|
||||
using MetagraphOptimization
|
||||
using QEDbase
|
||||
using AccurateArithmetic
|
||||
using Random
|
||||
|
||||
import MetagraphOptimization.ABCParticle
|
||||
import MetagraphOptimization.interaction_result
|
||||
|
||||
const RTOL = sqrt(eps(Float64))
|
||||
RNG = Random.default_rng()
|
||||
|
||||
@ -46,174 +47,170 @@ function ground_truth_graph_result(input::ABCProcessInput)
|
||||
return sum_kbn([diagram1_result, diagram2_result])
|
||||
end
|
||||
|
||||
@testset "Unit Tests Execution" begin
|
||||
machine = get_machine_info()
|
||||
machine = get_machine_info()
|
||||
|
||||
process_2_2 = ABCProcessDescription(
|
||||
Dict{Type, Int64}(ParticleA => 1, ParticleB => 1),
|
||||
Dict{Type, Int64}(ParticleA => 1, ParticleB => 1),
|
||||
)
|
||||
process_2_2 = ABCProcessDescription(
|
||||
Dict{Type, Int64}(ParticleA => 1, ParticleB => 1),
|
||||
Dict{Type, Int64}(ParticleA => 1, ParticleB => 1),
|
||||
)
|
||||
|
||||
particles_2_2 = ABCProcessInput(
|
||||
process_2_2,
|
||||
ABCParticle[
|
||||
ParticleA(SFourMomentum(0.823648, 0.0, 0.0, 0.823648)),
|
||||
ParticleB(SFourMomentum(0.823648, 0.0, 0.0, -0.823648)),
|
||||
],
|
||||
ABCParticle[
|
||||
ParticleA(SFourMomentum(0.823648, -0.835061, -0.474802, 0.277915)),
|
||||
ParticleB(SFourMomentum(0.823648, 0.835061, 0.474802, -0.277915)),
|
||||
],
|
||||
)
|
||||
expected_result = ground_truth_graph_result(particles_2_2)
|
||||
particles_2_2 = ABCProcessInput(
|
||||
process_2_2,
|
||||
ABCParticle[
|
||||
ParticleA(SFourMomentum(0.823648, 0.0, 0.0, 0.823648)),
|
||||
ParticleB(SFourMomentum(0.823648, 0.0, 0.0, -0.823648)),
|
||||
],
|
||||
ABCParticle[
|
||||
ParticleA(SFourMomentum(0.823648, -0.835061, -0.474802, 0.277915)),
|
||||
ParticleB(SFourMomentum(0.823648, 0.835061, 0.474802, -0.277915)),
|
||||
],
|
||||
)
|
||||
expected_result = ground_truth_graph_result(particles_2_2)
|
||||
|
||||
@testset "AB->AB no optimization" begin
|
||||
for _ in 1:10 # test in a loop because graph layout should not change the result
|
||||
graph = parse_dag(joinpath(@__DIR__, "..", "input", "AB->AB.txt"), ABCModel())
|
||||
@test isapprox(execute(graph, process_2_2, machine, particles_2_2), expected_result; rtol = RTOL)
|
||||
|
||||
# graph should be fully scheduled after being executed
|
||||
@test is_scheduled(graph)
|
||||
|
||||
func = get_compute_function(graph, process_2_2, machine)
|
||||
@test isapprox(func(particles_2_2), expected_result; rtol = RTOL)
|
||||
end
|
||||
end
|
||||
|
||||
@testset "AB->AB after random walk" begin
|
||||
for i in 1:200
|
||||
graph = parse_dag(joinpath(@__DIR__, "..", "input", "AB->AB.txt"), ABCModel())
|
||||
optimize!(RandomWalkOptimizer(RNG), graph, 50)
|
||||
|
||||
@test is_valid(graph)
|
||||
|
||||
@test isapprox(execute(graph, process_2_2, machine, particles_2_2), expected_result; rtol = RTOL)
|
||||
|
||||
# graph should be fully scheduled after being executed
|
||||
@test is_scheduled(graph)
|
||||
end
|
||||
end
|
||||
|
||||
process_2_4 = ABCProcessDescription(
|
||||
Dict{Type, Int64}(ParticleA => 1, ParticleB => 1),
|
||||
Dict{Type, Int64}(ParticleA => 1, ParticleB => 3),
|
||||
)
|
||||
particles_2_4 = gen_process_input(process_2_4)
|
||||
graph = parse_dag(joinpath(@__DIR__, "..", "input", "AB->ABBB.txt"), ABCModel())
|
||||
expected_result = execute(graph, process_2_4, machine, particles_2_4)
|
||||
|
||||
@testset "AB->ABBB no optimization" begin
|
||||
for _ in 1:5 # test in a loop because graph layout should not change the result
|
||||
graph = parse_dag(joinpath(@__DIR__, "..", "input", "AB->ABBB.txt"), ABCModel())
|
||||
@test isapprox(execute(graph, process_2_4, machine, particles_2_4), expected_result; rtol = RTOL)
|
||||
|
||||
func = get_compute_function(graph, process_2_4, machine)
|
||||
@test isapprox(func(particles_2_4), expected_result; rtol = RTOL)
|
||||
end
|
||||
end
|
||||
|
||||
@testset "AB->ABBB after random walk" begin
|
||||
for i in 1:50
|
||||
graph = parse_dag(joinpath(@__DIR__, "..", "input", "AB->ABBB.txt"), ABCModel())
|
||||
optimize!(RandomWalkOptimizer(RNG), graph, 100)
|
||||
@test is_valid(graph)
|
||||
|
||||
@test isapprox(execute(graph, process_2_4, machine, particles_2_4), expected_result; rtol = RTOL)
|
||||
end
|
||||
end
|
||||
|
||||
@testset "AB->AB large sum fusion" for _ in 1:20
|
||||
@testset "AB->AB no optimization" begin
|
||||
for _ in 1:10 # test in a loop because graph layout should not change the result
|
||||
graph = parse_dag(joinpath(@__DIR__, "..", "input", "AB->AB.txt"), ABCModel())
|
||||
|
||||
# push a fusion with the sum node
|
||||
ops = get_operations(graph)
|
||||
for fusion in ops.nodeFusions
|
||||
if isa(fusion.input[3].task, ComputeTaskSum)
|
||||
push_operation!(graph, fusion)
|
||||
break
|
||||
end
|
||||
end
|
||||
|
||||
# push two more fusions with the fused node
|
||||
for _ in 1:15
|
||||
ops = get_operations(graph)
|
||||
for fusion in ops.nodeFusions
|
||||
if isa(fusion.input[3].task, FusedComputeTask)
|
||||
push_operation!(graph, fusion)
|
||||
break
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
# try execute
|
||||
@test is_valid(graph)
|
||||
expected_result = ground_truth_graph_result(particles_2_2)
|
||||
@test isapprox(execute(graph, process_2_2, machine, particles_2_2), expected_result; rtol = RTOL)
|
||||
|
||||
# graph should be fully scheduled after being executed
|
||||
@test is_scheduled(graph)
|
||||
|
||||
func = get_compute_function(graph, process_2_2, machine)
|
||||
@test isapprox(func(particles_2_2), expected_result; rtol = RTOL)
|
||||
end
|
||||
|
||||
|
||||
@testset "AB->AB large sum fusion" for _ in 1:20
|
||||
graph = parse_dag(joinpath(@__DIR__, "..", "input", "AB->AB.txt"), ABCModel())
|
||||
|
||||
# push a fusion with the sum node
|
||||
ops = get_operations(graph)
|
||||
for fusion in ops.nodeFusions
|
||||
if isa(fusion.input[3].task, ComputeTaskSum)
|
||||
push_operation!(graph, fusion)
|
||||
break
|
||||
end
|
||||
end
|
||||
|
||||
# push two more fusions with the fused node
|
||||
for _ in 1:15
|
||||
ops = get_operations(graph)
|
||||
for fusion in ops.nodeFusions
|
||||
if isa(fusion.input[3].task, FusedComputeTask)
|
||||
push_operation!(graph, fusion)
|
||||
break
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
# try execute
|
||||
@test is_valid(graph)
|
||||
expected_result = ground_truth_graph_result(particles_2_2)
|
||||
@test isapprox(execute(graph, process_2_2, machine, particles_2_2), expected_result; rtol = RTOL)
|
||||
end
|
||||
|
||||
@testset "AB->AB fusion edge case" for _ in 1:20
|
||||
graph = parse_dag(joinpath(@__DIR__, "..", "input", "AB->AB.txt"), ABCModel())
|
||||
|
||||
# push two fusions with ComputeTaskV
|
||||
for _ in 1:2
|
||||
ops = get_operations(graph)
|
||||
for fusion in ops.nodeFusions
|
||||
if isa(fusion.input[1].task, ComputeTaskV)
|
||||
push_operation!(graph, fusion)
|
||||
break
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
# push fusions until the end
|
||||
cont = true
|
||||
while cont
|
||||
cont = false
|
||||
ops = get_operations(graph)
|
||||
for fusion in ops.nodeFusions
|
||||
if isa(fusion.input[1].task, FusedComputeTask)
|
||||
push_operation!(graph, fusion)
|
||||
cont = true
|
||||
break
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
# try execute
|
||||
@test is_valid(graph)
|
||||
expected_result = ground_truth_graph_result(particles_2_2)
|
||||
@test isapprox(execute(graph, process_2_2, machine, particles_2_2), expected_result; rtol = RTOL)
|
||||
end
|
||||
|
||||
end
|
||||
println("Execution Unit Tests Complete!")
|
||||
|
||||
@testset "AB->AB after random walk" begin
|
||||
for i in 1:200
|
||||
graph = parse_dag(joinpath(@__DIR__, "..", "input", "AB->AB.txt"), ABCModel())
|
||||
optimize!(RandomWalkOptimizer(RNG), graph, 50)
|
||||
|
||||
@test is_valid(graph)
|
||||
|
||||
@test isapprox(execute(graph, process_2_2, machine, particles_2_2), expected_result; rtol = RTOL)
|
||||
|
||||
# graph should be fully scheduled after being executed
|
||||
@test is_scheduled(graph)
|
||||
end
|
||||
end
|
||||
|
||||
process_2_4 = ABCProcessDescription(
|
||||
Dict{Type, Int64}(ParticleA => 1, ParticleB => 1),
|
||||
Dict{Type, Int64}(ParticleA => 1, ParticleB => 3),
|
||||
)
|
||||
particles_2_4 = gen_process_input(process_2_4)
|
||||
graph = parse_dag(joinpath(@__DIR__, "..", "input", "AB->ABBB.txt"), ABCModel())
|
||||
expected_result = execute(graph, process_2_4, machine, particles_2_4)
|
||||
|
||||
@testset "AB->ABBB no optimization" begin
|
||||
for _ in 1:5 # test in a loop because graph layout should not change the result
|
||||
graph = parse_dag(joinpath(@__DIR__, "..", "input", "AB->ABBB.txt"), ABCModel())
|
||||
@test isapprox(execute(graph, process_2_4, machine, particles_2_4), expected_result; rtol = RTOL)
|
||||
|
||||
func = get_compute_function(graph, process_2_4, machine)
|
||||
@test isapprox(func(particles_2_4), expected_result; rtol = RTOL)
|
||||
end
|
||||
end
|
||||
|
||||
@testset "AB->ABBB after random walk" begin
|
||||
for i in 1:50
|
||||
graph = parse_dag(joinpath(@__DIR__, "..", "input", "AB->ABBB.txt"), ABCModel())
|
||||
optimize!(RandomWalkOptimizer(RNG), graph, 100)
|
||||
@test is_valid(graph)
|
||||
|
||||
@test isapprox(execute(graph, process_2_4, machine, particles_2_4), expected_result; rtol = RTOL)
|
||||
end
|
||||
end
|
||||
|
||||
@testset "AB->AB large sum fusion" for _ in 1:20
|
||||
graph = parse_dag(joinpath(@__DIR__, "..", "input", "AB->AB.txt"), ABCModel())
|
||||
|
||||
# push a fusion with the sum node
|
||||
ops = get_operations(graph)
|
||||
for fusion in ops.nodeFusions
|
||||
if isa(fusion.input[3].task, ComputeTaskSum)
|
||||
push_operation!(graph, fusion)
|
||||
break
|
||||
end
|
||||
end
|
||||
|
||||
# push two more fusions with the fused node
|
||||
for _ in 1:15
|
||||
ops = get_operations(graph)
|
||||
for fusion in ops.nodeFusions
|
||||
if isa(fusion.input[3].task, FusedComputeTask)
|
||||
push_operation!(graph, fusion)
|
||||
break
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
# try execute
|
||||
@test is_valid(graph)
|
||||
expected_result = ground_truth_graph_result(particles_2_2)
|
||||
@test isapprox(execute(graph, process_2_2, machine, particles_2_2), expected_result; rtol = RTOL)
|
||||
end
|
||||
|
||||
|
||||
@testset "AB->AB large sum fusion" for _ in 1:20
|
||||
graph = parse_dag(joinpath(@__DIR__, "..", "input", "AB->AB.txt"), ABCModel())
|
||||
|
||||
# push a fusion with the sum node
|
||||
ops = get_operations(graph)
|
||||
for fusion in ops.nodeFusions
|
||||
if isa(fusion.input[3].task, ComputeTaskSum)
|
||||
push_operation!(graph, fusion)
|
||||
break
|
||||
end
|
||||
end
|
||||
|
||||
# push two more fusions with the fused node
|
||||
for _ in 1:15
|
||||
ops = get_operations(graph)
|
||||
for fusion in ops.nodeFusions
|
||||
if isa(fusion.input[3].task, FusedComputeTask)
|
||||
push_operation!(graph, fusion)
|
||||
break
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
# try execute
|
||||
@test is_valid(graph)
|
||||
expected_result = ground_truth_graph_result(particles_2_2)
|
||||
@test isapprox(execute(graph, process_2_2, machine, particles_2_2), expected_result; rtol = RTOL)
|
||||
end
|
||||
|
||||
@testset "AB->AB fusion edge case" for _ in 1:20
|
||||
graph = parse_dag(joinpath(@__DIR__, "..", "input", "AB->AB.txt"), ABCModel())
|
||||
|
||||
# push two fusions with ComputeTaskV
|
||||
for _ in 1:2
|
||||
ops = get_operations(graph)
|
||||
for fusion in ops.nodeFusions
|
||||
if isa(fusion.input[1].task, ComputeTaskV)
|
||||
push_operation!(graph, fusion)
|
||||
break
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
# push fusions until the end
|
||||
cont = true
|
||||
while cont
|
||||
cont = false
|
||||
ops = get_operations(graph)
|
||||
for fusion in ops.nodeFusions
|
||||
if isa(fusion.input[1].task, FusedComputeTask)
|
||||
push_operation!(graph, fusion)
|
||||
cont = true
|
||||
break
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
# try execute
|
||||
@test is_valid(graph)
|
||||
expected_result = ground_truth_graph_result(particles_2_2)
|
||||
@test isapprox(execute(graph, process_2_2, machine, particles_2_2), expected_result; rtol = RTOL)
|
||||
end
|
||||
|
@ -1,218 +1,213 @@
|
||||
using MetagraphOptimization
|
||||
|
||||
import MetagraphOptimization.insert_node!
|
||||
import MetagraphOptimization.insert_edge!
|
||||
import MetagraphOptimization.make_node
|
||||
import MetagraphOptimization.siblings
|
||||
import MetagraphOptimization.partners
|
||||
|
||||
@testset "Unit Tests Graph" begin
|
||||
graph = MetagraphOptimization.DAG()
|
||||
graph = MetagraphOptimization.DAG()
|
||||
|
||||
@test length(graph.nodes) == 0
|
||||
@test length(graph.appliedOperations) == 0
|
||||
@test length(graph.operationsToApply) == 0
|
||||
@test length(graph.dirtyNodes) == 0
|
||||
@test length(graph.diff) == (addedNodes = 0, removedNodes = 0, addedEdges = 0, removedEdges = 0)
|
||||
@test length(get_operations(graph)) == (nodeFusions = 0, nodeReductions = 0, nodeSplits = 0)
|
||||
@test length(graph.nodes) == 0
|
||||
@test length(graph.appliedOperations) == 0
|
||||
@test length(graph.operationsToApply) == 0
|
||||
@test length(graph.dirtyNodes) == 0
|
||||
@test length(graph.diff) == (addedNodes = 0, removedNodes = 0, addedEdges = 0, removedEdges = 0)
|
||||
@test length(get_operations(graph)) == (nodeFusions = 0, nodeReductions = 0, nodeSplits = 0)
|
||||
|
||||
# s to output (exit node)
|
||||
d_exit = insert_node!(graph, make_node(DataTask(10)), track = false)
|
||||
# s to output (exit node)
|
||||
d_exit = insert_node!(graph, make_node(DataTask(10)), track = false)
|
||||
|
||||
@test length(graph.nodes) == 1
|
||||
@test length(graph.dirtyNodes) == 1
|
||||
@test length(graph.nodes) == 1
|
||||
@test length(graph.dirtyNodes) == 1
|
||||
|
||||
# final s compute
|
||||
s0 = insert_node!(graph, make_node(ComputeTaskS2()), track = false)
|
||||
# final s compute
|
||||
s0 = insert_node!(graph, make_node(ComputeTaskS2()), track = false)
|
||||
|
||||
@test length(graph.nodes) == 2
|
||||
@test length(graph.dirtyNodes) == 2
|
||||
@test length(graph.nodes) == 2
|
||||
@test length(graph.dirtyNodes) == 2
|
||||
|
||||
# data from v0 and v1 to s0
|
||||
d_v0_s0 = insert_node!(graph, make_node(DataTask(5)), track = false)
|
||||
d_v1_s0 = insert_node!(graph, make_node(DataTask(5)), track = false)
|
||||
# data from v0 and v1 to s0
|
||||
d_v0_s0 = insert_node!(graph, make_node(DataTask(5)), track = false)
|
||||
d_v1_s0 = insert_node!(graph, make_node(DataTask(5)), track = false)
|
||||
|
||||
# v0 and v1 compute
|
||||
v0 = insert_node!(graph, make_node(ComputeTaskV()), track = false)
|
||||
v1 = insert_node!(graph, make_node(ComputeTaskV()), track = false)
|
||||
# v0 and v1 compute
|
||||
v0 = insert_node!(graph, make_node(ComputeTaskV()), track = false)
|
||||
v1 = insert_node!(graph, make_node(ComputeTaskV()), track = false)
|
||||
|
||||
# data from uB, uA, uBp and uAp to v0 and v1
|
||||
d_uB_v0 = insert_node!(graph, make_node(DataTask(3)), track = false)
|
||||
d_uA_v0 = insert_node!(graph, make_node(DataTask(3)), track = false)
|
||||
d_uBp_v1 = insert_node!(graph, make_node(DataTask(3)), track = false)
|
||||
d_uAp_v1 = insert_node!(graph, make_node(DataTask(3)), track = false)
|
||||
# data from uB, uA, uBp and uAp to v0 and v1
|
||||
d_uB_v0 = insert_node!(graph, make_node(DataTask(3)), track = false)
|
||||
d_uA_v0 = insert_node!(graph, make_node(DataTask(3)), track = false)
|
||||
d_uBp_v1 = insert_node!(graph, make_node(DataTask(3)), track = false)
|
||||
d_uAp_v1 = insert_node!(graph, make_node(DataTask(3)), track = false)
|
||||
|
||||
# uB, uA, uBp and uAp computes
|
||||
uB = insert_node!(graph, make_node(ComputeTaskU()), track = false)
|
||||
uA = insert_node!(graph, make_node(ComputeTaskU()), track = false)
|
||||
uBp = insert_node!(graph, make_node(ComputeTaskU()), track = false)
|
||||
uAp = insert_node!(graph, make_node(ComputeTaskU()), track = false)
|
||||
# uB, uA, uBp and uAp computes
|
||||
uB = insert_node!(graph, make_node(ComputeTaskU()), track = false)
|
||||
uA = insert_node!(graph, make_node(ComputeTaskU()), track = false)
|
||||
uBp = insert_node!(graph, make_node(ComputeTaskU()), track = false)
|
||||
uAp = insert_node!(graph, make_node(ComputeTaskU()), track = false)
|
||||
|
||||
# data from PB, PA, PBp and PAp to uB, uA, uBp and uAp
|
||||
d_PB_uB = insert_node!(graph, make_node(DataTask(6)), track = false)
|
||||
d_PA_uA = insert_node!(graph, make_node(DataTask(6)), track = false)
|
||||
d_PBp_uBp = insert_node!(graph, make_node(DataTask(6)), track = false)
|
||||
d_PAp_uAp = insert_node!(graph, make_node(DataTask(6)), track = false)
|
||||
# data from PB, PA, PBp and PAp to uB, uA, uBp and uAp
|
||||
d_PB_uB = insert_node!(graph, make_node(DataTask(6)), track = false)
|
||||
d_PA_uA = insert_node!(graph, make_node(DataTask(6)), track = false)
|
||||
d_PBp_uBp = insert_node!(graph, make_node(DataTask(6)), track = false)
|
||||
d_PAp_uAp = insert_node!(graph, make_node(DataTask(6)), track = false)
|
||||
|
||||
# P computes PB, PA, PBp and PAp
|
||||
PB = insert_node!(graph, make_node(ComputeTaskP()), track = false)
|
||||
PA = insert_node!(graph, make_node(ComputeTaskP()), track = false)
|
||||
PBp = insert_node!(graph, make_node(ComputeTaskP()), track = false)
|
||||
PAp = insert_node!(graph, make_node(ComputeTaskP()), track = false)
|
||||
# P computes PB, PA, PBp and PAp
|
||||
PB = insert_node!(graph, make_node(ComputeTaskP()), track = false)
|
||||
PA = insert_node!(graph, make_node(ComputeTaskP()), track = false)
|
||||
PBp = insert_node!(graph, make_node(ComputeTaskP()), track = false)
|
||||
PAp = insert_node!(graph, make_node(ComputeTaskP()), track = false)
|
||||
|
||||
# entry nodes getting data for P computes
|
||||
d_PB = insert_node!(graph, make_node(DataTask(4)), track = false)
|
||||
d_PA = insert_node!(graph, make_node(DataTask(4)), track = false)
|
||||
d_PBp = insert_node!(graph, make_node(DataTask(4)), track = false)
|
||||
d_PAp = insert_node!(graph, make_node(DataTask(4)), track = false)
|
||||
# entry nodes getting data for P computes
|
||||
d_PB = insert_node!(graph, make_node(DataTask(4)), track = false)
|
||||
d_PA = insert_node!(graph, make_node(DataTask(4)), track = false)
|
||||
d_PBp = insert_node!(graph, make_node(DataTask(4)), track = false)
|
||||
d_PAp = insert_node!(graph, make_node(DataTask(4)), track = false)
|
||||
|
||||
@test length(graph.nodes) == 26
|
||||
@test length(graph.dirtyNodes) == 26
|
||||
@test length(graph.nodes) == 26
|
||||
@test length(graph.dirtyNodes) == 26
|
||||
|
||||
# now for all the edges
|
||||
insert_edge!(graph, d_PB, PB, track = false)
|
||||
insert_edge!(graph, d_PA, PA, track = false)
|
||||
insert_edge!(graph, d_PBp, PBp, track = false)
|
||||
insert_edge!(graph, d_PAp, PAp, track = false)
|
||||
# now for all the edges
|
||||
insert_edge!(graph, d_PB, PB, track = false)
|
||||
insert_edge!(graph, d_PA, PA, track = false)
|
||||
insert_edge!(graph, d_PBp, PBp, track = false)
|
||||
insert_edge!(graph, d_PAp, PAp, track = false)
|
||||
|
||||
insert_edge!(graph, PB, d_PB_uB, track = false)
|
||||
insert_edge!(graph, PA, d_PA_uA, track = false)
|
||||
insert_edge!(graph, PBp, d_PBp_uBp, track = false)
|
||||
insert_edge!(graph, PAp, d_PAp_uAp, track = false)
|
||||
insert_edge!(graph, PB, d_PB_uB, track = false)
|
||||
insert_edge!(graph, PA, d_PA_uA, track = false)
|
||||
insert_edge!(graph, PBp, d_PBp_uBp, track = false)
|
||||
insert_edge!(graph, PAp, d_PAp_uAp, track = false)
|
||||
|
||||
insert_edge!(graph, d_PB_uB, uB, track = false)
|
||||
insert_edge!(graph, d_PA_uA, uA, track = false)
|
||||
insert_edge!(graph, d_PBp_uBp, uBp, track = false)
|
||||
insert_edge!(graph, d_PAp_uAp, uAp, track = false)
|
||||
insert_edge!(graph, d_PB_uB, uB, track = false)
|
||||
insert_edge!(graph, d_PA_uA, uA, track = false)
|
||||
insert_edge!(graph, d_PBp_uBp, uBp, track = false)
|
||||
insert_edge!(graph, d_PAp_uAp, uAp, track = false)
|
||||
|
||||
insert_edge!(graph, uB, d_uB_v0, track = false)
|
||||
insert_edge!(graph, uA, d_uA_v0, track = false)
|
||||
insert_edge!(graph, uBp, d_uBp_v1, track = false)
|
||||
insert_edge!(graph, uAp, d_uAp_v1, track = false)
|
||||
insert_edge!(graph, uB, d_uB_v0, track = false)
|
||||
insert_edge!(graph, uA, d_uA_v0, track = false)
|
||||
insert_edge!(graph, uBp, d_uBp_v1, track = false)
|
||||
insert_edge!(graph, uAp, d_uAp_v1, track = false)
|
||||
|
||||
insert_edge!(graph, d_uB_v0, v0, track = false)
|
||||
insert_edge!(graph, d_uA_v0, v0, track = false)
|
||||
insert_edge!(graph, d_uBp_v1, v1, track = false)
|
||||
insert_edge!(graph, d_uAp_v1, v1, track = false)
|
||||
insert_edge!(graph, d_uB_v0, v0, track = false)
|
||||
insert_edge!(graph, d_uA_v0, v0, track = false)
|
||||
insert_edge!(graph, d_uBp_v1, v1, track = false)
|
||||
insert_edge!(graph, d_uAp_v1, v1, track = false)
|
||||
|
||||
insert_edge!(graph, v0, d_v0_s0, track = false)
|
||||
insert_edge!(graph, v1, d_v1_s0, track = false)
|
||||
insert_edge!(graph, v0, d_v0_s0, track = false)
|
||||
insert_edge!(graph, v1, d_v1_s0, track = false)
|
||||
|
||||
insert_edge!(graph, d_v0_s0, s0, track = false)
|
||||
insert_edge!(graph, d_v1_s0, s0, track = false)
|
||||
insert_edge!(graph, d_v0_s0, s0, track = false)
|
||||
insert_edge!(graph, d_v1_s0, s0, track = false)
|
||||
|
||||
insert_edge!(graph, s0, d_exit, track = false)
|
||||
insert_edge!(graph, s0, d_exit, track = false)
|
||||
|
||||
@test length(graph.nodes) == 26
|
||||
@test length(graph.appliedOperations) == 0
|
||||
@test length(graph.operationsToApply) == 0
|
||||
@test length(graph.dirtyNodes) == 26
|
||||
@test length(graph.diff) == (addedNodes = 0, removedNodes = 0, addedEdges = 0, removedEdges = 0)
|
||||
@test length(graph.nodes) == 26
|
||||
@test length(graph.appliedOperations) == 0
|
||||
@test length(graph.operationsToApply) == 0
|
||||
@test length(graph.dirtyNodes) == 26
|
||||
@test length(graph.diff) == (addedNodes = 0, removedNodes = 0, addedEdges = 0, removedEdges = 0)
|
||||
|
||||
@test is_valid(graph)
|
||||
@test is_valid(graph)
|
||||
|
||||
@test is_entry_node(d_PB)
|
||||
@test is_entry_node(d_PA)
|
||||
@test is_entry_node(d_PBp)
|
||||
@test is_entry_node(d_PBp)
|
||||
@test !is_entry_node(PB)
|
||||
@test !is_entry_node(v0)
|
||||
@test !is_entry_node(d_exit)
|
||||
@test is_entry_node(d_PB)
|
||||
@test is_entry_node(d_PA)
|
||||
@test is_entry_node(d_PBp)
|
||||
@test is_entry_node(d_PBp)
|
||||
@test !is_entry_node(PB)
|
||||
@test !is_entry_node(v0)
|
||||
@test !is_entry_node(d_exit)
|
||||
|
||||
@test is_exit_node(d_exit)
|
||||
@test !is_exit_node(d_uB_v0)
|
||||
@test !is_exit_node(v0)
|
||||
@test is_exit_node(d_exit)
|
||||
@test !is_exit_node(d_uB_v0)
|
||||
@test !is_exit_node(v0)
|
||||
|
||||
@test length(children(v0)) == 2
|
||||
@test length(children(v1)) == 2
|
||||
@test length(parents(v0)) == 1
|
||||
@test length(parents(v1)) == 1
|
||||
@test length(children(v0)) == 2
|
||||
@test length(children(v1)) == 2
|
||||
@test length(parents(v0)) == 1
|
||||
@test length(parents(v1)) == 1
|
||||
|
||||
@test MetagraphOptimization.get_exit_node(graph) == d_exit
|
||||
@test MetagraphOptimization.get_exit_node(graph) == d_exit
|
||||
|
||||
@test length(partners(s0)) == 1
|
||||
@test length(siblings(s0)) == 1
|
||||
@test length(partners(s0)) == 1
|
||||
@test length(siblings(s0)) == 1
|
||||
|
||||
operations = get_operations(graph)
|
||||
@test length(operations) == (nodeFusions = 10, nodeReductions = 0, nodeSplits = 0)
|
||||
@test length(graph.dirtyNodes) == 0
|
||||
operations = get_operations(graph)
|
||||
@test length(operations) == (nodeFusions = 10, nodeReductions = 0, nodeSplits = 0)
|
||||
@test length(graph.dirtyNodes) == 0
|
||||
|
||||
i = 0
|
||||
for op in operations
|
||||
i += 1
|
||||
end
|
||||
@test i == 10
|
||||
@test sum(length(operations)) == 10
|
||||
|
||||
@test operations == get_operations(graph)
|
||||
nf = first(operations.nodeFusions)
|
||||
@test operations == get_operations(graph)
|
||||
nf = first(operations.nodeFusions)
|
||||
|
||||
properties = get_properties(graph)
|
||||
@test properties.computeEffort == 28
|
||||
@test properties.data == 62
|
||||
@test properties.computeIntensity ≈ 28 / 62
|
||||
@test properties.noNodes == 26
|
||||
@test properties.noEdges == 25
|
||||
properties = get_properties(graph)
|
||||
@test properties.computeEffort == 28
|
||||
@test properties.data == 62
|
||||
@test properties.computeIntensity ≈ 28 / 62
|
||||
@test properties.noNodes == 26
|
||||
@test properties.noEdges == 25
|
||||
|
||||
push_operation!(graph, nf)
|
||||
# **does not immediately apply the operation**
|
||||
push_operation!(graph, nf)
|
||||
# **does not immediately apply the operation**
|
||||
|
||||
@test length(graph.nodes) == 26
|
||||
@test length(graph.appliedOperations) == 0
|
||||
@test length(graph.operationsToApply) == 1
|
||||
@test first(graph.operationsToApply) == nf
|
||||
@test length(graph.dirtyNodes) == 0
|
||||
@test length(graph.diff) == (addedNodes = 0, removedNodes = 0, addedEdges = 0, removedEdges = 0)
|
||||
@test length(graph.nodes) == 26
|
||||
@test length(graph.appliedOperations) == 0
|
||||
@test length(graph.operationsToApply) == 1
|
||||
@test first(graph.operationsToApply) == nf
|
||||
@test length(graph.dirtyNodes) == 0
|
||||
@test length(graph.diff) == (addedNodes = 0, removedNodes = 0, addedEdges = 0, removedEdges = 0)
|
||||
|
||||
# this applies pending operations
|
||||
properties = get_properties(graph)
|
||||
# this applies pending operations
|
||||
properties = get_properties(graph)
|
||||
|
||||
@test length(graph.nodes) == 24
|
||||
@test length(graph.appliedOperations) == 1
|
||||
@test length(graph.operationsToApply) == 0
|
||||
@test length(graph.dirtyNodes) != 0
|
||||
@test properties.noNodes == 24
|
||||
@test properties.noEdges == 23
|
||||
@test properties.computeEffort == 28
|
||||
@test properties.data < 62
|
||||
@test properties.computeIntensity > 28 / 62
|
||||
@test length(graph.nodes) == 24
|
||||
@test length(graph.appliedOperations) == 1
|
||||
@test length(graph.operationsToApply) == 0
|
||||
@test length(graph.dirtyNodes) != 0
|
||||
@test properties.noNodes == 24
|
||||
@test properties.noEdges == 23
|
||||
@test properties.computeEffort == 28
|
||||
@test properties.data < 62
|
||||
@test properties.computeIntensity > 28 / 62
|
||||
|
||||
operations = get_operations(graph)
|
||||
@test length(graph.dirtyNodes) == 0
|
||||
operations = get_operations(graph)
|
||||
@test length(graph.dirtyNodes) == 0
|
||||
|
||||
@test length(operations) == (nodeFusions = 9, nodeReductions = 0, nodeSplits = 0)
|
||||
@test !isempty(operations)
|
||||
@test length(operations) == (nodeFusions = 9, nodeReductions = 0, nodeSplits = 0)
|
||||
@test !isempty(operations)
|
||||
|
||||
possibleNF = 9
|
||||
while !isempty(operations.nodeFusions)
|
||||
push_operation!(graph, first(operations.nodeFusions))
|
||||
operations = get_operations(graph)
|
||||
possibleNF = possibleNF - 1
|
||||
@test length(operations) == (nodeFusions = possibleNF, nodeReductions = 0, nodeSplits = 0)
|
||||
end
|
||||
|
||||
@test isempty(operations)
|
||||
|
||||
@test length(operations) == (nodeFusions = 0, nodeReductions = 0, nodeSplits = 0)
|
||||
@test length(graph.dirtyNodes) == 0
|
||||
@test length(graph.nodes) == 6
|
||||
@test length(graph.appliedOperations) == 10
|
||||
@test length(graph.operationsToApply) == 0
|
||||
|
||||
reset_graph!(graph)
|
||||
|
||||
@test length(graph.dirtyNodes) == 26
|
||||
@test length(graph.nodes) == 26
|
||||
@test length(graph.appliedOperations) == 0
|
||||
@test length(graph.operationsToApply) == 0
|
||||
|
||||
properties = get_properties(graph)
|
||||
@test properties.noNodes == 26
|
||||
@test properties.noEdges == 25
|
||||
@test properties.computeEffort == 28
|
||||
@test properties.data == 62
|
||||
@test properties.computeIntensity ≈ 28 / 62
|
||||
|
||||
operations = get_operations(graph)
|
||||
@test length(operations) == (nodeFusions = 10, nodeReductions = 0, nodeSplits = 0)
|
||||
|
||||
@test is_valid(graph)
|
||||
possibleNF = 9
|
||||
while !isempty(operations.nodeFusions)
|
||||
push_operation!(graph, first(operations.nodeFusions))
|
||||
global operations = get_operations(graph)
|
||||
global possibleNF = possibleNF - 1
|
||||
@test length(operations) == (nodeFusions = possibleNF, nodeReductions = 0, nodeSplits = 0)
|
||||
end
|
||||
println("Graph Unit Tests Complete!")
|
||||
|
||||
@test isempty(operations)
|
||||
|
||||
@test length(operations) == (nodeFusions = 0, nodeReductions = 0, nodeSplits = 0)
|
||||
@test length(graph.dirtyNodes) == 0
|
||||
@test length(graph.nodes) == 6
|
||||
@test length(graph.appliedOperations) == 10
|
||||
@test length(graph.operationsToApply) == 0
|
||||
|
||||
reset_graph!(graph)
|
||||
|
||||
@test length(graph.dirtyNodes) == 26
|
||||
@test length(graph.nodes) == 26
|
||||
@test length(graph.appliedOperations) == 0
|
||||
@test length(graph.operationsToApply) == 0
|
||||
|
||||
properties = get_properties(graph)
|
||||
@test properties.noNodes == 26
|
||||
@test properties.noEdges == 25
|
||||
@test properties.computeEffort == 28
|
||||
@test properties.data == 62
|
||||
@test properties.computeIntensity ≈ 28 / 62
|
||||
|
||||
operations = get_operations(graph)
|
||||
@test length(operations) == (nodeFusions = 10, nodeReductions = 0, nodeSplits = 0)
|
||||
|
||||
@test is_valid(graph)
|
||||
|
@ -1,36 +1,34 @@
|
||||
using MetagraphOptimization
|
||||
|
||||
@testset "Unit Tests Nodes" begin
|
||||
nC1 = MetagraphOptimization.make_node(MetagraphOptimization.ComputeTaskU())
|
||||
nC2 = MetagraphOptimization.make_node(MetagraphOptimization.ComputeTaskV())
|
||||
nC3 = MetagraphOptimization.make_node(MetagraphOptimization.ComputeTaskP())
|
||||
nC4 = MetagraphOptimization.make_node(MetagraphOptimization.ComputeTaskSum())
|
||||
nC1 = MetagraphOptimization.make_node(MetagraphOptimization.ComputeTaskU())
|
||||
nC2 = MetagraphOptimization.make_node(MetagraphOptimization.ComputeTaskV())
|
||||
nC3 = MetagraphOptimization.make_node(MetagraphOptimization.ComputeTaskP())
|
||||
nC4 = MetagraphOptimization.make_node(MetagraphOptimization.ComputeTaskSum())
|
||||
|
||||
nD1 = MetagraphOptimization.make_node(MetagraphOptimization.DataTask(10))
|
||||
nD2 = MetagraphOptimization.make_node(MetagraphOptimization.DataTask(20))
|
||||
nD1 = MetagraphOptimization.make_node(MetagraphOptimization.DataTask(10))
|
||||
nD2 = MetagraphOptimization.make_node(MetagraphOptimization.DataTask(20))
|
||||
|
||||
@test_throws ErrorException MetagraphOptimization.make_edge(nC1, nC2)
|
||||
@test_throws ErrorException MetagraphOptimization.make_edge(nC1, nC1)
|
||||
@test_throws ErrorException MetagraphOptimization.make_edge(nC3, nC4)
|
||||
@test_throws ErrorException MetagraphOptimization.make_edge(nD1, nD2)
|
||||
@test_throws ErrorException MetagraphOptimization.make_edge(nD1, nD1)
|
||||
@test_throws ErrorException MetagraphOptimization.make_edge(nC1, nC2)
|
||||
@test_throws ErrorException MetagraphOptimization.make_edge(nC1, nC1)
|
||||
@test_throws ErrorException MetagraphOptimization.make_edge(nC3, nC4)
|
||||
@test_throws ErrorException MetagraphOptimization.make_edge(nD1, nD2)
|
||||
@test_throws ErrorException MetagraphOptimization.make_edge(nD1, nD1)
|
||||
|
||||
ed1 = MetagraphOptimization.make_edge(nC1, nD1)
|
||||
ed2 = MetagraphOptimization.make_edge(nD1, nC2)
|
||||
ed3 = MetagraphOptimization.make_edge(nC2, nD2)
|
||||
ed4 = MetagraphOptimization.make_edge(nD2, nC3)
|
||||
ed1 = MetagraphOptimization.make_edge(nC1, nD1)
|
||||
ed2 = MetagraphOptimization.make_edge(nD1, nC2)
|
||||
ed3 = MetagraphOptimization.make_edge(nC2, nD2)
|
||||
ed4 = MetagraphOptimization.make_edge(nD2, nC3)
|
||||
|
||||
@test nC1 != nC2
|
||||
@test nD1 != nD2
|
||||
@test nC1 != nD1
|
||||
@test nC3 != nC4
|
||||
@test nC1 != nC2
|
||||
@test nD1 != nD2
|
||||
@test nC1 != nD1
|
||||
@test nC3 != nC4
|
||||
|
||||
nC1_2 = copy(nC1)
|
||||
@test nC1_2 != nC1
|
||||
nC1_2 = copy(nC1)
|
||||
@test nC1_2 != nC1
|
||||
|
||||
nD1_2 = copy(nD1)
|
||||
@test nD1_2 != nD1
|
||||
nD1_2 = copy(nD1)
|
||||
@test nD1_2 != nD1
|
||||
|
||||
nD1_c = MetagraphOptimization.make_node(MetagraphOptimization.DataTask(10))
|
||||
@test nD1_c != nD1
|
||||
end
|
||||
println("Node Unit Tests Complete!")
|
||||
nD1_c = MetagraphOptimization.make_node(MetagraphOptimization.DataTask(10))
|
||||
@test nD1_c != nD1
|
||||
|
@ -1,42 +1,40 @@
|
||||
using MetagraphOptimization
|
||||
using Random
|
||||
|
||||
RNG = Random.default_rng()
|
||||
|
||||
@testset "Unit Tests Optimization" begin
|
||||
graph = parse_dag(joinpath(@__DIR__, "..", "input", "AB->ABBB.txt"), ABCModel())
|
||||
graph = parse_dag(joinpath(@__DIR__, "..", "input", "AB->ABBB.txt"), ABCModel())
|
||||
|
||||
# create the optimizers
|
||||
FIXPOINT_OPTIMIZERS = [GreedyOptimizer(GlobalMetricEstimator()), ReductionOptimizer()]
|
||||
NO_FIXPOINT_OPTIMIZERS = [RandomWalkOptimizer(RNG)]
|
||||
# create the optimizers
|
||||
FIXPOINT_OPTIMIZERS = [GreedyOptimizer(GlobalMetricEstimator()), ReductionOptimizer()]
|
||||
NO_FIXPOINT_OPTIMIZERS = [RandomWalkOptimizer(RNG)]
|
||||
|
||||
@testset "Optimizer $optimizer" for optimizer in vcat(NO_FIXPOINT_OPTIMIZERS, FIXPOINT_OPTIMIZERS)
|
||||
@test operation_stack_length(graph) == 0
|
||||
@test 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 !fixpoint_reached(optimizer, graph)
|
||||
@test operation_stack_length(graph) == 1
|
||||
@test !fixpoint_reached(optimizer, graph)
|
||||
@test operation_stack_length(graph) == 1
|
||||
|
||||
@test optimize!(optimizer, graph, 10)
|
||||
@test optimize!(optimizer, graph, 10)
|
||||
|
||||
@test !fixpoint_reached(optimizer, graph)
|
||||
@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
|
||||
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
|
||||
println("Optimization Unit Tests Complete!")
|
||||
|
@ -1,35 +1,33 @@
|
||||
using MetagraphOptimization
|
||||
|
||||
@testset "GraphProperties Unit Tests" begin
|
||||
prop = GraphProperties()
|
||||
prop = GraphProperties()
|
||||
|
||||
@test prop.data == 0.0
|
||||
@test prop.computeEffort == 0.0
|
||||
@test prop.computeIntensity == 0.0
|
||||
@test prop.noNodes == 0.0
|
||||
@test prop.noEdges == 0.0
|
||||
@test prop.data == 0.0
|
||||
@test prop.computeEffort == 0.0
|
||||
@test prop.computeIntensity == 0.0
|
||||
@test prop.noNodes == 0.0
|
||||
@test prop.noEdges == 0.0
|
||||
|
||||
prop2 = (data = 5.0, computeEffort = 6.0, computeIntensity = 6.0 / 5.0, noNodes = 2, noEdges = 3)::GraphProperties
|
||||
prop2 = (data = 5.0, computeEffort = 6.0, computeIntensity = 6.0 / 5.0, noNodes = 2, noEdges = 3)::GraphProperties
|
||||
|
||||
@test prop + prop2 == prop2
|
||||
@test prop2 - prop == prop2
|
||||
@test prop + prop2 == prop2
|
||||
@test prop2 - prop == prop2
|
||||
|
||||
negProp = -prop2
|
||||
@test negProp.data == -5.0
|
||||
@test negProp.computeEffort == -6.0
|
||||
@test negProp.computeIntensity == 6.0 / 5.0
|
||||
@test negProp.noNodes == -2
|
||||
@test negProp.noEdges == -3
|
||||
negProp = -prop2
|
||||
@test negProp.data == -5.0
|
||||
@test negProp.computeEffort == -6.0
|
||||
@test negProp.computeIntensity == 6.0 / 5.0
|
||||
@test negProp.noNodes == -2
|
||||
@test negProp.noEdges == -3
|
||||
|
||||
@test negProp + prop2 == GraphProperties()
|
||||
@test negProp + prop2 == GraphProperties()
|
||||
|
||||
prop3 = (data = 7.0, computeEffort = 3.0, computeIntensity = 7.0 / 3.0, noNodes = -3, noEdges = 2)::GraphProperties
|
||||
prop3 = (data = 7.0, computeEffort = 3.0, computeIntensity = 7.0 / 3.0, noNodes = -3, noEdges = 2)::GraphProperties
|
||||
|
||||
propSum = prop2 + prop3
|
||||
propSum = prop2 + prop3
|
||||
|
||||
@test propSum.data == 12.0
|
||||
@test propSum.computeEffort == 9.0
|
||||
@test propSum.computeIntensity == 9.0 / 12.0
|
||||
@test propSum.noNodes == -1
|
||||
@test propSum.noEdges == 5
|
||||
end
|
||||
println("GraphProperties Unit Tests Complete!")
|
||||
@test propSum.data == 12.0
|
||||
@test propSum.computeEffort == 9.0
|
||||
@test propSum.computeIntensity == 9.0 / 12.0
|
||||
@test propSum.noNodes == -1
|
||||
@test propSum.noEdges == 5
|
||||
|
@ -1,51 +1,49 @@
|
||||
using MetagraphOptimization
|
||||
|
||||
@testset "Task Unit Tests" begin
|
||||
S1 = MetagraphOptimization.ComputeTaskS1()
|
||||
S2 = MetagraphOptimization.ComputeTaskS2()
|
||||
U = MetagraphOptimization.ComputeTaskU()
|
||||
V = MetagraphOptimization.ComputeTaskV()
|
||||
P = MetagraphOptimization.ComputeTaskP()
|
||||
Sum = MetagraphOptimization.ComputeTaskSum()
|
||||
S1 = MetagraphOptimization.ComputeTaskS1()
|
||||
S2 = MetagraphOptimization.ComputeTaskS2()
|
||||
U = MetagraphOptimization.ComputeTaskU()
|
||||
V = MetagraphOptimization.ComputeTaskV()
|
||||
P = MetagraphOptimization.ComputeTaskP()
|
||||
Sum = MetagraphOptimization.ComputeTaskSum()
|
||||
|
||||
Data10 = MetagraphOptimization.DataTask(10)
|
||||
Data20 = MetagraphOptimization.DataTask(20)
|
||||
Data10 = MetagraphOptimization.DataTask(10)
|
||||
Data20 = MetagraphOptimization.DataTask(20)
|
||||
|
||||
@test MetagraphOptimization.compute_effort(S1) == 11
|
||||
@test MetagraphOptimization.compute_effort(S2) == 12
|
||||
@test MetagraphOptimization.compute_effort(U) == 1
|
||||
@test MetagraphOptimization.compute_effort(V) == 6
|
||||
@test MetagraphOptimization.compute_effort(P) == 0
|
||||
@test MetagraphOptimization.compute_effort(Sum) == 1
|
||||
@test MetagraphOptimization.compute_effort(Data10) == 0
|
||||
@test MetagraphOptimization.compute_effort(Data20) == 0
|
||||
@test MetagraphOptimization.compute_effort(S1) == 11
|
||||
@test MetagraphOptimization.compute_effort(S2) == 12
|
||||
@test MetagraphOptimization.compute_effort(U) == 1
|
||||
@test MetagraphOptimization.compute_effort(V) == 6
|
||||
@test MetagraphOptimization.compute_effort(P) == 0
|
||||
@test MetagraphOptimization.compute_effort(Sum) == 1
|
||||
@test MetagraphOptimization.compute_effort(Data10) == 0
|
||||
@test MetagraphOptimization.compute_effort(Data20) == 0
|
||||
|
||||
@test MetagraphOptimization.data(S1) == 0
|
||||
@test MetagraphOptimization.data(S2) == 0
|
||||
@test MetagraphOptimization.data(U) == 0
|
||||
@test MetagraphOptimization.data(V) == 0
|
||||
@test MetagraphOptimization.data(P) == 0
|
||||
@test MetagraphOptimization.data(Sum) == 0
|
||||
@test MetagraphOptimization.data(Data10) == 10
|
||||
@test MetagraphOptimization.data(Data20) == 20
|
||||
@test MetagraphOptimization.data(S1) == 0
|
||||
@test MetagraphOptimization.data(S2) == 0
|
||||
@test MetagraphOptimization.data(U) == 0
|
||||
@test MetagraphOptimization.data(V) == 0
|
||||
@test MetagraphOptimization.data(P) == 0
|
||||
@test MetagraphOptimization.data(Sum) == 0
|
||||
@test MetagraphOptimization.data(Data10) == 10
|
||||
@test MetagraphOptimization.data(Data20) == 20
|
||||
|
||||
@test S1 != S2
|
||||
@test Data10 != Data20
|
||||
@test S1 != S2
|
||||
@test Data10 != Data20
|
||||
|
||||
Data10_2 = MetagraphOptimization.DataTask(10)
|
||||
Data10_2 = MetagraphOptimization.DataTask(10)
|
||||
|
||||
# two data tasks with same data are identical, their nodes need not be
|
||||
@test Data10_2 == Data10
|
||||
# two data tasks with same data are identical, their nodes need not be
|
||||
@test Data10_2 == Data10
|
||||
|
||||
@test Data10 == Data10
|
||||
@test S1 == S1
|
||||
@test Data10 == Data10
|
||||
@test S1 == S1
|
||||
|
||||
Data10_3 = copy(Data10)
|
||||
Data10_3 = copy(Data10)
|
||||
|
||||
@test Data10_3 == Data10
|
||||
@test Data10_3 == Data10
|
||||
|
||||
S1_2 = copy(S1)
|
||||
S1_2 = copy(S1)
|
||||
|
||||
@test S1_2 == S1
|
||||
@test S1 == MetagraphOptimization.ComputeTaskS1()
|
||||
end
|
||||
println("Task Unit Tests Complete!")
|
||||
@test S1_2 == S1
|
||||
@test S1 == MetagraphOptimization.ComputeTaskS1()
|
||||
|
@ -1,11 +1,10 @@
|
||||
using MetagraphOptimization
|
||||
import MetagraphOptimization.bytes_to_human_readable
|
||||
|
||||
@testset "Unit Tests Utility" begin
|
||||
@test MetagraphOptimization.bytes_to_human_readable(0) == "0.0 B"
|
||||
@test MetagraphOptimization.bytes_to_human_readable(1020) == "1020.0 B"
|
||||
@test MetagraphOptimization.bytes_to_human_readable(1025) == "1.001 KiB"
|
||||
@test MetagraphOptimization.bytes_to_human_readable(684235) == "668.2 KiB"
|
||||
@test MetagraphOptimization.bytes_to_human_readable(86214576) == "82.22 MiB"
|
||||
@test MetagraphOptimization.bytes_to_human_readable(9241457698) == "8.607 GiB"
|
||||
@test MetagraphOptimization.bytes_to_human_readable(3218598654367) == "2.927 TiB"
|
||||
end
|
||||
println("Utility Unit Tests Complete!")
|
||||
@test bytes_to_human_readable(0) == "0.0 B"
|
||||
@test bytes_to_human_readable(1020) == "1020.0 B"
|
||||
@test bytes_to_human_readable(1025) == "1.001 KiB"
|
||||
@test bytes_to_human_readable(684235) == "668.2 KiB"
|
||||
@test bytes_to_human_readable(86214576) == "82.22 MiB"
|
||||
@test bytes_to_human_readable(9241457698) == "8.607 GiB"
|
||||
@test bytes_to_human_readable(3218598654367) == "2.927 TiB"
|
||||
|
Loading…
x
Reference in New Issue
Block a user