Commit 3595c16d authored by Martin Bauer's avatar Martin Bauer
Browse files

Fixed new flake8 warnings

parent cd8a9329
......@@ -503,7 +503,7 @@ class SympyAssignment(Node):
def _repr_html_(self):
printed_lhs = sp.latex(self.lhs)
printed_rhs = sp.latex(self.rhs)
return "${printed_lhs} \leftarrow {printed_rhs}$".format(printed_lhs=printed_lhs, printed_rhs=printed_rhs)
return "${printed_lhs} \\leftarrow {printed_rhs}$".format(printed_lhs=printed_lhs, printed_rhs=printed_rhs)
class ResolvedFieldAccess(sp.Indexed):
......
......@@ -21,9 +21,9 @@ direction_member_name = "dir"
def numpy_data_type_for_boundary_object(boundary_object, dim):
coordinate_names = boundary_index_array_coordinate_names[:dim]
return np.dtype([(name, np.int32) for name in coordinate_names] +
[(direction_member_name, np.int32)] +
[(i[0], i[1].numpy_dtype) for i in boundary_object.additional_data], align=True)
return np.dtype([(name, np.int32) for name in coordinate_names]
+ [(direction_member_name, np.int32)]
+ [(i[0], i[1].numpy_dtype) for i in boundary_object.additional_data], align=True)
def _create_boundary_neighbor_index_list_python(flag_field_arr, nr_of_ghost_layers, boundary_mask,
......
......@@ -503,8 +503,8 @@ def compile_module(code, code_hash, base_dir):
run_compile_step(['link.exe', py_lib, '/DLL', '/out:' + lib_file, object_file])
else:
with atomic_file_write(lib_file) as file_name:
run_compile_step([compiler_config['command'], '-shared', object_file, '-o', file_name] +
compiler_config['flags'].split())
run_compile_step([compiler_config['command'], '-shared', object_file, '-o', file_name]
+ compiler_config['flags'].split())
return lib_file
......
......@@ -370,7 +370,7 @@ class BasicType(Type):
elif name == 'bool':
return 'bool'
else:
raise NotImplemented("Can map numpy to C name for %s" % (name,))
raise NotImplementedError("Can map numpy to C name for %s" % (name,))
def __init__(self, dtype, const=False):
self.const = const
......
......@@ -33,7 +33,7 @@ class DataHandling(ABC):
@abstractmethod
def add_array(self, name: str, values_per_cell: int = 1, dtype=np.float64,
latex_name: Optional[str]=None, ghost_layers: Optional[int] = None, layout: Optional[str] = None,
latex_name: Optional[str] = None, ghost_layers: Optional[int] = None, layout: Optional[str] = None,
cpu: bool = True, gpu: Optional[bool] = None, alignment=False) -> Field:
"""Adds a (possibly distributed) array to the handling that can be accessed using the given name.
......
......@@ -18,7 +18,7 @@ except ImportError:
class SerialDataHandling(DataHandling):
def __init__(self, domain_size: Sequence[int], default_ghost_layers: int = 1, default_layout: str='SoA',
def __init__(self, domain_size: Sequence[int], default_ghost_layers: int = 1, default_layout: str = 'SoA',
periodicity: Union[bool, Sequence[bool]] = False, default_target: str = 'cpu') -> None:
"""
Creates a data handling for single node simulations.
......
......@@ -143,8 +143,8 @@ class FiniteDifferenceStencilDerivation:
eqs.append(error_dict[derivative_tuple])
else:
for i in range(1, len(permutations)):
new_eq = (error_dict[tuple(sorted(permutations[i] + self._derivative))] -
error_dict[tuple(sorted(permutations[i - 1] + self._derivative))])
new_eq = (error_dict[tuple(sorted(permutations[i] + self._derivative))]
- error_dict[tuple(sorted(permutations[i - 1] + self._derivative))])
if new_eq:
eqs.append(new_eq)
else:
......
......@@ -92,7 +92,7 @@ class Diff(sp.Expr):
return self.args[2]
def _latex(self, printer, *_):
result = "{\partial"
result = r"{\partial"
if self.superscript >= 0:
result += "^{(%s)}" % (self.superscript,)
if self.target != -1:
......@@ -140,7 +140,7 @@ class DiffOperator(sp.Expr):
return self.args[1]
def _latex(self, *_):
result = "{\partial"
result = r"{\partial"
if self.superscript >= 0:
result += "^{(%s)}" % (self.superscript,)
if self.target != -1:
......
......@@ -79,12 +79,12 @@ class Discretization2ndOrder:
else:
return 1 + Discretization2ndOrder._diff_order(e.args[0])
def _discretize_diffusion(self, expr):
def _discretize_diffusion(self, e):
result = 0
for c in range(expr.dim):
first_diffs = [offset *
(expr.diffusion_scalar_at_offset(c, offset) * expr.diffusion_coefficient_at_offset(c, offset)
- expr.diffusion_scalar_at_offset(0, 0) * expr.diffusion_coefficient_at_offset(0, 0))
for c in range(e.dim):
first_diffs = [offset
* (e.diffusion_scalar_at_offset(c, offset) * e.diffusion_coefficient_at_offset(c, offset)
- e.diffusion_scalar_at_offset(0, 0) * e.diffusion_coefficient_at_offset(0, 0))
for offset in [-1, 1]]
result += first_diffs[1] - first_diffs[0]
return result / (self.dx ** 2)
......@@ -92,8 +92,8 @@ class Discretization2ndOrder:
def _discretize_advection(self, expr):
result = 0
for c in range(expr.dim):
interpolated = [(expr.advected_scalar_at_offset(c, offset) * expr.velocity_field_at_offset(c, offset, c) +
expr.advected_scalar_at_offset(c, 0) * expr.velocity_field_at_offset(c, 0, c)) / 2
interpolated = [(expr.advected_scalar_at_offset(c, offset) * expr.velocity_field_at_offset(c, offset, c)
+ expr.advected_scalar_at_offset(c, 0) * expr.velocity_field_at_offset(c, 0, c)) / 2
for offset in [-1, 1]]
result += interpolated[1] - interpolated[0]
return result / self.dx
......
......@@ -53,7 +53,7 @@ class Database:
self.backend.autocommit = True
def save(self, params: Dict, result: Dict, env: Dict=None, **kwargs) -> None:
def save(self, params: Dict, result: Dict, env: Dict = None, **kwargs) -> None:
"""Stores a simulation result in the database.
Args:
......
......@@ -53,7 +53,8 @@ class ParameterStudy:
Run = namedtuple("Run", ['parameter_dict', 'weight'])
def __init__(self, run_function: Callable[..., Dict], runs: Sequence = (), database_connector: str='./db') -> None:
def __init__(self, run_function: Callable[..., Dict], runs: Sequence = (),
database_connector: str = './db') -> None:
self.runs = list(runs)
self.run_function = run_function
self.db = Database(database_connector)
......@@ -133,7 +134,7 @@ class ParameterStudy:
self.db.save(run.parameter_dict, result, changed_params=parameter_update)
def run_server(self, ip: str ="0.0.0.0", port: int = 8342):
def run_server(self, ip: str = "0.0.0.0", port: int = 8342):
"""Runs server to supply runner clients with scenarios to simulate and collect results from them.
Skips scenarios that are already in the database."""
from http.server import BaseHTTPRequestHandler, HTTPServer
......@@ -220,7 +221,7 @@ class ParameterStudy:
server.handle_request()
server.handle_request()
def run_client(self, client_name: str="{hostname}_{pid}", server: str='localhost', port: int=8342,
def run_client(self, client_name: str = "{hostname}_{pid}", server: str = 'localhost', port: int = 8342,
parameter_update: Optional[ParameterDict] = None, max_time=None) -> None:
"""Start runner client that retrieves configuration from server, runs it and reports results back to server.
......
......@@ -29,8 +29,8 @@ class AssignmentCollection:
def __init__(self, main_assignments: Union[List[Assignment], Dict[sp.Expr, sp.Expr]],
subexpressions: Union[List[Assignment], Dict[sp.Expr, sp.Expr]],
simplification_hints: Optional[Dict[str, Any]]=None,
subexpression_symbol_generator: Iterator[sp.Symbol]=None) -> None:
simplification_hints: Optional[Dict[str, Any]] = None,
subexpression_symbol_generator: Iterator[sp.Symbol] = None) -> None:
if isinstance(main_assignments, Dict):
main_assignments = [Assignment(k, v)
for k, v in main_assignments.items()]
......@@ -144,7 +144,7 @@ class AssignmentCollection:
return handled_symbols
def lambdify(self, symbols: Sequence[sp.Symbol], fixed_symbols: Optional[Dict[sp.Symbol, Any]]=None, module=None):
def lambdify(self, symbols: Sequence[sp.Symbol], fixed_symbols: Optional[Dict[sp.Symbol, Any]] = None, module=None):
"""Returns a python function to evaluate this equation collection.
Args:
......
......@@ -75,8 +75,8 @@ def tanh_step_function_approximation(x, step_location, kind='right', steepness=0
return (1 + sp.tanh((x - step_location) / steepness)) / 2
elif kind == 'middle':
x1, x2 = step_location
return 1 - (tanh_step_function_approximation(x, x1, 'left', steepness) +
tanh_step_function_approximation(x, x2, 'right', steepness))
return 1 - (tanh_step_function_approximation(x, x1, 'left', steepness)
+ tanh_step_function_approximation(x, x2, 'right', steepness))
def multidimensional_sum(i, dim):
......
......@@ -621,7 +621,7 @@ def cut_loop(loop_node, cutting_points):
return new_loops
def simplify_conditionals(node: ast.Node, loop_counter_simplification: bool=False) -> None:
def simplify_conditionals(node: ast.Node, loop_counter_simplification: bool = False) -> None:
"""Removes conditionals that are always true/false.
Args:
......@@ -975,8 +975,8 @@ def get_optimal_loop_ordering(fields):
layouts = set([field.layout for field in fields])
if len(layouts) > 1:
raise ValueError("Due to different layout of the fields no optimal loop ordering exists " +
str({f.name: f.layout for f in fields}))
raise ValueError("Due to different layout of the fields no optimal loop ordering exists "
+ str({f.name: f.layout for f in fields}))
layout = list(layouts)[0]
return list(layout)
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment