From 5401ddd1607f51fc560dae1491653762166eb487 Mon Sep 17 00:00:00 2001 From: Renato Lui Geh Date: Sat, 23 May 2020 00:26:33 -0300 Subject: [PATCH 1/3] Add utility function for save_as_dot --- src/IO/CircuitSaver.jl | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/src/IO/CircuitSaver.jl b/src/IO/CircuitSaver.jl index e24c16ea..91dea00a 100644 --- a/src/IO/CircuitSaver.jl +++ b/src/IO/CircuitSaver.jl @@ -166,6 +166,13 @@ function get_nodes_level(circuit::ProbΔ) return levels end +"Save prob circuit to .dot file" +function save_as_dot(root::ProbΔNode, file::String) + circuit = Vector{ProbΔNode}() + foreach(x -> pushfirst!(circuit, x), root) + return save_as_dot(circuit, file) +end + "Save prob circuits to .dot file" function save_as_dot(circuit::ProbΔ, file::String) @@ -221,4 +228,4 @@ function save_as_dot(circuit::ProbΔ, file::String) write(f, "}\n") flush(f) close(f) -end \ No newline at end of file +end From 43ebccc3a12c7065b51515a4edb77a65c93c87f4 Mon Sep 17 00:00:00 2001 From: Pasha Khosravi Date: Sun, 24 May 2020 22:42:20 -0700 Subject: [PATCH 2/3] use node2dag --- src/IO/CircuitSaver.jl | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/src/IO/CircuitSaver.jl b/src/IO/CircuitSaver.jl index 91dea00a..f0090f40 100644 --- a/src/IO/CircuitSaver.jl +++ b/src/IO/CircuitSaver.jl @@ -168,9 +168,7 @@ end "Save prob circuit to .dot file" function save_as_dot(root::ProbΔNode, file::String) - circuit = Vector{ProbΔNode}() - foreach(x -> pushfirst!(circuit, x), root) - return save_as_dot(circuit, file) + return save_as_dot(node2dag(root), file) end "Save prob circuits to .dot file" From 82bd10bfadc91d715473c08c6625a472e0fb6c47 Mon Sep 17 00:00:00 2001 From: Pasha Khosravi Date: Sun, 24 May 2020 23:38:04 -0700 Subject: [PATCH 3/3] fix import, remove extra get_nodes_level --- src/IO/CircuitSaver.jl | 37 ++++++++++--------------------------- 1 file changed, 10 insertions(+), 27 deletions(-) diff --git a/src/IO/CircuitSaver.jl b/src/IO/CircuitSaver.jl index f0090f40..9bba0d78 100644 --- a/src/IO/CircuitSaver.jl +++ b/src/IO/CircuitSaver.jl @@ -1,7 +1,15 @@ using Printf: @sprintf import Base.copy -import LogicCircuits.IO: SDDElement, PSDDElement, save_lines, parse_psdd_file, PsddHeaderLine, LcHeaderLine, save_sdd_file +import LogicCircuits.IO: SDDElement, + PSDDElement, + save_lines, + parse_psdd_file, + PsddHeaderLine, + LcHeaderLine, + save_sdd_file, + save_as_dot, + get_nodes_level # Saving psdd @@ -141,31 +149,6 @@ function save_circuit(name::String, circuit, vtree=nothing) end end -# Save as .dot -"Rank nodes in the same layer left to right" -function get_nodes_level(circuit::ProbΔ) - levels = Vector{Vector{ProbΔNode}}() - current = Vector{ProbΔNode}() - next = Vector{ProbΔNode}() - - push!(next, circuit[end]) - push!(levels, Base.copy(next)) - while !isempty(next) - current, next = next, current - while !isempty(current) - n = popfirst!(current) - if n isa ProbInnerNode - for c in children(n) - if !(c in next) push!(next, c); end - end - end - end - push!(levels, Base.copy(next)) - end - - return levels -end - "Save prob circuit to .dot file" function save_as_dot(root::ProbΔNode, file::String) return save_as_dot(node2dag(root), file) @@ -173,7 +156,7 @@ end "Save prob circuits to .dot file" function save_as_dot(circuit::ProbΔ, file::String) - + # TODO (https://github.com/Juice-jl/LogicCircuits.jl/issues/7) node_cache = Dict{ProbΔNode, Int64}() for (i, n) in enumerate(circuit) node_cache[n] = i