3

I want to implement the $\sqrt{iSWAP}$ operator using simple operations in Qiskit such as it is done for the $iSWAP$ here or $\sqrt{SWAP}$ gate here. How can I do this? If possible I would like to know what 'methods' do people use to find such decomposition.

Apo
  • 545
  • 2
  • 10

2 Answers2

5

Given that the

$$\sqrt{iSWAP} = \begin{pmatrix} 1 & 0 & 0 & 0\\ 0 & 1/\sqrt{2} & i/\sqrt{2} & 0 \\ 0 & i/\sqrt{2} & 1/\sqrt{2} & 0 \\ 0 & 0 & 0 & 1 \end{pmatrix} $$

then we can use the decompose method in qiskit to get the set of elementary gates that would be implement on IBM hardware, which comes out to be:

enter image description here

You can use quirk to do the something similar I believe. Now, recently IBM changes its native set of gates to $\{ CZ, ID, RZ, SX, X \}$. So to see how this being implement on the hardware you can use the transpilation method. Which will transpile the above circuit to the following circuit on 'ibmq_athens':

enter image description here


If you wish to do the decomposition within qiskit, you can use the following script:

from qiskit.quantum_info.operators import Operator
from qiskit import QuantumCircuit, QuantumRegister
import numpy as np
sqrt2 = np.sqrt(2)
controls = QuantumRegister(2)
circuit = QuantumCircuit(controls)
Matrix = Operator( [
    [1, 0, 0, 0],
    [0, 1/sqrt2, 1j/sqrt2, 0],
    [0, 1j/sqrt2, 1/sqrt2, 0],
    [0, 0, 0, 1] ])
circuit.unitary(Matrix, [0,1])
decomp = QuantumCircuit.decompose(circuit) 
print(decomp)

And the transpilation process can be done as:

from qiskit.compiler import transpile
provider = IBMQ.load_account()
Circuit_Transpile = transpile(decomp, provider.get_backend('ibmq_athens') , optimization_level=3)
print(Circuit_Transpile)
KAJ226
  • 13,822
  • 2
  • 10
  • 30
  • Thank you! How would a basic code look like fo rusing the decompose method? do I need to construct the circuit with the corresponding gate I want to decompose? – Apo Feb 22 '21 at 05:26
  • 1
    I added the script of code that shows you how to do the decomposition in Qiskit. – KAJ226 Feb 22 '21 at 05:33
2

It is possible to create a $\sqrt{iSWAP}$ gate like this:

from qiskit.circuit.library import iSwapGate
sqrt_iSWAP = iSwapGate().power(1/2)

The matrix representation is the following:

from qiskit.visualization import array_to_latex
array_to_latex(sqrt_iSWAP.to_matrix())

$$ \begin{bmatrix} 1 & 0 & 0 & 0 \\ 0 & \tfrac{1}{\sqrt{2}} & \tfrac{1}{\sqrt{2}}i & 0 \\ 0 & \tfrac{1}{\sqrt{2}}i & \tfrac{1}{\sqrt{2}} & 0 \\ 0 & 0 & 0 & 1 \\ \end{bmatrix} $$

You can add that gate to a circuit as follow:

from qiskit import QuantumCircuit

circuit = QuantumCircuit(2) circuit.append(sqrt_iSWAP, [0, 1])

circuit.draw('mpl')

enter image description here

Following, transpiled to the IBMQ Athena backend:

from qiskit.compiler import transpile
from qiskit import IBMQ

provider = IBMQ.load_account() transpiled = transpile(circuit, provider.get_backend('ibmq_athens') , optimization_level=3) transpiled.draw('mpl', idle_wires=False)

enter image description here

luciano
  • 5,763
  • 1
  • 12
  • 34