1
$\begingroup$

I am creating the following circuit with Qiskit (2Toffoli gates controlled with coins) enter image description here

And to set the coins for one iteration of the circuit i do the following :

qsubnodes = QuantumRegister(2)
qsubnodes = QuantumRegister(2)
qc.h(subnode[0])
qc.h(subnode[1])

and then for the first Toffoli gate:

qc.ccx(subnode[0], subnode[1], *q) 

and the second toffoli gate (which is the issue) :

qc.h(subnode[0])
qc.h(subnode[1])
qc.x(subnode[1]) // to invert the coin to control for 0 (as shown in the circuit)
qc.ccx(subnode[0], subnode[1], *q)

Is it the right way of inverting the coin for the second toffoli ?

Thank you,

$\endgroup$
1
$\begingroup$

According to your circuit diagram, the second Toffoli should act in case "lower" qubit is in state $|1\rangle$ and "upper" one in state $|0\rangle$. Since Toffoli acts only in case both inputs are in state $|1\rangle$, you have to invert "upper" qubit, or in other words to apply $X$ there.

So it seems that your construction is right. To test this, try to prepare circuit containing one Toffoli gate with $X$ applied on one of its input. Set a input of the circuit to $|01\rangle$ or $|10\rangle$ depending on which Toffoli's input is neggated and try to measure Toffoli's output; you should get $|1\rangle$.

|improve this answer|||||
$\endgroup$
  • 1
    $\begingroup$ Thanks man, sure i will test with your inputs $\endgroup$ – Django Ace Feb 22 at 23:08

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.