Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up

CuPy linear-algebra backend for QuTiP

License

NotificationsYou must be signed in to change notification settings

qutip/qutip-cupy

A plugin forQuTiP providing aCuPy linear-algebra backend for GPU computation.

Support

Unitary FundPowered by NumFOCUS

We are proud to be affiliated withUnitary Fund andNumFOCUS.QuTiP development is supported byNori's lab at RIKEN, by the University of Sherbrooke, and by Aberystwyth University,among other supporting organizations.Initial work on this project was sponsored byGoogle Summer of Code 2021.

Installation

qutip-cupy is not yet officially released.

If you want to try out the package you will need to have a CUDA enabled GPU,QuTiP >5.0.0 andCuPy.We recommend using a conda environmentPython >= 3.7.To installCuPy we recommend the following steps:

  • conda install -c conda-forge cupy

To installQuTiP >5.0.0 while it is not yet released we recommend:

  • python -mpip install git+https://github.com/qutip/qutip.git@dev.major

Now you can safely installqutip_cupy

  • python -mpip install git+https://github.com/qutip/qutip-cupy.git

Usage

The main object thatqutip-cupy provides isCuPyDense which is aCuPy based interface to storeQobj's data.

When working with a newQobj you may proceed as follows:

importqutipimportqutip_cupyqobj=qutip.Qobj([0,1],dtype="cupyd")qobj.data

This then returns

<qutip_cupy.dense.CuPyDenseat0x7fea2b2338c0>

In this way you can create CuPyDense arrays that live in the defult GPU device on your environment. If you have more than one GPU we recommend that you check the documentation if you want to choose a custom one. We also provide some custom constructors to initializeCuPyDense arrays.

Operations that return an array will return control inmediately to the user, while scalar valued functions will block and return the result to general memory.

You can operate a CuPyDense-backed state with a CuPyDense-backed unitary, and the result will also be CuPyDense-backed.

importnumpyasnptheta= (1/2)*np.piU=qutip.Qobj([[np.cos(theta),1.j*np.sin(theta)],[-1.j*np.sin(theta),np.cos(theta) ]]).to('cupyd')qobj_end=U @qobjqobj_end.data
<qutip_cupy.dense.CuPyDenseat0x7f1190688d20>

You can then calculate the overlap of the new state with the original state. The resulting overlap lives in the CPU and if you wanted to then calculate the probability of finding the new state to be the original state (i.e. you were to project on a suitable base that has as an element the original state) one should use CPU-bound computation, in this case we callnp.linalg.norm .

overlap=qobj_end.overlap(qobj)np.linalg.norm(overlap)**2
3.749399456654644e-33

You can now start working withCuPy based arrays seamlessly.qutip-cupy takes care to dispatch all functions to specialisations onCuPyDense arrays, and if there is no specialisation for the given function yetQuTiP's data-layer will force a conversion to one of its own data-types and run the required function within the CPU. We recommend that you check ourGitHub issues to stay up to date on any missing or new specialisations.

Benchmarks

This is a work in progress.

About

CuPy linear-algebra backend for QuTiP

Resources

License

Code of conduct

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages


[8]ページ先頭

©2009-2025 Movatter.jp