Python3

238 views
Skip to first unread message

William Stein

unread,
May 20, 2016, 2:05:01 PM5/20/16
to sage-devel
Hi,

Somebody with possibly substantial grant funds asked me today: "How
much might it cost to get Sage to work with Python3?"

I don't know. Anybody have any thoughts? Is there anybody reading
this who wishes they could spend several months getting Sage to fully
work with Python3 instead of teaching Calculus?

-- William

--
William (http://wstein.org)

Jeroen Demeyer

unread,
May 20, 2016, 4:05:33 PM5/20/16
to sage-...@googlegroups.com
On 2016-05-20 20:04, William Stein wrote:
> How much might it cost to get Sage to work with Python3?

That's very difficult to say... many of the easy parts have been done.
But we haven't really looked at the hard parts, comparison for example.

William Stein

unread,
May 20, 2016, 6:16:09 PM5/20/16
to sage-devel
The following is not related to why I asked this question (which
involves some data science curriculum development at Berkeley), but
there is a huge thread about the Sympy lead dev threatening today to
discontinue support for Python2 for Sympy:

https://news.ycombinator.com/item?id=11738470
> --
> You received this message because you are subscribed to the Google Groups
> "sage-devel" group.
> To unsubscribe from this group and stop receiving emails from it, send an
> email to sage-devel+...@googlegroups.com.
> To post to this group, send email to sage-...@googlegroups.com.
> Visit this group at https://groups.google.com/group/sage-devel.
> For more options, visit https://groups.google.com/d/optout.



--
William (http://wstein.org)

D. S. McNeil

unread,
May 20, 2016, 6:33:35 PM5/20/16
to sage-...@googlegroups.com
On the subject of 3, for anyone who hasn't been following, a number of teams on the science stack have thought about Aaron's argument and are making plans:



Doug

William Stein

unread,
May 20, 2016, 6:46:25 PM5/20/16
to sage-devel
Thanks. To anybody else that clicks there, the page looks completely
broken, but if you scroll down it works. It's basically some intro
and a sort of public statement by the following projects to completely
drop support for Python2 in 3.5 years as well:

IPython
Jupyter notebook
Matplotlib
scikit-bio
PyStan
An Introduction to Applied Bioinformatics
QIIME
cual-id


>
> Doug

Volker Braun

unread,
May 20, 2016, 7:11:12 PM5/20/16
to sage-devel
I think there are a couple of low-hanging fruits that we should clean up first. Right now Vincent is adding "from __future__ import print_function" everywhere, which is a great start. There are a couple of further __future__ imports that we should gradually roll out. The future library (http://python-future.org) has a bunch of further enhancements to let you write python3 code in a python2 interpreter. And #20625 adds the future library to Sage since it is now a dependency for flask_autoindex. Then we should gradually roll out the whole 

from __future__ import absolute_import, division, print_function
from builtins import (bytes, str, open, super, range,
                      zip, round, input, int, pow, object)

saad khalid

unread,
May 21, 2016, 2:07:23 AM5/21/16
to sage-devel
What exactly are the benefits of using Python3? I thought that it tended to be a bit slower for computation, since it uses infinite precision numbers instead of ints. Not that I'm against it, I just didn't know the motivation.

Frédéric Chapoton

unread,
May 21, 2016, 2:23:07 AM5/21/16
to sage-devel
Sorry, but I am not Vincent.

Jeroen Demeyer

unread,
May 21, 2016, 4:19:17 AM5/21/16
to sage-...@googlegroups.com
On 2016-05-21 01:11, Volker Braun wrote:
> I think there are a couple of low-hanging fruits that we should clean up
> first.

Yes, there is a huge amount of low-hanging fruit. But what scares me is
the high-hanging fruit.

Dima Pasechnik

unread,
May 21, 2016, 4:27:53 AM5/21/16
to sage-devel
Given the snail speed of twised is ported to Python 3, sagenb won't be ready in another year or more (assuming it's still relevant then).

Volker Braun

unread,
May 21, 2016, 5:42:56 AM5/21/16
to sage-devel
My apologies!  In my defense, it was really late last night ;-)

Volker Braun

unread,
May 21, 2016, 9:31:56 AM5/21/16
to sage-devel
There are some potential speed bumps, e.g. a minor change in how cyclic imports are treated could become a huge headache. But at this point I don't know of any real issue. Its probably more of a matter of deploying all the 2/3 testing tools that already exist and slowly bring every module forward. 

Another milestone is surely to run python2 with the -3 switch turned on. E.g. right now: 

$  echo 'from sage.all import *' | sage -python -3 |& grep Deprecation | cut -d : -f 3- | sort -u
 DeprecationWarning: Overriding __eq__ blocks inheritance of __hash__ in 3.x
 DeprecationWarning: the cmp argument is not supported in 3.x
 DeprecationWarning: type inequality comparisons not supported in 3.x

Volker Braun

unread,
May 21, 2016, 10:36:32 AM5/21/16
to sage-devel
Twisted should work under Python3 now. Some modules are missing but sagenb might not depend on the more obscure stuff...

Erik Bray

unread,
May 23, 2016, 9:29:09 AM5/23/16
to sage-...@googlegroups.com
On Fri, May 20, 2016 at 8:04 PM, William Stein <wst...@gmail.com> wrote:
> Hi,
>
> Somebody with possibly substantial grant funds asked me today: "How
> much might it cost to get Sage to work with Python3?"
>
> I don't know. Anybody have any thoughts? Is there anybody reading
> this who wishes they could spend several months getting Sage to fully
> work with Python3 instead of teaching Calculus?

Based on previous experience with porting large code-bases I'd wager
something around 4 person-months.

With any luck it could be less. So much of Sage is Cython-oriented it
would get a lot of Python 3 support "for free", but even Cython
modules would be best ported over to use Python 3-isms too. The other
good news is that so much of Sage is numerically oriented and not as
likely to have string-related issues in as many places. Some of the
trickier I/O related code is bound up in pexpect which already works
with Python 3.

So my bet is that the majority of effort will be slogging through the
test suite to make sure everything is passing. Doctests are
notoriously tricky to make fully Python 2/3 compatible. But many of
the issues can be addressed through custom doctest flags / output
checkers. I did some work like this to get all of Astropy's doctests
working across Python versions, but Astropy has orders of magnitude
fewer doctests than Sage (since it relies more on unit tests).

Erik
Reply all
Reply to author
Forward
0 new messages