metagraphoptimization.jl/examples/profiling_utilities.jl

37 lines
1.1 KiB
Julia
Raw Normal View History

2023-08-18 11:47:12 +02:00
function test_random_walk(g::DAG, n::Int64)
# 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)
properties = get_properties(g)
2023-08-18 11:47:12 +02:00
2023-08-25 10:48:22 +02:00
for i in 1:n
2023-08-18 11:47:12 +02:00
# choose push or pop
if rand(Bool)
# push
opt = get_operations(g)
# choose one of fuse/split/reduce
option = rand(1:3)
if option == 1 && !isempty(opt.nodeFusions)
push_operation!(g, rand(collect(opt.nodeFusions)))
elseif option == 2 && !isempty(opt.nodeReductions)
push_operation!(g, rand(collect(opt.nodeReductions)))
elseif option == 3 && !isempty(opt.nodeSplits)
push_operation!(g, rand(collect(opt.nodeSplits)))
else
i = i - 1
end
else
# pop
if (can_pop(g))
pop_operation!(g)
else
i = i - 1
end
end
end
2023-08-25 10:48:22 +02:00
return reset_graph!(g)
end