Now that you've learned all about single-qubit gates, you have the tools to perform arbitrary quantum state preparation of a single qubit! State preparation takes place at the start of many algorithms. Given a target state we would like the qubit to be in, we need to figure out the sequence of operations that, acting on produces the desired state. Furthermore, we ideally want this sequence of operations to be as small as possible.

For this codercise, you will be asked to write a circuit that prepares the quantum state

up to a global phase using as few gates as possible.

Hint.

First look at the amplitudes of the target state, ignoring the complex phase. What operation sends to the state with the correct amplitudes? Then, determine which operation(s) would add the correct phase.

dev = qml.device("default.qubit", wires=1)


@qml.qnode(dev)
def prepare_state():
##################
# YOUR CODE HERE #
##################

# APPLY OPERATIONS TO PREPARE THE TARGET STATE

return qml.state()

or to submit your code

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

Learning Objectives:

  • Use this as a reference for all you've learned.
  • Combine gates to prepare specific quantum states.