Skip to content

Commit e4cc270

Browse files
committed
Merge remote-tracking branch 'origin/master' into neuralpint
2 parents f8699d9 + 42ddf1a commit e4cc270

File tree

55 files changed

+625
-120
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

55 files changed

+625
-120
lines changed

.github/workflows/ci_pipeline.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ jobs:
3939
fail-fast: false
4040
matrix:
4141
env: ['base', 'fenics', 'mpi4py', 'petsc', 'pytorch']
42-
python: ['3.9', '3.10', '3.11', '3.12', '3.13']
42+
python: ['3.10', '3.11', '3.12', '3.13']
4343
defaults:
4444
run:
4545
shell: bash -l {0}

README.md

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,8 @@
55
[![fair-software.eu](https://img.shields.io/badge/fair--software.eu-%E2%97%8F%20%20%E2%97%8F%20%20%E2%97%8F%20%20%E2%97%8F%20%20%E2%97%8F-green)](https://fair-software.eu)
66
[![SQAaaS badge shields.io](https://img.shields.io/badge/sqaaas%20software-silver-lightgrey)](https://api.eu.badgr.io/public/assertions/aS8J0NDTTjCyYP6iVufviQ "SQAaaS silver badge achieved")
77
[![PyPI - Downloads](https://img.shields.io/pypi/dm/pySDC?logo=pypi)](https://pypistats.org/packages/pysdc)
8+
[![HiRSE Code Promo Badge](https://img.shields.io/badge/Promo-8db427?label=HiRSE&labelColor=005aa0&link=https%3A%2F%2Fgo.fzj.de%2FCodePromo)](https://go.fzj.de/CodePromo)
9+
[![SWH](https://archive.softwareheritage.org/badge/origin/https://github.com/Parallel-in-Time/pySDC/)](https://archive.softwareheritage.org/browse/origin/?origin_url=https://github.com/Parallel-in-Time/pySDC)
810

911
# Welcome to pySDC!
1012

@@ -33,7 +35,7 @@ implemented.
3335
- Continuous integration via [GitHub
3436
Actions](https://github.com/Parallel-in-Time/pySDC/actions) and
3537
[Gitlab CI](https://gitlab.hzdr.de/r.speck/pysdc/-/pipelines) (through the [GitHub2Gitlab Action](https://github.com/jakob-fritz/github2lab_action))
36-
- Fully compatible with Python 3.9 - 3.12, runs at least on Ubuntu
38+
- Fully compatible with Python 3.10 - 3.13, runs at least on Ubuntu
3739

3840
## Getting started
3941

pySDC/helpers/blocks.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -102,7 +102,7 @@ def ranks(self):
102102
@property
103103
def localBounds(self):
104104
iLocList, nLocList = [], []
105-
for rank, nPoints, nBlocks in zip(self.ranks, self.gridSizes, self.nBlocks):
105+
for rank, nPoints, nBlocks in zip(self.ranks, self.gridSizes, self.nBlocks, strict=True):
106106
n0 = nPoints // nBlocks
107107
nRest = nPoints - nBlocks * n0
108108
nLoc = n0 + 1 * (rank < nRest)

pySDC/helpers/fieldsIO.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -159,7 +159,8 @@ def fromFile(cls, fileName):
159159
fieldsIO : :class:`FieldsIO`
160160
The specialized `FieldsIO` adapted to the file.
161161
"""
162-
assert os.path.isfile(fileName), f"not a file ({fileName})"
162+
if not os.path.isfile(fileName):
163+
raise FileNotFoundError(f"not a file ({fileName})")
163164
with open(fileName, "rb") as f:
164165
STRUCT, DTYPE = np.fromfile(f, dtype=H_DTYPE, count=2)
165166
fieldsIO: FieldsIO = cls.STRUCTS[STRUCT](DTYPES[DTYPE], fileName)
@@ -719,7 +720,7 @@ def writeFields_MPI(fileName, dtypeIdx, algo, nSteps, nVar, gridSizes):
719720

720721
iLoc, nLoc = blocks.localBounds
721722
Rectilinear.setupMPI(comm, iLoc, nLoc)
722-
s = [slice(i, i + n) for i, n in zip(iLoc, nLoc)]
723+
s = [slice(i, i + n) for i, n in zip(iLoc, nLoc, strict=True)]
723724
u0 = u0[(slice(None), *s)]
724725

725726
f1 = Rectilinear(DTYPES[dtypeIdx], fileName)

pySDC/helpers/plot_helper.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,13 +45,15 @@ def figsize_by_journal(journal, scale, ratio): # pragma: no cover
4545
'Springer_proceedings': 347.12354,
4646
'JSC_thesis': 434.26027,
4747
'TUHH_thesis': 426.79135,
48+
'Nature_CS': 372.0,
4849
}
4950
# store text height in points here, get this from LaTeX using \the\textheight
5051
textheights = {
5152
'JSC_beamer': 214.43411,
5253
'JSC_thesis': 635.5,
5354
'TUHH_thesis': 631.65118,
5455
'Springer_proceedings': 549.13828,
56+
'Nature_CS': 552.69478,
5557
}
5658
assert (
5759
journal in textwidths.keys()

pySDC/helpers/spectral_helper.py

Lines changed: 32 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -97,6 +97,7 @@ def __init__(self, N, x0=None, x1=None, useGPU=False, useFFTW=False):
9797

9898
if useGPU:
9999
self.setup_GPU()
100+
self.logger.debug('Set up for GPU')
100101
else:
101102
self.setup_CPU(useFFTW=useFFTW)
102103

@@ -161,6 +162,10 @@ def get_differentiation_matrix(self):
161162
def get_integration_matrix(self):
162163
raise NotImplementedError()
163164

165+
def get_integration_weights(self):
166+
"""Weights for integration across entire domain"""
167+
raise NotImplementedError()
168+
164169
def get_wavenumbers(self):
165170
"""
166171
Get the grid in spectral space
@@ -379,6 +384,16 @@ def get_integration_matrix(self, lbnd=0):
379384
raise NotImplementedError(f'This function allows to integrate only from x=0, you attempted from x={lbnd}.')
380385
return S
381386

387+
def get_integration_weights(self):
388+
"""Weights for integration across entire domain"""
389+
n = self.xp.arange(self.N, dtype=float)
390+
391+
weights = (-1) ** n + 1
392+
weights[2:] /= 1 - (n**2)[2:]
393+
394+
weights /= 2 / self.L
395+
return weights
396+
382397
def get_differentiation_matrix(self, p=1):
383398
'''
384399
Keep in mind that the T2T differentiation matrix is dense.
@@ -808,6 +823,12 @@ def get_integration_matrix(self, p=1):
808823
k[0] = 1j * self.L
809824
return self.linalg.matrix_power(self.sparse_lib.diags(1 / (1j * k)), p)
810825

826+
def get_integration_weights(self):
827+
"""Weights for integration across entire domain"""
828+
weights = self.xp.zeros(self.N)
829+
weights[0] = self.L / self.N
830+
return weights
831+
811832
def get_plan(self, u, forward, *args, **kwargs):
812833
if self.fft_lib.__name__ == 'mpi4py_fft.fftw':
813834
if 'axes' in kwargs.keys():
@@ -1006,7 +1027,6 @@ def __init__(self, comm=None, useGPU=False, debug=False):
10061027
self.BCs = None
10071028

10081029
self.fft_cache = {}
1009-
self.fft_dealias_shape_cache = {}
10101030

10111031
self.logger = logging.getLogger(name='Spectral Discretization')
10121032
if debug:
@@ -1293,11 +1313,12 @@ def setup_BCs(self):
12931313

12941314
diags = self.xp.ones(self.BCs.shape[0])
12951315
diags[self.BC_zero_index] = 0
1296-
self.BC_line_zero_matrix = sp.diags(diags)
1316+
self.BC_line_zero_matrix = sp.diags(diags).tocsc()
12971317

12981318
# prepare BCs in spectral space to easily add to the RHS
12991319
rhs_BCs = self.put_BCs_in_rhs(self.u_init)
1300-
self.rhs_BCs_hat = self.transform(rhs_BCs)
1320+
self.rhs_BCs_hat = self.transform(rhs_BCs).view(self.xp.ndarray)
1321+
del self.BC_rhs_mask
13011322

13021323
def check_BCs(self, u):
13031324
"""
@@ -1350,7 +1371,7 @@ def put_BCs_in_rhs_hat(self, rhs_hat):
13501371
Generate a mask where we need to set values in the rhs in spectral space to zero, such that can replace them
13511372
by the boundary conditions. The mask is then cached.
13521373
"""
1353-
self._rhs_hat_zero_mask = self.newDistArray().astype(bool)
1374+
self._rhs_hat_zero_mask = self.newDistArray(forward_output=True).astype(bool).view(self.xp.ndarray)
13541375

13551376
for axis in range(self.ndim):
13561377
for bc in self.full_BCs:
@@ -1498,7 +1519,7 @@ def get_indices(self, forward_output=True):
14981519
def get_pfft(self, axes=None, padding=None, grid=None):
14991520
if self.ndim == 1 or self.comm is None:
15001521
return None
1501-
from mpi4py_fft import PFFT
1522+
from mpi4py_fft import PFFT, newDistArray
15021523

15031524
axes = tuple(i for i in range(self.ndim)) if axes is None else axes
15041525
padding = list(padding if padding else [1.0 for _ in range(self.ndim)])
@@ -1530,6 +1551,10 @@ def no_transform(u, *args, **kwargs):
15301551
transforms=transforms,
15311552
grid=grid,
15321553
)
1554+
1555+
# do a transform to do the planning
1556+
_u = newDistArray(pfft, forward_output=False)
1557+
pfft.backward(pfft.forward(_u))
15331558
return pfft
15341559

15351560
def get_fft(self, axes=None, direction='object', padding=None, shape=None):
@@ -1885,6 +1910,7 @@ def get_differentiation_matrix(self, axes, **kwargs):
18851910
_D = self.axes[axis].get_differentiation_matrix(**kwargs)
18861911
D = D @ self.expand_matrix_ND(_D, axis)
18871912

1913+
self.logger.debug(f'Set up differentiation matrix along axes {axes} with kwargs {kwargs}')
18881914
return D
18891915

18901916
def get_integration_matrix(self, axes):
@@ -1948,4 +1974,5 @@ def get_basis_change_matrix(self, axes=None, **kwargs):
19481974
_C = self.axes[axis].get_basis_change_matrix(**kwargs)
19491975
C = C @ self.expand_matrix_ND(_C, axis)
19501976

1977+
self.logger.debug(f'Set up basis change matrix along axes {axes} with kwargs {kwargs}')
19511978
return C

pySDC/helpers/transfer_helper.py

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ def next_neighbors_periodic(p, ps, k):
2727

2828
# zip it
2929
value_index = []
30-
for d, i in zip(distance_to_p, range(distance_to_p.size)):
30+
for d, i in zip(distance_to_p, range(distance_to_p.size), strict=True):
3131
value_index.append((d, i))
3232
# sort by distance
3333
value_index_sorted = sorted(value_index, key=lambda s: s[0])
@@ -53,7 +53,7 @@ def next_neighbors(p, ps, k):
5353
distance_to_p = np.abs(ps - p)
5454
# zip it
5555
value_index = []
56-
for d, i in zip(distance_to_p, range(distance_to_p.size)):
56+
for d, i in zip(distance_to_p, range(distance_to_p.size), strict=True):
5757
value_index.append((d, i))
5858
# sort by distance
5959
value_index_sorted = sorted(value_index, key=lambda s: s[0])
@@ -80,7 +80,7 @@ def continue_periodic_array(arr, nn):
8080
else:
8181
cont_arr = [arr[nn[0]]]
8282
shift = 0.0
83-
for n, d in zip(nn[1:], d_nn):
83+
for n, d in zip(nn[1:], d_nn, strict=True):
8484
if d != 1:
8585
shift = -1
8686
cont_arr.append(arr[n] + shift)
@@ -107,7 +107,7 @@ def restriction_matrix_1d(fine_grid, coarse_grid, k=2, periodic=False, pad=1):
107107

108108
if periodic:
109109
M = np.zeros((coarse_grid.size, fine_grid.size))
110-
for i, p in zip(range(n_g), coarse_grid):
110+
for i, p in zip(range(n_g), coarse_grid, strict=True):
111111
nn = next_neighbors_periodic(p, fine_grid, k)
112112
circulating_one = np.asarray([1.0] + [0.0] * (k - 1))
113113
cont_arr = continue_periodic_array(fine_grid, nn)
@@ -120,7 +120,7 @@ def restriction_matrix_1d(fine_grid, coarse_grid, k=2, periodic=False, pad=1):
120120
M[i, nn] = np.asarray(list(map(lambda x: x(p), bary_pol)))
121121
else:
122122
M = np.zeros((coarse_grid.size, fine_grid.size + 2 * pad))
123-
for i, p in zip(range(n_g), coarse_grid):
123+
for i, p in zip(range(n_g), coarse_grid, strict=True):
124124
padded_f_grid = border_padding(fine_grid, pad, pad)
125125
nn = next_neighbors(p, padded_f_grid, k)
126126
# construct the lagrange polynomials for the k neighbors
@@ -158,7 +158,7 @@ def interpolation_matrix_1d(fine_grid, coarse_grid, k=2, periodic=False, pad=1,
158158
M = np.zeros((fine_grid.size, coarse_grid.size))
159159

160160
if equidist_nested:
161-
for i, p in zip(range(n_f), fine_grid):
161+
for i, p in zip(range(n_f), fine_grid, strict=True):
162162
if i % 2 == 0:
163163
M[i, int(i / 2)] = 1.0
164164
else:
@@ -189,7 +189,7 @@ def interpolation_matrix_1d(fine_grid, coarse_grid, k=2, periodic=False, pad=1,
189189
M[i, nn] = np.asarray(list(map(lambda x: x(p), bary_pol)))
190190

191191
else:
192-
for i, p in zip(range(n_f), fine_grid):
192+
for i, p in zip(range(n_f), fine_grid, strict=True):
193193
nn = next_neighbors_periodic(p, coarse_grid, k)
194194
circulating_one = np.asarray([1.0] + [0.0] * (k - 1))
195195
cont_arr = continue_periodic_array(coarse_grid, nn)
@@ -208,7 +208,7 @@ def interpolation_matrix_1d(fine_grid, coarse_grid, k=2, periodic=False, pad=1,
208208
padded_c_grid = border_padding(coarse_grid, pad, pad)
209209

210210
if equidist_nested:
211-
for i, p in zip(range(n_f), fine_grid):
211+
for i, p in zip(range(n_f), fine_grid, strict=True):
212212
if i % 2 != 0:
213213
M[i, int((i - 1) / 2) + 1] = 1.0
214214
else:
@@ -231,7 +231,7 @@ def interpolation_matrix_1d(fine_grid, coarse_grid, k=2, periodic=False, pad=1,
231231
M[i, nn] = np.asarray(list(map(lambda x: x(p), bary_pol)))
232232

233233
else:
234-
for i, p in zip(range(n_f), fine_grid):
234+
for i, p in zip(range(n_f), fine_grid, strict=True):
235235
nn = next_neighbors(p, padded_c_grid, k)
236236
# construct the lagrange polynomials for the k neighbors
237237
circulating_one = np.asarray([1.0] + [0.0] * (k - 1))

pySDC/helpers/vtkIO.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@ def field(u):
5252
return numpy_support.numpy_to_vtk(num_array=u.ravel(order='F'), deep=True, array_type=vtk.VTK_FLOAT)
5353

5454
pointData = vtr.GetPointData()
55-
for name, u in zip(varNames, data):
55+
for name, u in zip(varNames, data, strict=True):
5656
uVTK = field(u)
5757
uVTK.SetName(name)
5858
pointData.AddArray(uVTK)

pySDC/implementations/problem_classes/AllenCahn_Temp_MPIFFT.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -134,7 +134,7 @@ def __init__(
134134
N = self.fft.global_shape()
135135
k = [np.fft.fftfreq(n, 1.0 / n).astype(int) for n in N[:-1]]
136136
k.append(np.fft.rfftfreq(N[-1], 1.0 / N[-1]).astype(int))
137-
K = [ki[si] for ki, si in zip(k, s)]
137+
K = [ki[si] for ki, si in zip(k, s, strict=True)]
138138
Ks = list(np.meshgrid(*K, indexing='ij', sparse=True))
139139
Lp = 2 * np.pi / L
140140
for i in range(ndim):

pySDC/implementations/problem_classes/Brusselator.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -178,7 +178,7 @@ def plot(self, u, t=None, fig=None): # pragma: no cover
178178

179179
vmin = u.min()
180180
vmax = u.max()
181-
for i, label in zip([self.iU, self.iV], [r'$u$', r'$v$']):
181+
for i, label in zip([self.iU, self.iV], [r'$u$', r'$v$'], strict=True):
182182
im = axs[i].pcolormesh(self.X[0], self.X[1], u[i], vmin=vmin, vmax=vmax)
183183
axs[i].set_aspect(1)
184184
axs[i].set_title(label)

0 commit comments

Comments
 (0)