In Codercise I.8.3, we are told that " we’ll print the circuit using qml.draw
to investigate which operations were actually used under the hood." However, this is the output I see even though my submission was accepted as correct.

Here is my code
v = np.array([0.52889389-0.14956775j, 0.67262317+0.49545818j])
dev = qml.device("default.qubit", wires=1)
@qml.qnode(dev)
def prepare_state(state=v): qml.MottonenStatePreparation(state_vector=state, wires=0) return qml.state()
prepare_state(state=v) print() print(qml.draw(prepare_state)(v))
Thank you for pointing this out @Kamal_Mohamed!
We should add expansion_strategy='device'
in the qml.draw statement in order to see the gates.
Would you like to open an issue about this in the Codebook GitHub repo?
For sure. Here is the link to it.
Error: ufunc ‘isfinite’ not supported for the input types, and the inputs could not be safely coerced to any supported types according to the casting rule ‘‘safe’’. I am getting this error
v = np.array([0.52889389-0.14956775j, 0.67262317+0.49545818j])
##################
# YOUR CODE HERE #
##################
# CREATE A DEVICE
# CONSTRUCT A QNODE THAT USES qml.MottonenStatePreparation
# TO PREPARE A QUBIT IN STATE V, AND RETURN THE STATE
def prepare_state(state=v):
qml.MottonenStatePreparation(state,wires = 0)
return qml.state()
# This will draw the quantum circuit and allow you to inspect the output gates
print(prepare_state(v))
print()
print(qml.draw(prepare_state, expansion_strategy='device')(v))
Hey @SUDHIR_KUMAR_SAHOO, welcome to the forum!
You need to create a device and decorate your prepare_state
function with @qml.qnode
. This part of our documentation is a good resource to look at in order to understand what’s going on here: Quantum circuits — PennyLane 0.34.0 documentation
Let me know if that helps!