Skip to content

Commit e44313e

Browse files
committed
misc: Lint petsc branch
1 parent 53ea762 commit e44313e

19 files changed

Lines changed: 65 additions & 67 deletions

File tree

.github/workflows/lint.yaml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,9 +11,11 @@ on:
1111
push:
1212
branches:
1313
- main
14+
- petsc
1415
pull_request:
1516
branches:
1617
- main
18+
- petsc
1719

1820
jobs:
1921
codelint:

devito/petsc/config.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -78,7 +78,7 @@ def get_petsc_type_mappings():
7878
petsc_type_to_ctype = {v: k for k, v in printer_mapper.items()}
7979
# Add other PETSc types
8080
petsc_type_to_ctype.update({
81-
# Store a copy so it doens't segfault after SNESDestroy
81+
# Store a copy so it doesn't segfault after SNESDestroy
8282
'KSPType': ctypes.c_char * KSPTYPE_MAX_LEN,
8383
'KSPConvergedReason': petsc_type_to_ctype['PetscInt'],
8484
'KSPNormType': petsc_type_to_ctype['PetscInt'],

devito/petsc/iet/builder.py

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,8 @@ def _setup(self):
6868
)
6969

7070
local_size = math.prod(
71-
v for v, dim in zip(target.shape_allocated, target.dimensions) if dim.is_Space
71+
v for v, dim in zip(target.shape_allocated, target.dimensions, strict=True)
72+
if dim.is_Space
7273
)
7374
# TODO: Check - VecCreateSeqWithArray vs VecCreateMPIWithArray
7475
local_x = petsc_call('VecCreateSeqWithArray',
@@ -104,7 +105,7 @@ def _setup(self):
104105

105106
dmda_calls = self._create_dmda_calls(dmda)
106107

107-
# TODO: maybe don't need to explictly set this
108+
# TODO: maybe don't need to explicitly set this
108109
mat_set_dm = petsc_call('MatSetDM', [sobjs['Jac'], dmda])
109110

110111
base_setup = dmda_calls + (
@@ -252,7 +253,7 @@ def _setup(self):
252253

253254
dmda_calls = self._create_dmda_calls(dmda)
254255

255-
# TODO: maybe don't need to explictly set this
256+
# TODO: maybe don't need to explicitly set this
256257
mat_set_dm = petsc_call('MatSetDM', [sobjs['Jac'], dmda])
257258

258259
create_field_decomp = petsc_call(
@@ -299,7 +300,8 @@ def _setup(self):
299300
for t in targets:
300301
target_xloc = sobjs[f'xlocal{t.name}']
301302
local_size = math.prod(
302-
v for v, dim in zip(t.shape_allocated, t.dimensions) if dim.is_Space
303+
v for v, dim in zip(t.shape_allocated, t.dimensions, strict=True)
304+
if dim.is_Space
303305
)
304306
field_from_ptr = FieldFromPointer(
305307
t.function._C_field_data, t.function._C_symbol

devito/petsc/iet/callbacks.py

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -28,8 +28,8 @@ class BaseCallbackBuilder:
2828
"""
2929
def __init__(self, **kwargs):
3030

31-
self.rcompile = kwargs.get('rcompile', None)
32-
self.sregistry = kwargs.get('sregistry', None)
31+
self.rcompile = kwargs.get('rcompile')
32+
self.sregistry = kwargs.get('sregistry')
3333
self.options = kwargs.get('options', {})
3434
self.concretize_mapper = kwargs.get('concretize_mapper', {})
3535
self.time_dependence = kwargs.get('time_dependence')
@@ -148,7 +148,7 @@ def _make_options_callback(self):
148148
"""
149149
Create two callbacks: one to set PETSc options and one
150150
to clear them.
151-
Options are only set/cleared if they were not specifed via
151+
Options are only set/cleared if they were not specified via
152152
command line arguments.
153153
"""
154154
params = self.solver_parameters
@@ -574,7 +574,7 @@ def _make_initial_guess(self):
574574
sobjs = self.solver_objs
575575
objs = self.objs
576576

577-
# Compile initital guess `eqns` into an IET via recursive compilation
577+
# Compile initial guess `eqns` into an IET via recursive compilation
578578
irs, _ = self.rcompile(
579579
exprs, options={'mpi': False}, sregistry=self.sregistry,
580580
concretize_mapper=self.concretize_mapper
@@ -1335,7 +1335,7 @@ def residual_bundle(self, body, bundles):
13351335

13361336

13371337
def populate_matrix_context(efuncs):
1338-
if not objs['dummyefunc'] in efuncs.values():
1338+
if objs['dummyefunc'] not in efuncs.values():
13391339
return
13401340

13411341
subdms_expr = DummyExpr(

devito/petsc/iet/logging.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ def __init__(self, level, **kwargs):
2020
self.sobjs = kwargs.get('solver_objs')
2121
self.sreg = kwargs.get('sregistry')
2222
self.section_mapper = kwargs.get('section_mapper', {})
23-
self.inject_solve = kwargs.get('inject_solve', None)
23+
self.inject_solve = kwargs.get('inject_solve')
2424

2525
if level <= PERF:
2626
funcs = [

devito/petsc/iet/nodes.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,13 +18,13 @@ class MatShellSetOp(Callback):
1818
@property
1919
def callback_form(self):
2020
param_types_str = ', '.join([str(t) for t in self.param_types])
21-
return "(%s (*)(%s))%s" % (self.retval, param_types_str, self.name)
21+
return f"({self.retval} (*)({param_types_str})){self.name}"
2222

2323

2424
class FormFunctionCallback(Callback):
2525
@property
2626
def callback_form(self):
27-
return "%s" % self.name
27+
return f'{self.name}'
2828

2929

3030
class PETScCall(Call):

devito/petsc/iet/passes.py

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -168,10 +168,7 @@ def linear_indices(iet, **kwargs):
168168
if not iet.name.startswith("SetPointBCs"):
169169
return iet, {}
170170

171-
if kwargs['options']['index-mode'] == 'int32':
172-
dtype = np.int32
173-
else:
174-
dtype = np.int64
171+
dtype = np.int32 if kwargs['options']['index-mode'] == 'int32' else np.int64
175172

176173
tracker = Tracker('basic', dtype, kwargs['sregistry'])
177174

devito/petsc/iet/time_dependence.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -80,7 +80,7 @@ def is_target_time(self, target):
8080

8181
def target_time(self, target):
8282
target_time = [
83-
i for i, d in zip(target.indices, target.dimensions)
83+
i for i, d in zip(target.indices, target.dimensions, strict=True)
8484
if d.is_Time
8585
]
8686
assert len(target_time) == 1

devito/petsc/iet/type_builder.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -149,7 +149,7 @@ def _extend_build(self, base_dict):
149149
)
150150

151151
# Build the bundle mapper
152-
for f_arr, x_arr in zip(f_components, x_components):
152+
for f_arr, x_arr in zip(f_components, x_components, strict=True):
153153
bundle_mapper[f_arr.base] = fbundle
154154
bundle_mapper[x_arr.base] = xbundle
155155

devito/petsc/logging.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -77,7 +77,7 @@ def petsc_entry(self, petscinfo):
7777
petsc_return_variable_dict[f].name for f in petscinfo.query_functions
7878
]
7979
values = [getattr(petscinfo, c) for c in funcs]
80-
return PetscEntry(**{k: v for k, v in zip(funcs, values)})
80+
return PetscEntry(**{k: v for k, v in zip(funcs, values, strict=True)})
8181

8282
def _add_properties(self):
8383
"""
@@ -174,7 +174,7 @@ def _C_typedecl(self):
174174
entries = []
175175
for field in self._fields:
176176
if str(field.dtype) == 'KSPType':
177-
entries.append(Value('char', '%s[%d]' % (field.name, KSPTYPE_MAX_LEN)))
177+
entries.append(Value('char', f'{field.name}[{KSPTYPE_MAX_LEN}]'))
178178
else:
179179
entries.append(Value(str(field.dtype), field.name))
180180
return Struct(self.dtype._type_.__name__, entries)

0 commit comments

Comments
 (0)