ASKSAGE: Sage Q&A Forum - RSS feedhttps://ask.sagemath.org/questions/Q&A Forum for SageenCopyright Sage, 2010. Some rights reserved under creative commons license.Fri, 04 Jun 2021 19:14:07 +0200why using giac via libgiac crashes sagemath when giac crashes?https://ask.sagemath.org/question/57331/why-using-giac-via-libgiac-crashes-sagemath-when-giac-crashes/(I do not know if this is known issue or there is similar post about it)
I am testing solution given in [result-that-comes-with-warning-from-giac-integrator/](https://ask.sagemath.org/question/57312/result-that-comes-with-warning-from-giac-integrator/)
Which is to use giac integrator via libgiac vs. using what is called the text interface.
But on some integrals, this gives `sigfaul` and sagemath crashes. I am not able to even catch this using try block
Using version `9.3` on Linux with giac version `1.7`
Here is an example
sage: from sage.libs.giac import libgiac
// Giac share root-directory:/usr/share/giac/
// Giac share root-directory:/usr/share/giac/
Added 0 synonyms
sage: var('x')
x
sage: integrand=(x+(1+x)^(1/2))^(1/2)/(x^2+1)/(1+x)^(1/2)
sage: anti=libgiac.integrate(integrand,x).sage()
Segmentation fault (core dumped)
>
Compare to
sage: var('x')
x
sage: integrand=(x+(1+x)^(1/2))^(1/2)/(x^2+1)/(1+x)^(1/2)
sage: anti=integrate(integrand,x,algorithm="giac")
Giac crashed -- automatically restarting.
sage:
The difference is that sage does not crash here. And my script will continue running to the next integral.
Why does calling libgiac crashes sagemath itself (in the case when giac itself does crash) but not when using the text interface?
This makes this method not workable for me as is.
I suspect the reason is, when using libgic, it uses giac code which is linked statically into the sagemath image.
So when giac code core dumps, the whole sagemath process will core dump as well since it is all the same process.
But when using the text interface, sagemath will communicate with giac as separate process using some form of process to process communications. So when giac process core dumps, it does not affect sagemath process.
Any workaround so I can use libgiac but bypasses these giac crashes so my sagemath script does not itself crash?Fri, 28 May 2021 22:20:53 +0200https://ask.sagemath.org/question/57331/why-using-giac-via-libgiac-crashes-sagemath-when-giac-crashes/Answer by mwageringel for <p>(I do not know if this is known issue or there is similar post about it)</p>
<p>I am testing solution given in <a href="https://ask.sagemath.org/question/57312/result-that-comes-with-warning-from-giac-integrator/">result-that-comes-with-warning-from-giac-integrator/</a></p>
<p>Which is to use giac integrator via libgiac vs. using what is called the text interface. </p>
<p>But on some integrals, this gives <code>sigfaul</code> and sagemath crashes. I am not able to even catch this using try block</p>
<p>Using version <code>9.3</code> on Linux with giac version <code>1.7</code></p>
<p>Here is an example</p>
<pre><code>sage: from sage.libs.giac import libgiac
// Giac share root-directory:/usr/share/giac/
// Giac share root-directory:/usr/share/giac/
Added 0 synonyms
sage: var('x')
x
sage: integrand=(x+(1+x)^(1/2))^(1/2)/(x^2+1)/(1+x)^(1/2)
sage: anti=libgiac.integrate(integrand,x).sage()
Segmentation fault (core dumped)
>
</code></pre>
<p>Compare to </p>
<pre><code>sage: var('x')
x
sage: integrand=(x+(1+x)^(1/2))^(1/2)/(x^2+1)/(1+x)^(1/2)
sage: anti=integrate(integrand,x,algorithm="giac")
Giac crashed -- automatically restarting.
sage:
</code></pre>
<p>The difference is that sage does not crash here. And my script will continue running to the next integral.</p>
<p>Why does calling libgiac crashes sagemath itself (in the case when giac itself does crash) but not when using the text interface? </p>
<p>This makes this method not workable for me as is.</p>
<p>I suspect the reason is, when using libgic, it uses giac code which is linked statically into the sagemath image. </p>
<p>So when giac code core dumps, the whole sagemath process will core dump as well since it is all the same process. </p>
<p>But when using the text interface, sagemath will communicate with giac as separate process using some form of process to process communications. So when giac process core dumps, it does not affect sagemath process. </p>
<p>Any workaround so I can use libgiac but bypasses these giac crashes so my sagemath script does not itself crash?</p>
https://ask.sagemath.org/question/57331/why-using-giac-via-libgiac-crashes-sagemath-when-giac-crashes/?answer=57382#post-id-57382Yes, this looks like a bug and your explanation of the problem seems correct. It is not possible to recover from a crash. If you expect a computation to crash, the only way to deal with this is by starting Sage in a separate process. For example, you can call Sage externally in a loop from some script.
Or, internally in Sage, you can use the interface for parallel computations, which starts multiple processes of Sage in the background. This also has the advantage that you can run several integration problems in parallel and can set a timeout. Use it like this:
@parallel(ncpus=1)
def myintegrate(f, v):
from sage.libs.giac import libgiac
return libgiac.integrate(f, v).sage()
To run a computation in parallel, and thus in a different process, pass a list of arguments, of possibly several integration problems. The result is an iterator over (inputs, outputs) in arbitrary order. In this example, we only have one problem, so the lists have length one.
sage: integrand=(x+(1+x)^(1/2))^(1/2)/(x^2+1)/(1+x)^(1/2)
sage: results = list(myintegrate([(integrand, x)]))
sage: input, output = results[0]
If the process crashed or an exception was raised, then `output` is a `str` with some error message (this is not documented very well), otherwise it contains the result of the computation. So check the type of the output in order to test if the computation was successful:
sage: type(output) == str
True
sage: output
NO DATA
Mon, 31 May 2021 20:31:16 +0200https://ask.sagemath.org/question/57331/why-using-giac-via-libgiac-crashes-sagemath-when-giac-crashes/?answer=57382#post-id-57382Comment by mwageringel for <p>Yes, this looks like a bug and your explanation of the problem seems correct. It is not possible to recover from a crash. If you expect a computation to crash, the only way to deal with this is by starting Sage in a separate process. For example, you can call Sage externally in a loop from some script.</p>
<p>Or, internally in Sage, you can use the interface for parallel computations, which starts multiple processes of Sage in the background. This also has the advantage that you can run several integration problems in parallel and can set a timeout. Use it like this:</p>
<pre><code>@parallel(ncpus=1)
def myintegrate(f, v):
from sage.libs.giac import libgiac
return libgiac.integrate(f, v).sage()
</code></pre>
<p>To run a computation in parallel, and thus in a different process, pass a list of arguments, of possibly several integration problems. The result is an iterator over (inputs, outputs) in arbitrary order. In this example, we only have one problem, so the lists have length one.</p>
<pre><code>sage: integrand=(x+(1+x)^(1/2))^(1/2)/(x^2+1)/(1+x)^(1/2)
sage: results = list(myintegrate([(integrand, x)]))
sage: input, output = results[0]
</code></pre>
<p>If the process crashed or an exception was raised, then <code>output</code> is a <code>str</code> with some error message (this is not documented very well), otherwise it contains the result of the computation. So check the type of the output in order to test if the computation was successful:</p>
<pre><code>sage: type(output) == str
True
sage: output
NO DATA
</code></pre>
https://ask.sagemath.org/question/57331/why-using-giac-via-libgiac-crashes-sagemath-when-giac-crashes/?comment=57457#post-id-57457Even if Giac crashes and Sage does not, it is safer to restart Sage as well, just to be sure that no unclean internal state of the Pexpect interface is left.Fri, 04 Jun 2021 19:14:07 +0200https://ask.sagemath.org/question/57331/why-using-giac-via-libgiac-crashes-sagemath-when-giac-crashes/?comment=57457#post-id-57457Comment by Nasser for <p>Yes, this looks like a bug and your explanation of the problem seems correct. It is not possible to recover from a crash. If you expect a computation to crash, the only way to deal with this is by starting Sage in a separate process. For example, you can call Sage externally in a loop from some script.</p>
<p>Or, internally in Sage, you can use the interface for parallel computations, which starts multiple processes of Sage in the background. This also has the advantage that you can run several integration problems in parallel and can set a timeout. Use it like this:</p>
<pre><code>@parallel(ncpus=1)
def myintegrate(f, v):
from sage.libs.giac import libgiac
return libgiac.integrate(f, v).sage()
</code></pre>
<p>To run a computation in parallel, and thus in a different process, pass a list of arguments, of possibly several integration problems. The result is an iterator over (inputs, outputs) in arbitrary order. In this example, we only have one problem, so the lists have length one.</p>
<pre><code>sage: integrand=(x+(1+x)^(1/2))^(1/2)/(x^2+1)/(1+x)^(1/2)
sage: results = list(myintegrate([(integrand, x)]))
sage: input, output = results[0]
</code></pre>
<p>If the process crashed or an exception was raised, then <code>output</code> is a <code>str</code> with some error message (this is not documented very well), otherwise it contains the result of the computation. So check the type of the output in order to test if the computation was successful:</p>
<pre><code>sage: type(output) == str
True
sage: output
NO DATA
</code></pre>
https://ask.sagemath.org/question/57331/why-using-giac-via-libgiac-crashes-sagemath-when-giac-crashes/?comment=57388#post-id-57388Thanks for the info. There is suggestion/ticket here [https://ask.sagemath.org/question/57312/result-that-comes-with-warning-from-giac-integrator/](https://ask.sagemath.org/question/57312/result-that-comes-with-warning-from-giac-integrator/) to make calling libgiac the default in some future version of sagemath instead of the text interface. But then if this going to cause sagemath to also crash, may be something should be done before this change. Using parallel sagemath to bypass this might be something not practical for most people to do on normal basis.Tue, 01 Jun 2021 02:18:15 +0200https://ask.sagemath.org/question/57331/why-using-giac-via-libgiac-crashes-sagemath-when-giac-crashes/?comment=57388#post-id-57388Comment by mwageringel for <p>Yes, this looks like a bug and your explanation of the problem seems correct. It is not possible to recover from a crash. If you expect a computation to crash, the only way to deal with this is by starting Sage in a separate process. For example, you can call Sage externally in a loop from some script.</p>
<p>Or, internally in Sage, you can use the interface for parallel computations, which starts multiple processes of Sage in the background. This also has the advantage that you can run several integration problems in parallel and can set a timeout. Use it like this:</p>
<pre><code>@parallel(ncpus=1)
def myintegrate(f, v):
from sage.libs.giac import libgiac
return libgiac.integrate(f, v).sage()
</code></pre>
<p>To run a computation in parallel, and thus in a different process, pass a list of arguments, of possibly several integration problems. The result is an iterator over (inputs, outputs) in arbitrary order. In this example, we only have one problem, so the lists have length one.</p>
<pre><code>sage: integrand=(x+(1+x)^(1/2))^(1/2)/(x^2+1)/(1+x)^(1/2)
sage: results = list(myintegrate([(integrand, x)]))
sage: input, output = results[0]
</code></pre>
<p>If the process crashed or an exception was raised, then <code>output</code> is a <code>str</code> with some error message (this is not documented very well), otherwise it contains the result of the computation. So check the type of the output in order to test if the computation was successful:</p>
<pre><code>sage: type(output) == str
True
sage: output
NO DATA
</code></pre>
https://ask.sagemath.org/question/57331/why-using-giac-via-libgiac-crashes-sagemath-when-giac-crashes/?comment=57384#post-id-57384This bug is now tracked at https://trac.sagemath.org/ticket/31887.Mon, 31 May 2021 21:36:18 +0200https://ask.sagemath.org/question/57331/why-using-giac-via-libgiac-crashes-sagemath-when-giac-crashes/?comment=57384#post-id-57384