ASKSAGE: Sage Q&A Forum - Latest question feedhttp://ask.sagemath.org/questions/Q&A Forum for SageenCopyright Sage, 2010. Some rights reserved under creative commons license.Mon, 18 Jun 2018 05:24:39 -0500timeout does not work with maxima. Ok with othershttp://ask.sagemath.org/question/42644/timeout-does-not-work-with-maxima-ok-with-others/This is using SageMath version 8.3.beta5, Release Date: 2018-06-09
I set a timeout using Python signal to put a limit on how long an integral can take (since as far as I know python itself does not have a timeout constraint support to use on a call to a function, so one must program this in)
If integrate takes more than some number of seconds, an exception is raised. This way my script does not hang on an integral.
I found it works with `fricas`, but not with `maxima`. i.e. when I set the algorithm to `maxima`, and pick an integral that takes too long and set the timeout to short time (10 seconds), the exception never fires. It means the signal was lost or ignored.
When I do the same thing, set the algorithm to `fricas`, and pick an integral that also takes long time for `fricas` to do, the timeout works.
Same exact code. Only difference is the algorithm used.
May be the way I am setting timer is not the best, and there are more robust ways to do this. But I do not understand now why it works with `fricas` and not with `maxima`. Here is an example. This is file called `test_hanged.sag`
#!/usr/bin/env sage
import sys, os, signal, time
from sage.all import *
class TimeoutError(Exception):
pass
def handler(signum,frame):
print("handler fired")
raise TimeoutError()
signal.signal(signal.SIGALRM, handler)
signal.alarm(10) #10 seconds time out
try:
#this call will hang. Timer is either lost or ignored. Only with maxima
integrate(sqrt(x^2 + 1)*arctan(x)^2,x, algorithm="maxima")
#never reach here
signal.alarm(0)
print "Finished "
except Exception as e:
#this never gets called. It is supposed to be called after 10 seconds
print "exception=", type(e).__name__
print "finished...."
Then `$ ./test_hang.sage` just hangs. Now the following with `fricas`, works. Same code. Just changed the call to integrate
#!/usr/bin/env sage
import sys, os, signal, time
from sage.all import *
class TimeoutError(Exception):
pass
def handler(signum,frame):
print("handler fired")
raise TimeoutError()
signal.signal(signal.SIGALRM, handler)
signal.alarm(10) #10 seconds time out
try:
#this call will hang or take too long if there is no timeout
integrate((x+(1+x)^(1/2))^(1/2)/(x^2+1)/(1+x)^(1/2),x,algorithm="fricas")
#never reach here, due to time out
signal.alarm(0)
print "Finished "
except Exception as e:
#this is now called. So timer worked.
print "exception=", type(e).__name__
print "finished...."
And now
./test_hang.sage
handler fired
exception= TimeoutError
finished....
Any idea why the above works with `fricas` and not with `maxima`? I need now to try to find better way to do timeouts, as the above does not work for all.NasserMon, 18 Jun 2018 05:24:39 -0500http://ask.sagemath.org/question/42644/Macaulay2 Does Nothinghttp://ask.sagemath.org/question/24041/macaulay2-does-nothing/I've been trying to run Macaulay2 in Sage to generate some examples for a project I have.
I used cloud.sagemath.com and everything worked fine for a while, but some inputs just wouldn't evaluate. There was no error, and it wouldn't freeze- it's just that nothing would happen. I figured there was a calculation limit, so I downloaded sage and Macaulay2, but the same problem occurs. Sage and Macaulay2 appear to be properly installed.
An example of code which doesn't do anything is:
R = ZZ[O1,O2,O3,O4,O5,In1,In2,In3,In4,In5];
I = ideal(O1*O2,O2*O3,O3*O4,O4*O5,O5*O1,In1*In3,In3*In5,In5*In2,In2*In4,In4*In1,O1*In1,O2*In2,O3*In3,O4*In4,O5*In5);
J = ideal(O1,O2,O3,O4,O5,In1,In2,In3,In4,In5);
v = flatten entries mingens J;
e = flatten entries mingens I;
m = table(e,e,(a,b)->a*b);
s = unique flatten m;
for i when i<length e do s=delete(e#i^2,s);
dvds = (a,b) -> if b%(a*a)==0 then true else false;
f = x -> any(v, a -> dvds(a,x));
i = 0; while i<#s do if f(s#i)==false then s=delete(s#i,s) else i=i+1;
F = ideal(s);
betti F
betti I
Meanwhile, similar code which returns correct-looking output is
%macaulay2
R = ZZ[x1,x2,x3,x4];
I = ideal(x1*x2, x2*x3, x3*x4, x4*x1);
J = ideal (x1,x2,x3,x4);
v = flatten entries mingens J;
e = flatten entries mingens I;
m = table(e,e,(a,b)->a*b);
s = unique flatten m;
for i when i<length e do s=delete(e#i^2,s);
dvds = (a,b) -> if b%(a*a)==0 then true else false;
f = x -> any(v, a -> dvds(a,x));
i = 0; while i<#s do if f(s#i)==false then s=delete(s#i,s) else i=i+1;
F = ideal(s);
betti F
betti I
The output is
Ideal of R
Ideal of R
2 2 2 2
{x1*x3*x4 , x2*x3 x4, x1 x2*x4, x1*x2 x3}
List
Ideal of R
0 1
total: 1 4
0: 1 .
1: . .
2: . .
3: . 4
BettiTally
0 1
total: 1 4
0: 1 .
1: . 4
BettiTally
The only real difference seems to be the number of calculations made, and this idea is confirmed in that the calculations always seem to fail around `ZZ[x1..xn]` for `n>8`. There must be some way to fix this. Can anyone help?OWGSun, 07 Sep 2014 13:01:12 -0500http://ask.sagemath.org/question/24041/How does Notebook worksheet timeout work?http://ask.sagemath.org/question/23351/how-does-notebook-worksheet-timeout-work/I cannot understand how the Sage Notebook server actually treats the `timeout` parameter. The [documentation](http://sagemath.org/doc/reference/notebook/sagenb/notebook/notebook_object.html) just says that it is the "*...seconds until idle worksheet sessions automatically timeout.*" However, it is not completely clear when the worksheet is considered *idle*.
From [this answer](http://ask.sagemath.org/question/7638/what-state-is-preserved-when-i-close-a-running-notebook-browser-window/?answer=11556#post-id-11556) by William Stein it follows that the worksheet is considered *idle* if the user closes the corresponding tab in the browser.
I performed several tests today and here is what I got:
1. I started my local Notebook server with `timeout=10` and opened a couple of worksheets in my browser. After that I closed some of them keeping the others open, and just waited for the corresponding message in the console. After about 10 minutes I saw a bunch of messages in the console saying that Sage had just closed all of my opened worksheets. So, Sage server closed all the worksheets regardless of whether they were opened in the browser or not.
2. During the second test I opened two worksheets and started to refresh only one of them (by pressing `F5`). After ~10min Sage closed both of them at the same time. So, obviously, refreshing the page does not help.
3. The third test was to start computing something and see what happens. So I started some "never-ending" computation in the worksheet and kept the page open in the browser. It showed the rotating stick (`/ \ / \ ...`) for ~10 minutes and than terminated the process again, despite the fact that I kept the browser tab open all the time.
So it looks like the only thing that resets the timer is starting some cell to calculate something (`Shift+Enter`).
*And just a side note: I noticed that the minimum actual timeout is 10 minutes.*
---------------
My question is: are all my tests and conclusions correct? And if they are, is it really the intended behaviour for Notebook server?v_2eThu, 10 Jul 2014 12:26:37 -0500http://ask.sagemath.org/question/23351/Any way to timeout?http://ask.sagemath.org/question/7931/any-way-to-timeout/If I run the bool(eq) with the equation as in the following, sometimes it returns False, sometimes it hangs. I was wondering is there anyway to put a timelimit when I call bool(eq).
sage: eq=1/2*((2*e^(2*x) + e^(4*x) + 1)*(e^(2*x) + 1)^(1/2*e^(-x))*2^(1/2*e^x)*e^(1/2*x*e^x)*log(2*e^x/(e^(2*x) + 1)) + (2*e^(2*x) - e^(4*x) - 1)*(e^(2*x) + 1)^(1/2*e^(-x))*2^(1/2*e^x)*e^(1/2*x*e^x))*e^(-1/2*x*e^(-x))/((e^(3*x) + e^x)*(e^(2*x) + 1)^(1/2*e^x)*2^(1/2*e^(-x))) == 1/2*(2*(2*e^(2*x) + e^(4*x) + 1)*e^(x^(-1/2*e^(-x) + 1/2*e^x))*log(2*e^x/(e^(2*x) + 1)) + (2*e^(2*x) - e^(4*x) - 1)*e^(2*x^(-1/2*e^(-x) + 1/2*e^x)) + 2*e^(2*x) - e^(4*x) - 1)/((e^(3*x) + e^x)*e^(2*x^(-1/2*e^(-x) + 1/2*e^x)) + e^(3*x) + e^x)
sage: bool(eq)
False
sage: bool(eq)
ShuTue, 08 Feb 2011 10:02:57 -0600http://ask.sagemath.org/question/7931/libSingular Groebner basis computation time limithttp://ask.sagemath.org/question/10401/libsingular-groebner-basis-computation-time-limit/I would like to put a time limit on computation of Groebner basis in libSingular, but I have trouble finding out how to do that.
I know Singular command *groebner* takes a second argument, which would do exactly that, but I don't know how to pass it there from SAGE.
Is there a way to do that?blishkoThu, 01 Aug 2013 21:03:30 -0500http://ask.sagemath.org/question/10401/Sage in Virtualbox...how to turn off timeout?http://ask.sagemath.org/question/9742/sage-in-virtualboxhow-to-turn-off-timeout/The timeout issues I experienced on the public server seem to have followed me to the virtual machine. According to the documentation, timeout is turned off by default, so either something is turning it on, the silent errors I described earlier are unrelated, or something more complicated is happening. Given the limitations of the kiosk mode, how can I verify and change timeout settings? (Or do I just need to bite the bullet and switch to a distro that will play nice with my wireless card?) Again, thanks in advance... ZomulgustarFri, 25 Jan 2013 11:07:13 -0600http://ask.sagemath.org/question/9742/How can I add a timeout to a charpoly calculation?http://ask.sagemath.org/question/8219/how-can-i-add-a-timeout-to-a-charpoly-calculation/For some reason after a bunch of matrix charpoly calculations, charpoly hangs on me. I suppose it's some memory problem, but rather that fix that, I just want to put a timeout on the calculation and then restart it if it hangs.
The problem is I can't use the "alarm" solution given in the answer to [this question](http://ask.sagemath.org/question/369/any-way-to-timeout)
because sage.matrix.matrix_integer_dense.Matrix_integer_dense.charpoly doesn't catch the KeyboardInterrupt:
sage: M = random_matrix(ZZ,1000,1000)
sage: alarm(30)
sage: try:
....: P = M.charpoly()
....: except KeyboardInterrupt:
....: print "did not complete!"
....:
What is another approach I could use?Max FlanderMon, 11 Jul 2011 17:06:42 -0500http://ask.sagemath.org/question/8219/