[BUG] Unhandled type <class 'str'>
Closed this issue · 10 comments
To Reproduce
Steps to reproduce the behavior:
$ python addition.py
addition_method_gm_N_1_pretrain_0_exploration_False_run_0_210826_015053743282
Training for 1 epoch(s)
Epoch 1
Traceback (most recent call last):
File "/data/home/fchua/deepproblog/src/deepproblog/examples/MNIST/addition.py", line 66, in <module>
train = train_model(model, loader, 1, log_iter=100, profile=0)
File "/data/home/fchua/deepproblog/src/deepproblog/train.py", line 200, in train_model
train_object.train(loader, stop_condition, **kwargs)
File "/data/home/fchua/deepproblog/src/deepproblog/train.py", line 128, in train
loss = self.get_loss(batch, loss_function)
File "/data/home/fchua/deepproblog/src/deepproblog/train.py", line 39, in get_loss
result = self.model.solve(batch)
File "/data/home/fchua/deepproblog/src/deepproblog/model.py", line 106, in solve
return self.solver.solve(batch)
File "/data/home/fchua/deepproblog/src/deepproblog/solver.py", line 80, in solve
acs: List[ArithmeticCircuit] = [self.cache.get(q) for q in batch]
File "/data/home/fchua/deepproblog/src/deepproblog/solver.py", line 80, in <listcomp>
acs: List[ArithmeticCircuit] = [self.cache.get(q) for q in batch]
File "/data/home/fchua/deepproblog/src/deepproblog/utils/cache.py", line 52, in get
return self.first(item)
File "/data/home/fchua/deepproblog/src/deepproblog/solver.py", line 67, in build_ac
ground = self.engine.ground(q, label=LogicFormula.LABEL_QUERY)
File "/data/home/fchua/deepproblog/src/deepproblog/engines/approximate_engine.py", line 124, in ground
return self.engine.ground(
File "/data/home/fchua/deepproblog/src/deepproblog/engines/prolog_engine/engine.py", line 59, in ground
proofs = self.get_proofs(term, sp)
File "/data/home/fchua/deepproblog/src/deepproblog/engines/prolog_engine/engine.py", line 88, in get_proofs
res = program.query(query_str, profile=profile)
File "/data/home/fchua/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 "/data/home/fchua/deepproblog/src/deepproblog/engines/prolog_engine/swip.py", line 99, in parse
return pyswip_to_term(to_parse)
File "/data/home/fchua/deepproblog/src/deepproblog/engines/prolog_engine/swip.py", line 50, in pyswip_to_term
e, vars2 = pyswip_to_term(o, True)
File "/data/home/fchua/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)'])))
Desktop (please complete the following information):
- OS: Linux Ubuntu 18.04
- Python Version: 3.9
Additional context
pyswip is installed from master branch, otherwise pyswip has a bug in the last release.
Hi
Try using our PySwip fork, available here: https://github.com/ML-KULeuven/pyswip
Let me know if this resolves your issue.
Kind regards,
Robin
Works after re-installing PySDD.
Just in case someone else ends up doing my mistake of running pacman -S python-pyswip
instead of pip install git+https://github.com/ML-KLUeuven/pyswip.git#egg=PySwip
, you will get the same error.
Hence, the pointer given above by Robin is the resolution to this issue. Not sure it has anything to do with PySDD
.
I have the same problem as freddycct and could not solve it by installing this PySwip fork (https://github.com/ML-KULeuven/pyswip), or re-installing PySDD.
I am using Pop!_OS 20.04 and a this virtual environment:
# packages in environment at /home/david/anaconda3/envs/dplg2:
#
# Name Version Build Channel
_libgcc_mutex 0.1 main
_openmp_mutex 4.5 1_gnu
blas 1.0 mkl
bzip2 1.0.8 h7b6447c_0
ca-certificates 2021.10.26 h06a4308_2
certifi 2021.10.8 py39h06a4308_2
cudatoolkit 10.2.89 hfd86e86_1
cysignals 1.11.2 pypi_0 pypi
cython 0.29.28 pypi_0 pypi
deepproblog 2.0.0 pypi_0 pypi
ffmpeg 4.3 hf484d3e_0 pytorch
freetype 2.11.0 h70c0345_0
giflib 5.2.1 h7b6447c_0
gmp 6.2.1 h2531618_2
gnutls 3.6.15 he1e5248_0
intel-openmp 2021.4.0 h06a4308_3561
jpeg 9d h7f8727e_0
lame 3.100 h7b6447c_0
lcms2 2.12 h3be6417_0
ld_impl_linux-64 2.35.1 h7274673_9
libffi 3.3 he6710b0_2
libgcc-ng 9.3.0 h5101ec6_17
libgomp 9.3.0 h5101ec6_17
libiconv 1.15 h63c8f33_5
libidn2 2.3.2 h7f8727e_0
libpng 1.6.37 hbc83047_0
libstdcxx-ng 9.3.0 hd4cf53a_17
libtasn1 4.16.0 h27cfd23_0
libtiff 4.2.0 h85742a9_0
libunistring 0.9.10 h27cfd23_0
libuuid 1.0.3 h7f8727e_2
libuv 1.40.0 h7b6447c_0
libwebp 1.2.2 h55f646e_0
libwebp-base 1.2.2 h7f8727e_0
lz4-c 1.9.3 h295c915_1
mkl 2021.4.0 h06a4308_640
mkl-service 2.4.0 py39h7f8727e_0
mkl_fft 1.3.1 py39hd3c417c_0
mkl_random 1.2.2 py39h51133e4_0
ncurses 6.3 h7f8727e_2
nettle 3.7.3 hbbd107a_1
numpy 1.21.2 py39h20f2e39_0
numpy-base 1.21.2 py39h79a1101_0
olefile 0.46 pyhd3eb1b0_0
openh264 2.1.1 h4ff587b_0
openssl 1.1.1m h7f8727e_0
pillow 8.4.0 py39h5aabda8_0
pip 21.2.4 py39h06a4308_0
problog 2.2.2 pypi_0 pypi
pysdd 0.2.10 pypi_0 pypi
pyswip 0.2.11 pypi_0 pypi
python 3.9.7 h12debd9_1
pytorch 1.10.2 py3.9_cuda10.2_cudnn7.6.5_0 pytorch
pytorch-mutex 1.0 cuda pytorch
readline 8.1.2 h7f8727e_1
setuptools 58.0.4 py39h06a4308_0
six 1.16.0 pyhd3eb1b0_1
sqlite 3.37.2 hc218d9a_0
tk 8.6.11 h1ccaba5_0
torchaudio 0.10.2 py39_cu102 pytorch
torchvision 0.11.3 py39_cu102 pytorch
typing_extensions 3.10.0.2 pyh06a4308_0
tzdata 2021e hda174b7_0
wheel 0.37.1 pyhd3eb1b0_0
xz 5.2.5 h7b6447c_0
zlib 1.2.11 h7f8727e_4
zstd 1.4.9 haebb681_0
This is the error message:
addition_method_gm_N_1_pretrain_0_exploration_False_run_0_220224_220424427817
Training for 1 epoch(s)
Epoch 1
Traceback (most recent call last):
File "/home/david/ProjektXAI/deepproblog/src/deepproblog/examples/MNIST/addition.py", line 66, in <module>
train = train_model(model, loader, 1, log_iter=100, profile=0)
File "/home/david/anaconda3/envs/dplg2/lib/python3.9/site-packages/deepproblog/train.py", line 200, in train_model
train_object.train(loader, stop_condition, **kwargs)
File "/home/david/anaconda3/envs/dplg2/lib/python3.9/site-packages/deepproblog/train.py", line 128, in train
loss = self.get_loss(batch, loss_function)
File "/home/david/anaconda3/envs/dplg2/lib/python3.9/site-packages/deepproblog/train.py", line 39, in get_loss
result = self.model.solve(batch)
File "/home/david/anaconda3/envs/dplg2/lib/python3.9/site-packages/deepproblog/model.py", line 106, in solve
return self.solver.solve(batch)
File "/home/david/anaconda3/envs/dplg2/lib/python3.9/site-packages/deepproblog/solver.py", line 80, in solve
acs: List[ArithmeticCircuit] = [self.cache.get(q) for q in batch]
File "/home/david/anaconda3/envs/dplg2/lib/python3.9/site-packages/deepproblog/solver.py", line 80, in <listcomp>
acs: List[ArithmeticCircuit] = [self.cache.get(q) for q in batch]
File "/home/david/anaconda3/envs/dplg2/lib/python3.9/site-packages/deepproblog/utils/cache.py", line 52, in get
return self.first(item)
File "/home/david/anaconda3/envs/dplg2/lib/python3.9/site-packages/deepproblog/solver.py", line 67, in build_ac
ground = self.engine.ground(q, label=LogicFormula.LABEL_QUERY)
File "/home/david/anaconda3/envs/dplg2/lib/python3.9/site-packages/deepproblog/engines/approximate_engine.py", line 124, in ground
return self.engine.ground(
File "/home/david/anaconda3/envs/dplg2/lib/python3.9/site-packages/deepproblog/engines/prolog_engine/engine.py", line 59, in ground
proofs = self.get_proofs(term, sp)
File "/home/david/anaconda3/envs/dplg2/lib/python3.9/site-packages/deepproblog/engines/prolog_engine/engine.py", line 88, in get_proofs
res = program.query(query_str, profile=profile)
File "/home/david/anaconda3/envs/dplg2/lib/python3.9/site-packages/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/david/anaconda3/envs/dplg2/lib/python3.9/site-packages/deepproblog/engines/prolog_engine/swip.py", line 99, in parse
return pyswip_to_term(to_parse)
File "/home/david/anaconda3/envs/dplg2/lib/python3.9/site-packages/deepproblog/engines/prolog_engine/swip.py", line 50, in pyswip_to_term
e, vars2 = pyswip_to_term(o, True)
File "/home/david/anaconda3/envs/dplg2/lib/python3.9/site-packages/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)'])))
What version of SWIPL are you using?
I am using SWIPL version 8.4.2
Are you sure its using our forked version of PySwip? The list still specifies pypi as the channel.
I experience the same issue as @dtafler . Re-installing PySDD does not seem to work and I am sure that the forked version of PySwip is being used. I have tried with SWIPL version 8.4.0 and 8.4.2 on both Windows and Ubuntu 20.04.
I have discovered that running addition_noisy.py seems to work and that no error is given when running addition.py if the 'gm' method is removed from the parameters variable.
This error will not happen with you use the ExactEngine (e.g. when removig the 'gm' method). The problem is happening somewhere in the interface between the Python and SWIPL. I'm not immediately able to reproduce the error, as the code has not change at all in the meantime. I'll look into it more when I have the time.
For people still struggling with this issue, how did you install the forked version? The command on that was shown on the readme was not correct. The correct way to install it is to download the source code and do a pip install .