cschwan / sage-on-gentoo

(Unofficial) Gentoo Overlay for Sage- and Sage-related ebuilds
84 stars 26 forks source link

doctest sageinspect.py fails on a new install of sage-9999 (sage-9.3.beta9) #629

Closed strogdon closed 2 years ago

strogdon commented 3 years ago

I have the rather lengthy failure:

sage -t --long --warn-long 76.0 --random-seed=0 /usr/lib/python3.9/site-packages/sage/misc/sageinspect.py
**********************************************************************
File "/usr/lib/python3.9/site-packages/sage/misc/sageinspect.py", line 2102, in sage.misc.sageinspect._sage_getsourcelines_name_with_dot
Failed example:
    cython('''
    class A:
        def __init__(self):
            "some init doc"
            pass
    class B:
        "some class doc"
        class A(A):
            pass
    ''')
Exception raised:
    Traceback (most recent call last):
      File "/usr/lib/python3.9/site-packages/sage/doctest/forker.py", line 714, in _run
        self.compile_and_execute(example, compiler, test.globs)
      File "/usr/lib/python3.9/site-packages/sage/doctest/forker.py", line 1133, in compile_and_execute
        exec(compiled, globs)
      File "<doctest sage.misc.sageinspect._sage_getsourcelines_name_with_dot[3]>", line 1, in <module>
        cython('''
      File "sage/misc/lazy_import.pyx", line 360, in sage.misc.lazy_import.LazyImport.__call__ (/var/tmp/portage/sci-mathematics/sage-9999/work/sage-9999/src-python3_9/build/cythonized/sage/misc/lazy_import.c:4036)
        return self.get_object()(*args, **kwds)
      File "/usr/lib/python3.9/site-packages/sage/misc/cython.py", line 659, in cython_compile
        return cython_import_all(tmpfile, get_globals(), **kwds)
      File "/usr/lib/python3.9/site-packages/sage/misc/cython.py", line 549, in cython_import_all
        m = cython_import(filename, **kwds)
      File "/usr/lib/python3.9/site-packages/sage/misc/cython.py", line 529, in cython_import
        return builtins.__import__(name)
    ModuleNotFoundError: No module named '_home_steven__sage_temp_hp_probook_29214_tmp_ivnug8nt_pyx_0'
**********************************************************************
File "/usr/lib/python3.9/site-packages/sage/misc/sageinspect.py", line 2112, in sage.misc.sageinspect._sage_getsourcelines_name_with_dot
Failed example:
    B.A.__name__
Exception raised:
    Traceback (most recent call last):
      File "/usr/lib/python3.9/site-packages/sage/doctest/forker.py", line 714, in _run
        self.compile_and_execute(example, compiler, test.globs)
      File "/usr/lib/python3.9/site-packages/sage/doctest/forker.py", line 1133, in compile_and_execute
        exec(compiled, globs)
      File "<doctest sage.misc.sageinspect._sage_getsourcelines_name_with_dot[4]>", line 1, in <module>
        B.A.__name__
    NameError: name 'B' is not defined
**********************************************************************
File "/usr/lib/python3.9/site-packages/sage/misc/sageinspect.py", line 2114, in sage.misc.sageinspect._sage_getsourcelines_name_with_dot
Failed example:
    B.A.__qualname__
Exception raised:
    Traceback (most recent call last):
      File "/usr/lib/python3.9/site-packages/sage/doctest/forker.py", line 714, in _run
        self.compile_and_execute(example, compiler, test.globs)
      File "/usr/lib/python3.9/site-packages/sage/doctest/forker.py", line 1133, in compile_and_execute
        exec(compiled, globs)
      File "<doctest sage.misc.sageinspect._sage_getsourcelines_name_with_dot[5]>", line 1, in <module>
        B.A.__qualname__
    NameError: name 'B' is not defined
**********************************************************************
File "/usr/lib/python3.9/site-packages/sage/misc/sageinspect.py", line 2116, in sage.misc.sageinspect._sage_getsourcelines_name_with_dot
Failed example:
    sage_getsource(B.A)
Exception raised:
    Traceback (most recent call last):
      File "/usr/lib/python3.9/site-packages/sage/doctest/forker.py", line 714, in _run
        self.compile_and_execute(example, compiler, test.globs)
      File "/usr/lib/python3.9/site-packages/sage/doctest/forker.py", line 1133, in compile_and_execute
        exec(compiled, globs)
      File "<doctest sage.misc.sageinspect._sage_getsourcelines_name_with_dot[6]>", line 1, in <module>
        sage_getsource(B.A)
    NameError: name 'B' is not defined
**********************************************************************
File "/usr/lib/python3.9/site-packages/sage/misc/sageinspect.py", line 2251, in sage.misc.sageinspect.sage_getsourcelines
Failed example:
    cython('''cpdef test_funct(x,y): return''')
Exception raised:
    Traceback (most recent call last):
      File "/usr/lib/python3.9/site-packages/sage/doctest/forker.py", line 714, in _run
        self.compile_and_execute(example, compiler, test.globs)
      File "/usr/lib/python3.9/site-packages/sage/doctest/forker.py", line 1133, in compile_and_execute
        exec(compiled, globs)
      File "<doctest sage.misc.sageinspect.sage_getsourcelines[6]>", line 1, in <module>
        cython('''cpdef test_funct(x,y): return''')
      File "sage/misc/lazy_import.pyx", line 360, in sage.misc.lazy_import.LazyImport.__call__ (/var/tmp/portage/sci-mathematics/sage-9999/work/sage-9999/src-python3_9/build/cythonized/sage/misc/lazy_import.c:4036)
        return self.get_object()(*args, **kwds)
      File "/usr/lib/python3.9/site-packages/sage/misc/cython.py", line 659, in cython_compile
        return cython_import_all(tmpfile, get_globals(), **kwds)
      File "/usr/lib/python3.9/site-packages/sage/misc/cython.py", line 549, in cython_import_all
        m = cython_import(filename, **kwds)
      File "/usr/lib/python3.9/site-packages/sage/misc/cython.py", line 529, in cython_import
        return builtins.__import__(name)
    ModuleNotFoundError: No module named '_home_steven__sage_temp_hp_probook_29214_tmp_80behubn_pyx_0'
**********************************************************************
File "/usr/lib/python3.9/site-packages/sage/misc/sageinspect.py", line 2252, in sage.misc.sageinspect.sage_getsourcelines
Failed example:
    sage_getsourcelines(test_funct)
Exception raised:
    Traceback (most recent call last):
      File "/usr/lib/python3.9/site-packages/sage/doctest/forker.py", line 714, in _run
        self.compile_and_execute(example, compiler, test.globs)
      File "/usr/lib/python3.9/site-packages/sage/doctest/forker.py", line 1133, in compile_and_execute
        exec(compiled, globs)
      File "<doctest sage.misc.sageinspect.sage_getsourcelines[7]>", line 1, in <module>
        sage_getsourcelines(test_funct)
    NameError: name 'test_funct' is not defined
**********************************************************************
2 items had failures:
   4 of   8 in sage.misc.sageinspect._sage_getsourcelines_name_with_dot
   2 of  31 in sage.misc.sageinspect.sage_getsourcelines
    [341 tests, 6 failures, 5.91 s]
----------------------------------------------------------------------
sage -t --long --warn-long 76.0 --random-seed=0 /usr/lib/python3.9/site-packages/sage/misc/sageinspect.py  # 6 doctests failed
----------------------------------------------------------------------
Total time for all tests: 6.2 seconds
    cpu time: 3.3 seconds
    cumulative wall time: 5.9 seconds
Running doctests with ID 2021-03-18-14-16-07-b071192d.
Using --optional=dochtml,memlimit,sage
Doctesting 1 file.

Since this is a new install from scratch something could be missing.

kiwifb commented 3 years ago

What the heck is this supposed to be

ModuleNotFoundError: No module named '_home_steven__sage_temp_hp_probook_29214_tmp_ivnug8nt_pyx_0'

I am assuming it is taken from from a sage temporary path in your personal home. And that your machine is called "hp probook". This is a cython call so it is probably trying to compile something there, but those _ are probably a wrong substitution.

strogdon commented 3 years ago

So, the folder up to hp_probook exists where _ -> / and __ ->/. but that folder is empty. I will try from the sage prompt.

kiwifb commented 3 years ago

Yes, after hp_probook, that would be random string named folders or files that get cleaned up when sage shuts down.

strogdon commented 3 years ago

From the sage prompt:

sage: cython('''
....: class A:
....:     def __init__(self):
....:         "some init doc"
....:         pass
....: class B:
....:     "some class doc"
....:     class A(A):
....:         pass
....: ''')
---------------------------------------------------------------------------
ModuleNotFoundError                       Traceback (most recent call last)
<ipython-input-1-8e3b671afc30> in <module>
----> 1 cython('''
      2 class A:
      3     def __init__(self):
      4         "some init doc"
      5         pass

/usr/lib/python3.9/site-packages/sage/misc/lazy_import.pyx in sage.misc.lazy_import.LazyImpo
    358             True
    359         """
--> 360         return self.get_object()(*args, **kwds)
    361 
    362     def __repr__(self):

/usr/lib/python3.9/site-packages/sage/misc/cython.py in cython_compile(code, **kwds)
    657     with open(tmpfile, 'w') as f:
    658         f.write(code)
--> 659     return cython_import_all(tmpfile, get_globals(), **kwds)
    660 
    661 

/usr/lib/python3.9/site-packages/sage/misc/cython.py in cython_import_all(filename, globals,
    547       code
    548     """
--> 549     m = cython_import(filename, **kwds)
    550     for k, x in m.__dict__.items():
    551         if k[0] != '_':

/usr/lib/python3.9/site-packages/sage/misc/cython.py in cython_import(filename, **kwds)
    527     try:
    528         sys.path.append(build_dir)
--> 529         return builtins.__import__(name)
    530     finally:
    531         sys.path = oldpath

ModuleNotFoundError: No module named '_home_steven__sage_temp_hp_probook_6078_tmp_b3nfqdcz_p
strogdon commented 3 years ago

The incomplete line should be

/usr/lib/python3.9/site-packages/sage/misc/lazy_import.pyx in sage.misc.lazy_import.LazyImport.__call__ (/var/tmp/portage/sci-mathematics/sage-9999/work/sage-9999/src-python3_9/build/cythonized/sage/misc/lazy_import.c:4036)()
strogdon commented 3 years ago

Using --verbose in the doctest

Trying (line 2102):    cython('''
    class A:
        def __init__(self):
            "some init doc"
            pass
    class B:
        "some class doc"
        class A(A):
            pass
    ''')
Expecting nothing
**********************************************************************
File "/usr/lib/python3.9/site-packages/sage/misc/sageinspect.py", line 2102, in sage.misc.sageinspect._sage_getsourcelines_name_with_dot
Failed example:
    cython('''
    class A:
        def __init__(self):
            "some init doc"
            pass
    class B:
        "some class doc"
        class A(A):
            pass
    ''')
Exception raised:
    Traceback (most recent call last):
      File "/usr/lib/python3.9/site-packages/sage/doctest/forker.py", line 714, in _run
        self.compile_and_execute(example, compiler, test.globs)
      File "/usr/lib/python3.9/site-packages/sage/doctest/forker.py", line 1133, in compile_and_execute
        exec(compiled, globs)
      File "<doctest sage.misc.sageinspect._sage_getsourcelines_name_with_dot[3]>", line 1, in <module>
        cython('''
      File "sage/misc/lazy_import.pyx", line 360, in sage.misc.lazy_import.LazyImport.__call__ (/var/tmp/portage/sci-mathematics/sage-9999/work/sage-9999/src-python3_9/build/cythonized/sage/misc/lazy_import.c:4036)
        return self.get_object()(*args, **kwds)
      File "/usr/lib/python3.9/site-packages/sage/misc/cython.py", line 659, in cython_compile
        return cython_import_all(tmpfile, get_globals(), **kwds)
      File "/usr/lib/python3.9/site-packages/sage/misc/cython.py", line 549, in cython_import_all
        m = cython_import(filename, **kwds)
      File "/usr/lib/python3.9/site-packages/sage/misc/cython.py", line 529, in cython_import
        return builtins.__import__(name)
    ModuleNotFoundError: No module named '_home_steven__sage_temp_hp_probook_6241_tmp_y5w8993i_pyx_0'
strogdon commented 3 years ago

On vanilla (9.3.beta9) I see (different gentoo machine):

sage: cython(''' 
....: class A: 
....:     def __init__(self): 
....:         "some init doc" 
....:         pass 
....: class B: 
....:     "some class doc" 
....:     class A(A): 
....:         pass 
....: ''')                                                                                                                                                                                                                                   
/usr/lib/gcc/x86_64-pc-linux-gnu/10.2.0/../../../../x86_64-pc-linux-gnu/bin/ld: skipping incompatible ///usr/lib/libm.so when searching for -lm
/usr/lib/gcc/x86_64-pc-linux-gnu/10.2.0/../../../../x86_64-pc-linux-gnu/bin/ld: skipping incompatible ///usr/lib/libm.a when searching for -lm
/usr/lib/gcc/x86_64-pc-linux-gnu/10.2.0/../../../../x86_64-pc-linux-gnu/bin/ld: skipping incompatible ///usr/lib/libpthread.so when searching for -lpthread
/usr/lib/gcc/x86_64-pc-linux-gnu/10.2.0/../../../../x86_64-pc-linux-gnu/bin/ld: skipping incompatible ///usr/lib/libpthread.a when searching for -lpthread
/usr/lib/gcc/x86_64-pc-linux-gnu/10.2.0/../../../../x86_64-pc-linux-gnu/bin/ld: skipping incompatible ///usr/lib/libc.so when searching for -lc
/usr/lib/gcc/x86_64-pc-linux-gnu/10.2.0/../../../../x86_64-pc-linux-gnu/bin/ld: skipping incompatible ///usr/lib/libc.a when searching for -lc

Perhaps Gentoo gcc-10 issue? But you don't have any problem.

kiwifb commented 3 years ago

Do you have a multilib (both 64 and 32bits) enabled? This looks like hardcoded 32bit library path being searched first.

strogdon commented 3 years ago

I do have multilib enabled for gcc and glibc, thought not explicitly enabled except from perhaps my default profile. I just noticed this and have not previously had a problem. I should probably use -multilib. On vanilla 9.3.beta7 the sageinspect.py passed, but was probably built with gcc-9. I did not test vanilla 9.3.beta8.

kiwifb commented 3 years ago

On vanilla I am expecting multilib install to be probed when using cython, but not in sage-on-gentoo because of https://github.com/cschwan/sage-on-gentoo/blob/master/sci-mathematics/sage/sage-9999.ebuild#L199 and later. I talked to Matthias Koeppe about it during sage days so that will probably get fixed but not before 9.4 I would think.

strogdon commented 3 years ago

Is it possible that this issue is mulitilb-related? I doctested sageinspect.py (9.3.beta9) on prefix without an issue. It is curious that cython seems to be forefront.

kiwifb commented 3 years ago

That section is related to https://trac.sagemath.org/ticket/16309 which I cannot pretend I quite understand so far.

strogdon commented 3 years ago

Both machines have multilib enabled only when building gcc and glibc.

machine 1 (some components may be built with gcc-9, sage and cython built with gcc-10) $ uname -a Linux hp-envy 5.4.38-gentoo #7 SMP Sat Jan 16 21:46:51 MST 2021 x86_64 Intel(R) Core(TM) i7-7500U CPU @ 2.70GHz GenuineIntel GNU/Linux

sageinspect.py passes.

machine 2 (entirely built with gcc-10) $ uname -a Linux hp-probook 5.4.97-gentoo-x86_64 #16 SMP Mon Mar 15 21:41:09 MDT 2021 x86_64 AMD Ryzen 7 4700U with Radeon Graphics AuthenticAMD GNU/Linux

This is the machine where I have this issue.

strogdon commented 3 years ago

Some data points (testsuite for cython w/ py3.9 and gcc-10) machine 1

Doctest: cyfunction.inspect_isfunction ... FAIL
Doctest: cyfunction.inspect_isfunction ... FAIL
FAIL: inspect_isfunction (cyfunction)
FAIL: inspect_isfunction (cyfunction)
FAILED (failures=2, skipped=76)

machine 2

Doctest: cyfunction.inspect_isfunction ... FAIL
Doctest: cyfunction.inspect_isfunction ... FAIL
Doctest: reload_ext_module.test_reload ... FAIL
Doctest: reload_ext_module.test_reload ... FAIL
FAIL: inspect_isfunction (cyfunction)
FAIL: inspect_isfunction (cyfunction)
FAIL: test_reload (reload_ext_module)
FAIL: test_reload (reload_ext_module)
FAILED (failures=4, skipped=76)
strogdon commented 3 years ago

This works:

sage: from sage.misc.sageinspect import sage_getsource
sage: cython('''
....: class A:
....:     def __init__(self):
....:         "some init doc"
....:         pass
....: from sage.misc.nested_class import NestedClassMetaclass
....: class B:
....:     "some class doc"
....:     class A(A):
....:         pass
....: ''')
sage:
sage: B.A.__name__
'A'
sage: B.A.__qualname__
'B.A'
sage: sage_getsource(B.A)
'    class A(A):\n        pass\n\n'
sage:

which includes the line from sage.misc.nested_class import NestedClassMetaclass. That line was included here and deleted here as not being needed.

This is out of my league.

strogdon commented 3 years ago

The above does not resolve other issues in sageinspect.py.

strogdon commented 3 years ago

Well it obviously worked once (see above). But sometimes it will work and sometimes it will fail. Very strange. It may not be related the added line.

kiwifb commented 3 years ago

Well, it is out of my league too. Need to walk away from it for a little bit to think.

strogdon commented 3 years ago

A simple example:

sage: cython('''
....:     ''')
---------------------------------------------------------------------------
ModuleNotFoundError                       Traceback (most recent call last)
<ipython-input-1-ac456857e025> in <module>
----> 1 cython('''
      2     ''')

/usr/lib/python3.9/site-packages/sage/misc/lazy_import.pyx in sage.misc.lazy_import.LazyImport.__call__ (/var/tmp/portage/sci-mathematics/sage-9999/work/sage-9999/src-python3_9/build/cythonized/sage/misc/lazy_import.c:4036)()
    358             True
    359         """
--> 360         return self.get_object()(*args, **kwds)
    361 
    362     def __repr__(self):

/usr/lib/python3.9/site-packages/sage/misc/cython.py in cython_compile(code, **kwds)
    657     with open(tmpfile, 'w') as f:
    658         f.write(code)
--> 659     return cython_import_all(tmpfile, get_globals(), **kwds)
    660 
    661 

/usr/lib/python3.9/site-packages/sage/misc/cython.py in cython_import_all(filename, globals, **kwds)
    547       code
    548     """
--> 549     m = cython_import(filename, **kwds)
    550     for k, x in m.__dict__.items():
    551         if k[0] != '_':

/usr/lib/python3.9/site-packages/sage/misc/cython.py in cython_import(filename, **kwds)
    527     try:
    528         sys.path.append(build_dir)
--> 529         return builtins.__import__(name)
    530     finally:
    531         sys.path = oldpath

ModuleNotFoundError: No module named '_home_steven__sage_temp_hp_probook_16698_tmp_q1g_lxlm_pyx_0'

and

$ tree ~/.sage/temp/hp-probook/16698/
/home/steven/.sage/temp/hp-probook/16698/
├── ecl
├── spyx
│   └── _home_steven__sage_temp_hp_probook_16698_tmp_q1g_lxlm_pyx
│       ├── build
│       │   └── temp.linux-x86_64-3.9
│       │       └── home
│       │           └── steven
│       ├── _home_steven__sage_temp_hp_probook_16698_tmp_q1g_lxlm_pyx_0.c
│       ├── _home_steven__sage_temp_hp_probook_16698_tmp_q1g_lxlm_pyx_0.cpython-39-x86_64-linux-gnu.so
│       ├── _home_steven__sage_temp_hp_probook_16698_tmp_q1g_lxlm_pyx_0.err
│       ├── _home_steven__sage_temp_hp_probook_16698_tmp_q1g_lxlm_pyx_0.html
│       ├── _home_steven__sage_temp_hp_probook_16698_tmp_q1g_lxlm_pyx_0.lis
│       └── _home_steven__sage_temp_hp_probook_16698_tmp_q1g_lxlm_pyx_0.pyx
└── tmp_q1g_lxlm.pyx

So the module appears to be there but something is missing. Perhaps latency between read/write or path not set?

kiwifb commented 3 years ago

After sleeping on it a little bit I want to review the situation a bit. Are the following facts correct

  1. the problem only happens with a new freshly installed machine
  2. older machines do not exhibit the issue
strogdon commented 3 years ago

So far, I only see this on a new install of s-o-g on a freshly installed gentoo laptop. I don't see the issue on a recently installed prefix nor on an older installed gentoo.

kiwifb commented 3 years ago

I am musing that there is a runtime dependency that we are missing and that's why there are failures on the new machine. It may be something that only recently was an explicit dependency of something used by sage but not anymore.

strogdon commented 3 years ago

I have been able to get the simple example I mentioned above to occasionally work. But so far it will not work twice in succession.

strogdon commented 3 years ago

This almost reminds me of something not being thread safe, i.e. the generation of the module is done on one thread and the loading of that module on another thread. And the treads are not communicating.

kiwifb commented 3 years ago

An interesting observation. But I would expect other things to fail. I have trouble picturing something that would be uniquely affecting this doctest.

strogdon commented 3 years ago

I'm able to patch cython.py to see that the .pyx file is generated, it is cythonized to create the .so file, the .so file is present on my system and still it fails to load. I'm able to manually load it after things fail. And occasionally there is no failure, i.e. the module can be found and loaded. Are you aware of a hardware issue that could be a contribution? It is a new laptop/processor.

kiwifb commented 3 years ago

Hum, that would be a very tricky hardware problem. With all those symptoms I can only think of some kind of race conditions in the file system, so possibly hard drive which I am assuming is solid state. If it was that, an interesting check would be to run the test suite with a different DOT_SAGE, possibly pointing it to somewhere on /dev/shm.

strogdon commented 3 years ago

Same failure if I write to /dev/shm.

strogdon commented 3 years ago

Another data point. This always works

sage: cython('''
....: ''', create_local_so_file=True)

The module is written not only under ~/.sage/temp/ but also in the local folder. The name of the module is much shorter than when create_local_so_file=False. So maybe a parsing problem?

kiwifb commented 3 years ago

Parsing feels definitely part of the problem. I mentioned it earlier. I just pushed 9.3.rc0 I doubt there is anything in there that would fix the issue but it needs to be tried.

strogdon commented 3 years ago

Stll present with 9.3.rc0.

strogdon commented 3 years ago

I installed vanilla on the offending laptop and I have the same issue (the ld stuff is because of my gcc)

sage: cython(''' 
....: ''')                                                                                                                                                                                                                                   
/usr/lib/gcc/x86_64-pc-linux-gnu/10.2.0/../../../../x86_64-pc-linux-gnu/bin/ld: skipping incompatible ///usr/lib/libm.so when searching for -lm
/usr/lib/gcc/x86_64-pc-linux-gnu/10.2.0/../../../../x86_64-pc-linux-gnu/bin/ld: skipping incompatible ///usr/lib/libm.a when searching for -lm
/usr/lib/gcc/x86_64-pc-linux-gnu/10.2.0/../../../../x86_64-pc-linux-gnu/bin/ld: skipping incompatible ///usr/lib/libpthread.so when searching for -lpthread
/usr/lib/gcc/x86_64-pc-linux-gnu/10.2.0/../../../../x86_64-pc-linux-gnu/bin/ld: skipping incompatible ///usr/lib/libpthread.a when searching for -lpthread
/usr/lib/gcc/x86_64-pc-linux-gnu/10.2.0/../../../../x86_64-pc-linux-gnu/bin/ld: skipping incompatible ///usr/lib/libc.so when searching for -lc
/usr/lib/gcc/x86_64-pc-linux-gnu/10.2.0/../../../../x86_64-pc-linux-gnu/bin/ld: skipping incompatible ///usr/lib/libc.a when searching for -lc
---------------------------------------------------------------------------
ModuleNotFoundError                       Traceback (most recent call last)
<ipython-input-1-e3fd0203ef75> in <module>
----> 1 cython('''
      2 ''')

/local/sage-git/sage/local/lib/python3.9/site-packages/sage/misc/lazy_import.pyx in sage.misc.lazy_import.LazyImport.__call__ (build/cythonized/sage/misc/lazy_import.c:4032)()
    358             True
    359         """
--> 360         return self.get_object()(*args, **kwds)
    361 
    362     def __repr__(self):

/local/sage-git/sage/local/lib/python3.9/site-packages/sage/misc/cython.py in cython_compile(code, **kwds)
    657     with open(tmpfile, 'w') as f:
    658         f.write(code)
--> 659     return cython_import_all(tmpfile, get_globals(), **kwds)
    660 
    661 

/local/sage-git/sage/local/lib/python3.9/site-packages/sage/misc/cython.py in cython_import_all(filename, globals, **kwds)
    547       code
    548     """
--> 549     m = cython_import(filename, **kwds)
    550     for k, x in m.__dict__.items():
    551         if k[0] != '_':

/local/sage-git/sage/local/lib/python3.9/site-packages/sage/misc/cython.py in cython_import(filename, **kwds)
    527     try:
    528         sys.path.append(build_dir)
--> 529         return builtins.__import__(name)
    530     finally:
    531         sys.path = oldpath

ModuleNotFoundError: No module named '_home_steven__sage_temp_hp_probook_5515_tmp_9qct6xma_pyx_0'

This usually works

sage: cython(''' 
....: ''', create_local_so_file=True)                                                                                                                                                                                                        
/usr/lib/gcc/x86_64-pc-linux-gnu/10.2.0/../../../../x86_64-pc-linux-gnu/bin/ld: skipping incompatible ///usr/lib/libm.so when searching for -lm
/usr/lib/gcc/x86_64-pc-linux-gnu/10.2.0/../../../../x86_64-pc-linux-gnu/bin/ld: skipping incompatible ///usr/lib/libm.a when searching for -lm
/usr/lib/gcc/x86_64-pc-linux-gnu/10.2.0/../../../../x86_64-pc-linux-gnu/bin/ld: skipping incompatible ///usr/lib/libpthread.so when searching for -lpthread
/usr/lib/gcc/x86_64-pc-linux-gnu/10.2.0/../../../../x86_64-pc-linux-gnu/bin/ld: skipping incompatible ///usr/lib/libpthread.a when searching for -lpthread
/usr/lib/gcc/x86_64-pc-linux-gnu/10.2.0/../../../../x86_64-pc-linux-gnu/bin/ld: skipping incompatible ///usr/lib/libc.so when searching for -lc
/usr/lib/gcc/x86_64-pc-linux-gnu/10.2.0/../../../../x86_64-pc-linux-gnu/bin/ld: skipping incompatible ///usr/lib/libc.a when searching for -lc
sage:

although if done enough times in a row it will fail.

sage: cython(''' 
....: ''', create_local_so_file=True)                                                                                                                                                                                                        
/usr/lib/gcc/x86_64-pc-linux-gnu/10.2.0/../../../../x86_64-pc-linux-gnu/bin/ld: skipping incompatible ///usr/lib/libm.so when searching for -lm
/usr/lib/gcc/x86_64-pc-linux-gnu/10.2.0/../../../../x86_64-pc-linux-gnu/bin/ld: skipping incompatible ///usr/lib/libm.a when searching for -lm
/usr/lib/gcc/x86_64-pc-linux-gnu/10.2.0/../../../../x86_64-pc-linux-gnu/bin/ld: skipping incompatible ///usr/lib/libpthread.so when searching for -lpthread
/usr/lib/gcc/x86_64-pc-linux-gnu/10.2.0/../../../../x86_64-pc-linux-gnu/bin/ld: skipping incompatible ///usr/lib/libpthread.a when searching for -lpthread
/usr/lib/gcc/x86_64-pc-linux-gnu/10.2.0/../../../../x86_64-pc-linux-gnu/bin/ld: skipping incompatible ///usr/lib/libc.so when searching for -lc
/usr/lib/gcc/x86_64-pc-linux-gnu/10.2.0/../../../../x86_64-pc-linux-gnu/bin/ld: skipping incompatible ///usr/lib/libc.a when searching for -lc
---------------------------------------------------------------------------
ModuleNotFoundError                       Traceback (most recent call last)
<ipython-input-8-9468c4ca8fdc> in <module>
----> 1 cython('''
      2 ''', create_local_so_file=True)

/local/sage-git/sage/local/lib/python3.9/site-packages/sage/misc/lazy_import.pyx in sage.misc.lazy_import.LazyImport.__call__ (build/cythonized/sage/misc/lazy_import.c:4032)()
    358             True
    359         """
--> 360         return self.get_object()(*args, **kwds)
    361 
    362     def __repr__(self):

/local/sage-git/sage/local/lib/python3.9/site-packages/sage/misc/cython.py in cython_compile(code, **kwds)
    657     with open(tmpfile, 'w') as f:
    658         f.write(code)
--> 659     return cython_import_all(tmpfile, get_globals(), **kwds)
    660 
    661 

/local/sage-git/sage/local/lib/python3.9/site-packages/sage/misc/cython.py in cython_import_all(filename, globals, **kwds)
    547       code
    548     """
--> 549     m = cython_import(filename, **kwds)
    550     for k, x in m.__dict__.items():
    551         if k[0] != '_':

/local/sage-git/sage/local/lib/python3.9/site-packages/sage/misc/cython.py in cython_import(filename, **kwds)
    527     try:
    528         sys.path.append(build_dir)
--> 529         return builtins.__import__(name)
    530     finally:
    531         sys.path = oldpath

ModuleNotFoundError: No module named 'tmp_mwggf0hd'
strogdon commented 3 years ago

Which vanilla components have to be rebuilt to allow for https://github.com/cschwan/sage-on-gentoo/blob/master/sci-mathematics/sage/sage-9999.ebuild#L199? Perhaps it's more complicated than just patching and rebuilding. I have tried make and ./sage -f sagelib after applying the sed change with no success. I'm trying to doctest vanilla without the results being cluttered with the ld warnings. As a last resort perhaps make distclean && make?

kiwifb commented 3 years ago

./sage -b after the change should be sufficient for a rebuild/re-install of a changed component. Thinking about it, there must be something more to get rid of those ld warnings from a vanilla sage. In fact, while it is necessary in sage-on-distros to have the sed (or equivalent) to avoid them, in vanilla that particular set of ld warnings may come from some other component with "polluted" -L flags. It is not just looking at /usr/lib but ///usr/lib which seems to imply it was /$A/$B/usr/lib and that coincidentally A and B are empty.

strogdon commented 3 years ago

Perhaps forget about this. A change to the patched file, cython.py should not really affect things, but the change appears in a cached function. And I didn't think about the -L flags.

strogdon commented 3 years ago

I have opened https://trac.sagemath.org/ticket/31626 for this issue since I see it with vanilla Sage. I removed the ld chatter warnings by fixing sage_conf.py as suggested here

strogdon commented 3 years ago

See trac ticket #28928 and sage-release comment. The comment relates to a, not specified, forking issue in Windows.

strogdon commented 3 years ago

A shot in the dark? I noticed from https://github.com/cschwan/sage-on-gentoo/issues/629#issuecomment-803407239 that the first item in the backtrace from lazy_import.pyx is

--> 360         return self.get_object()(*args, **kwds)

The get_object function from lazy_import.pyx reads

    cdef inline get_object(self):
        """
        Faster, Cython-only partially-inlined version of ``_get_object``.
        """
        if likely(self._object is not None):
            return self._object
        return self._get_object()

The likely construct/macro can be optimized in the kernel. Now on the machine where I have issues I have in my kernel config

┌────────────────────── General architecture-dependent options ───────────────────────┐
  │  Arrow keys navigate the menu.  <Enter> selects submenus ---> (or empty submenus    │  
  │  ----).  Highlighted letters are hotkeys.  Pressing <Y> includes, <N> excludes, <M> │  
  │  modularizes features.  Press <Esc><Esc> to exit, <?> for Help, </> for Search.     │  
  │  Legend: [*] built-in  [ ] excluded  <M> module  < > module capable                 │  
  │ ┌─────────────────────────────────────────────────────────────────────────────────┐ │  
  │ │     < > OProfile system profiling                                               │ │  
  │ │     [ ] Kprobes                                                                 │ │  
  │ │     [ ] Optimize very unlikely/likely branches                                  │ │  
  │ │     [*] Stack Protector buffer overflow detection                               │ │  
  │ │     [*]   Strong Stack Protector                                                │ │  
  │ │     [*] Use a virtually-mapped stack                                            │ │  
  │ │     [ ] Perform full reference count validation at the expense of speed         │ │  
  │ │     [ ] Locking event counts collection                                         │ │  
  │ │         GCOV-based kernel profiling  --->                                       │ │  
  │ │     [*] GCC plugins  --->

while on the machine with no issue I have Kprobes and unlikely/likely optimization built in. Is it possible that this is the issue?

strogdon commented 3 years ago

Rebuilding the kernel with Kprobes and unlikely/likely optimization and then (./sage -f sagelib && make) seemed to resolve things with vanilla

./sage -t src/sage/misc/cython.py 
Running doctests with ID 2021-04-12-14-38-18-4c565e5e.
Git branch: develop
Using --optional=build,dochtml,gentoo,pip,sage,sage_spkg
Doctesting 1 file.
sage -t --warn-long 95.4 --random-seed=0 src/sage/misc/cython.py
    [49 tests, 4.16 s]
----------------------------------------------------------------------
All tests passed!
strogdon commented 3 years ago

Doctested the wrong file! It should have been

./sage -t src/sage/misc/sageinspect.py

which still fails. I suspect the kernel changes only affect building the kernel.

kiwifb commented 3 years ago

OK, this is insane. I can see how this could be useful but I think it is completely insane that it would be needed at runtime. This is a kernel debugging and profiling infrastructure. You should be able to do without.

kiwifb commented 3 years ago

OK I miss your last email. It still fails.

strogdon commented 3 years ago

This hack fixes things here

diff --git a/src/sage/misc/cython.py b/src/sage/misc/cython.py
index e72c97f5c3..f77d7d956b 100644
--- a/src/sage/misc/cython.py
+++ b/src/sage/misc/cython.py
@@ -523,6 +523,8 @@ def cython_import(filename, **kwds):
     """
     name, build_dir = cython(filename, **kwds)

+    build_dir = build_dir + '/'
+
     oldpath = sys.path
     try:
         sys.path.append(build_dir)
$ sage -t /usr/lib/python3.9/site-packages/sage/misc/sageinspect.py 
Running doctests with ID 2021-04-23-20-47-33-49e98fe2.
Using --optional=dochtml,sage
Doctesting 1 file.
sage -t --warn-long 95.9 --random-seed=0 /usr/lib/python3.9/site-packages/sage/misc/sageinspect.py
    [340 tests, 113.15 s]
----------------------------------------------------------------------
All tests passed!
----------------------------------------------------------------------
Total time for all tests: 113.4 seconds
    cpu time: 110.8 seconds
    cumulative wall time: 113.1 seconds

See trac ticket.

kiwifb commented 3 years ago

The mind boggles. Something is either not behaving as expected or not used as it should. Cursory inspection of the code did not help. All I know is that the fix above is not windows safe.

strogdon commented 3 years ago

See https://trac.sagemath.org/ticket/31626#comment:8 for an update.

strogdon commented 3 years ago

No movement on https://trac.sagemath.org/ticket/31626. I think the resent proposal there is reasonable. There should NEVER be a ModuleNotFoundError. The proposal insures it will not occur. Perhaps s-o-g can do this? I patch here for each beta/rc so that cython code can be created from the sage prompt and sageinspect.py passes.

kiwifb commented 3 years ago

Yes, I can adopt that.

kiwifb commented 3 years ago

I am not sure I would care to much about any overhead. But either patch should get in soon.

strogdon commented 2 years ago

It only took a year but finally https://trac.sagemath.org/ticket/31626 has been resolved. The s-o-g patch for this issue will not be needed in the next beta (9.7.beta6).

kiwifb commented 2 years ago

I noticed, and it is merged in the vbraun branch.