3
$\begingroup$

How to implement a 3 qubit gate, that exchanges the level $|110\rangle$ and $|000\rangle$, with elementary gates (CNOT, SWAP, Toffoli, local gates, etc.(everything Qiskit allows)): $$ U=\pmatrix{ 0 & 0 & 0 & 0 & 0 & 0 & 1 & 0\\ 0 & 1 & 0 & 0 & 0 & 0 & 0 & 0\\ 0 & 0 & 1 & 0 & 0 & 0 & 0 & 0\\ 0 & 0 & 0 & 1 & 0 & 0 & 0 & 0\\ 0 & 0 & 0 & 0 & 1 & 0 & 0 & 0\\ 0 & 0 & 0 & 0 & 0 & 1 & 0 & 0\\ 1 & 0 & 0 & 0 & 0 & 0 & 0 & 0\\ 0 & 0 & 0 & 0 & 0 & 0 & 0 & 1\\ }=? $$ I tried to decompose the unitaries hamiltonian $U=\exp(-i\pi $$H$$)$ in the Zeeman basis, but it doesn't looks not very promising.

$\endgroup$
0

2 Answers 2

4
$\begingroup$

One simple idea would be to introduce an ancilla (I'm sure there will be protocols without an ancilla as well) that starts in $|0\rangle$. You can use a Toffoli (and some X gates) to flip the ancilla if the system is in the state $|000\rangle$. You can also do the same if it's in state $|110\rangle$. So, the ancilla is in state $|1\rangle$ if you need to flip the first two bits. In other words, two controlled-not gates will do the job. Then you just have to undo the computation of the ancilla.

enter image description here

I believe the following does the same without an ancilla (although you'll want to check it carefully: enter image description here

The theory was basically that controlled off the third qubit being 0, you essentially wanted to do a swap of the first two qubits (and swap can be composed of 3 controlled-nots). Except that swap usually preserves 00 and 11, switching 01 and 10, so if we perform an $X$ on one of the qubits, that means 01 and 10 are preserved, swapping 00 and 11. An initial construction would make many gates controlled off the third qubit, but it turns out these are unnecessary -- if the central toffoli does nothing, everything else cancels.

$\endgroup$
3
  • $\begingroup$ +1 thanks... $ $ $\endgroup$
    – draks ...
    Commented Sep 8, 2020 at 10:05
  • $\begingroup$ Just realised that this is a Fredkin gate modulo some NOTs, right? $\endgroup$
    – draks ...
    Commented Sep 11, 2020 at 5:59
  • $\begingroup$ Yes, indeed. NOTs both pre- and post-action on the control qubit and one of the others. $\endgroup$
    – DaftWullie
    Commented Sep 11, 2020 at 7:42
4
$\begingroup$

Adding to @DaftWullie's answer,

If you're only looking to implement a gate in Qiskit that swaps $\lvert000\rangle$ and $\lvert110\rangle$ without worrying about the underlying gates, the easiest way to do that would be to create a NumPy array containing the matrix and attach that to the circuit using QuantumCircuit.iso.

The code would look roughly like this:

from qiskit import QuantumCircuit, execute, Aer
import numpy as np

unitary = np.zeros((8,8))
unitary[0][6] = unitary[6][0] = 1
unitary[1][1] = unitary[2][2] = unitary[3][3] = unitary[4][4] = unitary[5][5] = unitary[7][7] = 1

ckt = QuantumCircuit(3)
ckt.iso(unitary, [0,1,2,3], [])
ckt.measure_all()

execute(ckt, backend=Aer.get_backend('qasm_simulator'), shots=1024).result()

# do what you want with the result 

Do keep in mind qiskit's "reverse-ordering" of qubits when you're playing around with this! Hope this helps...

$\endgroup$
1
  • $\begingroup$ +1 thanks, good hint for upcoming tasks... $\endgroup$
    – draks ...
    Commented Sep 8, 2020 at 10:05

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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