# Issue while using ReverseDiff in turing model

**URL:** <https://discourse.julialang.org/t/issue-while-using-reversediff-in-turing-model/99723>\
**Category:** New to Julia\
**Tags:** turing, reversediff, differentialequation\
**Created:** [June 1, 2023, 11:36am UTC](https://discourse.julialang.org/t/issue-while-using-reversediff-in-turing-model/99723 "2023-06-01T11:36:55Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![Sahil\_Khan](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/sahil_khan/32/47573_2.png) [@Sahil\_Khan](https://discourse.julialang.org/u/Sahil_Khan)\
**Post date:** [June 1, 2023, 11:36am UTC](https://discourse.julialang.org/t/issue-while-using-reversediff-in-turing-model/99723/1 "2023-06-01T11:36:55Z")

</div>

Hello,

In discourse I found out that using reversediff is better for performance when you have high dimensional model. So, I’m trying to switch to reversediff from forwarddiff.

But at the moment I’m facing this issue

```julia
nested task error: type TrackedArray has no field retcode

```

In my code I have this checkpoint

```julia
 if SciMLBase.successful_retcode(sol.retcode) == 1
    predicted[i] = sol'[16,6]
  else 
    Turing.@addlogprob! -Inf
    return nothing
  end

```

which seems to be cause of error message. Is there any way to resolve this?

---

<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:** [June 1, 2023, 12:06pm UTC](https://discourse.julialang.org/t/issue-while-using-reversediff-in-turing-model/99723/2 "2023-06-01T12:06:04Z")

</div>

It’s a ReverseDiff quirk. Do `if sol isa SciMLBase.AbstractSolution && SciMLBase.successful_retcode(sol.retcode)` since in the forward pass `sol` can be represented as a TrackedArray instead of as a solution, given its abstract array status. I think there’s a way to fix that though and I want to try something soon.

---

<div class="post-metadata">

**Author:** ![Sahil\_Khan](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/sahil_khan/32/47573_2.png) [@Sahil\_Khan](https://discourse.julialang.org/u/Sahil_Khan)\
**Post date:** [June 1, 2023, 12:20pm UTC](https://discourse.julialang.org/t/issue-while-using-reversediff-in-turing-model/99723/3 "2023-06-01T12:20:55Z")

</div>

I hope, I did it correct.

```julia
if sol isa SciMLBase.AbstractSolution && SciMLBase.successful_retcode(sol.retcode) == 1
    predicted[i] = sol'[16,6]
  else 
    Turing.@addlogprob! -Inf
    return nothing
  end

```

I’m getting this

```julia
nested task error: UndefVarError: AbstractSolution not defined

```

---

<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:** [June 1, 2023, 12:34pm UTC](https://discourse.julialang.org/t/issue-while-using-reversediff-in-turing-model/99723/4 "2023-06-01T12:34:13Z")

</div>

> [@Sahil\_Khan](#):
>
> `SciMLBase.AbstractSolution`

oops.  
SciMLBase.AbstractSciMLSolution

---

<div class="post-metadata">

**Author:** ![Sahil\_Khan](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/sahil_khan/32/47573_2.png) [@Sahil\_Khan](https://discourse.julialang.org/u/Sahil_Khan)\
**Post date:** [June 1, 2023, 1:16pm UTC](https://discourse.julialang.org/t/issue-while-using-reversediff-in-turing-model/99723/5 "2023-06-01T13:16:39Z")

</div>

That worked I guess. I don’t see that error anymore.

I will confirm once i have some results.
