Codexercise I.13.5 possible bug

Hi,

First of all, thank you for your excellent study materials and codexercises, they really thoughtful and engaging. My issue might be a duplicate of something, if so – sorry for that.

Was recently solving Codexercise I.13.5, tried this solution:

def four_qubit_mcx_only_tofs():
    # We will initialize the control qubits in state |1> so you can see
    # how the output state gets changed.
    qp.PauliX(wires=0)
    qp.PauliX(wires=1)
    qp.PauliX(wires=2)

    ##################
    # YOUR CODE HERE #
    ##################

    # IMPLEMENT A 3-CONTROLLED NOT WITH TOFFOLIS
    qp.Toffoli(wires=[1,2,3])
    qp.Toffoli(wires=[0,3,4])
    qp.Toffoli(wires=[1,2,3])
    return qp.state()

and the scoring system outputed the following error:

Error: Your gates are not applied to the correct wires

While I have found the correct implementation, the one I’ve shown above seem to provide with the same result. Is this error done intentionally (and if so, what was the intention), or is it a scoring system bug?

PS: I guess this order should work too:

qp.Toffoli(wires=[0,2,3])
qp.Toffoli(wires=[1,3,4])
qp.Toffoli(wires=[0,2,3])

Hi @Anton_Naumov, welcome to the Forum, and thank you for your kind words!

We love hearing that you find the material thoughtful and engaging, and I’ve shared your feedback with our team.

You’ve raised a great question. We are going to look into this and get back to you!

Hi @Anton_Naumov,
Thanks for your report and the clear examples! You’re absolutely right, this is a bug on our side, not an error in your solution.

The answers you found are perfectly valid implementations of the 3-controlled-NOT in codercise I.13.5. Indeed there are 3 possible solutions that produce the same final state. For example, starting from your initial circuit, it can be turned into our current implementation by permuting the 0th wire with the 1st and 2nd one.

We’ll correct the scoring system in the upcoming weeks and follow up here once it’s done.
Thanks again for taking the time to flag this issue, this really helps us improve the Codebook!

Thanks, happy to be of use :slight_smile:

1 Like

Hi @Anton_Naumov,
I just wanted to let you know that we have fixed this codercise :slight_smile:
Thanks again for letting us know and I hope you continue enjoying the exercises!

1 Like