From 23f3ef49137756ea30bb0d03b4ac7983acf62136 Mon Sep 17 00:00:00 2001 From: Max Date: Wed, 29 Oct 2025 21:59:46 +0100 Subject: [PATCH 1/2] Fixed E711, E714, E721, and F722 with ruff --- src/struphy/console/profile.py | 2 +- src/struphy/diagnostics/diagn_tools.py | 6 +++--- .../eigenvalue_solvers/legacy/inner_products_1d.py | 4 ++-- .../eigenvalue_solvers/legacy/mass_matrices_3d_pre.py | 10 +++++----- src/struphy/eigenvalue_solvers/mass_matrices_1d.py | 6 +++--- src/struphy/eigenvalue_solvers/mass_matrices_2d.py | 10 +++++----- src/struphy/eigenvalue_solvers/mass_matrices_3d.py | 10 +++++----- src/struphy/feec/projectors.py | 8 ++++---- src/struphy/feec/psydac_derham.py | 6 +++--- src/struphy/feec/utilities.py | 2 +- src/struphy/feec/variational_utilities.py | 4 ++-- src/struphy/linear_algebra/saddle_point.py | 2 +- src/struphy/main.py | 2 +- .../pic/tests/test_pic_legacy_files/pusher_pos.py | 2 +- src/struphy/post_processing/cprofile_analyser.py | 4 ++-- src/struphy/post_processing/likwid/roofline_plotter.py | 4 ++-- src/struphy/post_processing/profile_struphy.py | 2 +- src/struphy/propagators/propagators_coupling.py | 2 +- 18 files changed, 43 insertions(+), 43 deletions(-) diff --git a/src/struphy/console/profile.py b/src/struphy/console/profile.py index a2f10ce66..733e81efc 100644 --- a/src/struphy/console/profile.py +++ b/src/struphy/console/profile.py @@ -110,7 +110,7 @@ def struphy_profile(dirs, replace, all, n_lines, print_callers, savefig): ) print("-" * 154) for position, key in enumerate(dicts[0].keys()): - if list_of_funcs == None: + if list_of_funcs is None: for dict, sim_name, n, dim in zip(dicts, sim_names, nproc, Nel): string = f"{sim_name}".ljust(20) + f"{n}".ljust(7) + f"{position:2d}".ljust(5) + str(key.ljust(70)) for value in dict[key].values(): diff --git a/src/struphy/diagnostics/diagn_tools.py b/src/struphy/diagnostics/diagn_tools.py index e7a9d8ee3..befe9e5fe 100644 --- a/src/struphy/diagnostics/diagn_tools.py +++ b/src/struphy/diagnostics/diagn_tools.py @@ -120,19 +120,19 @@ def power_spectrum_2d( temp[n, :, :, :] = snapshot[component] # Extract 2d data (t, eta) for fft - if slice_at[0] == None: + if slice_at[0] is None: data = temp[:, :, slice_at[1], slice_at[2]] grid = grids[0] if grids_mapped is not None: grid = grids_mapped[0][:, slice_at[1], slice_at[2]] - elif slice_at[1] == None: + elif slice_at[1] is None: data = temp[:, slice_at[0], :, slice_at[2]] grid = grids[1] if grids_mapped is not None: grid = grids_mapped[1][slice_at[0], :, slice_at[2]] - elif slice_at[2] == None: + elif slice_at[2] is None: data = temp[:, slice_at[0], slice_at[1], :] grid = grids[2].flatten() if grids_mapped is not None: diff --git a/src/struphy/eigenvalue_solvers/legacy/inner_products_1d.py b/src/struphy/eigenvalue_solvers/legacy/inner_products_1d.py index b4f019995..0bf42397d 100644 --- a/src/struphy/eigenvalue_solvers/legacy/inner_products_1d.py +++ b/src/struphy/eigenvalue_solvers/legacy/inner_products_1d.py @@ -38,7 +38,7 @@ def inner_prod_V0(spline_space, fun, mapping=None): basisN = spline_space.basisN # evaluated basis functions at quadrature points # evaluation of mapping at quadrature points - if mapping == None: + if mapping is None: mat_map = xp.ones(pts.shape, dtype=float) else: mat_map = mapping(pts.flatten()).reshape(pts.shape) @@ -89,7 +89,7 @@ def inner_prod_V1(spline_space, fun, mapping=None): basisD = spline_space.basisD # evaluated basis functions at quadrature points # evaluation of mapping at quadrature points - if mapping == None: + if mapping is None: mat_map = xp.ones(pts.shape, dtype=float) else: mat_map = 1 / mapping(pts.flatten()).reshape(pts.shape) diff --git a/src/struphy/eigenvalue_solvers/legacy/mass_matrices_3d_pre.py b/src/struphy/eigenvalue_solvers/legacy/mass_matrices_3d_pre.py index a46097a8f..82514ec04 100644 --- a/src/struphy/eigenvalue_solvers/legacy/mass_matrices_3d_pre.py +++ b/src/struphy/eigenvalue_solvers/legacy/mass_matrices_3d_pre.py @@ -228,7 +228,7 @@ def get_M0_PRE_3(tensor_space_FEM, mats_pol=None): TODO """ - if mats_pol == None: + if mats_pol is None: mat = tensor_space_FEM.B0_pol.dot(tensor_space_FEM.M0_pol_mat.dot(tensor_space_FEM.B0_pol.T)) else: mat = mats_pol @@ -255,7 +255,7 @@ def get_M1_PRE_3(tensor_space_FEM, mats_pol=None): TODO """ - if mats_pol == None: + if mats_pol is None: mat = [ tensor_space_FEM.B1_pol.dot(tensor_space_FEM.M1_pol_mat[0].dot(tensor_space_FEM.B1_pol.T)), tensor_space_FEM.B0_pol.dot(tensor_space_FEM.M1_pol_mat[1].dot(tensor_space_FEM.B0_pol.T)), @@ -295,7 +295,7 @@ def get_M2_PRE_3(tensor_space_FEM, mats_pol=None): TODO """ - if mats_pol == None: + if mats_pol is None: mat = [ tensor_space_FEM.B2_pol.dot(tensor_space_FEM.M2_pol_mat[0].dot(tensor_space_FEM.B2_pol.T)), tensor_space_FEM.B3_pol.dot(tensor_space_FEM.M2_pol_mat[1].dot(tensor_space_FEM.B3_pol.T)), @@ -335,7 +335,7 @@ def get_M3_PRE_3(tensor_space_FEM, mats_pol=None): TODO """ - if mats_pol == None: + if mats_pol is None: mat = tensor_space_FEM.B3_pol.dot(tensor_space_FEM.M3_pol_mat.dot(tensor_space_FEM.B3_pol.T)) else: mat = mats_pol @@ -360,7 +360,7 @@ def get_Mv_PRE_3(tensor_space_FEM, mats_pol=None): TODO """ - if mats_pol == None: + if mats_pol is None: mat = [ tensor_space_FEM.Bv_pol.dot(tensor_space_FEM.Mv_pol_mat[0].dot(tensor_space_FEM.Bv_pol.T)), tensor_space_FEM.Mv_pol_mat[1], diff --git a/src/struphy/eigenvalue_solvers/mass_matrices_1d.py b/src/struphy/eigenvalue_solvers/mass_matrices_1d.py index b5013c088..3d9c665fb 100644 --- a/src/struphy/eigenvalue_solvers/mass_matrices_1d.py +++ b/src/struphy/eigenvalue_solvers/mass_matrices_1d.py @@ -46,7 +46,7 @@ def get_M(spline_space, phi_i=0, phi_j=0, fun=None): basisD = spline_space.basisD # evaluated basis functions at quadrature points # evaluation of weight function at quadrature points (optional) - if fun == None: + if fun is None: mat_fun = xp.ones(pts.shape, dtype=float) else: mat_fun = fun(pts.flatten()).reshape(Nel, n_quad) @@ -136,13 +136,13 @@ def get_M_gen(spline_space, phi_i=0, phi_j=0, fun=None, jac=None): basis_t = bsp.basis_ders_on_quad_grid(spline_space.t, p - 1, spline_space.pts, 0, normalize=False) # evaluation of weight function at quadrature points (optional) - if fun == None: + if fun is None: mat_fun = xp.ones(pts.shape, dtype=float) else: mat_fun = fun(pts.flatten()).reshape(Nel, n_quad) # evaluation of jacobian at quadrature points - if jac == None: + if jac is None: mat_jac = xp.ones(pts.shape, dtype=float) else: mat_jac = jac(pts.flatten()).reshape(Nel, n_quad) diff --git a/src/struphy/eigenvalue_solvers/mass_matrices_2d.py b/src/struphy/eigenvalue_solvers/mass_matrices_2d.py index c2c6c3ae9..b8f8943d4 100644 --- a/src/struphy/eigenvalue_solvers/mass_matrices_2d.py +++ b/src/struphy/eigenvalue_solvers/mass_matrices_2d.py @@ -45,7 +45,7 @@ def get_M0(tensor_space_FEM, domain, apply_boundary_ops=False, weight=None): det_df = det_df.reshape(Nel[0], n_quad[0], Nel[1], n_quad[1]) # evaluation of weight function at quadrature points - if weight == None: + if weight is None: mat_w = xp.ones(det_df.shape, dtype=float) else: mat_w = weight(pts[0].flatten(), pts[1].flatten(), 0.0) @@ -159,7 +159,7 @@ def get_M1(tensor_space_FEM, domain, apply_boundary_ops=False, weight=None): M[a][b] = xp.zeros((Ni[0], Ni[1], 2 * p[0] + 1, 2 * p[1] + 1), dtype=float) # evaluate inverse metric tensor at quadrature points - if weight == None: + if weight is None: mat_w = g_inv[a, b] else: mat_w = weight[a][b](pts[0].flatten(), pts[1].flatten(), 0.0) @@ -275,7 +275,7 @@ def get_M2(tensor_space_FEM, domain, apply_boundary_ops=False, weight=None): M[a][b] = xp.zeros((Ni[0], Ni[1], 2 * p[0] + 1, 2 * p[1] + 1), dtype=float) # evaluate metric tensor at quadrature points - if weight == None: + if weight is None: mat_w = g[a, b] else: mat_w = weight[a][b](pts[0].flatten(), pts[1].flatten(), 0.0) @@ -368,7 +368,7 @@ def get_M3(tensor_space_FEM, domain, apply_boundary_ops=False, weight=None): det_df = det_df.reshape(Nel[0], n_quad[0], Nel[1], n_quad[1]) # evaluation of weight function at quadrature points - if weight == None: + if weight is None: mat_w = xp.ones(det_df.shape, dtype=float) else: mat_w = weight(pts[0].flatten(), pts[1].flatten(), 0.0) @@ -478,7 +478,7 @@ def get_Mv(tensor_space_FEM, domain, apply_boundary_ops=False, weight=None): M[a][b] = xp.zeros((Ni[0], Ni[1], 2 * p[0] + 1, 2 * p[1] + 1), dtype=float) # evaluate metric tensor at quadrature points - if weight == None: + if weight is None: mat_w = g[a, b] else: mat_w = weight[a][b](pts[0].flatten(), pts[1].flatten(), 0.0) diff --git a/src/struphy/eigenvalue_solvers/mass_matrices_3d.py b/src/struphy/eigenvalue_solvers/mass_matrices_3d.py index d3dc4cad2..49be830b5 100644 --- a/src/struphy/eigenvalue_solvers/mass_matrices_3d.py +++ b/src/struphy/eigenvalue_solvers/mass_matrices_3d.py @@ -45,7 +45,7 @@ def get_M0(tensor_space_FEM, domain, apply_boundary_ops=False, weight=None): det_df = det_df.reshape(Nel[0], n_quad[0], Nel[1], n_quad[1], Nel[2], n_quad[2]) # evaluation of weight function at quadrature points - if weight == None: + if weight is None: mat_w = xp.ones(det_df.shape, dtype=float) else: mat_w = weight(pts[0].flatten(), pts[1].flatten(), pts[2].flatten()) @@ -164,7 +164,7 @@ def get_M1(tensor_space_FEM, domain, apply_boundary_ops=False, weight=None): M[a][b] = xp.zeros((Ni[0], Ni[1], Ni[2], 2 * p[0] + 1, 2 * p[1] + 1, 2 * p[2] + 1), dtype=float) # evaluate metric tensor at quadrature points - if weight == None: + if weight is None: mat_w = g_inv[a, b] else: mat_w = weight[a][b](pts[0].flatten(), pts[1].flatten(), pts[2].flatten()) @@ -284,7 +284,7 @@ def get_M2(tensor_space_FEM, domain, apply_boundary_ops=False, weight=None): M[a][b] = xp.zeros((Ni[0], Ni[1], Ni[2], 2 * p[0] + 1, 2 * p[1] + 1, 2 * p[2] + 1), dtype=float) # evaluate metric tensor at quadrature points - if weight == None: + if weight is None: mat_w = g[a, b] else: mat_w = weight[a][b](pts[0].flatten(), pts[1].flatten(), pts[2].flatten()) @@ -382,7 +382,7 @@ def get_M3(tensor_space_FEM, domain, apply_boundary_ops=False, weight=None): det_df = det_df.reshape(Nel[0], n_quad[0], Nel[1], n_quad[1], Nel[2], n_quad[2]) # evaluation of weight function at quadrature points - if weight == None: + if weight is None: mat_w = xp.ones(det_df.shape, dtype=float) else: mat_w = weight(pts[0].flatten(), pts[1].flatten(), pts[2].flatten()) @@ -520,7 +520,7 @@ def get_Mv(tensor_space_FEM, domain, apply_boundary_ops=False, weight=None): M[a][b] = xp.zeros((Ni[0], Ni[1], Ni[2], 2 * p[0] + 1, 2 * p[1] + 1, 2 * p[2] + 1), dtype=float) # evaluate metric tensor at quadrature points - if weight == None: + if weight is None: mat_w = g[a, b] else: mat_w = weight[a][b](pts[0].flatten(), pts[1].flatten(), pts[2].flatten()) diff --git a/src/struphy/feec/projectors.py b/src/struphy/feec/projectors.py index be56cc722..3b2baaedc 100644 --- a/src/struphy/feec/projectors.py +++ b/src/struphy/feec/projectors.py @@ -1717,7 +1717,7 @@ def get_rowstarts(self, i, h=None): Array that tell us for which rows the basis function in the i-th direction produces non-zero entries in the BasisProjectionOperatorLocal matrix. This array contains the start indices of said regions. """ - if h == None: + if h is None: rows_splines = getattr(self, f"_rows_B_or_D_splines_{i}") translation_indices = getattr(self, f"_translation_indices_B_or_D_splines_{i}") return rows_splines[self._B_or_D[i]][translation_indices[self._B_or_D[i]][self._basis_indices[i]]] @@ -1745,7 +1745,7 @@ def get_rowends(self, i, h=None): Array that tell us for which rows the basis function in the i-th direction produces non-zero entries in the BasisProjectionOperatorLocal matrix. This array contains the end indices of said regions. """ - if h == None: + if h is None: rowe_splines = getattr(self, f"_rowe_B_or_D_splines_{i}") translation_indices = getattr(self, f"_translation_indices_B_or_D_splines_{i}") return rowe_splines[self._B_or_D[i]][translation_indices[self._B_or_D[i]][self._basis_indices[i]]] @@ -1772,7 +1772,7 @@ def get_values(self, i, h=None): self._values_B_or_D_splines_i[self._B_or_D[i]][self._translation_indices_B_or_D_splines_i[self._B_or_D[i]][self._basis_indices[i]]] : 1d float array Array with the evaluated basis function for the i-th direction. """ - if h == None: + if h is None: values_splines = getattr(self, f"_values_B_or_D_splines_{i}") translation_indices = getattr(self, f"_translation_indices_B_or_D_splines_{i}") return values_splines[self._B_or_D[i]][translation_indices[self._B_or_D[i]][self._basis_indices[i]]] @@ -1800,7 +1800,7 @@ def get_are_zero(self, i, h=None): Array of zeros or ones. A one at index j means that for the set of quadrature points found in self._localpts[i][j] the basis function is not zero for at least one of them. """ - if h == None: + if h is None: are_zero_splines = getattr(self, f"_are_zero_B_or_D_splines_{i}") translation_indices = getattr(self, f"_translation_indices_B_or_D_splines_{i}") return are_zero_splines[self._B_or_D[i]][translation_indices[self._B_or_D[i]][self._basis_indices[i]]] diff --git a/src/struphy/feec/psydac_derham.py b/src/struphy/feec/psydac_derham.py index e5a8cde32..564ef461e 100644 --- a/src/struphy/feec/psydac_derham.py +++ b/src/struphy/feec/psydac_derham.py @@ -1304,7 +1304,7 @@ def _get_neighbour_one_component(self, comp): neigh_inds = xp.array(neigh_inds) # only use indices where information is present to find the neighbours rank - inds = xp.where(neigh_inds != None) + inds = xp.where(neigh_inds is not None) # find ranks (row index of domain_array) which agree in start/end indices index_temp = xp.squeeze(self.index_array[:, inds]) @@ -2252,7 +2252,7 @@ def _add_noise( sli = [] gl_s = [] for d in range(3): - if n == None: + if n is None: sli += [slice(self._gl_s[d], self._gl_e[d] + 1)] gl_s += [self._gl_s[d]] vec = self._vector @@ -2262,7 +2262,7 @@ def _add_noise( vec = self._vector[n] # local shape without ghost regions - if n == None: + if n is None: _shape = ( self._gl_e[0] + 1 - self._gl_s[0], self._gl_e[1] + 1 - self._gl_s[1], diff --git a/src/struphy/feec/utilities.py b/src/struphy/feec/utilities.py index 2fffe38e3..ee4ab95e9 100644 --- a/src/struphy/feec/utilities.py +++ b/src/struphy/feec/utilities.py @@ -238,7 +238,7 @@ def compare_arrays(arr_psy, arr, rank, atol=1e-14, verbose=False): elif isinstance(arr_psy, BlockLinearOperator): for row_psy, row in zip(arr_psy.blocks, arr): for mat_psy, mat in zip(row_psy, row): - if mat_psy == None: + if mat_psy is None: continue s = mat_psy.codomain.starts diff --git a/src/struphy/feec/variational_utilities.py b/src/struphy/feec/variational_utilities.py index 8174a1a5b..390c7e2fd 100644 --- a/src/struphy/feec/variational_utilities.py +++ b/src/struphy/feec/variational_utilities.py @@ -322,7 +322,7 @@ def __init__(self, derham, transposed=False, weights=None): # Get the projector and the spaces self._derham = derham self._transposed = transposed - if weights == None: + if weights is None: weights = [[None] * 3] * 3 self._weights = weights if self._transposed: @@ -477,7 +477,7 @@ def __init__(self, derham, transposed=False, weights=None): # Get the projector and the spaces self._derham = derham self._transposed = transposed - if weights == None: + if weights is None: weights = [[None] * 3] * 3 self._weights = weights if self._transposed: diff --git a/src/struphy/linear_algebra/saddle_point.py b/src/struphy/linear_algebra/saddle_point.py index 337664754..076ff74a6 100644 --- a/src/struphy/linear_algebra/saddle_point.py +++ b/src/struphy/linear_algebra/saddle_point.py @@ -94,7 +94,7 @@ def __init__( max_iter: int = 1000, **solver_params, ): - assert type(A) == type(B) + assert type(A) is type(B) if isinstance(A, list): self._variant = "Uzawa" for i in A: diff --git a/src/struphy/main.py b/src/struphy/main.py index 047abea95..4196b9efa 100644 --- a/src/struphy/main.py +++ b/src/struphy/main.py @@ -103,7 +103,7 @@ def run( save_step = env.save_step sort_step = env.sort_step num_clones = env.num_clones - use_mpi = (not comm is None,) + use_mpi = (comm is not None,) meta = {} meta["platform"] = sysconfig.get_platform() diff --git a/src/struphy/pic/tests/test_pic_legacy_files/pusher_pos.py b/src/struphy/pic/tests/test_pic_legacy_files/pusher_pos.py index 81b5e1e53..ee4c30c40 100644 --- a/src/struphy/pic/tests/test_pic_legacy_files/pusher_pos.py +++ b/src/struphy/pic/tests/test_pic_legacy_files/pusher_pos.py @@ -404,7 +404,7 @@ def pusher_step4( # ======================================================================================================== def reflect( - df: "", + df, ): from numpy import empty, sqrt diff --git a/src/struphy/post_processing/cprofile_analyser.py b/src/struphy/post_processing/cprofile_analyser.py index 74e8920f9..94bc2b1bf 100644 --- a/src/struphy/post_processing/cprofile_analyser.py +++ b/src/struphy/post_processing/cprofile_analyser.py @@ -84,7 +84,7 @@ def compare_cprofile_data(path, list_of_funcs=None): with open(os.path.join(path, "profile_dict.sav"), "rb") as f: data_cprofile = pickle.load(f) - if list_of_funcs == None: + if list_of_funcs is None: print("-" * 76) print("function name".ljust(60), "cumulative time") print("-" * 76) @@ -96,7 +96,7 @@ def compare_cprofile_data(path, list_of_funcs=None): counter = 0 for k, v in data_cprofile.items(): counter += 1 - if list_of_funcs == None: + if list_of_funcs is None: print(k.ljust(60), v["cumtime"]) if counter > 49: break diff --git a/src/struphy/post_processing/likwid/roofline_plotter.py b/src/struphy/post_processing/likwid/roofline_plotter.py index 3a4808bdc..5073aa8bd 100644 --- a/src/struphy/post_processing/likwid/roofline_plotter.py +++ b/src/struphy/post_processing/likwid/roofline_plotter.py @@ -121,14 +121,14 @@ def add_plot_flop( theoretical_max_gflops=3072.0, xmax=1e3, ): - if label == None: + if label is None: legend_label = f"{round(gflops)} GFLOP/s, {round(gflops / theoretical_max_gflops * 100, 2)} % of theoretical" else: legend_label = ( f"{label}({round(gflops)} GFLOP/s, {round(gflops / theoretical_max_gflops * 100, 2)} % of theoretical)" ) - if color == None: + if color is None: # line, = mfig.axs.loglog([xmin,xmax],[gflops,gflops],linestyle=linestyle)#,label = legend_label) line = mfig.axs.axhline(y=gflops, linestyle=linestyle) else: diff --git a/src/struphy/post_processing/profile_struphy.py b/src/struphy/post_processing/profile_struphy.py index 43d4be47d..4f610a975 100644 --- a/src/struphy/post_processing/profile_struphy.py +++ b/src/struphy/post_processing/profile_struphy.py @@ -97,7 +97,7 @@ def main(): ) print("-" * 154) for position, key in enumerate(dicts[0].keys()): - if list_of_funcs == None: + if list_of_funcs is None: for dict, sim_name, n, dim in zip(dicts, sim_names, nproc, Nel): string = f"{sim_name}".ljust(20) + f"{n}".ljust(7) + f"{position:2d}".ljust(5) + str(key.ljust(70)) for value in dict[key].values(): diff --git a/src/struphy/propagators/propagators_coupling.py b/src/struphy/propagators/propagators_coupling.py index 0b8760b6a..5584f5a84 100644 --- a/src/struphy/propagators/propagators_coupling.py +++ b/src/struphy/propagators/propagators_coupling.py @@ -429,7 +429,7 @@ def allocate(self): # ================================ # Preconditioner - if self.options.precond == None: + if self.options.precond is None: pc = None else: pc_class = getattr(preconditioner, self.options.precond) From b7e8c7456aa892caaadb1c9d14f415503d714327 Mon Sep 17 00:00:00 2001 From: Max Date: Wed, 29 Oct 2025 22:13:37 +0100 Subject: [PATCH 2/2] Bugfix, had to replace is not None with xp.not_equal(neigh_inds, None) --- src/struphy/feec/psydac_derham.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/struphy/feec/psydac_derham.py b/src/struphy/feec/psydac_derham.py index 564ef461e..2442731c1 100644 --- a/src/struphy/feec/psydac_derham.py +++ b/src/struphy/feec/psydac_derham.py @@ -1304,7 +1304,7 @@ def _get_neighbour_one_component(self, comp): neigh_inds = xp.array(neigh_inds) # only use indices where information is present to find the neighbours rank - inds = xp.where(neigh_inds is not None) + inds = xp.where(xp.not_equal(neigh_inds, None)) # find ranks (row index of domain_array) which agree in start/end indices index_temp = xp.squeeze(self.index_array[:, inds])