Skip to content

Commit

Permalink
Use ProgressLogging
Browse files Browse the repository at this point in the history
  • Loading branch information
tkf committed Nov 15, 2019
1 parent ea17d87 commit 02543d3
Show file tree
Hide file tree
Showing 5 changed files with 28 additions and 6 deletions.
1 change: 1 addition & 0 deletions Project.toml
Expand Up @@ -14,6 +14,7 @@ OrdinaryDiffEq = "1dea7af3-3e70-54e6-95c3-0bf5283fa5ed"
Parameters = "d96e819e-fc66-5662-9728-84c9c7592b0a"
Plots = "91a5bcdd-55d7-5caf-9e0b-520d859cae80"
Printf = "de0858da-6303-5e67-8744-51eddeeeb8d7"
ProgressLogging = "33c8b6b6-d38a-422a-b730-caa89a2f386c"
QuadGK = "1fd47b50-473d-5c70-9696-f719f8f3bcdc"
Random = "9a3f8284-a2c9-5f02-9a11-845980a1fd5c"
RecipesBase = "3cdcf5f2-1ef4-517c-9805-6587b60abb01"
Expand Down
1 change: 1 addition & 0 deletions src/continuations/continuations.jl
Expand Up @@ -5,6 +5,7 @@ import DiffEqBase: solve, solve!, init, step!

using ..ArrayUtils: _similar, _zeros, isalmostzero, zero_if_nan, _lq!, _det,
_normalize!, bottomrow, popbottomright
using ..MiscUtils: @progress_if

include("interface.jl")
include("euler_newton.jl")
Expand Down
7 changes: 1 addition & 6 deletions src/continuations/solver.jl
Expand Up @@ -40,11 +40,6 @@ solve(prob::AbstractContinuationProblem; kwargs...) =
function step!(solver::ContinuationSolver)
predictor_corrector_step!(solver.cache, solver.opts)

if solver.opts.verbose
print(stdout, '.')
flush(stdout)
end

# Errors are now thrown in predictor_corrector_step!. I need to
# reconsider the error handling...
if ! solver.cache.adaptation_success
Expand All @@ -66,7 +61,7 @@ function step!(wrapper::AbstractContinuationSolver, max_steps)
solver = as(wrapper, ContinuationSolver)
cache = solver.cache
cache.h = solver.opts.h0
for _ in 1:max_steps
@progress_if solver.opts.verbose for _ in 1:max_steps
step!(wrapper)
if ! isindomain(cache.u, cache.prob_cache)
return true
Expand Down
24 changes: 24 additions & 0 deletions src/utils/misc_utils.jl
@@ -0,0 +1,24 @@
module MiscUtils

import ProgressLogging

"""
@progress_if cond [options...] expr
If `cond` evaluates to `true`, run `@progress(options..., expr)`; otherwise
just run `expr`.
`options` and `expr` are passed to
[`ProgressLogging.@progress`](https://junolab.org/ProgressLogging.jl/dev/#ProgressLogging.@progress-Tuple)
"""
macro progress_if(cond, args...)
quote
if $cond
$ProgressLogging.@progress($(args...))
else
$(args[end])
end
end |> esc
end

end # module
1 change: 1 addition & 0 deletions src/utils/utils.jl
@@ -1,3 +1,4 @@
include("array_utils.jl")
include("fdiff_utils.jl")
include("poly_utils.jl")
include("misc_utils.jl")

0 comments on commit 02543d3

Please sign in to comment.