[ase-users] Opinion about potentially adding Cython as a dependency
Gaël Donval
G.Donval at bath.ac.uk
Tue Oct 10 16:32:18 CEST 2017
Dear Ask,
> Dear Gaël,
>
> 2017-10-10 12:52 GMT+02:00 Gaël Donval via ase-users
> <ase-users at listserv.fysik.dtu.dk>:
> > Dear list,
> >
> > I am currently working on some geometrical code that I will
> > ultimately
> > propose adding to ASE. I am currently using Cython to speed up what
> > needs speeding up and, to a more limited extent, I also use it to
> > very
> > conveniently generate bindings to C.
> >
> > The question is: would anyone see using Cython as a problem?
> >
> > I know that the fewer dependencies, the better. However Cython is
> > almost as ubiquitous as Scipy nowadays in Python's scientific
> > stack.
> >
> > The only real drawbacks I can think of (and I can read about on the
> > internet) are pain points on Windows and incompatibility with
> > different
> > Python implementations (e.g. PyPy). However, with pip wheels,
> > Windows
> > is a non problem (most Python distributions on Windows now also
> > include
> > Cython by default so manual compilation is far from the pain it
> > used to
> > be) and ASE/GPAW do not support PyPy anyway because of all the C
> > dependencies.
> >
> > Note that I am *not* proposing to convert any existing code to
> > Cython
> > nor to use Cython by default. I am talking about specific cases
> > which
> > would currently be handled by writing pure C code.
>
> There are already a few cases where performance becomes an issue, so
> this is worth thinking about. Can Cython be an optional dependency?
Yes it can and at two different levels:
1) *Provide fallback functions* Nothing would really prevent us from
providing two different versions of hot functions and degrade to
pure Python ones upon import if needed. However this would require
to keep function APIs in sync in two different places.
On the bright side, the slow and hopefully correct Python function
could be used as a reference in unit tests: these would rarely be
changed and most of the optimisation would occur in the Cython ones
instead.
2) *Provide C/C++ files* Ultimately, Cython generates a bunch of C
files containing Cython-defined code + everything needed to create a
native Python module. Directly using those C files (thus not
requiring Cython itself) is just a matter of tracking them in git!
:) That kind of optional Cython support can be reflected in setup.py
directly (look for USE_CYTHON ):
https://gist.github.com/ctokheim/6c34dc1d672afca0676a#setuppy-and-disutils
(note however that a C compiler is still needed).
Regards,
Gaël
>
> Best regards
> Ask
>
> >
> > Best regards,
> > Gaël
> >
> >
> > _______________________________________________
> > ase-users mailing list
> > ase-users at listserv.fysik.dtu.dk
> > https://listserv.fysik.dtu.dk/mailman/listinfo/ase-users
-------------- next part --------------
A non-text attachment was scrubbed...
Name: smime.p7s
Type: application/x-pkcs7-signature
Size: 3199 bytes
Desc: not available
URL: <http://listserv.fysik.dtu.dk/pipermail/ase-users/attachments/20171010/e118d84d/attachment.bin>
More information about the ase-users
mailing list