JuliaSmoothOptimizers / JuliaSmoothOptimizers/SolverCore.jl
Better output for GenericExecutionStats (show vs print) (Pluto display)
- Dominant language
- Julia
- Stars
- 8
- Forks
- 6
- PR merge metrics
- No merged PRs in 30d
Description
This is moved from https://github.com/JuliaSmoothOptimizers/SolverTools.jl/issues/93
To define the issue better:
The is a show method in https://github.com/JuliaSmoothOptimizers/SolverCore.jl/blob/main/src/stats.jl#L405
And a print method right below.
This means that on the REPL, the output of
```julia
output = trunk(nlp)
```
is
```
"Execution stats: first-order stationary"
```
And to see details, you have to use
```julia
print(output)
```
Which shows
```
Generic Execution stats
status: first-order stationary
objective value: 1.2067821564748022e-25
primal feasibility: 0.0
dual feasibility: 3.0567567125153457e-13
solution: [0.99999999999966 0.9999999999992844]
iterations: 10
elapsed time: 0.0009999275207519531
```
At least in Pluto notebooks, I want the initial call `output = trunk(nlp)` to show the complete output.
From the little I gathered, there are two strategies:
1. Don't have a separate `print` functions, instead, put everything in `show`; or
2. Use MIME types to show a different output for Pluto (which I guess is related to HTML).
I like option 2 more. @tmigot @dpo, opinions?
There is some information about display vs show vs print in this JuliaCon 2020 video: https://www.youtube.com/watch?v=S1Fb5oNhhbc that might be useful.
---
To reproduce, open a Pluto notebook and add the following cells:
# Cell 1
using ADNLPModel, JSOSolvers
# Cell 2
let
nlp = ADNLPModel(x -> (x[1] - 1)^2 + 4 * (x[2] - x[1]^2)^2, [-1.2; 1.0])
output = trunk(nlp)
end
---
There is also a `compact::Bool` flag in `show`, that might be enough to have a single function with everything.
Contributor guide
Assessment
This issue has not been assessed yet.