I found very useful using class Hamiltonian ( coeffs , observables , simplify=False )[link] for VQE.
It would be nice if I could also use it for the eigenvalues and eigenvectors of the constructed Hamiltonian. Is there any way to do this?

Hi @Antonio_Mele,

Thank you for your question and welcome to the forum!

I am not sure that I have completely understood the context of your question.

If you want to use the Hamiltonian class to represent a Hamiltonian observable in terms of its eigenvalues and eigenvectors, that should be possible. Please, see the “Example” section here illustrating how the user can provide custom observables to build a Hamiltonian object.

If your question points in a different direction, feel free to elaborate/provide more details about your specific problem and we would be happy to help with this.

Thank you!

Hi @Alain_Delgado_Gran, thanks for your reply.

Hamiltonian class has no attribute eigvals which could allow me to compute its spectrum.
I am using it in order to deal with class ExpvalCost, because I think that it allows me to save time in implementing VQE.
In order to benchmark the result of my VQE, it would be comfortable if I can extract also the exact ground state energy directly by this Hamiltonian. In this way I could compare E_{VQE} and E_{exact}.
Of course I could construct the same Hamiltonian in other different ways and diagonalize it, but I was wondering if I could do it using Hamiltonian.

Thank you so much for your attention.

Hi @Antonio_Mele,

Thank you for the explanation.

That’s right!

Currently, this functionality is not implemented within the Hamiltonian class. Thank you very much for your feedback. We will discuss this possibility with the PennyLane team.

Are you using VQE to simulate a molecular Hamiltonian? If this is the case, you could use openfermionpyscf or openfermionpsi4 plugins (for example, see HERE) to benchmark the VQE energy. If you experience issues using openfermion plugins feel free to post your code, we will be happy to help with this.

Best regards.

Thank you so much! No, I am not using it to simulate a molecular Hamiltonian, but to study some spin models.

Best regards.