FLINT memory errors do not crash Sage (:trac:`17629`)::
sage: t^(sys.maxsize//2)
Traceback (most recent call last):
...
RuntimeError: FLINT exception
Failed example:
G = f.galois_group(); G
Expected:
Transitive group number 5 of degree 4
Got:
Exception (FLINT memory_manager). Unable to allocate memory.
Transitive group number 5 of degree 4
The `f.galois_group()` command has nothing to do with this error, but something about it triggers the old output to be flushed.
How do we fix this? Note that patching FLINT is not ideal, since it won't help users who are using the system's version of the library. FLINT's most recent release was in 2015, so I don't know how much we can expect from upstream regarding new releases. So maybe the ideal solution would be to get Python to flush the output from these external libraries. I don't know how to do this; can anyone else help?
I'm also curious about what's causing the problem. Is it a bug in Python 3? If not, is this change in behavior documented anywhere? Why does it only appear on some platforms?
--
John
On Mon, Sep 9, 2019 at 7:51 PM John H Palmieri <jhpalm...@gmail.com> wrote:
> I am writing to ask for help fixing a Python 3 problem. On some platforms, there are Python 3 doctest failures in
>
> - libs/eclib/interface.py (#28454)
I believe that this has been fixed upstream, it has certainly been
reported by me. Are we using the latest eclib version?
> How do we fix this? Note that patching FLINT is not ideal, since it won't help users who are using the system's version of the library. FLINT's most recent release was in 2015, so I don't know how much we can expect from upstream regarding new releases. So maybe the ideal solution would be to get Python to flush the output from these external libraries. I don't know how to do this; can anyone else help?
Ideally, the upstream library should properly flush when producing
output. They should use fflush (in C) or std::endl or std::flush (in
C++).
I guess that Sage could also do the flushing whenever we return
from a library API call.
On Monday, September 9, 2019 at 2:06:21 PM UTC-7, Jeroen Demeyer wrote:On Mon, Sep 9, 2019 at 7:51 PM John H Palmieri <jhpalm...@gmail.com> wrote:
> I am writing to ask for help fixing a Python 3 problem. On some platforms, there are Python 3 doctest failures in
>
> - libs/eclib/interface.py (#28454)
I believe that this has been fixed upstream, it has certainly been
reported by me. Are we using the latest eclib version?John Cremona is part of the discussion at #28454, and I assume he knows the current state of eclib. I'll let him speak to this.
> How do we fix this? Note that patching FLINT is not ideal, since it won't help users who are using the system's version of the library. FLINT's most recent release was in 2015, so I don't know how much we can expect from upstream regarding new releases. So maybe the ideal solution would be to get Python to flush the output from these external libraries. I don't know how to do this; can anyone else help?
Ideally, the upstream library should properly flush when producing
output. They should use fflush (in C) or std::endl or std::flush (in
C++).I can confirm that patching flint to use fflush fixes the problem, and similarly for eclib. Patching is not ideal, though, since we are trying to move to better support libraries installed system-wide.I guess that Sage could also do the flushing whenever we return
from a library API call.Sounds okay to me, but I don't know how to do it. My impression is that `sys.stdout.flush()` just flushes Python output, not output coming from external libraries.
--
You received this message because you are subscribed to the Google Groups "sage-devel" group.
To unsubscribe from this group and stop receiving emails from it, send an email to sage-devel+...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/sage-devel/4df27a03-a625-47bb-ad4c-f2580f4b1298%40googlegroups.com.
On Mon, Sep 9, 2019 at 7:51 PM John H Palmieri <jhpalm...@gmail.com> wrote:
> I am writing to ask for help fixing a Python 3 problem. On some platforms, there are Python 3 doctest failures in
>
> - libs/eclib/interface.py (#28454)
I believe that this has been fixed upstream, it has certainly been
reported by me. Are we using the latest eclib version?
> How do we fix this? Note that patching FLINT is not ideal, since it won't help users who are using the system's version of the library. FLINT's most recent release was in 2015, so I don't know how much we can expect from upstream regarding new releases. So maybe the ideal solution would be to get Python to flush the output from these external libraries. I don't know how to do this; can anyone else help?
Ideally, the upstream library should properly flush when producing
output. They should use fflush (in C) or std::endl or std::flush (in
C++). I guess that Sage could also do the flushing whenever we return
from a library API call.
--
You received this message because you are subscribed to the Google Groups "sage-devel" group.
To unsubscribe from this group and stop receiving emails from it, send an email to sage-devel+...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/sage-devel/bc6e7a4a-c8a3-4511-94ec-718e0126b19e%40googlegroups.com.
To unsubscribe from this group and stop receiving emails from it, send an email to sage-...@googlegroups.com.
I found that and https://stackoverflow.com/questions/5081657/how-do-i-prevent-a-c-shared-library-to-print-on-stdout-in-python and maybe other related items, but I couldn't figure out how to use them to fix this particular problem. Others will know what they're doing more than I do regarding a Python/Cython interface to an external library, so others might have more luck.
To unsubscribe from this group and stop receiving emails from it, send an email to sage-devel+...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/sage-devel/73733782-6706-4839-a1ec-1477287dd112%40googlegroups.com.
That all looks very complicated. Before I fixed the eclib source code the previous method did work, namely to flush stdout and stderr from the c/python wrapper code after calling any library function (in some cases this is certainly redundant, but in the case of eclib it was very hard for anyone other than me to know which library functions might spit out some error or warning message). Somewhere in src/sage/libs/flint are the wrapper functions which need this.
FLINT memory errors do not crash Sage (:trac:`17629`)::
sage: t^(sys.maxsize//2)
Traceback (most recent call last):
...
RuntimeError: FLINT exception
and the "..." is supposed to capture "Exception (FLINT memory_manager). Unable to allocate memory." This text is what needs to be flushed, because otherwise it may not appear here, instead appearing in the output of some later doctest. So if we can add something at the end of the doctest, an analogue of
sage: sys.stdout.flush()
...
that could work and would not impact performance whenever FLINT is used.
--
John
On Wednesday, October 23, 2019 at 1:41:35 PM UTC-7, Nils Bruin wrote:On Wednesday, October 23, 2019 at 1:26:46 PM UTC-7, John Cremona wrote:That all looks very complicated. Before I fixed the eclib source code the previous method did work, namely to flush stdout and stderr from the c/python wrapper code after calling any library function (in some cases this is certainly redundant, but in the case of eclib it was very hard for anyone other than me to know which library functions might spit out some error or warning message). Somewhere in src/sage/libs/flint are the wrapper functions which need this.Given that fflush is a system call, it probably has quite a serious overhead. When the routine is meant to do I/O anyway, it's a fair price to pay, but just flushing on the odd chance that a warning was generated could very well be quite costly. For a low-level library like flint, that might be too high a price. I think you want to test for performance regression before working around lacking output flushes by flushing always.Is there a way to just flush output immediately after the relevant doctest? For the record, the doctest isFLINT memory errors do not crash Sage (:trac:`17629`):: sage: t^(sys.maxsize//2) Traceback (most recent call last): ... RuntimeError: FLINT exception
On Wednesday, October 23, 2019 at 2:47:54 PM UTC-7, John H Palmieri wrote:
On Wednesday, October 23, 2019 at 1:41:35 PM UTC-7, Nils Bruin wrote:On Wednesday, October 23, 2019 at 1:26:46 PM UTC-7, John Cremona wrote:That all looks very complicated. Before I fixed the eclib source code the previous method did work, namely to flush stdout and stderr from the c/python wrapper code after calling any library function (in some cases this is certainly redundant, but in the case of eclib it was very hard for anyone other than me to know which library functions might spit out some error or warning message). Somewhere in src/sage/libs/flint are the wrapper functions which need this.Given that fflush is a system call, it probably has quite a serious overhead. When the routine is meant to do I/O anyway, it's a fair price to pay, but just flushing on the odd chance that a warning was generated could very well be quite costly. For a low-level library like flint, that might be too high a price. I think you want to test for performance regression before working around lacking output flushes by flushing always.Is there a way to just flush output immediately after the relevant doctest? For the record, the doctest isFLINT memory errors do not crash Sage (:trac:`17629`):: sage: t^(sys.maxsize//2) Traceback (most recent call last): ... RuntimeError: FLINT exception
Wouldn't something liketry:t^(sys.maxsize//2)except:sys.stdout.flush()raisedo the trick, to ensure that the message gets flushed before the error gets raised?shouldn't a message like that occur on sys.stderr, though?
So maybe it should be on stderr, but it's not. Regarding sys.stdout.flush(), my understanding, as confirmed by my experience with this particular problem, is that this only flushes output coming from Python, not from external library calls.
I guess via ctypes it would be possible too.
On Thu, Oct 24, 2019 at 6:48 PM Nils Bruin <nbr...@sfu.ca> wrote:
>
> On Thursday, October 24, 2019 at 10:29:48 AM UTC-7, Nils Bruin wrote:
>>
>>
>> I guess via ctypes it would be possible too.
>
>
> Browsing the documentation, something like:
>
> libc=ctypes.cdll.LoadLibrary("libc.so.6")
> libc.fflush(0r)
>
> should work. And this should cause way less overhead than calling cython (because we don't have to call a c compiler). Problem here of course is how to make the "libc.so.6" cross-platform.
this is something that can be easily done at configure time, figuring
out the correct value for this string and putting it into
an environment variable.
> So perhaps the cython solution is better ...
>
> --
> You received this message because you are subscribed to the Google Groups "sage-devel" group.
> To unsubscribe from this group and stop receiving emails from it, send an email to sage-...@googlegroups.com.
I am thinking that having a cross-platform
sage_ctypes=ctypes.cdll.LoadLibrary("...")
mihgt be useful to have beyond 1 test...