How to create Hartree-Fock Hamiltonian

Hello everyone! Is there a way to construct HF hamiltonian in Pennylane? I’m referring to the one which is diagonal in the basis of Slater determinants and defined by the energies of the single determinant Hartree-Fock approximate ground state and its excitations. As I understand, hf.generate_hamiltonian and qchem.molecular_hamiltonian are both creating standard second-quantized hamiltonian for a given molecule. The one I’m seeking is used in this paper as mixer hamiltonian for QAOA. I’m not sure what is the difference with molecular hamiltonian and how to construct this mixer.

Hi @underforestaaa, welcome to the forum!

If you need a mixer hamiltonian for QAOA then this demo can be very helpful.

With only a few lines of code you can find the cost hamiltonian and the mixer hamiltonian.

from pennylane import qaoa
import networkx as nx

edges = [(0, 1), (1, 2), (2, 0), (2, 3)]
graph = nx.Graph(edges)
cost_h, mixer_h = qaoa.min_vertex_cover(graph, constrained=False)

You can also check the docs for Hamiltonian operators here.

If you’re looking for something different please let me know. I hope this helps!