PennyLane
PreviousNext

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

Beginner
Hamiltonians

A Simple Trotterization

Challenge Statement

The Hamiltonian H of a quantum system is the observable that measures its total energy. A surprising result in physics is that we can use this operator to calculate how a given quantum system evolves in time. An initial state \vert \psi\rangle will, after a time t, evolve into U(t)\vert \psi\rangle, where

U(t) = \exp(-iHt)

is a unitary operator. The symbol \textrm{exp} denotes the matrix exponential, which isn't always easy to calculate. However, we can build quantum circuits that approximately apply U(t). One method to do this is known as Trotterization. When the Hamiltonian is a sum

H = \sum_{i=1}^kH_i

of a number k of Hermitian operators H_i that do not necessarily commute, we can approximate U via

U(t) \approx \prod_{j=1}^{n}\prod_{i=1}^k\exp(-iH_i t/n).

Here, n \in \mathbb{N}^{+} is known as the Trotterization depth. The larger n is, the better the approximation of U that we get. As a quantum circuit, the Trotterization of U reads as in the figure below.

drawing

In tihs challenge, we will approximate the evolution of a one-dimensional spin-chain. A simplified version of a Hamiltonian that describes the interaction between two neighbouring spins is

H = \alpha X\otimes X + \beta Z\otimes Z.

Your task is to use a Trotterization approximation of depth n to simulate time evolution for a time t under this Hamiltonian. The parameters \alpha and \beta are to be kept arbitrary. You may find the IsingXX and IsingZZ gates useful for this problem.

Challenge code

You must complete the trotterize function to build the Trotterization of the Hamiltonian given above. You may not use PennyLane's built-in time evolution (qml.ApproxTimeEvolution, qml.evolve) nor qml.QubitUnitary, but feel free to check your answer locally using these built-in PennyLane functions!

Input

As input to this problem, you are given:

  • alpha (float): The coefficient \alpha of the X\otimes X term in the Hamiltonian.
  • beta (float): The coefficient \beta of the Z\otimes Z term in the Hamiltonian.
  • time (float): The period t over which the system evolves under the action of the Hamiltonian.
  • depth (int): The Trotterization depth n as explained above.

Output

This code will output a list(float) (list of real numbers) corresponding to the probabilities of measuring \lvert 00\rangle, \lvert 01\rangle, \lvert 10\rangle, and \lvert 11\rangle (in that order) of the Trotterization circuit that you implement in PennyLane. The initial state of the circuit is \lvert 00\rangle and all measurements are performed in the computational basis.

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.5,0.8,0.2,1] expected_output: [0.99003329, 0, 0, 0.00996671] test_input: [0.9,1.0,0.4,2] expected_output: [0.87590286, 0, 0, 0.12409714]

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

Good luck!

Loading...