I’m struggling to avoid printing the result after an nlsolve
call.
Results of Nonlinear Solver Algorithm
* Algorithm: Trust-region with dogleg and autoscaling
* Starting Point: [-2.9444389791664403, -2.197224577336219, 2.0, -0.2231435513142097]
* Zero: [-0.8473798621728809, 4.661998387995021, 2.996397431516435, -2.9186666380101856]
* Inf-norm of residuals: 0.000000
* Iterations: 9
* Convergence: true
* |x - x'| < 0.0e+00: false
* |f(x)| < 1.0e-08: true
* Function Calls (f): 10
* Jacobian Calls (df/dx): 9
I tried doing this
redirect_stdout(() -> nlsolve(f!, params_init_vec), devnull)
But that doesn’t redirect the summary output. It does, however, make debugging very hard. What IO
is the summary from NLSolve
sent to?
Sukera
June 25, 2021, 4:17pm
2
Should just be whatever IO
is passed to show
:
function Base.show(io::IO, r::SolverResults)
@printf io "Results of Nonlinear Solver Algorithm\n"
@printf io " * Algorithm: %s\n" r.method
@printf io " * Starting Point: %s\n" string(r.initial_x)
@printf io " * Zero: %s\n" string(r.zero)
@printf io " * Inf-norm of residuals: %f\n" r.residual_norm
@printf io " * Iterations: %d\n" r.iterations
@printf io " * Convergence: %s\n" converged(r)
@printf io " * |x - x'| < %.1e: %s\n" r.xtol r.x_converged
@printf io " * |f(x)| < %.1e: %s\n" r.ftol r.f_converged
@printf io " * Function Calls (f): %d\n" r.f_calls
@printf io " * Jacobian Calls (df/dx): %d" r.g_calls
return
end
That is obviously true.
But it doesn’t help me understand why redirect_stdout
doesn’t affect the printing. I also can’t find where the show
method is actually called in the nlsolve
function.
Sukera
June 25, 2021, 4:28pm
4
Well - redirect_stdout
just returns whatever the given function returns, so that’s why it’s probably being printed. The REPL just displays the value it was given, calling show
:
julia> redirect_stdout(() -> 1, devnull)
1
Would explain why everything inside nlsolve
is swallowed, but not the summary.
I apologize. I had a print
call I hadn’t realized.
2 Likes
Sukera
June 25, 2021, 4:32pm
6
No need to apologize! We all make these kinds of silly mistakes sometimes