list_timings() cannot be redirected to a file or a variable in python
Affects | Status | Importance | Assigned to | Milestone | |
---|---|---|---|---|---|
DOLFIN |
Fix Released
|
Undecided
|
Johan Hake |
Bug Description
In python it is not possible to redirect the output of list_timings() to a file.
set_output_
see also https:/
Marco Morandini (morandini) wrote : | #1 |
Johan Hake (johan-hake) wrote : | #2 |
Thanks Marco!
I will look into your code and see if we could use it, hopefully without the boost::python dependency.
Changed in dolfin: | |
assignee: | nobody → Johan Hake (johan-hake) |
status: | New → Confirmed |
milestone: | none → 1.1.0 |
Johan Hake (johan-hake) wrote : | #3 |
Marco, what would the syntax be for adding a file as the log output. Is it possible to add an already existing file pointer or just the file name as a string? This would be the ultimate solution as we then can merge the two log streams from dolfin and logging dependent python modules such as UFL.
My boost python skills are really limited so following the inner workings of this small file is hard for me...
Marco Morandini (morandini) wrote : Re: [Bug 1072694] Re: list_timings() cannot be redirected to a file or a variable in python | #4 |
On 10/30/2012 08:00 AM, Johan Hake wrote:
> Marco, what would the syntax be for adding a file as the log output. Is
> it possible to add an already existing file pointer or just the file
> name as a string? This would be the ultimate solution as we then can
> merge the two log streams from dolfin and logging dependent python
> modules such as UFL.
>
> My boost python skills are really limited so following the inner
> workings of this small file is hard for me...
>
In my old code (where everything is wrapped with boost)
after
fileout = ostream(cout_buf())
fileout will point to std::cout,
and after
fileout = ostream(
fileout will point to a newly opened ofstream.
Then, fileout can be passed to any wrapped c++ function that
has an std::ostream & argument.
I.e., if I have this c++ function
void DxOutput(
and I wrap it as
BOOST_PYTHON_
std::ofstream:
BOOST_PYTHON_
{
....
the wrapping code I've attached
....
python:
}
in python I can do
t=0.01
fileout = ostream(
DxOutput(fileout, t)
if I want to write with DxOutput into new_file_name.txt,
or
fileout = ostream(cout_buf())
DxOutput(fileout, t)
If I want DxOuptut's output on the screen.
Note however that I can't write directly from python into fileout
(and I fear that this is what you are looking for :( .
At least, I've not even tried to do it (perhaps one should start
extractig the file descriptor, as explained here:
http://
)
Or
http://
Hope this helps.
corrado maurini (corrado-maurini) wrote : Re: [Bug 1072694] list_timings() cannot be redirected to a file or a variable in python | #5 |
Johan,
Thanks a lot for taking care of this.
If redirecting ostream through python is too difficult, for the specific case a possible alternative can be to have a function similar to list_timings(), but giving a dolfin Table as output.
Then the Table is a python object and one can use the associated methods to access data or print it out (event in latex format!).
I have not done this directly because I do not if this may conflict with your general design principles for the logger.
Corrado
Le 30 oct. 2012 à 11:02, Marco Morandini a écrit :
> On 10/30/2012 08:00 AM, Johan Hake wrote:
>> Marco, what would the syntax be for adding a file as the log output. Is
>> it possible to add an already existing file pointer or just the file
>> name as a string? This would be the ultimate solution as we then can
>> merge the two log streams from dolfin and logging dependent python
>> modules such as UFL.
>>
>> My boost python skills are really limited so following the inner
>> workings of this small file is hard for me...
>>
>
> In my old code (where everything is wrapped with boost)
>
> after
>
> fileout = ostream(cout_buf())
>
> fileout will point to std::cout,
>
> and after
>
> fileout = ostream(
>
> fileout will point to a newly opened ofstream.
>
> Then, fileout can be passed to any wrapped c++ function that
> has an std::ostream & argument.
>
> I.e., if I have this c++ function
>
> void DxOutput(
>
> and I wrap it as
>
> BOOST_PYTHON_
> std::ofstream:
> BOOST_PYTHON_
> {
> ....
>
> the wrapping code I've attached
>
> ....
>
> python:
> }
>
> in python I can do
>
> t=0.01
> fileout = ostream(
> DxOutput(fileout, t)
>
> if I want to write with DxOutput into new_file_name.txt,
>
> or
>
> fileout = ostream(cout_buf())
> DxOutput(fileout, t)
>
> If I want DxOuptut's output on the screen.
>
> Note however that I can't write directly from python into fileout
> (and I fear that this is what you are looking for :( .
> At least, I've not even tried to do it (perhaps one should start
> extractig the file descriptor, as explained here:
>
> http://
>
> )
>
> Or
> http://
>
>
> Hope this helps.
>
> --
> You received this bug notification because you are a member of DOLFIN
> Team, which is subscribed to DOLFIN.
> https:/
>
> Title:
> list_timings() cannot be redirected to a file or a variable in python
>
> Status in DOLFIN:
> Confirmed
>
> Bug description:
> In python it is not possible to redirect the output of list_timings()
> to a file.
>
> set_output_
> python because of problems in wrapping cpp ostream
>
> see also https:/
>
> To manage notifications about this bug go to:
> https:/
Johan Hake (johan-hake) wrote : | #6 |
On 10/30/2012 11:53 AM, corrado maurini wrote:
> Johan,
>
> Thanks a lot for taking care of this.
Well, we see how far it goes :)
> If redirecting ostream through python is too difficult, for the specific
> case a possible alternative can be to have a function similar to
> list_timings(), but giving a dolfin Table as output.
Sure that would be pretty trivial to implement, and we have them same
analogy for list_linear_
where the later return a list of strings instead of printing them to the
screen.
So adding a free function called timings would fit fine here.
> Then the Table is a python object and one can use the associated methods
> to access data or print it out (event in latex format!).
Good point!
> I have not done this directly because I do not if this may conflict with
> your general design principles for the logger.
Should work just fine.
Johan
> Corrado
>
> Le 30 oct. 2012 à 11:02, Marco Morandini a écrit :
>
>> On 10/30/2012 08:00 AM, Johan Hake wrote:
>>> Marco, what would the syntax be for adding a file as the log output. Is
>>> it possible to add an already existing file pointer or just the file
>>> name as a string? This would be the ultimate solution as we then can
>>> merge the two log streams from dolfin and logging dependent python
>>> modules such as UFL.
>>>
>>> My boost python skills are really limited so following the inner
>>> workings of this small file is hard for me...
>>>
>>
>> In my old code (where everything is wrapped with boost)
>>
>> after
>>
>> fileout = ostream(cout_buf())
>>
>> fileout will point to std::cout,
>>
>> and after
>>
>> fileout = ostream(
>>
>> fileout will point to a newly opened ofstream.
>>
>> Then, fileout can be passed to any wrapped c++ function that
>> has an std::ostream & argument.
>>
>> I.e., if I have this c++ function
>>
>> void DxOutput(
>>
>> and I wrap it as
>>
>> BOOST_PYTHON_
>> std::ofstream:
>> BOOST_PYTHON_
>> {
>> ....
>>
>> the wrapping code I've attached
>>
>> ....
>>
>> python:
>> }
>>
>> in python I can do
>>
>> t=0.01
>> fileout = ostream(
>> DxOutput(fileout, t)
>>
>> if I want to write with DxOutput into new_file_name.txt,
>>
>> or
>>
>> fileout = ostream(cout_buf())
>> DxOutput(fileout, t)
>>
>> If I want DxOuptut's output on the screen.
>>
>> Note however that I can't write directly from python into fileout
>> (and I fear that this is what you are looking for :( .
>> At least, I've not even tried to do it (perhaps one should start
>> extractig the file descriptor, as explained here:
>>
>> http://
>>
>> )
>>
>> Or
>> http://
>>
>>
>> Hope this helps.
>>
>> --
>> You received this bug notification because you are a member of DOLFIN
>> Team, which is subscribed to DOLFIN.
>> https:/
>>
>> Title:
>> list_timings() cannot be redirected to a file or a variable in python
>>
>> Status in DOLFI...
corrado maurini (corrado-maurini) wrote : | #7 |
Johan, I started adding Table output, but this stopped me very soon:
As soon I add
#include "Table.h"
in the log.h I have the following error at compilation:
May you give a quick explanation/
Corrado
-------
majorana:
[ 0%] Building CXX object dolfin/
In file included from /opt/HPC/
/opt/HPC/
/opt/HPC/
/opt/HPC/
/opt/HPC/
/opt/HPC/
/opt/HPC/
/opt/HPC/
make[2]: *** [dolfin/
make[1]: *** [dolfin/
make: *** [all] Error 2
Le 30 oct. 2012 à 21:40, Johan Hake a écrit :
> On 10/30/2012 11:53 AM, corrado maurini wrote:
>> Johan,
>>
>> Thanks a lot for taking care of this.
>
> Well, we see how far it goes :)
>
>> If redirecting ostream through python is too difficult, for the specific
>> case a possible alternative can be to have a function similar to
>> list_timings(), but giving a dolfin Table as output.
>
> Sure that would be pretty trivial to implement, and we have them same
> analogy for list_linear_
> where the later return a list of strings instead of printing them to the
> screen.
>
> So adding a free function called timings would fit fine here.
>
>> Then the Table is a python object and one can use the associated methods
>> to access data or print it out (event in latex format!).
>
> Good point!
>
>> I have not done t...
Benjamin Kehlet (benjamik) wrote : | #8 |
2012/10/31 corrado maurini <email address hidden>:
> Johan, I started adding Table output, but this stopped me very soon:
>
> As soon I add
> #include "Table.h"
> in the log.h I have the following error at compilation:
>
> May you give a quick explanation/
I think you introduce a circular dependency of header files here:
log/log.h -> log/Table.h -> common/Variable.h ->
parameter/
Maybe class Table doesn't need to inherit class Variable? That would
solve it, I think, but the core developers should comment on that.
Regards
Benjamin
>
> Corrado
> -------
> majorana:
> [ 0%] Building CXX object dolfin/
> In file included from /opt/HPC/
> from /opt/HPC/
> from /opt/HPC/
> from /opt/HPC/
> from /opt/HPC/
> from /opt/HPC/
> from /opt/HPC/
> from /opt/HPC/
> /opt/HPC/
> /opt/HPC/
> /opt/HPC/
> /opt/HPC/
> /opt/HPC/
> /opt/HPC/
> /opt/HPC/
> make[2]: *** [dolfin/
> make[1]: *** [dolfin/
> make: *** [all] Error 2
>
> Le 30 oct. 2012 à 21:40, Johan Hake a écrit :
>
>> On 10/30/2012 11:53 AM, corrado maurini wrote:
>>> Johan,
>>>
>>> Thanks a lot for taking care of this.
>>
>> Well, we see how far it goes :)
>>
>>> If redirecting ostream through python is too difficult, for the specific
>>> case a possible alternative can be to have a function similar to
>>> list_timings(), but giving a dolfin Table as output.
>>
>> Sure that would be pretty trivial to impl...
Anders Logg (logg) wrote : | #9 |
On Wed, Oct 31, 2012 at 02:53:25PM -0000, Benjamin Kehlet wrote:
> 2012/10/31 corrado maurini <email address hidden>:
> > Johan, I started adding Table output, but this stopped me very soon:
> >
> > As soon I add
> > #include "Table.h"
> > in the log.h I have the following error at compilation:
> >
> > May you give a quick explanation/
>
> I think you introduce a circular dependency of header files here:
>
> log/log.h -> log/Table.h -> common/Variable.h ->
> parameter/
>
> Maybe class Table doesn't need to inherit class Variable? That would
> solve it, I think, but the core developers should comment on that.
Inheritance from Variable is there so we can do info(table) and info
will know to call table.str.
Circular dependencies can usually be worked around with forward
declarations but I haven't looked at this case in detail.
--
Anders
>
> Regards
> Benjamin
>
> >
> > Corrado
> > -------
> > majorana:
> > [ 0%] Building CXX object dolfin/
> > In file included from /opt/HPC/
> > from /opt/HPC/
> > from /opt/HPC/
> > from /opt/HPC/
> > from /opt/HPC/
> > from /opt/HPC/
> > from /opt/HPC/
> > from /opt/HPC/
> > /opt/HPC/
> > /opt/HPC/
> > /opt/HPC/
> > /opt/HPC/
> > /opt/HPC/
> > /opt/HPC/
> > /opt/HPC/
> > make[2]: *** [dolfin/
> > make[1]: *** [dolfin/
> > make: *** [all] Error 2
> >
> > Le 30 oct. 2012 à 21:40, Johan Hake a écrit :
> >
> >> On 10/...
Johan Hake (johan-hake) wrote : | #10 |
I have now added timings to timing.h and moved list_timings to . After some fiddling it should be fine. However I need to run it on the buildbot before it is checked in.
corrado maurini (corrado-maurini) wrote : Re: [Bug 1072694] Re: list_timings() cannot be redirected to a file or a variable in python | #11 |
Thanks a lot.
This is very useful for me.
I own you a coffee, or a beer if you prefer, whenever you pass through Paris !
As a minor note, the name "timings" as a pure function is prone to conflict with other definitions. I found for example
Table timings("Timings");
in dolfin/
Corrado
On Nov 1, 2012, at 8:57 AM, Johan Hake wrote:
> I have now added timings to timing.h and moved list_timings to . After
> some fiddling it should be fine. However I need to run it on the
> buildbot before it is checked in.
>
> --
> You received this bug notification because you are a member of DOLFIN
> Team, which is subscribed to DOLFIN.
> https:/
>
> Title:
> list_timings() cannot be redirected to a file or a variable in python
>
> Status in DOLFIN:
> Confirmed
>
> Bug description:
> In python it is not possible to redirect the output of list_timings()
> to a file.
>
> set_output_
> python because of problems in wrapping cpp ostream
>
> see also https:/
>
> To manage notifications about this bug go to:
> https:/
Anders Logg (logg) wrote : | #12 |
On Thu, Nov 01, 2012 at 07:57:43AM -0000, Johan Hake wrote:
> I have now added timings to timing.h and moved list_timings to . After
> some fiddling it should be fine. However I need to run it on the
> buildbot before it is checked in.
I'm not sure it should be moved to timing.h. That module only contains
helper functions for running timings. Actually storing them requires a
singleton object to keep track of the timings which is why it's stored
as part of the Logger class in dolfin/log/.
--
Anders
Johan Hake (johan-hake) wrote : | #13 |
On 11/01/2012 06:51 PM, Anders Logg wrote:
> On Thu, Nov 01, 2012 at 07:57:43AM -0000, Johan Hake wrote:
>> I have now added timings to timing.h and moved list_timings to . After
>> some fiddling it should be fine. However I need to run it on the
>> buildbot before it is checked in.
>
> I'm not sure it should be moved to timing.h. That module only contains
> helper functions for running timings. Actually storing them requires a
> singleton object to keep track of the timings which is why it's stored
> as part of the Logger class in dolfin/log/.
The actual work is still done within the singleton object of Logger. The
free function I put within timing.h. I thought and still thing they
functionalwise fit together.
If you are not cool with this we could move them back to dolfin/log, but
out of log.h.
Johan
Anders Logg (logg) wrote : | #14 |
On Thu, Nov 01, 2012 at 07:37:56PM +0100, Johan Hake wrote:
> On 11/01/2012 06:51 PM, Anders Logg wrote:
> > On Thu, Nov 01, 2012 at 07:57:43AM -0000, Johan Hake wrote:
> >> I have now added timings to timing.h and moved list_timings to . After
> >> some fiddling it should be fine. However I need to run it on the
> >> buildbot before it is checked in.
> >
> > I'm not sure it should be moved to timing.h. That module only contains
> > helper functions for running timings. Actually storing them requires a
> > singleton object to keep track of the timings which is why it's stored
> > as part of the Logger class in dolfin/log/.
>
> The actual work is still done within the singleton object of Logger. The
> free function I put within timing.h. I thought and still thing they
> functionalwise fit together.
ok, sounds good then.
--
Anders
> If you are not cool with this we could move them back to dolfin/log, but
> out of log.h.
>
> Johan
Changed in dolfin: | |
status: | Confirmed → Fix Committed |
Changed in dolfin: | |
status: | Fix Committed → Fix Released |
Using boost::python I ended up with something like the attached file; don't know if it is possible to do something similar using swig. Apologizes if this is only noise.