Regression in Python 3.2 // testing mpmath

16 views
Skip to first unread message

Vladimir Perić

unread,
Jun 28, 2011, 6:41:20 AM6/28/11
to mpmath
Hi,

I'm one of the GSoC students working on SymPy; my project is to port
SymPy to Python 3. I've found a failure under Python 3.2, caused by
this bit of code in test_basic_ops:

if sys.version >= "3.2":
assert hash(mpf(1))*2**2000 == hash(2**2000)
assert hash(mpf(1))/2**2000 == hash(mpq(1,2**2000))

I assume the left-hand hash was supposed to hash the whole expression,
not just mpf(1). The code was introduced in r1220: Changes to support
the new hashing algorithm in Python 3.2. This is basically a trivial
error, just took me some time to pinpoint among all the other changes
in SymPy under py3. :) Aaron told me something similuar occured under
Python 2.5 with or without gmpy, not sure now. Have you considered
using Tox to help with your testing?


Setting up a way to test multiple Python versions was a part of my
project, and Tox is by far the easiest/best choice for this. You can
read my blog post on the topic if you want[0], but the short version
is that you need to put a tox.ini file in the same directory as
setup.py. For mpmath, you'll want to define it something like:

[tox]
envlist = py25, py26, py27, py31, py32

[testenv]
commands = python mpmath/tests/runtests.py -local []

and that's it! You'll want to run it with "tox" to test all the
versions listed; you can also define custom test environments to check
with/without gmpy and such, details are in my blog post. The mpmath
test suite is quite short (about a minute, compared to SymPy's 10) so
it shouldn't be a problem for this.

Well, I hope that helps! If you've got any problems, feel free to
contact me (mail, or on #sympy).

[0] http://vperic.blogspot.com/2011/06/setting-up-and-using-tox-in-sympy.html

Aaron Meurer

unread,
Jun 28, 2011, 6:16:15 PM6/28/11
to mpm...@googlegroups.com
On Tue, Jun 28, 2011 at 4:41 AM, Vladimir Perić <vlada...@gmail.com> wrote:
> Hi,
>
> I'm one of the GSoC students working on SymPy; my project is to port
> SymPy to Python 3. I've found a failure under Python 3.2, caused by
> this bit of code in test_basic_ops:
>
>    if sys.version >= "3.2":
>        assert hash(mpf(1))*2**2000 == hash(2**2000)
>        assert hash(mpf(1))/2**2000 == hash(mpq(1,2**2000))
>
> I assume the left-hand hash was supposed to hash the whole expression,
> not just mpf(1). The code was introduced in r1220: Changes to support
> the new hashing algorithm in Python 3.2. This is basically a trivial
> error, just took me some time to pinpoint among all the other changes
> in SymPy under py3. :) Aaron told me something similuar occured under
> Python 2.5 with or without gmpy, not sure now. Have you considered
> using Tox to help with your testing?

The problem was that mpmath 0.16 does not work in Python 2.4 if gmpy
is installed, because several places in the code use mpz's as list
indices, and __index__ was not implemented until Python 2.5. We
worked around it in the SymPy 0.7.0 release by disabling the gmpy
backend in mpmath under Python 2.4.

Aaron Meurer

>
>
> Setting up a way to test multiple Python versions was a part of my
> project, and Tox is by far the easiest/best choice for this. You can
> read my blog post on the topic if you want[0], but the short version
> is that you need to put a tox.ini file in the same directory as
> setup.py. For mpmath, you'll want to define it something like:
>
> [tox]
> envlist = py25, py26, py27, py31, py32
>
> [testenv]
> commands = python mpmath/tests/runtests.py -local []
>
> and that's it! You'll want to run it with "tox" to test all the
> versions listed; you can also define custom test environments to check
> with/without gmpy and such, details are in my blog post. The mpmath
> test suite is quite short (about a minute, compared to SymPy's 10) so
> it shouldn't be a problem for this.
>
> Well, I hope that helps! If you've got any problems, feel free to
> contact me (mail, or on #sympy).
>
> [0] http://vperic.blogspot.com/2011/06/setting-up-and-using-tox-in-sympy.html
>

> --
> You received this message because you are subscribed to the Google Groups "mpmath" group.
> To post to this group, send email to mpm...@googlegroups.com.
> To unsubscribe from this group, send email to mpmath+un...@googlegroups.com.
> For more options, visit this group at http://groups.google.com/group/mpmath?hl=en.
>
>

Fredrik Johansson

unread,
Jun 30, 2011, 10:01:14 AM6/30/11
to mpm...@googlegroups.com
On Tue, Jun 28, 2011 at 12:41 PM, Vladimir Perić <vlada...@gmail.com> wrote:
> Hi,
>
> I'm one of the GSoC students working on SymPy; my project is to port
> SymPy to Python 3. I've found a failure under Python 3.2, caused by
> this bit of code in test_basic_ops:
>
>    if sys.version >= "3.2":
>        assert hash(mpf(1))*2**2000 == hash(2**2000)
>        assert hash(mpf(1))/2**2000 == hash(mpq(1,2**2000))

Thanks, I've (hopefully) fixed this.

> I assume the left-hand hash was supposed to hash the whole expression,
> not just mpf(1). The code was introduced in r1220: Changes to support
> the new hashing algorithm in Python 3.2. This is basically a trivial
> error, just took me some time to pinpoint among all the other changes
> in SymPy under py3. :) Aaron told me something similuar occured under
> Python 2.5 with or without gmpy, not sure now. Have you considered
> using Tox to help with your testing?

So far I've just manually run the tests with each Python version
before release. I don't think I had 3.2 installed though.

Fredrik

Aaron Meurer

unread,
Jun 30, 2011, 6:47:13 PM6/30/11
to mpm...@googlegroups.com

No, I checked, and in all fairness, mpmath 0.17 was released before
Python 3.2.0-final.

Can you give a link to the revision that fixes this, so we can apply
it in SymPy's mpmath?

Aaron Meurer

Reply all
Reply to author
Forward
0 new messages