[Design] vstate.expect_and_grad
Created by: PhilipVinc
The current vstate.expect_and_grad(op)
returns the conjugate gradient of the expectation value of an operator.
A good thing would be to add conjugate=True/False (default False?)
kwarg to return the conjugate or non-conjugate gradient.
But there's a catch: if the operator is hermitian, the gradient is computed as we usually do, with the formula ⟨OₖEˡ⟩
where the Eˡ
is the centered local estimator.
If the operator is non hermitian, we use a different formula relying on something like ⟨OₖEˡ⟩-⟨∇Eˡ⟩
, obtained through autodiff.
However in some cases one wants to use the hermitian formula even if the operator is non hermitian.
An example is time-evolution (cc @femtobit ) of non-hermitian hamiltonians or the lindblad (which is non hermitian), which require a gradient of the form ⟨OₖEˡ⟩
.
The reason is that, in those cases, one does not really want the gradient of the expectation value but something different, which happens, for hermitian operators, to match the gradient of the exp.val.
So how should the API behave in those cases?
Right now it is possible to pick an implementation by specifying is_hermitian=True/False
(the default is None, which means that it checks the operator).
But I think this keyword is confusing.
Can we do better?