Skip to content

Commit

Permalink
Update workflows (#6)
Browse files Browse the repository at this point in the history
* Pre-commit and workflow updates

* Fix typo

* Add MacOS build tests

* Fix style

* Fix typo

* Update mac tests

* Update mac tests

* Fix tests
  • Loading branch information
kratman authored Oct 17, 2024
1 parent 357ac25 commit 8a99bfc
Show file tree
Hide file tree
Showing 10 changed files with 185 additions and 65 deletions.
5 changes: 2 additions & 3 deletions .github/workflows/build_wheels.yml
Original file line number Diff line number Diff line change
Expand Up @@ -208,7 +208,7 @@ jobs:
python install_KLU_Sundials.py
python -m cibuildwheel --output-dir wheelhouse
env:
# 10.13 for Intel (macos-12/macos-13), 11.0 for Apple Silicon (macos-14 and macos-latest)
# 10.13 for Intel (macos-13), 11.0 for Apple Silicon (macos-14 and macos-latest)
MACOSX_DEPLOYMENT_TARGET: ${{ matrix.os == 'macos-14' && '11.0' || '10.13' }}
CIBW_ARCHS_MACOS: auto
CIBW_BEFORE_BUILD: python -m pip install cmake casadi setuptools wheel delocate
Expand Down Expand Up @@ -253,7 +253,7 @@ jobs:
if-no-files-found: error

publish_pypi:
if: github.repository == 'pybamm-team/pybammsolvers'
if: ${{ github.event_name == 'release' && github.repository == 'pybamm-team/pybammsolvers' }}
name: Upload package to PyPI
needs: [
build_manylinux_wheels,
Expand All @@ -279,7 +279,6 @@ jobs:
run: ls -lA artifacts/

- name: Publish to PyPI
if: github.event_name == 'release'
uses: pypa/gh-action-pypi-publish@release/v1
with:
packages-dir: artifacts/
19 changes: 19 additions & 0 deletions .github/workflows/pre-commit.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
name: Static analysis

on:
pull_request:
branches: [main]

concurrency:
group: ${{ github.workflow }}-${{ github.ref }}
cancel-in-progress: true

jobs:
pre-commit:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
with:
submodules: 'true'
- uses: actions/setup-python@v4
- uses: pre-commit/[email protected]
24 changes: 21 additions & 3 deletions .github/workflows/unit_tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -11,24 +11,42 @@ concurrency:

jobs:
pytest:
runs-on: ubuntu-latest
runs-on: ${{ matrix.os }}
strategy:
fail-fast: false
matrix:
python-version: ["3.11"]
os: [ ubuntu-latest, macos-13, macos-latest]
python-version: [ "3.9", "3.10", "3.11", "3.12" ]

steps:
- uses: actions/checkout@v4
with:
submodules: 'true'

- name: Set up Python ${{ matrix.python-version }}
uses: actions/setup-python@v4
with:
python-version: ${{ matrix.python-version }}
- name: Install dependencies

- name: Install dependencies (Linux)
if: matrix.os == 'ubuntu-latest'
run: |
sudo apt-get install gfortran gcc libopenblas-dev
pip install nox
- name: Install dependencies (MacOs)
if: matrix.os == 'macos-13' || matrix.os == 'macos-latest'
env:
HOMEBREW_NO_INSTALL_CLEANUP: 1
HOMEBREW_NO_AUTO_UPDATE: 1
HOMEBREW_NO_COLOR: 1
NONINTERACTIVE: 1
run: |
brew analytics off
brew install libomp
brew reinstall gcc
pip install nox
- name: Build and test
run: |
nox
13 changes: 13 additions & 0 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
ci:
autoupdate_commit_msg: "chore: update pre-commit hooks"
autofix_commit_msg: "style: pre-commit fixes"

repos:
- repo: https://github.com/astral-sh/ruff-pre-commit
rev: "v0.1.3"
hooks:
- id: ruff
args: [--fix, --show-fixes]
types_or: [python, pyi, jupyter]
- id: ruff-format
types_or: [python, pyi, jupyter]
25 changes: 16 additions & 9 deletions install_KLU_Sundials.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,9 @@ def build_solvers():
SUITESPARSE_CHECKSUM = (
"7111b505c1207f6f4bd0be9740d0b2897e1146b845d73787df07901b4f5c1fb7"
)
SUNDIALS_CHECKSUM = "4e0b998dff292a2617e179609b539b511eb80836f5faacf800e688a886288502"
SUNDIALS_CHECKSUM = (
"4e0b998dff292a2617e179609b539b511eb80836f5faacf800e688a886288502"
)
DEFAULT_INSTALL_DIR = str(pathlib.Path(__file__).parent.resolve() / ".idaklu")

def safe_remove_dir(path):
Expand Down Expand Up @@ -58,19 +60,19 @@ def install_suitesparse(download_dir):
# if in CI, set RPATH to the install directory for SuiteSparse_config
# dylibs to find libomp.dylib when repairing the wheel
if os.environ.get("CIBUILDWHEEL") == "1":
env["CMAKE_OPTIONS"] = (
f"-DCMAKE_INSTALL_PREFIX={install_dir} -DCMAKE_INSTALL_RPATH={install_dir}/lib"
)
env[
"CMAKE_OPTIONS"
] = f"-DCMAKE_INSTALL_PREFIX={install_dir} -DCMAKE_INSTALL_RPATH={install_dir}/lib"
else:
env["CMAKE_OPTIONS"] = f"-DCMAKE_INSTALL_PREFIX={install_dir}"
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
# at runtime just once. Otherwise, delocate complains about multiple
# references to the SuiteSparse_config dynamic library (auditwheel does not).
env["CMAKE_OPTIONS"] = (
f"-DCMAKE_INSTALL_PREFIX={install_dir} -DCMAKE_INSTALL_RPATH={install_dir}/lib -DCMAKE_INSTALL_RPATH_USE_LINK_PATH=FALSE -DCMAKE_BUILD_WITH_INSTALL_RPATH=FALSE"
)
env[
"CMAKE_OPTIONS"
] = f"-DCMAKE_INSTALL_PREFIX={install_dir} -DCMAKE_INSTALL_RPATH={install_dir}/lib -DCMAKE_INSTALL_RPATH_USE_LINK_PATH=FALSE -DCMAKE_BUILD_WITH_INSTALL_RPATH=FALSE"
subprocess.run(make_cmd, cwd=build_dir, env=env, shell=True, check=True)
subprocess.run(install_cmd, cwd=build_dir, check=True)

Expand Down Expand Up @@ -106,7 +108,9 @@ def install_sundials(download_dir, install_dir):
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_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:
Expand Down Expand Up @@ -305,7 +309,9 @@ def parallel_download(urls, download_dir):
"The '--force' option is activated: installation will be forced, ignoring any existing libraries."
)
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"SuiteSparse-{SUITESPARSE_VERSION}")
)
safe_remove_dir(os.path.join(download_dir, f"sundials-{SUNDIALS_VERSION}"))
sundials_found, suitesparse_found = False, False
else:
Expand Down Expand Up @@ -334,5 +340,6 @@ def parallel_download(urls, download_dir):
parallel_download([(SUITESPARSE_URL, SUITESPARSE_CHECKSUM)], download_dir)
install_suitesparse(download_dir)


if __name__ == "__main__":
build_solvers()
2 changes: 1 addition & 1 deletion noxfile.py
Original file line number Diff line number Diff line change
Expand Up @@ -114,6 +114,7 @@ def run_pybamm_requires(session):
else:
session.error("nox -s idaklu-requires is only available on Linux & macOS.")


@nox.session(name="unit")
def run_unit(session):
"""Run the unit tests."""
Expand All @@ -131,4 +132,3 @@ def run_unit(session):
silent=False,
)
session.run("pytest", "tests")

3 changes: 3 additions & 0 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -19,11 +19,14 @@ license = {file = "LICENSE"}
dynamic = ["version", "readme"]
dependencies = [
"casadi",
"numpy<2.0"
]

[project.optional-dependencies]
dev = [
"pytest",
"setuptools",
"wheel",
]

[tool.setuptools.packages.find]
Expand Down
59 changes: 59 additions & 0 deletions ruff.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
# Exclude a variety of commonly ignored directories.
exclude = [
"__init__.py",
"docs",
".eggs",
".git",
".mypy_cache",
".pytype",
".ruff_cache",
".venv",
"__pypackages__",
"_build",
"build",
"dist",
"node_modules",
"venv",
]

line-length = 88
indent-width = 4

target-version = "py310"

[lint]
select = [
"W",
"E",
"F",
"B",
"A",
"U",
"SLF",
]
ignore = [
"E501", # Line length check conflicted with the formatter
"B018", # Useless expression checks were a problem for notebooks
"B905", # Requires zip to have explict strict flag. Enable in the future
]

# Allow fix for all enabled rules (when `--fix`) is provided.
fixable = ["ALL"]
unfixable = []

# Allow unused variables when underscore-prefixed.
dummy-variable-rgx = "^(_+|(_+[a-zA-Z0-9_]*[a-zA-Z0-9]+?))$"

[format]
# Like Black, use double quotes for strings.
quote-style = "double"

# Like Black, indent with spaces, rather than tabs.
indent-style = "space"

# Like Black, respect magic trailing commas.
skip-magic-trailing-comma = false

# Like Black, automatically detect the appropriate line ending.
line-ending = "auto"

98 changes: 50 additions & 48 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -178,8 +178,9 @@ def move_output(self, ext):

# ---------- end of CMake steps --------------------------------------------------------


class CustomInstall(install):
"""A custom install command to add 2 build options"""
"""A custom installation command to add 2 build options"""

user_options = [
*install.user_options,
Expand Down Expand Up @@ -207,7 +208,7 @@ def run(self):


class bdist_wheel(orig.bdist_wheel):
"""A custom install command to add 2 build options"""
"""A custom installation command to add 2 build options"""

user_options = [
*orig.bdist_wheel.user_options,
Expand All @@ -231,52 +232,53 @@ def run(self):
orig.bdist_wheel.run(self)


idaklu_ext = Extension(
name="pybammsolvers.idaklu",
# The sources list should mirror the list in CMakeLists.txt
sources=[
"src/pybammsolvers/idaklu_source/Expressions/Expressions.hpp",
"src/pybammsolvers/idaklu_source/Expressions/Base/Expression.hpp",
"src/pybammsolvers/idaklu_source/Expressions/Base/ExpressionSet.hpp",
"src/pybammsolvers/idaklu_source/Expressions/Base/ExpressionTypes.hpp",
"src/pybammsolvers/idaklu_source/Expressions/Base/ExpressionSparsity.hpp",
"src/pybammsolvers/idaklu_source/Expressions/Casadi/CasadiFunctions.cpp",
"src/pybammsolvers/idaklu_source/Expressions/Casadi/CasadiFunctions.hpp",
"src/pybammsolvers/idaklu_source/Expressions/IREE/IREEBaseFunction.hpp",
"src/pybammsolvers/idaklu_source/Expressions/IREE/IREEFunction.hpp",
"src/pybammsolvers/idaklu_source/Expressions/IREE/IREEFunctions.cpp",
"src/pybammsolvers/idaklu_source/Expressions/IREE/IREEFunctions.hpp",
"src/pybammsolvers/idaklu_source/Expressions/IREE/iree_jit.cpp",
"src/pybammsolvers/idaklu_source/Expressions/IREE/iree_jit.hpp",
"src/pybammsolvers/idaklu_source/Expressions/IREE/ModuleParser.cpp",
"src/pybammsolvers/idaklu_source/Expressions/IREE/ModuleParser.hpp",
"src/pybammsolvers/idaklu_source/idaklu_solver.hpp",
"src/pybammsolvers/idaklu_source/IDAKLUSolver.cpp",
"src/pybammsolvers/idaklu_source/IDAKLUSolver.hpp",
"src/pybammsolvers/idaklu_source/IDAKLUSolverGroup.cpp",
"src/pybammsolvers/idaklu_source/IDAKLUSolverGroup.hpp",
"src/pybammsolvers/idaklu_source/IDAKLUSolverOpenMP.inl",
"src/pybammsolvers/idaklu_source/IDAKLUSolverOpenMP.hpp",
"src/pybammsolvers/idaklu_source/IDAKLUSolverOpenMP_solvers.cpp",
"src/pybammsolvers/idaklu_source/IDAKLUSolverOpenMP_solvers.hpp",
"src/pybammsolvers/idaklu_source/sundials_functions.inl",
"src/pybammsolvers/idaklu_source/sundials_functions.hpp",
"src/pybammsolvers/idaklu_source/IdakluJax.cpp",
"src/pybammsolvers/idaklu_source/IdakluJax.hpp",
"src/pybammsolvers/idaklu_source/common.hpp",
"src/pybammsolvers/idaklu_source/common.cpp",
"src/pybammsolvers/idaklu_source/Solution.cpp",
"src/pybammsolvers/idaklu_source/Solution.hpp",
"src/pybammsolvers/idaklu_source/SolutionData.cpp",
"src/pybammsolvers/idaklu_source/SolutionData.hpp",
"src/pybammsolvers/idaklu_source/observe.cpp",
"src/pybammsolvers/idaklu_source/observe.hpp",
"src/pybammsolvers/idaklu_source/Options.hpp",
"src/pybammsolvers/idaklu_source/Options.cpp",
"src/pybammsolvers/idaklu.cpp",
],
)
ext_modules = [idaklu_ext]
ext_modules = [
Extension(
name="pybammsolvers.idaklu",
# The sources list should mirror the list in CMakeLists.txt
sources=[
"src/pybammsolvers/idaklu_source/Expressions/Expressions.hpp",
"src/pybammsolvers/idaklu_source/Expressions/Base/Expression.hpp",
"src/pybammsolvers/idaklu_source/Expressions/Base/ExpressionSet.hpp",
"src/pybammsolvers/idaklu_source/Expressions/Base/ExpressionTypes.hpp",
"src/pybammsolvers/idaklu_source/Expressions/Base/ExpressionSparsity.hpp",
"src/pybammsolvers/idaklu_source/Expressions/Casadi/CasadiFunctions.cpp",
"src/pybammsolvers/idaklu_source/Expressions/Casadi/CasadiFunctions.hpp",
"src/pybammsolvers/idaklu_source/Expressions/IREE/IREEBaseFunction.hpp",
"src/pybammsolvers/idaklu_source/Expressions/IREE/IREEFunction.hpp",
"src/pybammsolvers/idaklu_source/Expressions/IREE/IREEFunctions.cpp",
"src/pybammsolvers/idaklu_source/Expressions/IREE/IREEFunctions.hpp",
"src/pybammsolvers/idaklu_source/Expressions/IREE/iree_jit.cpp",
"src/pybammsolvers/idaklu_source/Expressions/IREE/iree_jit.hpp",
"src/pybammsolvers/idaklu_source/Expressions/IREE/ModuleParser.cpp",
"src/pybammsolvers/idaklu_source/Expressions/IREE/ModuleParser.hpp",
"src/pybammsolvers/idaklu_source/idaklu_solver.hpp",
"src/pybammsolvers/idaklu_source/IDAKLUSolver.cpp",
"src/pybammsolvers/idaklu_source/IDAKLUSolver.hpp",
"src/pybammsolvers/idaklu_source/IDAKLUSolverGroup.cpp",
"src/pybammsolvers/idaklu_source/IDAKLUSolverGroup.hpp",
"src/pybammsolvers/idaklu_source/IDAKLUSolverOpenMP.inl",
"src/pybammsolvers/idaklu_source/IDAKLUSolverOpenMP.hpp",
"src/pybammsolvers/idaklu_source/IDAKLUSolverOpenMP_solvers.cpp",
"src/pybammsolvers/idaklu_source/IDAKLUSolverOpenMP_solvers.hpp",
"src/pybammsolvers/idaklu_source/sundials_functions.inl",
"src/pybammsolvers/idaklu_source/sundials_functions.hpp",
"src/pybammsolvers/idaklu_source/IdakluJax.cpp",
"src/pybammsolvers/idaklu_source/IdakluJax.hpp",
"src/pybammsolvers/idaklu_source/common.hpp",
"src/pybammsolvers/idaklu_source/common.cpp",
"src/pybammsolvers/idaklu_source/Solution.cpp",
"src/pybammsolvers/idaklu_source/Solution.hpp",
"src/pybammsolvers/idaklu_source/SolutionData.cpp",
"src/pybammsolvers/idaklu_source/SolutionData.hpp",
"src/pybammsolvers/idaklu_source/observe.cpp",
"src/pybammsolvers/idaklu_source/observe.hpp",
"src/pybammsolvers/idaklu_source/Options.hpp",
"src/pybammsolvers/idaklu_source/Options.cpp",
"src/pybammsolvers/idaklu.cpp",
],
)
]

# Project metadata was moved to pyproject.toml (which is read by pip). However, custom
# build commands and setuptools extension modules are still defined here.
Expand Down
2 changes: 1 addition & 1 deletion src/pybammsolvers/version.py
Original file line number Diff line number Diff line change
@@ -1 +1 @@
__version__="0.0.1"
__version__ = "0.0.1"

0 comments on commit 8a99bfc

Please sign in to comment.