2
$\begingroup$

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.

$\endgroup$
4
$\begingroup$

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)
$\endgroup$
2
  • $\begingroup$ 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? $\endgroup$
    – Pam
    Feb 22 at 5:26
  • 1
    $\begingroup$ I added the script of code that shows you how to do the decomposition in Qiskit. $\endgroup$
    – KAJ226
    Feb 22 at 5:33
1
$\begingroup$

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

$\endgroup$

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.