Skip to content

Commit 2ec6c13

Browse files
[pre-commit.ci] pre-commit autoupdate (#5553)
<!--pre-commit.ci start--> updates: - [github.com/astral-sh/ruff-pre-commit: v0.8.6 → v0.9.1](astral-sh/ruff-pre-commit@v0.8.6...v0.9.1) <!--pre-commit.ci end--> --------- Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com>
1 parent 555f435 commit 2ec6c13

File tree

26 files changed

+100
-97
lines changed

26 files changed

+100
-97
lines changed

.pre-commit-config.yaml

+1-1
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,7 @@ repos:
6969
# Python: Ruff linter & formatter
7070
# https://docs.astral.sh/ruff/
7171
- repo: https://github.com/astral-sh/ruff-pre-commit
72-
rev: v0.8.6
72+
rev: v0.9.1
7373
hooks:
7474
# Run the linter
7575
- id: ruff

Docs/source/usage/workflows/ml_materials/run_warpx_training.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -260,7 +260,7 @@ def get_laser(antenna_z, profile_t_peak, fill_in=True):
260260
diag_particle_list = ["weighting", "position", "momentum"]
261261
coarse_btd_end = int((L_plasma_bulk + 0.001 + stage_spacing * (N_stage - 1)) * 100000)
262262
stage_end_snapshots = [
263-
f"{int((L_plasma_bulk+stage_spacing*ii)*100000)}:{int((L_plasma_bulk+stage_spacing*ii)*100000+50)}:5"
263+
f"{int((L_plasma_bulk + stage_spacing * ii) * 100000)}:{int((L_plasma_bulk + stage_spacing * ii) * 100000 + 50)}:5"
264264
for ii in range(1)
265265
]
266266
btd_particle_diag = picmi.LabFrameParticleDiagnostic(

Docs/source/usage/workflows/ml_materials/train.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -180,7 +180,7 @@ def test_dataset(model, test_source, test_target, loss_fun):
180180
)
181181
# Manual: Training loop END
182182
t4 = time.time()
183-
print(f"total training time: {t4-t3:.3f}s")
183+
print(f"total training time: {t4 - t3:.3f}s")
184184

185185
######### save model #########
186186

Examples/Physics_applications/capacitive_discharge/inputs_base_1d_picmi.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -423,7 +423,7 @@ def run_sim(self):
423423
assert hasattr(self.solver, "phi")
424424

425425
if libwarpx.amr.ParallelDescriptor.MyProc() == 0:
426-
np.save(f"ion_density_case_{self.n+1}.npy", self.ion_density_array)
426+
np.save(f"ion_density_case_{self.n + 1}.npy", self.ion_density_array)
427427

428428
# query the particle z-coordinates if this is run during CI testing
429429
# to cover that functionality

Examples/Physics_applications/laser_acceleration/analysis_openpmd_rz.py

+12-12
Original file line numberDiff line numberDiff line change
@@ -20,15 +20,15 @@
2020
# this is in C (Python) order; r is the fastest varying index
2121
(Nm, Nz, Nr) = jt.shape
2222

23-
assert (
24-
Nm == 3
25-
), "Wrong number of angular modes stored or possible incorrect ordering when flushed"
26-
assert (
27-
Nr == 64
28-
), "Wrong number of radial points stored or possible incorrect ordering when flushed"
29-
assert (
30-
Nz == 512
31-
), "Wrong number of z points stored or possible incorrect ordering when flushed"
23+
assert Nm == 3, (
24+
"Wrong number of angular modes stored or possible incorrect ordering when flushed"
25+
)
26+
assert Nr == 64, (
27+
"Wrong number of radial points stored or possible incorrect ordering when flushed"
28+
)
29+
assert Nz == 512, (
30+
"Wrong number of z points stored or possible incorrect ordering when flushed"
31+
)
3232

3333
assert ii.meshes["part_per_grid"][io.Mesh_Record_Component.SCALAR].shape == [
3434
512,
@@ -60,6 +60,6 @@
6060
electron_meanz = np.sum(np.dot(zlist, rhoe0)) / np.sum(rhoe0)
6161
beam_meanz = np.sum(np.dot(zlist, rhob0)) / np.sum(rhob0)
6262

63-
assert (
64-
(electron_meanz > 0) and (beam_meanz < 0)
65-
), "problem with openPMD+RZ. Maybe openPMD+RZ mixed up the order of rho_<species> diagnostics?"
63+
assert (electron_meanz > 0) and (beam_meanz < 0), (
64+
"problem with openPMD+RZ. Maybe openPMD+RZ mixed up the order of rho_<species> diagnostics?"
65+
)

Examples/Physics_applications/laser_ion/plot_2d.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -120,7 +120,7 @@ def visualize_density_iteration(ts, iteration, out_dir):
120120
for ax in axs[:-1]:
121121
ax.set_xticklabels([])
122122
axs[2].set_xlabel(r"$z$ ($\mu$m)")
123-
fig.suptitle(f"Iteration: {it}, Time: {time/1e-15:.1f} fs")
123+
fig.suptitle(f"Iteration: {it}, Time: {time / 1e-15:.1f} fs")
124124

125125
plt.tight_layout()
126126

@@ -190,7 +190,7 @@ def visualize_field_iteration(ts, iteration, out_dir):
190190
for ax in axs[:-1]:
191191
ax.set_xticklabels([])
192192
axs[2].set_xlabel(r"$z$ ($\mu$m)")
193-
fig.suptitle(f"Iteration: {it}, Time: {time/1e-15:.1f} fs")
193+
fig.suptitle(f"Iteration: {it}, Time: {time / 1e-15:.1f} fs")
194194

195195
plt.tight_layout()
196196

Examples/Physics_applications/spacecraft_charging/analysis.py

+3-3
Original file line numberDiff line numberDiff line change
@@ -68,6 +68,6 @@ def func(x, v0, tau):
6868
print("percentage error for v0 = " + str(diff_v0 * 100) + "%")
6969
print("percentage error for tau = " + str(diff_tau * 100) + "%")
7070

71-
assert (diff_v0 < tolerance_v0) and (
72-
diff_tau < tolerance_tau
73-
), "Test spacecraft_charging did not pass"
71+
assert (diff_v0 < tolerance_v0) and (diff_tau < tolerance_tau), (
72+
"Test spacecraft_charging did not pass"
73+
)

Examples/Tests/accelerator_lattice/analysis.py

+4-2
Original file line numberDiff line numberDiff line change
@@ -118,9 +118,11 @@ def applylens(x0, vx0, vz0, gamma, lens_length, lens_strength):
118118
xx = xx + dt * vx
119119

120120
# Compare the analytic to the simulated final values
121-
print(f"Error in x position is {abs(np.abs((xx - xx_sim)/xx))}, which should be < 0.01")
122121
print(
123-
f"Error in x velocity is {abs(np.abs((ux - ux_sim)/ux))}, which should be < 0.002"
122+
f"Error in x position is {abs(np.abs((xx - xx_sim) / xx))}, which should be < 0.01"
123+
)
124+
print(
125+
f"Error in x velocity is {abs(np.abs((ux - ux_sim) / ux))}, which should be < 0.002"
124126
)
125127

126128
assert abs(np.abs((xx - xx_sim) / xx)) < 0.01, Exception("error in x particle position")

Examples/Tests/boundaries/analysis.py

+6-6
Original file line numberDiff line numberDiff line change
@@ -101,9 +101,9 @@ def do_periodic(x):
101101
assert len(a_id) == 1, "Absorbing particles not absorbed"
102102
assert np.all(vx == -vx0), "Reflecting particle velocity not correct"
103103
assert np.all(vz == +vz0), "Periodic particle velocity not correct"
104-
assert np.all(
105-
np.abs((xx - xxa) / xx) < 1.0e-15
106-
), "Reflecting particle position not correct"
107-
assert np.all(
108-
np.abs((zz - zza) / zz) < 1.0e-15
109-
), "Periodic particle position not correct"
104+
assert np.all(np.abs((xx - xxa) / xx) < 1.0e-15), (
105+
"Reflecting particle position not correct"
106+
)
107+
assert np.all(np.abs((zz - zza) / zz) < 1.0e-15), (
108+
"Periodic particle position not correct"
109+
)

Examples/Tests/effective_potential_electrostatic/analysis.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,7 @@ def get_radial_function(field, info):
6666
)
6767

6868
plt.plot(r_grid, n_e_analytic, "k--", alpha=0.6)
69-
plt.plot(r_grid, n_e, label=f"t = {ts.t[ii]*1e6:.2f} $\mu$s")
69+
plt.plot(r_grid, n_e, label=f"t = {ts.t[ii] * 1e6:.2f} $\mu$s")
7070

7171
print("RMS error (%) in density: ", rms_errors)
7272
assert np.all(rms_errors < 0.05)

Examples/Tests/effective_potential_electrostatic/inputs_test_3d_effective_potential_electrostatic_picmi.py

+3-3
Original file line numberDiff line numberDiff line change
@@ -102,13 +102,13 @@
102102
print(
103103
f"Plasma parameters:\n"
104104
f"\tlambda_e = {lambda_e:.1e} m\n"
105-
f"\tt_pe = {1.0/f_pe:.1e} s\n"
105+
f"\tt_pe = {1.0 / f_pe:.1e} s\n"
106106
f"\tv_ti = {v_ti:.1e} m/s\n"
107107
)
108108
print(
109109
f"Numerical parameters:\n"
110-
f"\tdz/lambda_e = {dz/lambda_e:.2f}\n"
111-
f"\tdt*w_pe = {dt*f_pe*2.0*np.pi:.2f}\n"
110+
f"\tdz/lambda_e = {dz / lambda_e:.2f}\n"
111+
f"\tdt*w_pe = {dt * f_pe * 2.0 * np.pi:.2f}\n"
112112
f"\tdiag steps = {diag_steps:d}\n"
113113
f"\ttotal steps = {total_steps:d}\n"
114114
)

Examples/Tests/ohm_solver_ion_Landau_damping/inputs_test_2d_ohm_solver_landau_damping_picmi.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -93,7 +93,7 @@ def __init__(self, test, dim, m, T_ratio, verbose):
9393
if comm.rank == 0:
9494
print(
9595
f"Initializing simulation with input parameters:\n"
96-
f"\tT = {self.T_plasma*1e-3:.1f} keV\n"
96+
f"\tT = {self.T_plasma * 1e-3:.1f} keV\n"
9797
f"\tn = {self.n_plasma:.1e} m^-3\n"
9898
f"\tB0 = {self.B0:.2f} T\n"
9999
f"\tM/m = {self.m_ion:.0f}\n"

Examples/Tests/ohm_solver_ion_beam_instability/inputs_test_1d_ohm_solver_ion_beam_picmi.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -110,7 +110,7 @@ def __init__(self, test, dim, resonant, verbose):
110110
if comm.rank == 0:
111111
print(
112112
f"Initializing simulation with input parameters:\n"
113-
f"\tT = {self.T_plasma*1e-3:.1f} keV\n"
113+
f"\tT = {self.T_plasma * 1e-3:.1f} keV\n"
114114
f"\tn = {self.n_plasma:.1e} m^-3\n"
115115
f"\tB0 = {self.B0:.2f} T\n"
116116
f"\tM/m = {self.m_ion:.0f}\n"

Examples/Tests/ohm_solver_magnetic_reconnection/inputs_test_2d_ohm_solver_magnetic_reconnection_picmi.py

+7-7
Original file line numberDiff line numberDiff line change
@@ -83,14 +83,14 @@ def __init__(self, test, verbose):
8383
self.Bg *= self.B0
8484
self.dB *= self.B0
8585
self.Bx = (
86-
f"{self.B0}*tanh(z*{1.0/self.l_i})"
87-
f"+{-self.dB*self.Lx/(2.0*self.Lz)}*cos({2.0*np.pi/self.Lx}*x)"
88-
f"*sin({np.pi/self.Lz}*z)"
86+
f"{self.B0}*tanh(z*{1.0 / self.l_i})"
87+
f"+{-self.dB * self.Lx / (2.0 * self.Lz)}*cos({2.0 * np.pi / self.Lx}*x)"
88+
f"*sin({np.pi / self.Lz}*z)"
8989
)
9090
self.By = (
91-
f"sqrt({self.Bg**2 + self.B0**2}-" f"({self.B0}*tanh(z*{1.0/self.l_i}))**2)"
91+
f"sqrt({self.Bg**2 + self.B0**2}-({self.B0}*tanh(z*{1.0 / self.l_i}))**2)"
9292
)
93-
self.Bz = f"{self.dB}*sin({2.0*np.pi/self.Lx}*x)*cos({np.pi/self.Lz}*z)"
93+
self.Bz = f"{self.dB}*sin({2.0 * np.pi / self.Lx}*x)*cos({np.pi / self.Lz}*z)"
9494

9595
self.J0 = self.B0 / constants.mu0 / self.l_i
9696

@@ -103,7 +103,7 @@ def __init__(self, test, verbose):
103103
if comm.rank == 0:
104104
print(
105105
f"Initializing simulation with input parameters:\n"
106-
f"\tTi = {self.Ti*1e-3:.1f} keV\n"
106+
f"\tTi = {self.Ti * 1e-3:.1f} keV\n"
107107
f"\tn0 = {self.n_plasma:.1e} m^-3\n"
108108
f"\tB0 = {self.B0:.2f} T\n"
109109
f"\tM/m = {self.m_ion:.0f}\n"
@@ -117,7 +117,7 @@ def __init__(self, test, verbose):
117117
)
118118
print(
119119
f"Numerical parameters:\n"
120-
f"\tdz = {self.Lz/self.NZ:.1e} m\n"
120+
f"\tdz = {self.Lz / self.NZ:.1e} m\n"
121121
f"\tdt = {self.dt:.1e} s\n"
122122
f"\tdiag steps = {self.diag_steps:d}\n"
123123
f"\ttotal steps = {self.total_steps:d}\n"

Examples/Tests/particle_boundary_interaction/analysis.py

+3-3
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,6 @@
4343
print("percentage error for x = %5.4f %%" % (diff_x * 100))
4444
print("percentage error for z = %5.4f %%" % (diff_z * 100))
4545

46-
assert (
47-
(diff_x < tolerance) and (y[0] < 1e-8) and (diff_z < tolerance)
48-
), "Test particle_boundary_interaction did not pass"
46+
assert (diff_x < tolerance) and (y[0] < 1e-8) and (diff_z < tolerance), (
47+
"Test particle_boundary_interaction did not pass"
48+
)

Examples/Tests/pass_mpi_communicator/analysis.py

+2-4
Original file line numberDiff line numberDiff line change
@@ -37,17 +37,15 @@
3737

3838
# Dictionaries have same outer keys (levels, species)?
3939
if checksum1.data.keys() != checksum2.data.keys():
40-
print("ERROR: plotfile 1 and plotfile 2 checksums " "have different outer keys:")
40+
print("ERROR: plotfile 1 and plotfile 2 checksums have different outer keys:")
4141
print("Plot1: %s" % checksum1.data.keys())
4242
print("Plot2: %s" % checksum2.data.keys())
4343
sys.exit(1)
4444

4545
# Dictionaries have same inner keys (field and particle quantities)?
4646
for key1 in checksum1.data.keys():
4747
if checksum1.data[key1].keys() != checksum2.data[key1].keys():
48-
print(
49-
"ERROR: plotfile 1 and plotfile 2 checksums have " "different inner keys:"
50-
)
48+
print("ERROR: plotfile 1 and plotfile 2 checksums have different inner keys:")
5149
print("Common outer keys: %s" % checksum2.data.keys())
5250
print("Plotfile 1 inner keys in %s: %s" % (key1, checksum1.data[key1].keys()))
5351
print("Plotfile 2 inner keys in %s: %s" % (key1, checksum2.data[key1].keys()))

Examples/Tests/plasma_lens/analysis.py

+8-4
Original file line numberDiff line numberDiff line change
@@ -160,13 +160,17 @@ def applylens(x0, vx0, vz0, gamma, lens_length, lens_strength):
160160
xx = xx + dt0 * vx
161161
yy = yy + dt1 * vy
162162

163-
print(f"Error in x position is {abs(np.abs((xx - xx_sim)/xx))}, which should be < 0.02")
164-
print(f"Error in y position is {abs(np.abs((yy - yy_sim)/yy))}, which should be < 0.02")
165163
print(
166-
f"Error in x velocity is {abs(np.abs((ux - ux_sim)/ux))}, which should be < 0.002"
164+
f"Error in x position is {abs(np.abs((xx - xx_sim) / xx))}, which should be < 0.02"
167165
)
168166
print(
169-
f"Error in y velocity is {abs(np.abs((uy - uy_sim)/uy))}, which should be < 0.002"
167+
f"Error in y position is {abs(np.abs((yy - yy_sim) / yy))}, which should be < 0.02"
168+
)
169+
print(
170+
f"Error in x velocity is {abs(np.abs((ux - ux_sim) / ux))}, which should be < 0.002"
171+
)
172+
print(
173+
f"Error in y velocity is {abs(np.abs((uy - uy_sim) / uy))}, which should be < 0.002"
170174
)
171175

172176
if plasma_lens_lengths[0] < 0.01:

Python/pywarpx/fields.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -284,10 +284,10 @@ def _find_start_stop(self, ii, imin, imax, d):
284284
iistart = ii
285285
iistop = ii + 1
286286
assert imin <= iistart <= imax, Exception(
287-
f"Dimension {d+1} lower index is out of bounds"
287+
f"Dimension {d + 1} lower index is out of bounds"
288288
)
289289
assert imin <= iistop <= imax, Exception(
290-
f"Dimension {d+1} upper index is out of bounds"
290+
f"Dimension {d + 1} upper index is out of bounds"
291291
)
292292
return iistart, iistop
293293

Python/pywarpx/particle_containers.py

+24-24
Original file line numberDiff line numberDiff line change
@@ -107,31 +107,31 @@ def add_particles(
107107
maxlen = max(maxlen, lenw)
108108

109109
# --- Make sure that the lengths of the input parameters are consistent
110-
assert (
111-
x is None or lenx == maxlen or lenx == 1
112-
), "Length of x doesn't match len of others"
113-
assert (
114-
y is None or leny == maxlen or leny == 1
115-
), "Length of y doesn't match len of others"
116-
assert (
117-
z is None or lenz == maxlen or lenz == 1
118-
), "Length of z doesn't match len of others"
119-
assert (
120-
ux is None or lenux == maxlen or lenux == 1
121-
), "Length of ux doesn't match len of others"
122-
assert (
123-
uy is None or lenuy == maxlen or lenuy == 1
124-
), "Length of uy doesn't match len of others"
125-
assert (
126-
uz is None or lenuz == maxlen or lenuz == 1
127-
), "Length of uz doesn't match len of others"
128-
assert (
129-
w is None or lenw == maxlen or lenw == 1
130-
), "Length of w doesn't match len of others"
110+
assert x is None or lenx == maxlen or lenx == 1, (
111+
"Length of x doesn't match len of others"
112+
)
113+
assert y is None or leny == maxlen or leny == 1, (
114+
"Length of y doesn't match len of others"
115+
)
116+
assert z is None or lenz == maxlen or lenz == 1, (
117+
"Length of z doesn't match len of others"
118+
)
119+
assert ux is None or lenux == maxlen or lenux == 1, (
120+
"Length of ux doesn't match len of others"
121+
)
122+
assert uy is None or lenuy == maxlen or lenuy == 1, (
123+
"Length of uy doesn't match len of others"
124+
)
125+
assert uz is None or lenuz == maxlen or lenuz == 1, (
126+
"Length of uz doesn't match len of others"
127+
)
128+
assert w is None or lenw == maxlen or lenw == 1, (
129+
"Length of w doesn't match len of others"
130+
)
131131
for key, val in kwargs.items():
132-
assert (
133-
np.size(val) == 1 or len(val) == maxlen
134-
), f"Length of {key} doesn't match len of others"
132+
assert np.size(val) == 1 or len(val) == maxlen, (
133+
f"Length of {key} doesn't match len of others"
134+
)
135135

136136
# --- Broadcast scalars into appropriate length arrays
137137
# --- If the parameter was not supplied, use the default value

Python/pywarpx/picmi.py

+8-8
Original file line numberDiff line numberDiff line change
@@ -2556,7 +2556,7 @@ def __init__(
25562556
**kw,
25572557
):
25582558
assert stl_file is None or implicit_function is None, Exception(
2559-
"Only one between implicit_function and " "stl_file can be specified"
2559+
"Only one between implicit_function and stl_file can be specified"
25602560
)
25612561

25622562
self.implicit_function = implicit_function
@@ -2666,9 +2666,9 @@ def __init__(
26662666
self.strengths_E = strengths_E
26672667
self.strengths_B = strengths_B
26682668

2669-
assert (self.strengths_E is not None) or (
2670-
self.strengths_B is not None
2671-
), Exception("One of strengths_E or strengths_B must be supplied")
2669+
assert (self.strengths_E is not None) or (self.strengths_B is not None), (
2670+
Exception("One of strengths_E or strengths_B must be supplied")
2671+
)
26722672

26732673
self.handle_init(kw)
26742674

@@ -3011,9 +3011,9 @@ def initialize_inputs(self):
30113011
particle_shape = self.particle_shape
30123012
for s in self.species:
30133013
if s.particle_shape is not None:
3014-
assert (
3015-
particle_shape is None or particle_shape == s.particle_shape
3016-
), Exception("WarpX only supports one particle shape for all species")
3014+
assert particle_shape is None or particle_shape == s.particle_shape, (
3015+
Exception("WarpX only supports one particle shape for all species")
3016+
)
30173017
# --- If this was set for any species, use that value.
30183018
particle_shape = s.particle_shape
30193019

@@ -4102,7 +4102,7 @@ def __init__(
41024102
kw = self._handle_charge_on_eb(**kw)
41034103
else:
41044104
raise RuntimeError(
4105-
f"{self.type} reduced diagnostic is not yet supported " "in pywarpx."
4105+
f"{self.type} reduced diagnostic is not yet supported in pywarpx."
41064106
)
41074107

41084108
self.handle_init(kw)

Regression/Checksum/checksum.py

+1-2
Original file line numberDiff line numberDiff line change
@@ -238,8 +238,7 @@ def evaluate(self, rtol=1.0e-9, atol=1.0e-40):
238238
# Dictionaries have same outer keys (levels, species)?
239239
if self.data.keys() != ref_benchmark.data.keys():
240240
print(
241-
"ERROR: Benchmark and output file checksum "
242-
"have different outer keys:"
241+
"ERROR: Benchmark and output file checksum have different outer keys:"
243242
)
244243
print("Benchmark: %s" % ref_benchmark.data.keys())
245244
print("Test file: %s" % self.data.keys())

Regression/PostProcessingUtils/post_processing_utils.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -164,6 +164,6 @@ def check_random_filter(fn, filtered_fn, random_fraction, dim, species_name):
164164
## Dirty trick to find particles with the same ID + same CPU (does not work with more than 10
165165
## MPI ranks)
166166
random_filter_expression = (
167-
"np.isin(ids + 0.1*cpus," "ids_filtered_warpx + 0.1*cpus_filtered_warpx)"
167+
"np.isin(ids + 0.1*cpus,ids_filtered_warpx + 0.1*cpus_filtered_warpx)"
168168
)
169169
check_particle_filter(fn, filtered_fn, random_filter_expression, dim, species_name)

0 commit comments

Comments
 (0)