# Error using Kriging surrogate derivative

**URL:** <https://discourse.julialang.org/t/error-using-kriging-surrogate-derivative/86788>\
**Category:** New to Julia\
**Tags:** optimization, zygote, modelling\
**Created:** [September 5, 2022, 8:48am UTC](https://discourse.julialang.org/t/error-using-kriging-surrogate-derivative/86788 "2022-09-05T08:48:44Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![davide445](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/davide445/32/33681_2.png) [@davide445](https://discourse.julialang.org/u/davide445)\
**Post date:** [September 5, 2022, 8:48am UTC](https://discourse.julialang.org/t/error-using-kriging-surrogate-derivative/86788/1 "2022-09-05T08:48:45Z")

</div>

Trying to test Surrogates.jl I have created this

```julia
using Surrogates
using Zygote
g = x -> x^2 + 5*x
x1 = sample(40,0,5,SobolSample())
y1 = g.(x1)
my_krig1 = Kriging(x1,y1,0,5;p=0.9)
d_my_krig1 = x -> my_krig1'(x)
d_g = x -> g'(x)

```

d\_g(2.0) get me 9.0

d\_my\_krig1(2.0) give this error

```julia

MethodError: no method matching +(::NamedTuple{(:x, :y, :lb, :ub, :p, :theta, :mu, :b, :sigma, :inverse_of_R), Tuple{Vector{Float64}, Nothing, Nothing, Nothing, Float64, Float64, Nothing, Vector{Float64}, Nothing, Nothing}}, ::Base.RefValue{Any})

Closest candidates are:

+(::Any, ::Any, !Matched::Any, !Matched::Any...) at D:\Program Files\Julia-1.7.2\share\julia\base\operators.jl:655

+(!Matched::ChainRulesCore.AbstractThunk, ::Any) at D:\Program Files (x86)\Julia-1.7.2\.julia\packages\ChainRulesCore\ctmSK\src\tangent_arithmetic.jl:122

+(!Matched::ChainRulesCore.Tangent{P}, ::P) where P at D:\Program Files (x86)\Julia-1.7.2\.julia\packages\ChainRulesCore\ctmSK\src\tangent_arithmetic.jl:146

...

    accum(::NamedTuple{(:x, :y, :lb, :ub, :p, :theta, :mu, :b, :sigma, :inverse_of_R), Tuple{Vector{Float64}, Nothing, Nothing, Nothing, Float64, Float64, Nothing, Vector{Float64}, Nothing, Nothing}}, ::Base.RefValue{Any})@lib.jl:17
    accum(::NamedTuple{(:x, :y, :lb, :ub, :p, :theta, :mu, :b, :sigma, :inverse_of_R), Tuple{Vector{Float64}, Nothing, Nothing, Nothing, Float64, Float64, Nothing, Vector{Float64}, Nothing, Nothing}}, ::Base.RefValue{Any}, ::Nothing, ::Vararg{Nothing})@lib.jl:22
    getindex@tuple.jl:29[inlined]
    gradindex@reverse.jl:12[inlined]
    Pullback@Kriging.jl:71[inlined]
    (::typeof(∂(λ)))(::Float64)@interface2.jl:0
    #60@interface.jl:45[inlined]
    #64@interface.jl:104[inlined]
    #5@Other: 1[inlined]
    top-level scope@Local: 1[inlined]

```

I suppose there is some error in the parameters I passed to the function, but since this way seems working in the [Surrogates tutorial](https://youtu.be/HLcBRhrS-3o?t=1119) I will be happy if someone can better explain me why this time is not working.

---

<div class="post-metadata">

**Author:** ![ChrisRackauckas](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/chrisrackauckas/32/77_2.png) [@ChrisRackauckas](https://discourse.julialang.org/u/ChrisRackauckas)\
**Post date:** [September 5, 2022, 3:57pm UTC](https://discourse.julialang.org/t/error-using-kriging-surrogate-derivative/86788/2 "2022-09-05T15:57:43Z")

</div>

That was a recently introduced Zygote.jl bug from a change in accumulation. I believe @ToucheSir would have more details. I think v0.6.42 would be a working version?

We’re working through this right now.

---

<div class="post-metadata">

**Author:** ![davide445](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/davide445/32/33681_2.png) [@davide445](https://discourse.julialang.org/u/davide445)\
**Post date:** [September 5, 2022, 9:25pm UTC](https://discourse.julialang.org/t/error-using-kriging-surrogate-derivative/86788/3 "2022-09-05T21:25:31Z")

</div>

I can confirm using Zygote 0.6.43 the error is not there.
