# How to hide output from an optimizer?

**URL:** <https://discourse.julialang.org/t/how-to-hide-output-from-an-optimizer/100336>\
**Category:** New to Julia\
**Created:** [June 12, 2023, 12:37am UTC](https://discourse.julialang.org/t/how-to-hide-output-from-an-optimizer/100336 "2023-06-12T00:37:22Z")\
**Posts on this page:** 1\
**Showing post:** 4

<div class="post-metadata">

**Author:** ![kellertuer](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/kellertuer/32/220707_2.png) [@kellertuer](https://discourse.julialang.org/u/kellertuer)\
**Post date:** [June 14, 2023, 7:47am UTC](https://discourse.julialang.org/t/how-to-hide-output-from-an-optimizer/100336/4 "2023-06-14T07:47:26Z")

</div>

Hi,  
without your full code (with the return it seems to be part of a function?) I have to guess a bit (see [Please read: make it easier to help you](https://discourse.julialang.org/t/please-read-make-it-easier-to-help-you/14757)) but I think I see what you did.

If you would execute your first line on REPL you would indeed just get the time and not the printed statistics, since that is what `@elapsed` returns from the code it runs. So (from my code)

```julia
using Optim
f(x) = (1.0 - x[1])^2 + 100.0 * (x[2] - x[1]^2)^2
elapsed_time = @elapsed begin
	res = optimize(f, [0.0, 0.0]) 
end

```

just prints the time. `res` however is the whole result, i.e.

```julia
julia> typeof(res)
Optim.MultivariateOptimizationResults{NelderMead{Optim.AffineSimplexer, Optim.AdaptiveParameters}, Vector{Float64}, Float64, Float64, Vector{OptimizationState{Float64, NelderMead{Optim.AffineSimplexer, Optim.AdaptiveParameters}}}, Bool, NamedTuple{(:f_limit_reached, :g_limit_reached, :h_limit_reached, :time_limit, :callback, :f_increased), NTuple{6, Bool}}}

```

(and not just a number, but a very complicated type). If you print it (or get it as a return value from any function on REPL) there is – however – a nicer display, namely the full statistics (because this type really does not look nice) we already saw above.

If your posted code is within a function (which I just assume due to the `return` in the last line), then your whole function is run but returns res (the complicated type above) and that on REPL prints the statistics again.

So at the place you call the function (whose inner part I think you posted) put a `;` behind that function call  
_Or_ change what you return here, do you really need to return all of `res`? Or is maybe `Optim.minimizer(res)` enough? That of course depends on your function 🙂

PS: And I just noticed these are your first steps here – so: Welcome to Julia Discourse 👋

---

_[View the full topic](https://discourse.julialang.org/t/how-to-hide-output-from-an-optimizer/100336)._
