Issues when using PennyLane Lightning GPU

Hello!

I am using lightning.gpu to accelerate my quantum simulator, but I got an error when I ran it.

Here is the code I am testing:

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

The error I got is:

Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File ".../anaconda/anaconda3/envs/QAG/lib/python3.10/site-packages/pennylane/__init__.py", line 393, in device
    dev = plugin_device_class(*args, **options)
  File ".../anaconda/anaconda3/envs/QAG/lib/python3.10/site-packages/pennylane_lightning/lightning_gpu/lightning_gpu.py", line 254, in __init__
    super().__init__(wires, shots=shots, c_dtype=c_dtype)
  File ".../anaconda/anaconda3/envs/QAG/lib/python3.10/site-packages/pennylane_lightning/core/lightning_base.py", line 74, in __init__
    raise ImportError(
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.

The version of PennyLane I am using is shown bellow:

Name: PennyLane
Version: 0.36.0
Summary: PennyLane is a cross-platform Python library for quantum computing, quantum machine learning, and quantum chemistry. Train a quantum computer the same way as a neural network.
Home-page: https://github.com/PennyLaneAI/pennylane
Author: 
Author-email: 
License: Apache License 2.0
Location: .../anaconda/anaconda3/envs/QAG/lib/python3.10/site-packages
Requires: appdirs, autograd, autoray, cachetools, networkx, numpy, pennylane-lightning, requests, rustworkx, scipy, semantic-version, toml, typing-extensions
Required-by: PennyLane_Lightning, PennyLane_Lightning_GPU, PennyLane_Lightning_Kokkos, Quantum_Angle_Generator

Platform info:           Linux-3.10.0-1160.105.1.el7.x86_64-x86_64-with-glibc2.17
Python version:          3.10.14
Numpy version:           1.26.4
Scipy version:           1.13.0
Installed devices:
- lightning.gpu (PennyLane_Lightning_GPU-0.36.0)
- default.clifford (PennyLane-0.36.0)
- default.gaussian (PennyLane-0.36.0)
- default.mixed (PennyLane-0.36.0)
- default.qubit (PennyLane-0.36.0)
- default.qubit.autograd (PennyLane-0.36.0)
- default.qubit.jax (PennyLane-0.36.0)
- default.qubit.legacy (PennyLane-0.36.0)
- default.qubit.tf (PennyLane-0.36.0)
- default.qubit.torch (PennyLane-0.36.0)
- default.qutrit (PennyLane-0.36.0)
- default.qutrit.mixed (PennyLane-0.36.0)
- null.qubit (PennyLane-0.36.0)
- lightning.kokkos (PennyLane_Lightning_Kokkos-0.36.0)
- lightning.qubit (PennyLane_Lightning-0.36.0)

The status of my GPU, as displayed by nvidia-smi , is

Thu May 23 19:04:02 2024       
+-----------------------------------------------------------------------------+
| NVIDIA-SMI 515.65.01    Driver Version: 515.65.01    CUDA Version: 11.7     |
|-------------------------------+----------------------+----------------------+
| GPU  Name        Persistence-M| Bus-Id        Disp.A | Volatile Uncorr. ECC |
| Fan  Temp  Perf  Pwr:Usage/Cap|         Memory-Usage | GPU-Util  Compute M. |
|                               |                      |               MIG M. |
|===============================+======================+======================|
|   0  Tesla V100-SXM2...  On   | 00000000:15:00.0 Off |                    0 |
| N/A   41C    P0    43W / 300W |      0MiB / 32768MiB |      0%      Default |
|                               |                      |                  N/A |
+-------------------------------+----------------------+----------------------+
|   1  Tesla V100-SXM2...  On   | 00000000:16:00.0 Off |                    0 |
| N/A   42C    P0    45W / 300W |      0MiB / 32768MiB |      0%      Default |
|                               |                      |                  N/A |
+-------------------------------+----------------------+----------------------+
                                                                               
+-----------------------------------------------------------------------------+
| Processes:                                                                  |
|  GPU   GI   CI        PID   Type   Process name                  GPU Memory |
|        ID   ID                                                   Usage      |
|=============================================================================|
|  No running processes found                                                 |
+-----------------------------------------------------------------------------+

I would greatly appreciate any guidance or insights to help address this issue. Thank you!

Hi @zebing_wang ,

Welcome to the forum!

How did you install Lightning GPU?

I recommend that you follow these steps:

  1. Create a new conda environment with:
    conda create --name name_of_your_environment python=3.10
  2. Activate the environment:
    conda activate name_of_your_environment
  3. Install PennyLane and Lightning with
    python -m pip install pennylane pennylane-lightning pennylane-lightning-gpu --upgrade to ensure the version is the most recent (v0.36 as of writing).
  4. pip install custatevec-cu11 to bring in the CUDA 11 variant of the NVIDIA cuQuantum custatevec library.

Let me know if this works for you.

Hi,

Thanks for your fast reply. I have try the steps you show me to reinstall all the packages. But the error are same when I run:

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

Thanks!

HI @zebing_wang,

lightning.gpu uses cuQuantum and CUDA. It can be a cause if you have incompatible versions.

Best

Hi,

The version of my cuQuantum is:

contourpy                  1.2.1
cupy                       13.1.0
cupy-cuda11x               13.1.0
cuquantum-python-cu11      24.3.0
custatevec-cu11            1.6.0.post1
cutensor-cu11              2.0.1
cutensornet-cu11           2.4.0.post1

The version of CUDA I am using is 11.7 I believe, I got it from nvidia-smi:

Tue May 28 11:22:44 2024       
+-----------------------------------------------------------------------------+
| NVIDIA-SMI 515.65.01    Driver Version: 515.65.01    CUDA Version: 11.7     |
|-------------------------------+----------------------+----------------------+
| GPU  Name        Persistence-M| Bus-Id        Disp.A | Volatile Uncorr. ECC |
| Fan  Temp  Perf  Pwr:Usage/Cap|         Memory-Usage | GPU-Util  Compute M. |
|                               |                      |               MIG M. |
|===============================+======================+======================|
|   0  Tesla V100-SXM2...  On   | 00000000:1F:00.0 Off |                    0 |
| N/A   31C    P0    43W / 300W |      0MiB / 32768MiB |      0%      Default |
|                               |                      |                  N/A |
+-------------------------------+----------------------+----------------------+
                                                                               
+-----------------------------------------------------------------------------+
| Processes:                                                                  |
|  GPU   GI   CI        PID   Type   Process name                  GPU Memory |
|        ID   ID                                                   Usage      |
|=============================================================================|
|  No running processes found                                                 |
+-----------------------------------------------------------------------------+

So, I thought the version was correct, right?

Thanks!

Hi @zebing_wang ,

Maybe it’s an issue with the NVIDIA drivers. Does it work if you install the following in a new environment? So following steps 1, 2 and 3 from before and replacing step 4 with the line below

python -m pip install nvidia-cusparse-cu11 nvidia-cublas-cu11 nvidia-cuda-runtime-cu11 custatevec-cu11

Hi,

I have try the steps you show me here. But the issue is still there.

Thanks!

Hi @zebing_wang

The recent versions of LightningGPU (0.35 and 0.36) migrated to use CUDA 12 by default (release notes for 0.35 here).
If you are running a CUDA 11 system, you can try to download the CUDA 12 runtime libraries with:

python -m pip install nvidia-cusparse-cu12 nvidia-cublas-cu12 nvidia-cuda-runtime-cu12 custatevec-cu12

rather than the CUDA 11 versions. Assuming your driver is recent enough, the CUDA 12 libraries should work. Also, please ensure the version of LightningGpu is installed from PennyLane-Lightning-GPU · PyPI — if you are running on a managed HPC system, it is possible your administrators may intercept and prevent outside libraries, which may also stop you from having the pre-built wheels being installed. If so, you can manually download the wheel from that URL and install it directly with pip.

Let us know if this helps.