PennyLane
PreviousNext

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

Beginner
Algorithms

Introduction to LCUs

Challenge statement

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

Suppose that we know a certain Hamiltonian H can be written as a linear combination of unitaries, that is

H = \sum_{i}\alpha_i U_i.

We know that quantum circuits can implement unitary operations really easily, but is there a way to implement a sum of unitaries? Note that the sum of unitaries is not always a unitary, so how can we even do this? We can use measurements!

A circuit of the form

drawing

will probabilistically implement the combination of unitaries \alpha U +\beta V on the bottom (main) register, where \alpha and \beta are positive real numbers, without loss of generality. Here, the single-qubit unitary W(\alpha,\beta) is represented by the matrix

W(\alpha,\beta)= \frac{1}{\sqrt{\alpha+\beta}}\begin{pmatrix} \sqrt{\alpha} & -\sqrt{\beta} \\ \sqrt{\beta} & \sqrt{\alpha} \end{pmatrix}

The combination will only be applied on the bottom (main) register when we measure the state of the top (auxiliary) register to be \vert 0 \rangle.

Your task is to calculate the probability that this the linear combination of unitaries is implemented with the circuit above.

Challenge code

You must complete the linear_combination function to build the above circuit that implements the linear combination

\alpha U + \beta V

of two single-qubit unitaries U and V, and returns the probabilities on the auxiliary register. For simplicity, we take \alpha and \beta to be positive real numbers.

As a helper function, you are also asked to complete the W function, which returns the unitary W(\alpha,\beta).

Input

As input to this problem, you are given:

  • U (list(list(float))): A 2\times 2 matrix representing the single-qubit unitary operator U.
  • V (list(list(float))): A 2\times 2 matrix representing the single-qubit unitary operator V
  • alpha (float): The prefactor \alpha of U in the linear combination, as above.
  • beta (float): The prefactor \beta of V in the linear combination, as above.

Output

The output used to test your solution is a float corresponding to the probability of measuring \vert 0 \rangle on the auxiliary register. This is the first element of your output of linear_combination. We will extract this element for you in our testing functions!

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.70710678, 0.70710678], [ 0.70710678, -0.70710678]],[[1, 0], [0, -1]], 1, 3] expected_output: 0.8901650422902458

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

Good luck!

Loading...