From e089aa4d1aa8eff0d8727d7000f27ff9150783d3 Mon Sep 17 00:00:00 2001 From: Lehman Garrison Date: Fri, 22 Jul 2022 10:17:15 -0400 Subject: [PATCH 1/4] Add MacOS CI config and add cross-platform maxthreads() --- .github/workflows/tests.yml | 6 +++++- abacusnbody/common.py | 17 +++++++++++++++++ abacusnbody/data/compaso_halo_catalog.py | 4 ++-- 3 files changed, 24 insertions(+), 3 deletions(-) create mode 100644 abacusnbody/common.py diff --git a/.github/workflows/tests.yml b/.github/workflows/tests.yml index 38e10240..0786dc1a 100644 --- a/.github/workflows/tests.yml +++ b/.github/workflows/tests.yml @@ -5,10 +5,14 @@ on: [push] jobs: build: - runs-on: ubuntu-latest + runs-on: ${{ matrix.os }} strategy: matrix: + os: [ubuntu-latest] python-version: ["3.7", "3.8", "3.9", "3.10"] + include: + - os: macos-latest + python-version: "3.10" steps: - uses: actions/checkout@v2 diff --git a/abacusnbody/common.py b/abacusnbody/common.py new file mode 100644 index 00000000..a926d143 --- /dev/null +++ b/abacusnbody/common.py @@ -0,0 +1,17 @@ +'''Common utility functions. +''' + +def maxthreads(): + '''Return the number of logical cores available to this process. + First tries the affinity mask, then the total number of CPUs, + then 1 if all else fails. + ''' + import multiprocessing + import os + + try: + maxthreads = len(os.sched_getaffinity(0)) + except AttributeError: + maxthreads = multiprocessing.cpu_count() or 1 + + return maxthreads diff --git a/abacusnbody/data/compaso_halo_catalog.py b/abacusnbody/data/compaso_halo_catalog.py index 873e91d7..951bb1c9 100644 --- a/abacusnbody/data/compaso_halo_catalog.py +++ b/abacusnbody/data/compaso_halo_catalog.py @@ -290,10 +290,11 @@ raise Exception("Abacus ASDF extension not properly loaded! Try reinstalling abacusutils, or updating ASDF: `pip install asdf>=2.8`") from e from . import bitpacked +from ..common import maxthreads # Default to 4 decompression threads, or fewer if fewer cores are available DEFAULT_BLOSC_THREADS = 4 -DEFAULT_BLOSC_THREADS = max(1, min(len(os.sched_getaffinity(0)), DEFAULT_BLOSC_THREADS)) +DEFAULT_BLOSC_THREADS = max(1, min(maxthreads(), DEFAULT_BLOSC_THREADS)) from . import asdf as _asdf _asdf.set_nthreads(DEFAULT_BLOSC_THREADS) @@ -1741,4 +1742,3 @@ def unpack_euler16(bin_this): ('sigmavtan_L2com', np.float32), ('rvcirc_max_L2com', np.float32), ], align=True) - From ca598ab48a29163233bf2ac4965548e2a3a6baff Mon Sep 17 00:00:00 2001 From: Lehman Garrison Date: Fri, 22 Jul 2022 11:17:33 -0400 Subject: [PATCH 2/4] Convert from namespace package to regular package so we can version the utils (and fix common.py import). Will need some thought if we want to convert back and include the simulation code in the namespace. --- setup.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/setup.py b/setup.py index 19cbc38b..0a54b576 100644 --- a/setup.py +++ b/setup.py @@ -1,6 +1,6 @@ import os -from setuptools import setup, find_namespace_packages +from setuptools import setup, find_packages install_requires = ['numpy>=1.16','blosc>=1.9.2','astropy>=4.0.0','scipy>=1.5.0','numba>=0.50','asdf>=2.8','h5py','pyyaml'] @@ -27,7 +27,7 @@ long_description=long_description, long_description_content_type="text/markdown", url="https://github.com/abacusorg/abacusutils", - packages=find_namespace_packages(include=['abacusnbody.*']), + packages=find_packages(include=['abacusnbody']), include_package_data=True, classifiers=[ "Programming Language :: Python :: 3", From 0b03a264592ecd340993da060947c2f38ff10cce Mon Sep 17 00:00:00 2001 From: Lehman Garrison Date: Fri, 22 Jul 2022 11:27:37 -0400 Subject: [PATCH 3/4] try to install gsl on mac --- .github/workflows/tests.yml | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/.github/workflows/tests.yml b/.github/workflows/tests.yml index 0786dc1a..2dc9a714 100644 --- a/.github/workflows/tests.yml +++ b/.github/workflows/tests.yml @@ -20,6 +20,11 @@ jobs: uses: actions/setup-python@v2 with: python-version: ${{ matrix.python-version }} + + - name: Install MacOS dependencies + if: matrix.os == 'macos-latest' + run: brew install gsl + - name: Install dependencies run: | python -m pip install -U pip From c970abcb40390ef3ee3c5cf7246520d9f8ae9b78 Mon Sep 17 00:00:00 2001 From: Lehman Garrison Date: Tue, 26 Jul 2022 09:59:02 -0400 Subject: [PATCH 4/4] changelog --- CHANGES.rst | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/CHANGES.rst b/CHANGES.rst index fae147dd..e8c77cd9 100644 --- a/CHANGES.rst +++ b/CHANGES.rst @@ -1,6 +1,13 @@ Changelog ========= +1.3.1 (upcoming) +---------------- + +Enhancements +~~~~~~~~~~~~ +- Add support for MacOS and add CI config [#59] + 1.3.0 (2022-06-08) ------------------