Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ForwardDiff on LazySum is failing #76

Open
AmitRotem opened this issue Dec 7, 2022 · 0 comments
Open

ForwardDiff on LazySum is failing #76

AmitRotem opened this issue Dec 7, 2022 · 0 comments

Comments

@AmitRotem
Copy link
Contributor

using QuantumOptics
import ForwardDiff as FD
mb = NLevelBasis(5)
s = randoperator(mb)
h = [randoperator(mb),randoperator(mb)]

LZtr(p) = abs2(tr(s'*(LazySum(p, h)*s)))

LZtr_workaround(p) = abs2(tr(s'*(LazySum(p, h)*s)))
function LZtr_workaround(p::Vector{<:FD.Dual})
    LS = LazySum(p, h)
    S = sum(LS.factors.*LS.operators)
    abs2(tr(s'*(S*s)))
end

FD.gradient(LZtr_workaround, rand(2)) |> display # ok
FD.gradient(LZtr, rand(2)) # error

seems to come from mul!(R,M,A,α,β) tring to convert (M*A)*α, which is type a has FD.Dual elements, to R which have ComplexF64 elements.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant