From d0aa69bee4cd0c3412a99bc61ec5c242e5f7bfaa Mon Sep 17 00:00:00 2001 From: Agriya Khetarpal <74401230+agriyakhetarpal@users.noreply.github.com> Date: Wed, 15 May 2024 18:37:57 +0530 Subject: [PATCH 01/23] Set `MACOSX_DEPLOYMENT_TARGET` for prerequisites --- .github/workflows/publish_pypi.yml | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/.github/workflows/publish_pypi.yml b/.github/workflows/publish_pypi.yml index fb4a203e5d..fc233d9423 100644 --- a/.github/workflows/publish_pypi.yml +++ b/.github/workflows/publish_pypi.yml @@ -115,6 +115,9 @@ jobs: # sometimes gfortran cannot be found, so reinstall gcc just to be sure - name: Install SuiteSparse and SUNDIALS on macOS if: matrix.os == 'macos-12' + # cibuildwheel sets this, but not for prerequisite C++ deps + env: + MACOSX_DEPLOYMENT_TARGET: 10.9 run: | brew install graphviz libomp brew reinstall gcc @@ -163,6 +166,9 @@ jobs: run: git clone --depth 1 --branch v2.11.1 https://github.com/pybind/pybind11.git - name: Install SuiteSparse and SUNDIALS on macOS + # cibuildwheel sets this, but not for prerequisite C++ deps + env: + MACOSX_DEPLOYMENT_TARGET: 11.0 run: | brew install graphviz libomp brew reinstall gcc From 9ea58f31439749500ac4d555fcaec94fa47d23db Mon Sep 17 00:00:00 2001 From: Agriya Khetarpal <74401230+agriyakhetarpal@users.noreply.github.com> Date: Thu, 16 May 2024 00:42:09 +0530 Subject: [PATCH 02/23] Remove previously set environment variables --- .github/workflows/publish_pypi.yml | 6 ------ 1 file changed, 6 deletions(-) diff --git a/.github/workflows/publish_pypi.yml b/.github/workflows/publish_pypi.yml index fc233d9423..fb4a203e5d 100644 --- a/.github/workflows/publish_pypi.yml +++ b/.github/workflows/publish_pypi.yml @@ -115,9 +115,6 @@ jobs: # sometimes gfortran cannot be found, so reinstall gcc just to be sure - name: Install SuiteSparse and SUNDIALS on macOS if: matrix.os == 'macos-12' - # cibuildwheel sets this, but not for prerequisite C++ deps - env: - MACOSX_DEPLOYMENT_TARGET: 10.9 run: | brew install graphviz libomp brew reinstall gcc @@ -166,9 +163,6 @@ jobs: run: git clone --depth 1 --branch v2.11.1 https://github.com/pybind/pybind11.git - name: Install SuiteSparse and SUNDIALS on macOS - # cibuildwheel sets this, but not for prerequisite C++ deps - env: - MACOSX_DEPLOYMENT_TARGET: 11.0 run: | brew install graphviz libomp brew reinstall gcc From 5c724f1f4a905c2dad1653d86459392db25a8303 Mon Sep 17 00:00:00 2001 From: Agriya Khetarpal <74401230+agriyakhetarpal@users.noreply.github.com> Date: Thu, 16 May 2024 00:43:47 +0530 Subject: [PATCH 03/23] Remove Homebrew libomp installations --- .github/workflows/publish_pypi.yml | 4 ++-- .github/workflows/run_periodic_tests.yml | 2 +- .github/workflows/test_on_push.yml | 4 ++-- 3 files changed, 5 insertions(+), 5 deletions(-) diff --git a/.github/workflows/publish_pypi.yml b/.github/workflows/publish_pypi.yml index fb4a203e5d..740c0766dd 100644 --- a/.github/workflows/publish_pypi.yml +++ b/.github/workflows/publish_pypi.yml @@ -116,7 +116,7 @@ jobs: - name: Install SuiteSparse and SUNDIALS on macOS if: matrix.os == 'macos-12' run: | - brew install graphviz libomp + brew install graphviz brew reinstall gcc python -m pip install cmake wget python scripts/install_KLU_Sundials.py @@ -164,7 +164,7 @@ jobs: - name: Install SuiteSparse and SUNDIALS on macOS run: | - brew install graphviz libomp + brew install graphviz brew reinstall gcc python -m pip install cmake pipx python scripts/install_KLU_Sundials.py diff --git a/.github/workflows/run_periodic_tests.yml b/.github/workflows/run_periodic_tests.yml index 671d2b371d..848297241e 100644 --- a/.github/workflows/run_periodic_tests.yml +++ b/.github/workflows/run_periodic_tests.yml @@ -68,7 +68,7 @@ jobs: if: matrix.os == 'macos-12' || matrix.os == 'macos-14' run: | brew analytics off - brew install graphviz libomp + brew install graphviz brew reinstall gcc - name: Install Windows system dependencies diff --git a/.github/workflows/test_on_push.yml b/.github/workflows/test_on_push.yml index f79bc61ddf..2f56f501eb 100644 --- a/.github/workflows/test_on_push.yml +++ b/.github/workflows/test_on_push.yml @@ -74,7 +74,7 @@ jobs: # sometimes gfortran cannot be found, so reinstall gcc just to be sure run: | brew analytics off - brew install graphviz libomp + brew install graphviz brew reinstall gcc - name: Install Windows system dependencies @@ -209,7 +209,7 @@ jobs: # sometimes gfortran cannot be found, so reinstall gcc just to be sure run: | brew analytics off - brew install graphviz libomp + brew install graphviz brew reinstall gcc - name: Install Windows system dependencies From 580f5ad09a5d4e313e42ecd759b111d2cddb0601 Mon Sep 17 00:00:00 2001 From: Agriya Khetarpal <74401230+agriyakhetarpal@users.noreply.github.com> Date: Thu, 16 May 2024 00:44:14 +0530 Subject: [PATCH 04/23] Ignore `pybamm-requires` OpenMP downloads --- .gitignore | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/.gitignore b/.gitignore index 03750e18b2..6f1f201617 100644 --- a/.gitignore +++ b/.gitignore @@ -137,3 +137,7 @@ results/ # tests test_callback.log + +# openmp downloads +install_KLU_Sundials/openmp-* +install_KLU_Sundials/usr/ From 4efd259e8102bb191a471f2d6106c845f119a11d Mon Sep 17 00:00:00 2001 From: Agriya Khetarpal <74401230+agriyakhetarpal@users.noreply.github.com> Date: Thu, 16 May 2024 00:50:09 +0530 Subject: [PATCH 05/23] Rework docs to add OpenMP instructions --- .../installation/install-from-source.rst | 17 +++++++++-------- 1 file changed, 9 insertions(+), 8 deletions(-) diff --git a/docs/source/user_guide/installation/install-from-source.rst b/docs/source/user_guide/installation/install-from-source.rst index ea664b4a5b..a2a7637c9e 100644 --- a/docs/source/user_guide/installation/install-from-source.rst +++ b/docs/source/user_guide/installation/install-from-source.rst @@ -43,11 +43,11 @@ You can install the above with Where ``X`` is the version sub-number. -.. tab:: MacOS +.. tab:: macOS .. code:: bash - brew install python openblas gcc gfortran graphviz libomp cmake pandoc + brew install python openblas gcc gfortran graphviz cmake pandoc .. note:: @@ -82,8 +82,9 @@ If you are running windows, you can simply skip this section and jump to :ref:`p # in the PyBaMM/ directory nox -s pybamm-requires -This will download, compile and install the SuiteSparse and SUNDIALS libraries. -Both libraries are installed in ``~/.local``. +This will download, compile and install the SuiteSparse and SUNDIALS (with OpenMP) libraries +and the ``pybind11`` headers. +SuiteSparse and SUNDIALS are installed in ``~/.local`` by default. For users requiring more control over the installation process, the ``pybamm-requires`` session supports additional command-line arguments: @@ -110,7 +111,7 @@ If you'd rather do things yourself, 1. Make sure you have CMake installed 2. Compile and install SuiteSparse (PyBaMM only requires the ``KLU`` component). -3. Compile and install SUNDIALS. +3. Compile and install SUNDIALS with `OpenMP support `_. 4. Clone the pybind11 repository in the ``PyBaMM/`` directory (make sure the directory is named ``pybind11``). @@ -315,12 +316,12 @@ source files to your current directory. ``ValueError: Integrator name ida does not exist``, or ``ValueError: Integrator name cvode does not exist``. -**Solution:** This could mean that you have not installed -``scikits.odes`` correctly, check the instructions given above and make +**Solution:** This could mean that you have not linked to +SUNDIALS correctly, check the instructions given above and make sure each command was successful. One possibility is that you have not set your ``LD_LIBRARY_PATH`` to -point to the sundials library, type ``echo $LD_LIBRARY_PATH`` and make +point to the SUNDIALS library, type ``echo $LD_LIBRARY_PATH`` and make sure one of the directories printed out corresponds to where the SUNDIALS libraries are located. From 0c8a9293df2e726cf84ae6b0d834b9fc3c9441cc Mon Sep 17 00:00:00 2001 From: Agriya Khetarpal <74401230+agriyakhetarpal@users.noreply.github.com> Date: Thu, 16 May 2024 00:51:26 +0530 Subject: [PATCH 06/23] Download LLVM-OpenMP on macOS --- scripts/install_KLU_Sundials.py | 110 ++++++++++++++++++++++++++------ 1 file changed, 90 insertions(+), 20 deletions(-) diff --git a/scripts/install_KLU_Sundials.py b/scripts/install_KLU_Sundials.py index 6224e40776..620ea54d1d 100755 --- a/scripts/install_KLU_Sundials.py +++ b/scripts/install_KLU_Sundials.py @@ -14,18 +14,35 @@ SUITESPARSE_VERSION = "6.0.3" SUNDIALS_VERSION = "6.5.0" + SUITESPARSE_URL = f"https://github.com/DrTimothyAldenDavis/SuiteSparse/archive/v{SUITESPARSE_VERSION}.tar.gz" SUNDIALS_URL = f"https://github.com/LLNL/sundials/releases/download/v{SUNDIALS_VERSION}/sundials-{SUNDIALS_VERSION}.tar.gz" + SUITESPARSE_CHECKSUM = ( "7111b505c1207f6f4bd0be9740d0b2897e1146b845d73787df07901b4f5c1fb7" ) SUNDIALS_CHECKSUM = "4e0b998dff292a2617e179609b539b511eb80836f5faacf800e688a886288502" + +# universal binaries for macOS 11.0 and later; sourced from https://mac.r-project.org/openmp/ +OPENMP_VERSION = "16.0.4" +OPENMP_URL = ( + f"https://mac.r-project.org/openmp/openmp-{OPENMP_VERSION}-darwin20-Release.tar.gz" +) +OPENMP_CHECKSUM = "a763f0bdc9115c4f4933accc81f514f3087d56d6528778f38419c2a0d2231972" + + DEFAULT_INSTALL_DIR = os.path.join(os.getenv("HOME"), ".local") def safe_remove_dir(path): - if os.path.exists(path): - shutil.rmtree(path) + """Remove a directory or file if it exists.""" + try: + if os.path.isfile(path): + os.remove(path) + elif os.path.isdir(path): + shutil.rmtree(path) + except Exception as e: + print(f"Error while removing {path}: {e}") def install_suitesparse(download_dir): @@ -93,23 +110,13 @@ def install_sundials(download_dir, install_dir): # try to find OpenMP on mac if platform.system() == "Darwin": # flags to find OpenMP on mac - if platform.processor() == "arm": - OpenMP_C_FLAGS = ( - "-Xpreprocessor -fopenmp -I/opt/homebrew/opt/libomp/include" - ) - OpenMP_C_LIB_NAMES = "omp" - OpenMP_omp_LIBRARY = "/opt/homebrew/opt/libomp/lib/libomp.dylib" - elif platform.processor() == "i386": - OpenMP_C_FLAGS = "-Xpreprocessor -fopenmp -I/usr/local/opt/libomp/include" - OpenMP_C_LIB_NAMES = "omp" - OpenMP_omp_LIBRARY = "/usr/local/opt/libomp/lib/libomp.dylib" - else: - raise NotImplementedError( - f"Unsupported processor architecture: {platform.processor()}. Only 'arm' and 'i386' architectures are supported." - ) + OpenMP_C_FLAGS = f"-Xpreprocessor -fopenmp -lomp -L{os.path.join(KLU_LIBRARY_DIR)} -I{os.path.join(KLU_INCLUDE_DIR)}" + OpenMP_C_LIB_NAMES = "omp" + OpenMP_omp_LIBRARY = os.path.join(KLU_LIBRARY_DIR, "libomp.dylib") cmake_args += [ "-DOpenMP_C_FLAGS=" + OpenMP_C_FLAGS, + "-DOpenMP_CXX_FLAGS=" + OpenMP_C_FLAGS, "-DOpenMP_C_LIB_NAMES=" + OpenMP_C_LIB_NAMES, "-DOpenMP_omp_LIBRARY=" + OpenMP_omp_LIBRARY, ] @@ -130,6 +137,36 @@ def install_sundials(download_dir, install_dir): subprocess.run(make_cmd, cwd=build_dir, check=True) +# relevant for macOS only because recent Xcode Clang does not include OpenMP headers. +# Other compilers (e.g. GCC) include OpenMP specification by default. +def set_up_openmp(download_dir, install_dir): + print("-" * 10, "Extracting OpenMP archive", "-" * 40) + + openmp_dir = f"openmp-{OPENMP_VERSION}" + openmp_src = os.path.join(download_dir, openmp_dir) + + # extract OpenMP archive + with tarfile.open( + os.path.join(download_dir, f"{openmp_dir}-darwin20-Release.tar.gz") + ) as tar: + tar.extractall(openmp_src) + + # create directories + os.makedirs(os.path.join(install_dir, "lib"), exist_ok=True) + os.makedirs(os.path.join(install_dir, "include"), exist_ok=True) + + # copy files + shutil.copy( + os.path.join(openmp_src, "usr", "local", "lib", "libomp.dylib"), + os.path.join(install_dir, "lib"), + ) + for file in os.listdir(os.path.join(openmp_src, "usr", "local", "include")): + shutil.copy( + os.path.join(openmp_src, "usr", "local", "include", file), + os.path.join(install_dir, "include"), + ) + + def check_libraries_installed(install_dir): # Define the directories to check for SUNDIALS and SuiteSparse libraries lib_dirs = [install_dir] @@ -177,7 +214,7 @@ def check_libraries_installed(install_dir): suitesparse_files = [file + ".dylib" for file in suitesparse_files] else: raise NotImplementedError( - f"Unsupported operating system: {platform.system()}. This script currently supports only Linux and macOS." + f"Unsupported operating system: {platform.system()}. This script supports only Linux and macOS." ) suitesparse_lib_found = True @@ -199,6 +236,16 @@ def check_libraries_installed(install_dir): return sundials_lib_found, suitesparse_lib_found +def check_openmp_installed_on_macos(install_dir): + openmp_lib_found = isfile(join(install_dir, "lib", "libomp.dylib")) + openmp_headers_found = isfile(join(install_dir, "include", "omp.h")) + if not openmp_lib_found or not openmp_headers_found: + print("libomp.dylib or omp.h not found. Proceeding with OpenMP installation.") + else: + print(f"libomp.dylib and omp.h found in {install_dir}.") + return openmp_lib_found + + def calculate_sha256(file_path): sha256_hash = hashlib.sha256() with open(file_path, "rb") as f: @@ -266,6 +313,9 @@ def parallel_download(urls, download_dir): # Build in parallel wherever possible os.environ["CMAKE_BUILD_PARALLEL_LEVEL"] = str(cpu_count()) +# Set macOS environment variables for compatibility +os.environ["MACOSX_DEPLOYMENT_TARGET"] = "11.0" + # Create download directory in PyBaMM dir pybamm_dir = os.path.split(os.path.abspath(os.path.dirname(__file__)))[0] download_dir = os.path.join(pybamm_dir, "install_KLU_Sundials") @@ -274,7 +324,7 @@ def parallel_download(urls, download_dir): # Get installation location parser = argparse.ArgumentParser( - description="Download, compile and install Sundials and SuiteSparse." + description="Download, compile and install SUNDIALS and SuiteSparse." ) parser.add_argument( "--force", @@ -296,10 +346,20 @@ def parallel_download(urls, download_dir): safe_remove_dir(os.path.join(download_dir, "build_sundials")) safe_remove_dir(os.path.join(download_dir, f"SuiteSparse-{SUITESPARSE_VERSION}")) safe_remove_dir(os.path.join(download_dir, f"sundials-{SUNDIALS_VERSION}")) - sundials_found, suitesparse_found = False, False + if platform.system() == "Darwin": + safe_remove_dir(os.path.join(install_dir, "lib", "libomp.dylib")) + safe_remove_dir(os.path.join(install_dir, "include", "omp.h")) + sundials_found, suitesparse_found, openmp_found = False, False, False + else: + sundials_found, suitesparse_found = False, False else: # Check whether the libraries are installed - sundials_found, suitesparse_found = check_libraries_installed(install_dir) + if platform.system() == "Darwin": + sundials_found, suitesparse_found = check_libraries_installed(install_dir) + openmp_found = check_openmp_installed_on_macos(install_dir) + else: # Linux + sundials_found, suitesparse_found = check_libraries_installed(install_dir) + if __name__ == "__main__": # Determine which libraries to download based on whether they were found @@ -312,12 +372,22 @@ def parallel_download(urls, download_dir): ], download_dir, ) + + if platform.system() == "Darwin" and not openmp_found: + download_extract_library(OPENMP_URL, OPENMP_CHECKSUM, download_dir) + set_up_openmp(download_dir, install_dir) + install_suitesparse(download_dir) install_sundials(download_dir, install_dir) + else: if not sundials_found: # Only SUNDIALS is missing, download and install it parallel_download([(SUNDIALS_URL, SUNDIALS_CHECKSUM)], download_dir) + if platform.system() == "Darwin" and not openmp_found: + download_extract_library(OPENMP_URL, OPENMP_CHECKSUM, download_dir) + set_up_openmp(download_dir, install_dir) + # openmp needed for sundials on macOS install_sundials(download_dir, install_dir) if not suitesparse_found: # Only SuiteSparse is missing, download and install it From b55169cb74cccd1ca52346466613d8e35137e30a Mon Sep 17 00:00:00 2001 From: Agriya Khetarpal <74401230+agriyakhetarpal@users.noreply.github.com> Date: Thu, 16 May 2024 01:03:26 +0530 Subject: [PATCH 07/23] Remove unused compiler argument --- scripts/install_KLU_Sundials.py | 1 - 1 file changed, 1 deletion(-) diff --git a/scripts/install_KLU_Sundials.py b/scripts/install_KLU_Sundials.py index 620ea54d1d..762596d6c7 100755 --- a/scripts/install_KLU_Sundials.py +++ b/scripts/install_KLU_Sundials.py @@ -116,7 +116,6 @@ def install_sundials(download_dir, install_dir): cmake_args += [ "-DOpenMP_C_FLAGS=" + OpenMP_C_FLAGS, - "-DOpenMP_CXX_FLAGS=" + OpenMP_C_FLAGS, "-DOpenMP_C_LIB_NAMES=" + OpenMP_C_LIB_NAMES, "-DOpenMP_omp_LIBRARY=" + OpenMP_omp_LIBRARY, ] From 6fb8ef02ef144d225bec2c177a2905f8fc912645 Mon Sep 17 00:00:00 2001 From: Agriya Khetarpal <74401230+agriyakhetarpal@users.noreply.github.com> Date: Thu, 16 May 2024 01:16:24 +0530 Subject: [PATCH 08/23] Fix rpath for libomp dylib at wheel repair --- .github/workflows/publish_pypi.yml | 8 ++++++-- scripts/fix_libomp_rpath_macos.py | 19 +++++++++++++++++++ 2 files changed, 25 insertions(+), 2 deletions(-) create mode 100644 scripts/fix_libomp_rpath_macos.py diff --git a/.github/workflows/publish_pypi.yml b/.github/workflows/publish_pypi.yml index 740c0766dd..c9c404da1e 100644 --- a/.github/workflows/publish_pypi.yml +++ b/.github/workflows/publish_pypi.yml @@ -139,7 +139,9 @@ jobs: env: CIBW_BEFORE_BUILD_MACOS: > python -m pip install --upgrade cmake casadi setuptools wheel - CIBW_REPAIR_WHEEL_COMMAND_MACOS: delocate-listdeps {wheel} && delocate-wheel -v -w {dest_dir} {wheel} + CIBW_REPAIR_WHEEL_COMMAND_MACOS: | + python scripts/fix_macos_wheel.py + delocate-listdeps {wheel} && delocate-wheel -v -w {dest_dir} {wheel} CIBW_TEST_COMMAND: python -c "import pybamm; pybamm.IDAKLUSolver()" - name: Upload wheels for ${{ matrix.os }} @@ -173,7 +175,9 @@ jobs: run: python -m pipx run cibuildwheel --output-dir wheelhouse env: CIBW_BEFORE_BUILD: python -m pip install cmake casadi setuptools wheel delocate - CIBW_REPAIR_WHEEL_COMMAND: delocate-listdeps {wheel} && delocate-wheel -v -w {dest_dir} {wheel} + CIBW_REPAIR_WHEEL_COMMAND_MACOS: | + python scripts/fix_libomp_rpath_macos.py + delocate-listdeps {wheel} && delocate-wheel -v -w {dest_dir} {wheel} CIBW_TEST_COMMAND: python -c "import pybamm; pybamm.IDAKLUSolver()" - name: Upload wheels for macOS arm64 diff --git a/scripts/fix_libomp_rpath_macos.py b/scripts/fix_libomp_rpath_macos.py new file mode 100644 index 0000000000..6f92719645 --- /dev/null +++ b/scripts/fix_libomp_rpath_macos.py @@ -0,0 +1,19 @@ +# A helper script to fix the rpath of the OpenMP dynamic library. This +# is to be used when building the wheels for PyBaMM on macOS (on both +# amd64 and arm64 architectures). + +import os +import subprocess + +homedir = os.path.expanduser("~") +libomp_path = os.path.join(homedir, ".local/lib/libomp.dylib") + +subprocess.run( + [ + "install_name_tool", + "-change", + "/usr/local/lib/libomp.dylib", + libomp_path, + libomp_path, + ] +) From 9185c355312d11ced582d6f9bd51308f74678d2d Mon Sep 17 00:00:00 2001 From: Agriya Khetarpal <74401230+agriyakhetarpal@users.noreply.github.com> Date: Thu, 16 May 2024 01:18:21 +0530 Subject: [PATCH 09/23] Fix a failing link --- .lycheeignore | 1 + 1 file changed, 1 insertion(+) diff --git a/.lycheeignore b/.lycheeignore index 338303b4ba..1543b69f03 100644 --- a/.lycheeignore +++ b/.lycheeignore @@ -1,6 +1,7 @@ # a list of links/files to be ignored by lychee link checker (see workflow file) https://github.com/DrTimothyAldenDavis/SuiteSparse/archive/v%7BSUITESPARSE_VERSION%7D.tar.gz https://github.com/LLNL/sundials/releases/download/v%7BSUNDIALS_VERSION%7D/sundials-%7BSUNDIALS_VERSION%7D.tar.gz +https://mac.r-project.org/openmp/openmp-%7BOPENMP_VERSION%7D-darwin20-Release.tar.gz # Errors in docs/source/user_guide/getting_started.md file:///home/runner/work/PyBaMM/PyBaMM/docs/source/user_guide/api_docs From f907ca655cc4f7f03104c0926420f396dd773205 Mon Sep 17 00:00:00 2001 From: Agriya Khetarpal <74401230+agriyakhetarpal@users.noreply.github.com> Date: Thu, 16 May 2024 01:27:53 +0530 Subject: [PATCH 10/23] Revert "Fix rpath for libomp dylib at wheel repair" This reverts commit 6fb8ef02ef144d225bec2c177a2905f8fc912645. --- .github/workflows/publish_pypi.yml | 8 ++------ scripts/fix_libomp_rpath_macos.py | 19 ------------------- 2 files changed, 2 insertions(+), 25 deletions(-) delete mode 100644 scripts/fix_libomp_rpath_macos.py diff --git a/.github/workflows/publish_pypi.yml b/.github/workflows/publish_pypi.yml index c9c404da1e..740c0766dd 100644 --- a/.github/workflows/publish_pypi.yml +++ b/.github/workflows/publish_pypi.yml @@ -139,9 +139,7 @@ jobs: env: CIBW_BEFORE_BUILD_MACOS: > python -m pip install --upgrade cmake casadi setuptools wheel - CIBW_REPAIR_WHEEL_COMMAND_MACOS: | - python scripts/fix_macos_wheel.py - delocate-listdeps {wheel} && delocate-wheel -v -w {dest_dir} {wheel} + CIBW_REPAIR_WHEEL_COMMAND_MACOS: delocate-listdeps {wheel} && delocate-wheel -v -w {dest_dir} {wheel} CIBW_TEST_COMMAND: python -c "import pybamm; pybamm.IDAKLUSolver()" - name: Upload wheels for ${{ matrix.os }} @@ -175,9 +173,7 @@ jobs: run: python -m pipx run cibuildwheel --output-dir wheelhouse env: CIBW_BEFORE_BUILD: python -m pip install cmake casadi setuptools wheel delocate - CIBW_REPAIR_WHEEL_COMMAND_MACOS: | - python scripts/fix_libomp_rpath_macos.py - delocate-listdeps {wheel} && delocate-wheel -v -w {dest_dir} {wheel} + CIBW_REPAIR_WHEEL_COMMAND: delocate-listdeps {wheel} && delocate-wheel -v -w {dest_dir} {wheel} CIBW_TEST_COMMAND: python -c "import pybamm; pybamm.IDAKLUSolver()" - name: Upload wheels for macOS arm64 diff --git a/scripts/fix_libomp_rpath_macos.py b/scripts/fix_libomp_rpath_macos.py deleted file mode 100644 index 6f92719645..0000000000 --- a/scripts/fix_libomp_rpath_macos.py +++ /dev/null @@ -1,19 +0,0 @@ -# A helper script to fix the rpath of the OpenMP dynamic library. This -# is to be used when building the wheels for PyBaMM on macOS (on both -# amd64 and arm64 architectures). - -import os -import subprocess - -homedir = os.path.expanduser("~") -libomp_path = os.path.join(homedir, ".local/lib/libomp.dylib") - -subprocess.run( - [ - "install_name_tool", - "-change", - "/usr/local/lib/libomp.dylib", - libomp_path, - libomp_path, - ] -) From 77e33e2cdac4eb424f3c825153740551d86b46a1 Mon Sep 17 00:00:00 2001 From: Agriya Khetarpal <74401230+agriyakhetarpal@users.noreply.github.com> Date: Thu, 16 May 2024 01:55:26 +0530 Subject: [PATCH 11/23] Fix RPATHs for SuiteSparse and libomp --- scripts/install_KLU_Sundials.py | 19 +++++++++++++++---- 1 file changed, 15 insertions(+), 4 deletions(-) diff --git a/scripts/install_KLU_Sundials.py b/scripts/install_KLU_Sundials.py index 762596d6c7..0bbdcc3ce6 100755 --- a/scripts/install_KLU_Sundials.py +++ b/scripts/install_KLU_Sundials.py @@ -68,11 +68,11 @@ def install_suitesparse(download_dir): env = os.environ.copy() for libdir in ["SuiteSparse_config", "AMD", "COLAMD", "BTF", "KLU"]: build_dir = os.path.join(suitesparse_src, libdir) - # We want to ensure that libsuitesparseconfig.dylib is not repeated in - # multiple paths at the time of wheel repair. Therefore, it should not be - # built with an RPATH since it is copied to the install prefix. + # Set an RPATH in order for libsuitesparseconfig.dylib to find libomp.dylib if libdir == "SuiteSparse_config": - env["CMAKE_OPTIONS"] = f"-DCMAKE_INSTALL_PREFIX={install_dir}" + env["CMAKE_OPTIONS"] = ( + f"-DCMAKE_INSTALL_PREFIX={install_dir} -DCMAKE_INSTALL_RPATH={install_dir}/lib" + ) else: # For AMD, COLAMD, BTF and KLU; do not set a BUILD RPATH but use an # INSTALL RPATH in order to ensure that the dynamic libraries are found @@ -165,6 +165,17 @@ def set_up_openmp(download_dir, install_dir): os.path.join(install_dir, "include"), ) + # fix rpath; for some reason the downloaded dylib has an absolute path + # to /usr/local/lib/, so use self-referential rpath + subprocess.check_call( + [ + "install_name_tool", + "-id", + "@rpath/libomp.dylib", + f"{os.path.join(install_dir, 'lib', 'libomp.dylib')}", + ] + ) + def check_libraries_installed(install_dir): # Define the directories to check for SUNDIALS and SuiteSparse libraries From 092af70895239015b740eabdde8eecca3ca6bd46 Mon Sep 17 00:00:00 2001 From: Agriya Khetarpal <74401230+agriyakhetarpal@users.noreply.github.com> Date: Thu, 16 May 2024 02:18:02 +0530 Subject: [PATCH 12/23] 11.1 for arm64 macOS and 11.0 for amd64 macOS --- scripts/install_KLU_Sundials.py | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/scripts/install_KLU_Sundials.py b/scripts/install_KLU_Sundials.py index 0bbdcc3ce6..2b9d268bac 100755 --- a/scripts/install_KLU_Sundials.py +++ b/scripts/install_KLU_Sundials.py @@ -323,8 +323,12 @@ def parallel_download(urls, download_dir): # Build in parallel wherever possible os.environ["CMAKE_BUILD_PARALLEL_LEVEL"] = str(cpu_count()) -# Set macOS environment variables for compatibility -os.environ["MACOSX_DEPLOYMENT_TARGET"] = "11.0" +# Set macOS environment variables for compatibility. this is set to +# 1. 11.1 for arm64 (libcasadi.dylib), and +# 2. 11.0 for x86_64 (libomp.dylib) +os.environ["MACOSX_DEPLOYMENT_TARGET"] = ( + "11.1" if platform.machine == "arm64" else "11.0" +) # Create download directory in PyBaMM dir pybamm_dir = os.path.split(os.path.abspath(os.path.dirname(__file__)))[0] From b47c0343029e9e4894a495cf02003e002d8675c5 Mon Sep 17 00:00:00 2001 From: Agriya Khetarpal <74401230+agriyakhetarpal@users.noreply.github.com> Date: Thu, 16 May 2024 02:18:25 +0530 Subject: [PATCH 13/23] Set up Fortran compiler via GHA --- .github/workflows/publish_pypi.yml | 18 +++++++++++++----- 1 file changed, 13 insertions(+), 5 deletions(-) diff --git a/.github/workflows/publish_pypi.yml b/.github/workflows/publish_pypi.yml index 740c0766dd..09eed0f0af 100644 --- a/.github/workflows/publish_pypi.yml +++ b/.github/workflows/publish_pypi.yml @@ -112,12 +112,15 @@ jobs: - name: Clone pybind11 repo (no history) run: git clone --depth 1 --branch v2.11.1 https://github.com/pybind/pybind11.git - # sometimes gfortran cannot be found, so reinstall gcc just to be sure + - uses: fortran-lang/setup-fortran@v1.6 + id: setup-fortran + with: + compiler: gcc + version: 13 + - name: Install SuiteSparse and SUNDIALS on macOS if: matrix.os == 'macos-12' run: | - brew install graphviz - brew reinstall gcc python -m pip install cmake wget python scripts/install_KLU_Sundials.py @@ -137,6 +140,7 @@ jobs: if: matrix.os == 'macos-12' run: pipx run cibuildwheel --output-dir wheelhouse env: + MACOSX_DEPLOYMENT_TARGET: 11.1 CIBW_BEFORE_BUILD_MACOS: > python -m pip install --upgrade cmake casadi setuptools wheel CIBW_REPAIR_WHEEL_COMMAND_MACOS: delocate-listdeps {wheel} && delocate-wheel -v -w {dest_dir} {wheel} @@ -162,10 +166,14 @@ jobs: - name: Clone pybind11 repo (no history) run: git clone --depth 1 --branch v2.11.1 https://github.com/pybind/pybind11.git + - uses: fortran-lang/setup-fortran@v1.6 + id: setup-fortran + with: + compiler: gcc + version: 13 + - name: Install SuiteSparse and SUNDIALS on macOS run: | - brew install graphviz - brew reinstall gcc python -m pip install cmake pipx python scripts/install_KLU_Sundials.py From 4809a31b9f8cb5678541a19fad7277b3879f534d Mon Sep 17 00:00:00 2001 From: Agriya Khetarpal <74401230+agriyakhetarpal@users.noreply.github.com> Date: Thu, 16 May 2024 02:25:22 +0530 Subject: [PATCH 14/23] Downgrade to gcc 12 --- .github/workflows/publish_pypi.yml | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/.github/workflows/publish_pypi.yml b/.github/workflows/publish_pypi.yml index 09eed0f0af..0bb2f38449 100644 --- a/.github/workflows/publish_pypi.yml +++ b/.github/workflows/publish_pypi.yml @@ -116,7 +116,7 @@ jobs: id: setup-fortran with: compiler: gcc - version: 13 + version: 12 - name: Install SuiteSparse and SUNDIALS on macOS if: matrix.os == 'macos-12' @@ -170,7 +170,7 @@ jobs: id: setup-fortran with: compiler: gcc - version: 13 + version: 12 - name: Install SuiteSparse and SUNDIALS on macOS run: | @@ -180,6 +180,7 @@ jobs: - name: Build wheels on macOS arm64 run: python -m pipx run cibuildwheel --output-dir wheelhouse env: + MACOSX_DEPLOYMENT_TARGET: 11.1 CIBW_BEFORE_BUILD: python -m pip install cmake casadi setuptools wheel delocate CIBW_REPAIR_WHEEL_COMMAND: delocate-listdeps {wheel} && delocate-wheel -v -w {dest_dir} {wheel} CIBW_TEST_COMMAND: python -c "import pybamm; pybamm.IDAKLUSolver()" From b5d20cd9c8d4b6be06cd4a44ea0562a9406e7891 Mon Sep 17 00:00:00 2001 From: Agriya Khetarpal <74401230+agriyakhetarpal@users.noreply.github.com> Date: Thu, 16 May 2024 19:37:21 +0530 Subject: [PATCH 15/23] Try fix for macOS amd64 wheels first --- .github/workflows/publish_pypi.yml | 60 ++++++++++++++++++++++-------- 1 file changed, 45 insertions(+), 15 deletions(-) diff --git a/.github/workflows/publish_pypi.yml b/.github/workflows/publish_pypi.yml index 0bb2f38449..60d6a0d6f5 100644 --- a/.github/workflows/publish_pypi.yml +++ b/.github/workflows/publish_pypi.yml @@ -112,18 +112,6 @@ jobs: - name: Clone pybind11 repo (no history) run: git clone --depth 1 --branch v2.11.1 https://github.com/pybind/pybind11.git - - uses: fortran-lang/setup-fortran@v1.6 - id: setup-fortran - with: - compiler: gcc - version: 12 - - - name: Install SuiteSparse and SUNDIALS on macOS - if: matrix.os == 'macos-12' - run: | - python -m pip install cmake wget - python scripts/install_KLU_Sundials.py - - name: Build wheels on Linux run: pipx run cibuildwheel --output-dir wheelhouse if: matrix.os == 'ubuntu-latest' @@ -141,8 +129,50 @@ jobs: run: pipx run cibuildwheel --output-dir wheelhouse env: MACOSX_DEPLOYMENT_TARGET: 11.1 - CIBW_BEFORE_BUILD_MACOS: > - python -m pip install --upgrade cmake casadi setuptools wheel + # Sourced from + # https://github.com/scipy/scipy/blob/f2d4775e7762fad984f8f0acd8227c725ff21630/tools/wheels/cibw_before_build_macos.sh#L23-L49 + CIBW_BEFORE_ALL_MACOS: | + set -e -x + + # download gfortran with proper macos minimum version (11.0) + curl -L https://github.com/isuruf/gcc/releases/download/gcc-11.3.0-2/gfortran-darwin-x86_64-native.tar.gz -o gfortran.tar.gz + + GFORTRAN_SHA256=$(shasum --algorithm 256 gfortran.tar.gz) + KNOWN_SHA256="981367dd0ad4335613e91bbee453d60b6669f5d7e976d18c7bdb7f1966f26ae4 gfortran.tar.gz" + if [ "$GFORTRAN_SHA256" != "$KNOWN_SHA256" ]; then + echo "SHA256 mismatch for gfortran.tar.gz" + echo "expected: $KNOWN_SHA256" + echo "got: $GFORTRAN_SHA256" + exit 1 + fi + + mkdir -p gfortran_installed/ + tar -xv -C gfortran_installed/ -f gfortran.tar.gz + + export FC=$(pwd)/gfortran_installed/gfortran-darwin-x86_64-native/bin/gfortran + export PATH=$(pwd)/gfortran_installed/gfortran-darwin-x86_64-native/bin:$PATH + + # link libgfortran.5.dylib, libgfortran.dylib, libquadmath.0.dylib, libquadmath.dylib, libgcc_s.1.dylib, libgcc_s.1.1.dylib + # and place them in $HOME/.local/lib, and then change rpath + # to $HOME/.local/lib + + mkdir -p $HOME/.local/lib + lib_dir=$(pwd)/gfortran_installed/gfortran-darwin-x86_64-native/lib + for lib in libgfortran.5.dylib libgfortran.dylib libquadmath.0.dylib libquadmath.dylib libgcc_s.1.dylib libgcc_s.1.1.dylib; do + cp $lib_dir/$lib $HOME/.local/lib/ + install_name_tool -id $HOME/.local/lib/$lib $HOME/.local/lib/$lib + # can be removed I think + # install_name_tool -change $lib_dir/$lib $HOME/.local/lib/$lib $HOME/.local/lib/libgfortran.5.dylib + # install_name_tool -change $lib_dir/$lib $HOME/.local/lib/$lib $HOME/.local/lib/libgfortran.dylib + # install_name_tool -change $lib_dir/$lib $HOME/.local/lib/$lib $HOME/.local/lib/libquadmath.0.dylib + # install_name_tool -change $lib_dir/$lib $HOME/.local/lib/$lib $HOME/.local/lib/libquadmath.dylib + done + + export SDKROOT=${SDKROOT:-$(xcrun --show-sdk-path)} + + python -m pip install cmake wget + python scripts/install_KLU_Sundials.py + CIBW_BEFORE_BUILD_MACOS: python -m pip install --upgrade cmake casadi setuptools wheel delocate CIBW_REPAIR_WHEEL_COMMAND_MACOS: delocate-listdeps {wheel} && delocate-wheel -v -w {dest_dir} {wheel} CIBW_TEST_COMMAND: python -c "import pybamm; pybamm.IDAKLUSolver()" @@ -182,7 +212,7 @@ jobs: env: MACOSX_DEPLOYMENT_TARGET: 11.1 CIBW_BEFORE_BUILD: python -m pip install cmake casadi setuptools wheel delocate - CIBW_REPAIR_WHEEL_COMMAND: delocate-listdeps {wheel} && delocate-wheel -v -w {dest_dir} {wheel} + CIBW_REPAIR_WHEEL_COMMAND_MACOS: delocate-listdeps {wheel} && delocate-wheel -v -w {dest_dir} {wheel} CIBW_TEST_COMMAND: python -c "import pybamm; pybamm.IDAKLUSolver()" - name: Upload wheels for macOS arm64 From da25a4b5c3a0879dd20cfa92fd719947db9aeb54 Mon Sep 17 00:00:00 2001 From: Agriya Khetarpal <74401230+agriyakhetarpal@users.noreply.github.com> Date: Thu, 16 May 2024 20:43:15 +0530 Subject: [PATCH 16/23] Build on macos-13 image instead --- .github/workflows/publish_pypi.yml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/.github/workflows/publish_pypi.yml b/.github/workflows/publish_pypi.yml index 60d6a0d6f5..a2902ba20c 100644 --- a/.github/workflows/publish_pypi.yml +++ b/.github/workflows/publish_pypi.yml @@ -99,7 +99,7 @@ jobs: strategy: fail-fast: false matrix: - os: [ubuntu-latest, macos-12] + os: [ubuntu-latest, macos-13] steps: - uses: actions/checkout@v4 name: Check out PyBaMM repository @@ -125,7 +125,7 @@ jobs: CIBW_TEST_COMMAND: python -c "import pybamm; pybamm.IDAKLUSolver()" - name: Build wheels on macOS amd64 - if: matrix.os == 'macos-12' + if: matrix.os == 'macos-13' run: pipx run cibuildwheel --output-dir wheelhouse env: MACOSX_DEPLOYMENT_TARGET: 11.1 From 4bfe789b8c4781fdff221bc7087cf67fc5504f93 Mon Sep 17 00:00:00 2001 From: Agriya Khetarpal <74401230+agriyakhetarpal@users.noreply.github.com> Date: Thu, 16 May 2024 21:38:31 +0530 Subject: [PATCH 17/23] Debug further, try building against 11.0 --- .github/workflows/publish_pypi.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/publish_pypi.yml b/.github/workflows/publish_pypi.yml index a2902ba20c..d4c2dbfca9 100644 --- a/.github/workflows/publish_pypi.yml +++ b/.github/workflows/publish_pypi.yml @@ -128,7 +128,7 @@ jobs: if: matrix.os == 'macos-13' run: pipx run cibuildwheel --output-dir wheelhouse env: - MACOSX_DEPLOYMENT_TARGET: 11.1 + MACOSX_DEPLOYMENT_TARGET: 11.0 # Sourced from # https://github.com/scipy/scipy/blob/f2d4775e7762fad984f8f0acd8227c725ff21630/tools/wheels/cibw_before_build_macos.sh#L23-L49 CIBW_BEFORE_ALL_MACOS: | From 498151f1215308c13681bac3c7efa2719984e211 Mon Sep 17 00:00:00 2001 From: Agriya Khetarpal <74401230+agriyakhetarpal@users.noreply.github.com> Date: Thu, 16 May 2024 22:20:17 +0530 Subject: [PATCH 18/23] And now build for macOS arm64 --- .github/workflows/publish_pypi.yml | 60 ++++++++++++++++++++++-------- 1 file changed, 45 insertions(+), 15 deletions(-) diff --git a/.github/workflows/publish_pypi.yml b/.github/workflows/publish_pypi.yml index d4c2dbfca9..794496684f 100644 --- a/.github/workflows/publish_pypi.yml +++ b/.github/workflows/publish_pypi.yml @@ -172,7 +172,7 @@ jobs: python -m pip install cmake wget python scripts/install_KLU_Sundials.py - CIBW_BEFORE_BUILD_MACOS: python -m pip install --upgrade cmake casadi setuptools wheel delocate + CIBW_BEFORE_BUILD_MACOS: python -m pip install --upgrade pip cmake casadi setuptools wheel delocate CIBW_REPAIR_WHEEL_COMMAND_MACOS: delocate-listdeps {wheel} && delocate-wheel -v -w {dest_dir} {wheel} CIBW_TEST_COMMAND: python -c "import pybamm; pybamm.IDAKLUSolver()" @@ -196,22 +196,52 @@ jobs: - name: Clone pybind11 repo (no history) run: git clone --depth 1 --branch v2.11.1 https://github.com/pybind/pybind11.git - - uses: fortran-lang/setup-fortran@v1.6 - id: setup-fortran - with: - compiler: gcc - version: 12 - - - name: Install SuiteSparse and SUNDIALS on macOS - run: | - python -m pip install cmake pipx - python scripts/install_KLU_Sundials.py - - name: Build wheels on macOS arm64 - run: python -m pipx run cibuildwheel --output-dir wheelhouse + run: | + python -m pip install cibuildwheel + python -m cibuildwheel --output-dir wheelhouse env: - MACOSX_DEPLOYMENT_TARGET: 11.1 - CIBW_BEFORE_BUILD: python -m pip install cmake casadi setuptools wheel delocate + MACOSX_DEPLOYMENT_TARGET: 11.1 # CasADi requires macOS 11.1 + # Sourced from + # https://github.com/scipy/scipy/blob/f2d4775e7762fad984f8f0acd8227c725ff21630/tools/wheels/cibw_before_build_macos.sh#L23-L49 + CIBW_BEFORE_ALL_MACOS: | + set -e -x + + # download gfortran with proper macos minimum version (11.0) + curl -L https://github.com/isuruf/gcc/releases/download/gcc-11.3.0-2/gfortran-darwin-arm64-native.tar.gz -o gfortran.tar.gz + + GFORTRAN_SHA256=$(shasum --algorithm 256 gfortran.tar.gz) + KNOWN_SHA256="84364eee32ba843d883fb8124867e2bf61a0cd73b6416d9897ceff7b85a24604 gfortran.tar.gz" + if [ "$GFORTRAN_SHA256" != "$KNOWN_SHA256" ]; then + echo "SHA256 mismatch for gfortran.tar.gz" + echo "expected: $KNOWN_SHA256" + echo "got: $GFORTRAN_SHA256" + exit 1 + fi + + mkdir -p gfortran_installed/ + tar -xv -C gfortran_installed/ -f gfortran.tar.gz + + export FC=$(pwd)/gfortran_installed/gfortran-darwin-arm64-native/bin/gfortran + export PATH=$(pwd)/gfortran_installed/gfortran-darwin-arm64-native/bin:$PATH + + # link libgfortran.5.dylib, libgfortran.dylib, libquadmath.0.dylib, libquadmath.dylib, libgcc_s.1.1.dylib + # and place them in $HOME/.local/lib, and then change rpath + # note: libgcc_s.1.dylib not present for arm64, skip for now + # to $HOME/.local/lib + + mkdir -p $HOME/.local/lib + lib_dir=$(pwd)/gfortran_installed/gfortran-darwin-arm64-native/lib + for lib in libgfortran.5.dylib libgfortran.dylib libquadmath.0.dylib libquadmath.dylib libgcc_s.1.1.dylib; do + cp $lib_dir/$lib $HOME/.local/lib/ + install_name_tool -id $HOME/.local/lib/$lib $HOME/.local/lib/$lib + done + + export SDKROOT=${SDKROOT:-$(xcrun --show-sdk-path)} + + python -m pip install cmake wget + python scripts/install_KLU_Sundials.py + CIBW_BEFORE_BUILD_MACOS: python -m pip install --upgrade pip cmake casadi setuptools wheel delocate CIBW_REPAIR_WHEEL_COMMAND_MACOS: delocate-listdeps {wheel} && delocate-wheel -v -w {dest_dir} {wheel} CIBW_TEST_COMMAND: python -c "import pybamm; pybamm.IDAKLUSolver()" From 3c84d8dfff6d3664b1e118bc9635a603d5f7714f Mon Sep 17 00:00:00 2001 From: Agriya Khetarpal <74401230+agriyakhetarpal@users.noreply.github.com> Date: Thu, 16 May 2024 22:29:32 +0530 Subject: [PATCH 19/23] Try building arm64 against 11.0 --- .github/workflows/publish_pypi.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/publish_pypi.yml b/.github/workflows/publish_pypi.yml index 794496684f..e5d8a190c8 100644 --- a/.github/workflows/publish_pypi.yml +++ b/.github/workflows/publish_pypi.yml @@ -201,7 +201,7 @@ jobs: python -m pip install cibuildwheel python -m cibuildwheel --output-dir wheelhouse env: - MACOSX_DEPLOYMENT_TARGET: 11.1 # CasADi requires macOS 11.1 + MACOSX_DEPLOYMENT_TARGET: 11.0 # Sourced from # https://github.com/scipy/scipy/blob/f2d4775e7762fad984f8f0acd8227c725ff21630/tools/wheels/cibw_before_build_macos.sh#L23-L49 CIBW_BEFORE_ALL_MACOS: | From 3f822893223319ec0e162bb555014585ede2f223 Mon Sep 17 00:00:00 2001 From: Agriya Khetarpal <74401230+agriyakhetarpal@users.noreply.github.com> Date: Thu, 16 May 2024 23:20:01 +0530 Subject: [PATCH 20/23] Rename wheel from 11_1 to 11_0 --- .github/workflows/publish_pypi.yml | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/.github/workflows/publish_pypi.yml b/.github/workflows/publish_pypi.yml index e5d8a190c8..b41c190531 100644 --- a/.github/workflows/publish_pypi.yml +++ b/.github/workflows/publish_pypi.yml @@ -242,7 +242,10 @@ jobs: python -m pip install cmake wget python scripts/install_KLU_Sundials.py CIBW_BEFORE_BUILD_MACOS: python -m pip install --upgrade pip cmake casadi setuptools wheel delocate - CIBW_REPAIR_WHEEL_COMMAND_MACOS: delocate-listdeps {wheel} && delocate-wheel -v -w {dest_dir} {wheel} + # Rename wheel for now: https://github.com/casadi/casadi/issues/3698 + CIBW_REPAIR_WHEEL_COMMAND_MACOS: | + delocate-listdeps {wheel} && delocate-wheel -v -w {dest_dir} {wheel} --require-target-macos-version 11.1 + mv {dest_dir}/{wheel} | sed 's/macosx_11_1/macosx_11_0/' {dest_dir}/{wheel} CIBW_TEST_COMMAND: python -c "import pybamm; pybamm.IDAKLUSolver()" - name: Upload wheels for macOS arm64 From e0ad96ccd379cb7d1445d0a2516ed97913e1910e Mon Sep 17 00:00:00 2001 From: Agriya Khetarpal <74401230+agriyakhetarpal@users.noreply.github.com> Date: Thu, 16 May 2024 23:49:54 +0530 Subject: [PATCH 21/23] Cleanup and fix up commands --- .github/workflows/publish_pypi.yml | 3 +-- scripts/install_KLU_Sundials.py | 13 +++---------- 2 files changed, 4 insertions(+), 12 deletions(-) diff --git a/.github/workflows/publish_pypi.yml b/.github/workflows/publish_pypi.yml index b41c190531..e644e4d5be 100644 --- a/.github/workflows/publish_pypi.yml +++ b/.github/workflows/publish_pypi.yml @@ -242,10 +242,9 @@ jobs: python -m pip install cmake wget python scripts/install_KLU_Sundials.py CIBW_BEFORE_BUILD_MACOS: python -m pip install --upgrade pip cmake casadi setuptools wheel delocate - # Rename wheel for now: https://github.com/casadi/casadi/issues/3698 + # Use higher macOS target for now: https://github.com/casadi/casadi/issues/3698 CIBW_REPAIR_WHEEL_COMMAND_MACOS: | delocate-listdeps {wheel} && delocate-wheel -v -w {dest_dir} {wheel} --require-target-macos-version 11.1 - mv {dest_dir}/{wheel} | sed 's/macosx_11_1/macosx_11_0/' {dest_dir}/{wheel} CIBW_TEST_COMMAND: python -c "import pybamm; pybamm.IDAKLUSolver()" - name: Upload wheels for macOS arm64 diff --git a/scripts/install_KLU_Sundials.py b/scripts/install_KLU_Sundials.py index 2b9d268bac..c0e046c48d 100755 --- a/scripts/install_KLU_Sundials.py +++ b/scripts/install_KLU_Sundials.py @@ -136,8 +136,8 @@ def install_sundials(download_dir, install_dir): subprocess.run(make_cmd, cwd=build_dir, check=True) -# relevant for macOS only because recent Xcode Clang does not include OpenMP headers. -# Other compilers (e.g. GCC) include OpenMP specification by default. +# Relevant for macOS only because recent Xcode Clang versions do not include OpenMP headers. +# Other compilers (e.g. GCC) include the OpenMP specification by default. def set_up_openmp(download_dir, install_dir): print("-" * 10, "Extracting OpenMP archive", "-" * 40) @@ -323,13 +323,6 @@ def parallel_download(urls, download_dir): # Build in parallel wherever possible os.environ["CMAKE_BUILD_PARALLEL_LEVEL"] = str(cpu_count()) -# Set macOS environment variables for compatibility. this is set to -# 1. 11.1 for arm64 (libcasadi.dylib), and -# 2. 11.0 for x86_64 (libomp.dylib) -os.environ["MACOSX_DEPLOYMENT_TARGET"] = ( - "11.1" if platform.machine == "arm64" else "11.0" -) - # Create download directory in PyBaMM dir pybamm_dir = os.path.split(os.path.abspath(os.path.dirname(__file__)))[0] download_dir = os.path.join(pybamm_dir, "install_KLU_Sundials") @@ -401,7 +394,7 @@ def parallel_download(urls, download_dir): if platform.system() == "Darwin" and not openmp_found: download_extract_library(OPENMP_URL, OPENMP_CHECKSUM, download_dir) set_up_openmp(download_dir, install_dir) - # openmp needed for sundials on macOS + # openmp needed for SUNDIALS on macOS install_sundials(download_dir, install_dir) if not suitesparse_found: # Only SuiteSparse is missing, download and install it From 18dcbbd7455ab2c9308c075df7952979437461c4 Mon Sep 17 00:00:00 2001 From: Agriya Khetarpal <74401230+agriyakhetarpal@users.noreply.github.com> Date: Thu, 16 May 2024 23:59:14 +0530 Subject: [PATCH 22/23] Rename wheel in dest dir instead --- .github/workflows/publish_pypi.yml | 1 + 1 file changed, 1 insertion(+) diff --git a/.github/workflows/publish_pypi.yml b/.github/workflows/publish_pypi.yml index e644e4d5be..7411345081 100644 --- a/.github/workflows/publish_pypi.yml +++ b/.github/workflows/publish_pypi.yml @@ -245,6 +245,7 @@ jobs: # Use higher macOS target for now: https://github.com/casadi/casadi/issues/3698 CIBW_REPAIR_WHEEL_COMMAND_MACOS: | delocate-listdeps {wheel} && delocate-wheel -v -w {dest_dir} {wheel} --require-target-macos-version 11.1 + for file in {dest_dir}/*.whl; do mv "$file" "${file//macosx_11_1/macosx_11_0}"; done CIBW_TEST_COMMAND: python -c "import pybamm; pybamm.IDAKLUSolver()" - name: Upload wheels for macOS arm64 From 30a76b90c1b9ac91c32dec1eb7247356ed75e5f2 Mon Sep 17 00:00:00 2001 From: Agriya Khetarpal <74401230+agriyakhetarpal@users.noreply.github.com> Date: Fri, 17 May 2024 20:19:25 +0530 Subject: [PATCH 23/23] Cleanup plus references to SciPy license --- .github/workflows/publish_pypi.yml | 7 ++----- 1 file changed, 2 insertions(+), 5 deletions(-) diff --git a/.github/workflows/publish_pypi.yml b/.github/workflows/publish_pypi.yml index 7411345081..01bf7ad95f 100644 --- a/.github/workflows/publish_pypi.yml +++ b/.github/workflows/publish_pypi.yml @@ -130,6 +130,7 @@ jobs: env: MACOSX_DEPLOYMENT_TARGET: 11.0 # Sourced from + # License: BSD-3-Clause # https://github.com/scipy/scipy/blob/f2d4775e7762fad984f8f0acd8227c725ff21630/tools/wheels/cibw_before_build_macos.sh#L23-L49 CIBW_BEFORE_ALL_MACOS: | set -e -x @@ -161,11 +162,6 @@ jobs: for lib in libgfortran.5.dylib libgfortran.dylib libquadmath.0.dylib libquadmath.dylib libgcc_s.1.dylib libgcc_s.1.1.dylib; do cp $lib_dir/$lib $HOME/.local/lib/ install_name_tool -id $HOME/.local/lib/$lib $HOME/.local/lib/$lib - # can be removed I think - # install_name_tool -change $lib_dir/$lib $HOME/.local/lib/$lib $HOME/.local/lib/libgfortran.5.dylib - # install_name_tool -change $lib_dir/$lib $HOME/.local/lib/$lib $HOME/.local/lib/libgfortran.dylib - # install_name_tool -change $lib_dir/$lib $HOME/.local/lib/$lib $HOME/.local/lib/libquadmath.0.dylib - # install_name_tool -change $lib_dir/$lib $HOME/.local/lib/$lib $HOME/.local/lib/libquadmath.dylib done export SDKROOT=${SDKROOT:-$(xcrun --show-sdk-path)} @@ -203,6 +199,7 @@ jobs: env: MACOSX_DEPLOYMENT_TARGET: 11.0 # Sourced from + # License: BSD-3-Clause # https://github.com/scipy/scipy/blob/f2d4775e7762fad984f8f0acd8227c725ff21630/tools/wheels/cibw_before_build_macos.sh#L23-L49 CIBW_BEFORE_ALL_MACOS: | set -e -x