Pennylane Jetson Xavier NX Error while running

I am using a Jetson Xavier NX with Ubuntu 20.04. The nvcc version is
nvcc: NVIDIA (R) Cuda compiler driver
Copyright (c) 2005-2022 NVIDIA Corporation
Built on Sun_Oct_23_22:16:07_PDT_2022
Cuda compilation tools, release 11.4, V11.4.315
Build cuda_11.4.r11.4/compiler.31964100_0

So this is my code:

wires=4
dev4 = qml.device("lightning.gpu", wires=wires )
@qml.qnode(dev4)
def CONVCircuit(phi, wires, i=0):
    """
    quantum convolution Node
    """
    # parameter
    theta = np.pi / 2
    qml.Rot(phi[0]*2*np.pi/255,phi[1]*2*np.pi/255,phi[2]*2*np.pi/255, wires=0)
    qml.Rot(phi[3]*2*np.pi/255,phi[4]*2*np.pi/255,phi[5]*2*np.pi/255, wires=1)
    qml.Rot(phi[6]*2*np.pi/255,phi[7]*2*np.pi/255,phi[8]*2*np.pi/255, wires=2)
    qml.Rot(phi[9]*2*np.pi/255,phi[10]*2*np.pi/255,phi[11]*2*np.pi/255, wires=3)

    qml.RX(np.pi, wires=0)
    qml.RX(np.pi, wires=1)
    qml.RX(np.pi, wires=2)
    qml.RX(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

This is the error message below:


File ~/anaconda3/envs/myenv/lib/python3.10/site-packages/pennylane/qnode.py:847, in QNode.__call__(self, *args, **kwargs)
    843     self._update_original_device()
    845     return res
--> 847 res = qml.execute(
    848     [self.tape],
    849     device=self.device,
    850     gradient_fn=self.gradient_fn,
    851     interface=self.interface,
    852     gradient_kwargs=self.gradient_kwargs,
    853     override_shots=override_shots,
    854     **self.execute_kwargs,
    855 )
    857 if old_interface == "auto":
    858     self.interface = "auto"

File ~/anaconda3/envs/myenv/lib/python3.10/site-packages/pennylane/interfaces/execution.py:724, in execute(tapes, device, gradient_fn, interface, mode, gradient_kwargs, cache, cachesize, max_diff, override_shots, expand_fn, max_expansion, device_batch_transform)
    718 except ImportError as e:
    719     raise qml.QuantumFunctionError(
    720         f"{mapped_interface} not found. Please install the latest "
    721         f"version of {mapped_interface} to enable the '{mapped_interface}' interface."
    722     ) from e
--> 724 res = _execute(
    725     tapes, device, execute_fn, gradient_fn, gradient_kwargs, _n=1, max_diff=max_diff, mode=_mode
    726 )
    728 return batch_fn(res)

File ~/anaconda3/envs/myenv/lib/python3.10/site-packages/pennylane/interfaces/autograd.py:81, in execute(tapes, device, execute_fn, gradient_fn, gradient_kwargs, _n, max_diff, mode)
     75 # pylint misidentifies autograd.builtins as a dict
     76 # pylint: disable=no-member
     77 parameters = autograd.builtins.tuple(
     78     [autograd.builtins.list(t.get_parameters()) for t in tapes]
     79 )
---> 81 return _execute(
     82     parameters,
     83     tapes=tapes,
     84     device=device,
     85     execute_fn=execute_fn,
     86     gradient_fn=gradient_fn,
     87     gradient_kwargs=gradient_kwargs,
     88     _n=_n,
     89     max_diff=max_diff,
     90 )[0]

File ~/anaconda3/envs/myenv/lib/python3.10/site-packages/autograd/tracer.py:48, in primitive.<locals>.f_wrapped(*args, **kwargs)
     46     return new_box(ans, trace, node)
     47 else:
---> 48     return f_raw(*args, **kwargs)

File ~/anaconda3/envs/myenv/lib/python3.10/site-packages/pennylane/interfaces/autograd.py:125, in _execute(parameters, tapes, device, execute_fn, gradient_fn, gradient_kwargs, _n, max_diff)
    104 """Autodifferentiable wrapper around ``Device.batch_execute``.
    105 
    106 The signature of this function is designed to work around Autograd restrictions.
   (...)
    122 understand the consequences!
    123 """
    124 with qml.tape.Unwrap(*tapes):
--> 125     res, jacs = execute_fn(tapes, **gradient_kwargs)
    127 for i, r in enumerate(res):
    128     if any(isinstance(m, CountsMP) for m in tapes[i].measurements):

File ~/anaconda3/envs/myenv/lib/python3.10/site-packages/pennylane/interfaces/execution.py:206, in cache_execute.<locals>.wrapper(tapes, **kwargs)
    202         return (res, []) if return_tuple else res
    204 else:
    205     # execute all unique tapes that do not exist in the cache
--> 206     res = fn(execution_tapes.values(), **kwargs)
    208 final_res = []
    210 for i, tape in enumerate(tapes):

File ~/anaconda3/envs/myenv/lib/python3.10/site-packages/pennylane/interfaces/execution.py:131, in cache_execute.<locals>.fn(tapes, **kwargs)
    129 def fn(tapes: Sequence[QuantumTape], **kwargs):  # pylint: disable=function-redefined
    130     tapes = [expand_fn(tape) for tape in tapes]
--> 131     return original_fn(tapes, **kwargs)

File ~/anaconda3/envs/myenv/lib/python3.10/contextlib.py:79, in ContextDecorator.__call__.<locals>.inner(*args, **kwds)
     76 @wraps(func)
     77 def inner(*args, **kwds):
     78     with self._recreate_cm():
---> 79         return func(*args, **kwds)

File ~/anaconda3/envs/myenv/lib/python3.10/site-packages/pennylane/_qubit_device.py:656, in QubitDevice.batch_execute(self, circuits)
    653     self.reset()
    655     # TODO: Insert control on value here
--> 656     res = self.execute(circuit)
    657     results.append(res)
    659 if self.tracker.active:

File ~/anaconda3/envs/myenv/lib/python3.10/site-packages/pennylane/_qubit_device.py:445, in QubitDevice.execute(self, circuit, **kwargs)
    443     results = self._collect_shotvector_results(circuit, counts_exist)
    444 else:
--> 445     results = self.statistics(circuit=circuit)
    447 if not circuit.is_sampled:
    449     if len(measurements) == 1:

File ~/pennylane-lightning-gpu-0.28.0_rc0/pennylane_lightning_gpu/lightning_gpu.py:407, in LightningGPU.statistics(self, circuit, shot_range, bin_size)
    405 def statistics(self, circuit, shot_range=None, bin_size=None):
    406     ## Ensure D2H sync before calculating non-GPU supported operations
--> 407     return super().statistics(circuit, shot_range, bin_size)

File ~/anaconda3/envs/myenv/lib/python3.10/site-packages/pennylane/_qubit_device.py:807, in QubitDevice.statistics(self, observables, shot_range, bin_size, circuit)
    803 # TODO: Remove return_type when `observables` argument is removed from this method
    804 # Pass instances directly
    805 elif obs.return_type is Expectation:
    806     # Appends a result of shape (num_bins,) if bin_size is not None, else a scalar
--> 807     results.append(self.expval(obs, shot_range=shot_range, bin_size=bin_size))
    809 elif obs.return_type is Variance:
    810     # Appends a result of shape (num_bins,) if bin_size is not None, else a scalar
    811     results.append(self.var(obs, shot_range=shot_range, bin_size=bin_size))

File ~/pennylane-lightning-gpu-0.28.0_rc0/pennylane_lightning_gpu/lightning_gpu.py:741, in LightningGPU.expval(self, observable, shot_range, bin_size)
    729         return self._gpu_state.ExpectationValue(
    730             device_wires, qml.matrix(observable).ravel(order="C")
    731         )
    733 par = (
    734     observable.parameters
    735     if (
   (...)
    739     else []
    740 )
--> 741 return self._gpu_state.ExpectationValue(
    742     observable.name,
    743     self.wires.indices(observable.wires),
    744     par,  # observables should not pass parameters, use matrix instead
    745     qml.matrix(observable).ravel(order="C"),
    746 )

PLException: [/home/auvmu/pennylane-lightning-gpu-0.28.0_rc0/pennylane_lightning_gpu/src/simulator/StateVectorCudaManaged.hpp][Line:1683][Method:getExpectationValueDeviceMatrix]: Error in PennyLane Lightning: Internal custatevec error


The output of 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/auvmu/anaconda3/envs/myenv/lib/python3.10/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.10.104-tegra-aarch64-with-glibc2.31
Python version:          3.10.12
Numpy version:           1.23.5
Scipy version:           1.11.1
Installed devices:
- 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)
- lightning.qubit (PennyLane-Lightning-0.28.0)
- lightning.gpu (PennyLane-Lightning-GPU-0.28.0)

Hi @Harshavardhan_Reddy

Since we do not explicitly ship wheels for LightningGPU to support ARM64 yet, I am curious if you have built from source? Also, which version of cuquantum/custatevec have you installed?

Currently the LightningGPU 0.28 release you have installed (we have now released 0.31) supports x86_64 and CUDA 11. I would suggest checking your installed version of CUDA, and making sure it is somewhere between 11.5 and 11.8, and that the installed custatevec library in CUDA 11, rather than CUDA 12.

If you wish to upgrade your install to 0.31, and want to enable CUDA 12, you can build the package from source followin the instructions at GitHub - PennyLaneAI/pennylane-lightning-gpu: GPU-enabled device for PennyLane

Feel free to reach out if any of the above does not help.

I have built from source following the steps in Lightning GPU 0.25 on Jetson Xavier NX - #26 by mlxd? .
These are the versions which I have installed.
cuquantum==23.6.1
cuquantum-cu11==23.6.1
custatevec-cu11==1.4.1

Hi @Harshavardhan_Reddy
I was able to run your script on an x86_64 machine using LightningGPU 0.31.0 and custatevec-cu11.

Since I do not have access to an ARM64+CUDA Jetson system to test, I will suggest trying the following:

  • Ensure the installed CUDA version is between 11.5 and 11.8. CUDA 12 and above will not work correctly
  • Ensure you are using the latest version of PennyLane and LightningGPU (0.31 in both cases)
  • If you have access to an x86_64 CUDA machine, try the execution there and see if the failure occurs. If not, this could be an issue with the Jetson device — LightningGPU is primarily built for use with large circuits and qubit registers (20+ qubit) with V100, A100 and H100 GPUs, so NVIDIA’s custatevec may not work as intended with the Jetson ecosystem.

You can also try to run your circuit using lightning.qubit our CPU device, and seeing if that succeeds to run your circuit.

1 Like

I have tried to repeat the installation process with CUDA 11.8.

This is the error I get when I try to run the code:
1 wires=4
----> 2 dev4 = qml.device(“lightning.gpu”, wires=wires )
3 @qml.qnode(dev4)
4 def CONVCircuit(phi, wires, i=0):
5 “”"
6 quantum convolution Node
7 “”"

File ~/anaconda3/envs/env1/lib/python3.10/site-packages/pennylane/init.py:325, in device(name, *args, **kwargs)
319 raise DeviceError(
320 f"The {name} plugin requires PennyLane versions {plugin_device_class.pennylane_requires}, "
321 f"however PennyLane version {version} is installed."
322 )
324 # Construct the device
→ 325 dev = plugin_device_class(*args, **options)
327 # Once the device is constructed, we set its custom expansion function if
328 # any custom decompositions were specified.
329 if custom_decomps is not None:

File ~/pennylane-lightning-gpu-0.28.0_rc0/pennylane_lightning_gpu/lightning_gpu.py:216, in LightningGPU.init(self, wires, sync, c_dtype, shots, batch_obs)
214 raise TypeError(f"Unsupported complex Type: {c_dtype}")
215 super().init(wires, shots=shots, r_dtype=r_dtype, c_dtype=c_dtype)
→ 216 self._gpu_state = _gpu_dtype(c_dtype)(self.num_wires)
217 self._create_basis_state_GPU(0)
218 self._sync = sync

PLException: [/home/auvmu/pennylane-lightning-gpu-0.28.0_rc0/pennylane_lightning_gpu/src/util/DataBuffer.hpp][Line:37][Method:DataBuffer]: Error in PennyLane Lightning: no error

qml.about() output:
Name: PennyLane
Version: 0.28.0
Summary: PennyLane is a Python quantum machine learning library by Xanadu Inc.
Home-page: GitHub - PennyLaneAI/pennylane: PennyLane is a cross-platform Python library for differentiable programming of quantum computers. Train a quantum computer the same way as a neural network.
Author:
Author-email:
License: Apache License 2.0
Location: /home/auvmu/anaconda3/envs/env1/lib/python3.10/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.10.104-tegra-aarch64-with-glibc2.31
Python version: 3.10.12
Numpy version: 1.23.5
Scipy version: 1.11.1
Installed devices:

  • 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)
  • lightning.qubit (PennyLane-Lightning-0.28.0)
  • lightning.gpu (PennyLane-Lightning-GPU-0.28.0)

Since the issue is resulting from custatevec API calls, I’d suggest trying option 2 (upgrade the PL version to 0.31) and/or option 3 (try this workload on an x86_64 CUDA enabled system) from my earlier post.

It may be possible that the Jetson devices are not fully compatible with custatevec, in which case a non-embedded CUDA device may be required for this workload.

It runs on the x86_64. But I want to run it on Jetson. Is there a way to do so with any other versions of Pennylane.
As in option 2 I have installed Pennylane 0.31.
CUDA version:

nvcc: NVIDIA (R) Cuda compiler driver
Copyright (c) 2005-2023 NVIDIA Corporation
Built on Tue_Jun_13_19:22:54_PDT_2023
Cuda compilation tools, release 12.2, V12.2.91
Build cuda_12.2.r12.2/compiler.32965470_0

For the time being I am trying to run this code:

from pennylane import numpy as np
import pennylane as qml
from pennylane.templates.layers import StronglyEntanglingLayers
from numpy.random import random

n_wires=4
dev = qml.device("lightning.gpu", wires=n_wires)
@qml.qnode(dev, diff_method="adjoint")
def circuit(weights):
    qml.StronglyEntanglingLayers(weights, wires=list(range(n_wires)))
    return [qml.expval(qml.PauliZ(i)) for i in range(n_wires)]

param_shape = qml.StronglyEntanglingLayers.shape(n_layers=2, n_wires=4)
params = np.random.random(param_shape)
jac = qml.jacobian(circuit)(params)

The error I am getting is:

Traceback (most recent call last):
  File "/home/auvmu/trial.py", line 10, in <module>
    dev = qml.device("lightning.gpu", wires=n_wires)
  File "/home/auvmu/anaconda3/envs/env2/lib/python3.10/site-packages/pennylane/__init__.py", line 337, in device
    dev = plugin_device_class(*args, **options)
  File "/home/auvmu/pennylane-lightning-gpu-0.31.0_rc/pennylane_lightning_gpu/lightning_gpu.py", line 258, in __init__
    self._gpu_state = _gpu_dtype(c_dtype)(self._num_local_wires)
pennylane_lightning_gpu.lightning_gpu_qubit_ops.PLException: [/home/auvmu/pennylane-lightning-gpu-0.31.0_rc/pennylane_lightning_gpu/src/util/DataBuffer.hpp][Line:37][Method:DataBuffer]: Error in PennyLane Lightning: no error

qml.about() output:

Name: PennyLane
Version: 0.31.0
Summary: PennyLane is a Python quantum machine learning library by Xanadu Inc.
Home-page: https://github.com/PennyLaneAI/pennylane
Author: 
Author-email: 
License: Apache License 2.0
Location: /home/auvmu/anaconda3/envs/env2/lib/python3.10/site-packages
Requires: appdirs, autograd, autoray, cachetools, networkx, numpy, pennylane-lightning, requests, rustworkx, scipy, semantic-version, toml
Required-by: PennyLane-Lightning, PennyLane-Lightning-GPU

Platform info:           Linux-5.10.104-tegra-aarch64-with-glibc2.31
Python version:          3.10.12
Numpy version:           1.23.5
Scipy version:           1.10.0
Installed devices:
- default.gaussian (PennyLane-0.31.0)
- default.mixed (PennyLane-0.31.0)
- default.qubit (PennyLane-0.31.0)
- default.qubit.autograd (PennyLane-0.31.0)
- default.qubit.jax (PennyLane-0.31.0)
- default.qubit.tf (PennyLane-0.31.0)
- default.qubit.torch (PennyLane-0.31.0)
- default.qutrit (PennyLane-0.31.0)
- null.qubit (PennyLane-0.31.0)
- lightning.qubit (PennyLane-Lightning-0.31.0)
- lightning.gpu (PennyLane-Lightning-GPU-0.31.0rc1)

Hi @Harshavardhan_Reddy
It seems you are still using CUDA 12, as your nvcc driver says:

Cuda compilation tools, release 12.2, V12.2.91
Build cuda_12.2.r12.2/compiler.32965470_0

You can try downgrade to CUDA 11.8, and see if this works, or you can try installing the custatevec-cu12 package, and removing the custatevec-cu11. If neither of these options works, I cannot guarantee that cuQuantum works on these devices.

You can try to use the lightning.kokkos device, following the instructions at GitHub - PennyLaneAI/pennylane-lightning-kokkos: Kokkos enabled Lightning simulator for accelerated circuit simulation with a CUDA backend build, as this could work, but I cannot guarantee without access to the platform to verify.

2 Likes

I tried with CUDA version 11.8. Still getting the same error.
I am using lightning.qubit for now.
Will try lightning.kokkos.
Thank you.

Hi @Harshavardhan_Reddy, thank you for reporting this. Please let us know how it goes using lightning.kokkos!