Skip to content

Remove sage backend#732

Merged
skirpichev merged 1 commit intompmath:masterfrom
skirpichev:no-sage
Nov 18, 2023
Merged

Remove sage backend#732
skirpichev merged 1 commit intompmath:masterfrom
skirpichev:no-sage

Conversation

@skirpichev
Copy link
Copy Markdown
Collaborator

Closes #705
Closes #574

@skirpichev skirpichev requested a review from dimpase October 19, 2023 04:20
@skirpichev skirpichev merged commit 05dc18a into mpmath:master Nov 18, 2023
@skirpichev skirpichev deleted the no-sage branch November 18, 2023 03:32
@tornaria
Copy link
Copy Markdown
Contributor

This breaks sagemath (which sets MPMATH_SAGE=1 in the environment and expects the mantissa to be of type sage.rings.integer.Integer. I'm testing with mpmath 1.4.0a0, now that sympy 1.12.1a1 supports it.

Is there a plan on how to move forward sagemath?

cc: @dimpase

@dimpase
Copy link
Copy Markdown
Collaborator

dimpase commented Mar 29, 2024

@tornaria - I don't recall what the plan was - perhaps just to drop that Sage variable?

@tornaria
Copy link
Copy Markdown
Contributor

@tornaria - I don't recall what the plan was - perhaps just to drop that Sage variable?

First sagemath has to support mpmath with gmpy2 backend, but I did not find a PR for that (maybe there is none, I just saw this being discussed on #705)

@skirpichev @fredrik-johansson do you have any input about this?

FWIW, I think removing the sage backend is a good move, but some coordination with sagemath seems a good thing.

@skirpichev
Copy link
Copy Markdown
Collaborator Author

First sagemath has to support mpmath with gmpy2 backend

I don't think we should do anything special for it. If sage has the gmpy2 module - gmpy2 support for the mpmath will be turned on, unless you disabled it by the MPMATH_NOGMPY environment variable.

@tornaria
Copy link
Copy Markdown
Contributor

First sagemath has to support mpmath with gmpy2 backend

I don't think we should do anything special for it. If sage has the gmpy2 module - gmpy2 support for the mpmath will be turned on, unless you disabled it by the MPMATH_NOGMPY environment variable.

Something has to be done somewhere, since running sagemath with 1.4.0a0 is broken, for instance:

$ sage
┌────────────────────────────────────────────────────────────────────┐
│ SageMath version 10.3, Release Date: 2024-03-19                    │
│ Using Python 3.12.2. Type "help()" for help.                       │
└────────────────────────────────────────────────────────────────────┘
sage: from sage.libs.mpmath.all import sage_to_mpmath, mpmath_to_sage
sage: mpmath_to_sage(sage_to_mpmath(0.0, prec=50), prec=50)
---------------------------------------------------------------------------
TypeError                                 Traceback (most recent call last)
Cell In[2], line 1
----> 1 mpmath_to_sage(sage_to_mpmath(RealNumber('0.0'), prec=Integer(50)), prec=Integer(50))

File /usr/lib/python3.12/site-packages/sage/libs/mpmath/utils.pyx:271, in sage.libs.mpmath.utils.mpmath_to_sage (build/cythonized/sage/libs/mpmath/utils.c:8440)()
    269 if hasattr(x, "_mpf_"):
    270     y = RealField(prec)()
--> 271     mpfr_from_mpfval(y.value, x._mpf_)
    272     return y
    273 elif hasattr(x, "_mpc_"):

File /usr/lib/python3.12/site-packages/sage/libs/mpmath/utils.pyx:166, in sage.libs.mpmath.utils.mpfr_from_mpfval (build/cythonized/sage/libs/mpmath/utils.c:7571)()
    164 cdef long exp
    165 cdef long bc
--> 166 sign, man, exp, bc = x
    167 if man:
    168     mpfr_set_z(res, man.value, MPFR_RNDZ)

TypeError: Cannot convert gmpy2.mpz to sage.rings.integer.Integer

Hopefully it's only conversion. As I said, sage is expecting man to be a sage integer. Also when going in the other direction sage will use sage integers for the mantissa, maybe this breaks mpmath in other ways.

@skirpichev
Copy link
Copy Markdown
Collaborator Author

I see. Sage has additional cython replacements for mpmath functions, but this interface is outdated already for the 1.3.0 version (see e.g. sagemath/sage#36447). I think it might be dropped.

@dimpase
Copy link
Copy Markdown
Collaborator

dimpase commented Mar 30, 2024

which version of scipy is compatible with this branch?

I am seeing

  File "/usr/lib/python3.11/site-packages/sympy/core/numbers.py", line 4567, in <module>
    _sympy_converter[type(mpmath.rational.mpq(1, 2))] = sympify_mpmath_mpq
                          ^^^^^^^^^^^^^^^
AttributeError: module 'mpmath' has no attribute 'rational'

while running ./sage -tp src/sage/libs/mpmath, so there is something going on there.

@skirpichev
Copy link
Copy Markdown
Collaborator Author

which version of scipy is compatible with this branch?

AFAIC, only the sympy master, since sympy/sympy#26269

@oscarbenjamin
Copy link
Copy Markdown

Actually there is sympy 1.12.1a1 that should be compatible:
https://pypi.org/project/sympy/#history

Soon there should be 1.12.1

@dimpase
Copy link
Copy Markdown
Collaborator

dimpase commented Mar 30, 2024

oh yeah, it's SymPy, not SciPy

@tornaria
Copy link
Copy Markdown
Contributor

Actually there is sympy 1.12.1a1 that should be compatible: https://pypi.org/project/sympy/#history

Yes, thanks for that. It's why I started testing this only now.

@oscarbenjamin
Copy link
Copy Markdown

I don't know how easily this fits your workflow but you might find it easier to track mpmath and sympy master branches. SymPy's master branch tracks mpmath's master branch directly regardless of prereleases:
https://github.com/sympy/sympy/blob/17639a46b648f265c968ea86b78725258024f715/.github/workflows/runtests.yml#L461
It is more likely that the master branches are in sync than that prereleases are.

@tornaria
Copy link
Copy Markdown
Contributor

I don't know how easily this fits your workflow but you might find it easier to track mpmath and sympy master branches. SymPy's master branch tracks mpmath's master branch directly regardless of prereleases: https://github.com/sympy/sympy/blob/17639a46b648f265c968ea86b78725258024f715/.github/workflows/runtests.yml#L461 It is more likely that the master branches are in sync than that prereleases are.

I track prereleases to have ahead-of-time warning of what will happen with future updates (maiainly sagemath and dependencies, e.g. void-linux/void-packages#49571). Tracking master would be unworkable (and for most projects building from master is a different procedure than building from a release or prerelease, so it wouldn't be testing the same). I dogfood my own draft packages so they have to be in a usable combination.

@mkoeppe
Copy link
Copy Markdown

mkoeppe commented May 31, 2024

I have the necessary update for Sage in sagemath/sage#38113

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Test sage integration or remove sage backend Commit 84ca137ff84f7b3d22cabcf8bfe260146db4defe breaks running distro-provided sagemath

5 participants