Skip to content

Commit e1ca2c3

Browse files
committed
Silence more warnings
1 parent 473d88c commit e1ca2c3

File tree

11 files changed

+84
-63
lines changed

11 files changed

+84
-63
lines changed

base/PyNucleus_base/plot_utils.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -212,6 +212,7 @@ def myFmt(a, fmt):
212212

213213

214214
def formatScientificLatex(a, useEnotation=True):
215+
import numpy as np
215216
if abs(a) > 0:
216217
exp = int(np.floor(np.log10(a)))
217218
mantissa = a/10**exp

base/PyNucleus_base/solver_factory.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,9 @@ def build(self, name, **kwargs):
5656
kwargs.pop('A', None)
5757
hierarchy = kwargs.pop('hierarchy')
5858
smoother = kwargs.pop('smoother', 'jacobi')
59-
if not isinstance(hierarchy, list) and isinstance(hierarchy.builtHierarchies[-1].algebraicLevels[-1].A, ComplexLinearOperator) and self.multiLevelSolverFactory.isRegistered('complex_'+name):
59+
if (not isinstance(hierarchy, list) and
60+
isinstance(hierarchy.builtHierarchies[-1].algebraicLevels[-1].A, ComplexLinearOperator) and
61+
self.multiLevelSolverFactory.isRegistered('complex_'+name)):
6062
name = 'complex_'+name
6163
solver = self.multiLevelSolverFactory.build(name, hierarchy, smoother, **kwargs)
6264
else:

base/PyNucleus_base/utilsFem.py

Lines changed: 37 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -262,20 +262,20 @@ def saveDictToHDF5(params, f, ignore=set()):
262262
if isinstance(val[0], list) and isinstance(val[0][0], (int, float, INDEX, REAL)):
263263
g = f.create_group(key)
264264
g.attrs['type'] = 'compressedList'
265-
l = 0
265+
listItems = 0
266266
for i in range(len(val)):
267-
l += len(val[i])
267+
listItems += len(val[i])
268268
indptr = uninitialized((len(val)+1), dtype=INDEX)
269269
if isinstance(val[0][0], (int, INDEX)):
270-
data = uninitialized((l), dtype=INDEX)
270+
data = uninitialized((listItems), dtype=INDEX)
271271
else:
272-
data = uninitialized((l), dtype=REAL)
273-
l = 0
272+
data = uninitialized((listItems), dtype=REAL)
273+
listItems = 0
274274
for i in range(len(val)):
275-
indptr[i] = l
276-
data[l:l+len(val[i])] = val[i]
277-
l += len(val[i])
278-
indptr[-1] = l
275+
indptr[i] = listItems
276+
data[listItems:listItems+len(val[i])] = val[i]
277+
listItems += len(val[i])
278+
indptr[-1] = listItems
279279
g.create_dataset('indptr', data=indptr)
280280
g.create_dataset('data', data=data)
281281
elif isinstance(val[0], str):
@@ -325,20 +325,20 @@ def loadDictFromHDF5(f):
325325
if isinstance(f[key], h5py.Group):
326326
if 'type' in f[key].attrs:
327327
if f[key].attrs['type'] == 'list':
328-
l = []
328+
myList = []
329329
for k in range(len(f[key].attrs)-1):
330-
l.append(f[key].attrs[str(k)])
331-
params[key] = l
330+
myList.append(f[key].attrs[str(k)])
331+
params[key] = myList
332332
elif f[key].attrs['type'] == 'compressedList':
333-
l = []
333+
myCompressedList = []
334334
indptr = np.array(f[key]['indptr'], dtype=INDEX)
335335
if isinstance(f[key]['data'], (int, INDEX)):
336336
data = np.array(f[key]['data'], dtype=INDEX)
337337
else:
338338
data = np.array(f[key]['data'], dtype=REAL)
339339
for i in range(len(indptr)-1):
340-
l.append(data[indptr[i]:indptr[i+1]].tolist())
341-
params[key] = l
340+
myCompressedList.append(data[indptr[i]:indptr[i+1]].tolist())
341+
params[key] = myCompressedList
342342
elif f[key].attrs['type'] == 'series':
343343
d = loadDictFromHDF5(f[key])
344344
grp = seriesOutputGroup(key)
@@ -359,10 +359,10 @@ def loadDictFromHDF5(f):
359359
else:
360360
params[key] = np.array(f[key])
361361
try:
362-
l = []
362+
myList = []
363363
for i in range(len(params[key])):
364-
l.append(params[key][i].decode('utf-8'))
365-
params[key] = l
364+
myList.append(params[key][i].decode('utf-8'))
365+
params[key] = myList
366366
except:
367367
pass
368368
return params
@@ -501,7 +501,8 @@ def __init__(self, filename, comm, mode=MPI.MODE_WRONLY | MPI.MODE_CREATE):
501501
# keep the absolute path, otherwise derived classes which use this
502502
# may come a cropper when the current directory changes
503503
self.baseFilename = os.path.abspath(filename)
504-
assert len(self.baseFilename) <= 245, 'The length of the log file path \"{}\" is too long and will probably crash MPI. Try running with \"--disableFileLog\"'.format(self.baseFilename)
504+
assert len(self.baseFilename) <= 245, ('The length of the log file path \"{}\" is too long ' +
505+
'and will probably crash MPI. Try running with \"--disableFileLog\"').format(self.baseFilename)
505506
if Path(self.baseFilename).exists() and comm.rank == 0:
506507
from os import remove
507508
remove(self.baseFilename)
@@ -538,16 +539,16 @@ def close(self):
538539

539540
def columns(lines, returnColWidth=False, colWidth=0):
540541
if colWidth == 0:
541-
for l, _, _ in lines:
542-
colWidth = max(len(l), colWidth)
542+
for line, _, _ in lines:
543+
colWidth = max(len(line), colWidth)
543544
s = []
544-
for l, f, v in lines:
545+
for line, f, v in lines:
545546
if isinstance(f, str):
546547
lf = '{:<'+str(colWidth+2)+'}'+f
547-
s.append(lf.format(l+':', v))
548+
s.append(lf.format(line+':', v))
548549
else:
549550
lf = '{:<'+str(colWidth+2)+'}'+'{}'
550-
s.append(lf.format(l+':', f(v)))
551+
s.append(lf.format(line+':', f(v)))
551552
s = '\n'.join(s)
552553
if returnColWidth:
553554
return s, colWidth
@@ -1488,18 +1489,22 @@ def __call__(self):
14881489
if isinstance(newValue, np.ndarray):
14891490
cached_args[prop] = newValue.copy()
14901491
if (newValue != oldValue).any():
1491-
dependencyLogger.log(self.logLevel, 'Values for {} differ: \'{}\' != \'{}\', calling \'{}\''.format(prop, oldValue, newValue, self.fun.__name__))
1492+
dependencyLogger.log(self.logLevel, 'Values for {} differ: \'{}\' != \'{}\', calling \'{}\''.format(prop, oldValue,
1493+
newValue, self.fun.__name__))
14921494
needToBuild = True
14931495
else:
14941496
dependencyLogger.log(self.logLevel, 'Values for {} are identical: \'{}\' == \'{}\''.format(prop, oldValue, newValue))
14951497
elif newValue != oldValue:
14961498
cached_args[prop] = newValue
1497-
dependencyLogger.log(self.logLevel, 'Values for {} differ: \'{}\' != \'{}\', calling \'{}\''.format(prop, oldValue, newValue, self.fun.__name__))
1499+
dependencyLogger.log(self.logLevel, 'Values for {} differ: \'{}\' != \'{}\', calling \'{}\''.format(prop, oldValue,
1500+
newValue, self.fun.__name__))
14981501
needToBuild = True
14991502
else:
15001503
dependencyLogger.log(self.logLevel, 'Values for {} are identical: \'{}\' == \'{}\''.format(prop, oldValue, newValue))
15011504
except Exception as e:
1502-
dependencyLogger.log(logging.WARN, 'Cannot compare values {}, {} for property \'{}\', exception {}, force call \'{}\''.format(oldValue, newValue, prop, e, self.fun.__name__))
1505+
dependencyLogger.log(logging.WARN,
1506+
'Cannot compare values {}, {} for property \'{}\', exception {}, force call \'{}\''.format(oldValue, newValue,
1507+
prop, e, self.fun.__name__))
15031508
needToBuild = True
15041509
except AttributeError:
15051510
raise AttributeError('Method \'{}\' has unsatisfied dependency on \'{}\''.format(self.fun.__name__, prop))
@@ -1768,6 +1773,7 @@ def changeLogLevel(self, properties, logLevel):
17681773
class driverAddon:
17691774
def __init__(self, driver):
17701775
self.driver = driver
1776+
self._timer = None
17711777
self.__parametrized_args__ = {}
17721778
self.flags = []
17731779
self.setDriverArgs()
@@ -1788,7 +1794,10 @@ def interpreter(v):
17881794
for p in parametrizedArgs:
17891795
if self.parametrizedArg(p).match(v):
17901796
return v
1791-
raise ArgumentTypeError("\"{}\" is not in list of accepted values {} or cannot be interpreted as parametrized arg {}.".format(v, acceptedValues, [repr(self.parametrizedArg(p)) for p in parametrizedArgs]))
1797+
raise ArgumentTypeError(("\"{}\" is not in list of accepted values {} " +
1798+
"or cannot be interpreted as parametrized arg {}.").format(v, acceptedValues,
1799+
[repr(self.parametrizedArg(p))
1800+
for p in parametrizedArgs]))
17921801

17931802
return interpreter
17941803

drivers/runParallelGMG.py

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -282,8 +282,10 @@
282282
P0.num_columns = numGlobalDoFs0
283283
P.append(P0.to_csr())
284284

285-
coords.append(d.comm.reduce(P[-1].T @ (overlaps.getDistributeAsDiagonalOperator(lvl).to_csr()@hM[FINE].algebraicLevels[lvl].DoFMap.getDoFCoordinates())))
286-
nullspace.append(d.comm.reduce(P[-1].T @ (overlaps.getDistributeAsDiagonalOperator(lvl).to_csr()@hM[FINE].algebraicLevels[lvl].DoFMap.ones())))
285+
coords.append(d.comm.reduce(P[-1].T @ (overlaps.getDistributeAsDiagonalOperator(lvl).to_csr() @
286+
hM[FINE].algebraicLevels[lvl].DoFMap.getDoFCoordinates())))
287+
nullspace.append(d.comm.reduce(P[-1].T @ (overlaps.getDistributeAsDiagonalOperator(lvl).to_csr() @
288+
hM[FINE].algebraicLevels[lvl].DoFMap.ones())))
287289

288290
A.append(d.comm.reduce((P[-1].T @ hM[FINE].algebraicLevels[lvl].A.to_csr() @ P[-1]).tocsr()))
289291

@@ -294,7 +296,8 @@
294296
for k in range(len(lvls)-1):
295297
lvlC = lvls[k]
296298
lvlF = lvls[k+1]
297-
P_ops.append(d.comm.reduce((P[lvlF].T @ overlaps.getDistributeAsDiagonalOperator(lvlF).to_csr() @ hM[FINE].algebraicLevels[lvlF].P.to_csr() @ P[lvlC]).tocsr()))
299+
P_ops.append(d.comm.reduce((P[lvlF].T @ overlaps.getDistributeAsDiagonalOperator(lvlF).to_csr() @
300+
hM[FINE].algebraicLevels[lvlF].P.to_csr() @ P[lvlC]).tocsr()))
298301

299302
if d.comm.rank == 0:
300303
from scipy.io import mmwrite
@@ -319,8 +322,10 @@
319322
# A_global = CSR_LinearOperator.from_csr(A_global)
320323
# A2_global = CSR_LinearOperator.from_csr(A2_global)
321324
# P_global = CSR_LinearOperator.from_csr(P_global)
322-
# mg = solverFactory('mg', hierarchy=[{'A': A2_global}, {'A': A_global, 'P': P_global, 'R': P_global.transpose()}], setup=True, smoother=('jacobi', {'presmoothingSteps': 2,
323-
# 'postsmoothingSteps': 2}))
325+
# mg = solverFactory('mg', hierarchy=[{'A': A2_global}, {'A': A_global, 'P': P_global, 'R': P_global.transpose()}],
326+
# setup=True,
327+
# smoother=('jacobi', {'presmoothingSteps': 2,
328+
# 'postsmoothingSteps': 2}))
324329
# print(mg)
325330
# cg = solverFactory('cg', A=A_global, setup=True, maxIter=d.maxiter, tolerance=tol)
326331
# cg.setPreconditioner(mg.asPreconditioner(), False)

fem/PyNucleus_fem/factories.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -176,6 +176,9 @@ def __call__(self, mesh, *args, **kwargs):
176176
meshFactory.register('circle', circle, 2, aliases=['disc', 'unitDisc', 'ball2d', '2dball'])
177177
meshFactory.register('graded_circle', graded_circle, 2, aliases=['gradedCircle'])
178178
meshFactory.register('discWithInteraction', discWithInteraction, 2)
179+
meshFactory.register('twinDisc', twinDisc, 2)
180+
meshFactory.register('dumbbell', dumbbell, 2)
181+
meshFactory.register('wrench', wrench, 2)
179182
meshFactory.register('cutoutCircle', cutoutCircle, 2, aliases=['cutoutDisc'])
180183
meshFactory.register('squareWithCircularCutout', squareWithCircularCutout, 2)
181184
meshFactory.register('boxWithBallCutout', boxWithBallCutout, 3, aliases=['boxMinusBall'])

fem/PyNucleus_fem/mesh.py

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -250,9 +250,9 @@ def doubleIntervalWithInteractions(a=0., b=1., c=2.,
250250
horizon1=0.1, horizon2=0.2,
251251
h=None):
252252

253-
def getNumCells(l, r):
253+
def getNumCells(left, right):
254254
eps = 1e-8
255-
return int(np.ceil((r-l-eps)/h))
255+
return int(np.ceil((right-left-eps)/h))
256256

257257
assert horizon2 >= horizon1
258258
assert horizon1 >= 0
@@ -341,7 +341,7 @@ def squareWithInteractions(ax, ay, bx, by,
341341
d1 = (circularSegment(bottomLeft, horizon, np.pi, 1.5*np.pi, numPointsPerUnitLength) +
342342
line(bottomLeft, bottomLeft-horizontalOffset) +
343343
line(bottomLeft, bottomLeft-verticalOffset) +
344-
(lineHorizontal+bottomLeft)+
344+
(lineHorizontal+bottomLeft) +
345345
(lineHorizontal+(bottomLeft-verticalOffset)))
346346

347347
d2 = (circularSegment(bottomRight, horizon, -0.5*np.pi, 0., numPointsPerUnitLength) +
@@ -386,11 +386,11 @@ def squareWithInteractions(ax, ay, bx, by,
386386
assert np.allclose(yVals1, yVals2), (yVals1, yVals2)
387387

388388
idx3 = np.logical_and(np.absolute(mesh.vertices_as_array[:, 1]-ay) < eps,
389-
np.logical_and(mesh.vertices_as_array[:, 0] >= ax-eps,
390-
mesh.vertices_as_array[:, 0] <= bx+eps))
389+
np.logical_and(mesh.vertices_as_array[:, 0] >= ax-eps,
390+
mesh.vertices_as_array[:, 0] <= bx+eps))
391391
idx4 = np.logical_and(np.absolute(mesh.vertices_as_array[:, 1]-by) < eps,
392-
np.logical_and(mesh.vertices_as_array[:, 0] >= ax-eps,
393-
mesh.vertices_as_array[:, 0] <= bx+eps))
392+
np.logical_and(mesh.vertices_as_array[:, 0] >= ax-eps,
393+
mesh.vertices_as_array[:, 0] <= bx+eps))
394394
xVals3 = np.sort(mesh.vertices_as_array[idx3, 0])
395395
xVals4 = np.sort(mesh.vertices_as_array[idx4, 0])
396396
assert np.allclose(xVals3, xVals4), (xVals3, xVals4)
@@ -2676,7 +2676,7 @@ class mesh3d(meshNd):
26762676

26772677
def plot(self):
26782678
import matplotlib.pyplot as plt
2679-
from mpl_toolkits.mplot3d import Axes3D
2679+
from mpl_toolkits.mplot3d import Axes3D # noqa: F401
26802680
from itertools import combinations
26812681
fig = plt.figure()
26822682
ax = fig.add_subplot(111, projection='3d')
@@ -2688,7 +2688,7 @@ def plot(self):
26882688

26892689
def plot_surface(self, boundary=False):
26902690
import matplotlib.pyplot as plt
2691-
from mpl_toolkits.mplot3d import Axes3D
2691+
from mpl_toolkits.mplot3d import Axes3D # noqa: F401
26922692
from mpl_toolkits.mplot3d.art3d import Poly3DCollection
26932693
# from matplotlib import rcParams
26942694
# from itertools import combinations

fem/PyNucleus_fem/meshConstruction.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -276,7 +276,7 @@ def rectangle(a, b, num_points=None, num_points_per_unit_len=None):
276276
def meshTransformation(x1, x2, xNew):
277277
eps = 1e-10
278278
if ((a[0]-eps <= x1[0] <= b[0]+eps) and (a[1]-eps <= x1[1] <= b[1]+eps) and
279-
(a[0]-eps <= x2[0] <= b[0]+eps) and (a[1]-eps <= x2[1] <= b[1]+eps)):
279+
(a[0]-eps <= x2[0] <= b[0]+eps) and (a[1]-eps <= x2[1] <= b[1]+eps)):
280280
xNew[:] = 0.5*(x1+x2)
281281
return True
282282

@@ -290,6 +290,6 @@ def __init__(self, seg, p1, p2):
290290
for t in seg.meshTransformations:
291291
def transform(x1, x2, xNew):
292292
if ((p1[0] <= xNew[0]) and (xNew[0] <= p2[0]) and
293-
(p1[1] <= xNew[1]) and (xNew[1] <= p2[1])):
293+
(p1[1] <= xNew[1]) and (xNew[1] <= p2[1])):
294294
t(x1, x2, xNew)
295295
self.meshTransformations.append(transform)

multilevelSolver/PyNucleus_multilevelSolver/connectors.py

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -11,14 +11,12 @@
1111
from mpi4py import MPI
1212
import logging
1313
import numpy as np
14-
from PyNucleus_base.myTypes import REAL, INDEX, TAG
15-
from PyNucleus_base import uninitialized
14+
from PyNucleus_base.myTypes import REAL, INDEX
1615
from . levels import meshLevel, algebraicLevel
1716
from . hierarchies import EmptyHierarchy, hierarchy, pCoarsenHierarchy
1817
from PyNucleus_base.utilsFem import TimerManager
1918
from PyNucleus_fem.factories import meshFactory
2019
from PyNucleus_fem.repartitioner import Repartitioner
21-
from PyNucleus_fem.meshOverlaps import meshOverlap, interfaceManager
2220

2321
LOGGER = logging.getLogger(__name__)
2422

@@ -214,13 +212,15 @@ def getLocalOverlap(self):
214212
if self.is_overlapping and self.comm1 is not None:
215213
subdomain = self.hierarchy1.meshLevels[-1].mesh
216214
if self.global_comm.rank in self.OM.overlaps:
217-
print('cells kept local on rank {} in repartitioning: {:,} / target: {:,}'.format(self.global_comm.rank,
218-
self.OM.overlaps[self.global_comm.rank].num_cells/subdomain.num_cells,
219-
self.comm1.size/self.global_comm.size))
215+
print(('cells kept local on rank {} in repartitioning: ' +
216+
'{:,} / target: {:,}').format(self.global_comm.rank,
217+
self.OM.overlaps[self.global_comm.rank].num_cells/subdomain.num_cells,
218+
self.comm1.size/self.global_comm.size))
220219
else:
221-
print('cells kept local on rank {} in repartitioning: {:,} / target: {:,}'.format(self.global_comm.rank,
222-
0.,
223-
self.comm1.size/self.global_comm.size))
220+
print(('cells kept local on rank {} in repartitioning: ' +
221+
'{:,} / target: {:,}').format(self.global_comm.rank,
222+
0.,
223+
self.comm1.size/self.global_comm.size))
224224

225225
def build(self):
226226
if self.hierarchy1 is not None:

multilevelSolver/PyNucleus_multilevelSolver/geometricMG.py

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,9 +8,7 @@
88
from __future__ import division
99
import logging
1010
import numpy as np
11-
from PyNucleus_base.utilsFem import getLoggingTimer
12-
from PyNucleus_base import REAL, INDEX, uninitialized
13-
from PyNucleus_fem import P1_DoFMap
11+
from PyNucleus_base import INDEX, uninitialized
1412
from PyNucleus_base.linear_operators import LinearOperator
1513

1614
LOGGER = logging.getLogger(__name__)

0 commit comments

Comments
 (0)