PennyLane
PreviousNext

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

Beginner
Quantum Circuits

Undo that Computation

Challenge statement

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

Some classical logical operations are irreversible. For instance,

\text{AND}(0, 0)= \text{AND}(0, 1)= \text{AND}(1, 0)= 0,

so given that \text{AND}(j, k) = 0, we can't tell the values of j and k.

AND

Put differently, there is no way to press ctrl-Z and learn what went in! In contrast, quantum circuits are built out of unitary gates, which are always reversible. We can always press ctrl-Z! How can we encode something irreversible, like an AND gate, into a quantum circuit? Aptly, the answer is a controlled Z gate! It encodes the classical operation into a phase:

CZ \vert j, k\rangle \mapsto (-1)^{\text{AND}(j, k)}\vert j, k\rangle.

A phase by itself is unobservable, so we need to interfere this state with some others to detect it. A simple way to do this is to use a controlled controlled Z gate, with some extra operations on either side:

AND

In this challenge, you are asked to figure out which operations to apply so that measurement on the first qubit is guaranteed to be in state \vert \text{AND}(j, k)\rangle.

Challenge code

In the code below, you are given a function called AND(j, k). You must complete this circuit and provide gates which implement a classical AND gate. More precisely, if the second and third qubits are in states \vert j\rangle and \vert k\rangle, the circuit should place the first qubit in state \vert\text{AND}(j, k)\rangle.

Inputs

As input to this problem, you are given two bits j (int) and k (int), encoded onto the second and third qubits for you.

Output

Your circuit must place the first qubit in basis state AND(j, k). This will be checked using qml.probs(wires = 0), which gives [1, 0] for \vert 0\rangle and [0, 1] for \vert 1\rangle.

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, 0] expected_output: [1, 0] test_input: [1, 1] expected_output: [0, 1]

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