TransWikia.com

Generate a 3-qubit SWAP unitary in terms of elementary gates

Quantum Computing Asked on August 9, 2021

I wish to generate the following unitary

[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,0,1,0,0,0;
0,0,0,1,0,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;]

However the three qubit Toffoli and Fredkin gates do not appear to generate this. Does anyone know a simple way to generate this unitary? It seems to me that it should not be hard to produce as it is so close to the identity.

2 Answers

By using similar ideas from this answer I have found this circuit:

Thought process:

The unitary is a permutation matrix that doesn't change bitstrings except $U |100rangle rightarrow |011rangle$ and $U |011rangle rightarrow |100rangle$ (identity action on the rest of the bitstrings). Here I am going to use Qiskit's indexing convention (qubit indexing in Qiskit $|q_2 q_1 q_0 rangle$). Note that the Toffoli gate and $2$ CNOT's after it will do the job for $U |011rangle rightarrow |100rangle$ and the same Tofalli with $2$ CNOTs before it will do the job for $U |100rangle rightarrow |011rangle$. How I came to this solution? I tried to write down a circuit only for these two bitstring transformations not worrying about the rest, then I have tried to correct the rest transformations by adding additional gates. Although this sounds good, actually this strategy didn't work perfectly but gave me a draft circuit...then I just started to play with that circuit and obtained this solution.

Qiskit code for prove:

from qiskit import *
import qiskit.quantum_info as qi

circuit = QuantumCircuit(3)

circuit.cx(2, 1)
circuit.cx(2, 0)
circuit.ccx(0, 1, 2)
circuit.cx(2, 1)
circuit.cx(2, 0)

matrix = qi.Operator(circuit)
print(matrix.data)

The output (the matrix that corresponds to the circuit):

[[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 0 1 0 0 0]
 [0 0 0 1 0 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]]

Correct answer by Davit Khachatryan on August 9, 2021

Qiskit supports gates defined by arbitrary unitary matrices and unitary synthesis.

First, define the matrix as a Numpy array, convert it into a gate and add it to a circuit:

import numpy as np
from qiskit import QuantumCircuit
from qiskit.extensions import UnitaryGate

matrix = np.array([[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,0,1,0,0,0],
                   [0,0,0,1,0,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]], dtype=np.complex)

circuit = QuantumCircuit(3)
circuit.append(UnitaryGate(matrix), [0,1,2])

Then, transpile it into your desired basis (the current synthesizer only supports 1q- and 2q-gates basis):

from qiskit import transpile

new_circuit = transpile(circuit, basis_gates=['cx', 'u1', 'u2', 'u3'])
new_circuit.draw('mpl')

enter image description here

You can check the equivalence with Operator

from qiskit.quantum_info import Operator
Operator(new_circuit).equiv(circuit)
True

Answered by luciano on August 9, 2021

Add your own answers!

Ask a Question

Get help from others!

© 2024 TransWikia.com. All rights reserved. Sites we Love: PCI Database, UKBizDB, Menu Kuliner, Sharing RPP