0

I am new to qutip and I am struggling on the way to create quantum objects with such a shape in a much clever manner:

from qutip import *
object1 = Qobj([[1, 0, 0, 0],
               [0, -1, 0, 0],
               [0, 0, 0, 0],
               [0, 0, 0, 0])

object2 = Qobj([[0, 0, 0, -1j],
               [0, 0, 1j, 0],
               [0, 0, 0, 0],
               [0, 0, 0, 0])

And so on.

The idea is to do so for all sigma submatrices with liberty on how to build in a nicer way usign sigma 2x2 matrix. Is there a better way to do so? Sincerely, Paul

PaulH
  • 19
  • 3

1 Answers1

0

First of all, QuTiP has sigmax, sigmay and sigmaz operators, see the docs. To achieve what you want, you can take tensor product of a sigma matrix with a matrix which has a 1 at the position where you wish to insert the sigma matrix:

import numpy as np
import qutip as qt

def one_at(pos=(0,0), N=2):
    arr = np.zeros((N, N))
    arr[pos] = 1
    return qt.Qobj(arr)

>>> one_at((0,0))
Qobj data =
[[1. 0.]
 [0. 0.]]

>>> one_at((0,1))
Qobj data =
[[0. 1.]
 [0. 0.]]

>>> qt.sigmay()
Qobj data =
[[0.+0.j 0.-1.j]
 [0.+1.j 0.+0.j]]

>>> qt.sigmaz()
Qobj data =
[[ 1.  0.]
 [ 0. -1.]]

>>> qt.tensor(one_at((0,0)), qt.sigmaz())
Qobj data =
[[ 1.  0.  0.  0.]
 [ 0. -1.  0.  0.]
 [ 0.  0.  0.  0.]
 [ 0.  0.  0.  0.]]

>>> qt.tensor(one_at((0,1)), qt.sigmay())
Qobj data =
[[0.+0.j 0.+0.j 0.+0.j 0.-1.j]
 [0.+0.j 0.+0.j 0.+1.j 0.+0.j]
 [0.+0.j 0.+0.j 0.+0.j 0.+0.j]
 [0.+0.j 0.+0.j 0.+0.j 0.+0.j]]
Andreas K.
  • 9,282
  • 3
  • 40
  • 45