In the theory section we have seen that the VQE algorithm aims to find the ground state energy of a Hamiltonian. Also, in Exercise V.2.1 we have calculated what the form of such a state should be. Now we will code the VQE algorithm estimate the values of the parameters that give the right ground state.
In the code below you are asked to write a VQE algorithm that finds the minimum energy of the following Hamiltonian:
You must complete the build_hamiltonian
function that returns this Hamiltonian. qml.dot
will be useful for you to do this. Then, you must complete the function run_vqe
that optimizes the parameters can returns the ground state energy of the Hamiltonian.
Note. The functions cost_function(observable,params)
and optimizer(observable,params)
remain available from previous exercises in node V.1, but you may also do this from scratch if you want to practice more! Also remember that the cost_function(observable,params)
uses qml.StronglyEntanglingLayers
as ansatz. You may choose the initial parameters to be random or fixed.
To interact with codercises, please switch to a larger screen size.
Learning Objectives: