# Domain Error when using Zygote to differentiate MultiStart minimization

**URL:** <https://discourse.julialang.org/t/domain-error-when-using-zygote-to-differentiate-multistart-minimization/115013>\
**Category:** Optimization (Mathematical)\
**Tags:** question, zygote, autodiff\
**Created:** [May 31, 2024, 12:59pm UTC](https://discourse.julialang.org/t/domain-error-when-using-zygote-to-differentiate-multistart-minimization/115013 "2024-05-31T12:59:16Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![paul188](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/paul188/32/207567_2.png) [@paul188](https://discourse.julialang.org/u/paul188)\
**Post date:** [May 31, 2024, 12:59pm UTC](https://discourse.julialang.org/t/domain-error-when-using-zygote-to-differentiate-multistart-minimization/115013/1 "2024-05-31T12:59:16Z")

</div>

I have the following MWE, with most of the code just copied from the MultiStartOptimization.jl documentation:

```julia
using Optimization, OptimizationMultistartOptimization, OptimizationNLopt
using Zygote
using ForwardDiff

rosenbrock(x, p) = (p[1] - x[1])^2 + p[2] * (x[2] - x[1]^2)^2
x0 = zeros(2)
f = OptimizationFunction(rosenbrock)

function solve_rosenbrock(p)
    prob = Optimization.OptimizationProblem(f, x0, p, lb = [-1.0, -1.0], ub = [1.0, 1.0])
    sol = solve(prob, MultistartOptimization.TikTak(100), NLopt.LD_LBFGS())
    println(sol.minimizer)
    return rosenbrock(sol.minimizer, p)
end

Zygote.gradient(x -> solve_rosenbrock(x), [1.0, 1.0])

```

When running it, I get the error:  
**ERROR: DomainError with -1: Cannot raise an integer x to a negative power -1. Make x or -1 a float by adding a zero decimal (e.g., 2.0^-1 or 2^-1.0 instead of 2^-1)or write 1/x^1, float(x)^-1, x^float(-1) or (x//1)^-1.**.

Is it just that MultiStartOptimization is not compatible with Zygote ? Because when I use ForwardDiff instead of Zygote, I do not get any errors. I would really prefer to use Zygote if possible.

Thanks in advance for any help

---

<div class="post-metadata">

**Author:** ![Vaibhavdixit02](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/vaibhavdixit02/32/2916_2.png) [@Vaibhavdixit02](https://discourse.julialang.org/u/Vaibhavdixit02)\
**Post date:** [May 31, 2024, 8:11pm UTC](https://discourse.julialang.org/t/domain-error-when-using-zygote-to-differentiate-multistart-minimization/115013/2 "2024-05-31T20:11:37Z")

</div>

What’s your goal here? Are you looking to differentiate through the multistart solver?

---

<div class="post-metadata">

**Author:** ![paul188](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/paul188/32/207567_2.png) [@paul188](https://discourse.julialang.org/u/paul188)\
**Post date:** [June 3, 2024, 12:05pm UTC](https://discourse.julialang.org/t/domain-error-when-using-zygote-to-differentiate-multistart-minimization/115013/3 "2024-06-03T12:05:57Z")

</div>

I wanted to implement a function inside my optimization routine that checks whether my model has a zero (very simplified). And for that I would like to differentiate through multistart. I wonder if it is at all possible. Or if it would be a better idea to just ignore all the derivatives of multistart and just take the result (there is a zero or there is no zero) and differentiate w.r.t. the result.
