sagemath / sage

Main repository of SageMath
https://www.sagemath.org
Other
1.44k stars 480 forks source link

giacpy_sage causes doctest failures due to threading #23976

Closed jdemeyer closed 7 years ago

jdemeyer commented 7 years ago

Sometimes, giacpy_sage doctests can run out of memory. This happens on systems with many cores because too many threads are started. Analogous to #23713, the number of threads should be limited by SAGE_NUM_THREADS.

// Groebner basis computation time 0.003507 Memory 0.296004M
sage: gb  # optional - giacpy_sage ## line 3485 ##
[c^3 - 79/210*c^2 + 1/30*b + 1/70*c, b^2 - 3/5*c^2 - 1/5*b + 1/5*c, b*c + 6/5*c^2 - 1/10*b - 2/5*c, a + 2*b + 2*c - 1]
sage: J.groebner_basis.set_cache(gb)  # optional - giacpy_sage ## line 3488 ##
sage: ideal(J.transformed_basis()).change_ring(P).interreduced_basis()  # testing trac 21884 ## line 3489 ##
[a - 60*c^3 + 158/7*c^2 + 8/7*c - 1, b + 30*c^3 - 79/7*c^2 + 3/7*c, c^4 - 10/21*c^3 + 1/84*c^2 + 1/84*c]
sage: A9=PolynomialRing(QQ,9,'x') # optional - giacpy_sage ## line 3495 ##
sage: I9=sage.rings.ideal.Katsura(A9) # optional - giacpy_sage ## line 3496 ##
sage: I9.groebner_basis("giac",proba_epsilon=1e-7) # optional - giacpy_sage, long time (3s) ## line 3497 ##
terminate called after throwing an instance of 'std::bad_alloc'
  what():  std::bad_alloc
terminate called recursively
------------------------------------------------------------------------
/home/jdemeyer/sage/local/lib/python2.7/site-packages/cysignals/signals.so(+0x58e8)[0x7fa1751f98e8]
/home/jdemeyer/sage/local/lib/python2.7/site-packages/cysignals/signals.so(+0x5955)[0x7fa1751f9955]
/home/jdemeyer/sage/local/lib/python2.7/site-packages/cysignals/signals.so(+0x8b56)[0x7fa1751fcb56]
/lib64/libpthread.so.0(+0x10e40)[0x7fa17a1b2e40]
/lib64/libc.so.6(gsignal+0x37)[0x7fa179730067]
/lib64/libc.so.6(abort+0x16a)[0x7fa1797314ba]
/usr/lib/gcc/x86_64-pc-linux-gnu/4.9.3/libstdc++.so.6(_ZN9__gnu_cxx27__verbose_terminate_handlerEv+0xfd)[0x7fa169ea25ad]
/usr/lib/gcc/x86_64-pc-linux-gnu/4.9.3/libstdc++.so.6(+0x79486)[0x7fa169ea0486]
/usr/lib/gcc/x86_64-pc-linux-gnu/4.9.3/libstdc++.so.6(+0x794d1)[0x7fa169ea04d1]
/usr/lib/gcc/x86_64-pc-linux-gnu/4.9.3/libstdc++.so.6(+0x796e8)[0x7fa169ea06e8]
/usr/lib/gcc/x86_64-pc-linux-gnu/4.9.3/libstdc++.so.6(+0x79c79)[0x7fa169ea0c79]
/home/jdemeyer/sage/local/lib/libgiac.so.0(_ZN4giac10in_zgbasisINS_8tdeg_t14EEEbRNS_11vectpolymodIT_EEjRSt6vectorIjSaIjEEibPS6_INS_5paireESaISA_EERS6_INS_7zinfo_tIS3_EESaISF_EEbbb+0x4ea)[0x7fa0f3fc23fa]
/home/jdemeyer/sage/local/lib/libgiac.so.0(_ZN4giac7zgbasisINS_8tdeg_t14EEEbRNS_9vectpoly8IT_EERNS_11vectpolymodIS3_EERSt6vectorIjSaIjEEibPS9_INS_5paireESaISD_EERS9_INS_7zinfo_tIS3_EESaISI_EEbbbb+0xf7)[0x7fa0f3fc5ff7]
/home/jdemeyer/sage/local/lib/libgiac.so.0(_ZN4giac13thread_gbasisINS_8tdeg_t14EEEPvS2_+0x3e)[0x7fa0f3fc606e]
/lib64/libpthread.so.0(+0x73d4)[0x7fa17a1a93d4]
/lib64/libc.so.6(clone+0x6d)[0x7fa1797e41ad]
------------------------------------------------------------------------
terminate called recursively

(default max thread, add a setitem method, take account of giac entries in pynac dict for translations from giacpy to sage)

CC: @frederichan-IMJPRG

Component: packages: optional

Author: Frederic Han

Branch/Commit: dda5551

Reviewer: Jeroen Demeyer

Issue created by migration from https://trac.sagemath.org/ticket/23976

jdemeyer commented 7 years ago

Author: Jeroen Demeyer

jdemeyer commented 7 years ago

Description changed:

--- 
+++ 
@@ -1 +1,35 @@
 Sometimes, `giacpy_sage` doctests can run out of memory. This happens on systems with many cores because too many threads are started. Analogous to #23713, the number of threads should be limited by `SAGE_NUM_THREADS`.
+
+```
+// Groebner basis computation time 0.003507 Memory 0.296004M
+sage: gb  # optional - giacpy_sage ## line 3485 ##
+[c^3 - 79/210*c^2 + 1/30*b + 1/70*c, b^2 - 3/5*c^2 - 1/5*b + 1/5*c, b*c + 6/5*c^2 - 1/10*b - 2/5*c, a + 2*b + 2*c - 1]
+sage: J.groebner_basis.set_cache(gb)  # optional - giacpy_sage ## line 3488 ##
+sage: ideal(J.transformed_basis()).change_ring(P).interreduced_basis()  # testing trac 21884 ## line 3489 ##
+[a - 60*c^3 + 158/7*c^2 + 8/7*c - 1, b + 30*c^3 - 79/7*c^2 + 3/7*c, c^4 - 10/21*c^3 + 1/84*c^2 + 1/84*c]
+sage: A9=PolynomialRing(QQ,9,'x') # optional - giacpy_sage ## line 3495 ##
+sage: I9=sage.rings.ideal.Katsura(A9) # optional - giacpy_sage ## line 3496 ##
+sage: I9.groebner_basis("giac",proba_epsilon=1e-7) # optional - giacpy_sage, long time (3s) ## line 3497 ##
+terminate called after throwing an instance of 'std::bad_alloc'
+  what():  std::bad_alloc
+terminate called recursively
+------------------------------------------------------------------------
+/home/jdemeyer/sage/local/lib/python2.7/site-packages/cysignals/signals.so(+0x58e8)[0x7fa1751f98e8]
+/home/jdemeyer/sage/local/lib/python2.7/site-packages/cysignals/signals.so(+0x5955)[0x7fa1751f9955]
+/home/jdemeyer/sage/local/lib/python2.7/site-packages/cysignals/signals.so(+0x8b56)[0x7fa1751fcb56]
+/lib64/libpthread.so.0(+0x10e40)[0x7fa17a1b2e40]
+/lib64/libc.so.6(gsignal+0x37)[0x7fa179730067]
+/lib64/libc.so.6(abort+0x16a)[0x7fa1797314ba]
+/usr/lib/gcc/x86_64-pc-linux-gnu/4.9.3/libstdc++.so.6(_ZN9__gnu_cxx27__verbose_terminate_handlerEv+0xfd)[0x7fa169ea25ad]
+/usr/lib/gcc/x86_64-pc-linux-gnu/4.9.3/libstdc++.so.6(+0x79486)[0x7fa169ea0486]
+/usr/lib/gcc/x86_64-pc-linux-gnu/4.9.3/libstdc++.so.6(+0x794d1)[0x7fa169ea04d1]
+/usr/lib/gcc/x86_64-pc-linux-gnu/4.9.3/libstdc++.so.6(+0x796e8)[0x7fa169ea06e8]
+/usr/lib/gcc/x86_64-pc-linux-gnu/4.9.3/libstdc++.so.6(+0x79c79)[0x7fa169ea0c79]
+/home/jdemeyer/sage/local/lib/libgiac.so.0(_ZN4giac10in_zgbasisINS_8tdeg_t14EEEbRNS_11vectpolymodIT_EEjRSt6vectorIjSaIjEEibPS6_INS_5paireESaISA_EERS6_INS_7zinfo_tIS3_EESaISF_EEbbb+0x4ea)[0x7fa0f3fc23fa]
+/home/jdemeyer/sage/local/lib/libgiac.so.0(_ZN4giac7zgbasisINS_8tdeg_t14EEEbRNS_9vectpoly8IT_EERNS_11vectpolymodIS3_EERSt6vectorIjSaIjEEibPS9_INS_5paireESaISD_EERS9_INS_7zinfo_tIS3_EESaISI_EEbbbb+0xf7)[0x7fa0f3fc5ff7]
+/home/jdemeyer/sage/local/lib/libgiac.so.0(_ZN4giac13thread_gbasisINS_8tdeg_t14EEEPvS2_+0x3e)[0x7fa0f3fc606e]
+/lib64/libpthread.so.0(+0x73d4)[0x7fa17a1a93d4]
+/lib64/libc.so.6(clone+0x6d)[0x7fa1797e41ad]
+------------------------------------------------------------------------
+terminate called recursively
+```
frederichan-IMJPRG commented 7 years ago

Commit: c2c8fd8

frederichan-IMJPRG commented 7 years ago
comment:2

So now the default giacsettings.threads is SAGE_NUM_THREADS or 1 if failed to import.

Some linear algebra tutorial is added in the libgiac doc and a _setitem_ function was added.

frederichan-IMJPRG commented 7 years ago

Branch: u/frederichan/giacpy_sage-0.6.6

frederichan-IMJPRG commented 7 years ago

Description changed:

--- 
+++ 
@@ -33,3 +33,9 @@
 ------------------------------------------------------------------------
 terminate called recursively

+ +updating giacpy_sage to 0.6.6 +http://webusers.imj-prg.fr/~frederic.han/xcas/giacpy/sage/giacpy_sage-0.6.6.tar.gz + +modifications details in git: +https://gitlab.math.univ-paris-diderot.fr/han/giacpy-sage

frederichan-IMJPRG commented 7 years ago

Description changed:

--- 
+++ 
@@ -34,8 +34,12 @@
 terminate called recursively

-updating giacpy_sage to 0.6.6 +--- + +* Updating giacpy_sage to 0.6.6 http://webusers.imj-prg.fr/~frederic.han/xcas/giacpy/sage/giacpy_sage-0.6.6.tar.gz

-modifications details in git: +* Modifications details in git: https://gitlab.math.univ-paris-diderot.fr/han/giacpy-sage + +(default max thread, add a setitem method, take account of giac entries in pynac dict for translations from giacpy to sage)

jdemeyer commented 7 years ago

Reviewer: Jeroen Demeyer

jdemeyer commented 7 years ago
comment:4

I planned to fix this in the Sage interface, but I guess your fix also works.

jdemeyer commented 7 years ago

Changed author from Jeroen Demeyer to Frederic Han

jdemeyer commented 7 years ago
comment:5

Why are you adding that extra doctest in Sage?

jdemeyer commented 7 years ago
comment:6

I tested the new version of giacpy_sage and it seems to work fine. So that leaves the question of the extra doctest...

frederichan-IMJPRG commented 7 years ago
comment:7

Replying to @jdemeyer:

Why are you adding that extra doctest in Sage?

Indeed, I though that the doctest was increasing the giacsettings.threads by two and was not restoring it back but it was not the case, I will remove this line.

7ed8c4ca-6d56-4ae9-953a-41e42b4ed313 commented 7 years ago

Changed commit from c2c8fd8 to dda5551

7ed8c4ca-6d56-4ae9-953a-41e42b4ed313 commented 7 years ago

Branch pushed to git repo; I updated commit sha1. New commits:

dda5551remove duplicate restoration of giacsetting.threads in doctest
vbraun commented 7 years ago

Changed branch from u/frederichan/giacpy_sage-0.6.6 to dda5551