# How to use \`precondprep\` with \`Optim.jl\`?

**URL:** <https://discourse.julialang.org/t/how-to-use-precondprep-with-optim-jl/100288>\
**Category:** General Usage\
**Tags:** question, optim\
**Created:** [June 13, 2023, 3:57pm UTC](https://discourse.julialang.org/t/how-to-use-precondprep-with-optim-jl/100288 "2023-06-13T15:57:13Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![fph](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/fph/32/17159_2.png) [@fph](https://discourse.julialang.org/u/fph)\
**Post date:** [June 13, 2023, 3:57pm UTC](https://discourse.julialang.org/t/how-to-use-precondprep-with-optim-jl/100288/1 "2023-06-13T15:57:13Z")

</div>

How do I use `precondprep` within `Optim.jl` to use a preconditioner that changes at each step? The results of the function seem to be ignored in my attempts. Example:

```julia
using Optim
res = optimize(x->(x[1]-1)^4 + x[2]^2, [2.;1.], Optim.ConjugateGradient(P=I, precondprep = (P,x)->[1;2;3]))

```

In this example my callback function `precondprep` even returns a vector of the wrong dimension (rather than a matrix as it should), but nothing breaks; it seems that the return value is ignored.

I can’t understand much from the [documentation](https://julianlsolvers.github.io/Optim.jl/stable/#algo/precondition/), unfortunately.

Thanks in advance!
