From 3595c16da7d61e7c27e6c15c0878ffa4b99f68fe Mon Sep 17 00:00:00 2001 From: Martin Bauer <martin.bauer@fau.de> Date: Mon, 18 Feb 2019 15:42:45 +0100 Subject: [PATCH] Fixed new flake8 warnings --- astnodes.py | 2 +- boundaries/createindexlist.py | 6 +++--- cpu/cpujit.py | 4 ++-- data_types.py | 2 +- datahandling/datahandling_interface.py | 2 +- datahandling/serial_datahandling.py | 2 +- fd/derivation.py | 4 ++-- fd/derivative.py | 4 ++-- fd/finitedifferences.py | 14 +++++++------- runhelper/db.py | 2 +- runhelper/parameterstudy.py | 7 ++++--- simp/assignment_collection.py | 6 +++--- sympyextensions.py | 4 ++-- transformations.py | 6 +++--- 14 files changed, 33 insertions(+), 32 deletions(-) diff --git a/astnodes.py b/astnodes.py index 6a7026c6a..09564178c 100644 --- a/astnodes.py +++ b/astnodes.py @@ -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): diff --git a/boundaries/createindexlist.py b/boundaries/createindexlist.py index cb25ca42e..6fcedeac8 100644 --- a/boundaries/createindexlist.py +++ b/boundaries/createindexlist.py @@ -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, diff --git a/cpu/cpujit.py b/cpu/cpujit.py index c083a7fb3..d5c38629b 100644 --- a/cpu/cpujit.py +++ b/cpu/cpujit.py @@ -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 diff --git a/data_types.py b/data_types.py index 99aaae0c0..fc1bd44e5 100644 --- a/data_types.py +++ b/data_types.py @@ -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 diff --git a/datahandling/datahandling_interface.py b/datahandling/datahandling_interface.py index f75a589a1..b9e81c7f3 100644 --- a/datahandling/datahandling_interface.py +++ b/datahandling/datahandling_interface.py @@ -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. diff --git a/datahandling/serial_datahandling.py b/datahandling/serial_datahandling.py index 9752acce3..7e4d19cd8 100644 --- a/datahandling/serial_datahandling.py +++ b/datahandling/serial_datahandling.py @@ -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. diff --git a/fd/derivation.py b/fd/derivation.py index 84167ec65..e3c4712d3 100644 --- a/fd/derivation.py +++ b/fd/derivation.py @@ -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: diff --git a/fd/derivative.py b/fd/derivative.py index d0e7ac77a..298cae16d 100644 --- a/fd/derivative.py +++ b/fd/derivative.py @@ -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: diff --git a/fd/finitedifferences.py b/fd/finitedifferences.py index dfc2aab95..3879addc0 100644 --- a/fd/finitedifferences.py +++ b/fd/finitedifferences.py @@ -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 diff --git a/runhelper/db.py b/runhelper/db.py index bec171bda..a19cc383a 100644 --- a/runhelper/db.py +++ b/runhelper/db.py @@ -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: diff --git a/runhelper/parameterstudy.py b/runhelper/parameterstudy.py index edfb77283..22d2bf2e3 100644 --- a/runhelper/parameterstudy.py +++ b/runhelper/parameterstudy.py @@ -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. diff --git a/simp/assignment_collection.py b/simp/assignment_collection.py index 1a19d0373..5d57addce 100644 --- a/simp/assignment_collection.py +++ b/simp/assignment_collection.py @@ -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: diff --git a/sympyextensions.py b/sympyextensions.py index b95fc6bc5..24c14c5f8 100644 --- a/sympyextensions.py +++ b/sympyextensions.py @@ -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): diff --git a/transformations.py b/transformations.py index f5d09bb31..8a2cf9992 100644 --- a/transformations.py +++ b/transformations.py @@ -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) -- GitLab