Ticket #6196 (closed enhancement: fixed)

Opened 15 months ago

Last modified 14 months ago

[with patch, positive review] mpmath support

Reported by: fredrik.johansson Owned by: mhansen
Priority: major Milestone: sage-4.1
Component: packages Keywords:
Cc: Author(s): Fredrik Johannson, Mike Hansen
Report Upstream: Reviewer(s): Nick Alexander
Merged in: sage-4.1.rc0 Work issues:

Description (last modified by fredrik.johansson) (diff)

Patch description:

Adds sage.libs.mpmath which provides wrapper functions and monkey patches some internal mpmath functions for speed. Mpmath functions can be called from Sage as follows (with forward and backward conversions handled automatically):

sage: import sage.libs.mpmath.all as a
sage: a.call(a.hyp2f1, 2, 2/3, -1/2, 3+4*I)
-0.111907858412569 - 0.536467867510390*I
sage: a.call(a.hyp2f1, 2, 2/3, -1/2, 3+4*I, prec=100)
-0.11190785841256900204178259859 - 0.53646786751038954277574814099*I

Some partial support for direct conversion from Sage -> mpmath is also implemented (this is not completely working yet).

Also providing a preliminary spkg (with current mpmath trunk) in this issue.

Attachments

mpmath.patch Download (15.5 KB) - added by fredrik.johansson 15 months ago.
trac_6196-review.patch Download (6.5 KB) - added by mhansen 15 months ago.
trac_6196-ncalexan.patch Download (2.1 KB) - added by ncalexan 15 months ago.

Change History

Changed 15 months ago by fredrik.johansson

Changed 15 months ago by fredrik.johansson

  • description modified (diff)

Changed 15 months ago by was

  • summary changed from mpmath support to [with patch; needs review] mpmath support

Changed 15 months ago by ncalexan

  • reviewer set to Nick Alexander
  • summary changed from [with patch; needs review] mpmath support to [with patch; needs work] mpmath support
  • author set to Fredrik Johannson

I am interested in using mpmath for numerical integration, but unfortunately I get major build errors with 4.0.2.alpha0. See  http://pastebin.com/d13f03d03 for details. Any thoughts?

Changed 15 months ago by mhansen

Changed 15 months ago by mhansen

  • owner changed from mabshoff to mhansen
  • status changed from new to assigned
  • summary changed from [with patch; needs work] mpmath support to [with patch; needs review] mpmath support

Changed 15 months ago by ncalexan

  • author changed from Fredrik Johannson to Fredrik Johannson, Mike Hansen

Apply all patches.

Changed 15 months ago by ncalexan

Positive review for me. Change status after my tiny patch is refereed.

Changed 15 months ago by ncalexan

Changed 15 months ago by mhansen

  • summary changed from [with patch; needs review] mpmath support to [with patch; positive review] mpmath support

Nick's changes look good.

Changed 14 months ago by boothby

  • summary changed from [with patch; positive review] mpmath support to [with patch; needs work] mpmath support

Doctest failures:

sage -t -long devel/sage/sage/rings/real_mpfr.pyx
**********************************************************************
File "/space/boothby/sage-4.0.3/devel/sage-main/sage/rings/real_mpfr.pyx", line 2284:
    sage: RR(-1.5)._mpmath_()
Exception raised:
    Traceback (most recent call last):
      File "/space/boothby/sage-4.0.3/local/bin/ncadoctest.py", line 1231, in run_one_test
        self.run_one_example(test, example, filename, compileflags)
      File "/space/boothby/sage-4.0.3/local/bin/sagedoctest.py", line 38, in run_one_example
        OrigDocTestRunner.run_one_example(self, test, example, filename, compileflags)
      File "/space/boothby/sage-4.0.3/local/bin/ncadoctest.py", line 1172, in run_one_example
        compileflags, 1) in test.globs
      File "<doctest __main__.example_65[2]>", line 1, in <module>
        RR(-RealNumber('1.5'))._mpmath_()###line 2284:
    sage: RR(-1.5)._mpmath_()
      File "real_mpfr.pyx", line 2289, in sage.rings.real_mpfr.RealNumber._mpmath_ (sage/rings/real$
        from sage.libs.mpmath.all import make_mpf
      File "/space/boothby/sage-4.0.3/local/lib/python2.5/site-packages/sage/libs/mpmath/all.py", l$
        import mpmath
    ImportError: No module named mpmath
**********************************************************************
1 items had failures:
   1 of   3 in __main__.example_65
***Test Failed*** 1 failures.
sage -t -long devel/sage/sage/rings/complex_number.pyx
**********************************************************************
File "/space/boothby/sage-4.0.3/devel/sage-main/sage/rings/complex_number.pyx", line 484:
    sage: CC(1,2)._mpmath_()
Exception raised:
    Traceback (most recent call last):
      File "/space/boothby/sage-4.0.3/local/bin/ncadoctest.py", line 1231, in run_one_test
        self.run_one_example(test, example, filename, compileflags)
      File "/space/boothby/sage-4.0.3/local/bin/sagedoctest.py", line 38, in run_one_example
        OrigDocTestRunner.run_one_example(self, test, example, filename, compileflags)
      File "/space/boothby/sage-4.0.3/local/bin/ncadoctest.py", line 1172, in run_one_example
        compileflags, 1) in test.globs
      File "<doctest __main__.example_15[2]>", line 1, in <module>
        CC(Integer(1),Integer(2))._mpmath_()###line 484:
    sage: CC(1,2)._mpmath_()
      File "complex_number.pyx", line 489, in sage.rings.complex_number.ComplexNumber._mpmath_ (sag$
        from sage.libs.mpmath.all import make_mpc
      File "/space/boothby/sage-4.0.3/local/lib/python2.5/site-packages/sage/libs/mpmath/all.py", l$
        import mpmath
    ImportError: No module named mpmath
**********************************************************************
1 items had failures:
   1 of   3 in __main__.example_15
***Test Failed*** 1 failures.
sage -t -long devel/sage/sage/structure/element.pyx
**********************************************************************
File "/space/boothby/sage-4.0.3/devel/sage-main/sage/structure/element.pyx", line 426:
    sage: from sage.libs.mpmath.all import mp, mpmathify
Exception raised:
    Traceback (most recent call last):
      File "/space/boothby/sage-4.0.3/local/bin/ncadoctest.py", line 1231, in run_one_test
        self.run_one_example(test, example, filename, compileflags)
      File "/space/boothby/sage-4.0.3/local/bin/sagedoctest.py", line 38, in run_one_example
        OrigDocTestRunner.run_one_example(self, test, example, filename, compileflags)
      File "/space/boothby/sage-4.0.3/local/bin/ncadoctest.py", line 1172, in run_one_example
        compileflags, 1) in test.globs
      File "<doctest __main__.example_13[2]>", line 1, in <module>
        from sage.libs.mpmath.all import mp, mpmathify###line 426:
    sage: from sage.libs.mpmath.all import mp, mpmathify
      File "/space/boothby/sage-4.0.3/local/lib/python2.5/site-packages/sage/libs/mpmath/all.py", l$
        import mpmath
    ImportError: No module named mpmath
**********************************************************************
File "/space/boothby/sage-4.0.3/devel/sage-main/sage/structure/element.pyx", line 427:
    sage: mp.dps = 30
Exception raised:
    Traceback (most recent call last):
      File "/space/boothby/sage-4.0.3/local/bin/ncadoctest.py", line 1231, in run_one_test
        self.run_one_example(test, example, filename, compileflags)
      File "/space/boothby/sage-4.0.3/local/bin/sagedoctest.py", line 38, in run_one_example
        OrigDocTestRunner.run_one_example(self, test, example, filename, compileflags)
      File "/space/boothby/sage-4.0.3/local/bin/ncadoctest.py", line 1172, in run_one_example
        compileflags, 1) in test.globs
      File "<doctest __main__.example_13[3]>", line 1, in <module>
        mp.dps = Integer(30)###line 427:
    sage: mp.dps = 30
    NameError: name 'mp' is not defined
**********************************************************************
File "/space/boothby/sage-4.0.3/devel/sage-main/sage/structure/element.pyx", line 428:
    sage: 25._mpmath_(53)
Exception raised:
    Traceback (most recent call last):
      File "/space/boothby/sage-4.0.3/local/bin/ncadoctest.py", line 1231, in run_one_test
        self.run_one_example(test, example, filename, compileflags)
      File "/space/boothby/sage-4.0.3/local/bin/sagedoctest.py", line 38, in run_one_example
        OrigDocTestRunner.run_one_example(self, test, example, filename, compileflags)
      File "/space/boothby/sage-4.0.3/local/bin/ncadoctest.py", line 1172, in run_one_example
        compileflags, 1) in test.globs

...
sage -t -long devel/sage/sage/libs/mpmath/utils.pyx
**********************************************************************
File "/space/boothby/sage-4.0.3/devel/sage-main/sage/libs/mpmath/utils.pyx", line 27:
    sage: from mpmath.libmpf import from_man_exp
Exception raised:
    Traceback (most recent call last):
      File "/space/boothby/sage-4.0.3/local/bin/ncadoctest.py", line 1231, in run_one_test
        self.run_one_example(test, example, filename, compileflags)
      File "/space/boothby/sage-4.0.3/local/bin/sagedoctest.py", line 38, in run_one_example
        OrigDocTestRunner.run_one_example(self, test, example, filename, compileflags)
      File "/space/boothby/sage-4.0.3/local/bin/ncadoctest.py", line 1172, in run_one_example
        compileflags, 1) in test.globs
      File "<doctest __main__.example_0[2]>", line 1, in <module>
        from mpmath.libmpf import from_man_exp###line 27:
    sage: from mpmath.libmpf import from_man_exp
    ImportError: No module named mpmath.libmpf
**********************************************************************
File "/space/boothby/sage-4.0.3/devel/sage-main/sage/libs/mpmath/utils.pyx", line 28:
    sage: from_man_exp(-6, -1)
Exception raised:
    Traceback (most recent call last):
      File "/space/boothby/sage-4.0.3/local/bin/ncadoctest.py", line 1231, in run_one_test
        self.run_one_example(test, example, filename, compileflags)
      File "/space/boothby/sage-4.0.3/local/bin/sagedoctest.py", line 38, in run_one_example
        OrigDocTestRunner.run_one_example(self, test, example, filename, compileflags)
      File "/space/boothby/sage-4.0.3/local/bin/ncadoctest.py", line 1172, in run_one_example
        compileflags, 1) in test.globs
...

Changed 14 months ago by ncalexan

There's an spkg; this looks a lot like you didn't install it. I did *exactly* the same thing with malb's singular spkg update when I was release manager. Maybe we need sage -merge to yell if it sees certain things, like spkgs?

Changed 14 months ago by boothby

Oh damn. Thanks, Nick.

Changed 14 months ago by ncalexan

  • summary changed from [with patch; needs work] mpmath support to [with patch, positive review] mpmath support

Changed 14 months ago by rlm

  • status changed from assigned to closed
  • resolution set to fixed
  • merged set to sage-4.1.rc0

Changed 14 months ago by mvngu

The milestone for this ticket should be 4.1. I can't change it, since I don't have admin privileges on trac.

Changed 14 months ago by rlm

  • milestone set to sage-4.1
Note: See TracTickets for help on using tickets.