Pennylane GPU install

Hi am trying to install Pennylane GPU after I bought a new laptop.

The nvcc --version :

nvcc: NVIDIA (R) Cuda compiler driver
Copyright (c) 2005-2024 NVIDIA Corporation
Built on Tue_Oct_29_23:50:19_PDT_2024
Cuda compilation tools, release 12.6, V12.6.85
Build cuda_12.6.r12.6/compiler.35059454_0

I have done the steps mentioned in Lightning-GPU installation

git clone https://github.com/PennyLaneAI/pennylane-lightning.git
cd pennylane-lightning
pip install -r requirements.txt
pip install custatevec-cu12
PL_BACKEND="lightning_qubit" python scripts/configure_pyproject_toml.py
SKIP_COMPILATION=True pip install -e . --config-settings editable_mode=compat -vv

Then a CUQUANTUM_SDK environment variable can be set:

export CUQUANTUM_SDK=$(python -c "import site; print( f'{site.getsitepackages()[0]}/cuquantum')")

The Lightning-GPU can then be installed with pip:

PL_BACKEND="lightning_gpu" python scripts/configure_pyproject_toml.py
python -m pip install -e . --config-settings editable_mode=compat -vv

The last step gives:

  cmd_obj.run()
  Traceback (most recent call last):
    File "/home/sreerajwarrier98/miniconda3/lib/python3.12/site-packages/pip/_vendor/pyproject_hooks/_in_process/_in_process.py", line 353, in <module>
      main()
    File "/home/sreerajwarrier98/miniconda3/lib/python3.12/site-packages/pip/_vendor/pyproject_hooks/_in_process/_in_process.py", line 335, in main
      json_out['return_val'] = hook(**hook_input['kwargs'])
                               ^^^^^^^^^^^^^^^^^^^^^^^^^^^^
    File "/home/sreerajwarrier98/miniconda3/lib/python3.12/site-packages/pip/_vendor/pyproject_hooks/_in_process/_in_process.py", line 273, in build_editable
      return hook(wheel_directory, config_settings, metadata_directory)
             ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
    File "/tmp/pip-build-env-_px87h6e/overlay/lib/python3.12/site-packages/setuptools/build_meta.py", line 476, in build_editable
      return self._build_with_temp_dir(
             ^^^^^^^^^^^^^^^^^^^^^^^^^^
    File "/tmp/pip-build-env-_px87h6e/overlay/lib/python3.12/site-packages/setuptools/build_meta.py", line 407, in _build_with_temp_dir
      self.run_setup()
    File "/tmp/pip-build-env-_px87h6e/overlay/lib/python3.12/site-packages/setuptools/build_meta.py", line 320, in run_setup
      exec(code, locals())
    File "<string>", line 206, in <module>
    File "/tmp/pip-build-env-_px87h6e/overlay/lib/python3.12/site-packages/setuptools/__init__.py", line 117, in setup
      return distutils.core.setup(**attrs)
             ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
    File "/tmp/pip-build-env-_px87h6e/overlay/lib/python3.12/site-packages/setuptools/_distutils/core.py", line 186, in setup
      return run_commands(dist)
             ^^^^^^^^^^^^^^^^^^
    File "/tmp/pip-build-env-_px87h6e/overlay/lib/python3.12/site-packages/setuptools/_distutils/core.py", line 202, in run_commands
      dist.run_commands()
    File "/tmp/pip-build-env-_px87h6e/overlay/lib/python3.12/site-packages/setuptools/_distutils/dist.py", line 983, in run_commands
      self.run_command(cmd)
    File "/tmp/pip-build-env-_px87h6e/overlay/lib/python3.12/site-packages/setuptools/dist.py", line 999, in run_command
      super().run_command(command)
    File "/tmp/pip-build-env-_px87h6e/overlay/lib/python3.12/site-packages/setuptools/_distutils/dist.py", line 1002, in run_command
      cmd_obj.run()
    File "/tmp/pip-build-env-_px87h6e/overlay/lib/python3.12/site-packages/setuptools/command/editable_wheel.py", line 139, in run
      self._create_wheel_file(bdist_wheel)
    File "/tmp/pip-build-env-_px87h6e/overlay/lib/python3.12/site-packages/setuptools/command/editable_wheel.py", line 340, in _create_wheel_file
      files, mapping = self._run_build_commands(dist_name, unpacked, lib, tmp)
                       ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
    File "/tmp/pip-build-env-_px87h6e/overlay/lib/python3.12/site-packages/setuptools/command/editable_wheel.py", line 263, in _run_build_commands
      self._run_build_subcommands()
    File "/tmp/pip-build-env-_px87h6e/overlay/lib/python3.12/site-packages/setuptools/command/editable_wheel.py", line 290, in _run_build_subcommands
      self.run_command(name)
    File "/tmp/pip-build-env-_px87h6e/overlay/lib/python3.12/site-packages/setuptools/_distutils/cmd.py", line 339, in run_command
      self.distribution.run_command(command)
    File "/tmp/pip-build-env-_px87h6e/overlay/lib/python3.12/site-packages/setuptools/dist.py", line 999, in run_command
      super().run_command(command)
    File "/tmp/pip-build-env-_px87h6e/overlay/lib/python3.12/site-packages/setuptools/_distutils/dist.py", line 1002, in run_command
      cmd_obj.run()
    File "/tmp/pip-build-env-_px87h6e/overlay/lib/python3.12/site-packages/setuptools/command/build_ext.py", line 99, in run
      _build_ext.run(self)
    File "/tmp/pip-build-env-_px87h6e/overlay/lib/python3.12/site-packages/setuptools/_distutils/command/build_ext.py", line 365, in run
      self.build_extensions()
    File "/tmp/pip-build-env-_px87h6e/overlay/lib/python3.12/site-packages/setuptools/_distutils/command/build_ext.py", line 481, in build_extensions
      self._build_extensions_serial()
    File "/tmp/pip-build-env-_px87h6e/overlay/lib/python3.12/site-packages/setuptools/_distutils/command/build_ext.py", line 507, in _build_extensions_serial
      self.build_extension(ext)
    File "<string>", line 156, in build_extension
    File "/home/sreerajwarrier98/miniconda3/lib/python3.12/subprocess.py", line 413, in check_call
      raise CalledProcessError(retcode, cmd)
  subprocess.CalledProcessError: Command '['cmake', '--build', '.', '--verbose', '--config', 'RelWithDebInfo']' returned non-zero exit status 1.
  error: subprocess-exited-with-error

  Γ— Building editable for PennyLane_Lightning_GPU (pyproject.toml) did not run successfully.
  β”‚ exit code: 1
  ╰─> See above for output.

  note: This error originates from a subprocess, and is likely not a problem with pip.
  full command: /home/sreerajwarrier98/miniconda3/bin/python /home/sreerajwarrier98/miniconda3/lib/python3.12/site-packages/pip/_vendor/pyproject_hooks/_in_process/_in_process.py build_editable /tmp/tmpwoh2rf_3
  cwd: /mnt/c/Users/Sreeraj/pennylane-lightning
  Building editable for PennyLane_Lightning_GPU (pyproject.toml) ... error
  ERROR: Failed building editable for PennyLane_Lightning_GPU
Failed to build PennyLane_Lightning_GPU
Remote version of pip: 24.3.1
Local version of pip:  24.2
Was pip installed by pip? False
ERROR: ERROR: Failed to build installable wheels for some pyproject.toml based projects (PennyLane_Lightning_GPU)
Exception information:
Traceback (most recent call last):
  File "/home/sreerajwarrier98/miniconda3/lib/python3.12/site-packages/pip/_internal/cli/base_command.py", line 105, in _run_wrapper
    status = _inner_run()
             ^^^^^^^^^^^^
  File "/home/sreerajwarrier98/miniconda3/lib/python3.12/site-packages/pip/_internal/cli/base_command.py", line 96, in _inner_run
    return self.run(options, args)
           ^^^^^^^^^^^^^^^^^^^^^^^
  File "/home/sreerajwarrier98/miniconda3/lib/python3.12/site-packages/pip/_internal/cli/req_command.py", line 67, in wrapper
    return func(self, options, args)
           ^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/home/sreerajwarrier98/miniconda3/lib/python3.12/site-packages/pip/_internal/commands/install.py", line 434, in run
    raise InstallationError(
pip._internal.exceptions.InstallationError: ERROR: Failed to build installable wheels for some pyproject.toml based projects (PennyLane_Lightning_GPU)
Removed build tracker: '/tmp/pip-build-tracker-l0t3gydw'

I am using Windows Subsytem for Linux wsl to install Pennylane GPU. Please tell me where I am going wrong. I am able to install Pytorch but Pennylane-Lightning-GPU is where I am stuck.

>>> import pennylane as qml
>>> dev = qml.device('lightning.gpu', wires=2)
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/home/sreerajwarrier98/miniconda3/lib/python3.12/site-packages/pennylane/devices/device_constructor.py", line 243, in device
    plugin_device_class = plugin_devices[name].load()
                          ^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/home/sreerajwarrier98/miniconda3/lib/python3.12/importlib/metadata/__init__.py", line 205, in load
    module = import_module(match.group('module'))
             ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/home/sreerajwarrier98/miniconda3/lib/python3.12/importlib/__init__.py", line 90, in import_module
    return _bootstrap._gcd_import(name[level:], package, level)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "<frozen importlib._bootstrap>", line 1387, in _gcd_import
  File "<frozen importlib._bootstrap>", line 1360, in _find_and_load
  File "<frozen importlib._bootstrap>", line 1331, in _find_and_load_unlocked
  File "<frozen importlib._bootstrap>", line 935, in _load_unlocked
  File "<frozen importlib._bootstrap_external>", line 999, in exec_module
  File "<frozen importlib._bootstrap>", line 488, in _call_with_frames_removed
  File "/mnt/c/Users/Sreeraj/pennylane-lightning/pennylane_lightning/lightning_gpu/__init__.py", line 18, in <module>
    from .lightning_gpu import LightningGPU
  File "/mnt/c/Users/Sreeraj/pennylane-lightning/pennylane_lightning/lightning_gpu/lightning_gpu.py", line 33, in <module>
    from pennylane.devices.capabilities import OperatorProperties
ModuleNotFoundError: No module named 'pennylane.devices.capabilities'

The Ubuntu Version is:

No LSB modules are available.
Distributor ID: Ubuntu
Description:    Ubuntu 22.04.5 LTS
Release:        22.04
Codename:       jammy

Hi @mass_of_15.

Do you still get the error if you remove the β€œ-e” that you had in the last step?

Hi, I can confirm this issue. It happens probably because you are installing the released version of PennyLane whereas PennyLane Lightning GPU is getting installed from the latest branch. The solution is to install PennyLane too from the latest branch. The issue will be resolved when a new PennyLane version is released.

git clone https://github.com/PennyLaneAI/pennylane.git
cd pennylane
pip install . 
1 Like

Good catch @quantshah ! Thanks!

@CatalinaAlbornoz and @quantshah , Thank you. I saw the versions from both were different. Now I both of them are of same version and GPU is working properly.

Also, how many qubits do we need to get good GPU acceleration? I heard somewhere that it’s more than 20 qubits. Or can we still get the GPU acceleration in 15 qubits?