PEP8 formatting cleanups.

这个提交包含在:
Craig Warren
2016-08-10 13:56:15 +01:00
父节点 0d24fe7e7a
当前提交 75a8ef43e2
共有 9 个文件被更改,包括 27 次插入31 次删除

查看文件

@@ -25,7 +25,7 @@ class GeneralError(ValueError):
"""Handles general errors. Subclasses the ValueError class."""
def __init__(self, message, *args):
self.message = message
super(GeneralError, self).__init__(message, *args)
print(Fore.RED)
@@ -33,9 +33,9 @@ class GeneralError(ValueError):
class CmdInputError(ValueError):
"""Handles errors in user specified commands. Subclasses the ValueError class."""
def __init__(self, message, *args):
self.message = message
super(CmdInputError, self).__init__(message, *args)
print(Fore.RED)
print(Fore.RED)

查看文件

@@ -212,9 +212,9 @@ def run_mpi_sim(args, numbermodelruns, inputfile, usernamespace, optparams=None)
rank = comm.rank # rank of this process
status = MPI.Status() # get MPI status object
name = MPI.Get_processor_name() # get name of processor/host
tsimstart = perf_counter()
if rank == 0: # Master process
modelrun = 1
numworkers = size - 1
@@ -381,7 +381,7 @@ def run_model(args, modelrun, numbermodelruns, inputfile, usernamespace):
else:
inputfilestr = '\nInput file not re-processed'
print(Fore.GREEN + '{} {}\n'.format(inputfilestr, '-' * (get_terminal_size()[0] - 1 - len(inputfilestr))))
# Clear arrays for field components
G.initialise_field_arrays()
@@ -439,10 +439,10 @@ def run_model(args, modelrun, numbermodelruns, inputfile, usernamespace):
# Start - Main FDTD calculations #
####################################
tsolvestart = perf_counter()
# Absolute time
abstime = 0
for timestep in tqdm(range(G.iterations), desc='Running simulation, model ' + str(modelrun) + ' of ' + str(numbermodelruns), ncols=get_terminal_size()[0] - 1):
# Store field component values for every receiver and transmission line
store_outputs(timestep, G.Ex, G.Ey, G.Ez, G.Hx, G.Hy, G.Hz, G)
@@ -493,7 +493,7 @@ def run_model(args, modelrun, numbermodelruns, inputfile, usernamespace):
abstime += 0.5 * G.dt
tsolveend = perf_counter()
# Write an output file in HDF5 format
write_hdf5(outputfile, G.Ex, G.Ey, G.Ez, G.Hx, G.Hy, G.Hz, G)

查看文件

@@ -47,7 +47,7 @@ def process_geometrycmds(geometry, G):
tqdmbar = True
else:
tqdmbar = False
for object in tqdm(geometry, desc='Processing geometry related cmds', unit='cmds', ncols=get_terminal_size()[0] - 1, disable=tqdmbar):
tmp = object.split()

查看文件

@@ -679,7 +679,7 @@ def process_multicmds(multicmds, G):
raise CmdInputError("'" + cmdname + ': ' + ' '.join(tmp) + "'" + ' requires type to be either n (normal) or f (fine)')
if tmp[10].lower() == 'f' and (dx * G.dx != G.dx or dy * G.dy != G.dy or dz * G.dz != G.dz):
raise CmdInputError("'" + cmdname + ': ' + ' '.join(tmp) + "'" + ' requires the spatial discretisation for the geometry view to be the same as the model for geometry view of type f (fine)')
# Set type of geometry file
if tmp[10].lower() == 'n':
type = '.vti'

查看文件

@@ -62,9 +62,9 @@ def process_singlecmds(singlecmds, G):
# Number of threads (OpenMP) to use
cmd = '#num_threads'
os.environ['OMP_WAIT_POLICY'] = 'ACTIVE' # What to do with threads when they are waiting
os.environ['OMP_DYNAMIC'] = 'FALSE' #
os.environ['OMP_PROC_BIND'] = 'TRUE' # Bind threads to physical cores
os.environ['OMP_WAIT_POLICY'] = 'ACTIVE' # What to do with threads when they are waiting
os.environ['OMP_DYNAMIC'] = 'FALSE'
os.environ['OMP_PROC_BIND'] = 'TRUE' # Bind threads to physical cores
if singlecmds[cmd] != 'None':
tmp = tuple(int(x) for x in singlecmds[cmd].split())
@@ -115,15 +115,13 @@ def process_singlecmds(singlecmds, G):
raise CmdInputError(cmd + ' requires at least one cell in every dimension')
if G.messages:
print('Domain size: {:g} x {:g} x {:g}m ({:d} x {:d} x {:d} = {:g} cells)'.format(tmp[0], tmp[1], tmp[2], G.nx, G.ny, G.nz, (G.nx * G.ny * G.nz)))
# Estimate memory (RAM) usage
# Currently this is a pretty loose estimate but seems to match reasonably with memory usage reported when model completes.
# Estimate memory (RAM) usage (currently this is a pretty loose estimate but seems to match reasonably with memory usage reported when model completes)
memestimate = (((G.nx + 1) * (G.ny + 1) * (G.nz + 1) * 13 * np.dtype(floattype).itemsize + (G.nx + 1) * (G.ny + 1) * (G.nz + 1) * 18) * 1.1) + 30e6
if memestimate > psutil.virtual_memory().total:
raise GeneralError('Estimated memory (RAM) required ~{} exceeds {} available!\n'.format(human_size(memestimate), human_size(psutil.virtual_memory().total)))
if G.messages:
print('Memory (RAM) required: ~{} ({} detected)'.format(human_size(memestimate), human_size(psutil.virtual_memory().total)))
# Time step CFL limit (use either 2D or 3D) and default PML thickness
if G.nx == 1:

查看文件

@@ -144,7 +144,7 @@ def process_materials(G):
Args:
G (class): Grid class instance - holds essential parameters describing the model.
Returns:
materialsdata (list): List of material IDs, names, and properties to print a table.
"""

查看文件

@@ -44,7 +44,7 @@ def run_opt_sim(args, numbermodelruns, inputfile, usernamespace):
"""
tsimstart = perf_counter()
if numbermodelruns > 1:
raise CmdInputError('When a Taguchi optimisation is being carried out the number of model runs argument is not required')
@@ -139,7 +139,7 @@ def run_opt_sim(args, numbermodelruns, inputfile, usernamespace):
# Rename confirmation experiment output file so that it is retained for each iteraction
os.rename(outputfile, os.path.splitext(outputfile)[0] + '_final' + str(iteration + 1) + '.out')
print(Fore.GREEN + '\nTaguchi optimisation, iteration {} completed. History of optimal parameter values {} and of fitness values {}'.format(iteration + 1, dict(optparamshist), fitnessvalueshist) + Style.RESET_ALL)
iteration += 1
@@ -157,7 +157,7 @@ def run_opt_sim(args, numbermodelruns, inputfile, usernamespace):
break
tsimend = perf_counter()
# Save optimisation parameters history and fitness values history to file
opthistfile = inputfileparts[0] + '_hist.pickle'
with open(opthistfile, 'wb') as f:

查看文件

@@ -27,13 +27,14 @@ import textwrap
from colorama import init, Fore, Style
init()
def logo(version):
"""Print gprMax logo, version, and licencing/copyright information.
Args:
version (str): Version number.
"""
description = '\n=== Electromagnetic modelling software based on the Finite-Difference Time-Domain (FDTD) method'
copyright = 'Copyright (C) 2015-2016: The University of Edinburgh'
authors = 'Authors: Craig Warren and Antonis Giannopoulos'
@@ -46,7 +47,7 @@ def logo(version):
/ _` | '_ \| '__| |\/| |/ _` \ \/ /
| (_| | |_) | | | | | | (_| |> <
\__, | .__/|_| |_| |_|\__,_/_/\_\\
|___/|_|
|___/|_|
v""" + version
print('{} {}\n'.format(description, '=' * (get_terminal_size()[0] - len(description) - 1)))
@@ -148,11 +149,7 @@ def get_machine_cpu_os():
allcpuinfo = subprocess.check_output("cat /proc/cpuinfo", shell=True).decode('utf-8').strip()
for line in allcpuinfo.split('\n'):
if 'model name' in line:
cpuID = re.sub( '.*model name.*:', '', line, 1)
cpuID = re.sub('.*model name.*:', '', line, 1)
osversion = 'Linux (' + platform.release() + ')'
return machineID, cpuID, osversion

查看文件

@@ -1,6 +1,7 @@
[flake8]
max-line-length = 200
# E402, module level import not at top of file
# E501, line too long
# F401, module imported but unused
ignore = E501, F401
ignore = E402, E501, F401