increasing verbose level for sub-routines

83 views
Skip to first unread message

Daniel Krenn

unread,
Aug 9, 2016, 5:42:32 AM8/9/16
to sage-...@googlegroups.com
Say I have some function doing something:

sage: def f(M):
....: A = M # something will be done here
....: verbose('something', 1)
....: iA = A^(-1)
....: return iA

Setting the level of verbosity to 1 gives the output

sage: set_verbose(1)
sage: f(Matrix([[1, 2], [3, 4]]))
verbose 1 (f) something (time = -0.092)
verbose 1 (f) computing inverse of 2 x 2 matrix using FLINT
[ -2 1]
[ 3/2 -1/2]

How to repress the second verbose ("inverse...FLINT")?

Ideally there would be something that increases all verbosity levels of
the functions I call within f, so that the messages are still there when
calling f with level >= 2, but leaves level 1 for my high-level function.

Any ideas how to accomplish this (in a good way)?

Best

Daniel

Volker Braun

unread,
Aug 9, 2016, 1:08:38 PM8/9/16
to sage-devel
The only good way is to rip out the "verbose" thing and replace it with the Python logging module. Then its easy to have different loggers for your code and for the flint interface, and make them log in different levels and/or different output streams.

William Stein

unread,
Aug 9, 2016, 1:31:18 PM8/9/16
to sage-...@googlegroups.com


On Tuesday, August 9, 2016, Volker Braun <vbrau...@gmail.com> wrote:
The only good way is to rip out the "verbose" thing and replace it with the Python logging module. Then its easy to have different loggers for your code and for the flint interface, and make them log in different levels and/or different output streams.


You don't have rip out verbose and replace it.  Just switch to using the built in Python logging module for what you're doing.   We should also reimplement verbose on top of pythons built in logging module (probably just a few lines of code to do that).  I'm very surprised nobody has done this already.  
 



On Tuesday, August 9, 2016 at 11:42:32 AM UTC+2, Daniel Krenn wrote:
Say I have some function doing something:

sage: def f(M):
....:     A = M  # something will be done here
....:     verbose('something', 1)
....:     iA = A^(-1)
....:     return iA

Setting the level of verbosity to 1 gives the output

sage: set_verbose(1)
sage: f(Matrix([[1, 2], [3, 4]]))
verbose 1 (f) something (time = -0.092)
verbose 1 (f) computing inverse of 2 x 2 matrix using FLINT
[  -2    1]
[ 3/2 -1/2]

How to repress the second verbose ("inverse...FLINT")?

Ideally there would be something that increases all verbosity levels of
the functions I call within f, so that the messages are still there when
calling f with level >= 2, but leaves level 1 for my high-level function.

Any ideas how to accomplish this (in a good way)?

Best

Daniel

--
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+unsubscribe@googlegroups.com.
To post to this group, send email to sage-...@googlegroups.com.
Visit this group at https://groups.google.com/group/sage-devel.
For more options, visit https://groups.google.com/d/optout.


--
Sent from my massive iPhone 6 plus.

Daniel Krenn

unread,
Aug 26, 2016, 1:27:44 PM8/26/16
to sage-...@googlegroups.com
On 2016-08-09 19:31, William Stein wrote:
> The only good way is to rip out the "verbose" thing and replace it
> with the Python logging module. Then its easy to have different
> loggers for your code and for the flint interface, and make them log
> in different levels and/or different output streams.
>
> You don't have rip out verbose and replace it. Just switch to using
> the built in Python logging module for what you're doing. We should
> also reimplement verbose on top of pythons built in logging module
> (probably just a few lines of code to do that). I'm very surprised
> nobody has done this already.

I've started this at
https://trac.sagemath.org/ticket/21349

Daniel

David Loeffler

unread,
Aug 31, 2016, 9:07:44 AM8/31/16
to SAGE devel
I'm surprised at the apparent consensus that the only solution is to re-implement "verbose" by some totally different method. I came across this issue before and I found a perfectly acceptable fix, which I didn't bother to make a ticket for because I didn't know if anyone else cared about this issue until I saw this thread.

The current implementation of "verbose" controls which messages to show according to the name of the Python module containing the code; and it extracts the module name from the Python interpreter state. Unfortunately, this doesn't play well with Cython modules, so if verbose is called from Cython code, it ends up going back up the call stack until it finds a Python module. Because Sage's matrix algebra routines have lots of diagnostic messages built in (definitely a Good Thing), and they are almost all implemented in Cython, this often leads to a slew of unwanted messages about matrix arithmetic, as in Daniel's example.

The solution I found was simply to add an optional extra argument to "verbose", specifying a string to use in place of the auto-detected module name (extending a mechanism that's already there for the function name); and then to grep through the Cython files in the Sage library, adjusting a few dozen calls to "verbose" to give the module name explicitly each time. This worked perfectly.

I'd be happy to make a ticket for this, if others agree that it's preferable to reinventing the wheel.

David


Daniel

Daniel Krenn

unread,
Nov 24, 2016, 1:48:45 PM11/24/16
to sage-...@googlegroups.com
Dear all,

this summer an attempt to use Python's logging module in SageMath for
logging/verbosing on
https://trac.sagemath.org/ticket/21349
From the Sage-side this seems to be completed, but the logging does not
work well with the jupyter notebook.

Is anyone out there, who can help fixing this?

Best wishes

Daniel
Reply all
Reply to author
Forward
0 new messages