From 19991c83fc34a014f21a829e34becfcc3dac6458 Mon Sep 17 00:00:00 2001 From: Sylwester Arabas Date: Wed, 7 Feb 2024 18:30:36 +0100 Subject: [PATCH] code formatting updates to match changes in black requirements --- .pre-commit-config.yaml | 6 +-- PyMPDATA/__init__.py | 1 + PyMPDATA/boundary_conditions/__init__.py | 1 + PyMPDATA/boundary_conditions/constant.py | 1 + PyMPDATA/boundary_conditions/extrapolated.py | 1 + PyMPDATA/boundary_conditions/periodic.py | 1 + PyMPDATA/boundary_conditions/polar.py | 1 + PyMPDATA/impl/clock.py | 1 + PyMPDATA/impl/domain_decomposition.py | 1 + PyMPDATA/impl/enumerations.py | 1 + PyMPDATA/impl/field.py | 1 + PyMPDATA/impl/formulae_antidiff.py | 21 ++++++----- PyMPDATA/impl/formulae_axpy.py | 1 + PyMPDATA/impl/formulae_flux.py | 37 +++++++++++-------- PyMPDATA/impl/formulae_laplacian.py | 11 ++++-- PyMPDATA/impl/formulae_nonoscillatory.py | 8 ++-- PyMPDATA/impl/formulae_upwind.py | 9 +++-- PyMPDATA/impl/grid.py | 1 + PyMPDATA/impl/indexers.py | 1 + PyMPDATA/impl/meta.py | 1 + PyMPDATA/impl/traversals.py | 1 + PyMPDATA/impl/traversals_common.py | 1 + PyMPDATA/impl/traversals_halos_scalar.py | 1 + PyMPDATA/impl/traversals_halos_vector.py | 1 + PyMPDATA/impl/traversals_scalar.py | 1 + PyMPDATA/impl/traversals_vector.py | 1 + PyMPDATA/options.py | 1 + PyMPDATA/scalar_field.py | 1 + PyMPDATA/solver.py | 25 ++++++++----- PyMPDATA/stepper.py | 1 + PyMPDATA/vector_field.py | 1 + .../Shipway_and_Hill_2012/settings.py | 4 +- examples/PyMPDATA_examples/__init__.py | 1 + examples/setup.py | 1 + setup.py | 1 + tests/smoke_tests/timing/fixtures.py | 1 + 36 files changed, 100 insertions(+), 49 deletions(-) diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml index bfa52bae..b7727740 100644 --- a/.pre-commit-config.yaml +++ b/.pre-commit-config.yaml @@ -4,18 +4,18 @@ default_stages: [commit] repos: - repo: https://github.com/psf/black - rev: 23.1.0 + rev: 24.1.1 hooks: - id: black - repo: https://github.com/timothycrosley/isort - rev: 5.12.0 + rev: 5.13.2 hooks: - id: isort args: ["--profile", "black"] - repo: https://github.com/pre-commit/pre-commit-hooks - rev: v4.4.0 + rev: v4.5.0 hooks: - id: trailing-whitespace - id: end-of-file-fixer diff --git a/PyMPDATA/__init__.py b/PyMPDATA/__init__.py index afb58b25..b737f921 100644 --- a/PyMPDATA/__init__.py +++ b/PyMPDATA/__init__.py @@ -7,6 +7,7 @@ `PyMPDATA.vector_field.VectorField` elements: ![](https://github.com/atmos-cloud-sim-uj/PyMPDATA/releases/download/tip/readme_grid.png) """ + # pylint: disable=invalid-name from importlib.metadata import PackageNotFoundError, version diff --git a/PyMPDATA/boundary_conditions/__init__.py b/PyMPDATA/boundary_conditions/__init__.py index 021da215..43983351 100644 --- a/PyMPDATA/boundary_conditions/__init__.py +++ b/PyMPDATA/boundary_conditions/__init__.py @@ -1,4 +1,5 @@ """ classes representing boundary conditions """ + from .constant import Constant from .extrapolated import Extrapolated from .periodic import Periodic diff --git a/PyMPDATA/boundary_conditions/constant.py b/PyMPDATA/boundary_conditions/constant.py index a2ff9166..2dde8a84 100644 --- a/PyMPDATA/boundary_conditions/constant.py +++ b/PyMPDATA/boundary_conditions/constant.py @@ -1,4 +1,5 @@ """ boundary condition filling halos with a constant value """ + # pylint: disable=too-many-arguments from functools import lru_cache diff --git a/PyMPDATA/boundary_conditions/extrapolated.py b/PyMPDATA/boundary_conditions/extrapolated.py index 6fe44116..46cd8d86 100644 --- a/PyMPDATA/boundary_conditions/extrapolated.py +++ b/PyMPDATA/boundary_conditions/extrapolated.py @@ -1,6 +1,7 @@ """ boundary condition extrapolating values from the edge to the halo for scalars and returning edge-of-the-domain value for vectors (with all negative scalar values set to zero) """ + # pylint: disable=too-many-arguments from functools import lru_cache diff --git a/PyMPDATA/boundary_conditions/periodic.py b/PyMPDATA/boundary_conditions/periodic.py index 52ec5a58..6754649d 100644 --- a/PyMPDATA/boundary_conditions/periodic.py +++ b/PyMPDATA/boundary_conditions/periodic.py @@ -1,4 +1,5 @@ """ periodic/cyclic boundary condition logic """ + from functools import lru_cache import numba diff --git a/PyMPDATA/boundary_conditions/polar.py b/PyMPDATA/boundary_conditions/polar.py index 56b89766..fb4dcf4f 100644 --- a/PyMPDATA/boundary_conditions/polar.py +++ b/PyMPDATA/boundary_conditions/polar.py @@ -1,4 +1,5 @@ """ polar boundary condition for use in with spherical coordinates """ + from functools import lru_cache import numba diff --git a/PyMPDATA/impl/clock.py b/PyMPDATA/impl/clock.py index 282aac04..36388ff8 100644 --- a/PyMPDATA/impl/clock.py +++ b/PyMPDATA/impl/clock.py @@ -1,5 +1,6 @@ """ CPU-time returning clock() function which works from within njit-ted code, no time unit guaranteed, returned value only for relative time measurements """ + import ctypes clock = ctypes.pythonapi._PyTime_GetSystemClock # pylint:disable=protected-access diff --git a/PyMPDATA/impl/domain_decomposition.py b/PyMPDATA/impl/domain_decomposition.py index d53ed145..c347c093 100644 --- a/PyMPDATA/impl/domain_decomposition.py +++ b/PyMPDATA/impl/domain_decomposition.py @@ -1,4 +1,5 @@ """ logic defining domain decomposition scheme for multi-threading """ + import math import numba diff --git a/PyMPDATA/impl/enumerations.py b/PyMPDATA/impl/enumerations.py index af482022..20424ea4 100644 --- a/PyMPDATA/impl/enumerations.py +++ b/PyMPDATA/impl/enumerations.py @@ -1,4 +1,5 @@ """ common constants (mostly integer indices used for indexing tuples) """ + import numpy as np ARG_FOCUS, ARG_DATA, ARG_DATA_OUTER, ARG_DATA_MID3D, ARG_DATA_INNER = 0, 1, 1, 2, 3 diff --git a/PyMPDATA/impl/field.py b/PyMPDATA/impl/field.py index 29e8a2b4..1405bf89 100644 --- a/PyMPDATA/impl/field.py +++ b/PyMPDATA/impl/field.py @@ -1,5 +1,6 @@ """ common logic for `PyMPDATA.scalar_field.ScalarField` and `PyMPDATA.vector_field.VectorField` classes """ + import abc from collections import namedtuple diff --git a/PyMPDATA/impl/formulae_antidiff.py b/PyMPDATA/impl/formulae_antidiff.py index f90ddf94..4c9c03f3 100644 --- a/PyMPDATA/impl/formulae_antidiff.py +++ b/PyMPDATA/impl/formulae_antidiff.py @@ -1,5 +1,6 @@ """ antidiffusive velocity formulae incl. divergent-flow, third-order-terms, DPDC and partially also infinite-gauge logic """ + import numba import numpy as np @@ -12,16 +13,18 @@ def make_antidiff(non_unit_g_factor, options, traversals, last_pass=False): apply_vector = traversals.apply_vector() formulae_antidiff = tuple( - __make_antidiff( - atv=idx.atv[i], - ats=idx.ats[i], - non_unit_g_factor=non_unit_g_factor, - options=options, - n_dims=traversals.n_dims, - last_pass=last_pass, + ( + __make_antidiff( + atv=idx.atv[i], + ats=idx.ats[i], + non_unit_g_factor=non_unit_g_factor, + options=options, + n_dims=traversals.n_dims, + last_pass=last_pass, + ) + if idx.ats[i] is not None + else None ) - if idx.ats[i] is not None - else None for i in range(MAX_DIM_NUM) ) diff --git a/PyMPDATA/impl/formulae_axpy.py b/PyMPDATA/impl/formulae_axpy.py index 40d9514c..f943b944 100644 --- a/PyMPDATA/impl/formulae_axpy.py +++ b/PyMPDATA/impl/formulae_axpy.py @@ -1,4 +1,5 @@ """ basic a*x+y operation logic for use in Fickian term handling """ + import numba from .enumerations import INNER, MID3D, OUTER diff --git a/PyMPDATA/impl/formulae_flux.py b/PyMPDATA/impl/formulae_flux.py index e9865da8..e25d8941 100644 --- a/PyMPDATA/impl/formulae_flux.py +++ b/PyMPDATA/impl/formulae_flux.py @@ -1,4 +1,5 @@ """ staggered-grid flux logic including infinite-gauge logic handling """ + import numba import numpy as np @@ -11,15 +12,17 @@ def make_flux_first_pass(options, traversals): apply_vector = traversals.apply_vector() formulae_flux_first_pass = tuple( - __make_flux( - options.jit_flags, - idx.atv[i], - idx.ats[i], - first_pass=True, - infinite_gauge=False, + ( + __make_flux( + options.jit_flags, + idx.atv[i], + idx.ats[i], + first_pass=True, + infinite_gauge=False, + ) + if idx.ats[i] is not None + else None ) - if idx.ats[i] is not None - else None for i in range(MAX_DIM_NUM) ) @@ -47,15 +50,17 @@ def make_flux_subsequent(options, traversals): apply_vector = traversals.apply_vector() formulae_flux_subsequent = tuple( - __make_flux( - options.jit_flags, - idx.atv[i], - idx.ats[i], - first_pass=False, - infinite_gauge=options.infinite_gauge, + ( + __make_flux( + options.jit_flags, + idx.atv[i], + idx.ats[i], + first_pass=False, + infinite_gauge=options.infinite_gauge, + ) + if idx.ats[i] is not None + else None ) - if idx.ats[i] is not None - else None for i in range(MAX_DIM_NUM) ) diff --git a/PyMPDATA/impl/formulae_laplacian.py b/PyMPDATA/impl/formulae_laplacian.py index 9936e948..64711de0 100644 --- a/PyMPDATA/impl/formulae_laplacian.py +++ b/PyMPDATA/impl/formulae_laplacian.py @@ -1,4 +1,5 @@ """ logic for handling the Fickian term by modifying physical velocity """ + import numba from ..impl.enumerations import MAX_DIM_NUM @@ -19,11 +20,13 @@ def apply(_1, _2, _3): apply_vector = traversals.apply_vector() formulae_laplacian = tuple( - __make_laplacian( - options.jit_flags, idx.ats[i], options.epsilon, non_unit_g_factor + ( + __make_laplacian( + options.jit_flags, idx.ats[i], options.epsilon, non_unit_g_factor + ) + if idx.ats[i] is not None + else None ) - if idx.ats[i] is not None - else None for i in range(MAX_DIM_NUM) ) diff --git a/PyMPDATA/impl/formulae_nonoscillatory.py b/PyMPDATA/impl/formulae_nonoscillatory.py index adc2802e..ddd24e65 100644 --- a/PyMPDATA/impl/formulae_nonoscillatory.py +++ b/PyMPDATA/impl/formulae_nonoscillatory.py @@ -288,9 +288,11 @@ def apply(_, __, ___): apply_vector = traversals.apply_vector() formulae = tuple( - __make_correction(options.jit_flags, idx.ats[i], idx.atv[i]) - if idx.ats[i] is not None - else None + ( + __make_correction(options.jit_flags, idx.ats[i], idx.atv[i]) + if idx.ats[i] is not None + else None + ) for i in range(MAX_DIM_NUM) ) diff --git a/PyMPDATA/impl/formulae_upwind.py b/PyMPDATA/impl/formulae_upwind.py index 78d611a8..d304b233 100644 --- a/PyMPDATA/impl/formulae_upwind.py +++ b/PyMPDATA/impl/formulae_upwind.py @@ -1,4 +1,5 @@ """ upwind/donor-cell formula logic including G-factor handling """ + import numba from PyMPDATA.impl.enumerations import MAX_DIM_NUM @@ -10,9 +11,11 @@ def make_upwind(options, non_unit_g_factor, traversals): idx = traversals.indexers[traversals.n_dims] formulae_upwind = tuple( - __make_upwind(options.jit_flags, idx.atv[i], idx.ats[i], non_unit_g_factor) - if idx.ats[i] is not None - else None + ( + __make_upwind(options.jit_flags, idx.atv[i], idx.ats[i], non_unit_g_factor) + if idx.ats[i] is not None + else None + ) for i in range(MAX_DIM_NUM) ) diff --git a/PyMPDATA/impl/grid.py b/PyMPDATA/impl/grid.py index 39874489..b6b5222d 100644 --- a/PyMPDATA/impl/grid.py +++ b/PyMPDATA/impl/grid.py @@ -1,6 +1,7 @@ """ static (extents known to JIT) and dynamic (run-time extents) grid handling logic """ + import numba from PyMPDATA.impl.domain_decomposition import make_subdomain diff --git a/PyMPDATA/impl/indexers.py b/PyMPDATA/impl/indexers.py index c82497d8..4874fcfa 100644 --- a/PyMPDATA/impl/indexers.py +++ b/PyMPDATA/impl/indexers.py @@ -1,4 +1,5 @@ """ array indexing logic for 1D, 2D and 3D staggered grids """ + # pylint: disable=missing-function-docstring from collections import namedtuple diff --git a/PyMPDATA/impl/meta.py b/PyMPDATA/impl/meta.py index 44a2ac67..73359287 100644 --- a/PyMPDATA/impl/meta.py +++ b/PyMPDATA/impl/meta.py @@ -1,4 +1,5 @@ """ constants for indexing and a factory for creating the "meta" tuples """ + from collections import namedtuple from pathlib import Path diff --git a/PyMPDATA/impl/traversals.py b/PyMPDATA/impl/traversals.py index b565a4e9..a94c4ba0 100644 --- a/PyMPDATA/impl/traversals.py +++ b/PyMPDATA/impl/traversals.py @@ -1,4 +1,5 @@ """ staggered-grid traversals orchestration """ + from collections import namedtuple from pathlib import Path diff --git a/PyMPDATA/impl/traversals_common.py b/PyMPDATA/impl/traversals_common.py index a6f1f702..343ca576 100644 --- a/PyMPDATA/impl/traversals_common.py +++ b/PyMPDATA/impl/traversals_common.py @@ -1,4 +1,5 @@ """ commons for scalar and vector field traversals """ + # pylint: disable=too-many-arguments,line-too-long,unused-argument import numba diff --git a/PyMPDATA/impl/traversals_halos_scalar.py b/PyMPDATA/impl/traversals_halos_scalar.py index c27a6ce0..c2cc588d 100644 --- a/PyMPDATA/impl/traversals_halos_scalar.py +++ b/PyMPDATA/impl/traversals_halos_scalar.py @@ -1,4 +1,5 @@ """ halo-filling logic for scalar field traversals (incl. multi-threading) """ + # pylint: disable=too-many-arguments import numba diff --git a/PyMPDATA/impl/traversals_halos_vector.py b/PyMPDATA/impl/traversals_halos_vector.py index 61c6aa8f..71f4cc7f 100644 --- a/PyMPDATA/impl/traversals_halos_vector.py +++ b/PyMPDATA/impl/traversals_halos_vector.py @@ -1,4 +1,5 @@ """ halo-filling logic for vector field traversals (incl. multi-threading) """ + # pylint: disable=too-many-statements,too-many-locals,too-many-lines,too-many-function-args,too-many-arguments import numba diff --git a/PyMPDATA/impl/traversals_scalar.py b/PyMPDATA/impl/traversals_scalar.py index 0395e4a2..d53c027f 100644 --- a/PyMPDATA/impl/traversals_scalar.py +++ b/PyMPDATA/impl/traversals_scalar.py @@ -1,4 +1,5 @@ """ scalar field traversals (incl. multi-threading) """ + import numba from .enumerations import INNER, INVALID_INDEX, MID3D, RNG_START, RNG_STOP diff --git a/PyMPDATA/impl/traversals_vector.py b/PyMPDATA/impl/traversals_vector.py index 5fd99dc6..d6785067 100644 --- a/PyMPDATA/impl/traversals_vector.py +++ b/PyMPDATA/impl/traversals_vector.py @@ -1,4 +1,5 @@ """ vector field traversals (incl. multi-threading) """ + import numba from .enumerations import ( diff --git a/PyMPDATA/options.py b/PyMPDATA/options.py index a06c95f9..8968105d 100644 --- a/PyMPDATA/options.py +++ b/PyMPDATA/options.py @@ -1,6 +1,7 @@ """ MPDATA variants, iterations, data-type and jit-flags settings """ + import numpy as np from pystrict import strict diff --git a/PyMPDATA/scalar_field.py b/PyMPDATA/scalar_field.py index c7ed0f60..03fbe526 100644 --- a/PyMPDATA/scalar_field.py +++ b/PyMPDATA/scalar_field.py @@ -1,6 +1,7 @@ """ scalar field abstractions for the staggered grid """ + import inspect import numpy as np diff --git a/PyMPDATA/solver.py b/PyMPDATA/solver.py index 054ae802..98300131 100644 --- a/PyMPDATA/solver.py +++ b/PyMPDATA/solver.py @@ -2,6 +2,7 @@ class grouping user-supplied stepper, fields and post-step/post-iter hooks, as well as self-initialised temporary storage """ + from typing import Union import numba @@ -71,15 +72,21 @@ def null_vector_field(): "g_factor": g_factor or null_scalar_field(), "vectmp_a": vector_field(), "vectmp_b": vector_field(), - "vectmp_c": vector_field() - if stepper.options.non_zero_mu_coeff - else null_vector_field(), - "nonosc_xtrm": scalar_field(dtype=complex) - if stepper.options.nonoscillatory - else null_scalar_field(), - "nonosc_beta": scalar_field(dtype=complex) - if stepper.options.nonoscillatory - else null_scalar_field(), + "vectmp_c": ( + vector_field() + if stepper.options.non_zero_mu_coeff + else null_vector_field() + ), + "nonosc_xtrm": ( + scalar_field(dtype=complex) + if stepper.options.nonoscillatory + else null_scalar_field() + ), + "nonosc_beta": ( + scalar_field(dtype=complex) + if stepper.options.nonoscillatory + else null_scalar_field() + ), } for field in self.__fields.values(): field.assemble(stepper.traversals) diff --git a/PyMPDATA/stepper.py b/PyMPDATA/stepper.py index a906ece5..ea82cdb9 100644 --- a/PyMPDATA/stepper.py +++ b/PyMPDATA/stepper.py @@ -1,4 +1,5 @@ """ MPDATA iteration logic """ + import sys import warnings from functools import lru_cache diff --git a/PyMPDATA/vector_field.py b/PyMPDATA/vector_field.py index d7ab78ac..66795982 100644 --- a/PyMPDATA/vector_field.py +++ b/PyMPDATA/vector_field.py @@ -1,6 +1,7 @@ """ vector field abstractions for the staggered grid """ + import inspect import numpy as np diff --git a/examples/PyMPDATA_examples/Shipway_and_Hill_2012/settings.py b/examples/PyMPDATA_examples/Shipway_and_Hill_2012/settings.py index 6e8f7712..e61fe0b1 100644 --- a/examples/PyMPDATA_examples/Shipway_and_Hill_2012/settings.py +++ b/examples/PyMPDATA_examples/Shipway_and_Hill_2012/settings.py @@ -69,8 +69,8 @@ def drhod_dz(z, rhod): self.rhod = interp1d(z_points, rhod_solution.y[0]) self.t_1 = 600 * si.s - self.rhod_w = ( - lambda t: rhod_w_const * np.sin(np.pi * t / self.t_1) if t < self.t_1 else 0 + self.rhod_w = lambda t: ( + rhod_w_const * np.sin(np.pi * t / self.t_1) if t < self.t_1 else 0 ) self.r_min = r_min diff --git a/examples/PyMPDATA_examples/__init__.py b/examples/PyMPDATA_examples/__init__.py index 9dca3049..68e7940f 100644 --- a/examples/PyMPDATA_examples/__init__.py +++ b/examples/PyMPDATA_examples/__init__.py @@ -2,6 +2,7 @@ PyMPDATA_examples package includes common Python modules used in PyMPDATA smoke tests and in example notebooks (but the package wheels do not include the notebooks) """ + from importlib.metadata import PackageNotFoundError, version try: diff --git a/examples/setup.py b/examples/setup.py index d2a0b4e8..8234f4d1 100644 --- a/examples/setup.py +++ b/examples/setup.py @@ -1,4 +1,5 @@ """ the magick behind ``pip install ...`` """ + import os from setuptools import find_packages, setup diff --git a/setup.py b/setup.py index 4781d2ef..79792fc7 100644 --- a/setup.py +++ b/setup.py @@ -1,6 +1,7 @@ """ the magick behind ``pip install ...`` """ + import os import platform diff --git a/tests/smoke_tests/timing/fixtures.py b/tests/smoke_tests/timing/fixtures.py index ef815584..599b9cdf 100644 --- a/tests/smoke_tests/timing/fixtures.py +++ b/tests/smoke_tests/timing/fixtures.py @@ -1,4 +1,5 @@ """ pytest fixtures for timing tests """ + import numba import pytest