Skip to content

automatic cross platform progress monitoring #450

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

Merged
merged 2 commits into from
Mar 9, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions Project.toml
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,9 @@ DocStringExtensions = "ffbed154-4ef7-542d-bbb7-c09d3a79fcae"
FunctionWrappers = "069b7b12-0de2-55c6-9aab-29f3d0a68a2e"
IterativeSolvers = "42fd0dbc-a981-5370-80f2-aaf504508153"
IteratorInterfaceExtensions = "82899510-4779-5014-852e-03e436cf321d"
Juno = "e5e0dc1b-0480-54bc-9374-aad01c23163d"
LinearAlgebra = "37e2e46d-f89d-539d-b4ee-838fcccc9c8e"
Logging = "56ddb016-857b-54e1-b83d-db4d58db5568"
MuladdMacro = "46d2c3a1-f734-5fdb-9937-b9b9aeba4221"
Parameters = "d96e819e-fc66-5662-9728-84c9c7592b0a"
Printf = "de0858da-6303-5e67-8744-51eddeeeb8d7"
Expand All @@ -26,6 +28,7 @@ StaticArrays = "90137ffa-7385-5640-81b9-e52037218182"
Statistics = "10745b16-79ce-11e8-11f9-7d13ad32a3b2"
SuiteSparse = "4607b0f0-06f3-5cda-b6b1-a6196a1729e9"
TableTraits = "3783bdb8-4a98-5b6b-af9a-565f29a5fe9c"
TerminalLoggers = "5d786b92-1e48-4d6f-9151-6b4477ca9bed"
TreeViews = "a2a6695c-b41b-5b7d-aed9-dbfdeacea5d7"
ZygoteRules = "700de1a5-db45-46bc-99cf-38207098b444"

Expand Down
2 changes: 1 addition & 1 deletion src/DiffEqBase.jl
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ module DiffEqBase
using RecipesBase, RecursiveArrayTools,
Requires, TableTraits, IteratorInterfaceExtensions, TreeViews,
IterativeSolvers, RecursiveFactorization, Distributed, ArrayInterface,
DataStructures
DataStructures, Logging, TerminalLoggers, Juno

import ZygoteRules, ChainRulesCore

Expand Down
12 changes: 9 additions & 3 deletions src/solve.jl
Original file line number Diff line number Diff line change
Expand Up @@ -33,17 +33,23 @@ function init(prob::DEProblem,args...;kwargs...)
end
end

function solve_call(_prob,args...;merge_callbacks = true,kwargs...)
function solve_call(_prob,args...;merge_callbacks = true,
logger = default_logger(),
kwargs...)
if :kwargs ∈ propertynames(_prob)
if merge_callbacks && haskey(_prob.kwargs,:callback) && haskey(kwargs, :callback)
kwargs_temp = NamedTuple{Base.diff_names(Base._nt_names(
values(kwargs)), (:callback,))}(values(kwargs))
callbacks = NamedTuple{(:callback,)}( [DiffEqBase.CallbackSet(_prob.kwargs.callback, values(kwargs).callback )] )
kwargs = merge(kwargs_temp, callbacks)
end
__solve(_prob,args...;_prob.kwargs...,kwargs...)
maybe_with_logger(logger) do
__solve(_prob,args...;_prob.kwargs...,kwargs...)
end
else
__solve(_prob,args...;kwargs...)
maybe_with_logger(default_logger(logger)) do
__solve(_prob,args...;kwargs...)
end
end
end

Expand Down
3 changes: 3 additions & 0 deletions src/utils.jl
Original file line number Diff line number Diff line change
Expand Up @@ -255,3 +255,6 @@ prob2dtmin(tspan, onet, ::Any) = onet*1//10^(10)
timedepentdtmin(integrator::DEIntegrator) = timedepentdtmin(integrator.t, integrator.opts.dtmin)
timedepentdtmin(t::AbstractFloat, dtmin) = abs(max(eps(t), dtmin))
timedepentdtmin(::Any, dtmin) = abs(dtmin)

maybe_with_logger(f, logger) = logger === nothing ? f() : with_logger(f, logger)
default_logger() = Juno.isactive() ? nothing : TerminalLogger()
Copy link
Contributor

@tkf tkf Mar 9, 2020

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe
Suggested change
default_logger() = Juno.isactive() ? nothing : TerminalLogger()
default_logger() = Juno.isactive() || current_logger() isa TerminalLogger ? nothing : TerminalLogger()

or, even more hacky "solution" that does not require Juno:

Suggested change
default_logger() = Juno.isactive() ? nothing : TerminalLogger()
default_logger() =
Logging.min_enabled_level(current_logger()) == LogLevel(-1) ? nothing : TerminalLogger()

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

how does the latter work with Juno?

Copy link
Contributor

@tkf tkf Mar 9, 2020

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actually, I think @devmotion's solution using LoggingExtras.TeeLogger is much better SciML/DifferentialEquations.jl#424 (comment)

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

how does the latter work with Juno?

The log level of the JunoProgressLogger is guaranteed to be <= -1: https://github.com/JunoLab/Atom.jl/blob/016327893e4c2a22688446758debd1a4d47ed721/src/progress.jl#L75-L76