-
Notifications
You must be signed in to change notification settings - Fork 6
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Bump Python / Numpy supported versions (#166)
* python-wheels: bump action versions * bump supported Python versions Follow https://scientific-python.org/specs/spec-0000/ * bump python version in conda environments * support numpy 2.0 Already supported by recents versions of pybind11 and xtensor-python, but we need to build against numpy 2.x in order to make fastscapelib-python work with numpy 1.xx and 2.x. * support numpy 1.24 at minimum Follow https://scientific-python.org/specs/spec-0000/ * bump xtensor(-python) downloaded versions * make numba dependency optional Allow building python 3.13 wheels without support for numba flow kernels for now. * fix import error + fix typing issue * fix doc builds (API) * doc: fix doxygen warnings * misc fixes * ci: add numpy 1.xx compat test * try fix doc build error No such error when building locally?! * fix pip install numpy version * try tracking doc build error on RTD * try fix RTD - add numba to doc environment - revert api hidden (it works locally so it should work on RTD) - doc envrionment: bump python version to 3.11 (maybe will solve the annotation warning similar to sphinx-doc/sphinx#11460 ?)
- Loading branch information
Showing
17 changed files
with
171 additions
and
146 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,86 @@ | ||
from __future__ import annotations | ||
|
||
from typing import TYPE_CHECKING, Any, Callable, Iterable | ||
|
||
if TYPE_CHECKING: | ||
import numba as nb | ||
|
||
from fastscapelib.flow import FlowGraph, FlowGraphTraversalDir | ||
from fastscapelib.flow.numba.flow_kernel import ( | ||
NumbaFlowKernel, | ||
NumbaFlowKernelData, | ||
NumbaJittedClass, | ||
) | ||
|
||
|
||
def create_flow_kernel( | ||
flow_graph: FlowGraph, | ||
kernel_func: Callable[[NumbaJittedClass], int], | ||
spec: dict[str, nb.types.Type | tuple[nb.types.Type, Any]], | ||
apply_dir: FlowGraphTraversalDir, | ||
outputs: Iterable[str] = (), | ||
max_receivers: int = -1, | ||
n_threads: int = 1, | ||
print_generated_code: bool = False, | ||
print_stats: bool = False, | ||
) -> tuple[NumbaFlowKernel, NumbaFlowKernelData]: | ||
"""Creates a numba flow kernel. | ||
Parameters | ||
---------- | ||
flow_graph : :py:class:`~fastscapelib.FlowGraph` | ||
A flow graph object. | ||
kernel_func : callable | ||
A Python function to apply to each node of the graph. It must take one | ||
input argument (numba jit-compiled class) that holds or references input | ||
and output kernel data of one graph node. It should return an integer. | ||
spec : dict | ||
Dictionary where keys are kernel input and output variable names and | ||
values are either variable types (i.e. numba scalar or array types) or | ||
variable (type, value) tuples (only for scalar variables). | ||
apply_dir : :py:class:`~fastscapelib.FlowGraphTraversalDir.` | ||
The direction and order in which the flow kernel will be applied along | ||
the graph. | ||
outputs : iterable | ||
The names of the kernel output variables. All names given here must be | ||
also present in ``spec``. | ||
max_receivers : int | ||
Maximum number of flow receiver nodes per graph node. Setting this number | ||
to 1 may speed up the application of the kernel function along the graph. | ||
Setting this number to -1 (default) will use the maximum number defined | ||
from the flow graph object and is generally safer. | ||
n_threads : int | ||
Number of threads to use for applying the kernel function in parallel | ||
along the flow graph (default: 1, the kernel will be applied sequentially). | ||
A value > 1 may be useful for kernel functions that are computationally | ||
expensive. For trivial kernel functions it is generally more efficient to | ||
apply the kernel sequentially (i.e., ``n_threads = 1``). | ||
print_generated_code : bool | ||
If True, prints the code used to create the numba jit-compiled classes for | ||
managing kernel data (default: False). Useful for debugging. | ||
print_stats : bool | ||
If True, prints a small report on kernel creation performance | ||
(default: False). | ||
Returns | ||
------- | ||
flow_kernel : :py:class:`~fastscapelib.flow.numba.flow_kernel.NumbaFlowKernel` | ||
An object used to apply the flow kernel. | ||
flow_kernel_data : :py:class:`~fastscapelib.flow.numba.flow_kernel.NumbaFlowKernelData` | ||
An object used to manage flow kernel data. | ||
""" | ||
from fastscapelib.flow.numba.flow_kernel import NumbaFlowKernelFactory | ||
|
||
factory = NumbaFlowKernelFactory( | ||
flow_graph, | ||
kernel_func, | ||
spec, | ||
apply_dir, | ||
outputs=outputs, | ||
max_receivers=max_receivers, | ||
n_threads=n_threads, | ||
print_generated_code=print_generated_code, | ||
print_stats=print_stats, | ||
) | ||
return factory.kernel, factory.data |
Oops, something went wrong.