QuTiP example: Quantum Gates and their usage

Author: Anubhav Vardhan (anubhavvardhan@gmail.com)

For more information about QuTiP see http://qutip.org

Note: The circuit image visualizations require ImageMagick for display.

ImageMagick can be easily installed with the command conda install imagemagick if you have conda installed. Otherwise, please follow the installation instructions on the ImageMagick documentation.


In [2]:
%matplotlib inline

In [3]:
from IPython.display import Image

In [4]:
from numpy import pi

In [5]:
from qutip import *

Introduction

Gates in QuTiP and their representation

Controlled-PHASE


In [6]:
cphase(pi/2)


Out[6]:
Quantum object: dims = [[2, 2], [2, 2]], shape = (4, 4), type = oper, isherm = False\begin{equation*}\left(\begin{array}{*{11}c}1.0 & 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.0 & 0.0 & 1.0j\\\end{array}\right)\end{equation*}

In [21]:
q = QubitCircuit(2, reverse_states=False)
q.add_gate("CSIGN", controls=[0], targets=[1])
q.png


Out[21]:

Rotation about X-axis


In [7]:
rx(pi/2)


Out[7]:
Quantum object: dims = [[2], [2]], shape = [2, 2], type = oper, isherm = False\begin{equation*}\left(\begin{array}{*{11}c}0.707 & -0.707j\\-0.707j & 0.707\\\end{array}\right)\end{equation*}

In [23]:
q = QubitCircuit(1, reverse_states=False)
q.add_gate("RX", targets=[0], arg_value=pi/2, arg_label=r'\frac{\pi}{2}')
q.png


Out[23]:

Rotation about Y-axis


In [9]:
ry(pi/2)


Out[9]:
Quantum object: dims = [[2], [2]], shape = [2, 2], type = oper, isherm = False\begin{equation*}\left(\begin{array}{*{11}c}0.707 & -0.707\\0.707 & 0.707\\\end{array}\right)\end{equation*}

In [24]:
q = QubitCircuit(1, reverse_states=False)
q.add_gate("RY", targets=[0], arg_value=pi/2, arg_label=r'\frac{\pi}{2}')
q.png


Out[24]:

Rotation about Z-axis


In [25]:
rz(pi/2)


Out[25]:
Quantum object: dims = [[2], [2]], shape = (2, 2), type = oper, isherm = False\begin{equation*}\left(\begin{array}{*{11}c}(0.707-0.707j) & 0.0\\0.0 & (0.707+0.707j)\\\end{array}\right)\end{equation*}

In [26]:
q = QubitCircuit(1, reverse_states=False)
q.add_gate("RZ", targets=[0], arg_value=pi/2, arg_label=r'\frac{\pi}{2}')
q.png


Out[26]:

CNOT


In [27]:
cnot()


Out[27]:
Quantum object: dims = [[2, 2], [2, 2]], shape = (4, 4), type = oper, isherm = True\begin{equation*}\left(\begin{array}{*{11}c}1.0 & 0.0 & 0.0 & 0.0\\0.0 & 1.0 & 0.0 & 0.0\\0.0 & 0.0 & 0.0 & 1.0\\0.0 & 0.0 & 1.0 & 0.0\\\end{array}\right)\end{equation*}

In [28]:
q = QubitCircuit(2, reverse_states=False)
q.add_gate("CNOT", controls=[0], targets=[1])
q.png


Out[28]:

CSIGN


In [29]:
csign()


Out[29]:
Quantum object: dims = [[2, 2], [2, 2]], shape = (4, 4), type = oper, isherm = True\begin{equation*}\left(\begin{array}{*{11}c}1.0 & 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.0 & 0.0 & -1.0\\\end{array}\right)\end{equation*}

In [31]:
q = QubitCircuit(2, reverse_states=False)
q.add_gate("CSIGN", controls=[0], targets=[1])
q.png


Out[31]:

Berkeley


In [32]:
berkeley()


Out[32]:
Quantum object: dims = [[2, 2], [2, 2]], shape = (4, 4), type = oper, isherm = False\begin{equation*}\left(\begin{array}{*{11}c}0.924 & 0.0 & 0.0 & 0.383j\\0.0 & 0.383 & 0.924j & 0.0\\0.0 & 0.924j & 0.383 & 0.0\\0.383j & 0.0 & 0.0 & 0.924\\\end{array}\right)\end{equation*}

In [35]:
q = QubitCircuit(2, reverse_states=False)
q.add_gate("BERKELEY", targets=[0, 1])
q.png


Out[35]:

SWAPalpha


In [36]:
swapalpha(pi/2)


Out[36]:
Quantum object: dims = [[2, 2], [2, 2]], shape = (4, 4), type = oper, isherm = False\begin{equation*}\left(\begin{array}{*{11}c}1.0 & 0.0 & 0.0 & 0.0\\0.0 & (0.610-0.488j) & (0.390+0.488j) & 0.0\\0.0 & (0.390+0.488j) & (0.610-0.488j) & 0.0\\0.0 & 0.0 & 0.0 & 1.0\\\end{array}\right)\end{equation*}

FREDKIN


In [21]:
fredkin()


Out[21]:
Quantum object: dims = [[2, 2, 2], [2, 2, 2]], shape = [8, 8], type = oper, isherm = True\begin{equation*}\left(\begin{array}{*{11}c}1.0 & 0.0 & 0.0 & 0.0 & 0.0 & 0.0 & 0.0 & 0.0\\0.0 & 1.0 & 0.0 & 0.0 & 0.0 & 0.0 & 0.0 & 0.0\\0.0 & 0.0 & 1.0 & 0.0 & 0.0 & 0.0 & 0.0 & 0.0\\0.0 & 0.0 & 0.0 & 1.0 & 0.0 & 0.0 & 0.0 & 0.0\\0.0 & 0.0 & 0.0 & 0.0 & 1.0 & 0.0 & 0.0 & 0.0\\0.0 & 0.0 & 0.0 & 0.0 & 0.0 & 0.0 & 1.0 & 0.0\\0.0 & 0.0 & 0.0 & 0.0 & 0.0 & 1.0 & 0.0 & 0.0\\0.0 & 0.0 & 0.0 & 0.0 & 0.0 & 0.0 & 0.0 & 1.0\\\end{array}\right)\end{equation*}

TOFFOLI


In [23]:
toffoli()


Out[23]:
Quantum object: dims = [[2, 2, 2], [2, 2, 2]], shape = [8, 8], type = oper, isherm = True\begin{equation*}\left(\begin{array}{*{11}c}1.0 & 0.0 & 0.0 & 0.0 & 0.0 & 0.0 & 0.0 & 0.0\\0.0 & 1.0 & 0.0 & 0.0 & 0.0 & 0.0 & 0.0 & 0.0\\0.0 & 0.0 & 1.0 & 0.0 & 0.0 & 0.0 & 0.0 & 0.0\\0.0 & 0.0 & 0.0 & 1.0 & 0.0 & 0.0 & 0.0 & 0.0\\0.0 & 0.0 & 0.0 & 0.0 & 1.0 & 0.0 & 0.0 & 0.0\\0.0 & 0.0 & 0.0 & 0.0 & 0.0 & 1.0 & 0.0 & 0.0\\0.0 & 0.0 & 0.0 & 0.0 & 0.0 & 0.0 & 0.0 & 1.0\\0.0 & 0.0 & 0.0 & 0.0 & 0.0 & 0.0 & 1.0 & 0.0\\\end{array}\right)\end{equation*}

SWAP


In [25]:
swap()


Out[25]:
Quantum object: dims = [[2, 2], [2, 2]], shape = [4, 4], type = oper, isherm = True\begin{equation*}\left(\begin{array}{*{11}c}1.0 & 0.0 & 0.0 & 0.0\\0.0 & 0.0 & 1.0 & 0.0\\0.0 & 1.0 & 0.0 & 0.0\\0.0 & 0.0 & 0.0 & 1.0\\\end{array}\right)\end{equation*}

ISWAP


In [27]:
iswap()


Out[27]:
Quantum object: dims = [[2, 2], [2, 2]], shape = [4, 4], type = oper, isherm = False\begin{equation*}\left(\begin{array}{*{11}c}1.0 & 0.0 & 0.0 & 0.0\\0.0 & 0.0 & 1.0j & 0.0\\0.0 & 1.0j & 0.0 & 0.0\\0.0 & 0.0 & 0.0 & 1.0\\\end{array}\right)\end{equation*}

SQRTiSWAP


In [29]:
sqrtiswap()


Out[29]:
Quantum object: dims = [[2, 2], [2, 2]], shape = [4, 4], type = oper, isherm = False\begin{equation*}\left(\begin{array}{*{11}c}1.0 & 0.0 & 0.0 & 0.0\\0.0 & 0.707 & 0.707j & 0.0\\0.0 & 0.707j & 0.707 & 0.0\\0.0 & 0.0 & 0.0 & 1.0\\\end{array}\right)\end{equation*}

SQRTSWAP


In [31]:
sqrtswap()


Out[31]:
Quantum object: dims = [[2, 2], [2, 2]], shape = [4, 4], type = oper, isherm = False\begin{equation*}\left(\begin{array}{*{11}c}1.0 & 0.0 & 0.0 & 0.0\\0.0 & (0.500+0.500j) & (0.500-0.500j) & 0.0\\0.0 & (0.500-0.500j) & (0.500+0.500j) & 0.0\\0.0 & 0.0 & 0.0 & 1.0\\\end{array}\right)\end{equation*}

SQRTNOT


In [33]:
sqrtnot()


Out[33]:
Quantum object: dims = [[2], [2]], shape = [2, 2], type = oper, isherm = False\begin{equation*}\left(\begin{array}{*{11}c}(0.500+0.500j) & (0.500-0.500j)\\(0.500-0.500j) & (0.500+0.500j)\\\end{array}\right)\end{equation*}

HADAMARD


In [35]:
snot()


Out[35]:
Quantum object: dims = [[2], [2]], shape = [2, 2], type = oper, isherm = True\begin{equation*}\left(\begin{array}{*{11}c}0.707 & 0.707\\0.707 & -0.707\\\end{array}\right)\end{equation*}

PHASEGATE


In [37]:
phasegate(pi/2)


Out[37]:
Quantum object: dims = [[2], [2]], shape = [2, 2], type = oper, isherm = False\begin{equation*}\left(\begin{array}{*{11}c}1.0 & 0.0\\0.0 & 1.0j\\\end{array}\right)\end{equation*}

GLOBALPHASE


In [39]:
globalphase(pi/2)


Out[39]:
Quantum object: dims = [[2], [2]], shape = [2, 2], type = oper, isherm = False\begin{equation*}\left(\begin{array}{*{11}c}1.0j & 0.0\\0.0 & 1.0j\\\end{array}\right)\end{equation*}

Expanding gates to larger qubit registers

The example above show how to generate matrice representations of the gates implemented in QuTiP, in their minimal qubit requirements. If the same gates is to be represented in a qubit register of size $N$, the optional keywork argument N can be specified when calling the gate function. For example, to generate the matrix for the CNOT gate for a $N=3$ bit register:


In [41]:
cnot(N=3)


Out[41]:
Quantum object: dims = [[2, 2, 2], [2, 2, 2]], shape = [8, 8], type = oper, isherm = True\begin{equation*}\left(\begin{array}{*{11}c}1.0 & 0.0 & 0.0 & 0.0 & 0.0 & 0.0 & 0.0 & 0.0\\0.0 & 1.0 & 0.0 & 0.0 & 0.0 & 0.0 & 0.0 & 0.0\\0.0 & 0.0 & 1.0 & 0.0 & 0.0 & 0.0 & 0.0 & 0.0\\0.0 & 0.0 & 0.0 & 1.0 & 0.0 & 0.0 & 0.0 & 0.0\\0.0 & 0.0 & 0.0 & 0.0 & 0.0 & 0.0 & 1.0 & 0.0\\0.0 & 0.0 & 0.0 & 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.0\\0.0 & 0.0 & 0.0 & 0.0 & 0.0 & 1.0 & 0.0 & 0.0\\\end{array}\right)\end{equation*}

In [39]:
q = QubitCircuit(3, reverse_states=False)
q.add_gate("CNOT", controls=[1], targets=[2])
q.png


Out[39]:

Furthermore, the control and target qubits (when applicable) can also be similarly specified using keyword arguments control and target (or in some cases controls or targets):


In [43]:
cnot(N=3, control=2, target=0)


Out[43]:
Quantum object: dims = [[2, 2, 2], [2, 2, 2]], shape = [8, 8], type = oper, isherm = True\begin{equation*}\left(\begin{array}{*{11}c}1.0 & 0.0 & 0.0 & 0.0 & 0.0 & 0.0 & 0.0 & 0.0\\0.0 & 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.0 & 0.0 & 0.0\\0.0 & 0.0 & 0.0 & 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.0\\0.0 & 1.0 & 0.0 & 0.0 & 0.0 & 0.0 & 0.0 & 0.0\\0.0 & 0.0 & 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.0 & 0.0\\\end{array}\right)\end{equation*}

In [40]:
q = QubitCircuit(3, reverse_states=False)
q.add_gate("CNOT", controls=[0], targets=[2])
q.png


Out[40]:

Setup of a Qubit Circuit

The gates implemented in QuTiP can be used to build any qubit circuit using the class QubitCircuit. The output can be obtained in the form of a unitary matrix or a latex representation.

In the following example, we take a SWAP gate. It is known that a swap gate is equivalent to three CNOT gates applied in the given format.


In [41]:
N = 2
qc0 = QubitCircuit(N)
qc0.add_gate("SWAP", [0, 1], None)
qc0.png


Out[41]:

In [42]:
U_list0 = qc0.propagators()
U0 = gate_sequence_product(U_list0)
U0


Out[42]:
Quantum object: dims = [[2, 2], [2, 2]], shape = (4, 4), type = oper, isherm = True\begin{equation*}\left(\begin{array}{*{11}c}1.0 & 0.0 & 0.0 & 0.0\\0.0 & 0.0 & 1.0 & 0.0\\0.0 & 1.0 & 0.0 & 0.0\\0.0 & 0.0 & 0.0 & 1.0\\\end{array}\right)\end{equation*}

In [43]:
qc1 = QubitCircuit(N)
qc1.add_gate("CNOT", 0, 1)
qc1.add_gate("CNOT", 1, 0)
qc1.add_gate("CNOT", 0, 1)
qc1.png


Out[43]:

In [44]:
U_list1 = qc1.propagators()
U1 = gate_sequence_product(U_list1)
U1


Out[44]:
Quantum object: dims = [[2, 2], [2, 2]], shape = (4, 4), type = oper, isherm = True\begin{equation*}\left(\begin{array}{*{11}c}1.0 & 0.0 & 0.0 & 0.0\\0.0 & 0.0 & 1.0 & 0.0\\0.0 & 1.0 & 0.0 & 0.0\\0.0 & 0.0 & 0.0 & 1.0\\\end{array}\right)\end{equation*}

In place of manually converting the SWAP gate to CNOTs, it can be automatically converted using an inbuilt function in QubitCircuit


In [45]:
qc2 = qc0.resolve_gates("CNOT")
qc2.png


Out[45]:

In [46]:
U_list2 = qc2.propagators()
U2 = gate_sequence_product(U_list2)
U2


Out[46]:
Quantum object: dims = [[2, 2], [2, 2]], shape = (4, 4), type = oper, isherm = True\begin{equation*}\left(\begin{array}{*{11}c}1.0 & 0.0 & 0.0 & 0.0\\0.0 & 0.0 & 1.0 & 0.0\\0.0 & 1.0 & 0.0 & 0.0\\0.0 & 0.0 & 0.0 & 1.0\\\end{array}\right)\end{equation*}

Example of basis transformation


In [47]:
qc3 = QubitCircuit(3)
qc3.add_gate("CNOT", 1, 0)
qc3.add_gate("RX", 0, None, pi/2, r"\pi/2")
qc3.add_gate("RY", 1, None, pi/2, r"\pi/2")
qc3.add_gate("RZ", 2, None, pi/2, r"\pi/2")
qc3.add_gate("ISWAP", [1, 2])
qc3.png


Out[47]:

In [48]:
U3 = gate_sequence_product(qc3.propagators())
U3


Out[48]:
Quantum object: dims = [[2, 2, 2], [2, 2, 2]], shape = (8, 8), type = oper, isherm = False\begin{equation*}\left(\begin{array}{*{11}c}(0.354-0.354j) & 0.0 & (-0.354+0.354j) & 0.0 & (0.354+0.354j) & 0.0 & (-0.354-0.354j) & 0.0\\(0.354+0.354j) & 0.0 & (0.354+0.354j) & 0.0 & (0.354-0.354j) & 0.0 & (0.354-0.354j) & 0.0\\0.0 & (-0.354+0.354j) & 0.0 & (0.354-0.354j) & 0.0 & (-0.354-0.354j) & 0.0 & (0.354+0.354j)\\0.0 & (0.354+0.354j) & 0.0 & (0.354+0.354j) & 0.0 & (0.354-0.354j) & 0.0 & (0.354-0.354j)\\(-0.354-0.354j) & 0.0 & (0.354+0.354j) & 0.0 & (-0.354+0.354j) & 0.0 & (0.354-0.354j) & 0.0\\(0.354-0.354j) & 0.0 & (0.354-0.354j) & 0.0 & (0.354+0.354j) & 0.0 & (0.354+0.354j) & 0.0\\0.0 & (0.354+0.354j) & 0.0 & (-0.354-0.354j) & 0.0 & (0.354-0.354j) & 0.0 & (-0.354+0.354j)\\0.0 & (0.354-0.354j) & 0.0 & (0.354-0.354j) & 0.0 & (0.354+0.354j) & 0.0 & (0.354+0.354j)\\\end{array}\right)\end{equation*}

The transformation can either be only in terms of 2-qubit gates:


In [49]:
qc4 = qc3.resolve_gates("CNOT")
qc4.png


Out[49]:

In [50]:
U4 = gate_sequence_product(qc4.propagators())
U4


Out[50]:
Quantum object: dims = [[2, 2, 2], [2, 2, 2]], shape = (8, 8), type = oper, isherm = False\begin{equation*}\left(\begin{array}{*{11}c}(0.354-0.354j) & 0.0 & (-0.354+0.354j) & 0.0 & (0.354+0.354j) & 0.0 & (-0.354-0.354j) & 0.0\\(0.354+0.354j) & 0.0 & (0.354+0.354j) & 0.0 & (0.354-0.354j) & 0.0 & (0.354-0.354j) & 0.0\\0.0 & (-0.354+0.354j) & 0.0 & (0.354-0.354j) & 0.0 & (-0.354-0.354j) & 0.0 & (0.354+0.354j)\\0.0 & (0.354+0.354j) & 0.0 & (0.354+0.354j) & 0.0 & (0.354-0.354j) & 0.0 & (0.354-0.354j)\\(-0.354-0.354j) & 0.0 & (0.354+0.354j) & 0.0 & (-0.354+0.354j) & 0.0 & (0.354-0.354j) & 0.0\\(0.354-0.354j) & 0.0 & (0.354-0.354j) & 0.0 & (0.354+0.354j) & 0.0 & (0.354+0.354j) & 0.0\\0.0 & (0.354+0.354j) & 0.0 & (-0.354-0.354j) & 0.0 & (0.354-0.354j) & 0.0 & (-0.354+0.354j)\\0.0 & (0.354-0.354j) & 0.0 & (0.354-0.354j) & 0.0 & (0.354+0.354j) & 0.0 & (0.354+0.354j)\\\end{array}\right)\end{equation*}

In [51]:
qc5 = qc3.resolve_gates("ISWAP")
qc5.png


Out[51]:

In [52]:
U5 = gate_sequence_product(qc5.propagators())
U5


Out[52]:
Quantum object: dims = [[2, 2, 2], [2, 2, 2]], shape = (8, 8), type = oper, isherm = False\begin{equation*}\left(\begin{array}{*{11}c}(0.354-0.354j) & 0.0 & (-0.354+0.354j) & 0.0 & (0.354+0.354j) & 0.0 & (-0.354-0.354j) & 0.0\\(0.354+0.354j) & 0.0 & (0.354+0.354j) & 0.0 & (0.354-0.354j) & 0.0 & (0.354-0.354j) & 0.0\\0.0 & (-0.354+0.354j) & 0.0 & (0.354-0.354j) & 0.0 & (-0.354-0.354j) & 0.0 & (0.354+0.354j)\\0.0 & (0.354+0.354j) & 0.0 & (0.354+0.354j) & 0.0 & (0.354-0.354j) & 0.0 & (0.354-0.354j)\\(-0.354-0.354j) & 0.0 & (0.354+0.354j) & 0.0 & (-0.354+0.354j) & 0.0 & (0.354-0.354j) & 0.0\\(0.354-0.354j) & 0.0 & (0.354-0.354j) & 0.0 & (0.354+0.354j) & 0.0 & (0.354+0.354j) & 0.0\\0.0 & (0.354+0.354j) & 0.0 & (-0.354-0.354j) & 0.0 & (0.354-0.354j) & 0.0 & (-0.354+0.354j)\\0.0 & (0.354-0.354j) & 0.0 & (0.354-0.354j) & 0.0 & (0.354+0.354j) & 0.0 & (0.354+0.354j)\\\end{array}\right)\end{equation*}

Or the transformation can be in terms of any 2 single qubit rotation gates along with the 2-qubit gate.


In [53]:
qc6 = qc3.resolve_gates(["ISWAP", "RX", "RY"])
qc6.png


Out[53]:

In [54]:
U6 = gate_sequence_product(qc6.propagators())
U6


Out[54]:
Quantum object: dims = [[2, 2, 2], [2, 2, 2]], shape = (8, 8), type = oper, isherm = False\begin{equation*}\left(\begin{array}{*{11}c}(0.354-0.354j) & 0.0 & (-0.354+0.354j) & 0.0 & (0.354+0.354j) & 0.0 & (-0.354-0.354j) & 0.0\\(0.354+0.354j) & 0.0 & (0.354+0.354j) & 0.0 & (0.354-0.354j) & 0.0 & (0.354-0.354j) & 0.0\\0.0 & (-0.354+0.354j) & 0.0 & (0.354-0.354j) & 0.0 & (-0.354-0.354j) & 0.0 & (0.354+0.354j)\\0.0 & (0.354+0.354j) & 0.0 & (0.354+0.354j) & 0.0 & (0.354-0.354j) & 0.0 & (0.354-0.354j)\\(-0.354-0.354j) & 0.0 & (0.354+0.354j) & 0.0 & (-0.354+0.354j) & 0.0 & (0.354-0.354j) & 0.0\\(0.354-0.354j) & 0.0 & (0.354-0.354j) & 0.0 & (0.354+0.354j) & 0.0 & (0.354+0.354j) & 0.0\\0.0 & (0.354+0.354j) & 0.0 & (-0.354-0.354j) & 0.0 & (0.354-0.354j) & 0.0 & (-0.354+0.354j)\\0.0 & (0.354-0.354j) & 0.0 & (0.354-0.354j) & 0.0 & (0.354+0.354j) & 0.0 & (0.354+0.354j)\\\end{array}\right)\end{equation*}

In [55]:
qc7 = qc3.resolve_gates(["CNOT", "RZ", "RX"])
qc7.png


Out[55]:

In [56]:
U7 = gate_sequence_product(qc7.propagators())
U7


Out[56]:
Quantum object: dims = [[2, 2, 2], [2, 2, 2]], shape = (8, 8), type = oper, isherm = False\begin{equation*}\left(\begin{array}{*{11}c}(0.354-0.354j) & 0.0 & (-0.354+0.354j) & 0.0 & (0.354+0.354j) & 0.0 & (-0.354-0.354j) & 0.0\\(0.354+0.354j) & 0.0 & (0.354+0.354j) & 0.0 & (0.354-0.354j) & 0.0 & (0.354-0.354j) & 0.0\\0.0 & (-0.354+0.354j) & 0.0 & (0.354-0.354j) & 0.0 & (-0.354-0.354j) & 0.0 & (0.354+0.354j)\\0.0 & (0.354+0.354j) & 0.0 & (0.354+0.354j) & 0.0 & (0.354-0.354j) & 0.0 & (0.354-0.354j)\\(-0.354-0.354j) & 0.0 & (0.354+0.354j) & 0.0 & (-0.354+0.354j) & 0.0 & (0.354-0.354j) & 0.0\\(0.354-0.354j) & 0.0 & (0.354-0.354j) & 0.0 & (0.354+0.354j) & 0.0 & (0.354+0.354j) & 0.0\\0.0 & (0.354+0.354j) & 0.0 & (-0.354-0.354j) & 0.0 & (0.354-0.354j) & 0.0 & (-0.354+0.354j)\\0.0 & (0.354-0.354j) & 0.0 & (0.354-0.354j) & 0.0 & (0.354+0.354j) & 0.0 & (0.354+0.354j)\\\end{array}\right)\end{equation*}

Resolving non-adjacent interactions

Interactions between non-adjacent qubits can be resolved by QubitCircuit to a series of adjacent interactions, which is useful for systems such as spin chain models.


In [57]:
qc8 = QubitCircuit(3)
qc8.add_gate("CNOT", 2, 0)
qc8.png


Out[57]:

In [58]:
U8 = gate_sequence_product(qc8.propagators())
U8


Out[58]:
Quantum object: dims = [[2, 2, 2], [2, 2, 2]], shape = (8, 8), type = oper, isherm = True\begin{equation*}\left(\begin{array}{*{11}c}1.0 & 0.0 & 0.0 & 0.0 & 0.0 & 0.0 & 0.0 & 0.0\\0.0 & 1.0 & 0.0 & 0.0 & 0.0 & 0.0 & 0.0 & 0.0\\0.0 & 0.0 & 1.0 & 0.0 & 0.0 & 0.0 & 0.0 & 0.0\\0.0 & 0.0 & 0.0 & 1.0 & 0.0 & 0.0 & 0.0 & 0.0\\0.0 & 0.0 & 0.0 & 0.0 & 0.0 & 1.0 & 0.0 & 0.0\\0.0 & 0.0 & 0.0 & 0.0 & 1.0 & 0.0 & 0.0 & 0.0\\0.0 & 0.0 & 0.0 & 0.0 & 0.0 & 0.0 & 0.0 & 1.0\\0.0 & 0.0 & 0.0 & 0.0 & 0.0 & 0.0 & 1.0 & 0.0\\\end{array}\right)\end{equation*}

In [59]:
qc9 = qc8.adjacent_gates()
qc9.png


Out[59]:

In [60]:
U9 = gate_sequence_product(qc9.propagators())
U9


Out[60]:
Quantum object: dims = [[2, 2, 2], [2, 2, 2]], shape = (8, 8), type = oper, isherm = True\begin{equation*}\left(\begin{array}{*{11}c}1.0 & 0.0 & 0.0 & 0.0 & 0.0 & 0.0 & 0.0 & 0.0\\0.0 & 1.0 & 0.0 & 0.0 & 0.0 & 0.0 & 0.0 & 0.0\\0.0 & 0.0 & 1.0 & 0.0 & 0.0 & 0.0 & 0.0 & 0.0\\0.0 & 0.0 & 0.0 & 1.0 & 0.0 & 0.0 & 0.0 & 0.0\\0.0 & 0.0 & 0.0 & 0.0 & 0.0 & 1.0 & 0.0 & 0.0\\0.0 & 0.0 & 0.0 & 0.0 & 1.0 & 0.0 & 0.0 & 0.0\\0.0 & 0.0 & 0.0 & 0.0 & 0.0 & 0.0 & 0.0 & 1.0\\0.0 & 0.0 & 0.0 & 0.0 & 0.0 & 0.0 & 1.0 & 0.0\\\end{array}\right)\end{equation*}

In [61]:
qc10 = qc9.resolve_gates("CNOT")
qc10.png


Out[61]:

In [62]:
U10 = gate_sequence_product(qc10.propagators())
U10


Out[62]:
Quantum object: dims = [[2, 2, 2], [2, 2, 2]], shape = (8, 8), type = oper, isherm = True\begin{equation*}\left(\begin{array}{*{11}c}1.0 & 0.0 & 0.0 & 0.0 & 0.0 & 0.0 & 0.0 & 0.0\\0.0 & 1.0 & 0.0 & 0.0 & 0.0 & 0.0 & 0.0 & 0.0\\0.0 & 0.0 & 1.0 & 0.0 & 0.0 & 0.0 & 0.0 & 0.0\\0.0 & 0.0 & 0.0 & 1.0 & 0.0 & 0.0 & 0.0 & 0.0\\0.0 & 0.0 & 0.0 & 0.0 & 0.0 & 1.0 & 0.0 & 0.0\\0.0 & 0.0 & 0.0 & 0.0 & 1.0 & 0.0 & 0.0 & 0.0\\0.0 & 0.0 & 0.0 & 0.0 & 0.0 & 0.0 & 0.0 & 1.0\\0.0 & 0.0 & 0.0 & 0.0 & 0.0 & 0.0 & 1.0 & 0.0\\\end{array}\right)\end{equation*}

Software versions


In [63]:
from qutip.ipynbtools import version_table
version_table()


Out[63]:
SoftwareVersion
QuTiP4.4.0.dev0+723960fe
Numpy1.15.0
SciPy1.3.0
matplotlib3.0.2
Cython0.29.6
Number of CPUs6
BLAS InfoINTEL MKL
IPython7.2.0
Python3.7.2 (default, Dec 29 2018, 00:00:04) [Clang 4.0.1 (tags/RELEASE_401/final)]
OSposix [darwin]
Wed May 29 15:55:13 2019 CEST