dev = qml.device("default.qubit", wires=9)
@qml.qnode(dev)
def shor(state, error_type, wires):
"""A quantum circuit that implements Shor's 9-qubit code
Args:
state (tensor): a numpy array representing a 1-qubit state: alpha |0> + beta |1>
This is used to initialize the 0th wire with qml.StatePrep
error_type (str): for example, XX, YY, XZ, YZ.
wires (list(int)): the wires the error acts on.
Returns:
(tuple(tensor, tensor)): the separate probability distributions over the 0th wire (|psi>)
and all 8 ancillary qubits in that order.
"""
##################
# YOUR CODE HERE #
##################
qml.StatePrep(state, wires=0)
# ENCODE
# bit-flip repetition on (0,1,2)
qml.CNOT(wires=[0, 1])
qml.CNOT(wires=[0, 2])
# convert phase flips to bit flips in H-basis
for i in [0, 1, 2]:
qml.Hadamard(wires=i)
# phase-flip repetition: fan out each of 0,1,2 to make three GHZ blocks
for i in [0, 1, 2]:
qml.CNOT(wires=[i, i + 3])
qml.CNOT(wires=[i, i + 6])
# apply the error
for err in error(error_type=error_type, wires=wires):
err
##################
# YOUR CODE HERE #
##################
# DECODE (inverse of encode)
# undo phase-flip repetition
for i in [0, 1, 2]:
qml.CNOT(wires=[i, i + 6])
qml.CNOT(wires=[i, i + 3])
# undo H-basis
for i in [0, 1, 2]:
qml.Hadamard(wires=i)
# undo bit-flip repetition
qml.CNOT(wires=[0, 2])
qml.CNOT(wires=[0, 1])
return qml.probs(wires=0), qml.probs(wires=range(1, 9))
I’m not sure where I’m going wrong here, can someone please guide me?