ADOL-C icon indicating copy to clipboard operation
ADOL-C copied to clipboard

Support for python 3

Open bradbell opened this issue 4 years ago • 13 comments

I notice in you swig interface code https://github.com/coin-or/ADOL-C/blob/master/ADOL-C/swig/adolc-python.i at line number 442

adub* __rdiv__ (double a) {
    return (adub*) (a / (*($self)));
}

This no longer works in python3; see https://stackoverflow.com/questions/34344025/have-the-rdiv-and-idiv-operators-changed-in-python-3-x

bradbell avatar Apr 22 '20 12:04 bradbell

Hi. It would be best if you open a pull-request with a fix, so that we are compatible with both python2 and python3.

kkulshre avatar Apr 25 '20 20:04 kkulshre

Hi, is there any news on this topic? Is anybody planning to make it compatible with python3?

DiegoRomeres avatar Aug 07 '20 16:08 DiegoRomeres

As I wrote before, anyone who feels like it, please open a pull-request with the fix.

kkulshre avatar Aug 07 '20 16:08 kkulshre

cppad_py is an alternative that works with python3; see https://cppad-py.readthedocs.io/

bradbell avatar Oct 12 '23 14:10 bradbell

Hi there,

as Python 2 did reach end of life quite some time ago, I think it would be a good Idea to support Python 3 from now on forward. (Just to be clear, the current swig wrapper works with 3.11, you just can't do any division.)

I went ahead and made the required changes, however due to #42 I had to make some more changes to the build system that are possibly a little hackish. In my opinion, it would be best to resolve the problems with the buildsystem first. Afterwards I will gladly add a test case for the changes.

My changes can be found in 7b0078e704fbb7bf69c93e8d31b7f86c2862f3dc .

Best, Stefan

cklb avatar Nov 30 '23 15:11 cklb

Hi Stefan,

thanks a lot for your comment!!

We also found some issues with the build system. I will try to integrate them within the next two weeks. It would be great if you could provide a test case after that.

Best regards

Andrea

awalther1 avatar Dec 04 '23 08:12 awalther1

No problem, if you post it here I'll be notified.

FYI: My changes to the build system can be found in https://github.com/cklb/ADOL-C/tree/makepkg

cklb avatar Dec 06 '23 12:12 cklb

Hi Stefan,

I just tried to adapt the build system correspondingly. However, I was not completely successful. Could we discuss these issue to fix it? That would be great.

Best regards

Andrea

awalther1 avatar Jan 15 '24 15:01 awalther1

Hey,

a few weeks ago, a colleague of mine made some changes to get the build running again. I don't think that he is on Github by luckily he collected his changes (based on the 2.7.2 release) in form of a patch and provided a package for the archlinux user repository which you can find here: https://aur.archlinux.org/packages/python-adolc. The patch itself can be found here: https://aur.archlinux.org/cgit/aur.git/tree/setup.patch?h=python-adolc.

Best, Stefan

cklb avatar Jan 17 '24 14:01 cklb

Hey,

thanks a lot for the patch. It should be included now in the master branch. However, the installation does not work on my system. It would be great if you could give it a try to check whether it works on your system? That might help to identify the reason.

Thanks and best regards

Andrea

awalther1 avatar Jan 28 '24 14:01 awalther1

Hey,

it seems like one line of the patch did not get included on the master branch, it is the line 217 in ADOL-C/swig/setup.py:

-      version='2.7-trunk',
+      version='2.7.2',

without that change, the packaging module gives packaging.version.InvalidVersion: Invalid version: '2.7-trunk' .

However, after applying that line a myriad of similar compile errors arise from the wrapper class. One example:

adolc-python_wrap.cpp: In Funktion »adub* badouble___pow____SWIG_1(badouble*, double)«:
adolc-python_wrap.cpp:5353:16: Fehler: ungültige Umwandlung von Typ »adub« in Typ »adub*«
 5353 |         return (adub*) pow((*(self)),c);

I think the problem here is that the patch is based on the last available tagged version of ADOL-C (https://github.com/coin-or/ADOL-C/releases/tag/releases%2F2.7.2) and in the meantime changes were made to the C++ code that did not get ported to the swig wrapper, possibly because no one was using the python extension. However, as adolc-python_wrap.cpp is generated by swig itself, the culprit is probably the interface definition in adolc-python.i.

The build commands I used are

autoreconf -fi
./configure --enable-sparse --enable-python
make 
make install

Best, Stefan

cklb avatar Jan 30 '24 11:01 cklb

Hi,

oK, this is the same behaviour that I observe. I will try to trace down the reason for this and to fix the interface definition.

Best regards

Andrea

awalther1 avatar Jan 30 '24 13:01 awalther1

With python3.12 the numpy.distutils package is no longer available; see https://numpy.org/doc/stable/reference/distutils_guide.html

But it is used by adolc's python setup.py file; see

from numpy.distutils import misc_util as np_dist

in https://github.com/coin-or/ADOL-C/blob/master/ADOL-C/swig/setup.py

bradbell avatar Jul 24 '24 13:07 bradbell