From e5d4a5e5232f4cdc2c8b0cce2ed895b32ebe9963 Mon Sep 17 00:00:00 2001 From: Thomas Robitaille Date: Tue, 8 Feb 2022 22:18:08 +0000 Subject: [PATCH 1/7] Adding GitHub Actions configuration --- .github/workflows/main.yml | 53 ++++++++++++++++++++++++++++++++++++++ 1 file changed, 53 insertions(+) create mode 100644 .github/workflows/main.yml diff --git a/.github/workflows/main.yml b/.github/workflows/main.yml new file mode 100644 index 00000000..01e2966d --- /dev/null +++ b/.github/workflows/main.yml @@ -0,0 +1,53 @@ +name: Continuous Integration + +on: + push: + branches: + - '*' + tags: + - '*' + pull_request: + +jobs: + tests: + name: ${{ matrix.name }} + runs-on: ${{ matrix.os }} + strategy: + matrix: + include: + - name: Python 3.6 + os: ubuntu-latest + python: '3.6' + - name: Python 3.7 + os: ubuntu-latest + python: '3.7' + - name: Python 3.8 + os: ubuntu-latest + python: '3.8' + - name: Python 3.9 + os: ubuntu-latest + python: '3.9' + - name: Python 3.10 + os: ubuntu-latest + python: '3.10' + steps: + - name: Checkout code + uses: actions/checkout@v2 + - name: Set up Python + uses: actions/setup-python@v2 + with: + python-version: ${{ matrix.python }} + - name: Install HDF5 and MPI + if: startsWith(matrix.os, 'ubuntu') + run: sudo apt-get install libhdf5-serial-dev libmpich-dev + - name: Install Hyperion Fortran executables + run: | + ./configure + make serial + sudo make install + pip install -e .[test] + pytest hyperion + - name: Install Hyperion Python package + run: pip install -e .[test] + - name: Run tests + run: pytest hyperion From 2db22e37540021fdb19c36ad044ab71f5ec39ecc Mon Sep 17 00:00:00 2001 From: Thomas Robitaille Date: Tue, 8 Feb 2022 22:19:49 +0000 Subject: [PATCH 2/7] Check out submodules --- .github/workflows/main.yml | 2 ++ 1 file changed, 2 insertions(+) diff --git a/.github/workflows/main.yml b/.github/workflows/main.yml index 01e2966d..373da67c 100644 --- a/.github/workflows/main.yml +++ b/.github/workflows/main.yml @@ -33,6 +33,8 @@ jobs: steps: - name: Checkout code uses: actions/checkout@v2 + with: + submodules: 'true' - name: Set up Python uses: actions/setup-python@v2 with: From b278eb1816a848c56d5fe5412f17866f44ff1e01 Mon Sep 17 00:00:00 2001 From: Thomas Robitaille Date: Tue, 8 Feb 2022 22:20:27 +0000 Subject: [PATCH 3/7] Don't fast fail --- .github/workflows/main.yml | 1 + 1 file changed, 1 insertion(+) diff --git a/.github/workflows/main.yml b/.github/workflows/main.yml index 373da67c..c402b6ec 100644 --- a/.github/workflows/main.yml +++ b/.github/workflows/main.yml @@ -13,6 +13,7 @@ jobs: name: ${{ matrix.name }} runs-on: ${{ matrix.os }} strategy: + fail-fast: false matrix: include: - name: Python 3.6 From 467a8ed23b626c6d2cbd96a3c587340ae415caa4 Mon Sep 17 00:00:00 2001 From: Thomas Robitaille Date: Tue, 8 Feb 2022 22:22:38 +0000 Subject: [PATCH 4/7] Use oldest-supported-numpy --- .github/workflows/main.yml | 2 -- setup.cfg | 2 +- 2 files changed, 1 insertion(+), 3 deletions(-) diff --git a/.github/workflows/main.yml b/.github/workflows/main.yml index c402b6ec..b8d115fd 100644 --- a/.github/workflows/main.yml +++ b/.github/workflows/main.yml @@ -48,8 +48,6 @@ jobs: ./configure make serial sudo make install - pip install -e .[test] - pytest hyperion - name: Install Hyperion Python package run: pip install -e .[test] - name: Run tests diff --git a/setup.cfg b/setup.cfg index 922cde97..18d36b6b 100644 --- a/setup.cfg +++ b/setup.cfg @@ -10,7 +10,7 @@ description = Monte-Carlo Radiative Transfer Code zip_safe = True packages = find: include_package_data = True -setup_requires = numpy>=1.11 +setup_requires = oldest-supported-numpy install_requires = numpy>=1.11 matplotlib>=1.5 From afa0875d3c8981165fee6d41490f3323f0411519 Mon Sep 17 00:00:00 2001 From: Thomas Robitaille Date: Tue, 8 Feb 2022 23:04:48 +0000 Subject: [PATCH 5/7] Fix compatibility with h5py 3.x --- hyperion/util/functions.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/hyperion/util/functions.py b/hyperion/util/functions.py index ac0bb718..7d67ece7 100644 --- a/hyperion/util/functions.py +++ b/hyperion/util/functions.py @@ -21,7 +21,7 @@ def random_id(length=32): def virtual_file(): - return h5py.File(random_id(), driver='core', backing_store=False) + return h5py.File(random_id(), driver='core', backing_store=False, mode='w') def str2bool(value): From 4170c6cc3009893e2b591e133baeb9927122aef1 Mon Sep 17 00:00:00 2001 From: Thomas Robitaille Date: Tue, 8 Feb 2022 23:20:18 +0000 Subject: [PATCH 6/7] Fix more tests --- hyperion/grid/amr_grid.py | 6 +++--- hyperion/grid/cartesian_grid.py | 6 +++--- hyperion/grid/cylindrical_polar_grid.py | 6 +++--- hyperion/grid/octree_grid.py | 6 +++--- hyperion/grid/spherical_polar_grid.py | 6 +++--- hyperion/grid/tests/test_io.py | 16 ++++++++-------- hyperion/grid/voronoi_grid.py | 6 +++--- hyperion/util/functions.py | 7 +++++++ 8 files changed, 33 insertions(+), 26 deletions(-) diff --git a/hyperion/grid/amr_grid.py b/hyperion/grid/amr_grid.py index 13742ee3..2ee8a200 100644 --- a/hyperion/grid/amr_grid.py +++ b/hyperion/grid/amr_grid.py @@ -9,7 +9,7 @@ import numpy as np from ..util.meshgrid import meshgrid_nd -from ..util.functions import FreezableClass, link_or_copy +from ..util.functions import FreezableClass, link_or_copy, as_str from astropy import log as logger from .grid_helpers import single_grid_dims @@ -245,7 +245,7 @@ def read_geometry(self, group): ''' # Check that grid is indeed AMR - if group.attrs['grid_type'].decode('utf-8') != 'amr': + if as_str(group.attrs['grid_type']) != 'amr': raise Exception("Grid is not an AMR grid") # Initialize levels list @@ -285,7 +285,7 @@ def read_geometry(self, group): grid.nz = int(g_grid.attrs['n3']) # Check that advertised hash matches real hash - if group.attrs['geometry'].decode('utf-8') != self.get_geometry_id(): + if as_str(group.attrs['geometry']) != self.get_geometry_id(): raise Exception("Calculated geometry hash does not match hash in file") def read_quantities(self, group, quantities='all'): diff --git a/hyperion/grid/cartesian_grid.py b/hyperion/grid/cartesian_grid.py index cb4c0290..52ad7492 100644 --- a/hyperion/grid/cartesian_grid.py +++ b/hyperion/grid/cartesian_grid.py @@ -8,7 +8,7 @@ from astropy import log as logger from ..util.meshgrid import meshgrid_nd -from ..util.functions import FreezableClass, is_numpy_array, monotonically_increasing, link_or_copy +from ..util.functions import FreezableClass, is_numpy_array, monotonically_increasing, link_or_copy, as_str from .grid_helpers import single_grid_dims @@ -252,7 +252,7 @@ def read_geometry(self, group): The HDF5 group to read the grid geometry from. ''' - if group.attrs['grid_type'].decode('utf-8') != 'car': + if as_str(group.attrs['grid_type']) != 'car': raise ValueError("Grid is not cartesian") self.set_walls(group['walls_1']['x'], @@ -260,7 +260,7 @@ def read_geometry(self, group): group['walls_3']['z']) # Check that advertised hash matches real hash - if group.attrs['geometry'].decode('utf-8') != self.get_geometry_id(): + if as_str(group.attrs['geometry']) != self.get_geometry_id(): raise Exception("Calculated geometry hash does not match hash in file") def read_quantities(self, group, quantities='all'): diff --git a/hyperion/grid/cylindrical_polar_grid.py b/hyperion/grid/cylindrical_polar_grid.py index c58dd490..2fc8cff5 100644 --- a/hyperion/grid/cylindrical_polar_grid.py +++ b/hyperion/grid/cylindrical_polar_grid.py @@ -7,7 +7,7 @@ import numpy as np from ..util.meshgrid import meshgrid_nd -from ..util.functions import FreezableClass, is_numpy_array, monotonically_increasing, link_or_copy +from ..util.functions import FreezableClass, is_numpy_array, monotonically_increasing, link_or_copy, as_str from astropy import log as logger from .grid_helpers import single_grid_dims @@ -280,7 +280,7 @@ def read_geometry(self, group): The HDF5 group to read the grid geometry from. ''' - if group.attrs['grid_type'].decode('utf-8') != 'cyl_pol': + if as_str(group.attrs['grid_type']) != 'cyl_pol': raise ValueError("Grid is not cylindrical polar") self.set_walls(group['walls_1']['w'], @@ -288,7 +288,7 @@ def read_geometry(self, group): group['walls_3']['p']) # Check that advertised hash matches real hash - if group.attrs['geometry'].decode('utf-8') != self.get_geometry_id(): + if as_str(group.attrs['geometry']) != self.get_geometry_id(): raise Exception("Calculated geometry hash does not match hash in file") def read_quantities(self, group, quantities='all'): diff --git a/hyperion/grid/octree_grid.py b/hyperion/grid/octree_grid.py index cae565db..651db7c2 100644 --- a/hyperion/grid/octree_grid.py +++ b/hyperion/grid/octree_grid.py @@ -7,7 +7,7 @@ import h5py import numpy as np -from ..util.functions import FreezableClass, is_numpy_array, link_or_copy +from ..util.functions import FreezableClass, is_numpy_array, link_or_copy, as_str from astropy import log as logger from .grid_helpers import single_grid_dims @@ -341,7 +341,7 @@ def read_geometry(self, group): The HDF5 group to read the grid geometry from. ''' - if group.attrs['grid_type'].decode('utf-8') != 'oct': + if as_str(group.attrs['grid_type']) != 'oct': raise ValueError("Grid is not an octree") self.set_walls(group.attrs['x'], @@ -353,7 +353,7 @@ def read_geometry(self, group): group['cells']['refined'].astype(bool)) # Check that advertised hash matches real hash - if group.attrs['geometry'].decode('utf-8') != self.get_geometry_id(): + if as_str(group.attrs['geometry']) != self.get_geometry_id(): raise Exception("Calculated geometry hash does not match hash in file") def read_quantities(self, group, quantities='all'): diff --git a/hyperion/grid/spherical_polar_grid.py b/hyperion/grid/spherical_polar_grid.py index d58f864f..5b0f67b5 100644 --- a/hyperion/grid/spherical_polar_grid.py +++ b/hyperion/grid/spherical_polar_grid.py @@ -7,7 +7,7 @@ import numpy as np from ..util.meshgrid import meshgrid_nd -from ..util.functions import FreezableClass, is_numpy_array, monotonically_increasing, link_or_copy +from ..util.functions import FreezableClass, is_numpy_array, monotonically_increasing, link_or_copy, as_str from astropy import log as logger from .grid_helpers import single_grid_dims @@ -290,7 +290,7 @@ def read_geometry(self, group): The HDF5 group to read the grid geometry from. ''' - if group.attrs['grid_type'].decode('utf-8') != 'sph_pol': + if as_str(group.attrs['grid_type']) != 'sph_pol': raise ValueError("Grid is not spherical polar") self.set_walls(group['walls_1']['r'], @@ -298,7 +298,7 @@ def read_geometry(self, group): group['walls_3']['p']) # Check that advertised hash matches real hash - if group.attrs['geometry'].decode('utf-8') != self.get_geometry_id(): + if as_str(group.attrs['geometry']) != self.get_geometry_id(): raise Exception("Calculated geometry hash does not match hash in file") def read_quantities(self, group, quantities='all'): diff --git a/hyperion/grid/tests/test_io.py b/hyperion/grid/tests/test_io.py index e8653dbf..b2b21e18 100644 --- a/hyperion/grid/tests/test_io.py +++ b/hyperion/grid/tests/test_io.py @@ -5,7 +5,7 @@ import pytest import six -from ...util.functions import random_id +from ...util.functions import virtual_file from .. import (CartesianGrid, CylindricalPolarGrid, SphericalPolarGrid, @@ -75,7 +75,7 @@ def setup_method(self, method): @pytest.mark.parametrize(('grid_type'), ALL_GRID_TYPES) def test_write_read_empty(self, grid_type): g = self.grid[grid_type] - f = h5py.File(random_id(), driver='core', backing_store=False) + f = virtual_file() g.write(f) h = self.grid_empty[grid_type]() h.read(f) @@ -85,7 +85,7 @@ def test_write_read_empty(self, grid_type): @pytest.mark.parametrize(('grid_type'), ALL_GRID_TYPES) def test_write_read_single(self, grid_type): g = self.grid[grid_type] - f = h5py.File(random_id(), driver='core', backing_store=False) + f = virtual_file() g['density'] = [] g['density'].append(self.density[grid_type]) g.write(f) @@ -101,7 +101,7 @@ def test_write_read_single(self, grid_type): @pytest.mark.parametrize(('grid_type'), ALL_GRID_TYPES) def test_write_read_double(self, grid_type): g = self.grid[grid_type] - f = h5py.File(random_id(), driver='core', backing_store=False) + f = virtual_file() g['density'] = [] g['density'].append(self.density[grid_type]) g['density'].append(self.density[grid_type]) @@ -118,7 +118,7 @@ def test_write_read_double(self, grid_type): @pytest.mark.parametrize(('grid_type'), ALL_GRID_TYPES) def test_write_read_double_multiple(self, grid_type): g = self.grid[grid_type] - f = h5py.File(random_id(), driver='core', backing_store=False) + f = virtual_file() g['density'] = [] g['density'].append(self.density[grid_type]) g['density'].append(self.density[grid_type]) @@ -140,7 +140,7 @@ def test_write_read_double_multiple(self, grid_type): @pytest.mark.parametrize(('grid_type'), ALL_GRID_TYPES) def test_write_read_type_mismatch(self, grid_type): g = self.grid[grid_type] - f = h5py.File(random_id(), driver='core', backing_store=False) + f = virtual_file() g['density'] = [] g['density'].append(self.density[grid_type]) g.write(f) @@ -162,7 +162,7 @@ def test_write_read_type_mismatch(self, grid_type): @pytest.mark.parametrize(('grid_type'), ALL_GRID_TYPES) def test_write_read_hash_mismatch(self, grid_type): g = self.grid[grid_type] - f = h5py.File(random_id(), driver='core', backing_store=False) + f = virtual_file() g['density'] = [] g['density'].append(self.density[grid_type]) g.write(f) @@ -176,7 +176,7 @@ def test_write_read_hash_mismatch(self, grid_type): @pytest.mark.parametrize(('grid_type'), ALL_GRID_TYPES) def test_write_read_groups_exist(self, grid_type): g = self.grid[grid_type] - f = h5py.File(random_id(), driver='core', backing_store=False) + f = virtual_file() f.create_group('Geometry') f.create_group('Quantities') g['density'] = [] diff --git a/hyperion/grid/voronoi_grid.py b/hyperion/grid/voronoi_grid.py index ad0d03f8..bfc4c52f 100644 --- a/hyperion/grid/voronoi_grid.py +++ b/hyperion/grid/voronoi_grid.py @@ -10,7 +10,7 @@ from astropy import log as logger from astropy.table import Table -from ..util.functions import FreezableClass, is_numpy_array, link_or_copy +from ..util.functions import FreezableClass, is_numpy_array, link_or_copy, as_str from .grid_helpers import single_grid_dims @@ -362,7 +362,7 @@ def read_geometry(self, group): The HDF5 group to read the grid geometry from. ''' - if group.attrs['grid_type'].decode('utf-8') != 'vor': + if as_str(group.attrs['grid_type']) != 'vor': raise ValueError("Grid is not an voronoi") coords = group['cells']['coordinates'] @@ -373,7 +373,7 @@ def read_geometry(self, group): zmin=group.attrs['zmin'], zmax=group.attrs['zmax']) # Check that advertised hash matches real hash - if group.attrs['geometry'].decode('utf-8') != self.get_geometry_id(): + if as_str(group.attrs['geometry']) != self.get_geometry_id(): raise Exception("Calculated geometry hash does not match hash in file") # Avoid re-computing Voronoi table diff --git a/hyperion/util/functions.py b/hyperion/util/functions.py index 7d67ece7..f0ea3340 100644 --- a/hyperion/util/functions.py +++ b/hyperion/util/functions.py @@ -32,6 +32,13 @@ def bool2str(value): return np.string_('yes'.encode('utf-8')) if value else np.string_('no'.encode('utf-8')) +def as_str(value): + if isinstance(value, bytes): + return value.decode('utf-8') + else: + return value + + def link_or_copy(group, name, link, copy, absolute_paths=False): ''' Link or copy a dataset or group From cb411ff466d861500291c49796adf5a5543398f1 Mon Sep 17 00:00:00 2001 From: Thomas Robitaille Date: Wed, 9 Feb 2022 13:46:23 +0000 Subject: [PATCH 7/7] Remove Travis configuration --- .travis.yml | 30 ------------------------------ 1 file changed, 30 deletions(-) delete mode 100644 .travis.yml diff --git a/.travis.yml b/.travis.yml deleted file mode 100644 index a8abfd45..00000000 --- a/.travis.yml +++ /dev/null @@ -1,30 +0,0 @@ -language: c - -os: - - linux - - osx - -env: - global: - - SETUP_XVFB=True - - CONDA_CHANNELS='conda-forge' - - CONDA_DEPENDENCIES='numpy astropy h5py matplotlib yt mpich hdf5 hdf5-static' - - SETUP_CMD='test' - - MPLBACKEND='Agg' - matrix: - - PYTHON_VERSION=3.6 - - PYTHON_VERSION=3.7 - -install: - - git clone git://github.com/astropy/ci-helpers.git - - source ci-helpers/travis/setup_conda.sh - - if [[ $TRAVIS_OS_NAME == linux ]]; then conda install gcc_linux-64 gxx_linux-64 gfortran_linux-64; fi - - if [[ $TRAVIS_OS_NAME == osx ]]; then conda install clang_osx-64 clangxx_osx-64 gfortran_osx-64; fi - -script: - - set -e - - ./configure - - make serial - - sudo make install - - pip install -e .[test] - - pytest hyperion