Tractables / LogicCircuits.jl

Logic Circuits from the Juice library
https://tractables.github.io/LogicCircuits.jl/dev/
Apache License 2.0
48 stars 4 forks source link

issues running the Juice-Example notebook #107

Closed pedrozudo closed 2 years ago

pedrozudo commented 2 years ago

I started looking at the code and playing around with the library. Is it possible that parts of the API have changed? It seems that some functions used in the example notebook are not supported (besides the plotting #103 )

  1. It looks like the second call below should not be made, ie. not be part of the notebook at all?
c1 = 0.3 * (X1[1] * X2[1]) + 
     0.7 * (X1[2] * X3[2])
c2 = 0.3 * (X1[1] * X2[1]) + 
     0.7 * (X1[2] * X2[2])
println("Is ", tree_formula_string(c1), " decomposable : ", isdecomposable(c1))
println("Is ", tree_formula_string(c1), " structured decomposable : ", isstruct_decomposable(c1))
println("Is ", tree_formula_string(c2), " structured decomposable : ", isstruct_decomposable(c2))
Is ((1 ⋀ 2) ⋁ (-1 ⋀ -3)) decomposable : true

"Circuit not smooth. Inferring vtree not supported yet!"

Stacktrace:
 [1] infer_vtree(root::PlainSumNode, cache::Nothing)
   @ LogicCircuits ~/.julia/packages/LogicCircuits/WsDi1/src/queries/queries.jl:161
 [2] infer_vtree
   @ ~/.julia/packages/LogicCircuits/WsDi1/src/queries/queries.jl:160 [inlined]
 [3] isstruct_decomposable(root::PlainSumNode)
   @ LogicCircuits ~/.julia/packages/LogicCircuits/WsDi1/src/queries/queries.jl:148
 [4] top-level scope
   @ In[22]:6
 [5] eval
   @ ./boot.jl:360 [inlined]
 [6] include_string(mapexpr::typeof(REPL.softscope), mod::Module, code::String, filename::String)
   @ Base ./loading.jl:1094
  1. cnditional?
c1 = (X1[1] + X1[2]) * (X2[1] + X2[2])
println(tree_formula_string(c1))
c2 = condition(c1, Lit(1))
println(tree_formula_string(c2))
UndefVarError: condition not defined

Stacktrace:
 [1] top-level scope
   @ In[21]:3
 [2] eval
   @ ./boot.jl:360 [inlined]
 [3] include_string(mapexpr::typeof(REPL.softscope), mod::Module, code::String, filename::String)
   @ Base ./loading.jl:1094

3.

input = DataFrame(BitArray([1 1 0; 1 0 1]))
println(tree_formula_string(pc))
satisfies(pc, input)
ArgumentError: a 'BitMatrix' is not a table; see `?Tables.table` for ways to treat an AbstractVecOrMat as a table

Stacktrace:
 [1] columns(m::BitMatrix)
   @ Tables ~/.julia/packages/Tables/M26tI/src/matrix.jl:5
 [2] DataFrame(x::BitMatrix; copycols::Nothing)
   @ DataFrames ~/.julia/packages/DataFrames/MA4YO/src/other/tables.jl:58
 [3] DataFrame(x::BitMatrix)
   @ DataFrames ~/.julia/packages/DataFrames/MA4YO/src/other/tables.jl:49
 [4] top-level scope
   @ In[31]:1
 [5] eval
   @ ./boot.jl:360 [inlined]
 [6] include_string(mapexpr::typeof(REPL.softscope), mod::Module, code::String, filename::String)
   @ Base ./loading.jl:1094

I'll leave it here. I have more when running the notebook but I guess they will likely be resolved if the ones above are resolved as well.

Here, is my question: are theses errors due to changes in the API or do I have a wrong install.

Here are my packes:


  [537997a7] AbstractPlotting v0.15.27
  [1520ce14] AbstractTrees v0.3.4
  [6e4b80f9] BenchmarkTools v1.2.2
  [052768ef] CUDA v2.6.3
  [13f3f980] CairoMakie v0.3.19
  [082447d4] ChainRules v1.26.0
  [d360d2e6] ChainRulesCore v1.12.0
  [a93c6f00] DataFrames v0.22.7
  [864edb3b] DataStructures v0.18.9
  [e2ba6199] ExprTools v0.1.3
  [e9467ef8] GLMakie v0.1.30
  [c91e804a] Gadfly v1.3.3
  [fd0ad045] GeometricalPredicates v0.4.0
  [5c1252a2] GeometryBasics v0.3.12
  [86223c79] Graphs v1.5.1
  [7073ff75] IJulia v1.23.2
  [a09fc81d] ImageCore v0.8.22
  [929cbde3] LLVM v3.9.0
  [093fc24a] LightGraphs v1.3.5
  [a7847b3b] LogicCircuits v0.2.4
  [eb30cadb] MLDatasets v0.5.14
  [d96e819e] Parameters v0.12.2
  [91a5bcdd] Plots v1.13.2
  [c3e4b0f8] Pluto v0.17.7
  [2396afbe] ProbabilisticCircuits v0.2.3
  [295af30f] Revise v3.1.15
  [7fb4d062] SententialDecisionDiagrams v0.1.0
  [47aef6b3] SimpleWeightedGraphs v1.2.1
  [2913bbd2] StatsBase v0.33.14
  [e3e34ffb] VoronoiCells v0.2.1
  [72f80fcb] VoronoiDelaunay v0.4.0
  [e88e6eb3] Zygote v0.6.34
khosravipasha commented 2 years ago

Hi, yes there has been quite a few changes since version 0.2.3 assuming you are refering to the notebook from here: https://github.com/Juice-jl/JuiceExamples. The notebook is not fully updated. For more updated examples and documentation you can refer to https://juice-jl.github.io/LogicCircuits.jl/dev/. The examples on the doc website should work since they pass the unit tests before being deployed.

  1. I don't remember the exact reason but I think we now require smoothing the circuit before checking for stucture decomposable. This should work instead:
isstruct_decomposable(smooth(c1))
isstruct_decomposable(smooth(c2))
  1. Yes, we renamed condition to conjoin (since we were really doing conjoin and not condition) See https://github.com/Juice-jl/LogicCircuits.jl/issues/78 for more detail.
  2. DataFrames.jl has changes its API and no longer supports doing this. You can try the following instead:
    DataFrame(BitArray([1 1 0; 1 0 1]), :auto)
khosravipasha commented 2 years ago

Make a new noteook for upgrading to Juice v0.3 versions and fixed the above problems, still need to fix one or two issues, but in the meanwhile can find the notebook in v3 branch here: https://github.com/Juice-jl/JuiceExamples/blob/v3/Juice-Example.ipynb

The plotting should actually work now [if you have LaTeX installed on your machine]. The notebook mentions which packages to install. It should be latest versions of LaTeX.

pedrozudo commented 2 years ago

Ah right, running with the updated version now roughly works (even the plotting, I had a Latex library missing).

I am more or less able to run the whole notebook now, apart from the parts that need the insurance dataset

twenty_datasets("insurance")
AssertionError: name in twenty_dataset_names

    twenty_datasets(::String)@data_load.jl:56
    top-level scope@Local: 1[inlined]

and indeed, the "insurance" is not part of the list in data_load.jl

const twenty_dataset_names = [
        "accidents", "ad", "baudio", "bbc", "bnetflix", "book", "c20ng", "cr52", "cwebkb",
        "dna", "jester", "kdd", "kosarek", "msnbc", "msweb", "nltcs", "plants", "pumsb_star", "tmovie", "tretail", 
        "binarized_mnist"
];
khosravipasha commented 2 years ago

Yes, Insurance is not part of the 20 datasets. It is included in the JuiceExamples repository https://github.com/Juice-jl/JuiceExamples/tree/master/insurance.

pedrozudo commented 2 years ago

I'll close this, seems to work now. Thanks for the help.