What is the preferred way of applying an operator to a product state?

49 views
Skip to first unread message

Muhammad Saad

unread,
Jan 5, 2016, 7:53:26 AM1/5/16
to QuTiP: Quantum Toolbox in Python
I am new to QuTiP. While trying a simple exercise, I encountered a problem with matrix products. It's something quite elementary but I can't figure it out yet.

I start with these states.

h = basis(2,0)
v = basis(2,1)

psi_a = 1/np.sqrt(2) * ( h + v )
psi_b = 1/np.sqrt(2) * ( h + v )

Then take the tensor product.

psi_ab_t0 = tensor(psi_a,psi_b)

which gives:
Quantum object: dims = [[2, 2], [1, 1]], shape = [4, 1], type = ket
Qobj data =
[[ 0.5]
 [ 0.5]
 [ 0.5]
 [ 0.5]]

I take a simple hamiltonian.

hmlt = Qobj([[1,0,0,0],[0,1,0,0],[0,0,1,0],[0,0,0,-1]])
hmltpr = (-1j*np.pi/2) * hmlt
hmlt_tf = hmltpr.expm()

Now I need to do apply the hamiltonian hmlt_tf to the state psi_ab_t0.
But the matrix product does not work because the dimensions for hmlt_tf are [[4], [4]] and dimensions for psi_ab_t0 are [[2, 2], [1, 1]].
I can convert them to numpy arrays and multiply them but there's a problem. I need to measure concurrence at the end which takes a tensor product as its input.
The only way I can get it to work right now is to manually change psi_ab_t0.dims to [[4], [4]] and then back after I've taken the matrix product. This is obviously an ugly hack. What is the preferred way of doing this?

Paul Nation

unread,
Feb 2, 2016, 4:32:37 PM2/2/16
to QuTiP: Quantum Toolbox in Python
You are building a composite object psi_ab_t0, but not giving hmtl any composite structure. Your Hamiltonian in this case needs to be fed the correct dims since you are not using tensor to build it. The dims should be: dims = [[2, 2], [2, 2]].  So,

hmlt = Qobj([[1,0,0,0],[0,1,0,0],[0,0,1,0],[0,0,0,-1]], dims = [[2, 2], [2, 2]])

Muhammad Saad

unread,
Feb 3, 2016, 6:04:49 AM2/3/16
to QuTiP: Quantum Toolbox in Python
Thanks! It does work when I feed the Hamiltonian the correct dimensions.
Reply all
Reply to author
Forward
0 new messages