From 10b13d2223dc3acf4db4a242b598d62e5c3725c2 Mon Sep 17 00:00:00 2001 From: Edward Caunt Date: Mon, 22 Apr 2024 14:53:40 +0100 Subject: [PATCH 1/8] misc: Update cached_property to functools version --- devito/arch/archinfo.py | 2 +- devito/data/decomposition.py | 2 +- devito/finite_differences/coefficients.py | 2 +- devito/finite_differences/derivative.py | 2 +- devito/finite_differences/differentiable.py | 2 +- devito/ir/clusters/cluster.py | 2 +- devito/ir/equations/equation.py | 2 +- devito/ir/iet/efunc.py | 2 +- devito/ir/iet/nodes.py | 2 +- devito/ir/support/basic.py | 2 +- devito/ir/support/space.py | 2 +- devito/mpi/distributed.py | 2 +- devito/mpi/halo_scheme.py | 2 +- devito/operations/interpolators.py | 2 +- devito/operator/operator.py | 2 +- devito/passes/clusters/aliases.py | 2 +- devito/passes/clusters/buffering.py | 2 +- devito/passes/iet/parpragma.py | 2 +- devito/types/array.py | 2 +- devito/types/basic.py | 2 +- devito/types/dense.py | 2 +- devito/types/dimension.py | 2 +- devito/types/equation.py | 2 +- devito/types/grid.py | 2 +- devito/types/lazy.py | 2 +- devito/types/parallel.py | 2 +- devito/types/sparse.py | 2 +- devito/types/tensor.py | 2 +- examples/seismic/source.py | 2 +- requirements.txt | 1 - tests/test_dse.py | 2 +- tests/test_mpi.py | 2 +- 32 files changed, 31 insertions(+), 32 deletions(-) diff --git a/devito/arch/archinfo.py b/devito/arch/archinfo.py index fe0a15c3e0..562a5dc6de 100644 --- a/devito/arch/archinfo.py +++ b/devito/arch/archinfo.py @@ -2,7 +2,7 @@ from subprocess import PIPE, Popen, DEVNULL, run -from cached_property import cached_property +from functools import cached_property import cpuinfo import ctypes import numpy as np diff --git a/devito/data/decomposition.py b/devito/data/decomposition.py index 532e03e3c6..ecbe5ac6ae 100644 --- a/devito/data/decomposition.py +++ b/devito/data/decomposition.py @@ -1,7 +1,7 @@ from collections.abc import Iterable import numpy as np -from cached_property import cached_property +from functools import cached_property from devito.data.meta import LEFT from devito.tools import is_integer, as_tuple diff --git a/devito/finite_differences/coefficients.py b/devito/finite_differences/coefficients.py index 5ad167b8d5..1f5865a24c 100644 --- a/devito/finite_differences/coefficients.py +++ b/devito/finite_differences/coefficients.py @@ -1,5 +1,5 @@ import numpy as np -from cached_property import cached_property +from functools import cached_property from devito.finite_differences import Weights, generate_indices from devito.finite_differences.tools import numeric_weights diff --git a/devito/finite_differences/derivative.py b/devito/finite_differences/derivative.py index a32acce34c..e813d2dcc7 100644 --- a/devito/finite_differences/derivative.py +++ b/devito/finite_differences/derivative.py @@ -1,7 +1,7 @@ from collections import OrderedDict from collections.abc import Iterable -from cached_property import cached_property +from functools import cached_property import sympy from .finite_difference import generic_derivative, first_derivative, cross_derivative diff --git a/devito/finite_differences/differentiable.py b/devito/finite_differences/differentiable.py index c9264ddb41..56a3a1fb9a 100644 --- a/devito/finite_differences/differentiable.py +++ b/devito/finite_differences/differentiable.py @@ -2,7 +2,7 @@ from itertools import product from functools import singledispatch -from cached_property import cached_property +from functools import cached_property import numpy as np import sympy from sympy.core.add import _addsort diff --git a/devito/ir/clusters/cluster.py b/devito/ir/clusters/cluster.py index 2e3699fe5e..ca9277d454 100644 --- a/devito/ir/clusters/cluster.py +++ b/devito/ir/clusters/cluster.py @@ -1,7 +1,7 @@ from itertools import chain import numpy as np -from cached_property import cached_property +from functools import cached_property from devito.ir.equations import ClusterizedEq from devito.ir.support import (PARALLEL, PARALLEL_IF_PVT, BaseGuardBoundNext, diff --git a/devito/ir/equations/equation.py b/devito/ir/equations/equation.py index e1e487df46..2575a19baf 100644 --- a/devito/ir/equations/equation.py +++ b/devito/ir/equations/equation.py @@ -1,4 +1,4 @@ -from cached_property import cached_property +from functools import cached_property import sympy from devito.ir.equations.algorithms import dimension_sort, lower_exprs diff --git a/devito/ir/iet/efunc.py b/devito/ir/iet/efunc.py index a8450bc4aa..67f58c8d2e 100644 --- a/devito/ir/iet/efunc.py +++ b/devito/ir/iet/efunc.py @@ -1,4 +1,4 @@ -from cached_property import cached_property +from functools import cached_property from devito.ir.iet.nodes import Call, Callable from devito.ir.iet.utils import derive_parameters diff --git a/devito/ir/iet/nodes.py b/devito/ir/iet/nodes.py index 305f5291f2..4f1d2727be 100644 --- a/devito/ir/iet/nodes.py +++ b/devito/ir/iet/nodes.py @@ -2,7 +2,7 @@ import abc import inspect -from cached_property import cached_property +from functools import cached_property from collections import OrderedDict, namedtuple from collections.abc import Iterable diff --git a/devito/ir/support/basic.py b/devito/ir/support/basic.py index 30a0923fb0..0b87ffd30f 100644 --- a/devito/ir/support/basic.py +++ b/devito/ir/support/basic.py @@ -1,6 +1,6 @@ from itertools import chain, product -from cached_property import cached_property +from functools import cached_property from sympy import S from devito.ir.support.space import Backward, null_ispace diff --git a/devito/ir/support/space.py b/devito/ir/support/space.py index c1170839b8..1f2e3e95d2 100644 --- a/devito/ir/support/space.py +++ b/devito/ir/support/space.py @@ -3,7 +3,7 @@ from functools import reduce from operator import mul -from cached_property import cached_property +from functools import cached_property from sympy import Expr from devito.ir.support.utils import minimum, maximum diff --git a/devito/mpi/distributed.py b/devito/mpi/distributed.py index b1b0d6de1a..556b34f301 100644 --- a/devito/mpi/distributed.py +++ b/devito/mpi/distributed.py @@ -6,7 +6,7 @@ import atexit -from cached_property import cached_property +from functools import cached_property import numpy as np from cgen import Struct, Value diff --git a/devito/mpi/halo_scheme.py b/devito/mpi/halo_scheme.py index b8b689296f..ac69855c62 100644 --- a/devito/mpi/halo_scheme.py +++ b/devito/mpi/halo_scheme.py @@ -2,7 +2,7 @@ from itertools import product from operator import attrgetter -from cached_property import cached_property +from functools import cached_property from sympy import Max, Min import sympy diff --git a/devito/operations/interpolators.py b/devito/operations/interpolators.py index 8983b3acef..bc74094b6d 100644 --- a/devito/operations/interpolators.py +++ b/devito/operations/interpolators.py @@ -3,7 +3,7 @@ import sympy import numpy as np -from cached_property import cached_property +from functools import cached_property try: from scipy.special import i0 diff --git a/devito/operator/operator.py b/devito/operator/operator.py index 462e5b335b..ed13ac419d 100644 --- a/devito/operator/operator.py +++ b/devito/operator/operator.py @@ -3,7 +3,7 @@ from operator import attrgetter from math import ceil -from cached_property import cached_property +from functools import cached_property from sympy import sympify from devito.arch import compiler_registry, platform_registry diff --git a/devito/passes/clusters/aliases.py b/devito/passes/clusters/aliases.py index 7814ecd67f..40d4bd2e34 100644 --- a/devito/passes/clusters/aliases.py +++ b/devito/passes/clusters/aliases.py @@ -2,7 +2,7 @@ from functools import singledispatch from itertools import groupby -from cached_property import cached_property +from functools import cached_property import numpy as np import sympy diff --git a/devito/passes/clusters/buffering.py b/devito/passes/clusters/buffering.py index 48a7b27b31..3582a218f8 100644 --- a/devito/passes/clusters/buffering.py +++ b/devito/passes/clusters/buffering.py @@ -1,7 +1,7 @@ from collections import OrderedDict, defaultdict, namedtuple from itertools import combinations -from cached_property import cached_property +from functools import cached_property import numpy as np from devito.ir import (Cluster, Forward, GuardBound, Interval, IntervalGroup, diff --git a/devito/passes/iet/parpragma.py b/devito/passes/iet/parpragma.py index cc5d5dd5f9..b3c8332b0b 100644 --- a/devito/passes/iet/parpragma.py +++ b/devito/passes/iet/parpragma.py @@ -2,7 +2,7 @@ import numpy as np import cgen as c -from cached_property import cached_property +from functools import cached_property from sympy import And, Max, true from devito.data import FULL diff --git a/devito/types/array.py b/devito/types/array.py index 0cfc754bd6..def7653ba7 100644 --- a/devito/types/array.py +++ b/devito/types/array.py @@ -1,7 +1,7 @@ from ctypes import POINTER, Structure, c_void_p, c_ulong import numpy as np -from cached_property import cached_property +from functools import cached_property from sympy import Expr from devito.tools import (Reconstructable, as_tuple, c_restrict_void_p, diff --git a/devito/types/basic.py b/devito/types/basic.py index 9bb9334c4a..5b15020dff 100644 --- a/devito/types/basic.py +++ b/devito/types/basic.py @@ -9,7 +9,7 @@ from sympy.core.assumptions import _assume_rules from sympy.core.decorators import call_highest_priority -from cached_property import cached_property +from functools import cached_property from devito.data import default_allocator from devito.parameters import configuration diff --git a/devito/types/dense.py b/devito/types/dense.py index 74baeab3d0..69ab530905 100644 --- a/devito/types/dense.py +++ b/devito/types/dense.py @@ -6,7 +6,7 @@ import numpy as np import sympy from psutil import virtual_memory -from cached_property import cached_property +from functools import cached_property from devito.builtins import assign from devito.data import (DOMAIN, OWNED, HALO, NOPAD, FULL, LEFT, CENTER, RIGHT, diff --git a/devito/types/dimension.py b/devito/types/dimension.py index cf0749e777..25703b3b88 100644 --- a/devito/types/dimension.py +++ b/devito/types/dimension.py @@ -4,7 +4,7 @@ import sympy from sympy.core.decorators import call_highest_priority import numpy as np -from cached_property import cached_property +from functools import cached_property from devito.data import LEFT, RIGHT from devito.exceptions import InvalidArgument diff --git a/devito/types/equation.py b/devito/types/equation.py index eb786b632c..c4af3385c3 100644 --- a/devito/types/equation.py +++ b/devito/types/equation.py @@ -2,7 +2,7 @@ import sympy -from cached_property import cached_property +from functools import cached_property from devito.finite_differences import default_rules from devito.tools import as_tuple diff --git a/devito/types/grid.py b/devito/types/grid.py index 7bc3492ef1..e82d126aef 100644 --- a/devito/types/grid.py +++ b/devito/types/grid.py @@ -4,7 +4,7 @@ import numpy as np from sympy import prod -from cached_property import cached_property +from functools import cached_property from devito.data import LEFT, RIGHT from devito.logger import warning diff --git a/devito/types/lazy.py b/devito/types/lazy.py index e96a081ecf..f4279327d9 100644 --- a/devito/types/lazy.py +++ b/devito/types/lazy.py @@ -1,4 +1,4 @@ -from cached_property import cached_property +from functools import cached_property from devito.tools import Reconstructable diff --git a/devito/types/parallel.py b/devito/types/parallel.py index 0b7c3f9271..a76051530c 100644 --- a/devito/types/parallel.py +++ b/devito/types/parallel.py @@ -9,7 +9,7 @@ import os from ctypes import POINTER, c_void_p -from cached_property import cached_property +from functools import cached_property import numpy as np from devito.exceptions import InvalidArgument diff --git a/devito/types/sparse.py b/devito/types/sparse.py index dfc193e72c..094ec7dd98 100644 --- a/devito/types/sparse.py +++ b/devito/types/sparse.py @@ -8,7 +8,7 @@ import sympy import numpy as np -from cached_property import cached_property +from functools import cached_property from devito.finite_differences import generate_fd_shortcuts from devito.mpi import MPI, SparseDistributor diff --git a/devito/types/tensor.py b/devito/types/tensor.py index 0ca08b44b1..ae69ba8899 100644 --- a/devito/types/tensor.py +++ b/devito/types/tensor.py @@ -1,5 +1,5 @@ from collections import OrderedDict -from cached_property import cached_property +from functools import cached_property import numpy as np from sympy.core.sympify import converter as sympify_converter diff --git a/examples/seismic/source.py b/examples/seismic/source.py index a736c5bb4f..578c950ab3 100644 --- a/examples/seismic/source.py +++ b/examples/seismic/source.py @@ -1,5 +1,5 @@ from scipy import interpolate -from cached_property import cached_property +from functools import cached_property import numpy as np try: import matplotlib.pyplot as plt diff --git a/requirements.txt b/requirements.txt index 3f780bd6aa..61a9636de7 100644 --- a/requirements.txt +++ b/requirements.txt @@ -1,7 +1,6 @@ pip>=9.0.1 numpy>1.16 sympy>=1.9,<1.13 -cached-property psutil>=5.1.0,<6.0 py-cpuinfo<10 cgen>=2020.1 diff --git a/tests/test_dse.py b/tests/test_dse.py index eaab3dcee6..db9f9fb2e4 100644 --- a/tests/test_dse.py +++ b/tests/test_dse.py @@ -1,6 +1,6 @@ import numpy as np import pytest -from cached_property import cached_property +from functools import cached_property from sympy import Mul # noqa from sympy.core.mul import _mulsort diff --git a/tests/test_mpi.py b/tests/test_mpi.py index 4096fb9c46..4602810292 100644 --- a/tests/test_mpi.py +++ b/tests/test_mpi.py @@ -1,6 +1,6 @@ import numpy as np import pytest -from cached_property import cached_property +from functools import cached_property from conftest import _R, assert_blocking, assert_structure from devito import (Grid, Constant, Function, TimeFunction, SparseFunction, From 31fe870e5410c00b7609775cfed0c310e500f50b Mon Sep 17 00:00:00 2001 From: Edward Caunt Date: Mon, 22 Apr 2024 16:02:10 +0100 Subject: [PATCH 2/8] misc: Remove renaming/aliasing of cached_properties --- devito/types/dense.py | 37 ++++++++++++++++++++++++++++++++++--- 1 file changed, 34 insertions(+), 3 deletions(-) diff --git a/devito/types/dense.py b/devito/types/dense.py index 69ab530905..310fb9c5bc 100644 --- a/devito/types/dense.py +++ b/devito/types/dense.py @@ -30,6 +30,7 @@ RegionMeta = namedtuple('RegionMeta', 'offset size') +Offset = namedtuple('Offset', 'left right') class DiscreteFunction(AbstractFunction, ArgProvider, Differentiable): @@ -242,8 +243,21 @@ def shape_with_halo(self): on the rank position in the decomposed grid (corner, side, ...). """ return tuple(j + i + k for i, (j, k) in zip(self.shape, self._size_outhalo)) + + @cached_property + def _shape_with_outhalo(self): + """ + Shape of the domain+outhalo region. The outhalo is the region + surrounding the domain that may be read by an Operator. - _shape_with_outhalo = shape_with_halo + Notes + ----- + In an MPI context, this is the *local* with_halo region shape. + Further, note that the outhalo of inner ranks is typically empty, while + the outhalo of boundary ranks contains a number of elements depending + on the rank position in the decomposed grid (corner, side, ...). + """ + return tuple(j + i + k for i, (j, k) in zip(self.shape, self._size_outhalo)) @cached_property def _shape_with_inhalo(self): @@ -310,8 +324,25 @@ def size_global(self): """ return reduce(mul, self.shape_global) - _offset_inhalo = AbstractFunction._offset_halo - _size_inhalo = AbstractFunction._size_halo + @cached_property + def _offset_inhalo(self): + """Number of points before the first and last halo elements.""" + left = tuple(self._size_padding.left) + right = tuple(np.add(np.add(left, self._size_halo.left), self._size_domain)) + + offsets = tuple(Offset(i, j) for i, j in zip(left, right)) + + return DimensionTuple(*offsets, getters=self.dimensions, left=left, right=right) + + @cached_property + def _size_inhalo(self): + """Number of points in the halo region.""" + left = tuple(zip(*self._halo))[0] + right = tuple(zip(*self._halo))[1] + + sizes = tuple(Size(i, j) for i, j in self._halo) + + return DimensionTuple(*sizes, getters=self.dimensions, left=left, right=right) @cached_property def _size_outhalo(self): From 8686de3573965a63f1a12a31f001ed37fbbaa4f9 Mon Sep 17 00:00:00 2001 From: Edward Caunt Date: Mon, 22 Apr 2024 16:17:43 +0100 Subject: [PATCH 3/8] misc: Flake8 --- devito/types/dense.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/devito/types/dense.py b/devito/types/dense.py index 310fb9c5bc..613a3d58aa 100644 --- a/devito/types/dense.py +++ b/devito/types/dense.py @@ -243,7 +243,7 @@ def shape_with_halo(self): on the rank position in the decomposed grid (corner, side, ...). """ return tuple(j + i + k for i, (j, k) in zip(self.shape, self._size_outhalo)) - + @cached_property def _shape_with_outhalo(self): """ From a53b10eaa326e3c396d297d26b6a674ed15e16d1 Mon Sep 17 00:00:00 2001 From: Edward Caunt Date: Mon, 22 Apr 2024 16:40:47 +0100 Subject: [PATCH 4/8] reqs: Drop Python 3.7 as end-of-life --- .github/workflows/pytest-core-nompi.yml | 15 ++++-- devito/tools/utils.py | 72 +++++++++---------------- setup.py | 3 +- versioneer.py | 2 +- 4 files changed, 39 insertions(+), 53 deletions(-) diff --git a/.github/workflows/pytest-core-nompi.yml b/.github/workflows/pytest-core-nompi.yml index 38959f4a8c..6abd78008b 100644 --- a/.github/workflows/pytest-core-nompi.yml +++ b/.github/workflows/pytest-core-nompi.yml @@ -32,11 +32,15 @@ jobs: name: [ pytest-ubuntu-py311-gcc11-noomp, pytest-ubuntu-py38-gcc12-omp, - pytest-ubuntu-py37-gcc7-omp, + pytest-ubuntu-py38-gcc7-omp, pytest-ubuntu-py310-gcc10-noomp, pytest-ubuntu-py312-gcc13-omp, pytest-ubuntu-py39-gcc9-omp, +<<<<<<< HEAD pytest-osx-py312-clang-omp, +======= + pytest-osx-py38-clang-omp, +>>>>>>> 84f366ba7 (reqs: Drop Python 3.7 as end-of-life) pytest-docker-py39-gcc-omp, pytest-docker-py39-icx-omp ] @@ -56,8 +60,8 @@ jobs: language: "openmp" sympy: "1.10" - - name: pytest-ubuntu-py37-gcc7-omp - python-version: '3.7' + - name: pytest-ubuntu-py38-gcc7-omp + python-version: '3.8' os: ubuntu-20.04 arch: "gcc-7" language: "openmp" @@ -84,8 +88,13 @@ jobs: language: "openmp" sympy: "1.9" +<<<<<<< HEAD - name: pytest-osx-py312-clang-omp python-version: '3.12' +======= + - name: pytest-osx-py38-clang-omp + python-version: '3.8' +>>>>>>> 84f366ba7 (reqs: Drop Python 3.7 as end-of-life) os: macos-latest arch: "clang" language: "C" diff --git a/devito/tools/utils.py b/devito/tools/utils.py index e89a1aaa4e..57fc1573b7 100644 --- a/devito/tools/utils.py +++ b/devito/tools/utils.py @@ -3,7 +3,6 @@ from functools import reduce from itertools import chain, combinations, groupby, product, zip_longest from operator import attrgetter, mul -import sys import types import numpy as np @@ -16,11 +15,6 @@ 'humanbytes', 'contains_val', 'sorted_priority'] -# Some utils run faster with Python>=3.7 -vi = sys.version_info -py_ge_37 = (vi.major, vi.minor) >= (3, 7) - - def prod(iterable, initial=1): return reduce(mul, iterable, initial) @@ -163,49 +157,33 @@ def single_or(l): return any(i) and not any(i) -if py_ge_37: - def filter_ordered(elements, key=None): - # This method exploits the fact that dictionary keys are unique and ordered - # (since Python 3.7). It's concise and often faster for larger lists +def filter_ordered(elements, key=None): + """ + Filter elements in a list while preserving order. - if isinstance(elements, types.GeneratorType): - elements = list(elements) + Parameters + ---------- + key : callable, optional + Conversion key used during equality comparison. + """ + if isinstance(elements, types.GeneratorType): + elements = list(elements) - if key is None: - return list(dict.fromkeys(elements)) - else: - return list(dict(zip([key(i) for i in elements], elements)).values()) - -else: - def filter_ordered(elements, key=None): - if isinstance(elements, types.GeneratorType): - elements = list(elements) - - seen = set() - if key is None: - try: - unordered, inds = np.unique(elements, return_index=True) - return unordered[np.argsort(inds)].tolist() - except: - return sorted(list(set(elements)), key=elements.index) - else: - ret = [] - for e in elements: - k = key(e) - if k not in seen: - ret.append(e) - seen.add(k) - return ret - - -filter_ordered.__doc__ = """\ -Filter elements in a list while preserving order. - -Parameters ----------- -key : callable, optional - Conversion key used during equality comparison. -""" + seen = set() + if key is None: + try: + unordered, inds = np.unique(elements, return_index=True) + return unordered[np.argsort(inds)].tolist() + except: + return sorted(list(set(elements)), key=elements.index) + else: + ret = [] + for e in elements: + k = key(e) + if k not in seen: + ret.append(e) + seen.add(k) + return ret def filter_sorted(elements, key=None): diff --git a/setup.py b/setup.py index 85f165c78c..5d22060ba0 100644 --- a/setup.py +++ b/setup.py @@ -70,7 +70,7 @@ }, url='http://www.devitoproject.org', platforms=["Linux", "Mac OS-X", "Unix"], - python_requires=">=3.7", + python_requires=">=3.8", classifiers=[ 'Development Status :: 5 - Production/Stable', 'Intended Audience :: Developers', @@ -82,7 +82,6 @@ 'Operating System :: Unix', 'Programming Language :: Python', 'Programming Language :: Python :: 3', - 'Programming Language :: Python :: 3.7', 'Programming Language :: Python :: 3.8', 'Programming Language :: Python :: 3.9', 'Programming Language :: Python :: 3.10', diff --git a/versioneer.py b/versioneer.py index 1e3753e63f..c44e729860 100644 --- a/versioneer.py +++ b/versioneer.py @@ -10,7 +10,7 @@ * https://github.com/python-versioneer/python-versioneer * Brian Warner * License: Public Domain (Unlicense) -* Compatible with: Python 3.7, 3.8, 3.9, 3.10, 3.11 and pypy3 +* Compatible with: Python 3.8, 3.9, 3.10, 3.11, 3.12 and pypy3 * [![Latest Version][pypi-image]][pypi-url] * [![Build Status][travis-image]][travis-url] From aa79aabef510681d7573cc848f8ff2b00a0ef2d0 Mon Sep 17 00:00:00 2001 From: Edward Caunt Date: Tue, 23 Apr 2024 10:34:05 +0100 Subject: [PATCH 5/8] misc: Fix order of imports for style --- devito/data/decomposition.py | 2 +- devito/finite_differences/coefficients.py | 3 ++- devito/finite_differences/derivative.py | 2 +- devito/finite_differences/differentiable.py | 3 +-- devito/ir/clusters/cluster.py | 2 +- devito/ir/equations/equation.py | 1 + devito/ir/support/basic.py | 2 +- devito/ir/support/space.py | 3 +-- devito/mpi/distributed.py | 3 ++- devito/mpi/halo_scheme.py | 2 +- devito/operations/interpolators.py | 3 +-- devito/operator/operator.py | 2 +- devito/passes/clusters/aliases.py | 3 +-- devito/passes/clusters/buffering.py | 2 +- devito/passes/iet/parpragma.py | 2 +- devito/types/array.py | 2 +- devito/types/basic.py | 3 +-- devito/types/dimension.py | 2 +- devito/types/grid.py | 2 +- devito/types/parallel.py | 2 +- examples/seismic/source.py | 2 +- tests/test_dse.py | 3 ++- 22 files changed, 25 insertions(+), 26 deletions(-) diff --git a/devito/data/decomposition.py b/devito/data/decomposition.py index ecbe5ac6ae..7fad455d33 100644 --- a/devito/data/decomposition.py +++ b/devito/data/decomposition.py @@ -1,7 +1,7 @@ from collections.abc import Iterable +from functools import cached_property import numpy as np -from functools import cached_property from devito.data.meta import LEFT from devito.tools import is_integer, as_tuple diff --git a/devito/finite_differences/coefficients.py b/devito/finite_differences/coefficients.py index 1f5865a24c..0d7b7213a1 100644 --- a/devito/finite_differences/coefficients.py +++ b/devito/finite_differences/coefficients.py @@ -1,6 +1,7 @@ -import numpy as np from functools import cached_property +import numpy as np + from devito.finite_differences import Weights, generate_indices from devito.finite_differences.tools import numeric_weights from devito.tools import filter_ordered, as_tuple diff --git a/devito/finite_differences/derivative.py b/devito/finite_differences/derivative.py index e813d2dcc7..c65d06790d 100644 --- a/devito/finite_differences/derivative.py +++ b/devito/finite_differences/derivative.py @@ -1,7 +1,7 @@ from collections import OrderedDict from collections.abc import Iterable - from functools import cached_property + import sympy from .finite_difference import generic_derivative, first_derivative, cross_derivative diff --git a/devito/finite_differences/differentiable.py b/devito/finite_differences/differentiable.py index 56a3a1fb9a..9eabef12d1 100644 --- a/devito/finite_differences/differentiable.py +++ b/devito/finite_differences/differentiable.py @@ -1,8 +1,7 @@ from collections import ChainMap from itertools import product -from functools import singledispatch +from functools import singledispatch, cached_property -from functools import cached_property import numpy as np import sympy from sympy.core.add import _addsort diff --git a/devito/ir/clusters/cluster.py b/devito/ir/clusters/cluster.py index ca9277d454..2964ce25f8 100644 --- a/devito/ir/clusters/cluster.py +++ b/devito/ir/clusters/cluster.py @@ -1,7 +1,7 @@ from itertools import chain +from functools import cached_property import numpy as np -from functools import cached_property from devito.ir.equations import ClusterizedEq from devito.ir.support import (PARALLEL, PARALLEL_IF_PVT, BaseGuardBoundNext, diff --git a/devito/ir/equations/equation.py b/devito/ir/equations/equation.py index 2575a19baf..8e478fe1d7 100644 --- a/devito/ir/equations/equation.py +++ b/devito/ir/equations/equation.py @@ -1,4 +1,5 @@ from functools import cached_property + import sympy from devito.ir.equations.algorithms import dimension_sort, lower_exprs diff --git a/devito/ir/support/basic.py b/devito/ir/support/basic.py index 0b87ffd30f..8aedf970d9 100644 --- a/devito/ir/support/basic.py +++ b/devito/ir/support/basic.py @@ -1,6 +1,6 @@ from itertools import chain, product - from functools import cached_property + from sympy import S from devito.ir.support.space import Backward, null_ispace diff --git a/devito/ir/support/space.py b/devito/ir/support/space.py index 1f2e3e95d2..2c773e08a5 100644 --- a/devito/ir/support/space.py +++ b/devito/ir/support/space.py @@ -1,9 +1,8 @@ import abc from collections import OrderedDict -from functools import reduce +from functools import reduce, cached_property from operator import mul -from functools import cached_property from sympy import Expr from devito.ir.support.utils import minimum, maximum diff --git a/devito/mpi/distributed.py b/devito/mpi/distributed.py index 556b34f301..6baf924dae 100644 --- a/devito/mpi/distributed.py +++ b/devito/mpi/distributed.py @@ -1,12 +1,13 @@ from abc import ABC, abstractmethod from ctypes import c_int, c_void_p, sizeof from itertools import groupby, product +from functools import cached_property + from math import ceil, pow from sympy import factorint import atexit -from functools import cached_property import numpy as np from cgen import Struct, Value diff --git a/devito/mpi/halo_scheme.py b/devito/mpi/halo_scheme.py index ac69855c62..745024a35d 100644 --- a/devito/mpi/halo_scheme.py +++ b/devito/mpi/halo_scheme.py @@ -1,8 +1,8 @@ from collections import OrderedDict, namedtuple, defaultdict from itertools import product from operator import attrgetter - from functools import cached_property + from sympy import Max, Min import sympy diff --git a/devito/operations/interpolators.py b/devito/operations/interpolators.py index bc74094b6d..52501c54c4 100644 --- a/devito/operations/interpolators.py +++ b/devito/operations/interpolators.py @@ -1,9 +1,8 @@ from abc import ABC, abstractmethod -from functools import wraps +from functools import wraps, cached_property import sympy import numpy as np -from functools import cached_property try: from scipy.special import i0 diff --git a/devito/operator/operator.py b/devito/operator/operator.py index ed13ac419d..3b3290f621 100644 --- a/devito/operator/operator.py +++ b/devito/operator/operator.py @@ -1,9 +1,9 @@ from collections import OrderedDict, namedtuple +from functools import cached_property import ctypes from operator import attrgetter from math import ceil -from functools import cached_property from sympy import sympify from devito.arch import compiler_registry, platform_registry diff --git a/devito/passes/clusters/aliases.py b/devito/passes/clusters/aliases.py index 40d4bd2e34..0b4c7dd782 100644 --- a/devito/passes/clusters/aliases.py +++ b/devito/passes/clusters/aliases.py @@ -1,8 +1,7 @@ from collections import Counter, OrderedDict, defaultdict, namedtuple -from functools import singledispatch +from functools import singledispatch, cached_property from itertools import groupby -from functools import cached_property import numpy as np import sympy diff --git a/devito/passes/clusters/buffering.py b/devito/passes/clusters/buffering.py index 3582a218f8..aff349ea1a 100644 --- a/devito/passes/clusters/buffering.py +++ b/devito/passes/clusters/buffering.py @@ -1,7 +1,7 @@ from collections import OrderedDict, defaultdict, namedtuple from itertools import combinations - from functools import cached_property + import numpy as np from devito.ir import (Cluster, Forward, GuardBound, Interval, IntervalGroup, diff --git a/devito/passes/iet/parpragma.py b/devito/passes/iet/parpragma.py index b3c8332b0b..195069d8e7 100644 --- a/devito/passes/iet/parpragma.py +++ b/devito/passes/iet/parpragma.py @@ -1,8 +1,8 @@ from collections import defaultdict +from functools import cached_property import numpy as np import cgen as c -from functools import cached_property from sympy import And, Max, true from devito.data import FULL diff --git a/devito/types/array.py b/devito/types/array.py index def7653ba7..82ef432d65 100644 --- a/devito/types/array.py +++ b/devito/types/array.py @@ -1,7 +1,7 @@ from ctypes import POINTER, Structure, c_void_p, c_ulong +from functools import cached_property import numpy as np -from functools import cached_property from sympy import Expr from devito.tools import (Reconstructable, as_tuple, c_restrict_void_p, diff --git a/devito/types/basic.py b/devito/types/basic.py index 5b15020dff..5ca2be984d 100644 --- a/devito/types/basic.py +++ b/devito/types/basic.py @@ -1,7 +1,7 @@ import abc from collections import namedtuple from ctypes import POINTER, _Pointer, c_char_p, c_char -from functools import reduce +from functools import reduce, cached_property from operator import mul import numpy as np @@ -9,7 +9,6 @@ from sympy.core.assumptions import _assume_rules from sympy.core.decorators import call_highest_priority -from functools import cached_property from devito.data import default_allocator from devito.parameters import configuration diff --git a/devito/types/dimension.py b/devito/types/dimension.py index 25703b3b88..df412db0d6 100644 --- a/devito/types/dimension.py +++ b/devito/types/dimension.py @@ -1,10 +1,10 @@ from collections import namedtuple +from functools import cached_property import math import sympy from sympy.core.decorators import call_highest_priority import numpy as np -from functools import cached_property from devito.data import LEFT, RIGHT from devito.exceptions import InvalidArgument diff --git a/devito/types/grid.py b/devito/types/grid.py index e82d126aef..8dbc4767ef 100644 --- a/devito/types/grid.py +++ b/devito/types/grid.py @@ -1,10 +1,10 @@ from abc import ABC from collections import namedtuple +from functools import cached_property from math import floor import numpy as np from sympy import prod -from functools import cached_property from devito.data import LEFT, RIGHT from devito.logger import warning diff --git a/devito/types/parallel.py b/devito/types/parallel.py index a76051530c..fe195e9c06 100644 --- a/devito/types/parallel.py +++ b/devito/types/parallel.py @@ -8,8 +8,8 @@ import os from ctypes import POINTER, c_void_p - from functools import cached_property + import numpy as np from devito.exceptions import InvalidArgument diff --git a/examples/seismic/source.py b/examples/seismic/source.py index 578c950ab3..94297296e1 100644 --- a/examples/seismic/source.py +++ b/examples/seismic/source.py @@ -1,5 +1,5 @@ -from scipy import interpolate from functools import cached_property +from scipy import interpolate import numpy as np try: import matplotlib.pyplot as plt diff --git a/tests/test_dse.py b/tests/test_dse.py index db9f9fb2e4..0f0fcff31a 100644 --- a/tests/test_dse.py +++ b/tests/test_dse.py @@ -1,6 +1,7 @@ +from functools import cached_property + import numpy as np import pytest -from functools import cached_property from sympy import Mul # noqa from sympy.core.mul import _mulsort From 8ac080b7ef5569b1c7d24611386276fc4359fb41 Mon Sep 17 00:00:00 2001 From: Edward Caunt Date: Tue, 23 Apr 2024 11:00:04 +0100 Subject: [PATCH 6/8] misc: Reduce duplication --- devito/types/dense.py | 37 +++++++++++++++---------------------- 1 file changed, 15 insertions(+), 22 deletions(-) diff --git a/devito/types/dense.py b/devito/types/dense.py index 613a3d58aa..bf8c6efe9b 100644 --- a/devito/types/dense.py +++ b/devito/types/dense.py @@ -231,34 +231,27 @@ def shape_domain(self): @cached_property def shape_with_halo(self): - """ - Shape of the domain+outhalo region. The outhalo is the region - surrounding the domain that may be read by an Operator. - - Notes - ----- - In an MPI context, this is the *local* with_halo region shape. - Further, note that the outhalo of inner ranks is typically empty, while - the outhalo of boundary ranks contains a number of elements depending - on the rank position in the decomposed grid (corner, side, ...). - """ return tuple(j + i + k for i, (j, k) in zip(self.shape, self._size_outhalo)) @cached_property def _shape_with_outhalo(self): - """ - Shape of the domain+outhalo region. The outhalo is the region - surrounding the domain that may be read by an Operator. - - Notes - ----- - In an MPI context, this is the *local* with_halo region shape. - Further, note that the outhalo of inner ranks is typically empty, while - the outhalo of boundary ranks contains a number of elements depending - on the rank position in the decomposed grid (corner, side, ...). - """ return tuple(j + i + k for i, (j, k) in zip(self.shape, self._size_outhalo)) + _shape_with_halo_docstring = """\ + Shape of the domain+outhalo region. The outhalo is the region + surrounding the domain that may be read by an Operator. + + Notes + ----- + In an MPI context, this is the *local* with_halo region shape. + Further, note that the outhalo of inner ranks is typically empty, while + the outhalo of boundary ranks contains a number of elements depending + on the rank position in the decomposed grid (corner, side, ...). + """ + + shape_with_halo.__doc__ = _shape_with_halo_docstring + _shape_with_outhalo.__doc__ = _shape_with_halo_docstring + @cached_property def _shape_with_inhalo(self): """ From e7561b48826e3ee89ecec9a2c24f45fbe1e0e732 Mon Sep 17 00:00:00 2001 From: Edward Caunt Date: Tue, 30 Apr 2024 15:47:06 +0100 Subject: [PATCH 7/8] misc: Tidy rebase leftovers --- .github/workflows/pytest-core-nompi.yml | 9 --------- 1 file changed, 9 deletions(-) diff --git a/.github/workflows/pytest-core-nompi.yml b/.github/workflows/pytest-core-nompi.yml index 6abd78008b..553fbccb15 100644 --- a/.github/workflows/pytest-core-nompi.yml +++ b/.github/workflows/pytest-core-nompi.yml @@ -36,11 +36,7 @@ jobs: pytest-ubuntu-py310-gcc10-noomp, pytest-ubuntu-py312-gcc13-omp, pytest-ubuntu-py39-gcc9-omp, -<<<<<<< HEAD pytest-osx-py312-clang-omp, -======= - pytest-osx-py38-clang-omp, ->>>>>>> 84f366ba7 (reqs: Drop Python 3.7 as end-of-life) pytest-docker-py39-gcc-omp, pytest-docker-py39-icx-omp ] @@ -88,13 +84,8 @@ jobs: language: "openmp" sympy: "1.9" -<<<<<<< HEAD - name: pytest-osx-py312-clang-omp python-version: '3.12' -======= - - name: pytest-osx-py38-clang-omp - python-version: '3.8' ->>>>>>> 84f366ba7 (reqs: Drop Python 3.7 as end-of-life) os: macos-latest arch: "clang" language: "C" From c3d8356b63692ade27e289a4cd1c2330ef4e8577 Mon Sep 17 00:00:00 2001 From: mloubout Date: Tue, 21 May 2024 00:36:26 -0400 Subject: [PATCH 8/8] api: avoid duplicate properties --- devito/types/dense.py | 52 +++++++++++++++---------------------------- 1 file changed, 18 insertions(+), 34 deletions(-) diff --git a/devito/types/dense.py b/devito/types/dense.py index bf8c6efe9b..0a5385b7a5 100644 --- a/devito/types/dense.py +++ b/devito/types/dense.py @@ -204,6 +204,10 @@ def coefficients(self): """Form of the coefficients of the function.""" return self._coefficients + @property + def _shape_with_outhalo(self): + return self.shape_with_halo + @cached_property def shape(self): """ @@ -231,27 +235,19 @@ def shape_domain(self): @cached_property def shape_with_halo(self): - return tuple(j + i + k for i, (j, k) in zip(self.shape, self._size_outhalo)) + """ + Shape of the domain+outhalo region. The outhalo is the region + surrounding the domain that may be read by an Operator. - @cached_property - def _shape_with_outhalo(self): + Notes + ----- + In an MPI context, this is the *local* with_halo region shape. + Further, note that the outhalo of inner ranks is typically empty, while + the outhalo of boundary ranks contains a number of elements depending + on the rank position in the decomposed grid (corner, side, ...). + """ return tuple(j + i + k for i, (j, k) in zip(self.shape, self._size_outhalo)) - _shape_with_halo_docstring = """\ - Shape of the domain+outhalo region. The outhalo is the region - surrounding the domain that may be read by an Operator. - - Notes - ----- - In an MPI context, this is the *local* with_halo region shape. - Further, note that the outhalo of inner ranks is typically empty, while - the outhalo of boundary ranks contains a number of elements depending - on the rank position in the decomposed grid (corner, side, ...). - """ - - shape_with_halo.__doc__ = _shape_with_halo_docstring - _shape_with_outhalo.__doc__ = _shape_with_halo_docstring - @cached_property def _shape_with_inhalo(self): """ @@ -317,25 +313,13 @@ def size_global(self): """ return reduce(mul, self.shape_global) - @cached_property + @property def _offset_inhalo(self): - """Number of points before the first and last halo elements.""" - left = tuple(self._size_padding.left) - right = tuple(np.add(np.add(left, self._size_halo.left), self._size_domain)) - - offsets = tuple(Offset(i, j) for i, j in zip(left, right)) + return super()._offset_halo - return DimensionTuple(*offsets, getters=self.dimensions, left=left, right=right) - - @cached_property + @property def _size_inhalo(self): - """Number of points in the halo region.""" - left = tuple(zip(*self._halo))[0] - right = tuple(zip(*self._halo))[1] - - sizes = tuple(Size(i, j) for i, j in self._halo) - - return DimensionTuple(*sizes, getters=self.dimensions, left=left, right=right) + return super()._size_halo @cached_property def _size_outhalo(self):