Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Replace imports from sage.all #123

Merged
merged 46 commits into from
Jan 14, 2025

Conversation

mkoeppe
Copy link
Contributor

@mkoeppe mkoeppe commented Oct 29, 2024

Preparation for using modularized distributions of the Sage library.

Done in part using sage -fiximports.

@unhyperbolic
Copy link
Member

unhyperbolic commented Oct 31, 2024

Thanks for looking into this.

How stable are these import paths? How many versions of sage do they go back?

The CI is configured to run SnapPy against various docker containers with different SageMath versions. It reports that 4 out of 11 suites failed. Unfortunately, github doesn't let me see which :(

In the past, we had large try: ... except ImportError: ... blocks to account for different sage versions.

@mkoeppe
Copy link
Contributor Author

mkoeppe commented Oct 31, 2024

How stable are these import paths? How many versions of sage do they go back?

AFAICS these imports are all unchanged in Sage over at least the past 5 years

The CI is configured to run SnapPy against various docker containers with different SageMath versions. It reports that 4 out of 11 suites failed. Unfortunately, github doesn't let me see which :(

Are you saying that the current branch was already tested?

By the way, my motivation here is to get SnapPy to run on top of my modularized fork of Sage https://github.com/passagemath/passagemath

@NathanDunfield
Copy link
Member

NathanDunfield commented Oct 31, 2024

Our CI tests SnapPy on the official Sage Docker images, from 9.3 (circa 2021) up to 10.4. We do not test against the development branch of Sage.

I enabled the CI for this PR and tweaked the CI config. The PR fails when running the doctests for Sage 9.* and passes for Sage 10.*. The common error is:

  File "/home/sage/sage/local/var/lib/sage/venv-python3.9.9/lib/python3.9/site-packages/snappy/snap/polished_reps.py", line 18, in <module>
    from sage.combinat.subset import powerset
ImportError: cannot import name 'powerset' from 'sage.combinat.subset' (/home/sage/sage/local/var/lib/sage/venv-python3.9.9/lib/python3.9/site-packages/sage/combinat/subset.py)

@mkoeppe
Copy link
Contributor Author

mkoeppe commented Oct 31, 2024

Thanks @NathanDunfield. Would changes like just pushed in ada49ea be acceptable?

@NathanDunfield
Copy link
Member

Would changes like just pushed in ada49ea be acceptable?

Overall, it looks good to me. For the frequently imported things, it might be better to do the import in sage_helper.py , especially if it needs a try-except block. See the example of ComplexField in that file.

@mkoeppe
Copy link
Contributor Author

mkoeppe commented Nov 1, 2024

Here's a more complete version (still has a failure in doctesting snappy.database that I don't understand at the moment).
With this version, I can get snappy.test to run on top of only passagemath-flint, passagemath-repl, passagemath-groups, passagemath-symbolics, passagemath-plot, passagemath-graphs.

@mkoeppe
Copy link
Contributor Author

mkoeppe commented Dec 31, 2024

@NathanDunfield @unhyperbolic This passes tests now

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Now that you've added a bunch of Sage imports to sage_helper.py, I think it makes sense to import those objects through it here and in analogous places throughout. E.g.

from ..sage_helper import ZZ, QQ, matrix

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done, I think. Preview: https://github.com/mkoeppe/SnapPy/actions/runs/12575148681

Happy new year!

@NathanDunfield
Copy link
Member

@mkoeppe Looks good to me so far.

@unhyperbolic and @culler any comments?

from sage.all import sqrt
from sage.all import I, Infinity
from sage.all import arccosh
from sage.all import RIF, CIF
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do we actually need this?

Note: I do use the name RIF and CIF for RealIntervalField and ComplexIntervalField instances with precisions different from RealIntervalField() and ComplexIntervalField().

@@ -17,8 +17,8 @@
from ...sage_helper import _within_sage

if _within_sage:
import sage.all
from sage.all import matrix
from ...sage_helper import I, matrix, RIF, CIF
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This RIF and CIF import should go into run_tests again.

import sage.all
from sage.all import matrix, sqrt
from sage.rings.real_mpfi import is_RealIntervalFieldElement
import sage
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is this "import sage" needed?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think it can be removed.

@unhyperbolic unhyperbolic merged commit 28b2932 into 3-manifolds:master Jan 14, 2025
@mkoeppe
Copy link
Contributor Author

mkoeppe commented Jan 14, 2025

Thanks for merging! I'll follow up with some more proposed changes

@mkoeppe mkoeppe deleted the sage.all-imports branch January 14, 2025 21:19
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.

3 participants