Code cleanups from pylint.

这个提交包含在:
craig-warren
2020-04-08 09:47:44 +01:00
父节点 62b73edded
当前提交 fd4f607a97
共有 7 个文件被更改,包括 33 次插入34 次删除

查看文件

@@ -53,7 +53,7 @@ class UserObjectMulti:
def __str__(self):
"""Readable user string as per hash commands."""
s = ''
for k, v in self.kwargs.items():
for _, v in self.kwargs.items():
if isinstance(v, tuple) or isinstance(v, list):
v = ' '.join([str(el) for el in v])
s += str(v) + ' '

查看文件

@@ -130,6 +130,12 @@ class FractalVolume:
self.nx = xf - xs
self.ny = yf - ys
self.nz = zf - zs
self.originalxs = xs
self.originalxf = xf
self.originalys = ys
self.originalyf = yf
self.originalzs = zs
self.originalzf = zf
self.averaging = False
self.seed = None
self.dimension = dimension

查看文件

@@ -25,7 +25,7 @@ from .contexts import Context, MPIContext
from .utilities import setup_logging
logger = logging.getLogger(__name__)
setup_logging(level=25)
setup_logging(level=20)
def run(
scenes=None,

查看文件

@@ -16,11 +16,13 @@
# You should have received a copy of the GNU General Public License
# along with gprMax. If not, see <http://www.gnu.org/licenses/>.
import logging
import numpy as np
from scipy.constants import c
from ..grid import FDTDGrid
logger = logging.getLogger(__name__)
class SubGridBase(FDTDGrid):
@@ -65,6 +67,7 @@ class SubGridBase(FDTDGrid):
def main_grid_index_to_subgrid_index(self, i, j, k):
"""Calculate local subgrid index from global main grid index."""
logger.debug('SubGridBase has no i0, j0, k0 members.')
i_s = self.n_boundary_cells_x + (i - self.i0) * self.ratio
j_s = self.n_boundary_cells_y + (j - self.j0) * self.ratio
k_s = self.n_boundary_cells_z + (k - self.k0) * self.ratio

查看文件

@@ -16,8 +16,12 @@
# You should have received a copy of the GNU General Public License
# along with gprMax. If not, see <http://www.gnu.org/licenses/>.
import logging
from ..receivers import Rx
logger = logging.getLogger(__name__)
class ReferenceRx(Rx):
"""Receiver that mimicks a receiver in coarse grid.
@@ -27,6 +31,8 @@ class ReferenceRx(Rx):
position as the coarse grid.
"""
logger.debug('ReferenceRx has no offset member.')
def get_field(self, str_id, field):
"""Return the field value at the equivalent coarse yee cell.

查看文件

@@ -16,11 +16,12 @@
# You should have received a copy of the GNU General Public License
# along with gprMax. If not, see <http://www.gnu.org/licenses/>.
import sys
import logging
import numpy as np
from scipy import interpolate
logger = logging.getLogger(__name__)
def calculate_weighting_coefficients(x1, x):
c1 = (x - x1) / x
@@ -28,7 +29,7 @@ def calculate_weighting_coefficients(x1, x):
return (c1, c2)
class PrecusorNodesBase:
class PrecursorNodesBase:
def __init__(self, fdtd_grid, sub_grid):
self.G = fdtd_grid
@@ -66,7 +67,6 @@ class PrecusorNodesBase:
self.initialize_magnetic_slices_array()
self.initialize_electric_slices_array()
def _initialize_fields(self):
# Initialise the precursor arrays
@@ -276,7 +276,7 @@ class PrecusorNodesBase:
setattr(self, obj[0], f)
class PrecursorNodes(PrecusorNodesBase):
class PrecursorNodes(PrecursorNodesBase):
def __init__(self, fdtd_grid, sub_grid):
super().__init__(fdtd_grid, sub_grid)
@@ -402,7 +402,7 @@ class PrecursorNodes(PrecusorNodesBase):
return f_1, f_2
class PrecursorNodesFiltered(PrecusorNodesBase):
class PrecursorNodesFiltered(PrecursorNodesBase):
def __init__(self, fdtd_grid, sub_grid):
super().__init__(fdtd_grid, sub_grid)

查看文件

@@ -324,10 +324,7 @@ def get_host_info():
pass
# Hyperthreading
if threadspercore == 2:
hyperthreading = True
else:
hyperthreading = False
hyperthreading = True if threadspercore == 2 else False
# OS version
osversion = platform.platform()
@@ -341,14 +338,17 @@ def get_host_info():
hostinfo['osversion'] = osversion
hostinfo['hyperthreading'] = hyperthreading
hostinfo['logicalcores'] = psutil.cpu_count()
try:
# Get number of physical CPU cores, i.e. avoid hyperthreading with OpenMP
hostinfo['physicalcores'] = psutil.cpu_count(logical=False)
except ValueError:
hostinfo['physicalcores'] = hostinfo['logicalcores']
# Handle case where cpu_count returns None on some machines
if not hostinfo['physicalcores']:
hostinfo['physicalcores'] = hostinfo['logicalcores']
hostinfo['ram'] = psutil.virtual_memory().total
hostinfo['ompthreads'] = 1
@@ -366,13 +366,17 @@ def set_omp_threads(nthreads=None):
# Should waiting threads consume CPU power (can drastically effect
# performance)
os.environ['OMP_WAIT_POLICY'] = 'ACTIVE'
# Number of threads may be adjusted by the run time environment to best
# utilize system resources
os.environ['OMP_DYNAMIC'] = 'FALSE'
# Each place corresponds to a single core (having one or more hardware threads)
os.environ['OMP_PLACES'] = 'cores'
# Bind threads to physical cores
os.environ['OMP_PROC_BIND'] = 'TRUE'
# Prints OMP version and environment variables (useful for debug)
# os.environ['OMP_DISPLAY_ENV'] = 'TRUE'
@@ -531,27 +535,7 @@ def detect_gpus():
return gpus
# def check_gpus(gpus):
# """Check if requested Nvidia GPU(s) deviceID(s) exist.
# Args:
# gpus (list): List of GPU object(s).
# """
# # Check if requested device ID(s) exist
# for ID in deviceIDs:
# if ID not in deviceIDsavail:
# raise GeneralError(f'GPU with device ID {ID} does not exist')
# # Gather information about selected/detected GPUs
# gpus = []
# for ID in deviceIDsavail:
# gpu = GPU(deviceID=ID)
# gpu.get_gpu_info(drv)
# gpus.append(gpu)
def timer():
"""Function to return time in fractional seconds."""
logger.debug('"thread_time" not currently available in macOS and bug (https://bugs.python.org/issue36205) with "process_time"')
logger.debug('"thread_time" not currently available in macOS and bug (https://bugs.python.org/issue36205) with "process_time", so use "perf_counter".')
return timer_fn()