Important: qubit-ordering convention. In PennyLane, qubits are indexed numerically from left to right. Therefore, a state such as indicates that the first and third qubit (or, wires 0 and 2) are in state and the second, fourth, and fifth qubit are in state When drawing quantum circuits, our convention is that the leftmost (first) qubit is at the top of the circuit, such that qubits starting in state correspond to the circuit below:

A different convention, where qubit 0 is the rightmost qubit in the ket, is used in a number of other quantum computing software frameworks and resources. Always check the qubit ordering when you start using a new software library!

For this codercise, you will write a circuit in PennyLane that accepts an integer value, then prepares and returns the corresponding computational basis state vector (Assume a 3-qubit device). Try a few examples; does the appearance of the state vector match what you expect given the integer?

Hint.

You will find the numpy function np.binary_repr helpful for this challenge.

Hint.

There are two ways to solve this challenge. The first is to manipulate the individual qubits based on the bit values. The second is to use a built-in state preparation template. Check out the PennyLane template library and see if there are any predefined functions that will help you.

or to submit your code

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

Learning Objectives:

  • Construct the state of a multi-qubit system using the tensor product.
  • Define and apply separable operations to multiple qubits.