SolverTraces.jl

Author jagot
Popularity
1 Star
Updated Last
6 Months Ago
Started In
November 2018

SolverTraces.jl

https://img.shields.io/badge/docs-stable-blue.svg https://img.shields.io/badge/docs-dev-blue.svg https://github.com/jagot/SolverTraces.jl/workflows/CI/badge.svg https://codecov.io/gh/jagot/SolverTraces.jl/branch/master/graph/badge.svg

Small utility library for printing solver traces. Based around Format.jl and Crayons.jl.

Usage example

using SolverTraces
using Format
using Crayons

# Custom column type, needs to inherit TraceColumn and have a fmt
# field.
struct Random{R<:Real} <: TraceColumn
    fmt::FormatExpr
    lc::LinearColorant{R}
    header::String
end

Random(::Type{R}=Float64) where R =
    Random{R}(FormatExpr("{1:s}{2:9.3e}$(crayon"reset")"),
            LinearColorant(1.0, 0.0, SolverTraces.red_green_scale()),
            "   Random")

# Also needs to be callable with current step as argument.
function (c::Random)(i::Integer)
    n = rand()
    c.lc(n), n
end

num_steps = 1000
load = 10
trace = SolverTrace(num_steps,
                    CurrentStep(num_steps),
                    Performance(load), # How much load per second can be handled
                    Random())

print_header(trace)
for i = 1:num_steps
    sleep(0.0001rand())
    SolverTraces.next!(trace)
end

Output on Linux with 24 bit colours available: figures/linux.png

Output on Windows with 16 colours available: figures/windows.png

Future ideas

  • Nested solver traces for algorithms where each step necessitates inner solves. It would be interesting to support such cases and have togglable visibility of nested traces.
  • Output to other backends than the terminal, e.g. HTML: asynchronous display of solver trace in the web browser of a computation running remotely.

Used By Packages