SolverTraces.jl

Author jagot
Popularity
0 Stars
Updated Last
1 Year 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 Formatting.jl and Crayons.jl.

Usage example

using SolverTraces
using Formatting
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)
# How much load per second can be handled
push!(trace, Performance(load))
push!(trace, 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

No packages found.