Skip to content

Commit

Permalink
Locate shared object file in the build directory
Browse files Browse the repository at this point in the history
  • Loading branch information
rauletorresc committed Aug 4, 2024
1 parent ba5c71d commit 6d7d6a3
Showing 1 changed file with 20 additions and 17 deletions.
37 changes: 20 additions & 17 deletions pennylane_lightning/lightning_kokkos/lightning_kokkos.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,6 @@
"""

import os.path
import platform
import sys
from os import getenv
from pathlib import Path
from typing import List
Expand Down Expand Up @@ -154,18 +152,6 @@ def _kokkos_configuration():
"Exp",
}

# The absolute path of the plugin shared object varies according to the installation type.
# This lookup table keeps track of those possible locations
lib_name = "liblightning_kokkos_catalyst.so"
package_root = os.path.dirname(__file__)
wheel_mode_location = os.path.join(package_root, "..", lib_name)
editable_mode_location = os.path.join(
package_root,
f"../../build/lib.{platform.system().lower()}-{platform.machine()}-{sys.version_info[0]}.{sys.version_info[1]}/pennylane_lightning",
lib_name,
)
plugin_locations = [wheel_mode_location, editable_mode_location]


class LightningKokkos(LightningBase):
"""PennyLane Lightning Kokkos device.
Expand Down Expand Up @@ -856,8 +842,25 @@ def get_c_interface():
the location to the shared object with the C/C++ device implementation.
"""

for location in plugin_locations:
if os.path.isfile(location):
return "LightningKokkosSimulator", location
lib_name = "liblightning_kokkos_catalyst.so"
package_root = os.path.dirname(__file__)

Check warning on line 846 in pennylane_lightning/lightning_kokkos/lightning_kokkos.py

View check run for this annotation

Codecov / codecov/patch

pennylane_lightning/lightning_kokkos/lightning_kokkos.py#L845-L846

Added lines #L845 - L846 were not covered by tests

# The absolute path of the plugin shared object varies according to the installation mode.

# Wheel mode:
# Fixed location at the root of the project
wheel_mode_location = os.path.join(package_root, "..", lib_name)
if os.path.isfile(wheel_mode_location):
return "LightningKokkosSimulator", wheel_mode_location

Check warning on line 854 in pennylane_lightning/lightning_kokkos/lightning_kokkos.py

View check run for this annotation

Codecov / codecov/patch

pennylane_lightning/lightning_kokkos/lightning_kokkos.py#L852-L854

Added lines #L852 - L854 were not covered by tests

# Editable mode:
# The build directory contains a folder which varies according to the platform:
# lib.<system>-<architecture>-<python-id>"
# 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 = os.path.join(package_root, "../../build")
for path, _, files in os.walk(editable_mode_path):
if lib_name in files:
return "LightningKokkosSimulator", os.path.join(path, lib_name)

Check warning on line 864 in pennylane_lightning/lightning_kokkos/lightning_kokkos.py

View check run for this annotation

Codecov / codecov/patch

pennylane_lightning/lightning_kokkos/lightning_kokkos.py#L861-L864

Added lines #L861 - L864 were not covered by tests

raise RuntimeError("Shared object not found")

Check warning on line 866 in pennylane_lightning/lightning_kokkos/lightning_kokkos.py

View check run for this annotation

Codecov / codecov/patch

pennylane_lightning/lightning_kokkos/lightning_kokkos.py#L866

Added line #L866 was not covered by tests

0 comments on commit 6d7d6a3

Please sign in to comment.