# Autodifferentiating through the second Rényi entropy

**URL:** <https://itensor.discourse.group/t/autodifferentiating-through-the-second-renyi-entropy/294>\
**Category:** ITensor Julia Questions\
**Tags:** mpo\
**Created:** [July 27, 2022, 9:43pm UTC](https://itensor.discourse.group/t/autodifferentiating-through-the-second-renyi-entropy/294 "2022-07-27T21:43:49Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![nticea](https://avatars.discourse-cdn.com/v4/letter/n/eb8c5e/32.png) [@nticea](https://itensor.discourse.group/u/nticea)\
**Post date:** [July 27, 2022, 9:43pm UTC](https://itensor.discourse.group/t/autodifferentiating-through-the-second-renyi-entropy/294/1 "2022-07-27T21:43:49Z")

</div>

Hi, I have a question about making some code AD-compatible (I am taking the gradient of an ITensor using Zygote). Ordinarily, I would compute the second entropy using this code:

```auto
function second_Renyi_entropy(ρ::MPO)
    return -log(tr(apply(ρ, ρ)))
end

```

However, this throws a pullback error somewhere along the chain. To that end, I tried to write my own AD-compatible code to compute the second Rényi entropy of an MPO:

```auto
function second_Renyi_entropy_AD(ρ::MPO)
    T = ρ[1] * ρ[1]
    for i in 2:length(ρ)
        T *= (ρ[i] * ρ[i])
    end
    T = array(T)[1]
    return -log(T)
end

```

However, this second approach is not giving me the same result as the first, which leads me to believe that I am doing something naive & wrong. Please let me know if you have any thoughts!
