Skip to content

Commit

Permalink
code formatting updates to match changes in black requirements (#420)
Browse files Browse the repository at this point in the history
  • Loading branch information
slayoo authored Feb 8, 2024
1 parent 991dc77 commit accea4a
Show file tree
Hide file tree
Showing 36 changed files with 100 additions and 49 deletions.
6 changes: 3 additions & 3 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
1 change: 1 addition & 0 deletions PyMPDATA/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
1 change: 1 addition & 0 deletions PyMPDATA/boundary_conditions/__init__.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
""" classes representing boundary conditions """

from .constant import Constant
from .extrapolated import Extrapolated
from .periodic import Periodic
Expand Down
1 change: 1 addition & 0 deletions PyMPDATA/boundary_conditions/constant.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
""" boundary condition filling halos with a constant value """

# pylint: disable=too-many-arguments
from functools import lru_cache

Expand Down
1 change: 1 addition & 0 deletions PyMPDATA/boundary_conditions/extrapolated.py
Original file line number Diff line number Diff line change
@@ -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

Expand Down
1 change: 1 addition & 0 deletions PyMPDATA/boundary_conditions/periodic.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
""" periodic/cyclic boundary condition logic """

from functools import lru_cache

import numba
Expand Down
1 change: 1 addition & 0 deletions PyMPDATA/boundary_conditions/polar.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
""" polar boundary condition for use in with spherical coordinates """

from functools import lru_cache

import numba
Expand Down
1 change: 1 addition & 0 deletions PyMPDATA/impl/clock.py
Original file line number Diff line number Diff line change
@@ -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
Expand Down
1 change: 1 addition & 0 deletions PyMPDATA/impl/domain_decomposition.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
""" logic defining domain decomposition scheme for multi-threading """

import math

import numba
Expand Down
1 change: 1 addition & 0 deletions PyMPDATA/impl/enumerations.py
Original file line number Diff line number Diff line change
@@ -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
Expand Down
1 change: 1 addition & 0 deletions PyMPDATA/impl/field.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
""" common logic for `PyMPDATA.scalar_field.ScalarField` and
`PyMPDATA.vector_field.VectorField` classes """

import abc
from collections import namedtuple

Expand Down
21 changes: 12 additions & 9 deletions PyMPDATA/impl/formulae_antidiff.py
Original file line number Diff line number Diff line change
@@ -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

Expand All @@ -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)
)

Expand Down
1 change: 1 addition & 0 deletions PyMPDATA/impl/formulae_axpy.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
""" basic a*x+y operation logic for use in Fickian term handling """

import numba

from .enumerations import INNER, MID3D, OUTER
Expand Down
37 changes: 21 additions & 16 deletions PyMPDATA/impl/formulae_flux.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
""" staggered-grid flux logic including infinite-gauge logic handling """

import numba
import numpy as np

Expand All @@ -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)
)

Expand Down Expand Up @@ -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)
)

Expand Down
11 changes: 7 additions & 4 deletions PyMPDATA/impl/formulae_laplacian.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
""" logic for handling the Fickian term by modifying physical velocity """

import numba

from ..impl.enumerations import MAX_DIM_NUM
Expand All @@ -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)
)

Expand Down
8 changes: 5 additions & 3 deletions PyMPDATA/impl/formulae_nonoscillatory.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
)

Expand Down
9 changes: 6 additions & 3 deletions PyMPDATA/impl/formulae_upwind.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
""" upwind/donor-cell formula logic including G-factor handling """

import numba

from PyMPDATA.impl.enumerations import MAX_DIM_NUM
Expand All @@ -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)
)

Expand Down
1 change: 1 addition & 0 deletions PyMPDATA/impl/grid.py
Original file line number Diff line number Diff line change
@@ -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
Expand Down
1 change: 1 addition & 0 deletions PyMPDATA/impl/indexers.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
""" array indexing logic for 1D, 2D and 3D staggered grids """

# pylint: disable=missing-function-docstring

from collections import namedtuple
Expand Down
1 change: 1 addition & 0 deletions PyMPDATA/impl/meta.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
""" constants for indexing and a factory for creating the "meta" tuples """

from collections import namedtuple
from pathlib import Path

Expand Down
1 change: 1 addition & 0 deletions PyMPDATA/impl/traversals.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
""" staggered-grid traversals orchestration """

from collections import namedtuple
from pathlib import Path

Expand Down
1 change: 1 addition & 0 deletions PyMPDATA/impl/traversals_common.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
""" commons for scalar and vector field traversals """

# pylint: disable=too-many-arguments,line-too-long,unused-argument
import numba

Expand Down
1 change: 1 addition & 0 deletions PyMPDATA/impl/traversals_halos_scalar.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
""" halo-filling logic for scalar field traversals (incl. multi-threading) """

# pylint: disable=too-many-arguments
import numba

Expand Down
1 change: 1 addition & 0 deletions PyMPDATA/impl/traversals_halos_vector.py
Original file line number Diff line number Diff line change
@@ -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
Expand Down
1 change: 1 addition & 0 deletions PyMPDATA/impl/traversals_scalar.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
""" scalar field traversals (incl. multi-threading) """

import numba

from .enumerations import INNER, INVALID_INDEX, MID3D, RNG_START, RNG_STOP
Expand Down
1 change: 1 addition & 0 deletions PyMPDATA/impl/traversals_vector.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
""" vector field traversals (incl. multi-threading) """

import numba

from .enumerations import (
Expand Down
1 change: 1 addition & 0 deletions PyMPDATA/options.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
"""
MPDATA variants, iterations, data-type and jit-flags settings
"""

import numpy as np
from pystrict import strict

Expand Down
1 change: 1 addition & 0 deletions PyMPDATA/scalar_field.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
"""
scalar field abstractions for the staggered grid
"""

import inspect

import numpy as np
Expand Down
25 changes: 16 additions & 9 deletions PyMPDATA/solver.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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)
Expand Down
1 change: 1 addition & 0 deletions PyMPDATA/stepper.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
""" MPDATA iteration logic """

import sys
import warnings
from functools import lru_cache
Expand Down
1 change: 1 addition & 0 deletions PyMPDATA/vector_field.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
"""
vector field abstractions for the staggered grid
"""

import inspect

import numpy as np
Expand Down
4 changes: 2 additions & 2 deletions examples/PyMPDATA_examples/Shipway_and_Hill_2012/settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
1 change: 1 addition & 0 deletions examples/PyMPDATA_examples/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
1 change: 1 addition & 0 deletions examples/setup.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
""" the magick behind ``pip install ...`` """

import os

from setuptools import find_packages, setup
Expand Down
Loading

0 comments on commit accea4a

Please sign in to comment.