Skip to content

Commit

Permalink
Add C++ decomposition with scipy_openblas32 (#995)
Browse files Browse the repository at this point in the history
### Before submitting

Please complete the following checklist when submitting a PR:

- [ ] All new features must include a unit test.
If you've fixed a bug or added code that should be tested, add a test to
the
      [`tests`](../tests) directory!

- [ ] All new functions and code must be clearly commented and
documented.
If you do make documentation changes, make sure that the docs build and
      render correctly by running `make docs`.

- [ ] Ensure that the test suite passes, by running `make test`.

- [x] Add a new entry to the `.github/CHANGELOG.md` file, summarizing
the
      change, and including a link back to the PR.

- [x] Ensure that code is properly formatted by running `make format`. 

When all the above are checked, delete everything above the dashed
line and fill in the pull request template.


------------------------------------------------------------------------------------------------------------

**Context:**

[sc-78187] & [sc-53754]

The `blas/lapack` support is a long standing issue for `lightning`. The
main challenge is the wheels building for the `windows` platform, which
does not support a `fortran` compiler natively. Recently, the `scipy`
team release the standalone `scipy-openblas32` wheel for `linux`,
`windows` and `macos` platform. This could solve the win support issue.

There are a few technical discussions on how to add the
`scipy-openblas32` support to `lightning`:
- Dynamic loading vs static linking? Dynamic loading was chosen and the
`relative path` to the `libscipy_openblas` is added to the `runpath` of
the shared lib object of installations from wheel. In this case,
`scipy-openblas32` is required to be installed in the same
`site-packages` dir. However, for the direct C++ usage as well as `pip
editable install`, the absolute path to `libscipy_openblas` is still
needed to ensure the `libscipy_openblas` lib can be found and loaded.
- As a result, `scipy-openblas32` is a dependency of `lightning`.
- This implementation does not support `conda-forge`.

This PR also brings a few other changes:
- `BLASLib` loading is handled by a singleton class
`BLASLibLoaderManager`, instead of the `compute_diagonalizing_gates`
API.
- The `openblas` support is tested against `macos`, `linux` and
`windows` for the C++ tests on CIs and integration with `catalyst`
locally.
- An additional `cmake option`: `PY_INSTALL` is added to identify if the
pip installation is editable or not. This `PY_INSTALL` is `ON` if `not
self.editable_mode`.

**Description of the Change:**

**Benefits:**

**Possible Drawbacks:**

**Related GitHub Issues:**

---------

Co-authored-by: ringo-but-quantum <[email protected]>
Co-authored-by: lillian542 <[email protected]>
Co-authored-by: Ali Asadi <[email protected]>
  • Loading branch information
4 people authored Dec 4, 2024
1 parent f9e8f62 commit 705fe89
Show file tree
Hide file tree
Showing 42 changed files with 297 additions and 344 deletions.
25 changes: 14 additions & 11 deletions .github/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -17,13 +17,13 @@

### Breaking changes

* Removed all instances of `qml.QubitStateVector`.
[(#985)](https://github.com/PennyLaneAI/pennylane-lightning/pull/985)

* Handling for the legacy operator arithmetic (the `Hamiltonian` and `Tensor` classes in PennyLane) is removed.
[(#994)](https://github.com/PennyLaneAI/pennylane-lightning/pull/994)
[(#997)](https://github.com/PennyLaneAI/pennylane-lightning/pull/997)

* Removed all instances of `qml.QubitStateVector`.
[(#985)](https://github.com/PennyLaneAI/pennylane-lightning/pull/985)

### Improvements

* Update the logic for enabling `grad_on_execution` during device execution.
Expand All @@ -38,9 +38,20 @@
* Enable N-controlled gate and matrix support to `lightning.gpu` simulator for Catalyst.
[(#1005)](https://github.com/PennyLaneAI/pennylane-lightning/pull/1005)

* Generalize seeding mechanism for all measurements.
[(#1003)](https://github.com/PennyLaneAI/pennylane-lightning/pull/1003)

* `lightning.qubit`, `lightning.gpu`, and `lightning.kokkos` now define
the `eval_jaxpr` method for integration with the experimental
capture project.
[(#1002)](https://github.com/PennyLaneAI/pennylane-lightning/pull/1002)

* Update Kokkos version support to 4.4.1 and enable Lightning-Kokkos[CUDA] C++ tests on CI.
[(#1000)](https://github.com/PennyLaneAI/pennylane-lightning/pull/1000)

* Add native BLAS support to the C++ layer via dynamic `scipy-openblas32` loading.
[(#995)](https://github.com/PennyLaneAI/pennylane-lightning/pull/995)

* Update installation instruction for Lightning-GPU-MPI to explicitly ask users to add `path/to/libmpi.so` to the `LD_LIBRARY_PATH`. Update the runtime error message to ensure users know how to fix.
[(#993)](https://github.com/PennyLaneAI/pennylane-lightning/pull/993)

Expand All @@ -53,14 +64,6 @@
* Update the `lightning.kokkos` CUDA backend for compatibility with Catalyst.
[(#942)](https://github.com/PennyLaneAI/pennylane-lightning/pull/942)

* `lightning.qubit`, `lightning.gpu`, and `lightning.kokkos` now define
the `eval_jaxpr` method for integration with the experimental
capture project.
[(#1002)](https://github.com/PennyLaneAI/pennylane-lightning/pull/1002)

* Generalize seeding mechanism for all measurements.
[(#1003)](https://github.com/PennyLaneAI/pennylane-lightning/pull/1003)

### Documentation

* Update Lightning-Tensor installation docs and usage suggestions.
Expand Down
3 changes: 2 additions & 1 deletion .github/workflows/tests_gpu_cpp.yml
Original file line number Diff line number Diff line change
Expand Up @@ -124,7 +124,7 @@ jobs:
- name: Install required basic packages
run: |
python -m pip install ninja cmake scipy
python -m pip install ninja cmake scipy-openblas32
- name: Install required lightning_gpu only packages
if: matrix.pl_backend == 'lightning_gpu'
Expand All @@ -144,6 +144,7 @@ jobs:
-DBUILD_TESTS=ON \
-DENABLE_PYTHON=OFF \
-DPL_BACKEND=${{ matrix.pl_backend }} \
-DSCIPY_OPENBLAS=$(python -c "import scipy_openblas32; print(scipy_openblas32.get_lib_dir())") \
-DCMAKE_CXX_COMPILER=$(which g++-$GCC_VERSION) \
-DENABLE_COVERAGE=ON \
-G Ninja
Expand Down
2 changes: 2 additions & 0 deletions .github/workflows/tests_lgpumpi_cpp.yml
Original file line number Diff line number Diff line change
Expand Up @@ -129,6 +129,7 @@ jobs:
run: |
source /etc/profile.d/modules.sh && module use /opt/modules/ && module load ${{ matrix.mpilib }}/cuda-${{ matrix.cuda_version_maj }}.${{ matrix.cuda_version_min }}
export CUQUANTUM_SDK=$(python -c "import site; print( f'{site.getsitepackages()[0]}/cuquantum')")
export SCIPY_OPENBLAS=$(python -c "import scipy_openblas32; print(scipy_openblas32.get_lib_dir())")
cmake . -BBuild \
-DPL_BACKEND=lightning_gpu \
-DENABLE_PYTHON=OFF \
Expand All @@ -140,6 +141,7 @@ jobs:
-DCMAKE_CUDA_COMPILER=$(which nvcc) \
-DCMAKE_CUDA_ARCHITECTURES="86" \
-DCUQUANTUM_SDK=${CUQUANTUM_SDK} \
-DSCIPY_OPENBLAS=${SCIPY_OPENBLAS} \
-DPython_EXECUTABLE:FILE="${{ steps.python_path.outputs.python }}" \
-G Ninja
cmake --build ./Build
Expand Down
24 changes: 13 additions & 11 deletions .github/workflows/tests_linux_cpp.yml
Original file line number Diff line number Diff line change
Expand Up @@ -46,12 +46,11 @@ jobs:
pl_backend: ["lightning_qubit"]
enable_kernel_omp: ["OFF", "ON"]
enable_kernel_avx_streaming: ["OFF", "ON"]
enable_lapack: ["OFF", "ON"]
exclude:
- enable_kernel_omp: OFF
enable_kernel_avx_streaming: ON
timeout-minutes: 60
name: C++ Tests (${{ matrix.pl_backend }}, ENABLE_KERNEL_OMP=${{ matrix.enable_kernel_omp }}, ENABLE_KERNEL_AVX_STREAMING=${{ matrix.enable_kernel_avx_streaming }}), ENABLE_LAPACK=${{ matrix.enable_lapack }})
name: C++ Tests (${{ matrix.pl_backend }}, ENABLE_KERNEL_OMP=${{ matrix.enable_kernel_omp }}, ENABLE_KERNEL_AVX_STREAMING=${{ matrix.enable_kernel_avx_streaming }})
runs-on: pl-4-core-large-runner

steps:
Expand All @@ -66,15 +65,15 @@ jobs:
- name: Install dependencies
run: |
echo ${{ github.event_name }} && sudo apt-get update && sudo apt-get -y -q install cmake gcc-$GCC_VERSION g++-$GCC_VERSION ninja-build gcovr lcov
python -m pip install scipy
python -m pip install scipy-openblas32
- name: Build and run unit tests
run: |
cmake . -BBuild -G Ninja \
-DCMAKE_BUILD_TYPE=Debug \
-DBUILD_TESTS=ON \
-DENABLE_PYTHON=OFF \
-DENABLE_LAPACK=${{ matrix.enable_lapack }} \
-DSCIPY_OPENBLAS=$(python -c "import scipy_openblas32; print(scipy_openblas32.get_lib_dir())") \
-DPL_BACKEND=${{ matrix.pl_backend }} \
-DCMAKE_CXX_COMPILER=$(which g++-$GCC_VERSION) \
-DENABLE_COVERAGE=ON \
Expand All @@ -88,13 +87,13 @@ jobs:
for file in *runner ; do ./$file --order lex --reporter junit --out ./tests/results/report_$file.xml; done;
lcov --directory . -b ../pennylane_lightning/core/src --capture --output-file coverage.info
lcov --remove coverage.info '/usr/*' --output-file coverage.info
mv coverage.info coverage-${{ github.job }}-${{ matrix.pl_backend }}-${{ matrix.enable_kernel_avx_streaming }}-${{ matrix.enable_kernel_omp }}-${{ matrix.enable_lapack }}.info
mv coverage.info coverage-${{ github.job }}-${{ matrix.pl_backend }}-${{ matrix.enable_kernel_avx_streaming }}-${{ matrix.enable_kernel_omp }}.info
- name: Upload test results
uses: actions/upload-artifact@v4
if: always()
with:
name: ubuntu-tests-reports-${{ github.job }}-${{ matrix.pl_backend }}-${{ matrix.enable_kernel_avx_streaming }}-${{ matrix.enable_kernel_omp }}-${{ matrix.enable_lapack }}
name: ubuntu-tests-reports-${{ github.job }}-${{ matrix.pl_backend }}-${{ matrix.enable_kernel_avx_streaming }}-${{ matrix.enable_kernel_omp }}
retention-days: 1
include-hidden-files: true
path: |
Expand All @@ -105,8 +104,8 @@ jobs:
- name: Upload code coverage results
uses: actions/upload-artifact@v4
with:
name: ubuntu-codecov-results-${{ matrix.pl_backend }}-${{ matrix.enable_kernel_avx_streaming }}-${{ matrix.enable_kernel_omp }}-${{ matrix.enable_lapack }}
path: ./Build/coverage-${{ github.job }}-${{ matrix.pl_backend }}-${{ matrix.enable_kernel_avx_streaming }}-${{ matrix.enable_kernel_omp }}-${{ matrix.enable_lapack }}.info
name: ubuntu-codecov-results-${{ matrix.pl_backend }}-${{ matrix.enable_kernel_avx_streaming }}-${{ matrix.enable_kernel_omp }}
path: ./Build/coverage-${{ github.job }}-${{ matrix.pl_backend }}-${{ matrix.enable_kernel_avx_streaming }}-${{ matrix.enable_kernel_omp }}.info
if-no-files-found: error

cpptestswithOpenBLAS:
Expand All @@ -130,7 +129,7 @@ jobs:
- name: Install dependencies
run: |
sudo apt-get update && sudo apt-get -y -q install cmake gcc-$GCC_VERSION g++-$GCC_VERSION libopenblas-base libopenblas-dev ninja-build gcovr lcov
python -m pip install scipy
python -m pip install scipy-openblas32
- name: Build and run unit tests
run: |
Expand All @@ -139,6 +138,7 @@ jobs:
-DENABLE_PYTHON=OFF \
-DENABLE_BLAS=ON \
-DPL_BACKEND=${{ matrix.pl_backend }} \
-DSCIPY_OPENBLAS=$(python -c "import scipy_openblas32; print(scipy_openblas32.get_lib_dir())") \
-DBUILD_TESTS=ON \
-DCMAKE_CXX_COMPILER=$(which g++-$GCC_VERSION) \
-DENABLE_COVERAGE=ON
Expand Down Expand Up @@ -215,7 +215,7 @@ jobs:
- name: Install dependencies
run: |
sudo apt-get update && sudo apt-get -y -q install cmake gcc-$GCC_VERSION g++-$GCC_VERSION ninja-build gcovr lcov
python -m pip install scipy
python -m pip install scipy-openblas32
- name: Build and run unit tests
run: |
Expand All @@ -226,6 +226,7 @@ jobs:
-DCMAKE_PREFIX_PATH=${{ github.workspace }}/Kokkos \
-DPL_BACKEND=${{ matrix.pl_backend }} \
-DCMAKE_CXX_COMPILER=$(which g++-$GCC_VERSION) \
-DSCIPY_OPENBLAS=$(python -c "import scipy_openblas32; print(scipy_openblas32.get_lib_dir())") \
-DENABLE_COVERAGE=ON
cmake --build ./Build
cd ./Build
Expand Down Expand Up @@ -314,7 +315,7 @@ jobs:
- name: Install dependencies
run: |
sudo apt-get update && sudo apt-get -y -q install cmake gcc-$GCC_VERSION g++-$GCC_VERSION ninja-build gcovr lcov
python -m pip install scipy
python -m pip install scipy-openblas32
- name: Build and run unit tests
run: |
Expand All @@ -324,6 +325,7 @@ jobs:
-DENABLE_PYTHON=OFF \
-DCMAKE_PREFIX_PATH=${{ github.workspace }}/Kokkos \
-DPL_BACKEND="lightning_qubit;lightning_kokkos" \
-DSCIPY_OPENBLAS=$(python -c "import scipy_openblas32; print(scipy_openblas32.get_lib_dir())") \
-DCMAKE_CXX_COMPILER=$(which g++-$GCC_VERSION)
cmake --build ./Build
cd ./Build
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/tests_lkcpu_python.yml
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,7 @@ jobs:
- name: Install dependencies
run: |
sudo apt-get update && sudo apt-get -y -q install cmake gcc-$GCC_VERSION g++-$GCC_VERSION
python -m pip install scipy wheel
python -m pip install scipy-openblas32 wheel
- name: Get required Python packages
run: |
Expand Down
6 changes: 5 additions & 1 deletion .github/workflows/tests_lkcuda_cpp.yml
Original file line number Diff line number Diff line change
Expand Up @@ -182,7 +182,9 @@ jobs:
- name: Install dependencies
run: sudo apt-get update && sudo apt-get -y -q install cmake gcc-$GCC_VERSION g++-$GCC_VERSION ninja-build gcovr lcov
run: |
sudo apt-get update && sudo apt-get -y -q install cmake gcc-$GCC_VERSION g++-$GCC_VERSION ninja-build gcovr lcov
python -m pip install scipy-openblas32
- name: Build and run unit tests
run: |
Expand All @@ -191,6 +193,8 @@ jobs:
-DCMAKE_BUILD_TYPE=RelWithDebInfo \
-DBUILD_TESTS=ON \
-DENABLE_PYTHON=OFF \
-DSCIPY_OPENBLAS=$(python -c "import scipy_openblas32; print(scipy_openblas32.get_lib_dir())") \
-DCMAKE_PREFIX_PATH=${{ github.workspace }}/Kokkos \
-DPL_BACKEND=${{ matrix.pl_backend }} \
-DCMAKE_CXX_COMPILER=$(which g++-$GCC_VERSION) \
-DENABLE_COVERAGE=ON
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/tests_lqcpu_python.yml
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ jobs:
- name: Install dependencies
run: |
sudo apt-get update && sudo apt-get -y -q install cmake gcc-$GCC_VERSION g++-$GCC_VERSION libopenblas-base libopenblas-dev
python -m pip install scipy wheel
python -m pip install scipy-openblas32 wheel
- name: Get required Python packages
run: |
Expand Down
16 changes: 14 additions & 2 deletions .github/workflows/tests_windows_cpp.yml
Original file line number Diff line number Diff line change
Expand Up @@ -124,13 +124,19 @@ jobs:

- name: Install dependencies
run: |
python -m pip install cmake build ninja scipy
python -m pip install cmake build ninja scipy-openblas32
- name: Setup OpenCppCoverage and add to PATH
run: |
choco install OpenCppCoverage -y
echo "C:\Program Files\OpenCppCoverage" >> $env:GITHUB_PATH
- name: Add path to scipy-openblas32 to environment variable
run: |
$scipy_openblas32_path = python -c "import scipy_openblas32; print(scipy_openblas32.get_lib_dir())"
echo "SCIPY_OPENBLAS32=${scipy_openblas32_path}" | Out-File -Append -FilePath $env:GITHUB_ENV
Get-Content $env:GITHUB_ENV
- name: Build and run unit tests for code coverage
run: |
cmake -BBuild `
Expand Down Expand Up @@ -202,7 +208,7 @@ jobs:

- name: Install dependencies
run: |
python -m pip install cmake build ninja
python -m pip install cmake build ninja scipy-openblas32
- name: Checkout PennyLane-Lightning
uses: actions/checkout@v4
Expand All @@ -221,6 +227,12 @@ jobs:
run: |
choco install OpenCppCoverage -y
echo "C:\Program Files\OpenCppCoverage" >> $env:GITHUB_PATH
- name: Add path to scipy-openblas32 to environment variable
run: |
$scipy_openblas32_path = python -c "import scipy_openblas32; print(scipy_openblas32.get_lib_dir())"
echo "SCIPY_OPENBLAS32=${scipy_openblas32_path}" | Out-File -Append -FilePath $env:GITHUB_ENV
Get-Content $env:GITHUB_ENV
- name: Build and run unit tests for code coverage
run: |
Expand Down
1 change: 1 addition & 0 deletions .github/workflows/tidy.yml
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@ jobs:
-DCLANG_TIDY_BINARY=$(dirname $(which python))/clang-tidy \
-DBUILD_TESTS=ON \
-DENABLE_WARNINGS=ON \
-DSCIPY_OPENBLAS=$(python -c "import scipy_openblas32; print(scipy_openblas32.get_lib_dir())") \
-DPL_BACKEND=${{ matrix.pl_backend }} \
-DCMAKE_CXX_COMPILER="$(which g++-11)" \
-DCMAKE_C_COMPILER="$(which gcc-11)"
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/wheel_linux_x86_64.yml
Original file line number Diff line number Diff line change
Expand Up @@ -151,7 +151,7 @@ jobs:
# Python build settings
CIBW_BEFORE_BUILD: |
cat /etc/dnf.conf | sed "s/\[main\]/\[main\]\ntimeout=5/g" > /etc/dnf.conf
python -m pip install ninja cmake~=3.27.0 scipy
python -m pip install ninja cmake~=3.27.0
dnf clean all -y
dnf install gcc-toolset-13 -y
source /opt/rh/gcc-toolset-13/enable -y
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/wheel_macos_arm64.yml
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,7 @@ jobs:
# Python build settings
CIBW_BEFORE_BUILD: |
python -m pip install pybind11 ninja cmake~=3.27.0 setuptools scipy
python -m pip install pybind11 ninja cmake~=3.27.0 setuptools
CIBW_ENVIRONMENT: |
CMAKE_ARGS="-DCMAKE_CXX_COMPILER_TARGET=arm64-apple-macos11 -DCMAKE_SYSTEM_NAME=Darwin -DCMAKE_SYSTEM_PROCESSOR=ARM64 -DENABLE_OPENMP=OFF -DCMAKE_BUILD_TYPE=Release"
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/wheel_macos_x86_64.yml
Original file line number Diff line number Diff line change
Expand Up @@ -145,7 +145,7 @@ jobs:
# Python build settings
CIBW_BEFORE_BUILD: |
python -m pip install pybind11 ninja cmake~=3.27.0 setuptools scipy
python -m pip install pybind11 ninja cmake~=3.27.0 setuptools
CIBW_ENVIRONMENT: |
CMAKE_ARGS="-DCMAKE_BUILD_TYPE=Release"
Expand Down
51 changes: 23 additions & 28 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -47,8 +47,6 @@ option(ENABLE_WARNINGS "Enable warnings" ON)
option(ENABLE_NATIVE "Enable native CPU build tuning" OFF)
option(ENABLE_PYTHON "Enable compilation of the Python module" ON)

option(ENABLE_LAPACK "Enable compilation with scipy/LAPACK" OFF)

# OpenMP
find_package(OpenMP)
if (OpenMP_CXX_FOUND)
Expand Down Expand Up @@ -88,29 +86,6 @@ set(CMAKE_POLICY_DEFAULT_CMP0127 NEW) # To suppress pybind11 CMP0127 warning
# Add pybind11
include(FetchContent)

if(ENABLE_LAPACK)
find_package(Python COMPONENTS Interpreter Development)
set(SCIPYLIBS ${Python_SITELIB})

if(CMAKE_SYSTEM_NAME MATCHES "Darwin")
set(SCIPYLIBS "/System/Library/Frameworks/Accelerate.framework/Versions/Current/Frameworks/vecLib.framework/libLAPACK.dylib")
elseif(CMAKE_SYSTEM_NAME MATCHES "Linux")
if(EXISTS ${SCIPYLIBS}/scipy.libs)
set(SCIPYLIBS ${SCIPYLIBS}/scipy.libs)
else()
# Fallback to the lib path of Python for `conda` support
set(SCIPYLIBS ${SCIPYLIBS}/../..)
endif()
elseif(CMAKE_SYSTEM_NAME MATCHES "Windows")
else()
message(FATAL_ERROR "Unsupported platform: ${CMAKE_SYSTEM_NAME}")
endif()

add_compile_definitions(SCIPY_LIBS_PATH="${SCIPYLIBS}")

message(STATUS "Python scipy-lib path: ${SCIPYLIBS}")
endif()

if(ENABLE_PYTHON)
find_package(Python COMPONENTS Interpreter Development)
FetchContent_Declare(pybind11
Expand All @@ -123,6 +98,23 @@ endif()
# Print Python site-packages directory for reference
message("Python site-packages directory: ${Python_SITELIB}")

if(DEFINED PY_INSTALL)
# Note the following setting is only for pyenv and not for conda
# TODO: Add support for conda
set(SCIPY_OPENBLAS32_RUNTIME_LIB_PATH "$ORIGIN/../scipy_openblas32/lib")
else()
include("${CMAKE_CURRENT_SOURCE_DIR}/cmake/FindSCIPY_OPENBLAS32.cmake")
if(NOT DEFINED SCIPY_OPENBLAS32_LIB_PATH AND NOT EXISTS ${SCIPY_OPENBLAS32_LIB_PATH})
set(SCIPY_OPENBLAS32_LIB_PATH "")
find_path_to_openblas(SCIPY_OPENBLAS32_LIB_PATH)
add_compile_definitions(SCIPY_OPENBLAS32_LIB="${SCIPY_OPENBLAS32_LIB_PATH}")
message(STATUS "SCIPY_OPENBLAS32_LIB_PATH: ${SCIPY_OPENBLAS32_LIB_PATH}")
else()
add_compile_definitions(SCIPY_OPENBLAS32_LIB="${SCIPY_OPENBLAS32_LIB_PATH}")
endif()
set(SCIPY_OPENBLAS32_RUNTIME_LIB_PATH "${SCIPY_OPENBLAS32_LIB_PATH}")
endif()

set (CMAKE_RUNTIME_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR})

# All CMakeLists.txt in subdirectories use pennylane_lightning_compile_options and pennylane_lightning_external_libs
Expand Down Expand Up @@ -154,10 +146,13 @@ if(ENABLE_PYTHON)
message(STATUS "ENABLE_PYTHON is ON.")
pybind11_add_module("${PL_BACKEND}_ops" "pennylane_lightning/core/src/bindings/Bindings.cpp")

# Allow pip installation of cuQuantum & CUDA 12 libs to be accessible without setting LD_LIBRARY_PATH for lightning_gpu
set(CMAKE_BUILD_RPATH_USE_ORIGIN ON)
if("${PL_BACKEND}" STREQUAL "lightning_gpu" OR "${PL_BACKEND}" STREQUAL "lightning_tensor")
set(CMAKE_BUILD_RPATH_USE_ORIGIN ON)
set_target_properties("${PL_BACKEND}_ops" PROPERTIES BUILD_RPATH "$ORIGIN/../cuquantum/lib:$ORIGIN/../nvidia/cuda_runtime/lib:$ORIGIN/../nvidia/cublas/lib:$ORIGIN/../nvidia/cusparse/lib:$ORIGIN")
# Allow pip installation of cuQuantum & CUDA 12 libs to be accessible without setting LD_LIBRARY_PATH for lightning_gpu
# BUILD_RPATH only works for the last call
set_target_properties("${PL_BACKEND}_ops" PROPERTIES BUILD_RPATH "$ORIGIN/../cuquantum/lib:$ORIGIN/../nvidia/cuda_runtime/lib:$ORIGIN/../nvidia/cublas/lib:$ORIGIN/../nvidia/cusparse/lib:${SCIPY_OPENBLAS32_RUNTIME_LIB_PATH}:$ORIGIN")
else()
set_target_properties("${PL_BACKEND}_ops" PROPERTIES BUILD_RPATH "${SCIPY_OPENBLAS32_RUNTIME_LIB_PATH}")
endif()

target_link_libraries("${PL_BACKEND}_ops" PRIVATE lightning_compile_options
Expand Down
Loading

0 comments on commit 705fe89

Please sign in to comment.