Introduction to Quantum Objects

Author: Vineeth Thalakottoor

Email: vineethfrancis.physics@gmail.com

[1]:
# Define the source path
SourcePath = '/media/HD2/Vineeth/PostDoc_Simulations/Github/PyOR_V1/PyOR_Combined/PyOR/Source_Doc'

# Add source path
import sys
sys.path.append(SourcePath)

# Import PyOR package
from PyOR_QuantumObject import QunObj

Define State and Operator

[70]:
# Vector (ket)
ket1 = QunObj([[1], [0]],PrintDefault=True)
ket2 = QunObj([[0], [1]],PrintDefault=True)

# Matrix (Spin operator operator)
Sx = QunObj([[0.0, 0.5],[0.5,0.0]],PrintDefault=True)
Sy = QunObj([[0.0, -0.5j],[0.5j,  0.0]],PrintDefault=True)
Sz = QunObj([[0.5, 0.0],[0.0, -0.5]],PrintDefault=True)

Id = QunObj([[1., 0.0],[0.0, 1]],PrintDefault=True)
Quantum object initialized: shape=(2, 1), type='ket', dtype=complex128
Quantum object initialized: shape=(2, 1), type='ket', dtype=complex128
Quantum object initialized: shape=(2, 2), type='operator', dtype=complex128
Quantum object initialized: shape=(2, 2), type='operator', dtype=complex128
Quantum object initialized: shape=(2, 2), type='operator', dtype=complex128
Quantum object initialized: shape=(2, 2), type='operator', dtype=complex128

Quantum Object: Ket

[ ]:
# Attribute : matrix - show matrix form using sympy

ket1.matrix
$\displaystyle \left[\begin{matrix}1.0\\0\end{matrix}\right]$
[ ]:
# Attribute : matrix - show matrix form using sympy

ket2.matrix
$\displaystyle \left[\begin{matrix}0\\1.0\end{matrix}\right]$
[ ]:
# Attribute : type - show the type of the object (ket, bra or operator)

ket1.type
'ket'
[ ]:
# Attribute : data - show matrix form using numpy, as array

ket1.data
array([[1.+0.j],
       [0.+0.j]])
[ ]:
# Attribute : datatype - show the data type of the array

ket1.datatype
dtype('complex128')
[ ]:
# Attribute : datatype - show the dimension of the array

ket1.shape
(2, 1)

Quantum object: Operators

[ ]:
# Attribute : matrix - show matrix form using sympy

Sx.matrix
$\displaystyle \left[\begin{matrix}0 & 0.5\\0.5 & 0\end{matrix}\right]$
[ ]:
# Attribute : data - show matrix form using numpy, as array

Sx.data
array([[0. +0.j, 0.5+0.j],
       [0.5+0.j, 0. +0.j]])
[ ]:
# Attribute : type - show the type of the object (ket, bra or operator)

Sx.type
'operator'
[ ]:
# Attribute : datatype - show the data type of the array

Sx.datatype
dtype('complex128')
[ ]:
# Attribute : shape - show the dimension of the array

Sx.shape
(2, 2)
[48]:
# Attribute : matrix - show matrix form using sympy

Sy.matrix
[48]:
$\displaystyle \left[\begin{matrix}0 & - 0.5 i\\0.5 i & 0\end{matrix}\right]$
[49]:
# Attribute : matrix - show matrix form using sympy

Sz.matrix
[49]:
$\displaystyle \left[\begin{matrix}0.5 & 0\\0 & -0.5\end{matrix}\right]$
[71]:
# Attribute : matrix - show matrix form using sympy

Id.matrix
[71]:
$\displaystyle \left[\begin{matrix}1.0 & 0\\0 & 1.0\end{matrix}\right]$

Rotate an qunatum object

[ ]:
# Method : Rotate - Rotate the object

ket3 = ket1.Rotate(180,Sx)
ket3.matrix
$\displaystyle \left[\begin{matrix}0\\- 1.0 i\end{matrix}\right]$

Adding two objects

[ ]:
# Method : Add two objects

ket4 = 2 * ket1 + 5 *  ket2
ket4.matrix
$\displaystyle \left[\begin{matrix}2.0\\5.0\end{matrix}\right]$

Multiply two objects

[ ]:
# Method : Multiply two objects

ket5 = Sx * ket1
ket5.matrix
$\displaystyle \left[\begin{matrix}0\\0.5\end{matrix}\right]$

Add and multiply objects

[ ]:
# Multiply and add quantum objects

H =  10 * Sx * Sx + 10 * Sy * Sy + 10 * Sz * Sz
H.matrix
$\displaystyle \left[\begin{matrix}7.5 & 0\\0 & 7.5\end{matrix}\right]$

Adjoint

[ ]:
# Method : Adjoint

bra1 = ket1.Adjoint()
bra1.matrix
$\displaystyle \left[\begin{matrix}1.0 & 0\end{matrix}\right]$
[46]:
bra1.type
[46]:
'bra'

Conjugate

[58]:
# Method : Conjugate

ket3.Conjugate().matrix
[58]:
$\displaystyle \left[\begin{matrix}0\\1.0 i\end{matrix}\right]$

Transpose

[ ]:
#Method : Transpose

ket3.Tranpose().matrix
$\displaystyle \left[\begin{matrix}0 & - 1.0 i\end{matrix}\right]$

Trace

[60]:
# Method : Trace

Sx.Trace()
[60]:
0j

Frobenius norm

[ ]:
# method : Norm

Sx.Norm()
0.7071067811865476
[ ]:
# method : Norm

ket1.Norm()
1.0

Exponential of an operator

[ ]:
# Method : Expm, Compute the matrix exponential

Sx.Expm().matrix
$\displaystyle \left[\begin{matrix}1.12762596520638 & 0.521095305493747\\0.521095305493747 & 1.12762596520638\end{matrix}\right]$

Check for Hermitian

[67]:
# Method : Hermitian, Check whether the matrix is Hermitian (A = A†)

Sx.Hermitian()
[67]:
True

Check for commute

[68]:
# Method : Commute, Check if two QunObj instances commute

Sx.Commute(Sy)
Don't Commute
[68]:
False
[69]:
Sy.Commute(Sy)
Commute
[69]:
True

Tensor Producrt

[73]:
# Method : Tensor Product

Sx.TensorProduct(Id).matrix
[73]:
$\displaystyle \left[\begin{matrix}0 & 0 & 0.5 & 0\\0 & 0 & 0 & 0.5\\0.5 & 0 & 0 & 0\\0 & 0.5 & 0 & 0\end{matrix}\right]$
[ ]:
# Method : Tensor Product

Id.TensorProduct(Sx).matrix
$\displaystyle \left[\begin{matrix}0 & 0.5 & 0 & 0\\0.5 & 0 & 0 & 0\\0 & 0 & 0 & 0.5\\0 & 0 & 0.5 & 0\end{matrix}\right]$

Outer Product

[ ]:
# Method : OuterProduct

ket1.OuterProduct(ket1).matrix
$\displaystyle \left[\begin{matrix}1.0 & 0\\0 & 0\end{matrix}\right]$
[ ]:
# Method : OuterProduct

ket1.OuterProduct(ket2).matrix
$\displaystyle \left[\begin{matrix}0 & 1.0\\0 & 0\end{matrix}\right]$

Inner Product

[78]:
# Method : InnerProduct

ket1.InnerProduct(ket1)
[78]:
(1+0j)
[79]:
# Method : InnerProduct

Sx.InnerProduct(Sx)
[79]:
(0.5+0j)

Normalize

[80]:
# Method : Normalize, normalize an object

Sx.Normalize().matrix
[80]:
$\displaystyle \left[\begin{matrix}0 & 0.707106781186547\\0.707106781186547 & 0\end{matrix}\right]$
[82]:
Sx.Normalize().Norm()
[82]:
0.9999999999999999
[83]:
Sx.Norm()
[83]:
0.7071067811865476