QNN with lightning.gpu device

I am able to run the Quanvolutional Neural Network example at

with lightning.qubit. However when I switch in lightning.gpu I get the following output:

Quantum pre-processing of train images:
Traceback (most recent call last):
File “quanvolutional_nn.py”, line 81, in
q_train_images.append(quanv(img))
File “quanvolutional_nn.py”, line 62, in quanv
q_results = circuit(
File “/home/arthurlobo/.conda/envs/qml_py38_b/lib/python3.8/site-packages/pennylane/qnode.py”, line 660, in call
res = qml.execute(
File “/home/arthurlobo/.conda/envs/qml_py38_b/lib/python3.8/site-packages/pennylane/interfaces/execution.py”, line 443, in execute
res = _execute(
File “/home/arthurlobo/.conda/envs/qml_py38_b/lib/python3.8/site-packages/pennylane/interfaces/tensorflow.py”, line 89, in execute
res, jacs = execute_fn(tapes, **gradient_kwargs)
File “/home/arthurlobo/.conda/envs/qml_py38_b/lib/python3.8/site-packages/pennylane/interfaces/execution.py”, line 197, in wrapper
res = fn(execution_tapes.values(), **kwargs)
File “/home/arthurlobo/.conda/envs/qml_py38_b/lib/python3.8/site-packages/pennylane/interfaces/execution.py”, line 122, in fn
return original_fn(tapes, **kwargs)
File “/home/arthurlobo/.conda/envs/qml_py38_b/lib/python3.8/contextlib.py”, line 75, in inner
return func(*args, **kwds)
File “/home/arthurlobo/.conda/envs/qml_py38_b/lib/python3.8/site-packages/pennylane/_qubit_device.py”, line 576, in batch_execute
res = self.execute(circuit)
File “/home/arthurlobo/.conda/envs/qml_py38_b/lib/python3.8/site-packages/pennylane/_qubit_device.py”, line 323, in execute
results = self.statistics(circuit.observables)
File “/media/arthurlobo/QML/pennylane_lightning_gpu_38/pennylane-lightning-gpu/pennylane_lightning_gpu/lightning_gpu.py”, line 149, in statistics
return super().statistics(observables, shot_range, bin_size, circuit)
TypeError: statistics() takes from 2 to 4 positional arguments but 5 were given

Any suggestions?

Hi @art, what version of lightning are you using?

Could you please post de output of qml.about()?

I can see that we made a change in the statistics (in the dev version) method due to an API change.

If you’re using v0.25 you can install the development version by using python -m pip install git+https://github.com/PennyLaneAI/pennylane-lightning-gpu.git#egg=pennylane-lightning-gpu.

Could you please post de output of qml.about() ?

@CatalinaAlbornoz I had been using PennyLane-Lightning-GPU-0.26.0.dev0.

Output of qml.about():

Platform info: Linux-5.10.104-tegra-aarch64-with-glibc2.26
Python version: 3.8.13
Numpy version: 1.23.2
Scipy version: 1.9.1
Installed devices:

  • lightning.gpu (PennyLane-Lightning-GPU-0.26.0.dev0)
  • braket.aws.qubit (amazon-braket-pennylane-plugin-1.6.9)
  • braket.local.qubit (amazon-braket-pennylane-plugin-1.6.9)
  • lightning.qubit (PennyLane-Lightning-0.25.1)
  • default.gaussian (PennyLane-0.25.1)
  • default.mixed (PennyLane-0.25.1)
  • default.qubit (PennyLane-0.25.1)
  • default.qubit.autograd (PennyLane-0.25.1)
  • default.qubit.jax (PennyLane-0.25.1)
  • default.qubit.tf (PennyLane-0.25.1)
  • default.qubit.torch (PennyLane-0.25.1)
  • default.qutrit (PennyLane-0.25.1)

Hi @art,

I see that you have PennyLane v0.25.1. In that case pennylane-lightning-gpu v0.25.0 should work.

You can install it by using python -m pip install pennylane-lightning[gpu]==0.25.0

Does this work for you?

@CatalinaAlbornoz

You can install it by using python -m pip install pennylane-lightning[gpu]==0.25.0

the above line did not work for me. qml.about() still shows v0.26.0.dev0.

For my aarch64 install @mlxd had suggested the following steps
which builds from source and installs lightning_gpu_qubit_ops.cpython-38-aarch64-linux-gnu.so in the pennylane-lightning-gpu sub-folder:

git clone https://github.com/PennyLaneAI/pennylane-lightning-gpu
cd pennylane-lightning-gpu
python -m pip install -e .

(installs v0.26.0.dev0).

Is it possible to checkout a specific branch (0.25.0) to build from source?

Hi @art
The issue here is that for a manual build from lightning.gpu v0.26, you also need the up-to-date master branch of pennylane

Maybe keep the lightning.gpu (PennyLane-Lightning-GPU-0.26.0.dev0) version, and on-top of it install pennylane as python -m pip install git+https://github.com/PennyLaneAI/pennylane.git@master.

That should hopefully fix the issue, until the next release version in a few weeks.

1 Like

@CatalinaAlbornoz that worked. I am able to use lightning.gpu and lightning.qubit with PyTorch and TensorFlow CUDA versions. Note that if I specify default.qubit I get an error as shown:

Platform info: Linux-5.10.104-tegra-aarch64-with-glibc2.26
Python version: 3.8.13
Numpy version: 1.23.2
Scipy version: 1.9.1
Installed devices:

  • lightning.gpu (PennyLane-Lightning-GPU-0.26.0.dev0)
  • braket.aws.qubit (amazon-braket-pennylane-plugin-1.6.9)
  • braket.local.qubit (amazon-braket-pennylane-plugin-1.6.9)
  • default.gaussian (PennyLane-0.26.0.dev0)
  • default.mixed (PennyLane-0.26.0.dev0)
  • default.qubit (PennyLane-0.26.0.dev0)
  • default.qubit.autograd (PennyLane-0.26.0.dev0)
  • default.qubit.jax (PennyLane-0.26.0.dev0)
  • default.qubit.tf (PennyLane-0.26.0.dev0)
  • default.qubit.torch (PennyLane-0.26.0.dev0)
  • default.qutrit (PennyLane-0.26.0.dev0)
  • lightning.qubit (PennyLane-Lightning-0.25.1)
    Traceback (most recent call last):
    File “quanvolutional_nn.py”, line 39, in
    dev = qml.device(“default.qubit”, wires=4)
    File “/home/arthurlobo/.conda/envs/qml_py38_b/lib/python3.8/site-packages/pennylane/init.py”, line 314, in device
    raise DeviceError(
    pennylane._device.DeviceError: The default.qubit plugin requires PennyLane versions 0.26.0-dev, however PennyLane version 0.26.0-dev is installed.

Hi @art, thank you for pointing this out. This looks like a bug in our development version. v0.26 should be released in 2 weeks so it should be fixed by then.