-
-
Notifications
You must be signed in to change notification settings - Fork 594
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 sage.libs.giac with new optional package sagemath-giac #39376
Conversation
Documentation preview for this PR (built with commit d7a5f54; changes) is ready! 🎉 |
How is giac integration different from bliss/meataxe/sirocco that makes it impossible for it to be optional while still living in the main sage source tree? |
It's not. Matthias has a What you'll find at https://github.com/orlitzky/sagemath-giac is a normal cython package. You can clone it, build it, test it, package it, etc. independent of sage-the-distro, using what you already know as a python developer. There's no magic, and even the doctests work with a simple |
I disagree - thinking outside the sage-the-distro framework I see a few disadvantages of this approach:
Since, as you said, this works properly in meson and we're moving towards making meson the default buildsystem, won't this eventually fix itself? |
Fair concerns, but in this case I would not be too worried:
Absolutely, this was a tempting approach. But giac is completely broken on both types of systems I have. It doesn't build on anything other than x86_64/arm64, and even on x86_64, it crashes under a hardened glibcxx. How long is eventually? |
It is maybe worth mentioning that, once upon a time, this was already a separate package. It was bundled with sagelib when it was made a standard package to avoid a circular dependency sagelib -> sagemath_giac -> sagelib. But today, there is no sagelib -> sagemath_giac dependency. All of the integration backends are drop-ins and can fail without issue. |
8302d6c
to
454c025
Compare
Can you explain the problem with the cython compilation in more detail please. You mentioned in the other PR:
So, you have sage installed in venv A, but cython in venv B; and try to build sagemath-giac in venv A? I think the reason why this is not working is because you don't declare sage as a dependency here: To make this easier we may add a |
Almost. The system cython is being used to build sagemath-giac against sagelib installed in a venv (I am building sage-the-distro "normally" to make sure it works). Without the
That's a "cythonize" failure that occurs because the
If you look further down, I am including a similar thing for |
If the issue is at the cythonize stage, then adding something like this should work (with the path to the root of Lines 128 to 131 in dc99dc8
|
Sure, but this is just one of potentially many external cython packages, and the issue only arises because sage-the-distro hides sagelib in a venv. Wouldn't it be better to address the problem once, in sage-the-distro? sagemath-standard is declared as a dependency of sagemath-giac (in At build time, sage-the-distro is using the venv python, which has all of the dependencies in its path. At run time, sage-the-distro uses the venv python for the same reason. It's only the call to the system |
454c025
to
37eba1c
Compare
Reviewers should take a look at https://github.com/sagemath/sagemath-giac too since obviously a big part of this was separating the package. |
@dimpase I don't know why but you aren't in the reviewer dropdown |
I screamed too loudly on #39467. |
Thinking more about this recently, there is another reason why "wait for meson" isn't as nice of a solution. On Gentoo (and on sage-the-distro), sagelib usually "breaks" whenever giac is updated. And, to fix it, you have to rebuild all of sagelib. With sagemath-giac separate, you can instead do a 30s rebuild of the affected modules only. |
"wait for meson" is worse than doing a proper Pythonic modularisation, IMHO. |
Sorry for the late reply. This makes a lot more sense now. So, I agree, having a "sage cython" in sage-the-distro as a wrapper around cython with the correct path/deps handling looks like a good solution. But this should then be a script specific to sage-the-distro, and not something that is installed as part of sagelib, right? |
Right. |
(The Gentoo CI failures related to giac are a pre-existing condition) |
Regardless of modularisation, having to recompile sage to enable an option (in the sage packaging context - I am aware that if you are pottering in your local tree install, it is not the same) has always been a bit of a downer. Having it being a plug and play thing is much more effective and easy to turn on and off. |
Could you then please create this sage-cython wrapper in |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Apart from the sage-cython script and some minor comments, things are looking good to me.
(Sorry for the late review)
@@ -560,7 +560,7 @@ def __init__(self): | |||
""" | |||
JoinFeature.__init__(self, 'sage.libs.giac', | |||
[PythonModule('sage.libs.giac.giac')], | |||
spkg='sagemath_giac', type='standard') | |||
spkg='sagemath_giac', type='optional') |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Should this feature not better now use the new sagemath-giac package to test it? sage.libs.giac.giac
is always available.
Alternatively, if we no longer need the giac tests (because all tests are now in the new giac repo), then please remove it.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This still works because the PythonModule
test tries to import the module and it will fail if sagemath-giac is not installed:
sage: from sage.features.sagemath import sage__libs__giac
sage: sage__libs__giac().is_present()
FeatureTestResult('sage.libs.giac.giac', False)
There are indeed some integral tests in sagelib that have # needs sage.libs.giac
. I did some work a month or two ago to carefully separate them from the # needs giac
tests.
gb_giac = F.eliminate(list(elim_variables), 'gbasis') | ||
|
||
return PolynomialSequence(gb_giac, P, immutable=True) | ||
# sagemath_giac split its __init__.py into these two |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Not utterly important, but could we add a pytest that checks if this integration is working at least in principle by, say, calculating something simple.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can you elaborate?
In sagemath-giac, I have taken the contents of the old __init__.py
and moved them into two separate files, gb.py
and context.py
. In sagelib I am importing those two modules inside of __init__.py
so that, if sagemath-giac is installed, all of the old stuff will be available where you expect it using from sage.libs.giac import foo
. If, on the other hand, sagemath-giac is not installed, then import sage.libs.giac
will fail with an ImportError
.
There are doctests that have # needs sage.libs.giac
that will test this when sagemath-giac is installed. Or did you just want something for pytest specifically?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I wanted a test that checks that these simple reexports work as expected (as a kind of silly integration test). But, as you write above, there are still tests in sage using giac, so this is not really needed.
We can set |
This one is not so easy because sage-cython needs to be inside the venv for it to magically pick up the venv python/sitedir when it is launched.
# Only makes sense in sage-the-distribution. TODO: Move to another installation script.
bin/sage-list-packages but I've no idea what such an installation script might look like. |
This package has been split off into sagemath-giac.
SageMath no longer links against libgiac directly.
This directory has been removed (into a separate package).
The sage library can now be built without giac.
The sage library no longer requires giac.
This helper script has been moved to the sagemath-giac package.
The src/sage/libs/giac tree has been split off into a separate package, sagemath-giac.
This interface is now contained in a separate package, but until cython supports namespace packages, that interface must have a different name. We bring back sage.libs.giac as a wrapper around it to avoid breaking existing code.
This optional sage/giac integration package replaces the old hard dependency on giac that was required to build sage.libs.giac.
This is now strictly required only by the (optional) sagemath_giac package. There is a feature test guarding the doctests in the old pexpect interface under sage.interfaces.giac, and nothing else in sagelib imports that pexpect interface, so if you do not use it explicitly, giac is optional.
37eba1c
to
d7a5f54
Compare
Force push:
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for all the work you put into this!
Thanks! I've updated the release tour, and with this, sage now runs on risc-v hardware out-of-the-box: |
As the last step in #38668, we move
sage/libs/giac
into a separate package,and make it optional. This module is already mostly independent of sage -- there is nothing in sagelib that depends on it unconditionally. Its main use is as an integration backend, where it is technically optional because we try whatever backends are available in succession and expect some to fail.
In fact, the modules themselves are already optional if you are using meson. The
sage/libs/giac
directory is simply skipped when meson cannot find giac. It is not possible to do the same thing using the build system for sage-the-distro, however, which motivates the separate package. Many reasons are given in #38668 for why you might want to avoid giac, but the main reason for me right now is because it's not portable: it doesn't build and/or run on systems where the rest of sage works fine, including the one I am using most of the time.The new package uses the namespace
sagemath_giac
to work around missing namespace support in cython, butsage.libs.giac
re-exports everything under the old name for backwards compatibility.