Skip to content

Commit f91059c

Browse files
authored
Explicitly set numba config for each jit function (#221)
Using `parallel=True` on the Green's function was raising a warning because there is nothing to parallelize. Set arguments individually to avoid this. Add missing `numba.prange` to Spline Jacobian calculation to actually run it in parallel. A combination of Dask + numba makes some tests hang on CI randomly even if passing locally.Run the tests that use dask with the numpy engine to avoid this.
1 parent f680661 commit f91059c

File tree

5 files changed

+21
-34
lines changed

5 files changed

+21
-34
lines changed

.azure-pipelines.yml

Lines changed: 4 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -94,16 +94,12 @@ jobs:
9494
python.version: '3.7'
9595
PYTHON: '3.7'
9696
CONDA_INSTALL_EXTRA: "codecov pykdtree numba"
97-
NUMBA_NUM_THREADS: 1
98-
OMP_NUM_THREADS: 1
99-
MKL_NUM_THREADS: 1
97+
DASK_SCHEDULER: "synchronous"
10098
Python36-Optional:
10199
python.version: '3.6'
102100
PYTHON: '3.6'
103101
CONDA_INSTALL_EXTRA: "codecov pykdtree numba"
104-
NUMBA_NUM_THREADS: 1
105-
OMP_NUM_THREADS: 1
106-
MKL_NUM_THREADS: 1
102+
DASK_SCHEDULER: "synchronous"
107103

108104
steps:
109105

@@ -203,16 +199,12 @@ jobs:
203199
python.version: '3.7'
204200
PYTHON: '3.7'
205201
CONDA_INSTALL_EXTRA: "codecov pykdtree numba"
206-
NUMBA_NUM_THREADS: 1
207-
OMP_NUM_THREADS: 1
208-
MKL_NUM_THREADS: 1
202+
DASK_SCHEDULER: "synchronous"
209203
Python36-Optional:
210204
python.version: '3.6'
211205
PYTHON: '3.6'
212206
CONDA_INSTALL_EXTRA: "codecov pykdtree numba"
213-
NUMBA_NUM_THREADS: 1
214-
OMP_NUM_THREADS: 1
215-
MKL_NUM_THREADS: 1
207+
DASK_SCHEDULER: "synchronous"
216208

217209
steps:
218210

.travis.yml

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -56,17 +56,13 @@ matrix:
5656
os: linux
5757
env:
5858
- PYTHON=3.7
59-
- NUMBA_NUM_THREADS=1
60-
- OMP_NUM_THREADS=1
61-
- MKL_NUM_THREADS=1
59+
- DASK_SCHEDULER=synchronous
6260
- CONDA_INSTALL_EXTRA="codecov pykdtree numba"
6361
- name: "Linux - Python 3.6 (optional deps)"
6462
os: linux
6563
env:
6664
- PYTHON=3.6
67-
- NUMBA_NUM_THREADS=1
68-
- OMP_NUM_THREADS=1
69-
- MKL_NUM_THREADS=1
65+
- DASK_SCHEDULER=synchronous
7066
- CONDA_INSTALL_EXTRA="codecov pykdtree numba"
7167

7268
# Setup the build environment

verde/spline.py

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -23,9 +23,6 @@
2323
# Otherwise, DeprecationWarning won't be shown, kind of defeating the purpose.
2424
warnings.simplefilter("default")
2525

26-
# Default arguments for numba.jit
27-
JIT_ARGS = dict(nopython=True, target="cpu", fastmath=True, parallel=True)
28-
2926

3027
class SplineCV(BaseGridder):
3128
r"""
@@ -538,7 +535,7 @@ def jacobian_numpy(east, north, force_east, force_north, mindist, jac):
538535
return jac
539536

540537

541-
@jit(**JIT_ARGS)
538+
@jit(nopython=True, fastmath=True, parallel=True)
542539
def predict_numba(east, north, force_east, force_north, mindist, forces, result):
543540
"Calculate the predicted data using numba to speed things up."
544541
for i in numba.prange(east.size): # pylint: disable=not-an-iterable
@@ -551,10 +548,10 @@ def predict_numba(east, north, force_east, force_north, mindist, forces, result)
551548
return result
552549

553550

554-
@jit(**JIT_ARGS)
551+
@jit(nopython=True, fastmath=True, parallel=True)
555552
def jacobian_numba(east, north, force_east, force_north, mindist, jac):
556553
"Calculate the Jacobian matrix using numba to speed things up."
557-
for i in range(east.size):
554+
for i in numba.prange(east.size): # pylint: disable=not-an-iterable
558555
for j in range(force_east.size):
559556
jac[i, j] = GREENS_FUNC_JIT(
560557
east[i] - force_east[j], north[i] - force_north[j], mindist
@@ -563,4 +560,4 @@ def jacobian_numba(east, north, force_east, force_north, mindist, jac):
563560

564561

565562
# Jit compile the Green's functions for use in the numba functions
566-
GREENS_FUNC_JIT = jit(**JIT_ARGS)(greens_func)
563+
GREENS_FUNC_JIT = jit(nopython=True, fastmath=True)(greens_func)

verde/tests/test_spline.py

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -15,11 +15,15 @@
1515

1616

1717
@pytest.mark.parametrize(
18-
"delayed,client",
19-
[(False, None), (True, None), (False, Client(processes=False))],
18+
"delayed,client,engine",
19+
[
20+
(False, None, "auto"),
21+
(True, None, "numpy"),
22+
(False, Client(processes=False), "numpy"),
23+
],
2024
ids=["serial", "delayed", "distributed"],
2125
)
22-
def test_spline_cv(delayed, client):
26+
def test_spline_cv(delayed, client, engine):
2327
"See if the cross-validated spline solution matches the synthetic data"
2428
region = (100, 500, -800, -700)
2529
synth = CheckerBoard(region=region)
@@ -33,6 +37,7 @@ def test_spline_cv(delayed, client):
3337
cv=ShuffleSplit(n_splits=1, random_state=0),
3438
delayed=delayed,
3539
client=client,
40+
engine=engine,
3641
).fit(coords, data.scalars)
3742
if client is not None:
3843
client.close()

verde/vector.py

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -22,9 +22,6 @@
2222
# Otherwise, DeprecationWarning won't be shown, kind of defeating the purpose.
2323
warnings.simplefilter("default")
2424

25-
# Default arguments for numba.jit
26-
JIT_ARGS = dict(nopython=True, target="cpu", fastmath=True, parallel=True)
27-
2825

2926
class Vector(BaseGridder):
3027
"""
@@ -444,7 +441,7 @@ def jacobian_2d_numpy(east, north, force_east, force_north, mindist, poisson, ja
444441
return jac
445442

446443

447-
@jit(**JIT_ARGS)
444+
@jit(nopython=True, fastmath=True, parallel=True)
448445
def predict_2d_numba(
449446
east, north, force_east, force_north, mindist, poisson, forces, vec_east, vec_north
450447
):
@@ -462,7 +459,7 @@ def predict_2d_numba(
462459
return vec_east, vec_north
463460

464461

465-
@jit(**JIT_ARGS)
462+
@jit(nopython=True, fastmath=True, parallel=True)
466463
def jacobian_2d_numba(east, north, force_east, force_north, mindist, poisson, jac):
467464
"Calculate the Jacobian matrix using numba to speed things up."
468465
nforces = force_east.size
@@ -480,4 +477,4 @@ def jacobian_2d_numba(east, north, force_east, force_north, mindist, poisson, ja
480477

481478

482479
# JIT compile the Greens functions for use in numba functions
483-
GREENS_FUNC_2D_JIT = jit(**JIT_ARGS)(greens_func_2d)
480+
GREENS_FUNC_2D_JIT = jit(nopython=True, fastmath=True)(greens_func_2d)

0 commit comments

Comments
 (0)