-
-
Notifications
You must be signed in to change notification settings - Fork 96
Add progress info for OptimizationBBO #336
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
WIP implementation
Codecov Report
@@ Coverage Diff @@
## master #336 +/- ##
=======================================
Coverage 79.34% 79.34%
=======================================
Files 9 9
Lines 276 276
=======================================
Hits 219 219
Misses 57 57 📣 We’re building smart automated test selection to slash your CI/CD build times. Learn more |
function SciMLBase.__solve(prob::SciMLBase.OptimizationProblem, opt::BBO, data=Optimization.DEFAULT_DATA; | ||
callback=(args...) -> (false), | ||
maxiters::Union{Number,Nothing}=nothing, | ||
maxtime::Union{Number,Nothing}=nothing, | ||
abstol::Union{Number,Nothing}=nothing, | ||
reltol::Union{Number,Nothing}=nothing, | ||
progress=false, kwargs...) | ||
verbose::Symbol=:compact, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
we only allow true/false
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Do we separate between progress
and verbose
?
I'm not sure how to handle
progress=false
,verbose=true
. Do we show all logs with@info
here?progress=true
,verbose=false
. Do we just show the progress here?progress=true
,verbose=true
. And here we also add other info like in the screenshot?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Progress and verbose are different. Trace logs should all be handled by progress. Verbose should be left to things like throwing warnings.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ok, so in that case all the functionality of the PR should be captured by progress
and verbose
will be reserved for warnings?
For the progress, should we display anything besides number of steps/maxiters?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@ChrisRackauckas Should I remove verbose
from this PR and just always redirect the stdout
and use it for progress logging when progress=true
?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We shouldn't just redirect to stdout. We should always control it with progress and verbose ourselves.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for the comment. I reimplemented the PR using the callback and querying the BlackBoxOptim.OptRunController
for info. I've also implemented time based or maxiters based progress.
if !isnothing(m) | ||
s = tryparse(Int, m[1]) | ||
isnothing(s) && continue | ||
isnothing(maxiters) && continue |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We can assume the default for MaxSteps
from BBO in this case as well https://github.com/robertfeldt/BlackBoxOptim.jl/blob/83c811671c00fffdcaadf042ad07ee2e2194ecbf/src/default_parameters.jl#L17
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is maxiters
silently using that value? Should we have the maxiters
set to that value if the user doesn't provide anything? I think we shouldn't assume a maxiters
in the progress logging and have something else passed to BBO.
From what I understood from @ChrisRackauckas we want maxiters
to be always explicitely provided by the users.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
No. If the solver can do exiting properly, let it exit when tolerances are hit. A lot of solvers just don't do this. When there is no other exit criteria, maxiters is required.
wait(task) | ||
end | ||
end | ||
|
||
function SciMLBase.__solve(prob::SciMLBase.OptimizationProblem, opt::BBO, data=Optimization.DEFAULT_DATA; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What is data
and why do we set maxiters
to length(data)
if this is provided.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It's used for passing a dataset if you want to write a data based loss, for example if you have observations from a system and then write a dynamic model for it and estimate the parameters. Unfortunately it looks like we don't use it much in the docs, we should probably do that more. Minibatching is a good use case for this https://docs.sciml.ai/dev/modules/Optimization/tutorials/minibatch/.
why do we set maxiters to length(data) if this is provided.
I think this was a consequence of copy-pasting the optimizationflux implementation, it is done for two reasons, that the callback iterates over the data hence it is required that the number of calls of it are <= length of data else there will be a index error and second for minibatching where the length is the number of batches. I agree it should probably not be set to that
Co-authored-by: Vaibhav Kumar Dixit <[email protected]>
Reimplement progress logging using a callback. The required information is now extracted directly from the OptRunController.
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). |
I think it looks good now, I will go over it once more later today and merge, the test failures are unrelated |
This looks good to go, just needs to run the formatter. |
|
||
if progress | ||
# Set progressbar to 1 to finish it | ||
Base.@logmsg(Base.LogLevel(-1), msg, progress=1, _id=:OptimizationBBO) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
msg
is not defined here. Should it be ""
?
Also, shouldn't this be after the bboptimize
call?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I've added a commit to do that
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 theTraceMode
keyword argument, but that's specific toOptimizationBBO
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, likeTraceMode
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 JuliaLang/julia#12711 (comment)For the moment you need to set the verbose keyword to
:compact
and progress totrue
to get progress logging, but maybe we could auto-setverbose
to that if the user usesprogress=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.
