anderkve / gledeli

2 stars 0 forks source link

prefered way of logging #5

Closed fzeiser closed 4 years ago

fzeiser commented 4 years ago

What is the prefered way of logging within gambit? I saw that you had this very simple looging via print:

https://github.com/anderkve/gambit_np/blob/555bbe410340cb97040f7ef33003ed24a9c64eee/Backends/installed/fompy/1.0/fompy.py#L44

Is this just a simple example or should we log like this (instead of eg. using logging. Arguably, logging can be more complicatied, and if we couple this code to something else that is not python later, we probably anyhow won't use logging throughout (although one could redirect the output of course).

anderkve commented 4 years ago

There is a proper logging system in GAMBIT that we should use, where the messages end up in the log files in the-output-directory-you-set-in-your-yaml-file/logs/. However, you can only access the logging system from within GAMBIT. So what we should do in fompy is, for each new parameter point, accumulate a log string with our messages for that point, and pass this string back to GAMBIT (i.e. OMBit), where we can then enter it into the GAMBIT logging system.

For an example of how the logger is used inside GAMBIT, see here: https://github.com/anderkve/gambit_np/blob/8202e44028013a3e86c2716e8000ed81fddbf868/ExampleBit_A/src/ExampleBit_A.cpp#L291-L292

I guess the easiest way to set this up will simply be to change the return type of the run function in fompyBE.py from bool to a dictionary that contains both the current success bool and an entry called log_message with the accumulated fompy log string.

So how about I make the required changes to fompyBE.py and OMBit/src/OMBit.cpp, using a dummy log message in fompyBE.py. Then you can take care of the internal logging in fompy and how to communicate that to the run function in fompyBE.py

anderkve commented 4 years ago

OK, I've implemented the few changes needed in fompyBE.py and OMBit. So now log messages from fompy as written to the GAMBIT logs. To see how it works, you can run GAMBIT with yaml_files/ombit_demo.yaml and take a look at the generated log files:

This means that you can use whatever logging system you prefer inside fompy, as long as the resulting log (for the current parameter point) can be converted to a simple string that is passed back to GAMBIT in the run function in fompyBE.py:

https://github.com/anderkve/gambit_np/blob/8202e44028013a3e86c2716e8000ed81fddbf868/Backends/installed/fompy/1.0/fompyBE.py#L65-L76