Codercise E.3.2 - The circuit for Shor's code

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?

Hi!
Thanks for your question.
For now, I see two things that are going wrong. First, the first Hadamard transformation is being applied onto wires 0, 3, and 6, but in your code seems to being done on 0,1, and 2. Second, there are four Toffoli gates missing in your code. The ones that look like double-CNOTs.

I hope this helps.