Ask here about the “Are You Shor This Works?” Codebook topic from the “Quantum Error Correction” module.
Hello,
Here is my code for shor’s code
##################
# YOUR CODE HERE #
##################
qml.QubitStateVector(state, wires=[0])
qml.CNOT(0,3)
qml.CNOT(0,6)
qml.Hadamard(0)
qml.Hadamard(3)
qml.Hadamard(6)
qml.CNOT(0,1)
qml.CNOT(0,2)
qml.CNOT(3,4)
qml.CNOT(3,5)
qml.CNOT(6,7)
qml.CNOT(6,8)
# apply the error
for err in error(error_type=error_type, wires=wires):
err
##################
# YOUR CODE HERE #
##################
qml.CNOT(0,1)
qml.CNOT(0,2)
qml.Toffoli([1,2,0])
qml.CNOT(3,4)
qml.CNOT(3,5)
qml.Toffoli([4,5,3])
qml.CNOT(6,7)
qml.CNOT(6,8)
qml.Toffoli([7,8,6])
qml.Hadamard(0)
qml.Hadamard(3)
qml.Hadamard(6)
qml.CNOT(0,3)
qml.CNOT(0,6)
qml.Toffoli([6,3,0])
I get an error: ‘int’ object is not subscriptable, and I can’t understand where it comes from
I have a second question : Is there a way to convert qml.probs’s output to a numpy array ?
Hi @yoshypdf ,
The error “‘int’ object is not subscriptable” arises because the CNOTs don’t take two arguments, they take a single argument which is a list of wires.
So instead of having qml.CNOT(0,3)
you should write qml.CNOT([0,3])
.
I hope this helps!
Note: I’ve blurred out your answer to avoid spoilers for others.
1 Like
The output should indeed be a numpy array when you’re using the Numpy interface (which is what we use in the Codebook).