Why this returns Error: Incorrect: The output of ctrl_circuit doesn’t look quite right!.
dev = qml.device("default.qubit", wires=3)
@qml.qnode(dev)
def ctrl_circuit(theta, phi):
# Left column
qml.RY(phi, wires=0)
qml.H(wires=1)
qml.RX(theta, wires=2)
# Middle column
qml.ctrl(qml.S, control=0)(wires=1) # black dot control
qml.X(wires=1) # white dot on control-0
qml.ctrl(qml.T, control=1)(wires=2)
qml.X(wires=1)
# Right column
qml.H(wires=0)
return qml.state()
Hi @l.a.moncayo-martinez, welcome to the Forum!
You are very close to the correct answer. However, notice the wire coming out the Hadamard in what you called “right column”. It is a controlled Hadamard. Fixing that should give you the right answer.
I hope this helps.
Absolutely. Thanks,
dev = qml.device("default.qubit", wires = 3)
@qml.qnode(dev)
def ctrl_circuit(theta,phi):
"""Implements the circuit shown in the Codercise statement
Args:
theta (float): Rotation angle for RX
phi (float): Rotation angle for RY
Returns:
(numpy.array): The output state of the QNode
"""
####################
###YOUR CODE HERE###
####################
qml.RY(phi, wires=0)
qml.Hadamard(wires=1)
qml.RX(theta, wires=2)
# Controlled-S (control=0, target=1) — standard control (●)
qml.ctrl(qml.S, control=0)(wires=1)
# Controlled-T with inverted control (○ control=1, target=2)
qml.X(wires=1) # Flip qubit 1 to simulate control-|0⟩
qml.ctrl(qml.T, control=1)(wires=2)
qml.X(wires=1) # Flip back
# Controlled-H (control=0, target=2) — standard control (●)
qml.ctrl(qml.Hadamard, control=2)(wires=0)
return qml.state()
1 Like