Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

reqs: Update cached_property to functools version #2359

Merged
merged 8 commits into from
May 21, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions .github/workflows/pytest-core-nompi.yml
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ jobs:
name: [
pytest-ubuntu-py311-gcc11-noomp,
pytest-ubuntu-py38-gcc12-omp,
pytest-ubuntu-py37-gcc7-omp,
pytest-ubuntu-py38-gcc7-omp,
mloubout marked this conversation as resolved.
Show resolved Hide resolved
pytest-ubuntu-py310-gcc10-noomp,
pytest-ubuntu-py312-gcc13-omp,
pytest-ubuntu-py39-gcc9-omp,
Expand All @@ -56,8 +56,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"
Expand Down
2 changes: 1 addition & 1 deletion devito/arch/archinfo.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion devito/data/decomposition.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
from collections.abc import Iterable
from functools import cached_property

import numpy as np
from cached_property import cached_property

from devito.data.meta import LEFT
from devito.tools import is_integer, as_tuple
Expand Down
3 changes: 2 additions & 1 deletion devito/finite_differences/coefficients.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
from functools import cached_property

import numpy as np
from cached_property import cached_property

from devito.finite_differences import Weights, generate_indices
from devito.finite_differences.tools import numeric_weights
Expand Down
2 changes: 1 addition & 1 deletion devito/finite_differences/derivative.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
from collections import OrderedDict
from collections.abc import Iterable
from functools import cached_property

from cached_property import cached_property
import sympy

from .finite_difference import generic_derivative, first_derivative, cross_derivative
Expand Down
3 changes: 1 addition & 2 deletions devito/finite_differences/differentiable.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
from collections import ChainMap
from itertools import product
from functools import singledispatch
from functools import singledispatch, cached_property

from cached_property import cached_property
import numpy as np
import sympy
from sympy.core.add import _addsort
Expand Down
2 changes: 1 addition & 1 deletion devito/ir/clusters/cluster.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
from itertools import chain
from functools import cached_property

import numpy as np
from cached_property import cached_property

from devito.ir.equations import ClusterizedEq
from devito.ir.support import (PARALLEL, PARALLEL_IF_PVT, BaseGuardBoundNext,
Expand Down
3 changes: 2 additions & 1 deletion devito/ir/equations/equation.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
from cached_property import cached_property
from functools import cached_property

import sympy

from devito.ir.equations.algorithms import dimension_sort, lower_exprs
Expand Down
2 changes: 1 addition & 1 deletion devito/ir/iet/efunc.py
Original file line number Diff line number Diff line change
@@ -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
Expand Down
2 changes: 1 addition & 1 deletion devito/ir/iet/nodes.py
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
2 changes: 1 addition & 1 deletion devito/ir/support/basic.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
from itertools import chain, product
from functools import cached_property

from cached_property import cached_property
from sympy import S

from devito.ir.support.space import Backward, null_ispace
Expand Down
3 changes: 1 addition & 2 deletions devito/ir/support/space.py
Original file line number Diff line number Diff line change
@@ -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 cached_property import cached_property
from sympy import Expr

from devito.ir.support.utils import minimum, maximum
Expand Down
3 changes: 2 additions & 1 deletion devito/mpi/distributed.py
Original file line number Diff line number Diff line change
@@ -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 cached_property import cached_property
import numpy as np
from cgen import Struct, Value

Expand Down
2 changes: 1 addition & 1 deletion devito/mpi/halo_scheme.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
from collections import OrderedDict, namedtuple, defaultdict
from itertools import product
from operator import attrgetter
from functools import cached_property

from cached_property import cached_property
from sympy import Max, Min
import sympy

Expand Down
3 changes: 1 addition & 2 deletions devito/operations/interpolators.py
Original file line number Diff line number Diff line change
@@ -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 cached_property import cached_property

try:
from scipy.special import i0
Expand Down
2 changes: 1 addition & 1 deletion devito/operator/operator.py
Original file line number Diff line number Diff line change
@@ -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 cached_property import cached_property
from sympy import sympify

from devito.arch import compiler_registry, platform_registry
Expand Down
3 changes: 1 addition & 2 deletions devito/passes/clusters/aliases.py
Original file line number Diff line number Diff line change
@@ -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 cached_property import cached_property
import numpy as np
import sympy

Expand Down
2 changes: 1 addition & 1 deletion devito/passes/clusters/buffering.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
from collections import OrderedDict, defaultdict, namedtuple
from itertools import combinations
from functools import cached_property

from cached_property import cached_property
import numpy as np

from devito.ir import (Cluster, Forward, GuardBound, Interval, IntervalGroup,
Expand Down
2 changes: 1 addition & 1 deletion devito/passes/iet/parpragma.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
from collections import defaultdict
from functools import cached_property

import numpy as np
import cgen as c
from cached_property import cached_property
from sympy import And, Max, true

from devito.data import FULL
Expand Down
72 changes: 25 additions & 47 deletions devito/tools/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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)

Expand Down Expand Up @@ -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):
Expand Down
2 changes: 1 addition & 1 deletion devito/types/array.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
from ctypes import POINTER, Structure, c_void_p, c_ulong
from functools import cached_property

import numpy as np
from cached_property import cached_property
from sympy import Expr

from devito.tools import (Reconstructable, as_tuple, c_restrict_void_p,
Expand Down
3 changes: 1 addition & 2 deletions devito/types/basic.py
Original file line number Diff line number Diff line change
@@ -1,15 +1,14 @@
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
import sympy

from sympy.core.assumptions import _assume_rules
from sympy.core.decorators import call_highest_priority
from cached_property import cached_property

from devito.data import default_allocator
from devito.parameters import configuration
Expand Down
18 changes: 13 additions & 5 deletions devito/types/dense.py
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -30,6 +30,7 @@


RegionMeta = namedtuple('RegionMeta', 'offset size')
Offset = namedtuple('Offset', 'left right')


class DiscreteFunction(AbstractFunction, ArgProvider, Differentiable):
Expand Down Expand Up @@ -203,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):
"""
Expand Down Expand Up @@ -243,8 +248,6 @@ def shape_with_halo(self):
"""
return tuple(j + i + k for i, (j, k) in zip(self.shape, self._size_outhalo))

_shape_with_outhalo = shape_with_halo

@cached_property
def _shape_with_inhalo(self):
"""
Expand Down Expand Up @@ -310,8 +313,13 @@ def size_global(self):
"""
return reduce(mul, self.shape_global)

_offset_inhalo = AbstractFunction._offset_halo
_size_inhalo = AbstractFunction._size_halo
@property
def _offset_inhalo(self):
return super()._offset_halo

@property
def _size_inhalo(self):
return super()._size_halo

@cached_property
def _size_outhalo(self):
Expand Down
2 changes: 1 addition & 1 deletion devito/types/dimension.py
Original file line number Diff line number Diff line change
@@ -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 cached_property import cached_property

from devito.data import LEFT, RIGHT
from devito.exceptions import InvalidArgument
Expand Down
2 changes: 1 addition & 1 deletion devito/types/equation.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion devito/types/grid.py
Original file line number Diff line number Diff line change
@@ -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 cached_property import cached_property

from devito.data import LEFT, RIGHT
from devito.logger import warning
Expand Down
Loading
Loading