Closed DanPuzzuoli closed 3 years ago
Possible code suggestion from @chriseclectic for detecting/conversion from qutip without importing qutip.
def isinstance_qutip_qobj(obj):
if (type(obj).__name__ == 'Qobj'
and hasattr(obj, '_data')
and type(obj._data).__name__ == 'fast_csr_matrix'):
return True
return False
import qutip
op = qutip.Qobj([[0, 1], [1, 0]])
if isinstance_qutip_qobj(op):
op = op._data # csr matrix
What is the expected behavior?
There are a few type-handling issues that we need to sort out. Currently, the model classes support operation in both dense and sparse modes, however, regardless of the chosen mode of operation, at instantiation, everything is passed through the
to_array
function, which converts everything to a dense array. If a sparse mode is selected, it will then convert these arrays to sparse. We should set things up so that if a user specifies things in a sparse format then it never gets converted to a dense format.To do:
to_csr
analog ofto_array
, which does the same job but converts everything to the required format for the sparse types (see e.g. the constructor toSparseOperatorCollection
for the required format).to_array
andto_csr
. This should be done without actually importing qutip, so need to decide how to detect this (op.__name__
?) .