Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add SDD to PSDD compilation #56

Merged
merged 4 commits into from
Mar 12, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions src/structured_prob_nodes.jl
Original file line number Diff line number Diff line change
Expand Up @@ -135,6 +135,14 @@ function compile(::Type{<:StructProbCircuit}, vtree::Vtree, circuit::LogicCircui
foldup_aggregate(circuit, f_con, f_lit, f_a, f_o, StructProbCircuit)
end

function compile(::Type{<:StructProbCircuit}, sdd::Sdd)::StructProbCircuit
lc = LogicCircuit(sdd)
plc = propagate_constants(lc, remove_unary=true)
structplc = compile(StructLogicCircuit, vtree(sdd), plc)
sstructplc = smooth(structplc)
compile(StructProbCircuit, sstructplc)
end

function fully_factorized_circuit(::Type{<:ProbCircuit}, vtree::Vtree)
ff_logic_circuit = fully_factorized_circuit(PlainStructLogicCircuit, vtree)
compile(StructProbCircuit, vtree, ff_logic_circuit)
Expand Down
23 changes: 22 additions & 1 deletion test/structured_prob_nodes_tests.jl
Original file line number Diff line number Diff line change
Expand Up @@ -120,5 +120,26 @@ using DataFrames: DataFrame
@test num_parameters_node(r1) == num_parameters_node(r)
@test isempty(intersect(linearize(r1),linearize(r)))

# Convert tests
function apply_test_cnf(n_vars::Int, cnf_path::String)
for i in 1:10
vtree = Vtree(n_vars, :random)
khosravipasha marked this conversation as resolved.
Show resolved Hide resolved
sdd = compile(SddMgr(vtree), zoo_cnf(cnf_path))
@test num_variables(sdd) == n_vars
psdd = compile(StructProbCircuit, sdd)
@test num_variables(psdd) == n_vars
@test issmooth(psdd)
@test isdecomposable(psdd)
@test isdeterministic(psdd)
@test respects_vtree(psdd, vtree)
data = DataFrame(convert(BitMatrix, rand(Bool, 100, n_vars)))
@test all(sdd(data) .== (EVI(psdd, data) .!= -Inf))
end
nothing
end
apply_test_cnf(17, "easy/C17_mince.cnf")
apply_test_cnf(14, "easy/majority_mince.cnf")
apply_test_cnf(21, "easy/b1_mince.cnf")
apply_test_cnf(20, "easy/cm152a_mince.cnf")
end

end