The code below is a quantum function with all the gates from the circuit shown below. However, the gates are out of order! Re-arrange the lines of the function to match the order of operations in the circuit.

def my_circuit(theta, phi):
##################
# YOUR CODE HERE #
##################

# REORDER THESE 5 GATES TO MATCH THE CIRCUIT IN THE PICTURE

qml.CNOT(wires=[0, 1])
qml.CNOT(wires=[2, 0])
qml.Hadamard(wires=0)
qml.RX(theta, wires=2)
qml.RY(phi, wires=1)

# This is the measurement; we return the probabilities of all possible output states
# You'll learn more about what types of measurements are available in a later node
return qml.probs(wires=[0, 1, 2])

or to submit your code

To interact with codercises, please switch to a larger screen size.

Learning Objectives:

  • Identify the different components of a quantum circuit (qubits, gates, and measurements).
  • Translate between sequences of instructions and a quantum circuit.
  • Define and calculate the depth of a quantum circuit.