Skip to content
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

hang on doctest of giac.groebner_basis but NOT on interactive sage #33161

Open
tornaria opened this issue Jan 13, 2022 · 9 comments
Open

hang on doctest of giac.groebner_basis but NOT on interactive sage #33161

tornaria opened this issue Jan 13, 2022 · 9 comments

Comments

@tornaria
Copy link
Contributor

Using 9.5.rc0 and system giac 1.7.0-45:

sage-9.5.rc0 -t --long --verbose --random-seed=207028792283788636028114220041760561940 src/sage/libs/giac/__init__.py
...
Trying (line 172):    from sage.libs.giac import groebner_basis as gb_giac
Expecting nothing
ok [0.00 s]
...
Trying (line 198):    P = PolynomialRing(QQ,5, 'x')
Expecting nothing
ok [0.00 s]
Trying (line 199):    I = ideal([P.random_element(3,7) for j in range(5)])
Expecting nothing
ok [0.00 s]
Trying (line 200):    B1 = gb_giac(I.gens(),1e-16) # long time (1s)
Expecting:
    ...

gets stuck forever here, only for this random seed.

I reduced the doctest down to this file test.py:

def test():
    """
    EXAMPLES::

        sage: from sage.libs.giac import groebner_basis as gb_giac
        sage: P.<x0,x1,x2,x3,x4> = PolynomialRing(QQ,5, 'x')
        sage: gens = [6*x0*x1*x2 + 6*x1*x2*x3 - 1/4*x0^2*x4 + 2*x0*x1*x4 + 1/2*x0*x2,
        ....:            1/4*x0^2*x2 + x1^2*x2 - x1*x2^2 + 1/2*x0*x2*x4 - 1/2*x2^2*x4 + 10*x4^3 + 2*x2*x4,
        ....:            5/2*x1^2*x2 - 4*x2^2*x3 - 2*x0*x3^2 - 5*x1*x2*x4,
        ....:            1/2*x0*x2*x3 - 12*x1*x2*x4 - x3^2*x4 + 1/3*x0*x4^2 + 7*x3*x4^2 + 4*x1,
        ....:            2/3*x0*x2^2 - x0^2*x3 - 2*x0*x3^2 + 1/18*x1*x4^2 + 3/8*x0^2 + 2*x3]
        sage: B1 = gb_giac(gens,1e-16)
        ...
    """
    return

Now:

$ sage-9.5.rc0 -t --verbose test.py
...
Trying (line 12):    B1 = gb_giac(gens,1e-16)
Expecting:
    ...

gets stuck forever and doesn't depend on the random seed.

However, running the same example interactively works:

$ sage-9.5.rc0
┌────────────────────────────────────────────────────────────────────┐
│ SageMath version 9.5.rc0, Release Date: 2022-01-09                 │
│ Using Python 3.10.1. Type "help()" for help.                       │
└────────────────────────────────────────────────────────────────────┘
┏━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━┓
┃ Warning: this is a prerelease version, and it may be unstable.     ┃
┗━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━┛
sage: from sage.libs.giac import groebner_basis as gb_giac
// Giac share root-directory:/usr/share/giac/
// Giac share root-directory:/usr/share/giac/
Added 0 synonyms
sage: P.<x0,x1,x2,x3,x4> = PolynomialRing(QQ,5, 'x')
sage: gens = [6*x0*x1*x2 + 6*x1*x2*x3 - 1/4*x0^2*x4 + 2*x0*x1*x4 + 1/2*x0*x2,
....:                1/4*x0^2*x2 + x1^2*x2 - x1*x2^2 + 1/2*x0*x2*x4 - 1/2*x2^2*x4 + 10*x4^3 + 2*x2*x4,
....:                5/2*x1^2*x2 - 4*x2^2*x3 - 2*x0*x3^2 - 5*x1*x2*x4,
....:                1/2*x0*x2*x3 - 12*x1*x2*x4 - x3^2*x4 + 1/3*x0*x4^2 + 7*x3*x4^2 + 4*x1,
....:                2/3*x0*x2^2 - x0^2*x3 - 2*x0*x3^2 + 1/18*x1*x4^2 + 3/8*x0^2 + 2*x3]
sage: B1 = gb_giac(gens,1e-16)
Running a probabilistic check for the reconstructed Groebner basis. If successful, error probability is less than 1e-16 and is estimated to be less than 10^-49. Use proba_epsilon:=0 to certify (this takes more time).
// Groebner basis computation time 0.728084 Memory 256.532M
sage: 

Similar results in a different box with 9.5.beta9 and giac 1.7.0-39.

CC: @antonio-rojas @collares

Component: doctest framework

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

@orlitzky
Copy link
Contributor

comment:1

This is a duplicate of #33050, but with more information.

@tornaria
Copy link
Contributor Author

comment:2

Replying to @orlitzky:

This is a duplicate of #33050, but with more information.

It certainly looks the same, I'm sorry I missed that.

However, what really confuses me is why running via doctests should be different than running interactively. Do you have any clue about that?

I did the small file with only one test because I thought maybe some giac setting was changed by a previous test, but that doesn't change anything. Is there perhaps a weird interaction between the way doctests are run and the way giac is run? Maybe some diagnostic information printed by giac only in particular cases.

@orlitzky
Copy link
Contributor

comment:3

It's very weird and I can reproduce it now. We hit a similar issue in #33092; see the discussion starting around comment 45. Does using sage -t --serial fix the problem?

@antonio-rojas
Copy link
Contributor

comment:4

Using --serial worked fine exactly once. Every subsequent run hangs even with --serial

@orlitzky
Copy link
Contributor

comment:5

Replying to @antonio-rojas:

Using --serial worked fine exactly once. Every subsequent run hangs even with --serial

lol so I'm not the only one that happened to? I thought I was losing my mind. I wasn't even going to comment about it.

@seblabbe
Copy link
Contributor

comment:6

I can't reproduce the problem with 9.5.rc0 with:

$ lsb_release -a
No LSB modules are available.
Distributor ID:	Ubuntu
Description:	Ubuntu 20.04.2 LTS
Release:	20.04
Codename:	focal
$ giac -v
// Using locale /usr/share/locale/
// fr_CA.UTF-8
// /usr/share/locale/
// giac
// UTF-8
// Maximum number of parallel threads 8
// (c) 2001, 2018 B. Parisse & others
1.5.0

@antonio-rojas
Copy link
Contributor

comment:7

Not sure if useful, but here is a backtrace

#0  0x00007f784b78986f in mpn_mod_1_unnorm (d=18444403110374801408, un=946, up=0x5583997d2fc0) at mpn/../mpn/generic/mod_1.c:173
#1  __gmpn_mod_1_fat (b=<optimized out>, n=<optimized out>, ap=0x5583997d2fc0) at mpn/../mpn/generic/mod_1.c:259
#2  __gmpn_mod_1_fat (ap=0x5583997d2fc0, n=<optimized out>, b=<optimized out>) at mpn/../mpn/generic/mod_1.c:232
#3  0x00007f784b78dcd8 in __gmpz_fdiv_ui (dividend=<optimized out>, divisor=536802781) at mpz/fdiv_ui.c:89
#4  0x00007f77e8235c30 in giac::modulo (a=..., b=<optimized out>) at /build/giac/src/giac-1.7.0/src/ifactor.cc:410
#5  0x00007f77e89dda2f in giac::chinrem<giac::tdeg_t14> (tmp=..., qmodval=536802781, Q=..., pmod=..., P=...)
    at /build/giac/src/giac-1.7.0/src/cocoa.cc:9199
#6  giac::chinrem<giac::tdeg_t14> (start=<optimized out>, tmp=..., qmod=536802781, Q=..., pmod=..., P=...)
    at /build/giac/src/giac-1.7.0/src/cocoa.cc:9305
#7  giac::in_mod_gbasis<giac::tdeg_t14>(giac::vectpoly8<giac::tdeg_t14>&, bool, bool, int&, giac::context const*, giac::gbasis_param_t, int) [clone .isra.0] (res=..., modularcheck=modularcheck@entry=false, zdata=zdata@entry=true, rur=@0x7fff29922308: 0, contextptr=contextptr@entry=0x558398296290, 
    gbasis_logz_age=<optimized out>, gbasis_par=..., gbasis_par=...) at /build/giac/src/giac-1.7.0/src/cocoa.cc:15847
#8  0x00007f77e842f269 in giac::mod_gbasis<giac::tdeg_t14> (gbasis_param=..., gbasis_param=..., zdata=true, contextptr=0x558398296290, 
    rur=@0x7fff29922308: 0, modularcheck=<optimized out>, res=...) at /build/giac/src/giac-1.7.0/src/cocoa.cc:16130
#9  giac::gbasis8 (v=..., order=..., newres=..., env=0x7fff29922360, modularalgo=<optimized out>, modularcheck=<optimized out>, rur=@0x7fff29922308: 0, 
    contextptr=0x558398296290, gbasis_param=...) at /build/giac/src/giac-1.7.0/src/cocoa.cc:17838
#10 0x00007f77e8000abd in giac::giac_gbasis (res=..., order_=..., env=0x7fff29922360, modularcheck=1, rur=@0x7fff29922308: 0, contextptr=0x558398296290, 
    gbasis_param=...) at /build/giac/src/giac-1.7.0/src/solve.cc:6165
#11 0x00007f77e8001154 in giac::gbasis (v=..., order=..., with_cocoa=<optimized out>, modular=1, env=0x7fff29922360, rur=@0x7fff29922308: 0, 
    contextptr=0x558398296290, gbasis_param=...) at /build/giac/src/giac-1.7.0/src/solve.cc:6303
#12 0x00007f77e800e595 in giac::_gbasis (args=..., contextptr=<optimized out>) at /build/giac/src/giac-1.7.0/src/solve.cc:7388
#13 0x00007f77e7edbc1a in giac::unary_function_eval::operator() (this=<optimized out>, arg=..., context_ptr=<optimized out>, this=<optimized out>, 
    arg=..., context_ptr=<optimized out>) at /build/giac/src/giac-1.7.0/src/unary.h:203
#14 0x00007f77e84caad9 in giac::unary_function_ptr::operator() (this=<optimized out>, arg=..., context_ptr=<optimized out>)
    at /build/giac/src/giac-1.7.0/src/unary.cc:39
--Type <RET> for more, q to quit, c to continue without paging--
#15 0x00007f77e859e7f7 in giac::gen::operator() (this=0x55839801fe30, i=..., progname=..., contextptr=0x558398296290)
    at /build/giac/src/giac-1.7.0/src/gen.cc:9748
#16 0x00007f77e85a04bd in giac::gen::operator() (this=<optimized out>, i=..., contextptr=<optimized out>) at /build/giac/src/giac-1.7.0/src/gen.cc:9607
#17 0x00007f77e92237aa in ?? () from /usr/lib/python3.10/site-packages/sage/libs/giac/giac.cpython-310-x86_64-linux-gnu.so
#18 0x00007f77e9211423 in ?? () from /usr/lib/python3.10/site-packages/sage/libs/giac/giac.cpython-310-x86_64-linux-gnu.so
#19 0x00007f784c7a47cb in _PyObject_MakeTpCall () from /usr/lib/libpython3.10.so.1.0
#20 0x00007f784c7b6389 in ?? () from /usr/lib/libpython3.10.so.1.0
#21 0x00007f784c703565 in ?? () from /usr/lib/libpython3.10.so.1.0
#22 0x00007f77e921d5e3 in ?? () from /usr/lib/python3.10/site-packages/sage/libs/giac/giac.cpython-310-x86_64-linux-gnu.so
#23 0x00007f77e91302a5 in ?? () from /usr/lib/python3.10/site-packages/sage/libs/giac/giac.cpython-310-x86_64-linux-gnu.so
#24 0x00007f784c7ab475 in ?? () from /usr/lib/libpython3.10.so.1.0
#25 0x00007f784c79aa9b in _PyEval_EvalFrameDefault () from /usr/lib/libpython3.10.so.1.0
#26 0x00007f784c7aa73c in _PyFunction_Vectorcall () from /usr/lib/libpython3.10.so.1.0
#27 0x00007f784c79d225 in _PyEval_EvalFrameDefault () from /usr/lib/libpython3.10.so.1.0
#28 0x00007f784c7aa73c in _PyFunction_Vectorcall () from /usr/lib/libpython3.10.so.1.0
#29 0x00007f784c79a769 in _PyEval_EvalFrameDefault () from /usr/lib/libpython3.10.so.1.0
#30 0x00007f784c799392 in ?? () from /usr/lib/libpython3.10.so.1.0
#31 0x00007f784c851c14 in PyEval_EvalCode () from /usr/lib/libpython3.10.so.1.0
#32 0x00007f784c859671 in ?? () from /usr/lib/libpython3.10.so.1.0
#33 0x00007f784c7aa940 in ?? () from /usr/lib/libpython3.10.so.1.0
#34 0x00007f784c79a769 in _PyEval_EvalFrameDefault () from /usr/lib/libpython3.10.so.1.0
#35 0x00007f784c7aa73c in _PyFunction_Vectorcall () from /usr/lib/libpython3.10.so.1.0
#36 0x00007f784c79aa9b in _PyEval_EvalFrameDefault () from /usr/lib/libpython3.10.so.1.0
#37 0x00007f784c7aa73c in _PyFunction_Vectorcall () from /usr/lib/libpython3.10.so.1.0
#38 0x00007f784c79aa9b in _PyEval_EvalFrameDefault () from /usr/lib/libpython3.10.so.1.0
[...]

@fchapoton
Copy link
Contributor

comment:8

bump to 9.6

@fchapoton fchapoton modified the milestones: sage-9.5, sage-9.6 Jan 29, 2022
@mkoeppe mkoeppe modified the milestones: sage-9.6, sage-9.7 May 3, 2022
@fchapoton
Copy link
Contributor

comment:11

Another instance with another random seed, timing out with sage 9.7.rc1:

sage -t --long --warn-long 59.5 --random-seed=14952671518664531990234514377169608802 src/sage/libs/giac/__init__.py

@mkoeppe mkoeppe modified the milestones: sage-9.7, sage-9.8 Sep 19, 2022
@mkoeppe mkoeppe removed this from the sage-9.8 milestone Jan 29, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

6 participants