I am having error with janus

I’m using: SWI- Prolog version 9.3.0

I want the code to: run popper github: logic-and-learning-lab/Popper

I am having issue to run a code dependent on janus swi.

My installed version of janus is janus-swi-1.5.2.

It works fine when called separately from python

from janus_swi import query_once
print(query_once("member(X, [a,b,c])"))

{‘truth’: True, ‘X’: ‘a’}

But when I run with popper for the current version I see the error

ERROR: source_sink `library(janus)’ does not exist
Traceback (most recent call last):
File “/work/rp/HP/test_avi_prolog.py”, line 18, in
from heur.heur_utils import get_popper_examples, aggregate_all_solutions
File “/work/rp/HP/heur/heur_utils.py”, line 4, in
from popper.loop import learn_solution
File “/work/rp/HP/popper/popper/loop.py”, line 7, in
from . tester import Tester
File “/work/rp/HP/popper/popper/tester.py”, line 4, in
from janus_swi import query_once, consult
File “/work/rp/envs/rm_c117_py310_hp/lib/python3.10/site-packages/janus_swi/init.py”, line 23, in
_swipl.initialize(“swipl”,
janus_swi.janus.PrologError: Failed to load library(janus) into Prolog

This is my error from prolog environment

swipl
Welcome to SWI-Prolog (threaded, 64 bits, version 9.3.0)
SWI-Prolog comes with ABSOLUTELY NO WARRANTY. This is free software.
Please run ?- license. for legal details.

For online help and background, visit https://www.swi-prolog.org
For built-in help, use ?- help(Topic). or ?- apropos(Word).

1 ?- py_version.

ERROR: Unknown procedure: py_version/ 0 (DWIM could not correct goal)

2 ?- asserta(user:library_directory('/home/rp/swipl-9.3.0/packages/swipy'))
|    .

true.

3 ?- use_module(library(janus)).

ERROR: source_sink `library(janus)’ does not exist
ERROR: In:
ERROR: [23] throw(error(existence_error(source_sink,…),_192))
ERROR: [18] ‘$resolve_source_path’(library(janus),_224,[if(not_loaded),…]) at /home/rp/.local/swi-prolog/lib/swipl/boot/init.pl:2503
ERROR: [17] ‘$load_file_e’(library(janus),user,[if(not_loaded),…]) at /home/rp/.local/swi-prolog/lib/swipl/boot/init.pl:2472
ERROR: [16] ‘$load_file’(library(janus),user,[if(not_loaded),…]) at /home/rp/.local/swi-prolog/lib/swipl/boot/init.pl:2439
ERROR: [11] toplevel_call(user:user: …) at /home/rp/.local/swi-prolog/lib/swipl/boot/toplevel.pl:1317
ERROR:
ERROR: Note: some frames are missing due to last-call optimization.
ERROR: Re-run your program in debug mode (:- debug.) to get more detail.

1 ?- debug.
true.

[debug] 2 ?- use_module(library(janus)).
ERROR: source_sink `library(janus)’ does not exist
ERROR: In:
ERROR: [23] throw(error(existence_error(source_sink,…),_328))
ERROR: [22] ‘$existence_error’(source_sink,library(janus)) at /home/rp/.local/swi-prolog/lib/swipl/boot/init.pl:4063
ERROR: [21] ‘$abs_file_error’(library(janus),,_400{access:read,file_type:prolog}) at /home/rp/.local/swi-prolog/lib/swipl/boot/init.pl:1325
ERROR: [20] ‘$absolute_file_name’(library(janus),_434,[file_type(prolog),…]) at /home/rp/.local/swi-prolog/lib/swipl/boot/init.pl:1311
ERROR: [19] absolute_file_name(library(janus),_482,[file_type(prolog),…]) at /home/rp/.local/swi-prolog/lib/swipl/boot/init.pl:1257
ERROR: [18] ‘$resolve_source_path’(library(janus),_530,[if(not_loaded),…]) at /home/rp/.local/swi-prolog/lib/swipl/boot/init.pl:2503
ERROR: [17] ‘$load_file_e’(library(janus),user,[if(not_loaded),…]) at /home/rp/.local/swi-prolog/lib/swipl/boot/init.pl:2472
ERROR: [16] ‘$load_file’(library(janus),user,[if(not_loaded),…]) at /home/rp/.local/swi-prolog/lib/swipl/boot/init.pl:2439
ERROR: [15] ‘$load_one_file’(library(janus),user,[if(not_loaded),…]) at /home/rp/.local/swi-prolog/lib/swipl/boot/init.pl:2277
ERROR: [14] ‘$load_files’(library(janus),user,[if(not_loaded),…]) at /home/rp/.local/swi-prolog/lib/swipl/boot/init.pl:2254
ERROR: [13] load_files(user:library(janus),[if(not_loaded),…]) at /home/rp/.local/swi-prolog/lib/swipl/boot/init.pl:2234
ERROR: [12] use_module(user:library(janus)) at /home/rp/.local/swi-prolog/lib/swipl/boot/init.pl:2172
ERROR: [11] toplevel_call(user:user: …) at /home/rp/.local/swi-prolog/lib/swipl/boot/toplevel.pl:1317

I also tried with earlier version of janus as suggested https:// github. com/SWI-Prolog/packages-swipy/tree/master

If you installed SWI-Prolog from source, it is advised to install Janus from the packages/swipy directory in the Prolog source. The package can be installed from within this directory using

So, I from my swipl-9.3.0/packages/swipy/janus I also tried

pip install .

which gives me error

python -c “import janus_swi; print(janus_swi.file)”
ERROR: source_sink `library(janus)’ does not exist
Traceback (most recent call last):
File “”, line 1, in
File “/home/rp/swipl-9.3.0/packages/swipy/janus/init.py”, line 18, in
_swipl.initialize(“swipl”,
janus.PrologError: Failed to load library(janus) into Prolog

which is not seen in current version with code

python -c “import janus_swi; print(janus_swi.file)”
/work/rp/envs/rm_c117_py310_hp/lib/python3.10/site-packages/janus_swi/init.py

The issue here seems to be similar to issue discussed in “#14 (comment)”. Here it is mentioned the issue is fixed but I am not sure why it is still occurring. Would really be grateful if you could help me navigate through the error. I wanted to use janus integrated in popper.

The os I am currenlty using is

NAME=“CentOS Linux”
VERSION=“7 (Core)”
ID=“centos”
ID_LIKE=“rhel fedora”
VERSION_ID=“7”
PRETTY_NAME=“CentOS Linux 7 (Core)”
ANSI_COLOR=“0;31”
CPE_NAME=“cpe:/o:centos:centos:7”

CENTOS_MANTISBT_PROJECT=“CentOS-7”
CENTOS_MANTISBT_PROJECT_VERSION=“7”
REDHAT_SUPPORT_PRODUCT=“centos”
REDHAT_SUPPORT_PRODUCT_VERSION=“7”

My python version is 3.10.13
My swi prolog version is 9.3.0

It seem to be running fine with my mac environment. The only difference in my environment and this is local environment runs on cpu and this on gpu.

I also tried Janus and Conda to see if it would help me with the issue. But I got

?- py_version.

ERROR: Unknown procedure: py_version/0 (DWIM could not correct goal)

It would be really helpful I could get insights on the issue.

Have you tried installing SWIPL from the sources at GitHub - SWI-Prolog/swipl-devel: SWI-Prolog Main development repository ?
Using the instructions at swipl-devel/CMAKE.md at ff1c2009545e0ec1cf21a0c83d54ddb0e3e4192c · SWI-Prolog/swipl-devel · GitHub
and in particolar swipl-devel/CMAKE.md at ff1c2009545e0ec1cf21a0c83d54ddb0e3e4192c · SWI-Prolog/swipl-devel · GitHub I was able to run Janus. See also Janus and Conda

1 Like

Just to be clear the Python Janus package and the Prolog Janus library are distinct systems. Once installed and loaded they do the same thing and only differ in whether you load Prolog into Python or Python into Prolog. The Prolog library is part of the Prolog installation. Not all binary installers will provide it, but you didn’t tell us how you installed Prolog or on what platform.

@friguzzi @jan Thank you so much for you guidance. I previously had swi_prolog_9.3.0 build by compiling swipl-devel as you have mentioned in the comment @friguzzi. Then I tried few options like installing janus using standard

pip install janus-swi

. But this did not seem to be working. Then I also tried installing inside swipl prolog directory packagaes/wipy folder using

pip install .

which also failed. Then I also tried installing using

pip install git+https://github.com/SWI-Prolog/packages-swipy.git#egg=janus_swi.

This also failed. But lastly I again downloaded different version swipl_prolog_9.3.3, compiled it and installed janus inside its package folder and then

janus-swi version 1.1.4

was installed. Then once I added it to my

export SWI_HOME_DIR=$HOME/swi-prolog-9.3.3-janus/lib/swipl.

It seems to be working. Thank you so much for you help.

Note: There might be other changes between this versions but main change was in init.py in janus with added

swipl.call(“(exists_source(library(janus))->true;asserta(user:file_search_path(library, Here)))”,
{“Here”:os.path.dirname(file)})

which seemed to have helped.

If you install from source anyway, why not install the latest version (9.3.22)? Quite a few Janus related things have been fixed and improved.

Just to confirm it would install janus-swi version 1.5.2 ? Because with pip install it installed 1.5.2 and It was giving me error to get started with so I tried to skip it.

The current bundled source for Janus is at 1.5.2. There is only a patch to the docs since. If you install Prolog from source and the Python library can by found by CMake, you get a Prolog system that can call Python. On most systems, a subsequent pip install . in packages/swipy should allow loading Prolog into Python.

If things go wrong, please include the error message. If there are a lot (quite common), the first couple typically suffice.