Ask Your Question
2

why using giac via libgiac crashes sagemath when giac crashes?

asked 2021-05-28 22:20:53 +0100

Nasser gravatar image

updated 2021-05-29 02:45:14 +0100

(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/

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?

edit retag flag offensive close merge delete

1 Answer

Sort by ยป oldest newest most voted
3

answered 2021-05-31 20:31:16 +0100

mwageringel gravatar image

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.

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
edit flag offensive delete link more

Comments

This bug is now tracked at https://trac.sagemath.org/ticket/31887.

mwageringel gravatar imagemwageringel ( 2021-05-31 21:36:18 +0100 )edit

Thanks for the info. There is suggestion/ticket here 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.

Nasser gravatar imageNasser ( 2021-06-01 02:18:15 +0100 )edit

Even 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.

mwageringel gravatar imagemwageringel ( 2021-06-04 19:14:07 +0100 )edit

Your Answer

Please start posting anonymously - your entry will be published after you log in or create a new account.

Add Answer

Question Tools

1 follower

Stats

Asked: 2021-05-28 22:20:53 +0100

Seen: 548 times

Last updated: May 31 '21