QuantumBFS / Yao.jl

Extensible, Efficient Quantum Algorithm Design for Humans.

Home Page:https://yaoquantum.org

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

wrong gradient for real asysmetric hamiltonian

Roger-luo opened this issue · comments

This is from the email

I have a Yao question related to the attached code. Yao seems to give the wrong gradient for expectation values when the Hamiltonian is real and asymmetric. The code computes the gradient using a naive finite difference method and using Yao's AD.

The thing that is really surprising to me is that whatever Yao is doing seems to make VQE succeed when using a real, asymmetric Hamiltonian (i.e., a non-Hermitian Hamiltonian) in cases where the eigenvalues are real. At least, this holds in all the cases where I've tried. So, maybe this is a feature instead of a bug. :) Any idea what's going on?

Dan

MWE:

expect'(-im * Y, zero_state(1)=>rot(Y, 0.0))
expect(-im * Y, zero_state(1)=>rot(Y, -1e-8))
expect(-im * Y, zero_state(1)=>rot(Y, 1e-8))
expect'(Y, zero_state(1)=>rot(Y, 0.0))

The expectation value should not be imaginary, it has to be real because it is the loss.

I'm thinking if we should give a warning or something when differentiating a non-real loss? since I don't see any use case for a non-real loss, we should just say no when someone tries

non-real loss requires computing Jacobian matrices. Sometimes, determining if an observable is hermitian requires obtaining its matrix representation, we do not want it as the default behavior. No good solution in my mind.