How to get rid of output in nlsolve?

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?

Should just be whatever IO is passed to show:

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.

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)

Would explain why everything inside nlsolve is swallowed, but not the summary.

I apologize. I had a print call I hadn’t realized.


No need to apologize! We all make these kinds of silly mistakes sometimes :slight_smile: