Skip to content

Commit 0a5697b

Browse files
authored
Merge pull request #376 from GeoStat-Framework/outsource_cython
Outsource Cython backend
2 parents 1399d98 + 12024ba commit 0a5697b

File tree

11 files changed

+62
-721
lines changed

11 files changed

+62
-721
lines changed

.github/workflows/main.yml

Lines changed: 11 additions & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -49,48 +49,20 @@ jobs:
4949
run: |
5050
python -m pylint src/gstools/
5151
52-
- name: cython-lint check
53-
run: |
54-
cython-lint src/gstools/
55-
5652
- name: coveralls check
5753
run: |
5854
python -m pytest --cov gstools --cov-report term-missing -v tests/
5955
python -m coveralls --service=github
6056
env:
6157
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
6258

63-
build_wheels:
64-
name: wheels for ${{ matrix.os }}
59+
build:
60+
name: test on ${{ matrix.os }} with py ${{ matrix.ver.py }} numpy${{ matrix.ver.np }} scipy${{ matrix.ver.sp }}
6561
runs-on: ${{ matrix.os }}
6662
strategy:
6763
fail-fast: false
6864
matrix:
69-
# macos-13 is an intel runner, macos-14 is apple silicon
70-
os: [ubuntu-latest, windows-latest, macos-13, macos-14]
71-
72-
steps:
73-
- uses: actions/checkout@v4
74-
with:
75-
fetch-depth: "0"
76-
77-
- name: Build wheels
78-
uses: pypa/cibuildwheel@v2.22.0
79-
with:
80-
output-dir: dist-wheel-${{ matrix.os }}
81-
82-
- uses: actions/upload-artifact@v4
83-
with:
84-
name: dist-wheel-${{ matrix.os }}
85-
path: ./dist-wheel-${{ matrix.os }}/*.whl
86-
87-
build_sdist:
88-
name: sdist on ${{ matrix.os }} with py ${{ matrix.ver.py }} numpy${{ matrix.ver.np }} scipy${{ matrix.ver.sp }}
89-
runs-on: ${{ matrix.os }}
90-
strategy:
91-
fail-fast: false
92-
matrix:
93-
os: [ubuntu-latest, windows-latest, macos-13, macos-14]
65+
os: [ubuntu-latest, ubuntu-24.04-arm, windows-latest, macos-13, macos-14]
9466
# https://github.com/scipy/oldest-supported-numpy/blob/main/setup.cfg
9567
ver:
9668
- { py: "3.8", np: "==1.20.0", sp: "==1.5.4" }
@@ -101,6 +73,8 @@ jobs:
10173
- { py: "3.13", np: "==2.1.0", sp: "==1.14.1" }
10274
- { py: "3.13", np: ">=2.1.0", sp: ">=1.14.1" }
10375
exclude:
76+
- os: ubuntu-24.04-arm
77+
ver: { py: "3.8", np: "==1.20.0", sp: "==1.5.4" }
10478
- os: macos-14
10579
ver: { py: "3.8", np: "==1.20.0", sp: "==1.5.4" }
10680
- os: macos-14
@@ -123,8 +97,6 @@ jobs:
12397
pip install build
12498
12599
- name: Install GSTools
126-
env:
127-
GSTOOLS_BUILD_PARALLEL: 1
128100
run: |
129101
pip install -v --editable .[test]
130102
@@ -133,27 +105,25 @@ jobs:
133105
pip install "numpy${{ matrix.ver.np }}" "scipy${{ matrix.ver.sp }}"
134106
python -m pytest -v tests/
135107
136-
- name: Build sdist
108+
- name: Build dist
137109
run: |
138110
# PEP 517 package builder from pypa
139-
python -m build --sdist --outdir dist-sdist .
111+
python -m build .
140112
141113
- uses: actions/upload-artifact@v4
142114
if: matrix.os == 'ubuntu-latest' && matrix.ver.py == '3.11'
143115
with:
144-
name: dist-sdist
145-
path: dist-sdist/*.tar.gz
116+
name: dist
117+
path: dist/*
146118

147119
upload_to_pypi:
148-
needs: [build_wheels, build_sdist]
120+
needs: [build]
149121
runs-on: ubuntu-latest
150122

151123
steps:
152124
- uses: actions/download-artifact@v4
153125
with:
154-
pattern: dist-*
155-
merge-multiple: true
156-
path: dist
126+
name: dist
157127

158128
- name: Publish to Test PyPI
159129
# only if working on main

MANIFEST.in

Lines changed: 0 additions & 4 deletions
This file was deleted.

docs/source/index.rst

Lines changed: 16 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -88,38 +88,33 @@ When using conda, the parallel version of GSTools is installed per default.
8888

8989
***Parallelizing Cython***
9090

91-
To enable the OpenMP support in Cython when using pip, you have to provide a C
92-
compiler and OpenMP. Parallel support is controlled by an environment variable
93-
``GSTOOLS_BUILD_PARALLEL``, that can be ``0`` or ``1`` (interpreted as ``0``
94-
if not present). GSTools then needs to be installed from source:
91+
For parallel support, the `GSTools-Cython <https://github.com/GeoStat-Framework/GSTools-Cython>`_
92+
backend needs to be compiled from source the following way:
9593

9694
.. code-block:: none
9795
9896
export GSTOOLS_BUILD_PARALLEL=1
99-
pip install --no-binary=gstools gstools
97+
pip install --no-binary=gstools-cython gstools
10098
101-
Note, that the ``--no-binary=gstools`` option forces pip to not use a wheel
102-
for GSTools.
99+
You have to provide a C compiler and OpenMP to compile GSTools-Cython with parallel support.
100+
The feature is controlled by the environment variable
101+
``GSTOOLS_BUILD_PARALLEL``, that can be ``0`` or ``1`` (interpreted as ``0`` if not present).
102+
Note, that the ``--no-binary=gstools-cython`` option forces pip to not use a wheel
103+
for the GSTools-Cython backend.
103104

104105
For the development version, you can do almost the same:
105106

106107
.. code-block:: none
107108
108109
export GSTOOLS_BUILD_PARALLEL=1
110+
pip install git+git://github.com/GeoStat-Framework/GSTools-Cython.git@main
109111
pip install git+git://github.com/GeoStat-Framework/GSTools.git@main
110112
111113
112114
***Using GSTools-Core for parallelization and even more speed***
113115

114116
You can install the optional dependency `GSTools-Core <https://github.com/GeoStat-Framework/GSTools-Core>`_,
115-
which is a re-implementation of the algorithms used in GSTools. The new
116-
package uses the language Rust and it should be faster (in some cases by orders
117-
of magnitude), safer, and it will potentially completely replace the current
118-
standard implementation in Cython. Once the package GSTools-Core is available
119-
on your machine, it will be used by default. In case you want to switch back to
120-
the Cython implementation, you can set
121-
:code:`gstools.config.USE_GSTOOLS_CORE=False` in your code. This also works at
122-
runtime. You can install the optional dependency e.g. by
117+
which is a re-implementation of GSTools-Cython:
123118

124119
.. code-block:: none
125120
@@ -131,8 +126,12 @@ or by manually installing the package
131126
132127
pip install gstools-core
133128
134-
GSTools-Core will automatically run in parallel, without having to use provide
135-
OpenMP or a local C compiler.
129+
The new package uses the language Rust and it should be safer and faster (in some cases by orders of magnitude).
130+
Once the package GSTools-Core is available on your machine, it will be used by default.
131+
In case you want to switch back to the Cython implementation, you can set
132+
:code:`gstools.config.USE_GSTOOLS_CORE=False` in your code. This also works at runtime.
133+
134+
GSTools-Core will automatically run in parallel, without having to provide OpenMP or a local C compiler.
136135

137136

138137
Citation

pyproject.toml

Lines changed: 24 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,11 @@
1+
2+
13
[build-system]
24
requires = [
3-
"setuptools>=64",
4-
"setuptools_scm>=7",
5-
"numpy>=2.0.0rc1,<2.3; python_version >= '3.9'",
6-
"oldest-supported-numpy; python_version < '3.9'",
7-
"Cython>=3.0.10,<3.1.0",
8-
"extension-helpers>=1",
5+
"hatchling>=1.8.0",
6+
"hatch-vcs",
97
]
10-
build-backend = "setuptools.build_meta"
8+
build-backend = "hatchling.build"
119

1210
[project]
1311
requires-python = ">=3.8"
@@ -17,7 +15,7 @@ authors = [
1715
{name = "Sebastian Müller, Lennart Schüler", email = "info@geostat-framework.org"},
1816
]
1917
readme = "README.md"
20-
license = {text = "LGPL-3.0"}
18+
license = "LGPL-3.0"
2119
dynamic = ["version"]
2220
classifiers = [
2321
"Development Status :: 5 - Production/Stable",
@@ -47,6 +45,7 @@ classifiers = [
4745
"Topic :: Utilities",
4846
]
4947
dependencies = [
48+
"gstools-cython>=1,<2",
5049
"emcee>=3.0.0",
5150
"hankel>=1.0.0",
5251
"meshio>=5.1.0",
@@ -78,7 +77,6 @@ lint = [
7877
"black>=24",
7978
"pylint",
8079
"isort[colors]",
81-
"cython-lint",
8280
]
8381

8482
[project.urls]
@@ -89,14 +87,25 @@ Homepage = "https://geostat-framework.org/#gstools"
8987
Source = "https://github.com/GeoStat-Framework/GSTools"
9088
Tracker = "https://github.com/GeoStat-Framework/GSTools/issues"
9189

92-
[tool.setuptools]
93-
license-files = ["LICENSE"]
90+
[tool.hatch.version]
91+
source = "vcs"
92+
fallback_version = "0.0.0.dev0"
9493

95-
[tool.setuptools_scm]
96-
write_to = "src/gstools/_version.py"
97-
write_to_template = "__version__ = '{version}'"
94+
[tool.hatch.version.raw-options]
9895
local_scheme = "no-local-version"
99-
fallback_version = "0.0.0.dev0"
96+
97+
[tool.hatch.build.hooks.vcs]
98+
version-file = "src/gstools/_version.py"
99+
template = "__version__ = '{version}'"
100+
101+
[tool.hatch.build.targets.sdist]
102+
include = [
103+
"/src",
104+
"/tests",
105+
]
106+
107+
[tool.hatch.build.targets.wheel]
108+
packages = ["src/gstools"]
100109

101110
[tool.isort]
102111
profile = "black"
@@ -160,12 +169,3 @@ target-version = [
160169
max-attributes = 30
161170
max-public-methods = 80
162171
max-positional-arguments=20
163-
164-
[tool.cibuildwheel]
165-
# Switch to using build
166-
build-frontend = "build"
167-
# Disable building PyPy wheels on all platforms, 32bit for py3.10/11/12/13, musllinux builds, py3.6/7
168-
skip = ["cp36-*", "cp37-*", "pp*", "*-win32", "*-manylinux_i686", "*-musllinux_*"]
169-
# Run the package tests using `pytest`
170-
test-extras = "test"
171-
test-command = "pytest -v {package}/tests"

setup.py

Lines changed: 0 additions & 34 deletions
This file was deleted.

src/gstools/field/generator.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -20,12 +20,12 @@
2020
from copy import deepcopy as dcp
2121

2222
import numpy as np
23+
from gstools_cython.field import summate as summate_c
24+
from gstools_cython.field import summate_fourier as summate_fourier_c
25+
from gstools_cython.field import summate_incompr as summate_incompr_c
2326

2427
from gstools import config
2528
from gstools.covmodel.base import CovModel
26-
from gstools.field.summator import summate as summate_c
27-
from gstools.field.summator import summate_fourier as summate_fourier_c
28-
from gstools.field.summator import summate_incompr as summate_incompr_c
2929
from gstools.random.rng import RNG
3030
from gstools.tools.geometric import generate_grid
3131

0 commit comments

Comments
 (0)