qutip / qutip-cupy

CuPy linear-algebra backend for QuTiP
BSD 3-Clause "New" or "Revised" License
19 stars 10 forks source link

Example on "Usage" section of homepage raises an exception #43

Closed ss4adam closed 2 years ago

ss4adam commented 2 years ago

After following the installation instructions in the example in Readme.md verbatim, an exception gets raised. Looks like qutip's Qobj isn't expecting an optional parameter called dtype="qutip_cupy"

import qutip 
import qutip_cupy

qobj = qutip.Qobj([0, 1], dtype="cupyd") # line in question that raises exception
qobj.data

_Exception has occurred: TypeError init() got an unexpected keyword argument 'dtype' File "C:\Projects\Algorithms\GPU_SQA\test.py", line 20, in qobj = qtp.Qobj([0, 1], dtype="qutipcupy")

Machine/Environment specifics: metadata.version('qutip') '5.0.0.dev0+b5a4672' metadata.version('qutip_cupy') '0.1.0.dev0+320efa8' metadata.version('cupy') '10.0.0' Cuda compilation tools, release 11.5, V11.5.119 Build cuda_11.5.r11.5/compiler.30672275_0 GPU: RTX2070

Ericgig commented 2 years ago

dtype in Qobj was planned for dev.major, but has not been implemented yet. Qobj(data).to('cupyd') should work.

ss4adam commented 2 years ago

@Ericgig That seems to solve the issue. I noticed a similar GPU based linear-algebra backend for qutip that was created by the same developers https://github.com/qutip/qutip-tensorflow Although neither are officially supported, do you recommend users continue using qutip-cupy or switch to qutip-tensorflow since the latter project seems to be maintained more frequently?

hodgestar commented 2 years ago

@ss4adam qutip-cupy and qutip-tensorflow are both maintained by the QuTiP admin team. qutip-tensorflow is a little further along, and has been updated a little more recently. Both are currently "alpha" quality -- i.e. they work, but they could us a lot more real use & filing off of rough edges and filling in of missing pieces. I would pick whichever of the two makes the most sense for your use case (maybe you just want to work on a GPU on a single machine, in which case qutip-cupy might be better, or maybe you really want all the features of TensorFlow, in which case qutip-tensorflow might be better). The qutip-tensorflow backend also has some support for autodifferentiation of Qobjs, so that might be another reason to choose it. The downside is a little more overhead if you just want to run things on a GPU.

We'll gladly accept questions, patches and bug reports for both.

adamkimqai commented 2 years ago

Leaving this here in case it helps someone. I was getting several exceptions related to _cp not being defined when I would use Qobj(data).to('cupyd'). Instead, I found that qutip_cupy.CuPyDense(x_qobj.data.to_array()) would create the object and correctly give me a _cp attribute.