From e591da10d384838b0c20083804501473a65728fe Mon Sep 17 00:00:00 2001 From: Anton Reinhard Date: Fri, 18 Aug 2023 10:05:01 +0200 Subject: [PATCH] Move import to abc_model/ and rename to parse --- examples/ABAB_graph.jl | 108 -------------------------- examples/import_bench.jl | 4 +- examples/plot_chain.jl | 2 +- examples/plot_star.jl | 2 +- src/MetagraphOptimization.jl | 6 +- src/{import.jl => abc_model/parse.jl} | 3 +- test/known_graphs.jl | 2 +- 7 files changed, 10 insertions(+), 117 deletions(-) delete mode 100644 examples/ABAB_graph.jl rename src/{import.jl => abc_model/parse.jl} (98%) diff --git a/examples/ABAB_graph.jl b/examples/ABAB_graph.jl deleted file mode 100644 index 7b91b91..0000000 --- a/examples/ABAB_graph.jl +++ /dev/null @@ -1,108 +0,0 @@ -using MetagraphOptimization - -import MetagraphOptimization.insert_node! -import MetagraphOptimization.insert_edge! -import MetagraphOptimization.make_node -import MetagraphOptimization.make_edge - -function main() - graph = DAG() - - # s to output (exit node) - d_exit = insert_node!(graph, make_node(DataTask(10))) - - # final s compute - s0 = insert_node!(graph, make_node(ComputeTaskS2())) - - # data from v0 and v1 to s0 - d_v0_s0 = insert_node!(graph, make_node(DataTask(5))) - d_v1_s0 = insert_node!(graph, make_node(DataTask(5))) - - # v0 and v1 compute - v0 = insert_node!(graph, make_node(ComputeTaskV())) - v1 = insert_node!(graph, make_node(ComputeTaskV())) - - # data from uB, uA, uBp and uAp to v0 and v1 - d_uB_v0 = insert_node!(graph, make_node(DataTask(3))) - d_uA_v0 = insert_node!(graph, make_node(DataTask(3))) - d_uBp_v1 = insert_node!(graph, make_node(DataTask(3))) - d_uAp_v1 = insert_node!(graph, make_node(DataTask(3))) - - # uB, uA, uBp and uAp computes - uB = insert_node!(graph, make_node(ComputeTaskU())) - uA = insert_node!(graph, make_node(ComputeTaskU())) - uBp = insert_node!(graph, make_node(ComputeTaskU())) - uAp = insert_node!(graph, make_node(ComputeTaskU())) - - # data from PB, PA, PBp and PAp to uB, uA, uBp and uAp - d_PB_uB = insert_node!(graph, make_node(DataTask(6))) - d_PA_uA = insert_node!(graph, make_node(DataTask(6))) - d_PBp_uBp = insert_node!(graph, make_node(DataTask(6))) - d_PAp_uAp = insert_node!(graph, make_node(DataTask(6))) - - # P computes PB, PA, PBp and PAp - PB = insert_node!(graph, make_node(ComputeTaskP())) - PA = insert_node!(graph, make_node(ComputeTaskP())) - PBp = insert_node!(graph, make_node(ComputeTaskP())) - PAp = insert_node!(graph, make_node(ComputeTaskP())) - - # entry nodes getting data for P computes - d_PB = insert_node!(graph, make_node(DataTask(4))) - d_PA = insert_node!(graph, make_node(DataTask(4))) - d_PBp = insert_node!(graph, make_node(DataTask(4))) - d_PAp = insert_node!(graph, make_node(DataTask(4))) - - # now for all the edgese - insert_edge!(graph, make_edge(d_PB, PB)) - insert_edge!(graph, make_edge(d_PA, PA)) - insert_edge!(graph, make_edge(d_PBp, PBp)) - insert_edge!(graph, make_edge(d_PAp, PAp)) - - insert_edge!(graph, make_edge(PB, d_PB_uB)) - insert_edge!(graph, make_edge(PA, d_PA_uA)) - insert_edge!(graph, make_edge(PBp, d_PBp_uBp)) - insert_edge!(graph, make_edge(PAp, d_PAp_uAp)) - - insert_edge!(graph, make_edge(d_PB_uB, uB)) - insert_edge!(graph, make_edge(d_PA_uA, uA)) - insert_edge!(graph, make_edge(d_PBp_uBp, uBp)) - insert_edge!(graph, make_edge(d_PAp_uAp, uAp)) - - insert_edge!(graph, make_edge(uB, d_uB_v0)) - insert_edge!(graph, make_edge(uA, d_uA_v0)) - insert_edge!(graph, make_edge(uBp, d_uBp_v1)) - insert_edge!(graph, make_edge(uAp, d_uAp_v1)) - - insert_edge!(graph, make_edge(d_uB_v0, v0)) - insert_edge!(graph, make_edge(d_uA_v0, v0)) - insert_edge!(graph, make_edge(d_uBp_v1, v1)) - insert_edge!(graph, make_edge(d_uAp_v1, v1)) - - insert_edge!(graph, make_edge(v0, d_v0_s0)) - insert_edge!(graph, make_edge(v1, d_v1_s0)) - - insert_edge!(graph, make_edge(d_v0_s0, s0)) - insert_edge!(graph, make_edge(d_v1_s0, s0)) - - insert_edge!(graph, make_edge(s0, d_exit)) - - print(graph) - - println("Available optimizations from here:") - println(generate_options(graph)) - - # fuse some things - fuse1 = node_fusion!(graph, PB, d_PB_uB, uB) - fuse2 = node_fusion!(graph, PA, d_PA_uA, uA) - fuse3 = node_fusion!(graph, PBp, d_PBp_uBp, uBp) - fuse4 = node_fusion!(graph, PAp, d_PAp_uAp, uAp) - - # on this graph, nothing can be reduced - println("Same graph after node fusion") - print(graph) - - println("Available optimizations from here:") - println(generate_options(graph)) -end - -main() diff --git a/examples/import_bench.jl b/examples/import_bench.jl index 61f3671..6c30bf4 100644 --- a/examples/import_bench.jl +++ b/examples/import_bench.jl @@ -14,12 +14,12 @@ function bench_txt(filepath::String, bench::Bool = true) end println(name, ":") - g = import_txt(filepath) + g = parse_abc(filepath) print(g) println(" Graph size in memory: ", bytes_to_human_readable(Base.summarysize(g))) if (bench) - @btime import_txt($filepath) + @btime parse_abc($filepath) println() end end diff --git a/examples/plot_chain.jl b/examples/plot_chain.jl index ea47528..f66861f 100644 --- a/examples/plot_chain.jl +++ b/examples/plot_chain.jl @@ -12,7 +12,7 @@ function gen_plot(filepath) return end - g = import_txt(filepath) + g = parse_abc(filepath) Random.seed!(1) diff --git a/examples/plot_star.jl b/examples/plot_star.jl index 0bf249b..dfc34cf 100644 --- a/examples/plot_star.jl +++ b/examples/plot_star.jl @@ -12,7 +12,7 @@ function gen_plot(filepath) return end - g = import_txt(filepath) + g = parse_abc(filepath) Random.seed!(1) diff --git a/src/MetagraphOptimization.jl b/src/MetagraphOptimization.jl index 26a04ae..61432d4 100644 --- a/src/MetagraphOptimization.jl +++ b/src/MetagraphOptimization.jl @@ -1,10 +1,10 @@ module MetagraphOptimization export Node, Edge, ComputeTaskNode, DataTaskNode, DAG -export AbstractTask, AbstractComputeTask, AbstractDataTask, DataTask, ComputeTaskP, ComputeTaskS1, ComputeTaskS2, ComputeTaskV, ComputeTaskU, ComputeTaskSum, FusedComputeTask +export AbstractTask, AbstractComputeTask, AbstractDataTask, DataTask, FusedComputeTask export make_node, make_edge, insert_node, insert_edge, is_entry_node, is_exit_node, parents, children, compute, graph_properties, get_exit_node, is_valid export NodeFusion, NodeReduction, NodeSplit, push_operation!, pop_operation!, can_pop, reset_graph!, get_operations -export import_txt +export parse_abc, ComputeTaskP, ComputeTaskS1, ComputeTaskS2, ComputeTaskV, ComputeTaskU, ComputeTaskSum export ==, in, show, isempty, delete!, length @@ -27,10 +27,10 @@ include("task_functions.jl") include("node_functions.jl") include("graph_functions.jl") include("graph_operations.jl") -include("import.jl") include("utility.jl") include("abc_model/tasks.jl") include("abc_model/task_functions.jl") +include("abc_model/parse.jl") end # module MetagraphOptimization diff --git a/src/import.jl b/src/abc_model/parse.jl similarity index 98% rename from src/import.jl rename to src/abc_model/parse.jl index d4be7e1..3ece7ea 100644 --- a/src/import.jl +++ b/src/abc_model/parse.jl @@ -20,7 +20,8 @@ function parse_edges(input::AbstractString) return output end -function import_txt(filename::String, verbose::Bool = false) +# reads an abc-model process from the given file +function parse_abc(filename::String, verbose::Bool = false) file = open(filename, "r") if (verbose) println("Opened file") end diff --git a/test/known_graphs.jl b/test/known_graphs.jl index cff920f..beaca4b 100644 --- a/test/known_graphs.jl +++ b/test/known_graphs.jl @@ -2,7 +2,7 @@ using Random function test_known_graph(name::String, n, fusion_test=true) @testset "Test $name Graph ($n)" begin - graph = import_txt(joinpath(@__DIR__, "..", "examples", "$name.txt")) + graph = parse_abc(joinpath(@__DIR__, "..", "examples", "$name.txt")) props = graph_properties(graph) if (fusion_test)