Getting Lightning.GPU to work on Google Collab

Hello! I’m trying to install Lightning.gpu on google collab, and im running into some errors:

Starting from opening up a new notebook on google collab, I installed it using:
!pip install pennylane custatevec-cu11 pennylane-lightning-gpu
and I used this sample code:

import pennylane as qml

dev = qml.device("lightning.gpu", wires=2)

@qml.qnode(dev)
def circuit():
  qml.Hadamard(wires=0)
  qml.CNOT(wires=[0,1])
  return qml.expval(qml.PauliZ(0))

circuit()

This line however gives me some errors:

/usr/local/lib/python3.10/dist-packages/pennylane_lightning/lightning_gpu/lightning_gpu.py:94: UserWarning: libcublas.so.11: cannot open shared object file: No such file or directory
  warn(str(e), UserWarning)
---------------------------------------------------------------------------
ImportError                               Traceback (most recent call last)
<ipython-input-2-9daf1c568f25> in <cell line: 3>()
      1 import pennylane as qml
      2 
----> 3 dev = qml.device("lightning.gpu", wires=2)
      4 
      5 @qml.qnode(dev)

2 frames
/usr/local/lib/python3.10/dist-packages/pennylane_lightning/core/lightning_base.py in __init__(self, wires, c_dtype, shots, batch_obs)
     72     ):
     73         if not self._CPP_BINARY_AVAILABLE:
---> 74             raise ImportError(
     75                 f"Pre-compiled binaries for {self.short_name} are not available. "
     76                 "To manually compile from source, follow the instructions at "

ImportError: Pre-compiled binaries for lightning.gpu are not available. To manually compile from source, follow the instructions at https://pennylane-lightning.readthedocs.io/en/latest/installation.html.

---------------------------------------------------------------------------
NOTE: If your import is failing due to a missing package, you can
manually install dependencies using either !pip or !apt.

To view examples of installing some common dependencies, click the
"Open Examples" button below.
---------------------------------------------------------------------------

Wondering if anybody can replicate installing lightning.gpu and let me know where I’m going wrong?

Thanks so much!

Hey, I got this working! Give this a try:

First make sure you’re connected to a T4 GPU instance in colab. (It’s free to use but requires selecting this as its not default.)

Afterwards try,
!python -m pip install pennylane pennylane-lightning pennylane-lightning-gpu --upgrade
And then:
!pip install custatevec-cu12

Finally your circuit code should work as usual:

import pennylane as qml

dev = qml.device("lightning.gpu", wires=2)

@qml.qnode(dev)
def circuit():
  qml.Hadamard(wires=0)
  qml.CNOT(wires=[0,1])
  return qml.expval(qml.PauliZ(0))

circuit()

My output was:

tensor(0., requires_grad=True)

I hope this helps!

1 Like

That worked perfectly for me, thank you! The switch needed was from !pip install custatevec-cu11
to !pip install custatevec-cu12. Thanks!

1 Like

This is great to see @jwoodrg and @ImranNasrullah ! :raised_hands: