Skip to content

Commit

Permalink
Merge branch 'master' into cuda-wheel-dep
Browse files Browse the repository at this point in the history
  • Loading branch information
josephleekl committed Dec 16, 2024
2 parents cc608ee + 1782bbd commit ca44964
Show file tree
Hide file tree
Showing 6 changed files with 52 additions and 31 deletions.
6 changes: 6 additions & 0 deletions .github/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -84,11 +84,17 @@

### Documentation

* Add the exact tensor network to the Lightning-Tensor docs.
[(#1021)](https://github.com/PennyLaneAI/pennylane-lightning/pull/1021)

* Update Lightning-Tensor installation docs and usage suggestions.
[(#979)](https://github.com/PennyLaneAI/pennylane-lightning/pull/979)

### Bug fixes

* Update CUDA version to 12.4 for GPU tests on CI.
[(#1023)](https://github.com/PennyLaneAI/pennylane-lightning/pull/1023)

* Fix Lightning Kokkos `[[maybe_unused]]` and `exp2` errors with hipcc.
[(#1018)](https://github.com/PennyLaneAI/pennylane-lightning/pull/1018)

Expand Down
5 changes: 3 additions & 2 deletions .github/workflows/tests_gpu_cpp.yml
Original file line number Diff line number Diff line change
Expand Up @@ -40,14 +40,15 @@ jobs:
strategy:
max-parallel: 1
matrix:
cuda_version: ["12"]
cuda_version_maj: ["12"]
cuda_version_min: ["4"]

steps:
- name: Validate GPU version and installed compiler
run: |
source /etc/profile.d/modules.sh
module use /opt/modules
module load cuda/${{ matrix.cuda_version }}
module load cuda/${{ matrix.cuda_version_maj }}.${{ matrix.cuda_version_min }}
echo "${PATH}" >> $GITHUB_PATH
echo "LD_LIBRARY_PATH=${LD_LIBRARY_PATH}" >> $GITHUB_ENV
nvcc --version
Expand Down
5 changes: 3 additions & 2 deletions .github/workflows/tests_gpu_python.yml
Original file line number Diff line number Diff line change
Expand Up @@ -40,14 +40,15 @@ jobs:
strategy:
max-parallel: 1
matrix:
cuda_version: ["12"]
cuda_version_maj: ["12"]
cuda_version_min: ["4"]

steps:
- name: Validate GPU version and installed compiler
run: |
source /etc/profile.d/modules.sh
module use /opt/modules
module load cuda/${{ matrix.cuda_version }}
module load cuda/${{ matrix.cuda_version_maj }}.${{ matrix.cuda_version_min }}
echo "${PATH}" >> $GITHUB_PATH
echo "LD_LIBRARY_PATH=${LD_LIBRARY_PATH}" >> $GITHUB_ENV
nvcc --version
Expand Down
14 changes: 9 additions & 5 deletions .github/workflows/tests_lkcuda_cpp.yml
Original file line number Diff line number Diff line change
Expand Up @@ -48,15 +48,17 @@ jobs:
max-parallel: 1
matrix:
os: [ubuntu-22.04]
exec_model: ["CUDA"]
kokkos_version: ["4.5.00"]
exec_model: ["CUDA"]
cuda_version_maj: ["12"]
cuda_version_min: ["4"]

steps:
- name: Validate GPU version and installed compiler
run: |
source /etc/profile.d/modules.sh
module use /opt/modules
module load cuda/12.2
module load cuda/${{ matrix.cuda_version_maj }}.${{ matrix.cuda_version_min }}
echo "${PATH}" >> $GITHUB_PATH
echo "LD_LIBRARY_PATH=${LD_LIBRARY_PATH}" >> $GITHUB_ENV
nvcc --version
Expand Down Expand Up @@ -110,8 +112,10 @@ jobs:
matrix:
os: [ubuntu-22.04]
pl_backend: ["lightning_kokkos"]
exec_model: ["CUDA"]
kokkos_version: ["4.5.00"]
exec_model: ["CUDA"]
cuda_version_maj: ["12"]
cuda_version_min: ["4"]

name: C++ Tests (${{ matrix.pl_backend }}, kokkos-${{ matrix.kokkos_version }}, model-${{ matrix.exec_model }})
runs-on:
Expand All @@ -124,7 +128,7 @@ jobs:
run: |
source /etc/profile.d/modules.sh
module use /opt/modules
module load cuda/12.2
module load cuda/${{ matrix.cuda_version_maj }}.${{ matrix.cuda_version_min }}
echo "${PATH}" >> $GITHUB_PATH
echo "LD_LIBRARY_PATH=${LD_LIBRARY_PATH}" >> $GITHUB_ENV
nvcc --version
Expand Down Expand Up @@ -190,7 +194,7 @@ jobs:
run: |
cd main
cmake . -BBuild -G Ninja \
-DCMAKE_BUILD_TYPE=RelWithDebInfo \
-DCMAKE_BUILD_TYPE=Release \
-DBUILD_TESTS=ON \
-DENABLE_PYTHON=OFF \
-DSCIPY_OPENBLAS=$(python -c "import scipy_openblas32; print(scipy_openblas32.get_lib_dir())") \
Expand Down
12 changes: 8 additions & 4 deletions .github/workflows/tests_lkcuda_python.yml
Original file line number Diff line number Diff line change
Expand Up @@ -53,15 +53,17 @@ jobs:
max-parallel: 1
matrix:
os: [ubuntu-22.04]
exec_model: ["CUDA"]
kokkos_version: ["4.5.00"]
exec_model: ["CUDA"]
cuda_version_maj: ["12"]
cuda_version_min: ["4"]

steps:
- name: Validate GPU version and installed compiler
run: |
source /etc/profile.d/modules.sh
module use /opt/modules
module load cuda/12.2
module load cuda/${{ matrix.cuda_version_maj }}.${{ matrix.cuda_version_min }}
echo "${PATH}" >> $GITHUB_PATH
echo "LD_LIBRARY_PATH=${LD_LIBRARY_PATH}" >> $GITHUB_ENV
nvcc --version
Expand Down Expand Up @@ -115,8 +117,10 @@ jobs:
matrix:
os: [ubuntu-22.04]
pl_backend: ["lightning_kokkos", "all"]
exec_model: ["CUDA"]
kokkos_version: ["4.5.00"]
exec_model: ["CUDA"]
cuda_version_maj: ["12"]
cuda_version_min: ["4"]

name: Python Tests (${{ matrix.pl_backend }}, kokkos-${{ matrix.kokkos_version }}, model-${{ matrix.exec_model }})
runs-on:
Expand All @@ -129,7 +133,7 @@ jobs:
run: |
source /etc/profile.d/modules.sh
module use /opt/modules
module load cuda/12.2
module load cuda/${{ matrix.cuda_version_maj }}.${{ matrix.cuda_version_min }}
echo "${PATH}" >> $GITHUB_PATH
echo "LD_LIBRARY_PATH=${LD_LIBRARY_PATH}" >> $GITHUB_ENV
nvcc --version
Expand Down
41 changes: 23 additions & 18 deletions doc/lightning_tensor/device.rst
Original file line number Diff line number Diff line change
@@ -1,35 +1,27 @@
Lightning Tensor device
=======================

The ``lightning.tensor`` device is a tensor network simulator device. The device is built on top of the `cutensornet <https://docs.nvidia.com/cuda/cuquantum/latest/cutensornet/index.html>`__ from the NVIDIA cuQuantum SDK, enabling GPU-accelerated simulation of quantum tensor network evolution. This device is designed to simulate large-scale quantum circuits using tensor networks. For small circuits, state-vector simulator plugins may be more suitable.
The ``lightning.tensor`` device is a tensor network simulator, supporting both the Matrix Product State (MPS) and Exact Tensor Network methods. The device is built on top of the `cutensornet <https://docs.nvidia.com/cuda/cuquantum/latest/cutensornet/index.html>`__ from the NVIDIA cuQuantum SDK, enabling GPU-accelerated simulation of quantum tensor network evolution. This device is designed to simulate large-scale quantum circuits using tensor networks. For small circuits, state-vector simulator plugins may be more suitable.

A ``lightning.tensor`` device can be loaded simply using:
The ``lightning.tensor`` device defaults to the Matrix Product State (MPS) method, and can be loaded using:

.. code-block:: python
import pennylane as qml
dev = qml.device("lightning.tensor", wires=100)
By default, the device represents the quantum state approximated as a Matrix Product State (MPS).
By default, the device approximates the quantum state using an MPS.
The default setup for the MPS tensor network approximation is:
- ``max_bond_dim`` (maximum bond dimension) defaults to ``128`` .
- ``cutoff`` (singular value truncation threshold) defaults to ``0`` .
- ``cutoff_mode`` (singular value truncation mode) defaults to ``abs`` , considering the absolute values of the singular values; Alternatively, users can opt to set ``cutoff_mode`` to ``rel`` to consider the relative values of the singular values.
Note that the ``cutensornet`` will automatically determine the reduced extent of the bond dimension based on the lowest among the multiple truncation cutoffs (``max_bond_dim``, ``cutoff-abs`` and ``cutoff-rel``). For more details on how the ``cutoff`` works, please check it out the `cuQuantum documentation <https://docs.nvidia.com/cuda/cuquantum/latest/cutensornet/api/types.html#cutensornettensorsvdconfigattributes-t>`__.
Note that the ``cutensornet`` will automatically determine the reduced extent of the bond dimension based on the lowest among the multiple truncation cutoffs (``max_bond_dim``, ``cutoff-abs`` and ``cutoff-rel``). For more details on how the ``cutoff`` works, please check the `cuQuantum documentation <https://docs.nvidia.com/cuda/cuquantum/latest/cutensornet/api/types.html#cutensornettensorsvdconfigattributes-t>`__.

The ``lightning.tensor`` device dispatches all operations to be performed on a CUDA-capable GPU of generation SM 7.0 (Volta)
and greater. This device supports both exact and finite shots measurements. Currently, the supported differentiation methods are parameter-shift and finite-diff. Note that the MPS backend of lightning.tensor supports multi-wire gates via Matrix Product Operators (MPO).

The ``lightning.tensor`` device is designed for expectation value calculations. Measurements of ``qml.probs()`` or ``qml.state()`` return dense vectors of dimension :math:`2^{n_\text{qubits}}`, so they should only be used for small systems.

.. note:: ``qml.Hermitian`` is currently only supported for single wires. You can use ``qml.pauli_decompose`` on smaller matrices to obtain a compatible Pauli decomposition in the meantime.

Users also have the flexibility to customize these parameters according to their specific needs with:
Users also have the flexibility to customize MPS parameters according to their specific needs with:

.. code-block:: python
import pennylane as qml
import numpy as np
num_qubits = 100
Expand All @@ -41,7 +33,21 @@ Users also have the flexibility to customize these parameters according to their
dev = qml.device("lightning.tensor", wires=num_qubits, method="mps", **device_kwargs_mps)
The ``lightning.tensor`` device allows users to get quantum circuit gradients using the ``parameter-shift`` method. This can be enabled at the PennyLane ``QNode`` level with:
Users can also run the ``lightning.tensor`` device in the **Exact Tensor Network** mode by setting the ``method`` argument to ``"tn"``:

.. code-block:: python
import pennylane as qml
dev = qml.device("lightning.tensor", wires=100, method="tn")
The lightning.tensor device dispatches all operations to be performed on a CUDA-capable GPU of generation SM 7.0+ (Volta and later)
and greater. This device supports both exact and finite shots measurements. Currently, the supported differentiation methods are parameter-shift and finite-diff. Note that the MPS backend of ``lightning.tensor`` supports multi-wire gates via Matrix Product Operators (MPO).

The ``lightning.tensor`` device is designed for expectation value calculations. Measurements of :func:`~pennylane.probs` or :func:`~pennylane.state` return dense vectors of dimension :math:`2^{\text{n_qubits}}`, so they should only be used for small systems.

.. note:: Currently only single-wire :class:`~pennylane.Hermitian` observables are supported. You can use :func:`~pennylane.pauli_decompose` on smaller matrices to obtain a compatible Pauli decomposition in the meantime.

The ``lightning.tensor`` device allows users to get quantum circuit gradients using the :func:`~pennylane.gradients.param_shift` method. This can be enabled at the PennyLane :class:`~pennylane.QNode` level with:

.. code-block:: python
Expand All @@ -59,7 +65,7 @@ Note that as ``lightning.tensor`` cannot be cleaned up like other state-vector d
Operations and observables support
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

The "lightning.tensor" supports all gate operations supported by PennyLane.
The ``lightning.tensor`` supports all gate operations supported by PennyLane, with the exception of :class:`~pennylane.StatePrep`, which is *not supported* by the *Exact Tensor Network* method.

**Supported operations:**

Expand Down Expand Up @@ -128,9 +134,9 @@ The "lightning.tensor" supports all gate operations supported by PennyLane.

**Supported observables:**

The ``lightning.tensor`` supports all observables supported by the Lightning state-vector simulators, besides ``qml.SparseHamiltonian``, ``qml.Projector`` and limited support to ``qml.Hamiltonian``, ``qml.Prod`` since ``lightning.tensor`` only supports 1-wire Hermitian observables.
The ``lightning.tensor`` supports all observables supported by the Lightning state-vector simulators, besides :class:`~pennylane.SparseHamiltonian`, :class:`~pennylane.Projector` and limited support to :class:`~pennylane.ops.op_math.Sum`, :class:`~pennylane.ops.op_math.Prod` since ``lightning.tensor`` only supports 1-wire :class:`~pennylane.Hermitian` observables.

Users can not create a ``Hamiltonian`` or ``Prod`` observable from ``Hamiltonian`` observables.
Users cannot create a :class:`~pennylane.ops.op_math.Sum` observable or a :class:`~pennylane.ops.op_math.Prod` observable from :class:`~pennylane.ops.op_math.Sum` observables.



Expand All @@ -143,7 +149,6 @@ Users can not create a ``Hamiltonian`` or ``Prod`` observable from ``Hamiltonian

~pennylane.ops.op_math.Exp
~pennylane.Hadamard
~pennylane.Hamiltonian
~pennylane.Hermitian
~pennylane.Identity
~pennylane.PauliX
Expand Down

0 comments on commit ca44964

Please sign in to comment.