PennyLane
Next

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

Advanced
Hamiltonians

A Noisy Heisenberg Model

Challenge statement

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

Consider a spin chain that contains particles of spin 1/2 in each of its N sites. We make this model more realistic by assuming that the spins may be pointing in any direction, and we consider that there may be an external magnetic field acting on the system.

When we model a closed spin chain of length N in which spins can point in any direction, we need to use the Heisenberg Hamiltonian. In the presence of an external magnetic field of intensity h, the Hamiltonian is given by

H = -\sum_{i=1}^{N}\left(J_x X_{i}\otimes X_{i+1}+J_y Y_{i}\otimes Y_{i+1}+J_z Z_{i}\otimes Z_{i+1}\right) - h\sum_{i=1}^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. The coefficients J_x, J_y and J_z are known as coupling constants and they measure the strength of the interaction between neighbouring spins.

We would like to estimate how the noise affects Hamiltonian evolution. Your task is to build a Trotterization circuit that simulates U=\exp{(-iHt)}. This circuit must only contain RX, RY, RZ, and CNOT gates. Moreover, to make the Trotterization more realisitc, we will introduce noise on the target qubit of every execution of a CNOT gate. We model this via a Depolarizing Channel with parameter p. To quantify the effects of noise, you are asked to find the fidelity between this noisy Trotterization and the noiseless one.

Challenge code

You must complete the heisenberg_trotter that implements the Trotterization of the Heisenberg Hamiltonian for N=4 using only the following PennyLane gates: qml.RX qml.RY, qml.RZ, qml.CNOT, and qml.DepolarizingChannel. This function will return a quantum state. You should also minimize the number of CNOT gates as much as you can, in order to avoid noise. To verify that the that the Trotterization that you proposed is not excessively noisy, we will calculate for you the fidelity of your output state with respect to the noiseless case using the calculate_fidelity function.

Input

As input to this problem, you are given:

  • couplings (list(float)): An array of length 4 that contains the coupling constants and the magnetic field strength, in the order [J_x, J_y, J_z, h].
  • p (float): The depolarization probability on the target qubit after each CNOT gate.
  • depth (int): The Trotterization depth.
  • time (float): Time during which the state evolves.

Output

This code will output a float corresponding to the fidelity between the output states of the noisy and noiseless trotterizations, calculated from the output of heisenberg_trotter. The outputs in the test cases correspond to the minimal fidelity that you should achieve if you used a small enough amount of CNOT gates.

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,2,1,0.3],0.05,2.5,1] expected_output: 0.33723981123369573 test_input: [[1,3,2,0.3],0.05,2.5,2] expected_output: 0.15411351752086694

If your fidelity is larger, up to a tolerance of 0.005, of that specified in the output cases, the output will be "Success!". Otherwise, you will receive an "Incorrect" prompt.

Good luck!

Loading...