csr_matrix to fast_csr_matrix

40 views
Skip to first unread message

MM

unread,
Oct 31, 2017, 11:36:52 PM10/31/17
to QuTiP: Quantum Toolbox in Python
I have the following installation:

QuTiP Version:      4.0.2
Numpy Version:      1.12.0
Scipy Version:      0.18.1
Cython Version:     0.25.2
Matplotlib Version: 1.5.1
Python Version:     2.7.12
Number of CPUs:     2

I'm generating a csr_matrix but the QO formed from it complains

  File "/home/cqt/PycharmProjects/QFI/ramsey.py", line 93, in bsb_flop
    Wbsb.data = tr
  File "/home/cqt/.local/lib/python2.7/site-packages/qutip/qobj.py", line 328, in set_data
    raise TypeError('Qobj data must be in fast_csr format.')
TypeError: Qobj data must be in fast_csr format.

How do I convert from csr_matrix to fast_csr format?

part of the relevant code is :

def bsb_flop(rho0, W, eta, delta, theta, phi, c_op_list = [], return_op_list = []):
''' Return values of atom and motion populations during blue sideband Rabi flop
for rotation angles theta. Calls numerical solution of master equation for the
anti Jaynes-Cummings Hamiltonian.
@ var rho0: initial density matrix
@ var W: bare Rabi frequency
@ var delta: detuning between atom and motion
@ var theta: list of Rabi rotation angles (i.e. theta, or g*time)
@ var phi: phase of the input laser pulse
@ var c_op_list: list of collapse operators for the master equation treatment
@ var return_op_list: list of population operators the values of which will be returned

returns: time, populations of motional mode and atom
'''
N = shape(rho0.data)[0]/2 # assume N Fock states and two atom states
a = tensor(destroy(N), qeye(2))
sm = tensor( qeye(N), destroy(2))
Wbsb = destroy(N).dag()
# print csr_matrix(destroy(N).dag().data.dot(np.diag( rabi_coupling(N,1,eta) / np.sqrt(np.linspace(1,N,N)) ) ),dtype=complex)
tr = csr_matrix(destroy(N).dag().data.dot(np.diag( rabi_coupling(N,1,eta) / np.sqrt(np.linspace(1,N,N)) ) ))
print type(tr.indices[6])
Wbsb.data = fast_csr_matrix(tr)
# Wbsb.data = csr_matrix( destroy(N).dag().data.dot( np.diag( rabi_coupling(N,1,eta) / np.sqrt(np.linspace(1,N,N)))))
Absb = tensor(Wbsb.dag(), qeye(2))

Paul Nation

unread,
Oct 31, 2017, 11:49:47 PM10/31/17
to QuTiP Group
You need to do something like Qobj(tr).  Setting the data attribute directly should probably be avoided.

-P

--
You received this message because you are subscribed to the Google Groups "QuTiP: Quantum Toolbox in Python" group.
To unsubscribe from this group and stop receiving emails from it, send an email to qutip+unsubscribe@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

MM

unread,
Oct 31, 2017, 11:58:58 PM10/31/17
to QuTiP: Quantum Toolbox in Python
Thanks a lot for the quick (should have thought before:-)) trick...

best
MM
To unsubscribe from this group and stop receiving emails from it, send an email to qutip+un...@googlegroups.com.
Reply all
Reply to author
Forward
0 new messages