Optimization.jl icon indicating copy to clipboard operation
Optimization.jl copied to clipboard

[RFC] Redirect stdout and extract progress info

Open SebastianM-C opened this issue 3 years ago • 1 comments

It would be useful to be able to use OptimizationBBO without having all the output printed to stdout. In order to do this, we can use the TraceMode keyword argument, but that's specific to OptimizationBBO and doesn't translate to all the optimizers. I propose in this PR a new common keyword argument, verbose that could be translated to backend specific keywords, like TraceMode in BBO. This is the first commit of the PR.

A more general approach would be to avoid anything from getting to stdout and use the logging system for any messages. This would allow us to translate the stdout in progress information and more optimization backends could show progress bars. I have WIP implementation in the second commit which shows how this could work for OptimizationBBO. The stdout forwarding is based on https://github.com/JuliaLang/julia/issues/12711#issuecomment-912740865

For the moment you need to set the verbose keyword to :compact and progress to true to get progress logging, but maybe we could auto-set verbose to that if the user uses progress=true.

@Vaibhavdixit02 @ChrisRackauckas Let me know what you think about this. Should I try to go more on the logging route or should we just do the verbose keyword for now?

As an example, this is how VS Code would show the progress with the current implementation. image

SebastianM-C avatar Aug 10 '22 21:08 SebastianM-C

Codecov Report

Merging #336 (0f31a23) into master (fe73975) will not change coverage. The diff coverage is n/a.

@@           Coverage Diff           @@
##           master     #336   +/-   ##
=======================================
  Coverage   79.34%   79.34%           
=======================================
  Files           9        9           
  Lines         276      276           
=======================================
  Hits          219      219           
  Misses         57       57           

:mega: We’re building smart automated test selection to slash your CI/CD build times. Learn more

codecov[bot] avatar Aug 10 '22 21:08 codecov[bot]

I've reimplemented progress logging without doing any stdout redirection. The implementation is now simpler and it should be more robust. I've also added progress for time based limits. The only remaining part would be tests (and formatting).

SebastianM-C avatar Aug 18 '22 19:08 SebastianM-C

I think it looks good now, I will go over it once more later today and merge, the test failures are unrelated

Vaibhavdixit02 avatar Aug 19 '22 08:08 Vaibhavdixit02

This looks good to go, just needs to run the formatter.

ChrisRackauckas avatar Aug 19 '22 21:08 ChrisRackauckas