Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support for python 3 #25

Open
bradbell opened this issue Apr 22, 2020 · 13 comments
Open

Support for python 3 #25

bradbell opened this issue Apr 22, 2020 · 13 comments

Comments

@bradbell
Copy link

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

@kkulshre
Copy link
Contributor

kkulshre commented Apr 25, 2020

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

@DiegoRomeres
Copy link

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

@kkulshre
Copy link
Contributor

kkulshre commented Aug 7, 2020

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

@bradbell bradbell changed the title adolc-python.i uses __rdiv__ Support for python 3 Oct 12, 2023
@bradbell
Copy link
Author

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

@cklb
Copy link

cklb commented Nov 30, 2023

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 7b0078e .

Best,
Stefan

@awalther1
Copy link
Contributor

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

@cklb
Copy link

cklb commented Dec 6, 2023

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

@awalther1
Copy link
Contributor

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

@cklb
Copy link

cklb commented Jan 17, 2024

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

@awalther1
Copy link
Contributor

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

@cklb
Copy link

cklb commented Jan 30, 2024

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

@awalther1
Copy link
Contributor

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

@bradbell
Copy link
Author

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

5 participants