diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md index d748c0784..b90f2079c 100644 --- a/CONTRIBUTING.md +++ b/CONTRIBUTING.md @@ -35,6 +35,18 @@ information. You'll find more information about project maintenance (releases, reviews, etc) in our organization-wide [Maintainers Guide][maintenance]. +## About coverage analysis + +Harmonica relies on numba for performance within some functions, which can make +it a bit difficult to measure test coverage since the functions being +executed are the jit-compiled versions of the functions in the code. +Fortunately, numba now supports measuring coverage if the environment variable +`NUMBA_JIT_COVERAGE=1` is set. However, it still does not support branch +analysis and will report any `for` or `if` as missing coverage for a branch, +even if tests explicitly for that are added. To get around this, we have to +disable branch analysis for every single `for` and `if` statement in our code by +putting `# pragma: no branch` after the statement. + [coc]: https://github.com/fatiando/community/blob/main/CODE_OF_CONDUCT.md [contrib]: https://github.com/fatiando/community/blob/main/CONTRIBUTING.md [maintenance]: https://github.com/fatiando/community/blob/main/MAINTENANCE.md diff --git a/Makefile b/Makefile index 13ecd22a7..23a55c3f1 100644 --- a/Makefile +++ b/Makefile @@ -1,7 +1,7 @@ # Build, package, test, and clean STYLE_CHECK_FILES=src test doc -.PHONY: build install test test_coverage test_numba format check check-format check-style check-actions clean +.PHONY: build help install test format check check-format check-style check-actions clean help: @echo "Commands:" @@ -14,21 +14,14 @@ help: @echo " clean clean up build and generated files" @echo "" -.PHONY: build, install, test, test_coverage, test_numba, format, check, check-format, check-style, check-actions, clean - build: python -m build . install: python -m pip install --no-deps -e . -test: test_coverage test_numba - -test_coverage: - NUMBA_DISABLE_JIT=1 MPLBACKEND='agg' pytest --cov - -test_numba: - NUMBA_DISABLE_JIT=0 MPLBACKEND='agg' pytest -m use_numba +test: + NUMBA_JIT_COVERAGE=1 pytest format: ruff check --select I --fix $(STYLE_CHECK_FILES) # fix isort errors diff --git a/pyproject.toml b/pyproject.toml index d6176f616..6d9ed987e 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -145,10 +145,7 @@ convention = "numpy" [tool.pytest.ini_options] doctest_optionflags = "NUMBER" -markers = [ - "use_numba: mark test functions that call Numba jitted functions" -] -addopts = "--verbose --doctest-modules --doctest-continue-on-failure" +addopts = "--verbose --cov --doctest-modules --doctest-continue-on-failure" testpaths = [ "test", "src", diff --git a/src/harmonica/_equivalent_sources/utils.py b/src/harmonica/_equivalent_sources/utils.py index 72223b9ec..698cba083 100644 --- a/src/harmonica/_equivalent_sources/utils.py +++ b/src/harmonica/_equivalent_sources/utils.py @@ -62,8 +62,8 @@ def jacobian(coordinates, points, jac, greens_function): """ east, north, upward = coordinates[:] point_east, point_north, point_upward = points[:] - for i in numba.prange(east.size): - for j in range(point_east.size): + for i in numba.prange(east.size): # pragma: no branch + for j in range(point_east.size): # pragma: no branch jac[i, j] = greens_function( east[i], north[i], @@ -85,8 +85,8 @@ def predict(coordinates, points, coeffs, result, greens_function): """ east, north, upward = coordinates[:] point_east, point_north, point_upward = points[:] - for i in numba.prange(east.size): - for j in range(point_east.size): + for i in numba.prange(east.size): # pragma: no branch + for j in range(point_east.size): # pragma: no branch result[i] += coeffs[j] * greens_function( east[i], north[i], diff --git a/src/harmonica/_forward/_tesseroid_utils.py b/src/harmonica/_forward/_tesseroid_utils.py index 97b18e532..a742eb9bb 100644 --- a/src/harmonica/_forward/_tesseroid_utils.py +++ b/src/harmonica/_forward/_tesseroid_utils.py @@ -79,17 +79,17 @@ def gauss_legendre_quadrature( # optimization: reduce the number of times that the trigonometric functions # are evaluated) result = 0.0 - for j, lat_node in enumerate(lat_nodes): + for j, lat_node in enumerate(lat_nodes): # pragma: no branch # Get the latitude of the point mass latitude_p = np.radians(0.5 * (n - s) * lat_node + 0.5 * (n + s)) cosphi_p = np.cos(latitude_p) sinphi_p = np.sin(latitude_p) - for k, rad_node in enumerate(rad_nodes): + for k, rad_node in enumerate(rad_nodes): # pragma: no branch # Get the radius of the point mass radius_p = 0.5 * (top - bottom) * rad_node + 0.5 * (top + bottom) # Get kappa constant for the point mass kappa = radius_p**2 * cosphi_p - for i, lon_node in enumerate(lon_nodes): + for i, lon_node in enumerate(lon_nodes): # pragma: no branch # Get the longitude of the point mass longitude_p = np.radians(0.5 * (e - w) * lon_node + 0.5 * (e + w)) # Compute the mass of the point mass @@ -198,7 +198,7 @@ def _adaptive_discretization( stack[0] = tesseroid stack_top = 0 n_splits = 0 - while stack_top >= 0: + while stack_top >= 0: # pragma: no branch # Pop the first tesseroid from the stack tesseroid = stack[stack_top] stack_top -= 1 @@ -208,25 +208,29 @@ def _adaptive_discretization( distance = _distance_tesseroid_point(coordinates, tesseroid) # Check inequality n_lon, n_lat, n_rad = 1, 1, 1 - if distance / l_lon < distance_size_ratio: + if distance / l_lon < distance_size_ratio: # pragma: no branch n_lon = 2 - if distance / l_lat < distance_size_ratio: + if distance / l_lat < distance_size_ratio: # pragma: no branch n_lat = 2 - if distance / l_rad < distance_size_ratio and radial_discretization: + if ( + distance / l_rad < distance_size_ratio and radial_discretization + ): # pragma: no branch n_rad = 2 # Apply discretization - if n_lon * n_lat * n_rad > 1: + if n_lon * n_lat * n_rad > 1: # pragma: no branch # Raise error if stack overflow # Number of tesseroids in stack = stack_top + 1 - if (stack_top + 1) + n_lon * n_lat * n_rad > stack.shape[0]: + if (stack_top + 1) + n_lon * n_lat * n_rad > stack.shape[ + 0 + ]: # pragma: no branch msg = "Stack Overflow. Try to increase the stack size." raise OverflowError(msg) stack_top = _split_tesseroid( tesseroid, n_lon, n_lat, n_rad, stack, stack_top ) - else: + else: # pragma: no branch # Raise error if small_tesseroids overflow - if n_splits + 1 > small_tesseroids.shape[0]: + if n_splits + 1 > small_tesseroids.shape[0]: # pragma: no branch raise OverflowError( "Exceeded maximum discretizations." + " Please increase the MAX_DISCRETIZATIONS." @@ -246,9 +250,9 @@ def _split_tesseroid(tesseroid, n_lon, n_lat, n_rad, stack, stack_top): d_lon = (e - w) / n_lon d_lat = (n - s) / n_lat d_rad = (top - bottom) / n_rad - for i in range(n_lon): - for j in range(n_lat): - for k in range(n_rad): + for i in range(n_lon): # pragma: no branch + for j in range(n_lat): # pragma: no branch + for k in range(n_rad): # pragma: no branch stack_top += 1 stack[stack_top, 0] = w + d_lon * i stack[stack_top, 1] = w + d_lon * (i + 1) @@ -455,8 +459,8 @@ def _check_points_outside_tesseroids(coordinates, tesseroids): """ longitude, latitude, radius = coordinates[:] conflicting = [] - for i in range(longitude.size): - for j in range(tesseroids.shape[0]): + for i in range(longitude.size): # pragma: no branch + for j in range(tesseroids.shape[0]): # pragma: no branch # Longitudinal boundaries of the tesseroid must be compared with # longitudinal coordinates of computation points when moved to # [0, 360) and [-180, 180). @@ -467,7 +471,7 @@ def _check_points_outside_tesseroids(coordinates, tesseroids): (west < longitude_180 < east or west < longitude_360 < east) and south < latitude[i] < north and bottom < radius[i] < top - ): + ): # pragma: no branch conflicting.append((i, j)) return conflicting @@ -511,7 +515,7 @@ def _discard_null_tesseroids(tesseroids, density): Parameters ---------- tesseroids : 2d-array - Array containing the boundaries of the tesserois in the following + Array containing the boundaries of the tesseroids in the following order: ``west``, ``east``, ``south``, ``north``, ``bottom``, ``top`` defined in a geocentric spherical coordinate system. density : 1d-array diff --git a/src/harmonica/_forward/_tesseroid_variable_density.py b/src/harmonica/_forward/_tesseroid_variable_density.py index 3a085e43f..9d95e92db 100644 --- a/src/harmonica/_forward/_tesseroid_variable_density.py +++ b/src/harmonica/_forward/_tesseroid_variable_density.py @@ -79,18 +79,18 @@ def gauss_legendre_quadrature_variable_density( # optimization: reduce the number of times that the trigonometric functions # are evaluated) result = 0.0 - for j, lat_node in enumerate(lat_nodes): + for j, lat_node in enumerate(lat_nodes): # pragma: no branch # Get the latitude of the point mass latitude_p = np.radians(0.5 * (n - s) * lat_node + 0.5 * (n + s)) cosphi_p = np.cos(latitude_p) sinphi_p = np.sin(latitude_p) - for k, rad_node in enumerate(rad_nodes): + for k, rad_node in enumerate(rad_nodes): # pragma: no branch # Get the radius of the point mass radius_p = 0.5 * (top - bottom) * rad_node + 0.5 * (top + bottom) density_p = density(radius_p) # Get kappa constant for the point mass kappa = radius_p**2 * cosphi_p - for i, lon_node in enumerate(lon_nodes): + for i, lon_node in enumerate(lon_nodes): # pragma: no branch # Get the longitude of the point mass longitude_p = np.radians(0.5 * (e - w) * lon_node + 0.5 * (e + w)) # Compute the mass of the point mass diff --git a/src/harmonica/_forward/dipole.py b/src/harmonica/_forward/dipole.py index fe412fc8f..894c68701 100644 --- a/src/harmonica/_forward/dipole.py +++ b/src/harmonica/_forward/dipole.py @@ -326,8 +326,8 @@ def _jit_dipole_magnetic_field_cartesian( easting_p, northing_p, upward_p = dipoles mag_e, mag_n, mag_u = magnetic_moments # Iterate over computation points and dipoles - for i in numba.prange(easting.size): - for j in range(easting_p.size): + for i in numba.prange(easting.size): # pragma: no branch + for j in range(easting_p.size): # pragma: no branch easting_comp, northing_comp, upward_comp = magnetic_field( easting[i], northing[i], @@ -343,7 +343,7 @@ def _jit_dipole_magnetic_field_cartesian( b_n[i] += northing_comp b_u[i] += upward_comp # Update progress bar if called - if update_progressbar: + if update_progressbar: # pragma: no branch progress_proxy.update(1) @@ -383,8 +383,8 @@ def _jit_dipole_magnetic_component_cartesian( easting_p, northing_p, upward_p = dipoles mag_e, mag_n, mag_u = magnetic_moments # Iterate over computation points and dipoles - for i in numba.prange(easting.size): - for j in range(easting_p.size): + for i in numba.prange(easting.size): # pragma: no branch + for j in range(easting_p.size): # pragma: no branch result[i] += forward_func( easting[i], northing[i], @@ -397,7 +397,7 @@ def _jit_dipole_magnetic_component_cartesian( mag_u[j], ) # Update progress bar if called - if update_progressbar: + if update_progressbar: # pragma: no branch progress_proxy.update(1) diff --git a/src/harmonica/_forward/point.py b/src/harmonica/_forward/point.py index 4398e1fb8..e6888996d 100644 --- a/src/harmonica/_forward/point.py +++ b/src/harmonica/_forward/point.py @@ -385,8 +385,8 @@ def point_mass_cartesian( field on the computation points. It could be one of the forward modelling functions in :mod:`choclo.point`. """ - for i in numba.prange(easting.size): - for j in range(easting_p.size): + for i in numba.prange(easting.size): # pragma: no branch + for j in range(easting_p.size): # pragma: no branch out[i] += forward_func( easting[i], northing[i], @@ -433,8 +433,8 @@ def point_mass_spherical( cosphi_p = np.cos(latitude_p) sinphi_p = np.sin(latitude_p) # Compute gravitational field - for i in numba.prange(longitude.size): - for j in range(longitude_p.size): + for i in numba.prange(longitude.size): # pragma: no branch + for j in range(longitude_p.size): # pragma: no branch out[i] += masses[j] * kernel( longitude[i], cosphi[i], diff --git a/src/harmonica/_forward/prisms/gravity.py b/src/harmonica/_forward/prisms/gravity.py index c13cbfda4..a5e9f6f99 100644 --- a/src/harmonica/_forward/prisms/gravity.py +++ b/src/harmonica/_forward/prisms/gravity.py @@ -277,8 +277,8 @@ def _any_singular_point_g_ee(coordinates, prisms): easting, northing, upward = coordinates n_coords = easting.size n_prisms = prisms.shape[0] - for i in range(n_coords): - for j in range(n_prisms): + for i in range(n_coords): # pragma: no branch + for j in range(n_prisms): # pragma: no branch if is_point_on_northing_edge( easting[i], northing[i], @@ -299,7 +299,7 @@ def _any_singular_point_g_ee(coordinates, prisms): prisms[j, 3], prisms[j, 4], prisms[j, 5], - ): + ): # pragma: no branch return True return False @@ -312,8 +312,8 @@ def _any_singular_point_g_nn(coordinates, prisms): easting, northing, upward = coordinates n_coords = easting.size n_prisms = prisms.shape[0] - for i in range(n_coords): - for j in range(n_prisms): + for i in range(n_coords): # pragma: no branch + for j in range(n_prisms): # pragma: no branch if is_point_on_easting_edge( easting[i], northing[i], @@ -334,7 +334,7 @@ def _any_singular_point_g_nn(coordinates, prisms): prisms[j, 3], prisms[j, 4], prisms[j, 5], - ): + ): # pragma: no branch return True return False @@ -347,8 +347,8 @@ def _any_singular_point_g_zz(coordinates, prisms): easting, northing, upward = coordinates n_coords = easting.size n_prisms = prisms.shape[0] - for i in range(n_coords): - for j in range(n_prisms): + for i in range(n_coords): # pragma: no branch + for j in range(n_prisms): # pragma: no branch if is_point_on_easting_edge( easting[i], northing[i], @@ -369,7 +369,7 @@ def _any_singular_point_g_zz(coordinates, prisms): prisms[j, 3], prisms[j, 4], prisms[j, 5], - ): + ): # pragma: no branch return True return False @@ -382,8 +382,8 @@ def _any_singular_point_g_en(coordinates, prisms): easting, northing, upward = coordinates n_coords = easting.size n_prisms = prisms.shape[0] - for i in range(n_coords): - for j in range(n_prisms): + for i in range(n_coords): # pragma: no branch + for j in range(n_prisms): # pragma: no branch if is_point_on_upward_edge( easting[i], northing[i], @@ -394,7 +394,7 @@ def _any_singular_point_g_en(coordinates, prisms): prisms[j, 3], prisms[j, 4], prisms[j, 5], - ): + ): # pragma: no branch return True return False @@ -407,8 +407,8 @@ def _any_singular_point_g_ez(coordinates, prisms): easting, northing, upward = coordinates n_coords = easting.size n_prisms = prisms.shape[0] - for i in range(n_coords): - for j in range(n_prisms): + for i in range(n_coords): # pragma: no branch + for j in range(n_prisms): # pragma: no branch if is_point_on_northing_edge( easting[i], northing[i], @@ -419,7 +419,7 @@ def _any_singular_point_g_ez(coordinates, prisms): prisms[j, 3], prisms[j, 4], prisms[j, 5], - ): + ): # pragma: no branch return True return False @@ -432,8 +432,8 @@ def _any_singular_point_g_nz(coordinates, prisms): easting, northing, upward = coordinates n_coords = easting.size n_prisms = prisms.shape[0] - for i in range(n_coords): - for j in range(n_prisms): + for i in range(n_coords): # pragma: no branch + for j in range(n_prisms): # pragma: no branch if is_point_on_easting_edge( easting[i], northing[i], @@ -444,7 +444,7 @@ def _any_singular_point_g_nz(coordinates, prisms): prisms[j, 3], prisms[j, 4], prisms[j, 5], - ): + ): # pragma: no branch return True return False @@ -521,8 +521,8 @@ def jit_prism_gravity( # Check if we need to update the progressbar on each iteration update_progressbar = progress_proxy is not None # Iterate over computation points and prisms - for i in numba.prange(easting.size): - for j in range(prisms.shape[0]): + for i in numba.prange(easting.size): # pragma: no branch + for j in range(prisms.shape[0]): # pragma: no branch out[i] += forward_func( easting[i], northing[i], @@ -536,7 +536,7 @@ def jit_prism_gravity( density[j], ) # Update progress bar - if update_progressbar: + if update_progressbar: # pragma: no branch progress_proxy.update(1) diff --git a/src/harmonica/_forward/prisms/layer.py b/src/harmonica/_forward/prisms/layer.py index 62ad43bb5..de2ba9bd5 100644 --- a/src/harmonica/_forward/prisms/layer.py +++ b/src/harmonica/_forward/prisms/layer.py @@ -587,23 +587,23 @@ def _forward_gravity_prism_layer( # Check if we need to update the progressbar on each iteration update_progressbar = progress_proxy is not None - for i in numba.prange(n_coords): - for j, easting_center in enumerate(prisms_easting): + for i in numba.prange(n_coords): # pragma: no branch + for j, easting_center in enumerate(prisms_easting): # pragma: no branch west = easting_center - half_spacing_east east = easting_center + half_spacing_east - for k, northing_center in enumerate(prisms_northing): + for k, northing_center in enumerate(prisms_northing): # pragma: no branch # Ignore prisms with zero or NaN density density = densities[k, j] - if density == 0.0 or np.isnan(density): + if density == 0.0 or np.isnan(density): # pragma: no branch continue # Ignore thin prisms bottom, top = prisms_bottom[k, j], prisms_top[k, j] - if top - bottom < thickness_threshold: + if top - bottom < thickness_threshold: # pragma: no branch continue # Ignore prisms with nan top or bottom - if np.isnan(top) or np.isnan(bottom): + if np.isnan(top) or np.isnan(bottom): # pragma: no branch continue south = northing_center - half_spacing_north @@ -621,7 +621,7 @@ def _forward_gravity_prism_layer( density, ) # Update progress bar if called - if update_progressbar: + if update_progressbar: # pragma: no branch progress_proxy.update(1) diff --git a/src/harmonica/_forward/prisms/magnetic.py b/src/harmonica/_forward/prisms/magnetic.py index 862c78d83..452458d86 100644 --- a/src/harmonica/_forward/prisms/magnetic.py +++ b/src/harmonica/_forward/prisms/magnetic.py @@ -314,8 +314,8 @@ def _jit_prism_magnetic_field( easting, northing, upward = coordinates mag_e, mag_n, mag_u = magnetization # Iterate over computation points and prisms - for i in numba.prange(easting.size): - for j in range(prisms.shape[0]): + for i in numba.prange(easting.size): # pragma: no branch + for j in range(prisms.shape[0]): # pragma: no branch easting_comp, northing_comp, upward_comp = magnetic_field( easting[i], northing[i], @@ -334,7 +334,7 @@ def _jit_prism_magnetic_field( b_n[i] += northing_comp b_u[i] += upward_comp # Update progress bar if called - if update_progressbar: + if update_progressbar: # pragma: no branch progress_proxy.update(1) @@ -379,8 +379,8 @@ def _jit_prism_magnetic_component( easting, northing, upward = coordinates mag_e, mag_n, mag_u = magnetization # Iterate over computation points and prisms - for i in numba.prange(easting.size): - for j in range(prisms.shape[0]): + for i in numba.prange(easting.size): # pragma: no branch + for j in range(prisms.shape[0]): # pragma: no branch result[i] += forward_function( easting[i], northing[i], @@ -396,7 +396,7 @@ def _jit_prism_magnetic_component( mag_u[j], ) # Update progress bar if called - if update_progressbar: + if update_progressbar: # pragma: no branch progress_proxy.update(1) diff --git a/src/harmonica/_forward/tesseroid_gravity.py b/src/harmonica/_forward/tesseroid_gravity.py index 492b887dd..26b44b568 100644 --- a/src/harmonica/_forward/tesseroid_gravity.py +++ b/src/harmonica/_forward/tesseroid_gravity.py @@ -302,12 +302,12 @@ def jit_tesseroid_gravity( cosphi = np.cos(np.radians(latitude)) sinphi = np.sin(np.radians(latitude)) # Loop over computation points - for i in numba.prange(longitude.size): + for i in numba.prange(longitude.size): # pragma: no branch # Initialize arrays to perform memory allocation only once stack = np.empty((STACK_SIZE, 6), dtype=dtype) small_tesseroids = np.empty((MAX_DISCRETIZATIONS, 6), dtype=dtype) # Loop over tesseroids - for j in range(tesseroids.shape[0]): + for j in range(tesseroids.shape[0]): # pragma: no branch # Apply adaptive discretization on tesseroid n_splits = _adaptive_discretization( (longitude[i], latitude[i], radius[i]), @@ -318,7 +318,7 @@ def jit_tesseroid_gravity( radial_adaptive_discretization, ) # Compute effect of the tesseroid through GLQ - for tess_index in range(n_splits): + for tess_index in range(n_splits): # pragma: no branch tesseroid = small_tesseroids[tess_index, :] result[i] += gauss_legendre_quadrature( longitude_rad[i], @@ -332,7 +332,7 @@ def jit_tesseroid_gravity( kernel, ) # Update progress bar - if update_progressbar: + if update_progressbar: # pragma: no branch progress_proxy.update(1) @@ -405,12 +405,12 @@ def jit_tesseroid_gravity_variable_density( cosphi = np.cos(np.radians(latitude)) sinphi = np.sin(np.radians(latitude)) # Loop over computation points - for i in numba.prange(longitude.size): + for i in numba.prange(longitude.size): # pragma: no branch # Initialize arrays to perform memory allocation only once stack = np.empty((STACK_SIZE, 6), dtype=dtype) small_tesseroids = np.empty((MAX_DISCRETIZATIONS, 6), dtype=dtype) # Loop over tesseroids - for j in range(tesseroids.shape[0]): + for j in range(tesseroids.shape[0]): # pragma: no branch # Apply adaptive discretization on tesseroid n_splits = _adaptive_discretization( (longitude[i], latitude[i], radius[i]), @@ -421,7 +421,7 @@ def jit_tesseroid_gravity_variable_density( radial_adaptive_discretization, ) # Compute effect of the tesseroid through GLQ - for tess_index in range(n_splits): + for tess_index in range(n_splits): # pragma: no branch tesseroid = small_tesseroids[tess_index, :] result[i] += gauss_legendre_quadrature_variable_density( longitude_rad[i], @@ -435,7 +435,7 @@ def jit_tesseroid_gravity_variable_density( kernel, ) # Update progress bar - if update_progressbar: + if update_progressbar: # pragma: no branch progress_proxy.update(1) diff --git a/src/harmonica/_spherical_harmonics/igrf.py b/src/harmonica/_spherical_harmonics/igrf.py index 7d31d472d..f8fae22c5 100644 --- a/src/harmonica/_spherical_harmonics/igrf.py +++ b/src/harmonica/_spherical_harmonics/igrf.py @@ -580,7 +580,7 @@ def spherical_harmonics_magnetic_field( Calculate a spherical harmonic expansion of a magnetic field. """ n_data = longitude.size - for i in numba.prange(n_data): + for i in numba.prange(n_data): # pragma: no branch cos_colat = np.cos(colatitude[i]) sin_colat = np.sin(colatitude[i]) # Have to allocate here because of the parallel loop. These are small @@ -601,15 +601,15 @@ def spherical_harmonics_magnetic_field( sin_mlon[0] = 0 cos_mlon[1] = np.cos(longitude[i]) sin_mlon[1] = np.sin(longitude[i]) - for m in range(2, max_degree + 1): + for m in range(2, max_degree + 1): # pragma: no branch cos_mlon[m] = 2 * cos_mlon[1] * cos_mlon[m - 1] - cos_mlon[m - 2] sin_mlon[m] = 2 * cos_mlon[1] * sin_mlon[m - 1] - sin_mlon[m - 2] # Calculating the power like this results in about an 8% performance # boost. Not much but I'll take it. r_frac = normalized_radius[i] ** (min_degree - 1 + 2) - for n in range(min_degree, max_degree + 1): + for n in range(min_degree, max_degree + 1): # pragma: no branch r_frac *= normalized_radius[i] - for m in range(n + 1): + for m in range(n + 1): # pragma: no branch b_east[i] += ( r_frac * (-m * g[n, m] * sin_mlon[m] + m * h[n, m] * cos_mlon[m]) @@ -628,7 +628,7 @@ def spherical_harmonics_magnetic_field( ) # The east component is singular at the poles. Set it to zero if close # to the poles to avoid this. - if abs(sin_colat) < 1e-10: + if abs(sin_colat) < 1e-10: # pragma: no branch b_east[i] = 0 else: b_east[i] *= -1 / sin_colat @@ -658,19 +658,19 @@ def spherical_harmonics_magnetic_field_grid( # https://en.wikipedia.org/wiki/List_of_trigonometric_identities cos_mlon = np.empty((n_lon, max_degree + 1)) sin_mlon = np.empty((n_lon, max_degree + 1)) - for j in numba.prange(n_lon): + for j in numba.prange(n_lon): # pragma: no branch cos_mlon[j, 0] = 1 sin_mlon[j, 0] = 0 cos_mlon[j, 1] = np.cos(longitude[j]) sin_mlon[j, 1] = np.sin(longitude[j]) - for m in range(2, max_degree + 1): + for m in range(2, max_degree + 1): # pragma: no branch cos_mlon[j, m] = ( 2 * cos_mlon[j, 1] * cos_mlon[j, m - 1] - cos_mlon[j, m - 2] ) sin_mlon[j, m] = ( 2 * cos_mlon[j, 1] * sin_mlon[j, m - 1] - sin_mlon[j, m - 2] ) - for i in numba.prange(n_colat): + for i in numba.prange(n_colat): # pragma: no branch cos_colat = np.cos(colatitude[i]) sin_colat = np.sin(colatitude[i]) # Have to allocate here because of the parallel loop. These are small @@ -680,11 +680,11 @@ def spherical_harmonics_magnetic_field_grid( p_deriv = np.empty_like(g) legendre.associated_legendre_schmidt(cos_colat, max_degree, p) legendre.associated_legendre_schmidt_derivative(max_degree, p, p_deriv) - for j in range(n_lon): + for j in range(n_lon): # pragma: no branch r_frac = normalized_radius[i, j] ** (min_degree - 1 + 2) - for n in range(min_degree, max_degree + 1): + for n in range(min_degree, max_degree + 1): # pragma: no branch r_frac *= normalized_radius[i, j] - for m in range(n + 1): + for m in range(n + 1): # pragma: no branch b_east[i, j] += ( r_frac * (-m * g[n, m] * sin_mlon[j, m] + m * h[n, m] * cos_mlon[j, m]) @@ -703,7 +703,7 @@ def spherical_harmonics_magnetic_field_grid( ) # The east component is singular at the poles. Set it to zero if close # to the poles to avoid this. - if abs(sin_colat) < 1e-10: + if abs(sin_colat) < 1e-10: # pragma: no branch b_east[i, j] = 0 else: b_east[i, j] *= -1 / sin_colat diff --git a/src/harmonica/_spherical_harmonics/legendre.py b/src/harmonica/_spherical_harmonics/legendre.py index d93c339ac..cf5121631 100644 --- a/src/harmonica/_spherical_harmonics/legendre.py +++ b/src/harmonica/_spherical_harmonics/legendre.py @@ -16,10 +16,10 @@ def _rescale(u, max_degree, p): """Rescale Legendre functions to their original range.""" rescale = 1e280 - for m in range(max_degree + 1): - if m > 0: + for m in range(max_degree + 1): # pragma: no branch + if m > 0: # pragma: no branch rescale *= u - for n in range(m, max_degree + 1): + for n in range(m, max_degree + 1): # pragma: no branch p[n, m] *= rescale @@ -59,8 +59,8 @@ def associated_legendre(x, max_degree, p): """ u = np.sqrt((1 - x) * (1 + x)) p[0, 0] = 1 - for n in range(1, max_degree + 1): - for m in range(n - 1): + for n in range(1, max_degree + 1): # pragma: no branch + for m in range(n - 1): # pragma: no branch a_nm = (2 * n - 1) / (n - m) b_nm = -(n + m - 1) / (n - m) p[n, m] = a_nm * x * p[n - 1, m] + b_nm * p[n - 2, m] @@ -113,10 +113,10 @@ def associated_legendre_derivative(max_degree, p, dp): https://www.gnu.org/software/gsl/tr/tr001.pdf """ dp[0, 0] = 0 - for n in range(1, max_degree + 1): + for n in range(1, max_degree + 1): # pragma: no branch a_nm = -1 dp[n, 0] = a_nm * p[n, 1] - for m in range(1, n): + for m in range(1, n): # pragma: no branch b_nm = 0.5 * (n + m) * (n - m + 1) c_nm = -0.5 dp[n, m] = b_nm * p[n, m - 1] + c_nm * p[n, m + 1] @@ -170,13 +170,13 @@ def associated_legendre_schmidt(x, max_degree, p): # This equation doesn't have u because of the scaling p[1, 1] = p[0, 0] # Calculate the zero order terms first - for n in range(2, max_degree + 1): + for n in range(2, max_degree + 1): # pragma: no branch a_n0 = (2 * n - 1) / (sqrt[n] ** 2) b_n0 = -((sqrt[n - 1] / sqrt[n]) ** 2) p[n, 0] = a_n0 * x * p[n - 1, 0] + b_n0 * p[n - 2, 0] # Now calculate the other terms - for n in range(2, max_degree + 1): - for m in range(1, n - 1): + for n in range(2, max_degree + 1): # pragma: no branch + for m in range(1, n - 1): # pragma: no branch a_nm = (2 * n - 1) / (sqrt[n + m] * sqrt[n - m]) b_nm = -sqrt[n + m - 1] * sqrt[n - m - 1] / (sqrt[n + m] * sqrt[n - m]) p[n, m] = a_nm * x * p[n - 1, m] + b_nm * p[n - 2, m] @@ -237,13 +237,13 @@ def associated_legendre_schmidt_derivative(max_degree, p, dp): dp[0, 0] = 0 dp[1, 0] = -p[1, 1] dp[1, 1] = p[1, 0] - for n in range(2, max_degree + 1): + for n in range(2, max_degree + 1): # pragma: no branch a_nm = -sqrt[n] * sqrt[n + 1] / sqrt[2] dp[n, 0] = a_nm * p[n, 1] b_nm = 0.5 * sqrt[n] * sqrt[n + 1] * sqrt[2] c_nm = -0.5 * sqrt[n + 2] * sqrt[n - 1] dp[n, 1] = b_nm * p[n, 0] + c_nm * p[n, 2] - for m in range(2, n): + for m in range(2, n): # pragma: no branch b_nm = 0.5 * sqrt[n + m] * sqrt[n - m + 1] c_nm = -0.5 * sqrt[n + m + 1] * sqrt[n - m] dp[n, m] = b_nm * p[n, m - 1] + c_nm * p[n, m + 1] @@ -295,13 +295,13 @@ def associated_legendre_full(x, max_degree, p): # This equation doesn't have u because of the scaling p[1, 1] = p[0, 0] * sqrt[3] # Calculate the zero order terms first - for n in range(2, max_degree + 1): + for n in range(2, max_degree + 1): # pragma: no branch a_n0 = sqrt[2 * n - 1] * sqrt[2 * n + 1] / n b_n0 = -(n - 1) * sqrt[2 * n + 1] / (n * sqrt[2 * n - 3]) p[n, 0] = a_n0 * x * p[n - 1, 0] + b_n0 * p[n - 2, 0] # Now calculate the other terms - for n in range(2, max_degree + 1): - for m in range(1, n - 1): + for n in range(2, max_degree + 1): # pragma: no branch + for m in range(1, n - 1): # pragma: no branch a_nm = sqrt[2 * n + 1] * sqrt[2 * n - 1] / (sqrt[n + m] * sqrt[n - m]) b_nm = ( -sqrt[n + m - 1] @@ -364,13 +364,13 @@ def associated_legendre_full_derivative(max_degree, p, dp): dp[0, 0] = 0 dp[1, 0] = -p[1, 1] dp[1, 1] = p[1, 0] - for n in range(2, max_degree + 1): + for n in range(2, max_degree + 1): # pragma: no branch a_nm = -sqrt[n] * sqrt[n + 1] / sqrt[2] dp[n, 0] = a_nm * p[n, 1] b_n1 = 0.5 * sqrt[2] * sqrt[n + 1] * sqrt[n] c_n1 = -0.5 * sqrt[n + 2] * sqrt[n - 1] dp[n, 1] = b_n1 * p[n, 0] + c_n1 * p[n, 2] - for m in range(2, n): + for m in range(2, n): # pragma: no branch b_nm = 0.5 * sqrt[n + m] * sqrt[n - m + 1] c_nm = -0.5 * sqrt[n + m + 1] * sqrt[n - m] dp[n, m] = b_nm * p[n, m - 1] + c_nm * p[n, m + 1] diff --git a/test/test_dipole.py b/test/test_dipole.py index 028b4c001..976d1ffcd 100644 --- a/test/test_dipole.py +++ b/test/test_dipole.py @@ -23,8 +23,6 @@ from harmonica import dipole_magnetic from harmonica._forward.dipole import VALID_FIELDS -from .utils import run_only_with_numba - def test_invalid_field(): """Check if passing an invalid field raises an error.""" @@ -52,7 +50,6 @@ def test_disable_checks(field): ) -@pytest.mark.use_numba @pytest.mark.skipif(ProgressBar is None, reason="requires numba_progress") @pytest.mark.parametrize("field", VALID_FIELDS) def test_progress_bar(field): @@ -111,34 +108,9 @@ class TestSerialVsParallel: """ @pytest.mark.parametrize("field", VALID_FIELDS) - def test_dipoles_parallel_vs_serial_no_numba(self, field): - """ - Check results of parallelized and serials runs - Run a small problem with Numba disable to count for test coverage. - """ - coordinates = ([0, 10], [0, 10], [0, 10]) - dipoles = ([-100, 0], [0, 100], [-20, -50]) - magnetic_moments = ( - [1.0, 1.0], - [1.0, -1.0], - [1.0, 5.0], - ) - parallel = dipole_magnetic( - coordinates, dipoles, magnetic_moments, field=field, parallel=True - ) - serial = dipole_magnetic( - coordinates, dipoles, magnetic_moments, field=field, parallel=False - ) - npt.assert_allclose(parallel, serial) - - @run_only_with_numba - @pytest.mark.parametrize("field", VALID_FIELDS) - def test_dipoles_parallel_vs_serial( - self, field - ): # pragma: no cover (we don't track coverage when @run_only_with_numba) + def test_dipoles_parallel_vs_serial(self, field): """ Check results of parallelized and serials runs - Run a large problem only with Numba enabled. """ coordinates = bd.grid_coordinates( region=(-100, 100, -100, 100), spacing=20, non_dimensional_coords=10 diff --git a/test/test_eq_sources_cartesian.py b/test/test_eq_sources_cartesian.py index d4d736325..81cef3d3b 100644 --- a/test/test_eq_sources_cartesian.py +++ b/test/test_eq_sources_cartesian.py @@ -21,8 +21,6 @@ from harmonica._equivalent_sources.cartesian import greens_func_cartesian from harmonica._equivalent_sources.utils import jacobian_numba_serial -from .utils import run_only_with_numba - @pytest.fixture(name="region") def fixture_region(): @@ -69,7 +67,7 @@ def fixture_data(coordinates, points, masses): @pytest.fixture(name="weights") -def fixture_weights(data): # pragma: no cover (only used in @run_only_with_numba tests) +def fixture_weights(data): """ Return some sample data. """ @@ -108,11 +106,8 @@ def fixture_coordinates_9x9(region): return coordinates -@run_only_with_numba @pytest.mark.parametrize("dtype", ["default", np.float32]) -def test_equivalent_sources_cartesian( - region, points, masses, coordinates, data, dtype -): # pragma: no cover (we don't track coverage with @run_only_with_numba) +def test_equivalent_sources_cartesian(region, points, masses, coordinates, data, dtype): """ Check that predictions are reasonable when interpolating from one grid to a denser grid. Use Cartesian coordinates. @@ -152,52 +147,6 @@ def test_equivalent_sources_cartesian( npt.assert_allclose(true, profile.scalars, atol=atol) -def test_equivalent_sources_small_data_cartesian(region, points, masses): - """ - Check predictions against synthetic data using few data points for speed - Use Cartesian coordinates. - """ - # Define a small set of observation points - coordinates = bd.grid_coordinates( - region=region, shape=(8, 8), non_dimensional_coords=0 - ) - # Get synthetic data - data = point_gravity(coordinates, points, masses, field="g_z") - - # The interpolation should be perfect on the data points - eqs = EquivalentSources(depth=500) - eqs.fit(coordinates, data) - npt.assert_allclose(data, eqs.predict(coordinates), rtol=1e-5) - - # Check that the proper source locations were set - tmp = [i.ravel() for i in coordinates] - npt.assert_allclose(tmp[:2], eqs.points_[:2], rtol=1e-5) - npt.assert_allclose(tmp[2] - 500, eqs.points_[2], rtol=1e-5) - - # Gridding at higher altitude should be reasonably accurate when compared - # to synthetic values - upward = 20 - shape = (8, 8) - grid_coords = bd.grid_coordinates( - region=region, shape=shape, non_dimensional_coords=upward - ) - true = point_gravity(grid_coords, points, masses, field="g_z") - npt.assert_allclose(true, eqs.predict(grid_coords), rtol=0.08) - - # Test grid method - grid = eqs.grid(grid_coords) - npt.assert_allclose(true, grid.scalars, rtol=0.08) - - # Test profile method - point1 = (region[0], region[2]) - point2 = (region[0], region[3]) - profile = eqs.profile(point1, point2, upward, 10) - true = point_gravity( - (profile.easting, profile.northing, profile.upward), points, masses, field="g_z" - ) - npt.assert_allclose(true, profile.scalars, rtol=0.05) - - def test_equivalent_sources_build_points(coordinates): """ Check if build_points method works as expected. @@ -290,7 +239,6 @@ def test_equivalent_sources_scatter_not_implemented(): eqs.scatter() -@pytest.mark.use_numba def test_equivalent_sources_jacobian_cartesian(): """ Test Jacobian matrix under symmetric system of point sources. @@ -318,10 +266,7 @@ def test_equivalent_sources_jacobian_cartesian(): npt.assert_allclose(jacobian[nearest_neighbours][0], jacobian[nearest_neighbours]) -@run_only_with_numba -def test_equivalent_sources_cartesian_parallel( - coordinates, data -): # pragma: no cover (we don't track coverage with @run_only_with_numba) +def test_equivalent_sources_cartesian_parallel(coordinates, data): """ Check predictions when parallel is enabled and disabled. """ @@ -336,7 +281,6 @@ def test_equivalent_sources_cartesian_parallel( npt.assert_allclose(grid_serial.scalars, grid_parallel.scalars, rtol=1e-7) -@run_only_with_numba @pytest.mark.parametrize("block_size", [None, 500], ids=["no_blocks", "blocks"]) @pytest.mark.parametrize("custom_points", [False, True], ids=["no_points", "points"]) @pytest.mark.parametrize("weights_none", [False, True], ids=["no_weights", "weights"]) @@ -352,7 +296,7 @@ def test_dtype( weights_none, damping, dtype, -): # pragma: no cover (we don't track coverage with @run_only_with_numba) +): """ Test dtype argument on EquivalentSources. """ @@ -378,7 +322,6 @@ def test_dtype( # assert eqs.coefs_.dtype == np.dtype(dtype) -@pytest.mark.use_numba @pytest.mark.parametrize("dtype", ["float64", "float32"]) def test_jacobian_dtype(region, dtype): """ diff --git a/test/test_eq_sources_spherical.py b/test/test_eq_sources_spherical.py index 67c4ceb14..44134419b 100644 --- a/test/test_eq_sources_spherical.py +++ b/test/test_eq_sources_spherical.py @@ -16,8 +16,6 @@ from harmonica import EquivalentSourcesSph, point_gravity -from .utils import run_only_with_numba - @pytest.fixture(name="region") def fixture_region(): @@ -69,8 +67,7 @@ def fixture_data_small(points, masses, coordinates_small): ) -@run_only_with_numba -def test_equivalent_sources_spherical(): # pragma: no cover +def test_equivalent_sources_spherical(): """ Check that predictions are reasonable when interpolating from one grid to a denser grid. @@ -113,54 +110,6 @@ def test_equivalent_sources_spherical(): # pragma: no cover npt.assert_allclose(true, grid.scalars, rtol=1e-3) -def test_equivalent_sources_small_data_spherical(): - """ - Check predictions against synthetic data using few data points for speed - Use spherical coordinates. - """ - region = (-70, -60, -40, -30) - radius = 6400e3 - # Build synthetic point masses - points = bd.grid_coordinates( - region=region, shape=(6, 6), non_dimensional_coords=radius - 500e3 - ) - masses = vd.synthetic.CheckerBoard(amplitude=1e13, region=region).predict(points) - # Define a set of observation points - coordinates = bd.grid_coordinates( - region=region, shape=(8, 8), non_dimensional_coords=radius - ) - # Get synthetic data - data = point_gravity( - coordinates, points, masses, field="g_z", coordinate_system="spherical" - ) - - # The interpolation should be perfect on the data points - eqs = EquivalentSourcesSph(relative_depth=500e3, damping=1e-12) - eqs.fit(coordinates, data) - npt.assert_allclose(data, eqs.predict(coordinates), rtol=1e-5) - - # Check that the proper source locations were set - tmp = [i.ravel() for i in coordinates] - npt.assert_allclose(tmp[:2], eqs.points_[:2], rtol=1e-5) - npt.assert_allclose(tmp[2] - 500e3, eqs.points_[2], rtol=1e-5) - - # Gridding at higher altitude should be reasonably accurate when compared - # to synthetic values - upward = radius + 2e3 - shape = (8, 8) - grid_coords = bd.grid_coordinates( - region=region, shape=shape, non_dimensional_coords=upward - ) - true = point_gravity( - grid_coords, points, masses, field="g_z", coordinate_system="spherical" - ) - npt.assert_allclose(true, eqs.predict(grid_coords), rtol=0.05) - - # Test grid method - grid = eqs.grid(grid_coords) - npt.assert_allclose(true, grid.scalars, rtol=0.05) - - def test_equivalent_sources_custom_points_spherical(): """ Check that passing in custom points works and actually uses the points @@ -223,8 +172,7 @@ def test_equivalent_sources_spherical_no_projection(): eqs.grid(upward=10, projection=lambda a, b: (a * 2, b * 2)) -@run_only_with_numba -def test_equivalent_sources_spherical_parallel(): # pragma: no cover +def test_equivalent_sources_spherical_parallel(): """ Check predictions when parallel is enabled and disabled. """ diff --git a/test/test_forward_utils.py b/test/test_forward_utils.py index 1e20d7891..5416409a5 100644 --- a/test/test_forward_utils.py +++ b/test/test_forward_utils.py @@ -25,7 +25,6 @@ ProgressBar = None -@pytest.mark.use_numba def test_distance(): """Test if computed is distance is right.""" # Cartesian coordinate system diff --git a/test/test_gradient_boosted_eqs.py b/test/test_gradient_boosted_eqs.py index a52d9ce3c..44e2ae5bc 100644 --- a/test/test_gradient_boosted_eqs.py +++ b/test/test_gradient_boosted_eqs.py @@ -17,8 +17,6 @@ from harmonica import EquivalentSourcesGB, point_gravity from harmonica._equivalent_sources.gradient_boosted import _get_region_data_sources -from .utils import run_only_with_numba - @pytest.fixture(name="region") def fixture_region(): @@ -65,7 +63,7 @@ def fixture_data(coordinates, points, masses): @pytest.fixture(name="weights") -def fixture_weights(data): # pragma: no cover (only used by @run_only_with_numba) +def fixture_weights(data): """ Return some sample data. """ @@ -154,31 +152,7 @@ def test_memory_estimation(spacing, window_size, dtype, itemsize): # ----------------------------------------------------------------------- -@pytest.mark.use_numba -@pytest.mark.parametrize("weights", [None, np.ones((8, 8))]) -def test_gb_eqs_small_data(coordinates_small, data_small, weights): - """ - Check predictions against synthetic data using few data points for speed. - """ - # The interpolation should be good enought on the data points - # Gradient-boosted equivalent sources don't perform well on small data, so - # we will check if the error is no larger than 1mGal - # (sample data ranges from approximately -7mGal to 7mGal) - eqs = EquivalentSourcesGB(depth=1e3, damping=None, window_size=1e3, random_state=42) - eqs.fit(coordinates_small, data_small, weights=weights) - # Error tolerance is 5% of the maximum data. - npt.assert_allclose( - data_small, - eqs.predict(coordinates_small), - rtol=0, - atol=0.05 * vd.maxabs(data_small), - ) - - -@run_only_with_numba -def test_gradient_boosted_eqs_single_window( - region, points, masses, coordinates, data -): # pragma: no cover +def test_gradient_boosted_eqs_single_window(region, points, masses, coordinates, data): """ Test GB eq-sources with a single window that covers the whole region. """ @@ -195,10 +169,7 @@ def test_gradient_boosted_eqs_single_window( npt.assert_allclose(true, eqs.predict(grid), rtol=1e-3, atol=atol) -@run_only_with_numba -def test_gradient_boosted_eqs_predictions( - region, points, masses, coordinates, data -): # pragma: no cover +def test_gradient_boosted_eqs_predictions(region, points, masses, coordinates, data): """ Test GB eq-sources predictions. """ @@ -220,8 +191,7 @@ def test_gradient_boosted_eqs_predictions( npt.assert_allclose(true, eqs.predict(grid), rtol=0, atol=0.02 * vd.maxabs(true)) -@run_only_with_numba -def test_gradient_boosted_eqs_random_state(coordinates, data): # pragma: no cover +def test_gradient_boosted_eqs_random_state(coordinates, data): """ Check if EquivalentSourcesGB produces same result by setting random_state. """ @@ -300,7 +270,6 @@ def test_same_windows_data_and_sources(): # ------------------------------------------------- -@run_only_with_numba @pytest.mark.parametrize("block_size", [None, 500], ids=["no_blocks", "blocks"]) @pytest.mark.parametrize("custom_points", [False, True], ids=["no_points", "points"]) @pytest.mark.parametrize("weights_none", [False, True], ids=["no_weights", "weights"]) @@ -316,7 +285,7 @@ def test_dtype( weights_none, damping, dtype, -): # pragma: no cover +): """ Test dtype argument on EquivalentSources. """ @@ -344,8 +313,7 @@ def test_dtype( assert prediction.dtype == np.dtype(dtype) -@run_only_with_numba -def test_gradient_boosted_eqs_float32(coordinates, data): # pragma: no cover +def test_gradient_boosted_eqs_float32(coordinates, data): """ Check that predictions are reasonable when interpolating from one grid to a denser grid, using float32 as dtype. diff --git a/test/test_igrf.py b/test/test_igrf.py index 7447cd538..cb940d4f6 100644 --- a/test/test_igrf.py +++ b/test/test_igrf.py @@ -225,7 +225,6 @@ def test_interpolate_coefficients_invalid_date(date): ) -@pytest.mark.use_numba @pytest.mark.parametrize( ("data", "coordinates"), [ diff --git a/test/test_legendre.py b/test/test_legendre.py index 89bd2e25e..244a21c38 100644 --- a/test/test_legendre.py +++ b/test/test_legendre.py @@ -22,8 +22,6 @@ associated_legendre_schmidt_derivative, ) -from .utils import run_only_with_numba - def legendre_analytical(x): """Analytical expressions for unnormalized Legendre functions.""" @@ -47,7 +45,6 @@ def legendre_analytical(x): return p -@pytest.mark.use_numba def legendre_derivative_analytical(x): """ Analytical expressions for theta derivatives of unnormalized Legendre @@ -97,7 +94,6 @@ def full_normalization(p): ) -@pytest.mark.use_numba @pytest.mark.parametrize( ("func", "norm"), [ @@ -124,7 +120,6 @@ def test_associated_legendre_function_analytical(func, norm): np.testing.assert_allclose(p_analytical[n, m], p[n, m], atol=1e-10) -@pytest.mark.use_numba @pytest.mark.parametrize( ("func", "deriv", "norm"), [ @@ -215,7 +210,6 @@ def test_associated_legengre_function_legendre_equation(self, func, deriv): ) -@run_only_with_numba class TestSchmidtHighDegree(BaseSchmidt): max_degree = 2800 diff --git a/test/test_linearity.py b/test/test_linearity.py index fdfdcbb7a..5a030861c 100644 --- a/test/test_linearity.py +++ b/test/test_linearity.py @@ -348,7 +348,6 @@ def sample_coordinates(self): non_dimensional_coords=boule.WGS84.mean_radius + 100, ) - @pytest.mark.use_numba @pytest.mark.parametrize("field", ["potential", "g_z"]) def test_linearity( self, sample_coordinates, sample_tesseroids, sample_densities, field diff --git a/test/test_point_gravity.py b/test/test_point_gravity.py index 80b5a014f..b743b422a 100644 --- a/test/test_point_gravity.py +++ b/test/test_point_gravity.py @@ -32,8 +32,6 @@ from harmonica._forward.utils import distance_cartesian from harmonica.constants import GRAVITATIONAL_CONST -from .utils import run_only_with_numba - MODULE_DIR = Path(__file__).parent TEST_DATA_DIR = MODULE_DIR / "data" @@ -141,7 +139,6 @@ def fixture_sample_coordinates_potential(): return (easting, northing, upward, potential) -@pytest.mark.use_numba def test_potential_cartesian_known_values(point_mass, sample_coordinates_potential): """ Compare the computed gravitational potential with reference values. @@ -154,7 +151,6 @@ def test_potential_cartesian_known_values(point_mass, sample_coordinates_potenti npt.assert_allclose(results, precomputed_potential) -@pytest.mark.use_numba def test_potential_symmetry_cartesian(): """ Test if potential field of a point mass has symmetry in Cartesian coords. @@ -180,7 +176,6 @@ def test_potential_symmetry_cartesian(): npt.assert_allclose(*results) -@pytest.mark.use_numba @pytest.mark.parametrize("field", ["g_n", "g_e", "g_z"]) def test_acceleration_symmetry_cartesian(field): """ @@ -272,7 +267,6 @@ def acceleration_finite_differences(coordinates, point, mass, field, delta=0.05) return finite_diff, relative_error -@pytest.mark.use_numba @pytest.mark.parametrize("field", ["g_n", "g_e", "g_z"]) @pytest.mark.parametrize( ("coordinates", "point", "mass"), @@ -296,7 +290,6 @@ def test_acceleration_finite_diff_cartesian(coordinates, point, mass, field): npt.assert_allclose(result, finite_diff, rtol=relative_error) -@pytest.mark.use_numba @pytest.mark.parametrize("field", ["g_n", "g_e", "g_z"]) def test_acceleration_sign(field): """ @@ -323,14 +316,13 @@ def test_acceleration_sign(field): assert np.sign(mass) == -np.sign(results[2]) -@run_only_with_numba @pytest.mark.parametrize( "field", ["potential", "g_z", "g_n", "g_e", "g_ee", "g_nn", "g_zz", "g_en", "g_ez", "g_nz"], ) def test_point_mass_cartesian_parallel( field, -): # pragma: no cover (we don't track coverage with @run_only_with_numba) +): """ Check if parallel and serial runs return the same result. """ @@ -351,7 +343,6 @@ def test_point_mass_cartesian_parallel( npt.assert_allclose(result_serial, result_parallel) -@pytest.mark.use_numba def test_laplace_equation_cartesian(): """ Check if the diagonal components of the tensor satisfy Laplace equation. @@ -373,7 +364,6 @@ def test_laplace_equation_cartesian(): npt.assert_allclose(g_ee + g_nn, -g_zz) -@pytest.mark.use_numba @pytest.mark.parametrize( ("field", "flipped_field"), [("g_en", "g_ne"), ("g_ez", "g_ze"), ("g_nz", "g_zn")] ) @@ -522,7 +512,6 @@ def opposite_computation_points(self, directions): upward[1] -= distance return (easting, northing, upward) - @pytest.mark.use_numba @pytest.mark.parametrize("field", tensor_fields) def test_opposite(self, field): """ @@ -539,7 +528,6 @@ def test_opposite(self, field): # Check for expected symmetry npt.assert_allclose(results[0], results[1]) - @pytest.mark.use_numba @pytest.mark.parametrize("field", nondiagonal_fields) @pytest.mark.parametrize("swap_directions", [False, True], ids=["noswap", "swap"]) def test_mirrored_nondiagonals(self, field, swap_directions): @@ -626,7 +614,6 @@ def tensor_finite_differences(coordinates, point, mass, field, delta=0.05): return finite_diff, relative_error -@pytest.mark.use_numba @pytest.mark.parametrize("field", ["g_ee", "g_nn", "g_zz", "g_en", "g_ez", "g_nz"]) @pytest.mark.parametrize( ("coordinates", "point", "mass"), @@ -653,7 +640,6 @@ def test_tensor_finite_diff_cartesian(coordinates, point, mass, field): # --------------------------- # Spherical coordinates tests # --------------------------- -@pytest.mark.use_numba def test_point_mass_on_origin(): """Check potential and g_z of point mass on origin in spherical coordinates.""" point_mass = [0.0, 0.0, 0.0] @@ -678,7 +664,6 @@ def test_point_mass_on_origin(): ) -@pytest.mark.use_numba @pytest.mark.parametrize("field", ["potential", "g_z"]) def test_point_mass_same_radial_direction(field): """ @@ -708,7 +693,6 @@ def test_point_mass_same_radial_direction(field): ) -@pytest.mark.use_numba def test_point_mass_potential_on_equator(): """Check potential field on equator and same radial coordinate.""" radius = 3.0 @@ -738,7 +722,6 @@ def test_point_mass_potential_on_equator(): ) -@pytest.mark.use_numba def test_point_mass_potential_on_same_meridian(): """Check potential field on same meridian and radial coordinate.""" radius = 3.0 @@ -768,8 +751,7 @@ def test_point_mass_potential_on_same_meridian(): ) -@run_only_with_numba -def test_point_mass_spherical_parallel(): # pragma: no cover +def test_point_mass_spherical_parallel(): """ Check if parallel and serial runs return the same result. """ @@ -833,7 +815,6 @@ def sample_coordinates(self): upward = np.array([9, 6, 6, 12], dtype=float) return (easting, northing, upward) - @pytest.mark.use_numba @pytest.mark.parametrize( ("field", "choclo_func"), [ diff --git a/test/test_prism.py b/test/test_prism.py index 38463f50e..b0669c9b1 100644 --- a/test/test_prism.py +++ b/test/test_prism.py @@ -36,8 +36,6 @@ from harmonica._forward.prisms.gravity import _discard_null_prisms from harmonica._forward.prisms.utils import check_prisms -from .utils import run_only_with_numba - def test_invalid_field(): """Check if passing an invalid field raises an error.""" @@ -112,7 +110,6 @@ def test_discard_null_prisms(): npt.assert_allclose(density, np.array([2670])) -@pytest.mark.use_numba def test_forward_with_null_prisms(): """ Test if the forward model with null prisms gives sensible results. @@ -136,7 +133,6 @@ def test_forward_with_null_prisms(): ) -@pytest.mark.use_numba def test_disable_checks(): """Check if the disable_checks flag works properly.""" valid_prism = [0, 10, 0, 10, -10, 0] @@ -189,7 +185,6 @@ def sample_coordinates(self): upward = np.array([9, 6, 6, 12], dtype=float) return (easting, northing, upward) - @pytest.mark.use_numba @pytest.mark.parametrize( ("field", "choclo_func"), [ @@ -244,8 +239,7 @@ def test_against_choclo( npt.assert_allclose(result, expected_result) -@run_only_with_numba -def test_laplace(): # pragma: no cover +def test_laplace(): """ Test if the diagonal components satisfy Laplace equation. """ @@ -266,7 +260,6 @@ def test_laplace(): # pragma: no cover ) -@pytest.mark.use_numba def test_prism_against_infinite_slab(): """ Test if g_z of a large prism matches the solution for an infinite slab. @@ -297,7 +290,6 @@ def test_prism_against_infinite_slab(): npt.assert_allclose(analytical, results[-1]) -@pytest.mark.use_numba def test_prisms_parallel_vs_serial(): """ Check if the parallelized run returns the same results as the serial one. @@ -348,7 +340,6 @@ def coordinates(self): return coordinates @pytest.mark.skipif(ProgressBar is None, reason="requires numba_progress") - @pytest.mark.use_numba @pytest.mark.parametrize( "field", [ @@ -430,7 +421,6 @@ def get_upward_edges_center(self, prism): upward = np.full_like(easting, upward_c) return easting, northing, upward - @pytest.mark.use_numba @pytest.mark.parametrize("field", ["g_ee", "g_nn", "g_zz", "g_en", "g_ez", "g_nz"]) def test_on_vertices(self, sample_prism, sample_density, field): """ @@ -447,7 +437,6 @@ def test_on_vertices(self, sample_prism, sample_density, field): field=field, ) - @pytest.mark.use_numba @pytest.mark.parametrize("field", ["g_nn", "g_zz", "g_nz"]) def test_on_easting_edges(self, sample_prism, sample_density, field): """ @@ -465,7 +454,6 @@ def test_on_easting_edges(self, sample_prism, sample_density, field): field=field, ) - @pytest.mark.use_numba @pytest.mark.parametrize("field", ["g_ee", "g_zz", "g_ez"]) def test_on_northing_edges(self, sample_prism, sample_density, field): """ @@ -483,7 +471,6 @@ def test_on_northing_edges(self, sample_prism, sample_density, field): field=field, ) - @pytest.mark.use_numba @pytest.mark.parametrize("field", ["g_ee", "g_nn", "g_en"]) def test_on_upward_edges(self, sample_prism, sample_density, field): """ diff --git a/test/test_prism_layer.py b/test/test_prism_layer.py index 9ee5141ff..aaa354a2f 100644 --- a/test/test_prism_layer.py +++ b/test/test_prism_layer.py @@ -237,7 +237,6 @@ def test_prism_layer_get_prism_by_index(): ) -@pytest.mark.use_numba @pytest.mark.parametrize("field", FIELDS) def test_prism_layer_gravity(field, dummy_layer): """ @@ -279,7 +278,6 @@ def test_prism_layer_invalid_field(dummy_layer): layer.prism_layer.gravity(coordinates, field=invalid_field) -@pytest.mark.use_numba @pytest.mark.parametrize("field", ["potential", "g_z"]) def test_prism_layer_gravity_surface_nans(field, dummy_layer, prism_layer_with_holes): """ @@ -305,7 +303,6 @@ def test_prism_layer_gravity_surface_nans(field, dummy_layer, prism_layer_with_h ) -@pytest.mark.use_numba @pytest.mark.parametrize("field", ["potential", "g_z"]) def test_prism_layer_gravity_density_nans(field, dummy_layer, prism_layer_with_holes): """ @@ -397,7 +394,6 @@ def test_to_pyvista_drop_null_prisms(dummy_layer, drop_null_prisms): @pytest.mark.skipif(ProgressBar is None, reason="requires numba_progress") -@pytest.mark.use_numba def test_progress_bar(dummy_layer): """ Check if forward gravity results with and without progress bar match. diff --git a/test/test_prism_magnetic.py b/test/test_prism_magnetic.py index 82ef90b37..7c866cb9a 100644 --- a/test/test_prism_magnetic.py +++ b/test/test_prism_magnetic.py @@ -23,8 +23,6 @@ from harmonica import prism_magnetic from harmonica._forward.prisms.magnetic import VALID_FIELDS -from .utils import run_only_with_numba - def test_invalid_field(): """Check if passing an invalid field raises an error.""" @@ -35,7 +33,6 @@ def test_invalid_field(): prism_magnetic(coordinates, prism, magnetization, field="Not a valid field") -@pytest.mark.use_numba @pytest.mark.skipif(ProgressBar is None, reason="requires numba_progress") @pytest.mark.parametrize("field", VALID_FIELDS) def test_progress_bar(field): @@ -65,33 +62,9 @@ class TestSerialVsParallel: """ @pytest.mark.parametrize("field", VALID_FIELDS) - def test_prisms_parallel_vs_serial_no_numba(self, field): - """ - Check results of parallelized and serials runs. - - Run a small problem with Numba disable to count for test coverage. - """ - prisms = [ - [-100, 0, -100, 0, -10, 0], - [0, 100, -100, 0, -10, 0], - ] - magnetizations = ([1.0, 1.0], [1.0, -1.0], [1.0, 5.0]) - coordinates = ([0, 10], [0, 10], [0, 10]) - parallel = prism_magnetic( - coordinates, prisms, magnetizations, field=field, parallel=True - ) - serial = prism_magnetic( - coordinates, prisms, magnetizations, field=field, parallel=False - ) - npt.assert_allclose(parallel, serial) - - @run_only_with_numba - @pytest.mark.parametrize("field", VALID_FIELDS) # pragma: no cover def test_prisms_parallel_vs_serial(self, field): """ Check results of parallelized and serials runs. - - Run a large problem only with Numba enabled. """ prisms = [ [-100, 0, -100, 0, -10, 0], diff --git a/test/test_tesseroid.py b/test/test_tesseroid.py index 80d18158a..e082072fe 100644 --- a/test/test_tesseroid.py +++ b/test/test_tesseroid.py @@ -33,8 +33,6 @@ ) from harmonica.constants import GRAVITATIONAL_CONST -from .utils import run_only_with_numba - try: from numba_progress import ProgressBar except ImportError: # pragma: no cover @@ -45,27 +43,6 @@ ACCURACY_THRESHOLD = 1e-3 -@pytest.mark.use_numba -@pytest.mark.parametrize("field", ["potential", "g_z"]) -@pytest.mark.parametrize("radial_discretization", [True, False]) -def test_single_tesseroid(field, radial_discretization): - """Test single tesseroid for achieving coverage when Numba is disabled.""" - ellipsoid = boule.WGS84 - top = ellipsoid.mean_radius - bottom = top - 1e3 - tesseroid = np.array([-10.0, 10.0, -10.0, 10.0, bottom, top]) - density = 1000.0 - coordinates = [0.0, 0.0, top + 100] - tesseroid_gravity( - coordinates, - tesseroid, - density, - radial_adaptive_discretization=radial_discretization, - field=field, - ) - - -@pytest.mark.use_numba @pytest.mark.parametrize("field", ["potential", "g_z"]) @pytest.mark.parametrize("radial_discretization", [True, False]) def test_tesseroid_parallel(field, radial_discretization): @@ -220,7 +197,6 @@ def test_invalid_tesseroid(): _check_tesseroids(np.atleast_2d([-150, 300, s, n, bottom, top])) -@pytest.mark.use_numba def test_disable_checks(): """Check if the disable_checks flag works properly.""" valid_tesseroid = [0.0, 10.0, 0.0, 10.0, 10.0, 20.0] @@ -247,7 +223,6 @@ def test_disable_checks(): class TestPointInsideTesseroid: """Test checks for points inside tesseroids.""" - @pytest.mark.use_numba def test_points_outside_tesseroid(self): """Check if error is not raised when no point is inside a tesseroid.""" points = np.array( @@ -266,7 +241,6 @@ def test_points_outside_tesseroid(self): tesseroid = np.atleast_2d([-10, 10, -10, 10, 100, 200]) check_points_outside_tesseroids(points, tesseroid) - @pytest.mark.use_numba @pytest.mark.parametrize("points", [[0, 0, 150], [360, 0, 150]]) def test_point_inside_tesseroid(self, points): """Check if error is raised when point fall inside the tesseroid.""" @@ -276,7 +250,6 @@ def test_point_inside_tesseroid(self, points): with pytest.raises(ValueError, match=msg): check_points_outside_tesseroids(points, tesseroid) - @pytest.mark.use_numba @pytest.mark.parametrize( ("point", "tesseroid"), [ @@ -292,7 +265,6 @@ def test_point_phased_longitude(self, point, tesseroid): with pytest.raises(ValueError, match=msg): check_points_outside_tesseroids(point, tesseroid) - @pytest.mark.use_numba def test_multiple_points_and_tesseroids(self): """Check if error is raised with multiple points and tesseroids.""" tesseroids = np.atleast_2d( @@ -314,7 +286,6 @@ def test_multiple_points_and_tesseroids(self): check_points_outside_tesseroids(points, tesseroids) -@pytest.mark.use_numba def test_stack_overflow_on_adaptive_discretization(): """Test if _adaptive_discretization raises OverflowError on stack overflow.""" tesseroid = np.array([-10.0, 10.0, -10.0, 10.0, 0.5, 1.0]) @@ -374,7 +345,6 @@ def test_discard_null_tesseroids(): # -------------------------------------- # Test tesseroid distance and dimensions # -------------------------------------- -@pytest.mark.use_numba def test_distance_tesseroid_point(): """Test distance between tesseroid and computation point.""" ellipsoid = boule.WGS84 @@ -409,7 +379,6 @@ def test_distance_tesseroid_point(): npt.assert_allclose(_distance_tesseroid_point(point, tesseroid), distance) -@pytest.mark.use_numba def test_tesseroid_dimensions(): """Test calculation of tesseroid dimensions.""" # Tesseroid on equator @@ -462,7 +431,6 @@ def test_longitude_continuity_equivalent_tesseroids(field): # --------------------- # Test tesseroid splits # --------------------- -@pytest.mark.use_numba def test_split_tesseroid(): """Test splitting of a tesseroid on every direction.""" lon_indexes, lat_indexes, radial_indexes = [0, 1], [2, 3], [4, 5] @@ -482,7 +450,6 @@ def test_split_tesseroid(): assert not (splitted[0, radial_indexes] == splitted[:, radial_indexes]).all() -@pytest.mark.use_numba def test_split_tesseroid_only_longitude(): """Test splitting of a tesseroid only on longitude.""" lon_indexes, lat_indexes, radial_indexes = [0, 1], [2, 3], [4, 5] @@ -508,7 +475,6 @@ def test_split_tesseroid_only_longitude(): npt.assert_allclose(lon_splitted[1], [(e + w) / 2, e]) -@pytest.mark.use_numba def test_split_tesseroid_only_latitude(): """Test splitting of a tesseroid only on latitude.""" lon_indexes, lat_indexes, radial_indexes = [0, 1], [2, 3], [4, 5] @@ -534,7 +500,6 @@ def test_split_tesseroid_only_latitude(): npt.assert_allclose(lat_splitted[1], [(n + s) / 2, n]) -@pytest.mark.use_numba def test_split_tesseroid_only_radius(): """Test splitting of a tesseroid only on radius.""" lon_indexes, lat_indexes, radial_indexes = [0, 1], [2, 3], [4, 5] @@ -560,7 +525,6 @@ def test_split_tesseroid_only_radius(): npt.assert_allclose(radial_splitted[1], [(top + bottom) / 2, top]) -@pytest.mark.use_numba def test_split_tesseroid_only_horizontal(): """Test splitting of a tesseroid on horizontal directions.""" radial_indexes = [4, 5] @@ -581,9 +545,8 @@ def test_split_tesseroid_only_horizontal(): # ---------------------------- # Test adaptive discretization # ---------------------------- -@run_only_with_numba @pytest.mark.parametrize("radial_discretization", [True, False]) -def test_adaptive_discretization_on_radii(radial_discretization): # pragma: no cover +def test_adaptive_discretization_on_radii(radial_discretization): """Test if closer computation points increase the tesseroid discretization.""" tesseroid = np.array([-10.0, 10.0, -10.0, 10.0, 1.0, 10.0]) distance_size_ratio = 10 @@ -612,11 +575,10 @@ def test_adaptive_discretization_on_radii(radial_discretization): # pragma: no assert number_of_splits[i - 1] >= number_of_splits[i] -@run_only_with_numba @pytest.mark.parametrize("radial_discretization", [True, False]) def test_adaptive_discretization_vs_distance_size_ratio( radial_discretization, -): # pragma: no cover +): """Test if higher distance-size-ratio increase the tesseroid discretization.""" tesseroid = np.array([-10.0, 10.0, -10.0, 10.0, 1.0, 10.0]) coordinates = np.array([0.0, 0.0, 10.2]) @@ -638,8 +600,7 @@ def test_adaptive_discretization_vs_distance_size_ratio( assert number_of_splits[i - 1] <= number_of_splits[i] -@run_only_with_numba -def test_two_dimensional_adaptive_discretization(): # pragma: no cover +def test_two_dimensional_adaptive_discretization(): """ Test if 2D adaptive discretization produces no splits on radial direction. """ @@ -661,9 +622,7 @@ def test_two_dimensional_adaptive_discretization(): # pragma: no cover # ------------------------------------------------------------------ # Compare numerical result vs analytical solution of spherical shell # ------------------------------------------------------------------ -def spherical_shell_analytical( - top, bottom, density, radius -): # pragma: no cover (only used by @run_only_with_numba tests) +def spherical_shell_analytical(top, bottom, density, radius): """ Compute analytical solution of gravity fields for an homogeneous spherical shell. @@ -679,9 +638,8 @@ def spherical_shell_analytical( return analytical -@run_only_with_numba @pytest.mark.parametrize("field", ["potential", "g_z"]) -def test_spherical_shell_two_dim_adaptive_discret(field): # pragma: no cover +def test_spherical_shell_two_dim_adaptive_discret(field): """ Compare numerical result with analytical solution for 2D adaptive discretization. @@ -725,12 +683,9 @@ def test_spherical_shell_two_dim_adaptive_discret(field): # pragma: no cover ) -@run_only_with_numba @pytest.mark.parametrize("field", ["potential", "g_z"]) @pytest.mark.parametrize("thickness", [10, 100, 1e3, 1e4, 1e5]) -def test_spherical_shell_three_dim_adaptive_discret( - thickness, field -): # pragma: no cover +def test_spherical_shell_three_dim_adaptive_discret(thickness, field): """ Compare numerical result with analytical solution for 3D adaptive discretization. @@ -794,7 +749,6 @@ def coordinates(self): return coordinates @pytest.mark.skipif(ProgressBar is None, reason="requires numba_progress") - @pytest.mark.use_numba @pytest.mark.parametrize("field", ["potential", "g_z"]) def test_progress_bar(self, coordinates, tesseroids, densities, field): """ diff --git a/test/test_tesseroid_layer.py b/test/test_tesseroid_layer.py index 40f18badc..97ca57d1e 100644 --- a/test/test_tesseroid_layer.py +++ b/test/test_tesseroid_layer.py @@ -382,7 +382,6 @@ def test_nonans_tesseroid_mask_property( npt.assert_allclose(mask, expected_mask) -@pytest.mark.use_numba @pytest.mark.parametrize("field", ["potential", "g_z"]) def test_tesseroid_layer_gravity(field, dummy_layer): """ @@ -407,7 +406,6 @@ def test_tesseroid_layer_gravity(field, dummy_layer): ) -@pytest.mark.use_numba @pytest.mark.parametrize("field", ["potential", "g_z"]) def test_tesseroid_layer_gravity_surface_nans( field, dummy_layer, tesseroid_layer_with_holes @@ -438,7 +436,6 @@ def test_tesseroid_layer_gravity_surface_nans( ) -@pytest.mark.use_numba @pytest.mark.parametrize("field", ["potential", "g_z"]) def test_tesseroid_layer_gravity_density_nans( field, dummy_layer, tesseroid_layer_with_holes @@ -470,7 +467,6 @@ def test_tesseroid_layer_gravity_density_nans( @pytest.mark.skipif(ProgressBar is None, reason="requires numba_progress") -@pytest.mark.use_numba def test_progress_bar(dummy_layer): """ Check if forward gravity results with and without progress bar match. diff --git a/test/test_tesseroid_variable_density.py b/test/test_tesseroid_variable_density.py index 7e97740a7..7225c22e2 100644 --- a/test/test_tesseroid_variable_density.py +++ b/test/test_tesseroid_variable_density.py @@ -24,8 +24,6 @@ ) from harmonica.constants import GRAVITATIONAL_CONST -from .utils import run_only_with_numba - try: from numba_progress import ProgressBar except ImportError: # pragma: no cover @@ -320,7 +318,6 @@ def stupid_constant_density( # ---------------------------------------------- -@pytest.mark.use_numba @pytest.mark.parametrize("field", ["potential", "g_z"]) def test_single_tesseroid_against_constant_density(field): """ @@ -358,9 +355,7 @@ def constant_density( # ---------------------------- -def analytical_spherical_shell_linear( - radius, bottom, top, slope, constant_term -): # pragma: no cover (only used by @run_only_with_numba tests) +def analytical_spherical_shell_linear(radius, bottom, top, slope, constant_term): """ Analytical solutions of a spherical shell with linear density. """ @@ -377,7 +372,7 @@ def analytical_spherical_shell_linear( def analytical_spherical_shell_exponential( radius, bottom, top, a_factor, b_factor, constant_term -): # pragma: no cover (only used by @run_only_with_numba tests) +): r""" Analytical solutions of a spherical shell with exponential density. @@ -412,9 +407,7 @@ def analytical_spherical_shell_exponential( return data -def build_spherical_shell( - bottom, top, shape=(6, 12) -): # pragma: no cover (only used by @run_only_with_numba tests) +def build_spherical_shell(bottom, top, shape=(6, 12)): """ Return a set of tesseroids modelling a spherical shell. @@ -440,10 +433,9 @@ def build_spherical_shell( return tesseroids -@run_only_with_numba @pytest.mark.parametrize("field", ["potential", "g_z"]) @pytest.mark.parametrize("thickness", [1e2, 1e3, 1e6]) -def test_spherical_shell_linear_density(field, thickness): # pragma: no cover +def test_spherical_shell_linear_density(field, thickness): """ Test numerical results against analytical solution for linear density. """ @@ -481,13 +473,10 @@ def linear_density(radius): ) -@run_only_with_numba @pytest.mark.parametrize("field", ["potential", "g_z"]) @pytest.mark.parametrize("thickness", [1e2, 1e3, 1e6]) @pytest.mark.parametrize("b_factor", [5, 100]) -def test_spherical_shell_exponential_density( - field, thickness, b_factor -): # pragma: no cover +def test_spherical_shell_exponential_density(field, thickness, b_factor): """ Test numerical results against analytical solution for exponential density. """ @@ -557,7 +546,6 @@ def coordinates(self): return coordinates @pytest.mark.skipif(ProgressBar is None, reason="requires numba_progress") - @pytest.mark.use_numba @pytest.mark.parametrize("field", ["potential", "g_z"]) def test_progress_bar(self, coordinates, tesseroids, densities, field): """ diff --git a/test/utils.py b/test/utils.py index c81732190..6f0b2f803 100644 --- a/test/utils.py +++ b/test/utils.py @@ -8,10 +8,7 @@ Decorators and useful functions for running tests. """ -import os - import numpy as np -import pytest def root_mean_square_error(x, y): @@ -44,27 +41,3 @@ def combination(func): return func return combination - - -# Check if Numba is disabled -# (if NUMBA_DISABLE_JIT is not defined, we assume Numba jit is enabled) -NUMBA_IS_DISABLED = os.environ.get("NUMBA_DISABLE_JIT", default="0") != "0" - -# Decorator for pytest: run if Numba jit is enabled -# -# Tell pytest to run the test function only if Numba jit is enabled. To disable -# Numba jit the environmental variable ```NUMBA_DISABLE_JIT``` must be set to -# a value different than 0. -# -# Use this decorator on test functions that involve great computational load -# and don't want to run if Numba jit is disabled. The decorated test functions -# will be run and checked if pass or fail, but won't be taken into account for -# meassuring coverage. If the test function will run Numba code, but doesn't -# involve great computational load, we reccomend using the -# ``@pytest.mark.use_numba`` instead. Therefore the test function will be run -# twice: one with Numba jit enabled, and another one with Numba jit disable to -# check coverage. -run_only_with_numba = combine_decorators( - pytest.mark.skipif(NUMBA_IS_DISABLED, reason="Numba jit is disabled"), - pytest.mark.use_numba, -)