From a38b0363b98c87de84216ecded9d27cd458944d6 Mon Sep 17 00:00:00 2001 From: Joseph Lee <40768758+josephleekl@users.noreply.github.com> Date: Wed, 30 Oct 2024 09:57:53 -0400 Subject: [PATCH] Fix LK build path for catalyst shared library (#968) ### Before submitting Please complete the following checklist when submitting a PR: - [X] 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. - [ ] 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:** This PR fixes Lightning Kokkos with Catalyst failing due to wrong build path supplied to `setup.py` and lightning kokkos in editable mode. **Description of the Change:** **Benefits:** **Possible Drawbacks:** **Related GitHub Issues:** [sc-77123] --- .github/CHANGELOG.md | 5 ++++- .github/workflows/tests_lkcpu_python.yml | 11 +++++++++++ .../lightning_kokkos/lightning_kokkos.py | 2 +- setup.py | 2 +- 4 files changed, 17 insertions(+), 3 deletions(-) diff --git a/.github/CHANGELOG.md b/.github/CHANGELOG.md index 27f87c6638..a3acaba0e3 100644 --- a/.github/CHANGELOG.md +++ b/.github/CHANGELOG.md @@ -131,6 +131,9 @@ ### Bug fixes +* Fix `liblightning_kokkos_catalyst.so` not copied to correct build path for editable installation. + [(#968)](https://github.com/PennyLaneAI/pennylane-lightning/pull/968) + * Fix PTM stable latest related to `default.qubit.legacy`. [(#966)](https://github.com/PennyLaneAI/pennylane-lightning/pull/966) @@ -156,7 +159,7 @@ This release contains contributions from (in alphabetical order): -Ali Asadi, Amintor Dusko, Luis Alfredo Nuñez Meneses, Vincent Michaud-Rioux, Lee J. O'Riordan, Mudit Pandey, Shuli Shu, Haochen Paul Wang +Ali Asadi, Amintor Dusko, Joseph Lee, Luis Alfredo Nuñez Meneses, Vincent Michaud-Rioux, Lee J. O'Riordan, Mudit Pandey, Shuli Shu, Haochen Paul Wang --- diff --git a/.github/workflows/tests_lkcpu_python.yml b/.github/workflows/tests_lkcpu_python.yml index 6b55a9e734..909831aa83 100644 --- a/.github/workflows/tests_lkcpu_python.yml +++ b/.github/workflows/tests_lkcpu_python.yml @@ -264,6 +264,17 @@ jobs: pl-device-test --device ${DEVICENAME} --shots=None --skip-ops $COVERAGE_FLAGS --cov-append mv .coverage ${{ github.workspace }}/.coverage-${{ github.job }}-${{ matrix.pl_backend }}-${{ matrix.group }} + - name: Test editable install + run: | + rm -r build + pip uninstall pennylane-lightning pennylane-lightning-kokkos -y + python scripts/configure_pyproject_toml.py + SKIP_COMPILATION=True python -m pip install -e . --config-settings editable_mode=compat + DEVICENAME=`echo ${{ matrix.pl_backend }} | sed "s/_/./g"` + PL_BACKEND=${DEVICENAME} python scripts/configure_pyproject_toml.py + python -m pip install -e . --config-settings editable_mode=compat -vv + PL_DEVICE=${DEVICENAME} python -m pytest tests/test_device.py $COVERAGE_FLAGS + - name: Upload test durations uses: actions/upload-artifact@v4 with: diff --git a/pennylane_lightning/lightning_kokkos/lightning_kokkos.py b/pennylane_lightning/lightning_kokkos/lightning_kokkos.py index b30ca1ad21..42a27e969e 100644 --- a/pennylane_lightning/lightning_kokkos/lightning_kokkos.py +++ b/pennylane_lightning/lightning_kokkos/lightning_kokkos.py @@ -534,7 +534,7 @@ def get_c_interface(): # lib.--" # To avoid mismatching the folder name, we search for the shared object instead. # TODO: locate where the naming convention of the folder is decided and replicate it here. - editable_mode_path = package_root.parent.parent / "build" + editable_mode_path = package_root.parent.parent / "build_lightning_kokkos" for path, _, files in os.walk(editable_mode_path): if lib_name in files: lib_location = (Path(path) / lib_name).as_posix() diff --git a/setup.py b/setup.py index 0ef706955f..048219ed2b 100644 --- a/setup.py +++ b/setup.py @@ -161,7 +161,7 @@ def build_extension(self, ext: CMakeExtension): if platform.system() in ["Linux", "Darwin"]: shared_lib_ext = {"Linux": ".so", "Darwin": ".dylib"}[platform.system()] source = os.path.join(f"{extdir}", f"lib{backend}_catalyst{shared_lib_ext}") - destination = os.path.join(os.getcwd(), "build") + destination = os.path.join(os.getcwd(), self.build_temp) shutil.copy(source, destination) with open(os.path.join("pennylane_lightning", "core", "_version.py"), encoding="utf-8") as f: