PennyLane
Previous

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

Beginner
Getting Started

States and Probabilities

Challenge statement

In PennyLane, the fundamental unit of quantum circuit simulation is called a QNode. Basically, a QNode takes a quantum function—a Python function that contains instructions in the form of quantum gates acting on wires—and a device,then runs the function on the device, and returns a measurement. To see how this works, check out our YouTube video.

In this challenge, you need to simulate the following quantum circuit and return the resulting probability distribution as an output:

Challenge code

In the template code provided, you are given a function called circuit. You must complete this function by specifying a device, turning circuit into a QNode, and providing the appropriate gates.

Here are some helpful resources:

  • Creating a quantum circuit — YouTube video
  • Basic tutorial: qubit rotation
  • Quantum circuits in PennyLane

Input

As input to this problem, you are given two angles (list(float)). The first and second entries of angles correspond to \theta_0 and \theta_1 in the diagram above.

Output

This code must output the probabilities (numpy.tensor(float)) of measuring the output states \vert 00 \rangle, \vert 01 \rangle, \vert 10 \rangle, and \vert 11 \rangle in that order resulting from the quantum circuit pictured above.

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.23, 4.56] expected_output: [0.28293, 0.38419, 0.14117, 0.19171] test_input: [7.89, 0.12] expected_output: [0.48026, 0.00173, 0.51614, 0.00186]

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...