Skip to content

Commit

Permalink
Enable ruff Linter (#24)
Browse files Browse the repository at this point in the history
Enable ruff linter and fix errors (mostly sorting imports).
  • Loading branch information
fthaler authored Jun 24, 2024
1 parent 0a47c0f commit dce3117
Show file tree
Hide file tree
Showing 34 changed files with 169 additions and 90 deletions.
3 changes: 2 additions & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,13 +32,14 @@
# SPDX-License-Identifier: BSD-3-Clause
import os
import re

import setuptools


def read_file(*path):
"""Read file content."""
package_path = os.path.abspath(os.path.dirname(__file__))
with open(os.path.join(package_path, *path), 'r') as text_file:
with open(os.path.join(package_path, *path)) as text_file:
return text_file.read()


Expand Down
4 changes: 2 additions & 2 deletions stencil_benchmarks/benchmarks_collection/stencils/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -368,11 +368,11 @@ def __setitem__(self, index, value):

if not self.all_components:
(ustage, upos, utens, utensstage, wcon, ccol, dcol,
datacol) = [Wrapper(data) for data in data_before]
datacol) = (Wrapper(data) for data in data_before)
else:
(ustage, upos, utens, utensstage, vstage, vpos, vtens, vtensstage,
wstage, wpos, wtens, wtensstage, wcon, ccol, dcol,
datacol) = [Wrapper(data) for data in data_before]
datacol) = (Wrapper(data) for data in data_before)

dtr_stage = 3 / 20
beta_v = 0
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,8 +30,6 @@
# POSSIBILITY OF SUCH DAMAGE.
#
# SPDX-License-Identifier: BSD-3-Clause
from . import basic
from . import horizontal_diffusion
from . import vertical_advection
from . import basic, horizontal_diffusion, vertical_advection

__all__ = ['basic', 'horizontal_diffusion', 'vertical_advection']
Original file line number Diff line number Diff line change
Expand Up @@ -33,8 +33,8 @@
from stencil_benchmarks.benchmark import Parameter
from stencil_benchmarks.benchmarks_collection.stencils import base

from .mixin import StencilMixin
from .basic import BasicStencilMixin
from .mixin import StencilMixin


class HorizontalDiffusionMixin(StencilMixin):
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,9 +36,14 @@
import os
import warnings

from stencil_benchmarks.benchmark import (Benchmark, ExecutionError, Parameter,
ParameterError)
from stencil_benchmarks.tools import array, cpphelpers, compilation, template
from stencil_benchmarks.benchmark import (
Benchmark,
ExecutionError,
Parameter,
ParameterError,
)
from stencil_benchmarks.tools import array, compilation, cpphelpers, template

from . import api


Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,8 +33,9 @@
import numpy as np

from stencil_benchmarks.benchmark import Parameter
from .mixin import StencilMixin

from .. import base
from .mixin import StencilMixin


class BasicStencilMixin(StencilMixin):
Expand Down Expand Up @@ -96,7 +97,8 @@ class Laplacian(BasicStencilMixin, base.LaplacianStencil):
choices=['pad', 'set', 'roll', 'convolve'])

def stencil_definition(self):
from jax import numpy as jnp, scipy as jsp
from jax import numpy as jnp
from jax import scipy as jsp

along_axes = (self.along_x, self.along_y, self.along_z)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,8 +30,8 @@
# POSSIBILITY OF SUCH DAMAGE.
#
# SPDX-License-Identifier: BSD-3-Clause
from .mixin import StencilMixin
from .. import base
from .mixin import StencilMixin


class HdiffStencilMixin(StencilMixin):
Expand Down Expand Up @@ -84,7 +84,8 @@ def stencil(inp, coeff, out):

class Vmapped(HdiffStencilMixin, base.HorizontalDiffusionStencil):
def stencil_definition(self):
from jax import numpy as jnp, vmap
from jax import numpy as jnp
from jax import vmap

def plane(inp, coeff):
lap = 4 * inp[1:-1, 1:-1] - (inp[2:, 1:-1] + inp[:-2, 1:-1] +
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,8 +31,9 @@
#
# SPDX-License-Identifier: BSD-3-Clause
from stencil_benchmarks.benchmark import Parameter, ParameterError
from .mixin import StencilMixin

from .. import base
from .mixin import StencilMixin


class VadvStencilMixin(StencilMixin):
Expand All @@ -56,7 +57,8 @@ class PlaneLoop(VadvStencilMixin, base.VerticalAdvectionStencil):
loop = Parameter('loop implementation', 'jax', choices=['jax', 'python'])

def stencil_definition(self):
from jax import lax, numpy as jnp
from jax import lax
from jax import numpy as jnp

dtr_stage = 3 / 20
beta_v = 0
Expand Down Expand Up @@ -175,7 +177,7 @@ def backward(k, args):
utensstage = utensstage.data
if self.loop == 'jax':
_, utensstage = lax.fori_loop(
-(self.domain[2] - 2), -(-1),
-(self.domain[2] - 2), 1,
lambda nk, args: backward(-nk, args),
(datacol, utensstage))
else:
Expand All @@ -191,7 +193,8 @@ class ColumnLoop(VadvStencilMixin, base.VerticalAdvectionStencil):
loop = Parameter('loop implementation', 'jax', choices=['jax', 'python'])

def stencil_definition(self):
from jax import lax, numpy as jnp, vmap
from jax import lax, vmap
from jax import numpy as jnp

dtr_stage = 3 / 20
beta_v = 0
Expand Down Expand Up @@ -280,7 +283,7 @@ def backward(k, args):

if self.loop == 'jax':
_, utensstage = lax.fori_loop(
-(self.domain[2] - 2), -(-1),
-(self.domain[2] - 2), 1,
lambda nk, args: backward(-nk, args),
(datacol, utensstage))
else:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,8 +30,8 @@
# POSSIBILITY OF SUCH DAMAGE.
#
# SPDX-License-Identifier: BSD-3-Clause
from .. import base
from ....tools import timing
from .. import base

# pylint: disable=not-an-iterable

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,6 @@
# POSSIBILITY OF SUCH DAMAGE.
#
# SPDX-License-Identifier: BSD-3-Clause
from . import basic
from . import horizontal_diffusion
from . import basic, horizontal_diffusion

__all__ = ['basic', 'horizontal_diffusion']
Original file line number Diff line number Diff line change
Expand Up @@ -32,9 +32,13 @@
# SPDX-License-Identifier: BSD-3-Clause
import numpy as np

from ..base import (CopyStencil, OnesidedAverageStencil,
SymmetricAverageStencil, LaplacianStencil)
from ....tools import timing
from ..base import (
CopyStencil,
LaplacianStencil,
OnesidedAverageStencil,
SymmetricAverageStencil,
)


class Copy1D(CopyStencil):
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,8 +32,8 @@
# SPDX-License-Identifier: BSD-3-Clause
import numpy as np

from ..base import HorizontalDiffusionStencil
from ....tools import timing
from ..base import HorizontalDiffusionStencil


class OnTheFly(HorizontalDiffusionStencil):
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,8 +30,6 @@
# POSSIBILITY OF SUCH DAMAGE.
#
# SPDX-License-Identifier: BSD-3-Clause
from . import basic
from . import horizontal_diffusion
from . import vertical_advection
from . import basic, horizontal_diffusion, vertical_advection

__all__ = ['basic', 'horizontal_diffusion', 'vertical_advection']
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ def stencil_body_vec(self):
body = re.sub(
r'out\[index\] = ([^;]*)', r'storent(&out[index], \1)'
if self.streaming_stores else r'store(&out[index], \1)', body,
re.MULTILINE | re.DOTALL)
flags=re.MULTILINE | re.DOTALL)
return body

def template_file(self):
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,8 +33,8 @@
from stencil_benchmarks.benchmark import Parameter
from stencil_benchmarks.benchmarks_collection.stencils import base

from .mixin import StencilMixin
from .basic import BasicStencilMixin
from .mixin import StencilMixin


class HorizontalDiffusionMixin(StencilMixin):
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@
import warnings

from stencil_benchmarks.benchmark import Benchmark, ExecutionError, Parameter
from stencil_benchmarks.tools import cpphelpers, compilation, template
from stencil_benchmarks.tools import compilation, cpphelpers, template


class StencilMixin(Benchmark):
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,6 @@
# POSSIBILITY OF SUCH DAMAGE.
#
# SPDX-License-Identifier: BSD-3-Clause
from . import mc_calpin, cuda_hip
from . import cuda_hip, mc_calpin

__all__ = ['mc_calpin', 'cuda_hip']
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@
import re
import warnings

from ...benchmark import Benchmark, Parameter, ExecutionError
from ...benchmark import Benchmark, ExecutionError, Parameter
from ...tools import compilation, cpphelpers, template


Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@

import numpy as np

from ...benchmark import Benchmark, Parameter, ParameterError, ExecutionError
from ...benchmark import Benchmark, ExecutionError, Parameter, ParameterError
from ...tools import compilation, cpphelpers, template


Expand Down
3 changes: 2 additions & 1 deletion stencil_benchmarks/cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,8 @@
import click

from . import benchmark
from .tools import cli as cli_tools, validation
from .tools import cli as cli_tools
from .tools import validation


def _cli_command(bmark):
Expand Down
17 changes: 12 additions & 5 deletions stencil_benchmarks/scripts/sbench_a100_collection.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,12 +33,19 @@

import click

from stencil_benchmarks.benchmarks_collection.stencils.cuda_hip import basic
from stencil_benchmarks.benchmarks_collection.stencils.cuda_hip import (
basic, horizontal_diffusion as hdiff, vertical_advection as vadv)
from stencil_benchmarks.tools.multirun import (Configuration,
run_scaling_benchmark,
truncate_block_size_to_domain,
default_kwargs)
horizontal_diffusion as hdiff,
)
from stencil_benchmarks.benchmarks_collection.stencils.cuda_hip import (
vertical_advection as vadv,
)
from stencil_benchmarks.tools.multirun import (
Configuration,
default_kwargs,
run_scaling_benchmark,
truncate_block_size_to_domain,
)


@click.group()
Expand Down
25 changes: 19 additions & 6 deletions stencil_benchmarks/scripts/sbench_a64fx_collection.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,15 +36,28 @@
import click
import numpy as np

from stencil_benchmarks.benchmarks_collection.stencils.openmp import basic
from stencil_benchmarks.benchmarks_collection.stencils.openmp import (
basic, horizontal_diffusion as hdiff, vertical_advection as vadv)
horizontal_diffusion as hdiff,
)
from stencil_benchmarks.benchmarks_collection.stencils.openmp import (
vertical_advection as vadv,
)
from stencil_benchmarks.benchmarks_collection.stencils.openmp_blocked import (
basic as basic_blocked,
)
from stencil_benchmarks.benchmarks_collection.stencils.openmp_blocked import (
horizontal_diffusion as hdiff_blocked,
)
from stencil_benchmarks.benchmarks_collection.stencils.openmp_blocked import (
basic as basic_blocked, horizontal_diffusion as hdiff_blocked,
vertical_advection as vadv_blocked)
from stencil_benchmarks.tools.multirun import (Configuration,
run_scaling_benchmark,
truncate_block_size_to_domain)
vertical_advection as vadv_blocked,
)
from stencil_benchmarks.tools import alloc
from stencil_benchmarks.tools.multirun import (
Configuration,
run_scaling_benchmark,
truncate_block_size_to_domain,
)


@click.group()
Expand Down
3 changes: 2 additions & 1 deletion stencil_benchmarks/scripts/sbench_analyze.py
Original file line number Diff line number Diff line change
Expand Up @@ -171,8 +171,9 @@ def plot(csv, uniform, ylim, title, auto_group, group, select, filter,
X is the data column name for the values used for the x-axis in the plot, Y
is the column name for the y-axis.
"""
from matplotlib import pyplot as plt, ticker
import cycler
from matplotlib import pyplot as plt
from matplotlib import ticker
if output:
plt.switch_backend('Agg')
elif ascii:
Expand Down
17 changes: 12 additions & 5 deletions stencil_benchmarks/scripts/sbench_h100_collection.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,12 +33,19 @@

import click

from stencil_benchmarks.benchmarks_collection.stencils.cuda_hip import basic
from stencil_benchmarks.benchmarks_collection.stencils.cuda_hip import (
basic, horizontal_diffusion as hdiff, vertical_advection as vadv)
from stencil_benchmarks.tools.multirun import (Configuration,
run_scaling_benchmark,
truncate_block_size_to_domain,
default_kwargs)
horizontal_diffusion as hdiff,
)
from stencil_benchmarks.benchmarks_collection.stencils.cuda_hip import (
vertical_advection as vadv,
)
from stencil_benchmarks.tools.multirun import (
Configuration,
default_kwargs,
run_scaling_benchmark,
truncate_block_size_to_domain,
)


@click.group()
Expand Down
17 changes: 12 additions & 5 deletions stencil_benchmarks/scripts/sbench_mi100_collection.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,12 +33,19 @@

import click

from stencil_benchmarks.benchmarks_collection.stencils.cuda_hip import basic
from stencil_benchmarks.benchmarks_collection.stencils.cuda_hip import (
basic, horizontal_diffusion as hdiff, vertical_advection as vadv)
from stencil_benchmarks.tools.multirun import (Configuration,
run_scaling_benchmark,
truncate_block_size_to_domain,
default_kwargs)
horizontal_diffusion as hdiff,
)
from stencil_benchmarks.benchmarks_collection.stencils.cuda_hip import (
vertical_advection as vadv,
)
from stencil_benchmarks.tools.multirun import (
Configuration,
default_kwargs,
run_scaling_benchmark,
truncate_block_size_to_domain,
)


@click.group()
Expand Down
Loading

0 comments on commit dce3117

Please sign in to comment.