Difficulties with Lightning-GPU installation

I’m not familiar with Linux but prefer to use jupyter notebook. i’d love to try the Lightning-GPU feature, which is supposedly capable of acceleration. I tried my best to deploy it on Linux, but I had problems with the installation:
The above problems make me wonder if the installation was successful.

Hello @RX1, I believe you are required to pay NVIDIA for gpu access with cuQuantum in your notebooks. Here is a post from an NVIDIA employee regarding potential pip use instead of wheels and dockers.


Hi @RX1 since NVIDIA cuQuantum is linux only, you will need to run natively on a linux system (as you are already aware). For this, you need a CUDA-backed GPU that supports CUDA compute capability 7.0 and newer.

If you have access to a Linux machine with a CUDA capable GPU, you can follow the NVIDIA CUDA install guide here. Note that lightning.gpu currently supports CUDA-11, so if you are installing a fresh environment, it will be best to install CUDA 11.8

Once you have a working CUDA installation, you can install lightning.gpu as

python -m pip install pennylane pennylane-lightning-gpu custatevec-cu11 --upgrade

You should then be able to run your jupyter notebook environment, and use lightning.gpu as a device backend.

If you do not have a working install of CUDA, or a valid GPU supporting cuQuantum, the device will fall-back to running on the CPU only and warn you of the problem with your installation. Hope this helps.

Hi @RX1 ,

You can try using Google Colab if you have a short computation to run. Google Colab offers free access to a GPU but only in limited amounts so if you want something that will run on a GPU for many hours you will need to look at buying a GPU or buying a Pro version of a service that gives you access to one.

Here are the steps you can follow for a quick test on Google Colab:

  1. Open a new notebook
  2. In the navigation bar at the top go to Runtime → Change runtime type
  3. Choose a GPU
  4. In the first cell of the notebook run !pip install pennylane custatevec-cu11 pennylane-lightning-gpu
  5. Run a simple code (such as the code below) to test that everything works
import pennylane as qml

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

def circuit():
  return qml.expval(qml.PauliZ(0))


Note that not all GPUs are compatible with lightning.qubit so if you have questions about compatibility please let us know.

Also please note that the code above will probably run faster using lightning.qubit on a CPU that using lightning.gpu on a GPU. For computations under 20 qubits I recommend using lightning.qubit.

I hope this helps!


I am also having problems with lightning.gpu

I am trying to run:

import pennylane as qml
dev = qml.device(“lightning.gpu”, wires=2)

And I am getting back:

DeviceError: Device lightning.gpu does not exist. Make sure the required plugin is installed.

But when I run:
pip install pennylane-lightning[gpu]

I get back:

Requirement already satisfied: pennylane-lightning[gpu]

Hey @morgoth , welcome to the forum!
Do you mind sharing which versions you’re using, system and GPU? That will help us figure this out for you. :slight_smile:
If you could run qml.about() and share the output, that would be great!

Thank you for answering, Ivana. This is the output:

Platform info: Linux-4.18.0-372.32.1.el8_6.x86_64-x86_64-with-glibc2.28 Python version: 3.9.7 Numpy version: 1.23.4 Scipy version: 1.9.3 Installed devices: - lightning.qubit (PennyLane-Lightning-0.32.0) - default.gaussian (PennyLane-0.32.0) - default.mixed (PennyLane-0.32.0) - default.qubit (PennyLane-0.32.0) - default.qubit.autograd (PennyLane-0.32.0) - default.qubit.jax (PennyLane-0.32.0) - default.qubit.tf (PennyLane-0.32.0) - default.qubit.torch (PennyLane-0.32.0) - default.qutrit (PennyLane-0.32.0) - null.qubit (PennyLane-0.32.0)

The GPUs available are Nvidia V100.

Hi @morgoth, this looks like an installation error. You need to install NVIDIA’s custatevec library too.

If you run the following in a new environment does it work?
pip install pennylane custatevec-cu11 pennylane-lightning-gpu

That solved it. Thanks!

I’m glad it worked @morgoth! Enjoy using PennyLane!

1 Like

Hello, using !pip install pennylane custatevec-cu11 pennylane-lightning-gpu in Colab is the GPU selected in Colab a separate device with its own RAM separate from lightning.gpu? Thank you.

Hi @kevinkawchak , GPU access you get via Google Colab (which is used to run GPU-based simulators such as PennyLane’s lightning.gpu) is completely managed by Google Colab. You can find out more details about how Colab manages access to resources such as GPUs in the Google Colab FAQ.

I run the same code

import pennylane as qml
dev = qml.device(“lightning.gpu”, wires=2)

and the Python freeze. Nothing help. Can anyone help me?

Hi @souzateixeira , welcome to the forum!

You can find the answer to this question here.

In a few words,

  1. Open a new notebook
  2. In the navigation bar at the top go to Runtime → Change runtime type
  3. Choose a GPU
  4. In the first cell of the notebook run !pip install pennylane custatevec-cu11 pennylane-lightning-gpu
  5. Run a simple code to test that everything works

Let me know if this solves your problem!

By the way, we have a very small survey for PennyLane v0.32, and it would be awesome if you’d give us some feedback and tell us about your needs. Thank you! :grin:

1 Like

I tried to install lightning gpu locally on conda environment in windows, but this is the output:
(quantum) C:\Users\elyon>pip install pennylane custatevec-cu11 pennylane-lightning-gpu
Requirement already satisfied: pennylane in c:\users\elyon\anaconda3\envs\quantum\lib\site-packages (0.33.0)
ERROR: Could not find a version that satisfies the requirement custatevec-cu11 (from versions: none)
ERROR: No matching distribution found for custatevec-cu11

Hi @Eleonora_Panini

custatevec-cu11, is part of NVIDIA’s cuQuantum SDK, and is supported only on Linux platform, which is why you cannot install it.

You can try to set up CUDA through WSL on Windows, which may work, but we cannot guarantee this. You can try following the guide at 1. NVIDIA GPU Accelerated Computing on WSL 2 — CUDA on WSL 12.3 documentation but note you will require a CUDA 11 installation for a working version of lightning.gpu.