-
-
Notifications
You must be signed in to change notification settings - Fork 528
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
PolynomialRing_integral_domain ignores Ctrl-C and segfaults #7794
Comments
comment:1
I just verified that the problem seems to be fixed in sage-4.6.2. Firstly, the original example now works sufficiently quickly, so that there is no need to interrupt the computation:
Secondly, if one tries the same thing with a higher exponent, hitting Ctrl-c works (or at least it does after several attempts):
So, I believe this ticket can be closed! If I am not mistaken, I first need to put it as "needs review"... |
Reviewer: Simon King |
comment:2
I miss the possibility to change the ticket into the state "worksforme", but that's my review, in one word... |
comment:3
I'm still able to reproduce the problem on sage-4.7.rc2 (note that interrupt handling was completely rewritten in #9678, merged in sage-4.7.alpha1, so testing this with sage-4.6.2 is pointless).
|
comment:5
Since the problem seems to be related with get_cparent, I was first looking into that. There was a bare "except:", where it should be catching an attribute error. But that was not the problem. Next, I looked into polynomial_template.pxi, where get_cparent is frequently used. Too frequently, actually. In many methods it is called several times. So, it would be better to assign its output to a cdef'd variable -- that would actually boost the speed a lot! Namely, working on other tickets, I know that the "harmless" method So, one approach would be to remove the redundant calls - which makes sense anyway. If that does not help with the segfault, one could still try to wrap it into sig_on()/sig_off(). |
comment:6
It is really surprising how many redundant calls can be found in polynomial_template.pxi. I guess that's why get_cparent is defined as an inline cpdef function -- but that won't help if it internally calls pure Python functions! |
comment:7
The attached patch seems to fix the problem, but I haven't checked carefully whether it might break other stuff. I'm putting it to needs_review, but I haven't really thought about it much. |
comment:8
Hi Jeroen, Can you give me a pointer to the documentation of the I'll try your patch. I have prepared another patch, with the purpose of reducing the number of calls to get_cparent() (and thus to modulus()). But this will concern performance and should thus be on another ticket. |
comment:9
I think a found a reference to handling Cython errors. |
comment:10
After reading the documentation, it seems to me that your approach makes very much sense. The original problem seems to be solved. So, if the long doctests pass then I'll give it a positive review. |
comment:11
Meanwhile I wonder: In the original version of get_cparent, an attribute error was caught internally, and then zero was returned. Now, you return zero on error, and you do not catch the error internally. Couldn't that result in confusion, if the argument Perhaps it is safer to keep modify the internal try-except clause (namely replace the bare Namely, -1 can not result as a regular return value (the return value is the modulus of a ring, and thus a positive number), and so it would be safe to reserve -1 for errors (then you can also remove the question mark from Will you do this change (if you agree with my arguing), or shall I make the change in a separate patch? |
comment:12
Replying to @simon-king-jena:
On the other hand:
I will test whether |
comment:13
Replying to @simon-king-jena:
Yes, it is called with |
comment:14
I considered the following version of get_cparent in polynomial_zmod_flint.pyx:
Rationale: The original code was catching an error that should probably be an attribute error - so, we do the same, and return the same value that was returned by the original version. But the return value 1 can never occur (which I verified by the doctests of sage/rings/). So, it is safe to reserve 1 as the exceptional value, without question mark after However, our two patch versions performed equally when I tried some timings. Hence, unless you say that I convinced you to use 1 as exceptional return value (without question mark), I will give your patch a positive review, provided the doc tests pass. |
comment:15
Tests pass. So, let it be a positive review to your patch! |
Author: Jeroen Demeyer |
comment:16
Replying to @simon-king-jena:
Are you very sure that 1 cannot occur? You might be right, but I would not count on it. |
comment:17
you are probably right about
This will also catch the case |
comment:18
Replying to @jdemeyer:
Yes, that looks a bit better. Concerning modulus 1: It is possible to explicitly construct an instance of
So, in order to be on the safe side, one should not have One may argue, however, that it can not occur if one constructs a ring as one is supposed to, namely by calling the polynomial ring constructor:
But better safe than sorry, in particular since your safe solution ( Namely, as much as I understand, But, to the best of my knowledge, it is impossible to have a parent with modulus zero, even if one works around the polynomial ring constructor:
So, if one has return value zero then something exceptional must be happening: Either it is a real error, or it is during pickling, when Can you update your patch, so that the attribute error is caught? Then I'll run the tests again, and will hoppefully be able to renew my positive review. |
Work Issues: catch attribute error |
Attachment: 7794_get_cparent.patch.gz |
Changed work issues from catch attribute error to none |
comment:21
All long tests passed with your new patch. I tried to add a doc test, as follows:
However, it did not work, since there seem to be other places in which errors are not properly caught. Namely, I occasionally got:
So, the first alarm worked, but the second didn't, and only when I pressed -c then the computation was interrupted. What shall we do now? Clearly, your patch is a progress. So, I tend to give it a positive review (because all tests pass), and deal with the remaining problem on a different ticket. What do you think? |
comment:22
Replying to @simon-king-jena:
I'll see if I can identify the problem. |
comment:23
I cannot easily identify the problem, so let's put it to positive_review (even though I agree the isuue is not 100% solved). |
comment:24
I have tracked the
The problem is the line
Since this code is generated by Cython, perhaps it is not possible to solve this problem without patching Cython. |
comment:25
I believe the "Exception ignored" to be harmless, in the sense that it's not going to break anything or cause segmentation faults. If the exception is ignored, the computation simply continues and the user can press ctrl-C a second time and that should do it. |
comment:26
Replying to @jdemeyer:
Yes, but it made it impossible for me to create a doctest for your fix! |
Merged: sage-4.7.1.alpha2 |
The following was reported by Alex P on sage-support:
So: First, Ctrl-C is ignored, which is bad IMO. Then, hitting Ctrl-C again (actually twice) results in a segfault, which is a desaster.
Component: algebra
Keywords: Polynomial Ring KeyboardInterrupt
Author: Jeroen Demeyer
Reviewer: Simon King
Merged: sage-4.7.1.alpha2
Issue created by migration from https://trac.sagemath.org/ticket/7794
The text was updated successfully, but these errors were encountered: