-
-
Notifications
You must be signed in to change notification settings - Fork 487
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
Remove RingHomomorphism_coercion #23204
Comments
Changed branch from u/roed/remove_ringhomomorphism_coercion to u/saraedum/remove_ringhomomorphism_coercion |
Changed branch from u/saraedum/remove_ringhomomorphism_coercion to u/roed/remove_ringhomomorphism_coercion |
Branch pushed to git repo; I updated commit sha1. New commits:
|
Commit: |
Changed branch from u/roed/remove_ringhomomorphism_coercion to u/saraedum/remove_ringhomomorphism_coercion |
Work Issues: nonzero and is_zero should work like before |
Branch pushed to git repo; I updated commit sha1. New commits:
|
Branch pushed to git repo; I updated commit sha1. New commits:
|
Changed work issues from nonzero and is_zero should work like before to check that nonzero does not cause a major speed regression |
Changed keywords from sd86.5 to sd86.5, sd87 |
comment:13
The speed regression is minimal. About 235ns vs 220ns in some constructed cases. It should not have much of an effect since most elements overwrite |
Changed work issues from check that nonzero does not cause a major speed regression to none |
comment:16
Doctests are failing in structure/element.pyx, rings/homset.py, combinat/combinat.py, and rings/fraction_field.FpT.pyx. This has to do with the |
comment:17
A strong -1 on calling the category (first): this is relatively expensive, not likely able to be implemented by the No bare exceptions. I don't understand why this needs to be a more generic class: diff --git a/src/sage/rings/morphism.pxd b/src/sage/rings/morphism.pxd
index a751a23..26fbeed 100644
--- a/src/sage/rings/morphism.pxd
+++ b/src/sage/rings/morphism.pxd
@@ -15,10 +15,7 @@ cdef class RingMap_lift(RingMap):
cdef CategoryObject S
cdef class RingHomomorphism(RingMap):
- cdef RingMap _lift
-
-cdef class RingHomomorphism_coercion(RingHomomorphism):
- pass
+ cdef Morphism _lift
cdef class RingHomomorphism_im_gens(RingHomomorphism):
cdef __im_gens This is almost certainly a speed regression: diff --git a/src/sage/rings/morphism.pyx b/src/sage/rings/morphism.pyx
index 978fe44..054aea3 100644
--- a/src/sage/rings/morphism.pyx
+++ b/src/sage/rings/morphism.pyx
@@ -373,7 +375,10 @@ def is_RingHomomorphism(phi):
sage: sage.rings.morphism.is_RingHomomorphism(2/3)
False
"""
- return isinstance(phi, RingHomomorphism)
+ # We use the category framework to determine whether something is a ring homomorphism.
+ from sage.categories.map import Map
+ from sage.categories.all import Rings
+ return isinstance(phi, Map) and phi.category_for().is_subcategory(Rings())
cdef class RingMap(Morphism):
""" This may not be so important as it may not really be used in time-critical code, but it shows up all over the schemes stuff (which should be replaced with a direct I am a little wary of removing Why is this change done: diff --git a/src/sage/schemes/generic/morphism.py b/src/sage/schemes/generic/morphism.py
index 777e3ba..8b7aa8c 100644
--- a/src/sage/schemes/generic/morphism.py
+++ b/src/sage/schemes/generic/morphism.py
@@ -1442,7 +1441,7 @@ class SchemeMorphism_polynomial(SchemeMorphism):
S = self.codomain().change_ring(R)
H = Hom(T,S)
- if isinstance(R, Morphism):
+ if isinstance(R, Map):
if R.domain() == self.base_ring():
R = self.domain().ambient_space().coordinate_ring().hom(R, T.ambient_space().coordinate_ring())
G = [] It does not immediately seem to be related to this ticket. You need to properly handle old pickles with the old class. Error messages are not really sentences (according to Python's conventions): -raise TypeError("Natural coercion morphism from %s to %s not defined."%(self.domain(), self.codomain()))
+raise TypeError("natural coercion morphism from %s to %s not defined"%(self.domain(), self.codomain())) This change really makes me worry:
In particular, it seems like you will now get coercion morphisms that are compositions, which seems to be different behavior than before. This could have subtle effects on code and likely have a performance regression. I agree with the purpose of this ticket and would like to see the ring morphism code simplified. However, I care a lot about the speed in here because polynomials are a core part of the Sage functionality. |
Work Issues: docbuild |
comment:63
Replying to @tscrim:
Feel free to try the generic code first and ask the category only if that fails/throws. Then again, when the category can answer it, it's probably faster…Anyway, I just want PS: I could also imagine that some categories could quickly answer |
comment:64
It still will work when you remove the call up to the category in |
Branch pushed to git repo; I updated commit sha1. New commits:
|
comment:66
Let's see if this fixes the docbuild. I am running tests right now. I also created a followup to improve the performance of |
Changed work issues from docbuild to none |
comment:68
All long tests pass. Documentation builds. |
comment:69
Hi, There’s a lot of commits and discussion above. However, it seems to me that the entire point of this ticket is to remove some ugly code that David Roe wrote in 2007 when he was Cythonizing my morphisms code. The relevant git blame is:
They did the hard work to fix all the doctests, everything passes, and the speed regression has no real impact on other code (you can just compare to None), and there is a followup ticket for that. The modified code seems much cleaner. I’m giving this a positive review. I’ve always thought our coercion code is too complicated/ugly, so anything that cleans it up – and this surely does – is worth it. Please start discussing ideas for optimization on #23513. (Travis – I’m sitting here talking with the authors of this code, so maybe have more context than you.) |
Changed reviewer from Travis Scrimshaw, Aly Deines to Travis Scrimshaw, Aly Deines, William Stein |
comment:71
I apologize in advance for any frustration in my response. I tried to make it as constructive as I can. If you really think that this regression in the rest of Sage is worth the speed increase for rings (to which is only benefits certain rings and there is a check to see if the ring is in Replying to @williamstein:
I think this alone does not merit a positive review.
That is not true. Checking in/surjectivity for a formal composite morphism that is not in the category of rings will be slowed down by a 10x factor as demonstrated above, and it is not simply comparing something to
vs before
The reason why I am unsure is because the first time I run with the new code, I get ~28.5 µs. However, this does not happen on re-trails. Do you also experience this? Actually, when I removed the caching on
vs old:
So this does in fact net a ~2x speedup for this case. However, given the check for if something is in fields, that made me think of the following situation. Suppose we implement a special morphism for ring morphisms out of Z/nZ that checks for injectivity by looking at the image of Well, this argument is moot if we put the check for
The What about my comment about undoing the deprecation on I can think of some cases where not having the
I agree that removing the
I am not. Also, anybody trying to understand why this change was made latter will not have this context either. Since a few people in a room are making decisions and not giving me this context, I am going to stop reviewing and writing any code involving ring morphisms/coercions. I've spent too much time, energy, and political capital working on this. |
comment:72
Bummer. Hopefully, you can focus more on the millions of other interesting things you’ve done.
For what it is worth, I greatly respect and appreciation your many contributions to Sage, and your careful feedback related to this and many other ticket. Looking forward to seeing you sometime in the future at a Sage days... |
comment:73
Replying to @williamstein:
It is worth quite a bit, thank you. It will be nice to see you again too at a future Sage days. Also thank you to everyone else who worked on this ticket. I do think it is overall a step in the right direction. |
Changed branch from u/saraedum/remove_ringhomomorphism_coercion to |
, sagemath#24483, sagemath#24371, sagemath#24511, sagemath#25848, sagemath#26105, sagemath#28481, sagemath#29010, sagemath#29412, sagemath#30332, sagemath#30372, sagemath#31345, sagemath#32375, sagemath#32606, sagemath#32610, sagemath#32612, sagemath#32641, sagemath#32660, sagemath#32750, sagemath#32869, sagemath#33602 <!-- ^^^^^ Please provide a concise, informative and self-explanatory title. Don't put issue numbers in there, do this in the PR body below. For example, instead of "Fixes sagemath#1234" use "Introduce new method to calculate 1+1" --> <!-- Describe your changes here in detail --> <!-- Why is this change required? What problem does it solve? --> <!-- If this PR resolves an open issue, please link to it here. For example "Fixes sagemath#12345". --> <!-- If your change requires a documentation PR, please link it appropriately. --> ### 📝 Checklist <!-- Put an `x` in all the boxes that apply. --> <!-- If your change requires a documentation PR, please link it appropriately --> <!-- If you're unsure about any of these, don't hesitate to ask. We're here to help! --> <!-- Feel free to remove irrelevant items. --> - [x] The title is concise, informative, and self-explanatory. - [ ] The description explains in detail what this PR is about. - [x] I have linked a relevant issue or discussion. - [ ] I have created tests covering the changes. - [ ] I have updated the documentation accordingly. ### ⌛ Dependencies <!-- List all open PRs that this PR logically depends on - sagemath#12345: short description why this is a dependency - sagemath#34567: ... --> <!-- If you're unsure about any of these, don't hesitate to ask. We're here to help! --> URL: sagemath#36307 Reported by: Matthias Köppe Reviewer(s):
we should try to use
.coerce_map_from()
instead, so we getis_injective()/is_surjective()
and friends right forHom.natural_map()
.Depends on #23184
Depends on #23211
CC: @xcaruso
Component: commutative algebra
Keywords: sd86.5, sd87
Author: David Roe, Julian Rüth
Branch/Commit:
382e2d1
Reviewer: Travis Scrimshaw, Aly Deines, William Stein
Issue created by migration from https://trac.sagemath.org/ticket/23204
The text was updated successfully, but these errors were encountered: