Skip to content

Commit

Permalink
[pre-commit.ci] pre-commit autoupdate (#5553)
Browse files Browse the repository at this point in the history
<!--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>
  • Loading branch information
pre-commit-ci[bot] authored Jan 14, 2025
1 parent 555f435 commit 2ec6c13
Show file tree
Hide file tree
Showing 26 changed files with 100 additions and 97 deletions.
2 changes: 1 addition & 1 deletion .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ repos:
# Python: Ruff linter & formatter
# https://docs.astral.sh/ruff/
- repo: https://github.com/astral-sh/ruff-pre-commit
rev: v0.8.6
rev: v0.9.1
hooks:
# Run the linter
- id: ruff
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -260,7 +260,7 @@ def get_laser(antenna_z, profile_t_peak, fill_in=True):
diag_particle_list = ["weighting", "position", "momentum"]
coarse_btd_end = int((L_plasma_bulk + 0.001 + stage_spacing * (N_stage - 1)) * 100000)
stage_end_snapshots = [
f"{int((L_plasma_bulk+stage_spacing*ii)*100000)}:{int((L_plasma_bulk+stage_spacing*ii)*100000+50)}:5"
f"{int((L_plasma_bulk + stage_spacing * ii) * 100000)}:{int((L_plasma_bulk + stage_spacing * ii) * 100000 + 50)}:5"
for ii in range(1)
]
btd_particle_diag = picmi.LabFrameParticleDiagnostic(
Expand Down
2 changes: 1 addition & 1 deletion Docs/source/usage/workflows/ml_materials/train.py
Original file line number Diff line number Diff line change
Expand Up @@ -180,7 +180,7 @@ def test_dataset(model, test_source, test_target, loss_fun):
)
# Manual: Training loop END
t4 = time.time()
print(f"total training time: {t4-t3:.3f}s")
print(f"total training time: {t4 - t3:.3f}s")

######### save model #########

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -423,7 +423,7 @@ def run_sim(self):
assert hasattr(self.solver, "phi")

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

# query the particle z-coordinates if this is run during CI testing
# to cover that functionality
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,15 +20,15 @@
# this is in C (Python) order; r is the fastest varying index
(Nm, Nz, Nr) = jt.shape

assert (
Nm == 3
), "Wrong number of angular modes stored or possible incorrect ordering when flushed"
assert (
Nr == 64
), "Wrong number of radial points stored or possible incorrect ordering when flushed"
assert (
Nz == 512
), "Wrong number of z points stored or possible incorrect ordering when flushed"
assert Nm == 3, (
"Wrong number of angular modes stored or possible incorrect ordering when flushed"
)
assert Nr == 64, (
"Wrong number of radial points stored or possible incorrect ordering when flushed"
)
assert Nz == 512, (
"Wrong number of z points stored or possible incorrect ordering when flushed"
)

assert ii.meshes["part_per_grid"][io.Mesh_Record_Component.SCALAR].shape == [
512,
Expand Down Expand Up @@ -60,6 +60,6 @@
electron_meanz = np.sum(np.dot(zlist, rhoe0)) / np.sum(rhoe0)
beam_meanz = np.sum(np.dot(zlist, rhob0)) / np.sum(rhob0)

assert (
(electron_meanz > 0) and (beam_meanz < 0)
), "problem with openPMD+RZ. Maybe openPMD+RZ mixed up the order of rho_<species> diagnostics?"
assert (electron_meanz > 0) and (beam_meanz < 0), (
"problem with openPMD+RZ. Maybe openPMD+RZ mixed up the order of rho_<species> diagnostics?"
)
4 changes: 2 additions & 2 deletions Examples/Physics_applications/laser_ion/plot_2d.py
Original file line number Diff line number Diff line change
Expand Up @@ -120,7 +120,7 @@ def visualize_density_iteration(ts, iteration, out_dir):
for ax in axs[:-1]:
ax.set_xticklabels([])
axs[2].set_xlabel(r"$z$ ($\mu$m)")
fig.suptitle(f"Iteration: {it}, Time: {time/1e-15:.1f} fs")
fig.suptitle(f"Iteration: {it}, Time: {time / 1e-15:.1f} fs")

plt.tight_layout()

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

plt.tight_layout()

Expand Down
6 changes: 3 additions & 3 deletions Examples/Physics_applications/spacecraft_charging/analysis.py
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,6 @@ def func(x, v0, tau):
print("percentage error for v0 = " + str(diff_v0 * 100) + "%")
print("percentage error for tau = " + str(diff_tau * 100) + "%")

assert (diff_v0 < tolerance_v0) and (
diff_tau < tolerance_tau
), "Test spacecraft_charging did not pass"
assert (diff_v0 < tolerance_v0) and (diff_tau < tolerance_tau), (
"Test spacecraft_charging did not pass"
)
6 changes: 4 additions & 2 deletions Examples/Tests/accelerator_lattice/analysis.py
Original file line number Diff line number Diff line change
Expand Up @@ -118,9 +118,11 @@ def applylens(x0, vx0, vz0, gamma, lens_length, lens_strength):
xx = xx + dt * vx

# Compare the analytic to the simulated final values
print(f"Error in x position is {abs(np.abs((xx - xx_sim)/xx))}, which should be < 0.01")
print(
f"Error in x velocity is {abs(np.abs((ux - ux_sim)/ux))}, which should be < 0.002"
f"Error in x position is {abs(np.abs((xx - xx_sim) / xx))}, which should be < 0.01"
)
print(
f"Error in x velocity is {abs(np.abs((ux - ux_sim) / ux))}, which should be < 0.002"
)

assert abs(np.abs((xx - xx_sim) / xx)) < 0.01, Exception("error in x particle position")
Expand Down
12 changes: 6 additions & 6 deletions Examples/Tests/boundaries/analysis.py
Original file line number Diff line number Diff line change
Expand Up @@ -101,9 +101,9 @@ def do_periodic(x):
assert len(a_id) == 1, "Absorbing particles not absorbed"
assert np.all(vx == -vx0), "Reflecting particle velocity not correct"
assert np.all(vz == +vz0), "Periodic particle velocity not correct"
assert np.all(
np.abs((xx - xxa) / xx) < 1.0e-15
), "Reflecting particle position not correct"
assert np.all(
np.abs((zz - zza) / zz) < 1.0e-15
), "Periodic particle position not correct"
assert np.all(np.abs((xx - xxa) / xx) < 1.0e-15), (
"Reflecting particle position not correct"
)
assert np.all(np.abs((zz - zza) / zz) < 1.0e-15), (
"Periodic particle position not correct"
)
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ def get_radial_function(field, info):
)

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

print("RMS error (%) in density: ", rms_errors)
assert np.all(rms_errors < 0.05)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -102,13 +102,13 @@
print(
f"Plasma parameters:\n"
f"\tlambda_e = {lambda_e:.1e} m\n"
f"\tt_pe = {1.0/f_pe:.1e} s\n"
f"\tt_pe = {1.0 / f_pe:.1e} s\n"
f"\tv_ti = {v_ti:.1e} m/s\n"
)
print(
f"Numerical parameters:\n"
f"\tdz/lambda_e = {dz/lambda_e:.2f}\n"
f"\tdt*w_pe = {dt*f_pe*2.0*np.pi:.2f}\n"
f"\tdz/lambda_e = {dz / lambda_e:.2f}\n"
f"\tdt*w_pe = {dt * f_pe * 2.0 * np.pi:.2f}\n"
f"\tdiag steps = {diag_steps:d}\n"
f"\ttotal steps = {total_steps:d}\n"
)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,7 @@ def __init__(self, test, dim, m, T_ratio, verbose):
if comm.rank == 0:
print(
f"Initializing simulation with input parameters:\n"
f"\tT = {self.T_plasma*1e-3:.1f} keV\n"
f"\tT = {self.T_plasma * 1e-3:.1f} keV\n"
f"\tn = {self.n_plasma:.1e} m^-3\n"
f"\tB0 = {self.B0:.2f} T\n"
f"\tM/m = {self.m_ion:.0f}\n"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,7 @@ def __init__(self, test, dim, resonant, verbose):
if comm.rank == 0:
print(
f"Initializing simulation with input parameters:\n"
f"\tT = {self.T_plasma*1e-3:.1f} keV\n"
f"\tT = {self.T_plasma * 1e-3:.1f} keV\n"
f"\tn = {self.n_plasma:.1e} m^-3\n"
f"\tB0 = {self.B0:.2f} T\n"
f"\tM/m = {self.m_ion:.0f}\n"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -83,14 +83,14 @@ def __init__(self, test, verbose):
self.Bg *= self.B0
self.dB *= self.B0
self.Bx = (
f"{self.B0}*tanh(z*{1.0/self.l_i})"
f"+{-self.dB*self.Lx/(2.0*self.Lz)}*cos({2.0*np.pi/self.Lx}*x)"
f"*sin({np.pi/self.Lz}*z)"
f"{self.B0}*tanh(z*{1.0 / self.l_i})"
f"+{-self.dB * self.Lx / (2.0 * self.Lz)}*cos({2.0 * np.pi / self.Lx}*x)"
f"*sin({np.pi / self.Lz}*z)"
)
self.By = (
f"sqrt({self.Bg**2 + self.B0**2}-" f"({self.B0}*tanh(z*{1.0/self.l_i}))**2)"
f"sqrt({self.Bg**2 + self.B0**2}-({self.B0}*tanh(z*{1.0 / self.l_i}))**2)"
)
self.Bz = f"{self.dB}*sin({2.0*np.pi/self.Lx}*x)*cos({np.pi/self.Lz}*z)"
self.Bz = f"{self.dB}*sin({2.0 * np.pi / self.Lx}*x)*cos({np.pi / self.Lz}*z)"

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

Expand All @@ -103,7 +103,7 @@ def __init__(self, test, verbose):
if comm.rank == 0:
print(
f"Initializing simulation with input parameters:\n"
f"\tTi = {self.Ti*1e-3:.1f} keV\n"
f"\tTi = {self.Ti * 1e-3:.1f} keV\n"
f"\tn0 = {self.n_plasma:.1e} m^-3\n"
f"\tB0 = {self.B0:.2f} T\n"
f"\tM/m = {self.m_ion:.0f}\n"
Expand All @@ -117,7 +117,7 @@ def __init__(self, test, verbose):
)
print(
f"Numerical parameters:\n"
f"\tdz = {self.Lz/self.NZ:.1e} m\n"
f"\tdz = {self.Lz / self.NZ:.1e} m\n"
f"\tdt = {self.dt:.1e} s\n"
f"\tdiag steps = {self.diag_steps:d}\n"
f"\ttotal steps = {self.total_steps:d}\n"
Expand Down
6 changes: 3 additions & 3 deletions Examples/Tests/particle_boundary_interaction/analysis.py
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,6 @@
print("percentage error for x = %5.4f %%" % (diff_x * 100))
print("percentage error for z = %5.4f %%" % (diff_z * 100))

assert (
(diff_x < tolerance) and (y[0] < 1e-8) and (diff_z < tolerance)
), "Test particle_boundary_interaction did not pass"
assert (diff_x < tolerance) and (y[0] < 1e-8) and (diff_z < tolerance), (
"Test particle_boundary_interaction did not pass"
)
6 changes: 2 additions & 4 deletions Examples/Tests/pass_mpi_communicator/analysis.py
Original file line number Diff line number Diff line change
Expand Up @@ -37,17 +37,15 @@

# Dictionaries have same outer keys (levels, species)?
if checksum1.data.keys() != checksum2.data.keys():
print("ERROR: plotfile 1 and plotfile 2 checksums " "have different outer keys:")
print("ERROR: plotfile 1 and plotfile 2 checksums have different outer keys:")
print("Plot1: %s" % checksum1.data.keys())
print("Plot2: %s" % checksum2.data.keys())
sys.exit(1)

# Dictionaries have same inner keys (field and particle quantities)?
for key1 in checksum1.data.keys():
if checksum1.data[key1].keys() != checksum2.data[key1].keys():
print(
"ERROR: plotfile 1 and plotfile 2 checksums have " "different inner keys:"
)
print("ERROR: plotfile 1 and plotfile 2 checksums have different inner keys:")
print("Common outer keys: %s" % checksum2.data.keys())
print("Plotfile 1 inner keys in %s: %s" % (key1, checksum1.data[key1].keys()))
print("Plotfile 2 inner keys in %s: %s" % (key1, checksum2.data[key1].keys()))
Expand Down
12 changes: 8 additions & 4 deletions Examples/Tests/plasma_lens/analysis.py
Original file line number Diff line number Diff line change
Expand Up @@ -160,13 +160,17 @@ def applylens(x0, vx0, vz0, gamma, lens_length, lens_strength):
xx = xx + dt0 * vx
yy = yy + dt1 * vy

print(f"Error in x position is {abs(np.abs((xx - xx_sim)/xx))}, which should be < 0.02")
print(f"Error in y position is {abs(np.abs((yy - yy_sim)/yy))}, which should be < 0.02")
print(
f"Error in x velocity is {abs(np.abs((ux - ux_sim)/ux))}, which should be < 0.002"
f"Error in x position is {abs(np.abs((xx - xx_sim) / xx))}, which should be < 0.02"
)
print(
f"Error in y velocity is {abs(np.abs((uy - uy_sim)/uy))}, which should be < 0.002"
f"Error in y position is {abs(np.abs((yy - yy_sim) / yy))}, which should be < 0.02"
)
print(
f"Error in x velocity is {abs(np.abs((ux - ux_sim) / ux))}, which should be < 0.002"
)
print(
f"Error in y velocity is {abs(np.abs((uy - uy_sim) / uy))}, which should be < 0.002"
)

if plasma_lens_lengths[0] < 0.01:
Expand Down
4 changes: 2 additions & 2 deletions Python/pywarpx/fields.py
Original file line number Diff line number Diff line change
Expand Up @@ -284,10 +284,10 @@ def _find_start_stop(self, ii, imin, imax, d):
iistart = ii
iistop = ii + 1
assert imin <= iistart <= imax, Exception(
f"Dimension {d+1} lower index is out of bounds"
f"Dimension {d + 1} lower index is out of bounds"
)
assert imin <= iistop <= imax, Exception(
f"Dimension {d+1} upper index is out of bounds"
f"Dimension {d + 1} upper index is out of bounds"
)
return iistart, iistop

Expand Down
48 changes: 24 additions & 24 deletions Python/pywarpx/particle_containers.py
Original file line number Diff line number Diff line change
Expand Up @@ -107,31 +107,31 @@ def add_particles(
maxlen = max(maxlen, lenw)

# --- Make sure that the lengths of the input parameters are consistent
assert (
x is None or lenx == maxlen or lenx == 1
), "Length of x doesn't match len of others"
assert (
y is None or leny == maxlen or leny == 1
), "Length of y doesn't match len of others"
assert (
z is None or lenz == maxlen or lenz == 1
), "Length of z doesn't match len of others"
assert (
ux is None or lenux == maxlen or lenux == 1
), "Length of ux doesn't match len of others"
assert (
uy is None or lenuy == maxlen or lenuy == 1
), "Length of uy doesn't match len of others"
assert (
uz is None or lenuz == maxlen or lenuz == 1
), "Length of uz doesn't match len of others"
assert (
w is None or lenw == maxlen or lenw == 1
), "Length of w doesn't match len of others"
assert x is None or lenx == maxlen or lenx == 1, (
"Length of x doesn't match len of others"
)
assert y is None or leny == maxlen or leny == 1, (
"Length of y doesn't match len of others"
)
assert z is None or lenz == maxlen or lenz == 1, (
"Length of z doesn't match len of others"
)
assert ux is None or lenux == maxlen or lenux == 1, (
"Length of ux doesn't match len of others"
)
assert uy is None or lenuy == maxlen or lenuy == 1, (
"Length of uy doesn't match len of others"
)
assert uz is None or lenuz == maxlen or lenuz == 1, (
"Length of uz doesn't match len of others"
)
assert w is None or lenw == maxlen or lenw == 1, (
"Length of w doesn't match len of others"
)
for key, val in kwargs.items():
assert (
np.size(val) == 1 or len(val) == maxlen
), f"Length of {key} doesn't match len of others"
assert np.size(val) == 1 or len(val) == maxlen, (
f"Length of {key} doesn't match len of others"
)

# --- Broadcast scalars into appropriate length arrays
# --- If the parameter was not supplied, use the default value
Expand Down
16 changes: 8 additions & 8 deletions Python/pywarpx/picmi.py
Original file line number Diff line number Diff line change
Expand Up @@ -2556,7 +2556,7 @@ def __init__(
**kw,
):
assert stl_file is None or implicit_function is None, Exception(
"Only one between implicit_function and " "stl_file can be specified"
"Only one between implicit_function and stl_file can be specified"
)

self.implicit_function = implicit_function
Expand Down Expand Up @@ -2666,9 +2666,9 @@ def __init__(
self.strengths_E = strengths_E
self.strengths_B = strengths_B

assert (self.strengths_E is not None) or (
self.strengths_B is not None
), Exception("One of strengths_E or strengths_B must be supplied")
assert (self.strengths_E is not None) or (self.strengths_B is not None), (
Exception("One of strengths_E or strengths_B must be supplied")
)

self.handle_init(kw)

Expand Down Expand Up @@ -3011,9 +3011,9 @@ def initialize_inputs(self):
particle_shape = self.particle_shape
for s in self.species:
if s.particle_shape is not None:
assert (
particle_shape is None or particle_shape == s.particle_shape
), Exception("WarpX only supports one particle shape for all species")
assert particle_shape is None or particle_shape == s.particle_shape, (
Exception("WarpX only supports one particle shape for all species")
)
# --- If this was set for any species, use that value.
particle_shape = s.particle_shape

Expand Down Expand Up @@ -4102,7 +4102,7 @@ def __init__(
kw = self._handle_charge_on_eb(**kw)
else:
raise RuntimeError(
f"{self.type} reduced diagnostic is not yet supported " "in pywarpx."
f"{self.type} reduced diagnostic is not yet supported in pywarpx."
)

self.handle_init(kw)
Expand Down
3 changes: 1 addition & 2 deletions Regression/Checksum/checksum.py
Original file line number Diff line number Diff line change
Expand Up @@ -238,8 +238,7 @@ def evaluate(self, rtol=1.0e-9, atol=1.0e-40):
# Dictionaries have same outer keys (levels, species)?
if self.data.keys() != ref_benchmark.data.keys():
print(
"ERROR: Benchmark and output file checksum "
"have different outer keys:"
"ERROR: Benchmark and output file checksum have different outer keys:"
)
print("Benchmark: %s" % ref_benchmark.data.keys())
print("Test file: %s" % self.data.keys())
Expand Down
2 changes: 1 addition & 1 deletion Regression/PostProcessingUtils/post_processing_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -164,6 +164,6 @@ def check_random_filter(fn, filtered_fn, random_fraction, dim, species_name):
## Dirty trick to find particles with the same ID + same CPU (does not work with more than 10
## MPI ranks)
random_filter_expression = (
"np.isin(ids + 0.1*cpus," "ids_filtered_warpx + 0.1*cpus_filtered_warpx)"
"np.isin(ids + 0.1*cpus,ids_filtered_warpx + 0.1*cpus_filtered_warpx)"
)
check_particle_filter(fn, filtered_fn, random_filter_expression, dim, species_name)
Loading

0 comments on commit 2ec6c13

Please sign in to comment.