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

Restrict numpy to version <2 #571

Merged
merged 3 commits into from
Jun 17, 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.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
6 changes: 4 additions & 2 deletions pde/solvers/explicit_mpi.py
Original file line number Diff line number Diff line change
Expand Up @@ -121,12 +121,14 @@ def _make_error_synchronizer(self) -> Callable[[float], float]:
"""return helper function that synchronizes errors between multiple processes"""
if mpi.parallel_run:
# in a parallel run, we need to return the maximal error
from ..tools.mpi import mpi_allreduce
from ..tools.mpi import Operator, mpi_allreduce

operator_max_id = Operator.MAX

@register_jitable
def synchronize_errors(error: float) -> float:
"""return maximal error accross all cores"""
return mpi_allreduce(error, "MAX") # type: ignore
return mpi_allreduce(error, operator_max_id) # type: ignore

return synchronize_errors # type: ignore
else:
Expand Down
23 changes: 18 additions & 5 deletions pde/tools/mpi.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,11 @@
from numba import types
from numba.extending import overload, register_jitable

try:
from numba.types import Literal
except ImportError:
from numba.types.misc import Literal

Check warning on line 33 in pde/tools/mpi.py

View check run for this annotation

Codecov / codecov/patch

pde/tools/mpi.py#L32-L33

Added lines #L32 - L33 were not covered by tests

if TYPE_CHECKING:
from numba_mpi import Operator

Expand Down Expand Up @@ -184,18 +189,26 @@

if operator is None or isinstance(operator, nb.types.NoneType):
op_id = -1 # value will not be used
elif isinstance(operator, nb.types.misc.StringLiteral):
op_id = Operator.id(operator.literal_value)
elif isinstance(operator, nb.types.misc.Literal):
op_id = int(operator)
elif isinstance(operator, Literal):

Check warning on line 192 in pde/tools/mpi.py

View check run for this annotation

Codecov / codecov/patch

pde/tools/mpi.py#L192

Added line #L192 was not covered by tests
# an operator is specified (using a literal value
if isinstance(operator.literal_value, str):

Check warning on line 194 in pde/tools/mpi.py

View check run for this annotation

Codecov / codecov/patch

pde/tools/mpi.py#L194

Added line #L194 was not covered by tests
# an operator is specified by it's name
op_id = Operator.id(operator.literal_value)

Check warning on line 196 in pde/tools/mpi.py

View check run for this annotation

Codecov / codecov/patch

pde/tools/mpi.py#L196

Added line #L196 was not covered by tests
else:
# assume an operator is specified by it's id
op_id = int(operator.literal_value)
elif isinstance(operator, nb.types.Integer):
op_id = None # use given value of operator

Check warning on line 201 in pde/tools/mpi.py

View check run for this annotation

Codecov / codecov/patch

pde/tools/mpi.py#L199-L201

Added lines #L199 - L201 were not covered by tests
else:
raise RuntimeError("`operator` must be a literal type")
raise RuntimeError(f"`operator` must be a literal type, not {operator}")

Check warning on line 203 in pde/tools/mpi.py

View check run for this annotation

Codecov / codecov/patch

pde/tools/mpi.py#L203

Added line #L203 was not covered by tests

@register_jitable
def _allreduce(sendobj, recvobj, operator: int | str | None = None) -> int:
"""helper function that calls `numba_mpi.allreduce`"""
if operator is None:
return numba_mpi.allreduce(sendobj, recvobj) # type: ignore
elif op_id is None:
return numba_mpi.allreduce(sendobj, recvobj, operator) # type: ignore

Check warning on line 211 in pde/tools/mpi.py

View check run for this annotation

Codecov / codecov/patch

pde/tools/mpi.py#L210-L211

Added lines #L210 - L211 were not covered by tests
else:
return numba_mpi.allreduce(sendobj, recvobj, op_id) # type: ignore

Expand Down
2 changes: 1 addition & 1 deletion pde/tools/resources/requirements_basic.txt
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
# These are the basic requirements for the package
matplotlib>=3.1
numba>=0.59
numpy>=1.22
numpy>=1.22,<2
scipy>=1.10
sympy>=1.9
tqdm>=4.66
2 changes: 1 addition & 1 deletion pde/tools/resources/requirements_full.txt
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ ffmpeg-python>=0.2
h5py>=2.10
matplotlib>=3.1
numba>=0.59
numpy>=1.22
numpy>=1.22,<2
pandas>=2
py-modelrunner>=0.18
rocket-fft>=0.2.4
Expand Down
2 changes: 1 addition & 1 deletion pde/tools/resources/requirements_mpi.txt
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ matplotlib>=3.1
mpi4py>=3
numba>=0.59
numba-mpi>=0.22
numpy>=1.22
numpy>=1.22,<2
pandas>=2
scipy>=1.10
sympy>=1.9
Expand Down
2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ classifiers = [
]

# Requirements for setuptools
dependencies = ["matplotlib>=3.1", "numba>=0.59", "numpy>=1.22", "scipy>=1.10", "sympy>=1.9", "tqdm>=4.66"]
dependencies = ["matplotlib>=3.1", "numba>=0.59", "numpy>=1.22,<2", "scipy>=1.10", "sympy>=1.9", "tqdm>=4.66"]

[project.optional-dependencies]
io = ["h5py>=2.10", "pandas>=2", "ffmpeg-python>=0.2"]
Expand Down
2 changes: 1 addition & 1 deletion requirements.txt
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
matplotlib>=3.1
numba>=0.59
numpy>=1.22
numpy>=1.22,<2
scipy>=1.10
sympy>=1.9
tqdm>=4.66
2 changes: 1 addition & 1 deletion scripts/create_requirements.py
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ def line(self, relation: str = ">=") -> str:
),
Requirement(
name="numpy",
version_min="1.22",
version_min="1.22,<2",
usage="Handling numerical data",
essential=True,
),
Expand Down
2 changes: 1 addition & 1 deletion tests/requirements_full.txt
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ ffmpeg-python>=0.2
h5py>=2.10
matplotlib>=3.1
numba>=0.59
numpy>=1.22
numpy>=1.22,<2
pandas>=2
py-modelrunner>=0.18
rocket-fft>=0.2.4
Expand Down
2 changes: 1 addition & 1 deletion tests/requirements_min.txt
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
# These are the minimal requirements used to test compatibility
matplotlib~=3.1
numba~=0.59
numpy~=1.22
numpy~=1.22,<2
scipy~=1.10
sympy~=1.9
tqdm~=4.66
2 changes: 1 addition & 1 deletion tests/requirements_mpi.txt
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ matplotlib>=3.1
mpi4py>=3
numba>=0.59
numba-mpi>=0.22
numpy>=1.22
numpy>=1.22,<2
pandas>=2
scipy>=1.10
sympy>=1.9
Expand Down