Issues with pennylane lightning installation

I am running the following code:

import pennylane as qml
from timeit import default_timer as timer

# To set the number of threads used when executing this script,
# export the OMP_NUM_THREADS environment variable.ls

# Choose number of qubits (wires) and circuit layers
wires = 15
layers = 3

# Set number of runs for timing averaging
num_runs = 5

# Instantiate CPU (lightning.qubit) or GPU (lightning.gpu) device
dev = qml.device('lightning.qubit', wires=wires)


# Create QNode of device and circuit
@qml.qnode(dev, diff_method="adjoint")
def circuit(parameters):
    qml.StronglyEntanglingLayers(weights=parameters, wires=range(wires))
    return [qml.expval(qml.PauliZ(i)) for i in range(wires)]

# Set trainable parameters for calculating circuit Jacobian
shape = qml.StronglyEntanglingLayers.shape(n_layers=layers, n_wires=wires)
weights = qml.numpy.random.random(size=shape)

# Run, calculate the quantum circuit Jacobian, and average the timing results
timing = []
for t in range(num_runs):
    start = timer()
    jac = qml.jacobian(circuit)(weights)
    end = timer()
    timing.append(end - start)

print("Result: ", qml.numpy.mean(timing))

When the device is “lightning.qubit”, I get the following warning message

/home/sinha/miniconda3/envs/qns/lib/python3.8/site-packages/pennylane_lightning/lightning_qubit.py:893: UserWarning: Pre-compiled binaries for lightning.qubit are not available. Falling back to using the Python-based default.qubit implementation. To manually compile f
rom source, follow the instructions at https://pennylane-lightning.readthedocs.io/en/latest/installation.html.

And when the device is “lightning.gpu”, I get the following error message.

Traceback (most recent call last):
  File "/home/sinha/miniconda3/envs/qns/lib/python3.8/site-packages/pennylane_lightning_gpu/lightning_gpu.py", line 54, in <module>
    from .lightning_gpu_qubit_ops import (
ImportError: libcudart.so.11.0: cannot open shared object file: No such file or directory

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "trial_lightninig_gpu.py", line 15, in <module>
    dev = qml.device('lightning.gpu', wires=wires)
  File "/home/sinha/miniconda3/envs/qns/lib/python3.8/site-packages/pennylane/__init__.py", line 316, in device
    plugin_device_class = plugin_devices[name].load()
  File "/home/sinha/miniconda3/envs/qns/lib/python3.8/site-packages/pkg_resources/__init__.py", line 2471, in load
    return self.resolve()
  File "/home/sinha/miniconda3/envs/qns/lib/python3.8/site-packages/pkg_resources/__init__.py", line 2477, in resolve
    module = __import__(self.module_name, fromlist=['__name__'], level=0)
  File "/home/sinha/miniconda3/envs/qns/lib/python3.8/site-packages/pennylane_lightning_gpu/__init__.py", line 17, in <module>
    from .lightning_gpu import LightningGPU
  File "/home/sinha/miniconda3/envs/qns/lib/python3.8/site-packages/pennylane_lightning_gpu/lightning_gpu.py", line 92, in <module>
    except (ModuleNotFoundError, ImportError, ValueError, PLException) as e:
NameError: name 'PLException' is not defined

Output of qml.about().

>>> qml.about()
Name: PennyLane
Version: 0.28.0
Summary: PennyLane is a Python quantum machine learning library by Xanadu Inc.
Home-page: https://github.com/XanaduAI/pennylane
Author:
Author-email:
License: Apache License 2.0
Location: /home/sinha/miniconda3/envs/qns/lib/python3.8/site-packages
Requires: appdirs, autograd, autoray, cachetools, networkx, numpy, pennylane-lightning, requests, retworkx, scipy, semantic-version, toml
Required-by: PennyLane-Lightning, PennyLane-Lightning-GPU

Platform info:           Linux-5.4.0-147-generic-x86_64-with-glibc2.17
Python version:          3.8.16
Numpy version:           1.22.3
Scipy version:           1.7.3
Installed devices:
- lightning.gpu (PennyLane-Lightning-GPU-0.30.0)
- lightning.qubit (PennyLane-Lightning-0.28.1)
- default.gaussian (PennyLane-0.28.0)
- default.mixed (PennyLane-0.28.0)
- default.qubit (PennyLane-0.28.0)
- default.qubit.autograd (PennyLane-0.28.0)
- default.qubit.jax (PennyLane-0.28.0)
- default.qubit.tf (PennyLane-0.28.0)
- default.qubit.torch (PennyLane-0.28.0)
- default.qutrit (PennyLane-0.28.0)
- null.qubit (PennyLane-0.28.0)

I am not sure, where exactly is the problem.

Hey @imakash! It might be worth updating to the most-recent versions of everything — some of your package versions are out-of-sync (you’re pretty up-to-speed with lightning-gpu but not pl-lightning or pennylane)

You can try building pl-lightning from source via pip install pybind11 pennylane-lightning --no-binary :all:.

This forum post might be helpful!

Hello @isaacdevlugt ,

Thanks for your response. Actually this is just a dummy code to test pennylane lightning. I am actually training a Hybrid quantum Classical neural network. If I cannot make this work, can I use ‘pytorch’ interface with 'defaul.qubit" device to train on GPU a hybrid quantum-classical neural network?

If I can use ‘default.qubit’ for running the code on GPU, then what benefit does pennylane-lightning offer?

can I use ‘pytorch’ interface with 'defaul.qubit" device to train on GPU a hybrid quantum-classical neural network

Yeah that will work! For relatively small problems (<<20 qubits) this is a better option that using pl-lightning-gpu.

If I can use ‘default.qubit’ for running the code on GPU, then what benefit does pennylane-lightning offer?

It’s much much faster for large simulations (>20 qubits). But, pennylane-lightning-gpu’s claim to fame is that it combines NVIDIA’s cuQuantum SDK library with what Pennylane offers in the way of automatic differentiation, optimization, and direct support for GPU-enabled quantum gradients with adjoint differentiation. All of those points culminate in higher performance for larger circuits.

1 Like