Skip to content

Commit

Permalink
Revert openblas linking changes from #451 (#1386)
Browse files Browse the repository at this point in the history
PR #451 introduced linking against both OpenBLAS and LAPACKE+Accelerate
on arm macOS, which breaks re-compilation of certain user programs (like
Shor's). The cause of the shared library conflict is unknown.

For now, we revert these linking changes, which were originally
introduced due to Lightning not finding its OpenBLAS dependency when
invoked through Catalyst:
```
FAILED frontend/test/pytest/test_measurements_shots_results.py::TestExpval::test_hermitian[lightning.qubit]

RuntimeError: [pennylane_lightning/core/src/utils/SharedLibLoader.hpp][Line:60][Method:SharedLibLoader]: Error in PennyLane Lightning: dlopen(libscipy_openblas.dylib, 0x0001): tried: 'libscipy_openblas.dylib' (no such file), '$ORIGIN/../scipy_openblas32/lib/libscipy_openblas.dylib' (no such file)
```

The above test will fail as a result of this, which we plan to fix with
a PR on the lightning side.

[sc-80803]
  • Loading branch information
dime10 authored Dec 19, 2024
1 parent 4b243f7 commit 6ebfd70
Show file tree
Hide file tree
Showing 4 changed files with 27 additions and 26 deletions.
2 changes: 1 addition & 1 deletion .dep-versions
Original file line number Diff line number Diff line change
Expand Up @@ -12,4 +12,4 @@ pennylane=0.40.0-dev20

# For a custom LQ/LK version, update the package version here and at
# 'doc/requirements.txt'
lightning=0.40.0-dev30
lightning=0.40.0-dev41
10 changes: 7 additions & 3 deletions .github/workflows/build-wheel-macos-arm64.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@ jobs:
- name: Checkout Catalyst repo
uses: actions/checkout@v4

# Python 3.10 was dropped from the GH images on macOS arm
- name: Install Python 3.10
uses: actions/setup-python@v5
with:
Expand Down Expand Up @@ -235,8 +236,10 @@ jobs:
- name: Checkout Catalyst repo
uses: actions/checkout@v4

# Python 3.10 was dropped from the GH images on macOS arm
- name: Install Python 3.10
uses: actions/setup-python@v5
if: ${{ matrix.python_version }} == '3.10'
with:
python-version: '3.10'

Expand Down Expand Up @@ -418,10 +421,12 @@ jobs:
- name: Checkout Catalyst repo
uses: actions/checkout@v4

- name: Install Python ${{ matrix.python_version }}
# Python 3.10 was dropped from the GH images on macOS arm
- name: Install Python 3.10
uses: actions/setup-python@v5
if: ${{ matrix.python_version }} == '3.10'
with:
python-version: ${{ matrix.python_version }}
python-version: '3.10'

- name: Download Wheel Artifact
uses: actions/download-artifact@v4
Expand Down Expand Up @@ -453,7 +458,6 @@ jobs:
python${{ matrix.python_version }} -m pip install PennyLane-Lightning-Kokkos
python${{ matrix.python_version }} -m pip install 'amazon-braket-pennylane-plugin>1.27.1'
- name: Install OQC client
run: |
python${{ matrix.python_version }} -m pip install oqc-qcaas-client
Expand Down
4 changes: 2 additions & 2 deletions doc/requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,6 @@ lxml_html_clean

# Pre-install PL development wheels
--extra-index-url https://test.pypi.org/simple/
pennylane-lightning-kokkos==0.40.0-dev30
pennylane-lightning==0.40.0-dev30
pennylane-lightning-kokkos==0.40.0-dev41
pennylane-lightning==0.40.0-dev41
pennylane==0.40.0-dev20
37 changes: 17 additions & 20 deletions frontend/catalyst/compiler.py
Original file line number Diff line number Diff line change
Expand Up @@ -121,25 +121,24 @@ def get_default_flags(options):
path_within_package = "lib"
file_extension = ".so" if platform.system() == "Linux" else ".dylib" # pragma: no branch

package_spec = importlib.util.find_spec(package_name)
package_directory = path.dirname(package_spec.origin)
lapack_lib_path = path.join(package_directory, path_within_package)

search_pattern = path.join(lapack_lib_path, f"lib*{lib_name}*{file_extension}")
search_result = glob.glob(search_pattern)
if not search_result: # pragma: nocover
raise CompileError(
f'Unable to find OpenBLAS library at "{search_pattern}". '
"Please ensure that scipy is installed and available via pip."
)

lib_path_flags += [f"-Wl,-rpath,{lapack_lib_path}", f"-L{lapack_lib_path}"]
lapack_lib_name = path.basename(search_result[0])[3 : -len(file_extension)]

lapack_libs = [lapack_lib_name]
if platform.system() == "Darwin" and platform.machine() == "arm64": # pragma: nocover
# use our own build of LAPACKe to interface with Accelerate
lapack_libs += ["lapacke.3"]
lapack_lib_name = "lapacke.3"
else:
package_spec = importlib.util.find_spec(package_name)
package_directory = path.dirname(package_spec.origin)
lapack_lib_path = path.join(package_directory, path_within_package)

search_pattern = path.join(lapack_lib_path, f"lib*{lib_name}*{file_extension}")
search_result = glob.glob(search_pattern)
if not search_result: # pragma: nocover
raise CompileError(
f'Unable to find OpenBLAS library at "{search_pattern}". '
"Please ensure that scipy is installed and available via pip."
)

lib_path_flags += [f"-Wl,-rpath,{lapack_lib_path}", f"-L{lapack_lib_path}"]
lapack_lib_name = path.basename(search_result[0])[3 : -len(file_extension)]

system_flags = []
if platform.system() == "Linux":
Expand All @@ -159,8 +158,6 @@ def get_default_flags(options):
elif options.async_qnodes and platform.system() == "Darwin": # pragma: nocover
system_flags += ["-lc++"]

lapack_libs = [f"-l{name}" for name in lapack_libs]

default_flags = [
"-shared",
"-rdynamic",
Expand All @@ -169,7 +166,7 @@ def get_default_flags(options):
"-lrt_capi",
"-lpthread",
"-lmlir_c_runner_utils", # required for memref.copy
*lapack_libs,
f"-l{lapack_lib_name}", # required for custom_calls lib
"-lcustom_calls",
"-lmlir_async_runtime",
]
Expand Down

0 comments on commit 6ebfd70

Please sign in to comment.