qiskit-community / qiskit-dynamics

Tools for building and solving models of quantum systems in Qiskit
https://qiskit-community.github.io/qiskit-dynamics/
Apache License 2.0
106 stars 60 forks source link

Fix qutip Qobj handling for qutip 5.0.0 #354

Closed DanPuzzuoli closed 7 months ago

DanPuzzuoli commented 7 months ago

Summary

As pointed out in #353 , the handling of the qutip Qobj type by DYNAMICS_NUMPY.asarray was broken with the release of qutip 5.0.0. In the past, qutip Qobj instances always contained customized csr_matrix instances, so we would always consume them by explicitly converting them to a csr_matrix. Qutip 5.0.0 adds a "data layer" abstraction, allowing Qobj instances to store different underlying array types (e.g. dense np.ndarray). This data layer has been written to be extensible, and hence moving forward we have no guarantees on the type of array data within a Qobj.

As a result of this, I've changed DYNAMICS_NUMPY.asarray(qobj) to return qobj.full(), which returns a dense np.ndarray. This works regardless of underlying array type, so seems like a safe future-proof way of solving this issue.

Details and comments

I've also added an upgrade note outlining this change.