PennyLane
Previous

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

Intermediate
Quantum Chemistry

Ising Uprising

Challenge statement

This challenge is included in the QHack 2023 Flashback Badge Challenge event.

Consider a spin chain contains particles of spin 1/2 in each of its N sites. The spins may be pointing in the positive or negative z direction, and we consider that there may be an external magnetic field acting on the system.

drawing

Such a quantum system is described by the Transverse Ising Hamiltonian. For closed spin chain with a transverse magnetic field of intensity h, the Transverse Ising Hamiltonian reads

H = -\sum_{i=1}^{N}Z_{i}\otimes Z_{i+1} - h\sum_{i}^{N}X_{i}.

The subindices i indicate the spin site where the operators act. In a closed spin chain, we identify site N+1 with the first site.

In this challenge, we calculate the effect of external magnetic forces on the ground energy. Using the Variational Quantum Eigensolver (VQE) algorithm, we will compute the ground energy of a closed spin chain of length N=4.

Challenge code

In this challenge you will be given the following functions:

  • create_Hamiltonian: In which you build the Transverse Ising Hamiltonian for N=4 and a magnetic field intensity h. You must complete this function.
  • model: This QNode builds a general enough ansatz for the ground state. This circuit must depend on some parameters params, which you will later optimize. It returns the expectation value of the Hamiltonian for the output state of the circuit. You must complete this function.
  • train: This function returns the parameters that minimize the output of model. You must complete this function.

Input

As input to this problem, you are given:

  • h (float): The intensity of the magnetic field applied to the spin chain.

Output

This code will output a float corresponding to the energy of the ground state.

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: 1.0 expected_output: -5.226251859505506 test_input: 2.3 expected_output: -9.66382463698038

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

Good luck!

Loading...