From cdd16aa5369fc20043c3d37a84f901febec2c8dc Mon Sep 17 00:00:00 2001 From: Alexandru Fikl Date: Mon, 19 Aug 2024 11:44:58 +0300 Subject: [PATCH] fix new ruff UP031 errors --- examples/advection/surface.py | 4 ++-- examples/advection/var-velocity.py | 2 +- examples/advection/weak.py | 2 +- grudge/geometry/metrics.py | 2 +- grudge/op.py | 5 +++-- test/test_grudge.py | 6 +++--- 6 files changed, 11 insertions(+), 10 deletions(-) diff --git a/examples/advection/surface.py b/examples/advection/surface.py index c7b96c69..8eca7ab4 100644 --- a/examples/advection/surface.py +++ b/examples/advection/surface.py @@ -222,7 +222,7 @@ def rhs(t, u): step = 0 event = dt_stepper.StateComputed(0.0, 0, 0, u0) - plot(event, "fld-surface-%04d" % 0) + plot(event, f"fld-surface-{0:04d}") if visualize and dim == 3: from grudge.shortcuts import make_visualizer @@ -253,7 +253,7 @@ def rhs(t, u): step += 1 if step % 10 == 0: norm_u = actx.to_numpy(op.norm(dcoll, event.state_component, 2)) - plot(event, "fld-surface-%04d" % step) + plot(event, f"fld-surface-{step:04d}") logger.info("[%04d] t = %.5f |u| = %.5e", step, event.t, norm_u) diff --git a/examples/advection/var-velocity.py b/examples/advection/var-velocity.py index 7b6cebd8..753bf263 100644 --- a/examples/advection/var-velocity.py +++ b/examples/advection/var-velocity.py @@ -211,7 +211,7 @@ def rhs(t, u): if step % 10 == 0: norm_u = actx.to_numpy(op.norm(dcoll, event.state_component, 2)) - plot(event, "fld-var-velocity-%04d" % step) + plot(event, f"fld-var-velocity-{step:04d}") logger.info("[%04d] t = %.5f |u| = %.5e", step, event.t, norm_u) # NOTE: These are here to ensure the solution is bounded for the diff --git a/examples/advection/weak.py b/examples/advection/weak.py index 35ef9bf8..72a2932d 100644 --- a/examples/advection/weak.py +++ b/examples/advection/weak.py @@ -184,7 +184,7 @@ def rhs(t, u): if step % 10 == 0: norm_u = actx.to_numpy(op.norm(dcoll, event.state_component, 2)) - plot(event, "fld-weak-%04d" % step) + plot(event, f"fld-weak-{step:04d}") step += 1 logger.info("[%04d] t = %.5f |u| = %.5e", step, event.t, norm_u) diff --git a/grudge/geometry/metrics.py b/grudge/geometry/metrics.py index e1fbe8f4..67fd19bb 100644 --- a/grudge/geometry/metrics.py +++ b/grudge/geometry/metrics.py @@ -837,7 +837,7 @@ def second_fundamental_form( elif dim == 2: second_ref_axes = [((0, 2),), ((0, 1), (1, 1)), ((1, 2),)] else: - raise ValueError("%dD surfaces not supported" % dim) + raise ValueError(f"{dim}D surfaces not supported") from pytools import flatten diff --git a/grudge/op.py b/grudge/op.py index f9e762f1..468024e4 100644 --- a/grudge/op.py +++ b/grudge/op.py @@ -217,8 +217,9 @@ def _gradient_kernel(actx, out_discr, in_discr, get_diff_mat, inv_jac_mat, vec, inv_jac_mat)] return make_obj_array([ - DOFArray( - actx, data=tuple([pgg_i[xyz_axis] for pgg_i in per_group_grads])) + DOFArray(actx, data=tuple([ # noqa: C409 + pgg_i[xyz_axis] for pgg_i in per_group_grads + ])) for xyz_axis in range(out_discr.ambient_dim)]) diff --git a/test/test_grudge.py b/test/test_grudge.py index 8a5a5a67..b0849310 100644 --- a/test/test_grudge.py +++ b/test/test_grudge.py @@ -784,7 +784,7 @@ def test_convergence_advec(actx_factory, mesh_name, mesh_pars, op_type, flux_typ elif dim == 3: dt_factor = 2 else: - raise ValueError("dt_factor not known for %dd" % dim) + raise ValueError(f"dt_factor not known for {dim}d") elif mesh_name.startswith("warped"): dim = int(mesh_name[-1:]) mesh = mgen.generate_warped_rect_mesh(dim, order=order, @@ -795,7 +795,7 @@ def test_convergence_advec(actx_factory, mesh_name, mesh_pars, op_type, flux_typ elif dim == 3: dt_factor = 2 else: - raise ValueError("dt_factor not known for %dd" % dim) + raise ValueError(f"dt_factor not known for {dim}d") else: raise ValueError("invalid mesh name: " + mesh_name) @@ -861,7 +861,7 @@ def rhs(t, u, adv_operator=adv_operator): if visualize: vis.write_vtk_file( - "fld-%s-%04d.vtu" % (mesh_par, step), + f"fld-{mesh_par}-{step:04d}vtu" % (mesh_par, step), [("u", u)] )