Skip to content

⚠️ Update pre-commit hooks [review required] - #317

Draft
github-actions[bot] wants to merge 1 commit into
mainfrom
_bot/update-precommit
Draft

⚠️ Update pre-commit hooks [review required]#317
github-actions[bot] wants to merge 1 commit into
mainfrom
_bot/update-precommit

Conversation

@github-actions

Copy link
Copy Markdown
Contributor

Pre-commit is unable to automatically update the hooks due to unresolvable conflicts.
Please review the changes and merge manually.

Log:

check for added large files..........................(no files to check)Skipped
check json...............................................................Passed
check toml...............................................................Passed
check yaml...............................................................Passed
detect private key.......................................................Passed
fix end of files.........................................................Passed
trim trailing whitespace.................................................Passed
Validate pyproject.toml..................................................Passed
uv-lock..................................................................Passed
ruff (legacy alias)......................................................Failed
- hook id: ruff
- exit code: 1

C408 Unnecessary `dict()` call (rewrite as a literal)
  --> adept/_base_.py:40:22
   |
38 |         del solver_state, made_jump
39 |         y1 = terms.vf(t0, y0, args)
40 |         dense_info = dict(y0=y0, y1=y1)
   |                      ^^^^^^^^^^^^^^^^^^
41 |         return y1, None, dense_info, None, RESULTS.successful
   |
help: Rewrite as a literal

SIM102 Use a single `if` statement instead of nested `if` statements
   --> adept/_base_.py:283:9
    |
281 |           """
282 |           # Enforce float64 for kinetic solvers (density conservation requires it)
283 | /         if cfg["solver"] != "envelope-2d":
284 | |             if not jax.config.jax_enable_x64:
    | |_____________________________________________^
285 |                   raise RuntimeError(
286 |                       f"Solver '{cfg['solver']}' requires float64 for numerical precision. "
    |
help: Combine `if` statements using `and`

SIM118 Use `key in dict` instead of `key in dict.keys()`
   --> adept/_hermite_legendre_1d/modules.py:475:13
    |
473 |         coeff_data = {}
474 |
475 |         for k in sol.ys.keys():
    |             ^^^^^^^^^^^^^^^^^^
476 |             t_arr = np.asarray(sol.ts[k])
477 |             data = sol.ys[k]
    |
help: Remove `.keys()`

BLE001 Do not catch blind exception: `Exception`
   --> adept/_hermite_legendre_1d/modules.py:493:32
    |
491 |                             ax.set_title(field_name)
492 |                             fig.savefig(os.path.join(plots_dir, f"spacetime-{field_name}.png"), bbox_inches="tight")
493 |                         except Exception as e:
    |                                ^^^^^^^^^
494 |                             print(f"post_process: spacetime plot for {field_name} failed: {e}")
495 |                         finally:
    |

BLE001 Do not catch blind exception: `Exception`
   --> adept/_hermite_legendre_1d/modules.py:525:32
    |
523 |                             axes[1].grid(alpha=0.3)
524 |                             fig.savefig(os.path.join(plots_dir, f"scalar-{name}.png"), bbox_inches="tight")
525 |                         except Exception as e:
    |                                ^^^^^^^^^
526 |                             print(f"post_process: scalar plot for {name} failed: {e}")
527 |                         finally:
    |

BLE001 Do not catch blind exception: `Exception`
   --> adept/_hermite_legendre_1d/modules.py:533:20
    |
531 |             try:
532 |                 datasets["distribution"] = _distribution_diagnostics(self.cfg, coeff_data, plots_dir, binary_dir)
533 |             except Exception as e:
    |                    ^^^^^^^^^
534 |                 print(f"post_process: distribution diagnostics failed: {e}")
    |

SIM118 Use `key in dict` instead of `key in dict.keys()`
   --> adept/_hermite_poisson_1d/modules.py:495:13
    |
493 |                     metrics[stat_key] = int(sol.stats[stat_key])
494 |
495 |         for k in sol.ys.keys():
    |             ^^^^^^^^^^^^^^^^^^
496 |             t_arr = np.asarray(sol.ts[k])
497 |             data = sol.ys[k]
    |
help: Remove `.keys()`

BLE001 Do not catch blind exception: `Exception`
   --> adept/_hermite_poisson_1d/modules.py:519:32
    |
517 |                             ax.set_title(field_name)
518 |                             fig.savefig(os.path.join(plots_dir, f"spacetime-{field_name}.png"), bbox_inches="tight")
519 |                         except Exception as e:
    |                                ^^^^^^^^^
520 |                             print(f"post_process: spacetime plot for {field_name} failed: {e}")
521 |                         finally:
    |

BLE001 Do not catch blind exception: `Exception`
   --> adept/_hermite_poisson_1d/modules.py:550:32
    |
548 |                             axes[1].grid(alpha=0.3)
549 |                             fig.savefig(os.path.join(plots_dir, f"scalar-{name}.png"), bbox_inches="tight")
550 |                         except Exception as e:
    |                                ^^^^^^^^^
551 |                             print(f"post_process: scalar plot for {name} failed: {e}")
552 |                         finally:
    |

PLC0206 Extracting value from dictionary without calling `.items()`
  --> adept/_lpse2d/core/vector_field.py:44:13
   |
42 |     def _unpack_y_(self, y: dict[str, Array]) -> dict[str, Array]:
43 |         new_y = {}
44 |         for k in y:
   |             ^^^^^^
45 |             if k in self.complex_state_vars:
46 |                 new_y[k] = y[k].view(jnp.complex128)
   |                            ----
47 |             else:
48 |                 new_y[k] = y[k].view(jnp.float64)
   |                            ----
49 |         return new_y
   |
help: Use `for k, value in y.items()` instead

PLC0206 Extracting value from dictionary without calling `.items()`
  --> adept/_lpse2d/core/vector_field.py:52:13
   |
51 |     def _pack_y_(self, y: dict[str, Array], new_y: dict[str, Array]) -> tuple[dict[str, Array], dict[str, Array]]:
52 |         for k in y:
   |             ^^^^^^
53 |             y[k] = y[k].view(jnp.float64)
   |                    ----
54 |             new_y[k] = new_y[k].view(jnp.float64)
   |
help: Use `for k, value in y.items()` instead

SIM118 Use `key in dict` instead of `key in dict.keys()`
   --> adept/_lpse2d/helpers.py:210:9
    |
209 |     # Default save.*.t.tmin/tmax to grid values (preserves unit strings)
210 |     for save_type in cfg.get("save", {}).keys():
    |         ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
211 |         if "t" in cfg["save"][save_type]:
212 |             t_cfg = cfg["save"][save_type]["t"]
    |
help: Remove `.keys()`

SIM118 Use `key in dict` instead of `key in dict.keys()`
   --> adept/_lpse2d/helpers.py:259:9
    |
258 |     # change driver parameters to the right units
259 |     for k in cfg["drivers"].keys():
    |         ^^^^^^^^^^^^^^^^^^^^^^^^^^
260 |         cfg["drivers"][k]["derived"] = {}
261 |         cfg["drivers"][k]["derived"]["tw"] = _Q(cfg["drivers"][k]["envelope"]["tw"]).to("ps").value
    |
help: Remove `.keys()`

SIM118 Use `key in dict` instead of `key in dict.keys()`
   --> adept/_lpse2d/helpers.py:591:9
    |
590 | def plot_series(series, td):
591 |     for k in series.keys():
    |         ^^^^^^^^^^^^^^^^^^
592 |         fig, ax = plt.subplots(1, 2, figsize=(8, 3))
593 |         series[k].plot(ax=ax[0])
    |
help: Remove `.keys()`

C408 Unnecessary `dict()` call (rewrite as a literal)
  --> adept/_lpse2d/modules/base.py:67:35
   |
65 |           }
66 |
67 |           self.diffeqsolve_quants = dict(
   |  ___________________________________^
68 | |             terms=ODETerm(SplitStep(self.cfg)),
69 | |             solver=Stepper(),
70 | |             saveat=dict(
71 | |                 subs={
72 | |                     k: SubSaveAt(ts=subsave["t"]["ax"], fn=subsave["func"]) for k, subsave in self.cfg["save"].items()
73 | |                 }
74 | |             ),
75 | |         )
   | |_________^
76 |
77 |       def init_state_and_args(self) -> dict:
   |
help: Rewrite as a literal

C408 Unnecessary `dict()` call (rewrite as a literal)
  --> adept/_lpse2d/modules/base.py:70:20
   |
68 |               terms=ODETerm(SplitStep(self.cfg)),
69 |               solver=Stepper(),
70 |               saveat=dict(
   |  ____________________^
71 | |                 subs={
72 | |                     k: SubSaveAt(ts=subsave["t"]["ax"], fn=subsave["func"]) for k, subsave in self.cfg["save"].items()
73 | |                 }
74 | |             ),
   | |_____________^
75 |           )
   |
help: Rewrite as a literal

PERF102 When using only the values of a dict use the `values()` method
   --> adept/_lpse2d/modules/base.py:114:29
    |
112 |             args = self.args
113 |
114 |         for name, module in trainable_modules.items():
    |                             ^^^^^^^^^^^^^^^^^^^^^^^
115 |             state, args = module(state, args)
    |
help: Replace `.items()` with `.values()`

C408 Unnecessary `dict()` call (rewrite as a literal)
   --> adept/_pic1d/modules.py:151:35
    |
149 |           grid = self.simulation.grid
150 |           self.time_quantities = {"t0": 0.0, "t1": grid.tmax, "max_steps": grid.max_steps}
151 |           self.diffeqsolve_quants = dict(
    |  ___________________________________^
152 | |             terms=ODETerm(PIC1DVectorField(self.cfg, grid, self.simulation.drivers)),
153 | |             solver=Stepper(),
154 | |             saveat=dict(subs={k: SubSaveAt(ts=v["t"]["ax"], fn=v["func"]) for k, v in self.cfg["save"].items()}),
155 | |         )
    | |_________^
156 |
157 |       def __call__(self, trainable_modules: dict, args: dict | None = None):
    |
help: Rewrite as a literal

C408 Unnecessary `dict()` call (rewrite as a literal)
   --> adept/_pic1d/modules.py:154:20
    |
152 |             terms=ODETerm(PIC1DVectorField(self.cfg, grid, self.simulation.drivers)),
153 |             solver=Stepper(),
154 |             saveat=dict(subs={k: SubSaveAt(ts=v["t"]["ax"], fn=v["func"]) for k, v in self.cfg["save"].items()}),
    |                    ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
155 |         )
    |
help: Rewrite as a literal

SIM118 Use `key in dict` instead of `key in dict.keys()`
  --> adept/_pic1d/simulation.py:74:22
   |
73 | def _density_component_names(cfg: PIC1DConfig) -> list[str]:
74 |     return [name for name in cfg.density.model_extra.keys() if name.startswith("species-")]
   |                      ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
   |
help: Remove `.keys()`

SIM118 Use `key in dict` instead of `key in dict.keys()`
   --> adept/_spectrax1d/base_module.py:214:13
    |
213 |         # Default save.*.t.tmin/tmax to grid values
214 |         for save_type in self.cfg.get("save", {}).keys():
    |             ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
215 |             if "t" in self.cfg["save"][save_type]:
216 |                 t_cfg = self.cfg["save"][save_type]["t"]
    |
help: Remove `.keys()`

SIM118 Use `key in dict` instead of `key in dict.keys()`
    --> adept/_spectrax1d/base_module.py:1022:13
     |
1020 |         saved_datasets = {}
1021 |         has_fields_data = False
1022 |         for k in sol.ys.keys():
     |             ^^^^^^^^^^^^^^^^^^
1023 |             if k == "default":
1024 |                 # Default scalar diagnostics
     |
help: Remove `.keys()`

PERF102 When using only the values of a dict use the `values()` method
  --> adept/_spectrax1d/driver.py:62:41
   |
60 |         # so Ex remains real in real space and nonlinear E*C coupling stays local in k.
61 |         total_field = jnp.zeros(self.Nx, dtype=jnp.float64)
62 |         for pulse_name, pulse_params in pulse_configs.items():
   |                                         ^^^^^^^^^^^^^^^^^^^
63 |             total_field = total_field + self._get_single_pulse(pulse_params, t)
   |
help: Replace `.items()` with `.values()`

PLC0206 Extracting value from dictionary without calling `.items()`
   --> adept/_spectrax1d/exponential_operators.py:348:13
    |
346 |         }
347 |         # Forward any extra state keys (e.g. SSM hidden state) unchanged
348 |         for k in y:
    |             ^^^^^^
349 |             if k not in out:
350 |                 out[k] = y[k]
    |                          ----
351 |         return out
    |
help: Use `for k, value in y.items()` instead

PLC0206 Extracting value from dictionary without calling `.items()`
   --> adept/_spectrax1d/integrators.py:272:13
    |
271 |         # Forward any extra state keys (e.g. SSM hidden state) unchanged
272 |         for k in y:
    |             ^^^^^^
273 |             if k not in y_damped:
274 |                 y_damped[k] = y[k]
    |                               ----
275 |
276 |         return y_damped
    |
help: Use `for k, value in y.items()` instead

C408 Unnecessary `dict()` call (rewrite as a literal)
   --> adept/_spectrax1d/integrators.py:407:22
    |
406 |         # Dense info for interpolation (linear between endpoints)
407 |         dense_info = dict(y0=y0, y1=y1)
    |                      ^^^^^^^^^^^^^^^^^^
408 |
409 |         return y1, y_error, dense_info, solver_state, RESULTS.successful
    |
help: Rewrite as a literal

PLC0206 Extracting value from dictionary without calling `.items()`
   --> adept/_spectrax1d/nonlinear_vector_field.py:308:13
    |
306 |         """Unpack state from float64 views to complex128."""
307 |         new_y = {}
308 |         for k in y:
    |             ^^^^^^
309 |             if k in self.complex_state_vars:
310 |                 new_y[k] = y[k].view(jnp.complex128)
    |                            ----
311 |             else:
312 |                 new_y[k] = y[k].view(jnp.float64)
    |                            ----
313 |         return new_y
    |
help: Use `for k, value in y.items()` instead

PLC0206 Extracting value from dictionary without calling `.items()`
   --> adept/_spectrax1d/nonlinear_vector_field.py:434:13
    |
432 |         # Zero derivatives for extra state keys (e.g. SSM hidden state,
433 |         # which is updated discretely by the closure solver, not the ODE RHS)
434 |         for k in y:
    |             ^^^^^^
435 |             if k not in out:
436 |                 out[k] = jnp.zeros_like(y[k])
    |                                         ----
437 |         return out
    |
help: Use `for k, value in y.items()` instead

SIM118 Use `key in dict` instead of `key in dict.keys()`
  --> adept/_tf1d/modules.py:35:16
   |
33 |         datasets = {}
34 |         if any(x in ["x", "kx"] for x in self.cfg["save"]):
35 |             if "x" in self.cfg["save"].keys():
   |                ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
36 |                 datasets["x"] = save_arrays(solver_result["solver result"], td, self.cfg, label="x")
37 |                 plot_xrs("x", td, datasets["x"])
   |
help: Remove `.keys()`

SIM118 Use `key in dict` instead of `key in dict.keys()`
  --> adept/_tf1d/modules.py:38:16
   |
36 |                 datasets["x"] = save_arrays(solver_result["solver result"], td, self.cfg, label="x")
37 |                 plot_xrs("x", td, datasets["x"])
38 |             if "kx" in self.cfg["save"].keys():
   |                ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
39 |                 datasets["kx"] = save_arrays(solver_result["solver result"], td, self.cfg, label="kx")
40 |                 plot_xrs("kx", td, datasets["kx"])
   |
help: Remove `.keys()`

SIM118 Use `key in dict` instead of `key in dict.keys()`
  --> adept/_tf1d/modules.py:68:12
   |
67 |         box_length = ((self.cfg["grid"]["xmax"] - self.cfg["grid"]["xmin"]) * x0).to("microns")
68 |         if "ymax" in self.cfg["grid"].keys():
   |            ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
69 |             box_width = ((self.cfg["grid"]["ymax"] - self.cfg["grid"]["ymin"]) * x0).to("microns")
70 |         else:
   |
help: Remove `.keys()`

SIM118 Use `key in dict` instead of `key in dict.keys()`
   --> adept/_tf1d/modules.py:118:13
    |
117 |         # Default save.*.t.tmin/tmax to grid values
118 |         for save_type in self.cfg.get("save", {}).keys():
    |             ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
119 |             if "t" in self.cfg["save"][save_type]:
120 |                 t_cfg = self.cfg["save"][save_type]["t"]
    |
help: Remove `.keys()`

C408 Unnecessary `dict()` call (rewrite as a literal)
   --> adept/_tf1d/modules.py:184:35
    |
183 |           for species in ["ion", "electron"]:
184 |               self.state[species] = dict(
    |  ___________________________________^
185 | |                 n=jnp.ones(self.cfg["grid"]["nx"]),
186 | |                 p=jnp.full(self.cfg["grid"]["nx"], self.cfg["physics"][species]["T0"]),
187 | |                 u=jnp.zeros(self.cfg["grid"]["nx"]),
188 | |                 delta=jnp.zeros(self.cfg["grid"]["nx"]),
189 | |             )
    | |_____________^
190 |
191 |       def get_save_func(self) -> Callable:
    |
help: Rewrite as a literal

SIM118 Use `key in dict` instead of `key in dict.keys()`
   --> adept/_tf1d/modules.py:197:16
    |
195 |         """
196 |         if any(x in ["x", "kx"] for x in self.cfg["save"]):
197 |             if "x" in self.cfg["save"].keys():
    |                ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
198 |                 dx = (self.cfg["save"]["x"]["xmax"] - self.cfg["save"]["x"]["xmin"]) / self.cfg["save"]["x"]["nx"]
199 |                 self.cfg["save"]["x"]["ax"] = jnp.linspace(
    |
help: Remove `.keys()`

SIM118 Use `key in dict` instead of `key in dict.keys()`
   --> adept/_tf1d/modules.py:207:16
    |
205 |                 save_x = partial(jnp.interp, self.cfg["save"]["x"]["ax"], self.cfg["grid"]["x"])
206 |
207 |             if "kx" in self.cfg["save"].keys():
    |                ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
208 |                 self.cfg["save"]["kx"]["ax"] = jnp.linspace(
209 |                     self.cfg["save"]["kx"]["kxmin"], self.cfg["save"]["kx"]["kxmax"], self.cfg["save"]["kx"]["nkx"]
    |
help: Remove `.keys()`

SIM118 Use `key in dict` instead of `key in dict.keys()`
   --> adept/_tf1d/modules.py:219:20
    |
217 |             def save_func(t, y, args):
218 |                 save_dict = {}
219 |                 if "x" in self.cfg["save"].keys():
    |                    ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
220 |                     save_dict["x"] = jtu.tree_map(save_x, y)
221 |                 if "kx" in self.cfg["save"].keys():
    |
help: Remove `.keys()`

SIM118 Use `key in dict` instead of `key in dict.keys()`
   --> adept/_tf1d/modules.py:221:20
    |
219 |                 if "x" in self.cfg["save"].keys():
220 |                     save_dict["x"] = jtu.tree_map(save_x, y)
221 |                 if "kx" in self.cfg["save"].keys():
    |                    ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
222 |                     save_dict["kx"] = jtu.tree_map(save_kx, y)
    |
help: Remove `.keys()`

C408 Unnecessary `dict()` call (rewrite as a literal)
   --> adept/_tf1d/modules.py:248:35
    |
246 |               self.cfg["save"]["t"]["tmin"], self.cfg["save"]["t"]["tmax"], self.cfg["save"]["t"]["nt"]
247 |           )
248 |           self.diffeqsolve_quants = dict(
    |  ___________________________________^
249 | |             terms=ODETerm(VF(self.cfg)), solver=Tsit5(), saveat=dict(ts=self.cfg["save"]["t"]["ax"], fn=save_f)
250 | |         )
    | |_________^
251 |
252 |       def __call__(self, trainable_modules: dict, args: dict) -> dict:
    |
help: Rewrite as a literal

C408 Unnecessary `dict()` call (rewrite as a literal)
   --> adept/_tf1d/modules.py:249:65
    |
247 |         )
248 |         self.diffeqsolve_quants = dict(
249 |             terms=ODETerm(VF(self.cfg)), solver=Tsit5(), saveat=dict(ts=self.cfg["save"]["t"]["ax"], fn=save_f)
    |                                                                 ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
250 |         )
    |
help: Rewrite as a literal

SIM210 Remove unnecessary `True if ... else False`
   --> adept/_tf1d/solvers/pushers.py:179:60
    |
178 |         table_wrs, table_wis, table_klds = get_complex_frequency_table(1024, kinetic_real_epw)
179 |         wrs, wis, klds = get_complex_frequency_table(1024, True if physics["gamma"] == "kinetic" else False)
    |                                                            ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
180 |         wrs = jnp.interp(kxr, table_klds, table_wrs, left=1.0, right=table_wrs[-1])
181 |         self.wis = jnp.interp(kxr, table_klds, table_wis, left=0.0, right=0.0)
    |
help: Remove unnecessary `True if ... else False`

SIM118 Use `key in dict` instead of `key in dict.keys()`
  --> adept/_tf1d/solvers/vector_field.py:61:13
   |
59 |         ed = 0.0
60 |
61 |         for p_ind in self.cfg["drivers"]["ex"].keys():
   |             ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
62 |             ed += self.push_driver(args["drivers"]["ex"][p_ind], t)
   |
help: Remove `.keys()`

SIM118 Use `key in dict` instead of `key in dict.keys()`
   --> adept/_vlasov1d/helpers.py:205:9
    |
203 |     fields_base_dir = os.path.join(td, "plots", "fields")
204 |
205 |     for k in result.ys.keys():
    |         ^^^^^^^^^^^^^^^^^^^^^
206 |         if k.startswith("field"):
207 |             # store_fields now returns dict with species names and "fields" keys
    |
help: Remove `.keys()`

SIM118 Use `key in dict` instead of `key in dict.keys()`
  --> adept/_vlasov1d/modules.py:32:40
   |
30 |     else:
31 |         # Collect all density components (keys starting with "species-")
32 |         density_components = [name for name in cfg.density.model_extra.keys() if name.startswith("species-")]
   |                                        ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
33 |         if not density_components:
34 |             raise ValueError("No density components found (expected keys starting with 'species-')")
   |
help: Remove `.keys()`

SIM118 Use `key in dict` instead of `key in dict.keys()`
   --> adept/_vlasov1d/modules.py:114:12
    |
113 |         box_length = ((grid.xmax - grid.xmin) * norm.L0).to("microns")
114 |         if "ymax" in self.cfg["grid"].keys():
    |            ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
115 |             box_width = ((self.cfg["grid"]["ymax"] - self.cfg["grid"]["ymin"]) * norm.L0).to("microns")
116 |         else:
    |
help: Remove `.keys()`

C408 Unnecessary `dict()` call (rewrite as a literal)
   --> adept/_vlasov1d/modules.py:317:35
    |
315 |           grid = self.simulation.grid
316 |           self.time_quantities = {"t0": 0.0, "t1": grid.tmax, "max_steps": grid.max_steps}
317 |           self.diffeqsolve_quants = dict(
    |  ___________________________________^
318 | |             terms=ODETerm(
319 | |                 VlasovMaxwell(
320 | |                     self.cfg,
321 | |                     grid,
322 | |                     self.simulation.drivers,
323 | |                     nu_fp_prof=self.simulation.nu_fp_prof,
324 | |                     nu_K_prof=self.simulation.nu_K_prof,
325 | |                 )
326 | |             ),
327 | |             solver=Stepper(),
328 | |             saveat=dict(subs={k: SubSaveAt(ts=v["t"]["ax"], fn=v["func"]) for k, v in self.cfg["save"].items()}),
329 | |         )
    | |_________^
330 |
331 |       def __call__(self, trainable_modules: dict, args: dict | None = None):
    |
help: Rewrite as a literal

C408 Unnecessary `dict()` call (rewrite as a literal)
   --> adept/_vlasov1d/modules.py:328:20
    |
326 |             ),
327 |             solver=Stepper(),
328 |             saveat=dict(subs={k: SubSaveAt(ts=v["t"]["ax"], fn=v["func"]) for k, v in self.cfg["save"].items()}),
    |                    ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
329 |         )
    |
help: Rewrite as a literal

PLC0206 Extracting value from dictionary without calling `.items()`
   --> adept/_vlasov1d/solvers/vector_field.py:247:17
    |
245 |         if self.vlasov_dfdt:
246 |             # Compute diagnostics for each species
247 |             for species_name in f_dict:
    |                 ^^^^^^^^^^^^^^^^^^^^^^
248 |                 diags[f"diag-vlasov-dfdt-{species_name}"] = (f_vlasov[species_name] - f_dict[species_name]) / self.dt
    |                                                                                       --------------------
249 |         if self.fp_dfdt:
250 |             # Compute diagnostics for each species
    |
help: Use `for species_name, value in f_dict.items()` instead

SIM118 Use `key in dict` instead of `key in dict.keys()`
   --> adept/_vlasov2d/helpers.py:251:9
    |
250 |     fields_result = {}
251 |     for k in result.ys.keys():
    |         ^^^^^^^^^^^^^^^^^^^^^
252 |         if k.startswith("field"):
253 |             fields_dict = store_fields(cfg, binary_dir, result.ys[k], result.ts[k], k)
    |
help: Remove `.keys()`

SIM118 Use `key in dict` instead of `key in dict.keys()`
  --> adept/_vlasov2d/modules.py:32:28
   |
30 |     if cfg.terms.species:
31 |         return [Species.from_config(s) for s in cfg.terms.species]
32 |     components = [name for name in cfg.density.model_extra.keys() if name.startswith("species-")]
   |                            ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
33 |     if not components:
34 |         raise ValueError("No density components found (expected keys starting with 'species-').")
   |
help: Remove `.keys()`

SIM118 Use `key in dict` instead of `key in dict.keys()`
   --> adept/_vlasov2d/modules.py:215:13
    |
213 |         poisson = InitialPoissonSolver(self.simulation.grid.kx, self.simulation.grid.ky)
214 |         rho0 = jnp.zeros((grid.nx, grid.ny))
215 |         for s_name in dist_result.keys():
    |             ^^^^^^^^^^^^^^^^^^^^^^^^^^^^
216 |             sg = self.cfg["grid"]["species_grids"][s_name]
217 |             q = self.cfg["grid"]["species_params"][s_name]["charge"]
    |
help: Remove `.keys()`

C408 Unnecessary `dict()` call (rewrite as a literal)
   --> adept/_vlasov2d/modules.py:241:35
    |
239 |           grid = self.simulation.grid
240 |           self.time_quantities = {"t0": 0.0, "t1": grid.tmax, "max_steps": grid.max_steps}
241 |           self.diffeqsolve_quants = dict(
    |  ___________________________________^
242 | |             terms=ODETerm(VlasovMaxwell(self.cfg, grid, self.simulation)),
243 | |             solver=Stepper(),
244 | |             saveat=dict(subs={k: SubSaveAt(ts=v["t"]["ax"], fn=v["func"]) for k, v in self.cfg["save"].items()}),
245 | |         )
    | |_________^
246 |
247 |       def __call__(self, trainable_modules: dict, args: dict | None = None):
    |
help: Rewrite as a literal

C408 Unnecessary `dict()` call (rewrite as a literal)
   --> adept/_vlasov2d/modules.py:244:20
    |
242 |             terms=ODETerm(VlasovMaxwell(self.cfg, grid, self.simulation)),
243 |             solver=Stepper(),
244 |             saveat=dict(subs={k: SubSaveAt(ts=v["t"]["ax"], fn=v["func"]) for k, v in self.cfg["save"].items()}),
    |                    ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
245 |         )
    |
help: Rewrite as a literal

SIM118 Use `key in dict` instead of `key in dict.keys()`
   --> adept/_vlasov2d/solvers/vector_field.py:129:37
    |
128 |     def __call__(self, t, y, args):
129 |         f_dict = {name: y[name] for name in self.species_grids.keys()}
    |                                     ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
130 |         ex = y["ex"]
131 |         ey = y["ey"]
    |
help: Remove `.keys()`

PLC0414 Import alias does not rename original package
 --> adept/spectrax1d.py:3:39
  |
1 | """Convenience import for Spectrax-1D module"""
2 |
3 | from adept._spectrax1d.modules import EPW1D as EPW1D
  |                                       ^^^^^^^^^^^^^^
4 | from adept._spectrax1d.modules import BaseSpectrax1D as BaseSpectrax1D
5 | from adept._spectrax1d.modules import Maxwell1D as Maxwell1D
  |
help: Remove import alias

PLC0414 Import alias does not rename original package
 --> adept/spectrax1d.py:4:39
  |
3 | from adept._spectrax1d.modules import EPW1D as EPW1D
4 | from adept._spectrax1d.modules import BaseSpectrax1D as BaseSpectrax1D
  |                                       ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
5 | from adept._spectrax1d.modules import Maxwell1D as Maxwell1D
  |
help: Remove import alias

PLC0414 Import alias does not rename original package
 --> adept/spectrax1d.py:5:39
  |
3 | from adept._spectrax1d.modules import EPW1D as EPW1D
4 | from adept._spectrax1d.modules import BaseSpectrax1D as BaseSpectrax1D
5 | from adept._spectrax1d.modules import Maxwell1D as Maxwell1D
  |                                       ^^^^^^^^^^^^^^^^^^^^^^
  |
help: Remove import alias

BLE001 Do not catch blind exception: `Exception`
   --> adept/utils.py:274:16
    |
272 |             print(f"Successfully removed {directory}")
273 |             break
274 |         except Exception as e:
    |                ^^^^^^^^^
275 |             # if e.errno == 5:  # Input/output error
276 |             print(f"Attempt {attempt + 1} failed: {e}")
    |

SIM103 Return the condition `bool(hasattr(value, "ndim") and value.ndim == 0)` directly
   --> adept/utils.py:293:5
    |
291 |           return False
292 |       # Handle numpy scalar types
293 | /     if hasattr(value, "ndim") and value.ndim == 0:
294 | |         return True
295 | |     return False
    | |________________^
    |
help: Replace with `return bool(hasattr(value, "ndim") and value.ndim == 0)`

SIM118 Use `key in dict` instead of `key in dict.keys()`
   --> adept/vfp1d/base.py:131:13
    |
130 |         # Default save.*.t.tmin/tmax to computed grid values
131 |         for save_type in self.cfg.get("save", {}).keys():
    |             ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
132 |             if "t" in self.cfg["save"][save_type]:
133 |                 t_cfg = self.cfg["save"][save_type]["t"]
    |
help: Remove `.keys()`

C408 Unnecessary `dict()` call (rewrite as a literal)
   --> adept/vfp1d/base.py:232:35
    |
230 |               "max_steps": grid.max_steps,
231 |           }
232 |           self.diffeqsolve_quants = dict(
    |  ___________________________________^
233 | |             terms=ODETerm(OSHUN1D(self.cfg, grid=grid)),
234 | |             solver=Stepper(),
235 | |             saveat=dict(subs={k: SubSaveAt(ts=v["t"]["ax"], fn=v["func"]) for k, v in self.cfg["save"].items()}),
236 | |         )
    | |_________^
237 |
238 |       def __call__(self, trainable_modules: dict, args: dict):
    |
help: Rewrite as a literal

C408 Unnecessary `dict()` call (rewrite as a literal)
   --> adept/vfp1d/base.py:235:20
    |
233 |             terms=ODETerm(OSHUN1D(self.cfg, grid=grid)),
234 |             solver=Stepper(),
235 |             saveat=dict(subs={k: SubSaveAt(ts=v["t"]["ax"], fn=v["func"]) for k, v in self.cfg["save"].items()}),
    |                    ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
236 |         )
    |
help: Rewrite as a literal

SIM102 Use a single `if` statement instead of nested `if` statements
   --> adept/vfp1d/helpers.py:232:13
    |
230 |               profs = {}
231 |               m = species_params["m"]
232 | /             if name in params:
233 | |                 if "m" in params[name]:
    | |_______________________________________^
234 |                       m = params[name]["m"]
    |
help: Combine `if` statements using `and`

SIM118 Use `key in dict` instead of `key in dict.keys()`
   --> adept/vfp1d/storage.py:103:33
    |
101 |     tax = this_t * cfg["units"]["derived"]["tp0"].to("ps").magnitude
102 |
103 |     if any(x in ["x", "kx"] for x in cfg["save"][prefix].keys()):
    |                                 ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
104 |         crds = set(cfg["save"][prefix].keys()) - {"t", "func"}
105 |         if {"x"} == crds:
    |
help: Remove `.keys()`

SIM118 Use `key in dict` instead of `key in dict.keys()`
   --> adept/vfp1d/storage.py:191:9
    |
190 |     das = {}
191 |     for dist in ys["electron"].keys():
    |         ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
192 |         data = ys["electron"][dist]
193 |         # f0 at centers, f10 at edges
    |
help: Remove `.keys()`

SIM118 Use `key in dict` instead of `key in dict.keys()`
   --> adept/vfp1d/storage.py:235:9
    |
234 |     # merge
235 |     for k in soln.ys.keys():
    |         ^^^^^^^^^^^^^^^^^^^
236 |         if k.startswith("field"):
237 |             fields_xr = store_fields(cfg, binary_dir, soln.ys[k], soln.ts[k], k)
    |
help: Remove `.keys()`

SIM118 Use `key in dict` instead of `key in dict.keys()`
   --> adept/vfp1d/storage.py:375:9
    |
373 |     """
374 |
375 |     for k in cfg["save"].keys():  # this can be fields or electron or scalar?
    |         ^^^^^^^^^^^^^^^^^^^^^^^
376 |         tmin = normalize(cfg["save"][k]["t"]["tmin"], norm, dim="t")
377 |         tmax = normalize(cfg["save"][k]["t"]["tmax"], norm, dim="t")
    |
help: Remove `.keys()`

SIM118 Use `key in dict` instead of `key in dict.keys()`
   --> adept/vlasov1d2v/helpers.py:205:9
    |
204 |     # Default save.*.t.tmin/tmax to grid values
205 |     for save_type in cfg.get("save", {}).keys():
    |         ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
206 |         if "t" in cfg["save"][save_type]:
207 |             t_cfg = cfg["save"][save_type]["t"]
    |
help: Remove `.keys()`

C408 Unnecessary `dict()` call (rewrite as a literal)
   --> adept/vlasov1d2v/helpers.py:344:12
    |
343 |   def get_diffeqsolve_quants(cfg):
344 |       return dict(
    |  ____________^
345 | |         terms=ODETerm(VlasovMaxwell(cfg)),
346 | |         solver=Stepper(),
347 | |         saveat=dict(subs={k: SubSaveAt(ts=v["t"]["ax"], fn=v["func"]) for k, v in cfg["save"].items()}),
348 | |     )
    | |_____^
    |
help: Rewrite as a literal

C408 Unnecessary `dict()` call (rewrite as a literal)
   --> adept/vlasov1d2v/helpers.py:347:16
    |
345 |         terms=ODETerm(VlasovMaxwell(cfg)),
346 |         solver=Stepper(),
347 |         saveat=dict(subs={k: SubSaveAt(ts=v["t"]["ax"], fn=v["func"]) for k, v in cfg["save"].items()}),
    |                ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
348 |     )
    |
help: Rewrite as a literal

SIM118 Use `key in dict` instead of `key in dict.keys()`
   --> adept/vlasov1d2v/helpers.py:365:9
    |
363 |     # flds_paths = [os.path.join(flds_path, tf) for tf in flds_list]
364 |     # arr = xarray.open_mfdataset(flds_paths, combine="by_coords", parallel=True)
365 |     for k in result.ys.keys():
    |         ^^^^^^^^^^^^^^^^^^^^^
366 |         if k.startswith("field"):
367 |             fields_xr = store_fields(cfg, binary_dir, result.ys[k], result.ts[k], k)
    |
help: Remove `.keys()`

C408 Unnecessary `dict()` call (rewrite as a literal)
  --> adept/vlasov1d2v/integrator.py:17:22
   |
15 |         del solver_state, made_jump
16 |         y1 = terms.vf(t0, y0, args)
17 |         dense_info = dict(y0=y0, y1=y1)
   |                      ^^^^^^^^^^^^^^^^^^
18 |         return y1, None, dense_info, None, diffrax.RESULTS.successful
   |
help: Rewrite as a literal

PERF102 When using only the values of a dict use the `values()` method
  --> adept/vlasov1d2v/pushers/field.py:36:25
   |
34 |         total_de = jnp.zeros_like(self.xax)
35 |
36 |         for _, pulse in args["drivers"][self.driver_key].items():
   |                         ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
37 |             total_de += self.get_this_pulse(pulse, t)
   |
help: Replace `.items()` with `.values()`

SIM118 Use `key in dict` instead of `key in dict.keys()`
  --> adept/vlasov1d2v/storage.py:24:33
   |
22 |     """
23 |
24 |     if any(x in ["x", "kx"] for x in cfg["save"][prefix].keys()):
   |                                 ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
25 |         crds = set(cfg["save"][prefix].keys()) - {"t", "func"}
26 |         if {"x"} == crds:
   |
help: Remove `.keys()`

SIM118 Use `key in dict` instead of `key in dict.keys()`
   --> adept/vlasov1d2v/storage.py:256:9
    |
254 |     :return:
255 |     """
256 |     for k in cfg["save"].keys():  # this can be fields or electron or scalar?
    |         ^^^^^^^^^^^^^^^^^^^^^^^
257 |         # for k2 in cfg["save"][k].keys():  # this can be t, x, y, kx, ky (eventually)
258 |         #     if k2 == "x":
    |
help: Remove `.keys()`

BLE001 Do not catch blind exception: `Exception`
   --> docs/source/conf.py:137:12
    |
135 |         if filepath is None:
136 |             return
137 |     except Exception:
    |            ^^^^^^^^^
138 |         return None
    |

C403 Unnecessary list comprehension (rewrite as a set comprehension)
   --> tests/test_base/test_mlflow_logging.py:110:16
    |
109 |     assert len(pre_logging_matches) == 3
110 |     assert len(set([m.group(1) for m in pre_logging_matches])) == 3
    |                ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
111 |     assert len(post_logging_matches) == 3
112 |     assert len(set([m.group(1) for m in post_logging_matches])) == 3
    |
help: Rewrite as a set comprehension

C403 Unnecessary list comprehension (rewrite as a set comprehension)
   --> tests/test_base/test_mlflow_logging.py:112:16
    |
110 |     assert len(set([m.group(1) for m in pre_logging_matches])) == 3
111 |     assert len(post_logging_matches) == 3
112 |     assert len(set([m.group(1) for m in post_logging_matches])) == 3
    |                ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
113 |
114 |     assert set([m.group(1) for m in pre_logging_matches]) == set([m.group(1) for m in post_logging_matches])
    |
help: Rewrite as a set comprehension

C403 Unnecessary list comprehension (rewrite as a set comprehension)
   --> tests/test_base/test_mlflow_logging.py:114:12
    |
112 |     assert len(set([m.group(1) for m in post_logging_matches])) == 3
113 |
114 |     assert set([m.group(1) for m in pre_logging_matches]) == set([m.group(1) for m in post_logging_matches])
    |            ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
    |
help: Rewrite as a set comprehension

C403 Unnecessary list comprehension (rewrite as a set comprehension)
   --> tests/test_base/test_mlflow_logging.py:114:62
    |
112 |     assert len(set([m.group(1) for m in post_logging_matches])) == 3
113 |
114 |     assert set([m.group(1) for m in pre_logging_matches]) == set([m.group(1) for m in post_logging_matches])
    |                                                              ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
    |
help: Rewrite as a set comprehension

C403 Unnecessary list comprehension (rewrite as a set comprehension)
   --> tests/test_base/test_mlflow_logging.py:197:16
    |
196 |     assert len(pre_logging_matches) == 3
197 |     assert len(set([m.group(1) for m in pre_logging_matches])) == 3
    |                ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
198 |     assert len(post_logging_matches) == 3
199 |     assert len(set([m.group(1) for m in post_logging_matches])) == 3
    |
help: Rewrite as a set comprehension

C403 Unnecessary list comprehension (rewrite as a set comprehension)
   --> tests/test_base/test_mlflow_logging.py:199:16
    |
197 |     assert len(set([m.group(1) for m in pre_logging_matches])) == 3
198 |     assert len(post_logging_matches) == 3
199 |     assert len(set([m.group(1) for m in post_logging_matches])) == 3
    |                ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
200 |
201 |     assert set([m.group(1) for m in pre_logging_matches]) == set([m.group(1) for m in post_logging_matches])
    |
help: Rewrite as a set comprehension

C403 Unnecessary list comprehension (rewrite as a set comprehension)
   --> tests/test_base/test_mlflow_logging.py:201:12
    |
199 |     assert len(set([m.group(1) for m in post_logging_matches])) == 3
200 |
201 |     assert set([m.group(1) for m in pre_logging_matches]) == set([m.group(1) for m in post_logging_matches])
    |            ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
    |
help: Rewrite as a set comprehension

C403 Unnecessary list comprehension (rewrite as a set comprehension)
   --> tests/test_base/test_mlflow_logging.py:201:62
    |
199 |     assert len(set([m.group(1) for m in post_logging_matches])) == 3
200 |
201 |     assert set([m.group(1) for m in pre_logging_matches]) == set([m.group(1) for m in post_logging_matches])
    |                                                              ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
    |
help: Rewrite as a set comprehension

C419 Unnecessary list comprehension
  --> tests/test_lpse2d/test_tpd_threshold.py:31:16
   |
30 | def test_threshold():
31 |     if not any(["gpu" == device.platform for device in devices()]):
   |                ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
32 |         pytest.skip("Takes too long without a GPU")
33 |     else:
   |
help: Remove unnecessary comprehension

C419 Unnecessary list comprehension
   --> tests/test_tf1d/test_resonance_search.py:100:20
    |
 98 | if __name__ == "__main__":
 99 |     for gamma, adjoint in product(["kinetic", 3.0], ["Recursive", "Backsolve"]):
100 |         if not any(["gpu" == device.platform for device in devices()]):
    |                    ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
101 |             pytest.skip("Takes too long without a GPU")
102 |         else:
    |
help: Remove unnecessary comprehension

C419 Unnecessary list comprehension
  --> tests/test_vfp1d/test_kappa_eh.py:44:16
   |
42 | @pytest.mark.parametrize("ee", [True, False])
43 | def test_kappa_eh(Z, ee):
44 |     if not any(["gpu" == device.platform for device in devices()]):
   |                ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
45 |         if Z in [1, 21, 80]:
46 |             _run_(Z, ee)
   |
help: Remove unnecessary comprehension

C419 Unnecessary list comprehension
  --> tests/test_vfp1d/test_kappa_eh.py:57:16
   |
55 | @pytest.mark.parametrize("ee", [True, False])
56 | def test_kappa_eh_reflective(Z, ee):
57 |     if not any(["gpu" == device.platform for device in devices()]):
   |                ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
58 |         if Z in [1, 21, 80]:
59 |             _run_(Z, ee, config_name="epp-short-reflective")
   |
help: Remove unnecessary comprehension

Found 87 errors.
No fixes available (73 hidden fixes can be enabled with the `--unsafe-fixes` option).

ruff format..............................................................Passed

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant