PennyLane
Next

To attempt this challenge, please switch to a larger screen size.

Beginner
Quantum Chemistry

Hydro Bonding

Challenge statement

The Variational Quantum Eigensolver (VQE) algorithm has been touted as a game-changing near-term quantum algorithm. In particular, VQE is able to efficiently simulate low-energy properties of small molecules. In this challenge, you will calculate the energy of the hydrogen molecule bond lengths.

Challenge code

In the code below, you are given a few functions:

  • hydrogen_hamiltonian: This function will return the qubit Hamiltonian of the hydrogen molecule, H_2, given the coordinates of both hydrogen atoms.
  • hf: The "HF" stands for Hartree–Fock. This function's purpose is calculate the HF approximation — treat every electron as independent, electrons move under a Coulomb potential from the positively charged nuclei, and there's a mean field from the other electrons — for the ground state of the hydrogen molecule we're interested in. We'll use this later, so you must complete this function.
  • run_VQE: This function takes the coordinates, generates the HF state, defines a cost function and minimizes it. You must complete this function by:
    • defining the gates within the cost function, using the qml.AllSinglesDoubles template with singles and doubles arguments defined below; and
    • returning what we want to minimize, namely the expectation value of the hydrogen Hamiltonian!

Here are some helpful resources:

  • Building molecular Hamiltonians
  • A brief overview of VQE
  • Variational Quantum Eigensolver
  • Quantum Chemistry documentation

Input

As input to this problem, you are given:

  • coordinates (list(float)): the x, y, and z coordinates of each hydrogen atom

Output

This code must output the ground state energy (float) of the hydrogen molecule in question.

Test cases

The following public test cases are available to you. Note that there are additional hidden test cases that we use to verify that your code is valid in full generality.

test_input: [0.0, 0.0, -0.8, 0.0, 0.0, 0.8] expected_output: -1.1288156435018968 test_input: [0.0, 0.0, -0.45, 0.0, 0.0, 0.45] expected_output: -1.0310430254415315

If your solution matches the correct one within the given tolerance specified in check (in this case it's a 1e-3 relative error tolerance), the output will be "Success!". Otherwise, you will receive an "Incorrect" prompt.

Good luck!

Loading...