[BUG] Running addition.py gives a Python error
tillmo opened this issue · 6 comments
Describe the bug
Running deepproblog/src/deepproblog/examples/MNIST/addition.py
gives a Python error
To Reproduce
Steps to reproduce the behavior:
pip3 install git+https://github.com/wannesm/PySDD.git#egg=PySDD
pip3 install git+https://github.com/yuce/pyswip.git
git clone https://github.com/ML-KULeuven/deepproblog.git
cd deepproblog
pip3 install -e .
cd src/deepproblog/examples/MNIST
python 3addition.py
Note that I need to install PySDD
and pyswip
from sources (as above) in order to avoid other errors. Also, the swi-prolog version needs to come from a PPA (see below).
Expected behavior
There should be no error.
Desktop (please complete the following information):
- OS: Ubuntu 20.04
- Python Version: 3.8.10
apt-cache policy swi-prolog
swi-prolog:
Installed: 8.4.2-1-g94306448a-focalppa2
Installation candidate: 8.4.2-1-g94306448a-focalppa2
Version table:
*** 8.4.2-1-g94306448a-focalppa2 500
500 http://ppa.launchpad.net/swi-prolog/stable/ubuntu focal/main amd64 Packages
[...]
Additional context
Here is the error:
~/programs/deepproblog/src/deepproblog/examples/MNIST$ python3 addition.py
addition_method_gm_N_1_pretrain_0_exploration_False_run_0_220518_111251556629
Training for 1 epoch(s)
Epoch 1
Traceback (most recent call last):
File "addition.py", line 66, in <module>
train = train_model(model, loader, 1, log_iter=100, profile=0)
File "/home/till/programs/deepproblog/src/deepproblog/train.py", line 200, in train_model
train_object.train(loader, stop_condition, **kwargs)
File "/home/till/programs/deepproblog/src/deepproblog/train.py", line 128, in train
loss = self.get_loss(batch, loss_function)
File "/home/till/programs/deepproblog/src/deepproblog/train.py", line 39, in get_loss
result = self.model.solve(batch)
File "/home/till/programs/deepproblog/src/deepproblog/model.py", line 106, in solve
return self.solver.solve(batch)
File "/home/till/programs/deepproblog/src/deepproblog/solver.py", line 80, in solve
acs: List[ArithmeticCircuit] = [self.cache.get(q) for q in batch]
File "/home/till/programs/deepproblog/src/deepproblog/solver.py", line 80, in <listcomp>
acs: List[ArithmeticCircuit] = [self.cache.get(q) for q in batch]
File "/home/till/programs/deepproblog/src/deepproblog/utils/cache.py", line 52, in get
return self.first(item)
File "/home/till/programs/deepproblog/src/deepproblog/solver.py", line 67, in build_ac
ground = self.engine.ground(q, label=LogicFormula.LABEL_QUERY)
File "/home/till/programs/deepproblog/src/deepproblog/engines/approximate_engine.py", line 124, in ground
return self.engine.ground(
File "/home/till/programs/deepproblog/src/deepproblog/engines/prolog_engine/engine.py", line 59, in ground
proofs = self.get_proofs(term, sp)
File "/home/till/programs/deepproblog/src/deepproblog/engines/prolog_engine/engine.py", line 86, in get_proofs
res = program.query(query_str, profile=profile)
File "/home/till/programs/deepproblog/src/deepproblog/engines/prolog_engine/swi_program.py", line 321, in query
out_partial[k] = [p for p in term2list(parse(result[0][k]))]
File "/home/till/programs/deepproblog/src/deepproblog/engines/prolog_engine/swip.py", line 99, in parse
return pyswip_to_term(to_parse)
File "/home/till/programs/deepproblog/src/deepproblog/engines/prolog_engine/swip.py", line 50, in pyswip_to_term
e, vars2 = pyswip_to_term(o, True)
File "/home/till/programs/deepproblog/src/deepproblog/engines/prolog_engine/swip.py", line 62, in pyswip_to_term
raise Exception(
Exception: Unhandled type <class 'str'> from object -(10, -(addition(tensor(train(0)), tensor(train(1)), 5), and(["-(digit(tensor(train(0)), 2), ::(3, nn(mnist_net, ['tensor(train(0))'], 2), digit(tensor(train(0)), 2), ad(0, 2, ['tensor(train(0))'])))", "-(digit(tensor(train(1)), 3), ::(4, nn(mnist_net, ['tensor(train(1))'], 3), digit(tensor(train(1)), 3), ad(0, 3, ['tensor(train(1))'])))", '-(is(5, +(2, 3)), builtin)'])))
Aha, the hint for #2 solves the problem. And indeed this hint is there in the README... Still, it would be nice to have these two in README.md
pip3 install git+https://github.com/ML-KULeuven/pyswi
pip3 install git+https://github.com/wannesm/PySDD.git#egg=PySDD
and perhaps also something about swi-prolog form ppa.
I have updated the README with your suggestions, thanks!
Sorry @rmanhaeve,
I'm struggling with something similar, it seems that https://github.com/ML-KULeuven/pyswi(p) cannot be found. I added the brackets because I tried both with and without the "p".
I'm having the error at core.py in pyswip, and cannot import the SWI-Prolog library....
Any suggestion?
So this link doesn't work for you?
https://github.com/ML-KULeuven/pyswip
Ok now I can download it from your link, but it gives me the same problem.
ImportError: Could not find the SWI-Prolog library in this platform. If you are sure it is installed, please open an issue.
I thought a problem of the version of pyswip, but it seems something different
What version of swipl do you have installed?