jcmgray / quimb

A python library for quantum information and many-body calculations including tensor networks.
http://quimb.readthedocs.io
Other
455 stars 107 forks source link

Using quimb within torch on GPU #177

Closed yuxuanzhang1995 closed 1 year ago

yuxuanzhang1995 commented 1 year ago

What is your issue?

Hi quimb team,

In example 12 you showed how to perform optimizations in torch. What do I need to change in order to use cuda as the device for torch optimization?

Best, Yuxuan

jcmgray commented 1 year ago

It should just be as simple as calling: apply_to_arrays(lambda x: torch.tensor(x, dtype=torch.float32).cuda()), or whichever way is your favorite to get the initial torch data onto the gpu:

  1. torch.set_default_device(device) to set a default permanently
  2. with torch.device(device): ... to set a default temporarily
yuxuanzhang1995 commented 1 year ago

That works. Thank you!