Using qml.StatePrep write the state_preparation QNode that prepares a quantum state proportional to

Note that state_preparation takes the complex numbers (alpha), (beta), and (gamma) as arguments.

Do not assume that this state is normalized. That is, it might be the case that

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

@qml.qnode(dev)
def prep_circuit(alpha, beta, gamma):
"""
Prepares the state alpha|001> + beta|010> + gamma|100>.
Args:
alpha, beta, gamma (np.complex): The coefficients of the quantum state
to prepare.
Returns:
(np.array): The quantum state
"""

####################
###YOUR CODE HERE###
####################
return qml.state()

alpha, beta, gamma = 1/np.sqrt(3), 1/np.sqrt(3), 1/np.sqrt(3),

print("The prepared state is", prep_circuit(alpha, beta, gamma))

or to submit your code

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

Learning Objectives:

  • Use single- and multi-qubit gates in PennyLane.
  • Implement inverse operations and custom controlled gates.
  • Construct arbitraty gates from a unitary matrix or extract the matrix of a gate or circuit.