Pennylane-Lightning GPU

I am running a code on gpu. The code is:

import pennylane as qml


dev4 = qml.device("lightning.gpu", wires=wires)  # define the simulator
def CONVCircuit(phi, wires, i=0):
    quantum convolution Node
    # parameter
    theta = np.pi / 2

    qml.RX(phi[0] * np.pi, wires=0)
    qml.RX(phi[1] * np.pi, wires=1)
    qml.RX(phi[2] * np.pi, wires=2)
    qml.RX(phi[3] * np.pi, wires=3)

    qml.CRZ(theta, wires=[1, 0])
    qml.CRZ(theta, wires=[3, 2])
    qml.CRX(theta, wires=[1, 0])
    qml.CRX(theta, wires=[3, 2])
    qml.CRZ(theta, wires=[2, 0])
    qml.CRX(theta, wires=[2, 0])

    # Expectation value
    measurement = qml.expval(qml.PauliZ(wires=0))

    return measurement

def QCONV1(X, image_number, image_total, step=2):
    quantum convolutional layer

    #H, W, CH = X.shape
    H, W = X.shape
    step2 = 2
    out = np.zeros(((H//step), (W//step)))
    #progress = 0
    for i in range(0, W, step):
        #print("processing image "+str(image_number)+"/ "+str(image_total)+": "+str(int(((i/W+1))*100))+"% ", end="\r")
        print("processing image "+str(image_number)+"/ "+str(image_total)+": "+str(i)+"px   ", end="\r")
        for j in range(0, H, step):
            # get 2x2 pixels and make them 1D array
            phi = X[i:i+2, j:j+2].flatten()
            # Get Measurement
            measurement = CONVCircuit(phi, len(phi))
            out[i//step, j//step] = measurement

    return out

I am getting the error:

Error in PennyLane Lightning: the provided PTX was compiled with an unsupported toolchain.

I am executing the code on the NVIDIA DGX-1 server, which has 512 GB RAM, 7TB SSD, 40 CPU cores and 8 of V100(Volta) GPUs running the Ubuntu 18.04 operating system.

Hi @mass_of_15. Can you confirm for me your version of lightning.gpu, and the version of CUDA on your system, as well as the output of qml.about().

I suspect this is due to the library being compiled with a newer version of CUDA than your system has available. Can you try upgrading the version of PennyLane Lightning-GPU, and seeing if this fixes your issue:

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

We issued a release today that aims to support CUDA toolchains from 11.5 and newer, which may solve your problem if the CUDA version is the issue.

The output of qml.about():

Name: PennyLane
Version: 0.26.0
Summary: PennyLane is a Python quantum machine learning library by Xanadu Inc.
License: Apache License 2.0
Location: /usr/local/lib/python3.8/dist-packages
Requires: appdirs, autograd, autoray, cachetools, networkx, numpy, pennylane-lightning, retworkx, scipy, semantic-version, toml
Required-by: PennyLane-Lightning, PennyLane-Lightning-GPU

Platform info:           Linux-4.15.0-140-generic-x86_64-with-glibc2.29
Python version:          3.8.10
Numpy version:           1.18.5
Scipy version:           1.9.2
Installed devices:
- lightning.gpu (PennyLane-Lightning-GPU-0.28.0)
- lightning.qubit (PennyLane-Lightning-0.26.0)
- default.gaussian (PennyLane-0.26.0)
- default.mixed (PennyLane-0.26.0)
- default.qubit (PennyLane-0.26.0)
- default.qubit.autograd (PennyLane-0.26.0)
- default.qubit.jax (PennyLane-0.26.0)
- (PennyLane-0.26.0)
- default.qubit.torch (PennyLane-0.26.0)
- default.qutrit (PennyLane-0.26.0)

The CUDA version is 11.0

Are there any compatible versions?

Hi @mass_of_15

I can see two issues:

  1. The version of PennyLane installed is much older than the version of LightningGPU. It would be best to ensure all packages share the common minor versioning (in this case, 0.28.x). You can upgrade PennyLane with python -m pip install pennylane --upgrade
  2. CUDA 11.0 is too old to work with LightningGPU — we currently require a minimum CUDA version of 11.5. Assuming your CUDA driver is at least 450.x, it should be possible to simply upgrade the CUDA runtime libraries. If this is a managed system, I suggest requesting a system administrator to upgrade the CUDA installation. If not, you can download a new CUDA version from NVIDIA’s website, and add the new CUDA library directory to your LD_LIBRARY_PATH.

With both, it should be possible to run using the V100 devices. Feel free to let us know if you require any further assistance.

Hi, Now I have PennyLane - 0.28.0, PennyLane-Lightning -v0.28.1 and PennyLane-Lightning-GPU -v0.28.1. and CUDA -v11.5.
This time I am getting another error:

name 'PLException' is not defined

Is there any name or variable not defined by me?
Please look into this.

Hi @mass_of_15
Can you try creating a fresh environment, and retry your script?

python3 -m venv pyenv
source ./pyenv/bin/activate
python -m pip install pennylane pennylane-lightning-gpu cuquantum

It may be possible that due to the 0.26 → 0.28 change, the updates did not correctly take. If this does not work, please feel free to let me know and we can aim to debug further.

1 Like