From fef8a5554167abb552893231a03ff520706051f6 Mon Sep 17 00:00:00 2001 From: Agriya Khetarpal <74401230+agriyakhetarpal@users.noreply.github.com> Date: Thu, 7 Dec 2023 15:21:25 +0530 Subject: [PATCH] Try to use Python CasADi to link on Windows --- .github/workflows/publish_pypi.yml | 2 +- CMakeLists.txt | 15 +++++---------- pyproject.toml | 4 ++-- setup.py | 6 ------ vcpkg-configuration.json | 6 ------ vcpkg.json | 1 - 6 files changed, 8 insertions(+), 26 deletions(-) diff --git a/.github/workflows/publish_pypi.yml b/.github/workflows/publish_pypi.yml index a1db0e9a39..6447df67da 100644 --- a/.github/workflows/publish_pypi.yml +++ b/.github/workflows/publish_pypi.yml @@ -66,7 +66,7 @@ jobs: env: CIBW_ENVIRONMENT: 'PYBAMM_USE_VCPKG=ON VCPKG_ROOT_DIR=C:\vcpkg VCPKG_DEFAULT_TRIPLET=x64-windows-static-md VCPKG_FEATURE_FLAGS=manifests,registries CMAKE_GENERATOR="Visual Studio 17 2022" CMAKE_GENERATOR_PLATFORM=x64' CIBW_ARCHS: "AMD64" - CIBW_BEFORE_BUILD: python -m pip install setuptools wheel # skip CasADi and CMake + CIBW_BEFORE_BUILD: python -m pip install setuptools wheel casadi # skip CMake CIBW_TEST_COMMAND: python -c "import pybamm; pybamm.IDAKLUSolver()" - name: Upload Windows wheels diff --git a/CMakeLists.txt b/CMakeLists.txt index e9b3675e59..9f1608c36c 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -60,10 +60,6 @@ pybind11_add_module(idaklu pybamm/solvers/c_solvers/idaklu.cpp ) -if (NOT DEFINED USE_PYTHON_CASADI) - set(USE_PYTHON_CASADI TRUE) -endif() - # Use importlib to find the casadi path without importing it. This is useful # to find the path for the build-time dependency, not the run-time dependency. execute_process( @@ -77,15 +73,14 @@ if (CASADI_DIR) message("Found Python casadi path: ${CASADI_DIR}") endif() -if(${USE_PYTHON_CASADI}) - message("Trying to link against Python casadi package") - find_package(casadi CONFIG PATHS ${CASADI_DIR} REQUIRED NO_DEFAULT_PATH) -else() - message("Trying to link against any casadi package apart from the Python one") +message("Trying to link against Python casadi package") + +if (WIN32) set(CMAKE_IGNORE_PATH "${CASADI_DIR}/cmake") - find_package(casadi CONFIG REQUIRED) endif() +find_package(casadi CONFIG PATHS ${CASADI_DIR} REQUIRED NO_DEFAULT_PATH) + set_target_properties( idaklu PROPERTIES INSTALL_RPATH "${CASADI_DIR}" diff --git a/pyproject.toml b/pyproject.toml index 19c8800a63..40bf66a6d6 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -2,8 +2,8 @@ requires = [ "setuptools>=64", "wheel", - # On Windows, use the CasADi vcpkg registry and CMake bundled from MSVC - "casadi>=3.6.3; platform_system!='Windows'", + # On Windows, use CMake bundled from MSVC + "casadi>=3.6.3", "cmake; platform_system!='Windows'", ] build-backend = "setuptools.build_meta" diff --git a/setup.py b/setup.py index ef82e65e70..ffabf3b4af 100644 --- a/setup.py +++ b/setup.py @@ -84,16 +84,10 @@ def run(self): if not self.extensions: return - if system() == "Windows": - use_python_casadi = False - else: - use_python_casadi = True - build_type = os.getenv("PYBAMM_CPP_BUILD_TYPE", "RELEASE") cmake_args = [ "-DCMAKE_BUILD_TYPE={}".format(build_type), "-DPYTHON_EXECUTABLE={}".format(sys.executable), - "-DUSE_PYTHON_CASADI={}".format("TRUE" if use_python_casadi else "FALSE"), ] if self.suitesparse_root: cmake_args.append( diff --git a/vcpkg-configuration.json b/vcpkg-configuration.json index 8ab4e738fc..4a94841d32 100644 --- a/vcpkg-configuration.json +++ b/vcpkg-configuration.json @@ -9,12 +9,6 @@ "repository": "https://github.com/pybamm-team/sundials-vcpkg-registry.git", "baseline": "af9f5e4bc730bf2361c47f809dcfb733e7951faa", "packages": ["sundials"] - }, - { - "kind": "git", - "repository": "https://github.com/pybamm-team/casadi-vcpkg-registry.git", - "baseline": "70f49f3c22fee4874fb8a36ef1a559f2c185ef1f", - "packages": ["casadi"] } ] } diff --git a/vcpkg.json b/vcpkg.json index f62c18ddd2..e3c5e89424 100644 --- a/vcpkg.json +++ b/vcpkg.json @@ -2,7 +2,6 @@ "name": "pybamm", "version-string": "23.9", "dependencies": [ - "casadi", { "name": "sundials", "default-features": false,