Best/easiest way to downgrade to version 8.4.3, on Linux Ubuntu 20.04

Yesterday, the new stable PPA version (9.0.0) was released. That’s great, but this breaks Popper (GitHub - logic-and-learning-lab/Popper: Popper is an inductive logic programming (ILP) system.) which relies on the Python pyswip package to bridge between Python and SWI Prolog (GitHub - yuce/pyswip: PySwip is a Python - SWI-Prolog bridge enabling to query SWI-Prolog in your Python programs. It features an (incomplete) SWI-Prolog foreign language interface, a utility class that makes it easy querying with Prolog and also a Pythonic interface.).

The pyswip package worked with the previous stable version of SWI Prolog (8.4.3), so I wonder if there’s a quick fix of downgrading to this SWI Prolog version.

(I’ve also filed an issue on the Popper repo on this, Problem with SWI Prolog's new stable PPA version 9.0.0 (Linux Ubuntu) · Issue #55 · logic-and-learning-lab/Popper · GitHub . It does not help to downgrade to another pyswip version.)

If you are using the Ubuntu package manager for this you should probably search their docs for downgrading. I don’t know for certain but most package managers have some process to do exactly that. Maybe you have the previous package downloaded and need to downgrade? or maybe you need to install a specific version?

There is some discussion on how to install older PPA versions at apt - Getting older packages from ppa - Ask Ubuntu

If I recall correctly, the problem with pyswip is that it hard-codes the C types and constants from SWI-Prolog.h in the Python code. But, running git diff -b V8.4.3 SWI-Prolog.h says nothing changed between 8.4.3 and 9.0.0, only some new stuff was added. So I wonder why pyswip is broken? Is it looking for libswipl.so.8?

Thanks for the suggestion. However, Ubuntu’s own repo has a much older SWI Prolog version (v7.6.4) which does not work with pyswip.

The PPA archive contains all versions. See https://launchpad.net/~swi-prolog/+archive/ubuntu/stable/+builds?build_state=built. The previous link I gave says how to install a particular version. If this fails you can simply download the .deb and use dpkg -i file.deb.

1 Like

What I can see, pyswip (in core.py) is looking for ‘libswipl.so’ and ‘libpl.so’, so the specific SWI Prolog version is not hard coded.

Regarding downgrading via PPA, do you know exactly what version name to use when specifying the version via apt-get? The syntax is apt-get install pkg=version but I don’t know the exact version name to use.

I was trying sudo apt install swi-prolog=swi-prolog_8.4.2 but it was not found.

Thanks, Jan.

It worked using the packages from amd64 build of swi-prolog 8.4.3-1-g10c53c6e3-focalppa2 : SWI-Prolog stable : “SWI Prolog” team (the focal distribution since I’m on Ubuntu 20.04).

Note for self (and perhaps some other): The packages must be installed in this order:

sudo dpkg -i swi-prolog-nox_8.4.3-1-g10c53c6e3-focalppa2_amd64.deb
sudo dpkg -i swi-prolog-x_8.4.3-1-g10c53c6e3-focalppa2_amd64.deb
sudo dpkg -i swi-prolog_8.4.3-1-g10c53c6e3-focalppa2_amd64.deb
1 Like

I’m wondering what is wrong. The Prolog interface seems to load fine into Python using SWI-Prolog 9.0.0.

I did look at how pyswip loads libswipl. That can be improved. Following similar issues with sweep, there is now a flag libswipl that points at the shared object used by swipl (if any). I improved that a bit such that it is now fully reliable on Windows, MacOS and Linux (and other POSIX systems providing dladdr()) and make it available through swipl --dump-runtime-variables. I’ll make a PR on pyswip to use that as first choice.

But again, this does not seem to be the problem. That is to be expected as the installation locations have not changed and the interface should be fully binary compatible between 8.4.x and 9.0.x

1 Like

Thanks for looking into this, Jan.

The source of the problem seems be the one mentioned in pyswip PR 133 (Support SWI-Prolog versions > 8.5.2 by david-r-cox · Pull Request #133 · yuce/pyswip · GitHub), i.e. that pyswip tries to first check SWI Prolog’s PL_version instead of PL_version_info-

I did the following in my pyswip source:

diff --git a/pyswip/core.py b/pyswip/core.py
index 33f7035..0bb992f 100644
--- a/pyswip/core.py
+++ b/pyswip/core.py
@@ -584,7 +584,7 @@ PL_VERSION_VM               =6      # VM signature
 PL_VERSION_BUILT_IN    =7      # Built-in predicate signature
 
 try:
-    PL_version = _lib.PL_version
+    PL_version = _lib.PL_version_info
     PL_version.argtypes = [c_int]
     PL_version.restype = c_uint

and installed this version (after pip uninstall pyswip to remove all previous installations).

Now pyswip works with SWI Prolog version 9.0.0 (PPA stable version)! That’s great.

(The proper fix would probably be to check for some older version of SWI Prolog.)

3 Likes

Thanks. Created a PR Comparing yuce:master...JanWielemaker:find-libswipl · yuce/pyswip · GitHub that uses a new mechanism to find libswipl, falling back to trying the whole platform specific heuristics used in pyswip.

2 Likes

That’s great, Jan.

Let’s hope that the pyswip gang applies your fix soon.

1 Like

Thanks @hakank, @Boris & @jan !

I found that the community-maintained (universe) package sources needs to be enabled before instaling the package requirements to downgrade to the previous stable version of SWI Prolog (8.4.3) in Ubuntu 20.04 based docker images:

add-apt-repository "deb http://archive.ubuntu.com/ubuntu focal main universe restricted multiverse"
apt-get install -y libarchive13 libossp-uuid16 libgmp-dev libedit-dev libreadline-dev libncursesw5-dev libjs-jquery
dpkg -i swi-prolog-nox_8.4.3-1-g10c53c6e3-focalppa2_amd64.deb

Does anyone know a cleaner way to downgrade until the PySwip fix get applied?

Patching pyswip might be easier than downgrading. Just replace PL_version in core.py by PL_version_info and all is fine.

 Cheers --- Jan
1 Like

Might sound like a silly question but is there a macOS equivalent of downgradingSWI Prolog?

Depends how you installed it (download binary, Macports, Homebrew, built from source …) For the binary from the download page, download an older version and install it. Use the show all files at the bottom-right of the table to see all versions.

Of course, the question is “why?”. 9.x should be pretty compatible. So far only the pyswip issue came up, but that is fixed with a very simple edit in the pyswip package.

I think the challenge might be making that simple edit in the pyswip package available in our production continuous delivery pipelines. They are built around the Python Package Index at pypi.org and Personal Package Archives for Ubuntu at launchpad.net and companies feel confident integrating software from well-known sources.

I can imagine an ideal world where changes, including new versions in utilities like SWI-Prolog, trigger automated tests in dependency-using tools like PySwip so that the communities that support those tools can react faster to integration issues, merge the changes and release them through well known distribution channels.

I installed it through Homebrew. The problem I am faced with is that after reinstalling pyswip with your PR: #145 included, I am stilling getting the same error messages before the PR and after updating to 9.x. They are shown below:

File “/Users/amrsoliman/Documents/GitHub/mila/utils_modified.py”, line 15, in learn
prolog.consult(file_name)
File “/Users/amrsoliman/miniforge3/envs/M1/lib/python3.9/site-packages/pyswip/prolog.py”, line 168, in consult
next(cls.query(filename.join([“consult('”, “')”]), catcherrors=catcherrors))
File “/Users/amrsoliman/miniforge3/envs/M1/lib/python3.9/site-packages/pyswip/prolog.py”, line 128, in call
raise PrologError(“”.join([“Caused by: '”, query, "'. ",
pyswip.prolog.PrologError: Caused by: ‘consult(‘train.pl’)’. Returned: ‘error(instantiation_error, context(:(system, /(atom_chars, 2)), _3208))’.

I’m not sure how to fix it…

If I do pip install pyswip -U I still see the old version. My patch is actually irrelevant, it merely makes finding the shared object more robust for future versions. The one that really matters is Support SWI-Prolog versions > 8.5.2 by david-r-cox · Pull Request #133 · yuce/pyswip · GitHub

And the simple quick fix is to find core.py in the package and replace PL_version with PL_version_info.

These may be unrelated to your problem though. It seems you can create an instance of Prolog. Without some context on what is supposed to happen I can’t comment on these errors (and anyway, my Python knowledge is not much).

It finally works! Here is how:

For some reason downloading SWI-Prolog 8.4.3 from the website is causing me another slew of errors. Therefore I went back to SWI-Prolog 9.x via homebrew.

By implementing D.Cox’s PR #133, I get the “Exception: swi-prolog version number could not be determined”.

Then I implemented @hakank 's suggestion by amending Cox’s “PL_version = _lib.PL_version” to “PL_version = _lib.PL_version_info”

Viola! Thankfully, it works! In case anyone is curious, I have been using Aleph.

2 Likes

Hi Jan!

Do you know why the package swi-prolog-nox_8.4.3-1-g10c53c6e3-focalppa2_amd64.deb is not longer available in the usual URL ? Do you know an alternative way to get this package?

Thanks and regards!