Sage: Ticket #13028: mpmath import problem warning?
https://trac.sagemath.org/ticket/13028
<p>
A rather subtle bug just ate several hours of my (and Benjamin's) time, so for the sake of future sufferers, it's probably worth documenting and wondering if we can find a way to make sure this doesn't happen. The bug relates to trac <a class="closed ticket" href="https://trac.sagemath.org/ticket/12455" title="enhancement: Make Airy functions symbolic (closed: fixed)">#12455</a>, which introduces symbolic Airy functions and uses mpmath for numerical evaluation.
</p>
<p>
The manifestation is unusual: without the patch, we have
</p>
<pre class="wiki">sage: import mpmath
sage: from sage.libs.mpmath import utils as mpmath_utils
sage: mpmath_utils.call(mpmath.airyai, 3,4, prec=500)
0.0354943008052438353507905704856075851248207412675096681263890254113384424359941551501461978539207259766557679623911357156186928332753550261698746599899
</pre><p>
but with the patch (after moving an import to avoid a circularity), we have
</p>
<pre class="wiki">sage: import mpmath
sage: from sage.libs.mpmath import utils as mpmath_utils
sage: mpmath_utils.call(mpmath.airyai, 3,4, prec=500)
[...]
/Users/mcneil/sagedev/sage-5.1.beta0/local/lib/python2.7/site-packages/mpmath/libmp/libintmath.py in python_bitcount(n)
88 if bc != 300:
89 return bc
---> 90 bc = int(math.log(n, 2)) - 4
91 return bc + bctable[n>>bc]
92
OverflowError: cannot convert float infinity to integer
</pre><p>
even though we're not using any of the new functions, and it works fine for (say) prec=300 and lower!
</p>
<p>
This turns out to be because the patch created a new module <code>airy.py</code> in functions, and it was being imported in functions/all.py. mpmath determines its backend in libmp/backend.py by attempting to import sage.all, which fails (because it's not ready yet), and so mpmath decides it's not in Sage and uses the Python backend. This results in using math.log on a really big number, which leads to the <a class="missing wiki">OverflowError?</a>. It's quite unlikely that a beginner would ever guess this happens -- because it *works* whenever the precision is low enough, so many of the standard tests one might try would be passed.
</p>
<p>
Would there be a good place to insert a verification that our mpmath knows it's in Sage?
</p>
en-usSagehttps://trac.sagemath.org/chrome/site/logo_sagemath_trac.png
https://trac.sagemath.org/ticket/13028
Trac 1.1.6burcinThu, 20 Jun 2013 01:47:30 GMT
https://trac.sagemath.org/ticket/13028#comment:1
https://trac.sagemath.org/ticket/13028#comment:1
<p>
I can't reproduce this with the current patches in <a class="closed ticket" href="https://trac.sagemath.org/ticket/12455" title="enhancement: Make Airy functions symbolic (closed: fixed)">#12455</a>. Is there a different way to trigger the problem?
</p>
TicketeviatarbachSun, 14 Jul 2013 23:24:03 GMTcc set
https://trac.sagemath.org/ticket/13028#comment:2
https://trac.sagemath.org/ticket/13028#comment:2
<ul>
<li><strong>cc</strong>
<em>eviatarbach</em> added
</li>
</ul>
<p>
I got this bug with the patch in <a class="closed ticket" href="https://trac.sagemath.org/ticket/2516" title="enhancement: generalized hypergeometric functions should be implemented (closed: fixed)">#2516</a> with <code>hypergeometric((10, 10), (50,), 2.)</code>, where I say it was due to an mpmath limitation before seeing this ticket. It seems indeed to be a circular import problem; I moved the import <code>from mpmath import hyper</code> into a function rather than have it at the top and it works.
</p>
<p>
Is there at least a way to raise an error? It would be much preferable to the subtle failure currently encountered.
</p>
TicketjdemeyerTue, 13 Aug 2013 15:35:53 GMTmilestone changed
https://trac.sagemath.org/ticket/13028#comment:3
https://trac.sagemath.org/ticket/13028#comment:3
<ul>
<li><strong>milestone</strong>
changed from <em>sage-5.11</em> to <em>sage-5.12</em>
</li>
</ul>
Ticketvbraun_spamThu, 30 Jan 2014 21:20:52 GMTmilestone changed
https://trac.sagemath.org/ticket/13028#comment:4
https://trac.sagemath.org/ticket/13028#comment:4
<ul>
<li><strong>milestone</strong>
changed from <em>sage-6.1</em> to <em>sage-6.2</em>
</li>
</ul>
Ticketvbraun_spamTue, 06 May 2014 15:20:58 GMTmilestone changed
https://trac.sagemath.org/ticket/13028#comment:5
https://trac.sagemath.org/ticket/13028#comment:5
<ul>
<li><strong>milestone</strong>
changed from <em>sage-6.2</em> to <em>sage-6.3</em>
</li>
</ul>
Ticketvbraun_spamSun, 10 Aug 2014 16:51:03 GMTmilestone changed
https://trac.sagemath.org/ticket/13028#comment:6
https://trac.sagemath.org/ticket/13028#comment:6
<ul>
<li><strong>milestone</strong>
changed from <em>sage-6.3</em> to <em>sage-6.4</em>
</li>
</ul>
Ticket