PennyLane
Previous

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

Beginner
Quantum Circuits

Universality of Single-Qubit Gates

Challenge Statement

In quantum computing, we have two fundamental structures: states and operators, which we can represent with vectors and matrices respectively.

Vectors must have norm 1 (since they determine a sum of probabilities) and matrices must be unitary, i.e. U^{-1} = U^{\dagger} (to preserve the norm of the vectors). When building a quantum computer, we would like it to be able to generate any U operator we need. However, we cannot physically implement every possible operator, so the goal is to create subsets of gates or operators that are able to generate all the others.

It can be easily proved that in the case of one qubit, we can express any single-qubit unitary U in terms of rotations as follows:

U = e^{i\phi}R_Z(\gamma)R_X(\beta)R_Z(\alpha).

This means that R_X and R_Z form a universal set for single-qubit gates. That is why, in this challenge, you are asked to calculate the parameters \alpha, \beta, \gamma and \phi that generate given gate U.

To do so, you will use a variational method to find these parameters. Additionally, you must build an error function that tells us how close your matrix is to the input unitary U.

Note: Remember that if we write a gate U as A \cdot B, it means that B is executed first, and then A.

Challenge code

In this challenge, you must complete the following functions

  • get_matrix: Takes params as an input, which is a list(float) [\alpha, \beta, \gamma, \phi] of parameters. It returns the unitary matrix U = e^{i\phi}R_Z(\gamma)R_X(\beta)R_Z(\alpha) as an np.array(complex) of shape (2,2).
  • error: Takes params as in get_matrix above and a unitary U (np.array(complex) of shape (2,2)) as inputs. It returns a measure (float) that tells how close U is to the matrix e^{i\phi}R_Z(\gamma)R_X(\beta)R_Z(\alpha)

Once this is done, a small script will be given to optimize the algorithm looking for the best parameters using error as a cost function.

Input

As input to this problem, you are given a 2 \times 2 complex matrix that you will try to approximate.

Output

This code will calculate a list(float) containing the four parameters (\phi, \alpha, \beta, and \gamma) using the train_parameters function. Then, the code will output the associated matrix generated from get_matrix.

Test cases

The inputs and outputs for this problem are the same matrix. The input corresponds to the matrix that we want to approximate. The output is the matrix generated by get_matrix using the optimized parameters and your error function. Ideally, they are the same, but we will give you some leeway.

test_input: [[ 0.70710678, 0.70710678], [ 0.70710678, -0.70710678]] expected_output: [[ 0.70710678, 0.70710678], [ 0.70710678, -0.70710678]] test_input: [[ 1, 0], [ 0, -1]] expected_output: [[ 1, 0], [ 0, -1]]

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

Good luck!

Loading...