Skip to content

Commit 5716fde

Browse files
authored
Improve linting (#20)
## 2.4.3 2025-07-07 ### Changed * Configure linter to be slightly more strict * Format and resolve new lints
1 parent dbe1841 commit 5716fde

File tree

9 files changed

+1445
-1446
lines changed

9 files changed

+1445
-1446
lines changed

CHANGELOG_PYTHON.md

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,12 @@
11
# Changelog
22

3+
## 2.4.3 2025-07-07
4+
5+
### Changed
6+
7+
* Configure linter to be slightly more strict
8+
* Format and resolve new lints
9+
310
## 2.4.2 2025-06-16
411

512
### Changed

CHANGELOG_RUST.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,11 @@
11
# Changelog
22

3+
## 2.4.3 2025-07-07
4+
5+
### Changed
6+
7+
* No changes to rust side; version roll for lock-step versioning with python
8+
39
## 2.4.2 2025-06-16
410

511
### Changed

Cargo.lock

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
[package]
22
name = "cfsem"
3-
version = "2.4.2"
3+
version = "2.4.3"
44
edition = "2024"
55
authors = ["Commonwealth Fusion Systems <jlogan@cfs.energy>"]
66
license = "MIT"

cfsem/__init__.py

Lines changed: 28 additions & 51 deletions
Original file line numberDiff line numberDiff line change
@@ -1,30 +1,28 @@
11
"""Quasi-steady electromagnetics calcs"""
22

3-
from typing import Tuple
43
import numpy as np
5-
from numpy.typing import NDArray
64
from interpn import MulticubicRectilinear
7-
8-
from cfsem.types import Array3xN
5+
from numpy.typing import NDArray
96

107
from cfsem.bindings import (
8+
body_force_density_circular_filament_cartesian,
9+
body_force_density_linear_filament,
10+
filament_helix_path,
1111
flux_circular_filament,
12-
flux_density_linear_filament,
1312
flux_density_biot_savart,
1413
flux_density_circular_filament,
14+
flux_density_circular_filament_cartesian,
15+
flux_density_dipole,
16+
flux_density_linear_filament,
1517
gs_operator_order2,
1618
gs_operator_order4,
1719
inductance_piecewise_linear_filaments,
18-
filament_helix_path,
20+
mutual_inductance_circular_to_linear,
1921
rotate_filaments_about_path,
20-
vector_potential_linear_filament,
2122
vector_potential_circular_filament,
22-
flux_density_circular_filament_cartesian,
23-
mutual_inductance_circular_to_linear,
24-
flux_density_dipole,
25-
body_force_density_circular_filament_cartesian,
26-
body_force_density_linear_filament,
23+
vector_potential_linear_filament,
2724
)
25+
from cfsem.types import Array3xN
2826

2927
from .cfsem import ellipe, ellipk
3028

@@ -171,9 +169,7 @@ def mutual_inductance_piecewise_linear_filaments(
171169
return inductance # [H]
172170

173171

174-
def flux_density_ideal_solenoid(
175-
current: float, num_turns: float, length: float
176-
) -> float:
172+
def flux_density_ideal_solenoid(current: float, num_turns: float, length: float) -> float:
177173
"""
178174
Axial B-field on centerline of an ideal (infinitely long) solenoid.
179175
@@ -194,8 +190,8 @@ def flux_density_ideal_solenoid(
194190
def self_inductance_lyle6(r: float, dr: float, dz: float, n: float) -> float:
195191
"""
196192
Self-inductance of a cylindrically-symmetric coil of rectangular
197-
cross-section, estimated to 6th order.
198-
193+
cross-section, estimated to 6th order.
194+
199195
This estimate is viable up to an L/D of about 1.5, above which it
200196
rapidly accumulates error and eventually produces negative values.
201197
@@ -239,13 +235,7 @@ def self_inductance_lyle6(r: float, dr: float, dz: float, n: float) -> float:
239235
f = (
240236
ml
241237
+ (1 + u + v - 8 * (w + ww)) / 12.0 # 0th order in d/a
242-
+ (
243-
da2
244-
* (
245-
cd2 * (221 + 60 * ml - 6 * v)
246-
+ 3 * bd2 * (69 + 60 * ml + 10 * u - 64 * w)
247-
)
248-
)
238+
+ (da2 * (cd2 * (221 + 60 * ml - 6 * v) + 3 * bd2 * (69 + 60 * ml + 10 * u - 64 * w)))
249239
/ 5760.0 # 2nd order
250240
+ (
251241
da2**2
@@ -275,9 +265,7 @@ def self_inductance_lyle6(r: float, dr: float, dz: float, n: float) -> float:
275265
return self_inductance # [H]
276266

277267

278-
def mutual_inductance_of_circular_filaments(
279-
rzn1: NDArray, rzn2: NDArray, par: bool = True
280-
) -> float:
268+
def mutual_inductance_of_circular_filaments(rzn1: NDArray, rzn2: NDArray, par: bool = True) -> float:
281269
"""
282270
Analytic mutual inductance between a pair of ideal cylindrically-symmetric coaxial filaments.
283271
@@ -294,16 +282,12 @@ def mutual_inductance_of_circular_filaments(
294282
float: [H] mutual inductance
295283
"""
296284

297-
m = mutual_inductance_of_cylindrical_coils(
298-
rzn1.reshape((3, 1)), rzn2.reshape((3, 1)), par
299-
)
285+
m = mutual_inductance_of_cylindrical_coils(rzn1.reshape((3, 1)), rzn2.reshape((3, 1)), par)
300286

301287
return m # [H]
302288

303289

304-
def mutual_inductance_of_cylindrical_coils(
305-
f1: NDArray, f2: NDArray, par: bool = True
306-
) -> float:
290+
def mutual_inductance_of_cylindrical_coils(f1: NDArray, f2: NDArray, par: bool = True) -> float:
307291
"""
308292
Analytical mutual inductance between two coaxial collections of ideal filaments.
309293
@@ -324,16 +308,12 @@ def mutual_inductance_of_cylindrical_coils(
324308

325309
# Using n2 as the current per filament is equivalent to examining a 1A reference current,
326310
# which gives us the flux per amp (inductance)
327-
m = np.sum(
328-
n1 * flux_circular_filament(n2, r2, z2, r1, z1, par)
329-
) # [H] total mutual inductance
311+
m = np.sum(n1 * flux_circular_filament(n2, r2, z2, r1, z1, par)) # [H] total mutual inductance
330312

331313
return m # [H]
332314

333315

334-
def filament_coil(
335-
r: float, z: float, w: float, h: float, nt: float, nr: int, nz: int
336-
) -> NDArray:
316+
def filament_coil(r: float, z: float, w: float, h: float, nt: float, nr: int, nz: int) -> NDArray:
337317
"""
338318
Create an array of filaments from coil cross-section, evenly spaced
339319
_inside_ the winding pack. No filaments are coincident with the coil surface.
@@ -365,9 +345,7 @@ def filament_coil(
365345
return filaments # [m], [m], [dimensionless]
366346

367347

368-
def self_inductance_circular_ring_wien(
369-
major_radius: NDArray, minor_radius: NDArray
370-
) -> NDArray:
348+
def self_inductance_circular_ring_wien(major_radius: NDArray, minor_radius: NDArray) -> NDArray:
371349
"""
372350
Wien's formula for the self-inductance of a circular ring
373351
with thin circular cross section.
@@ -391,21 +369,19 @@ def self_inductance_circular_ring_wien(
391369
ra2 = (minor_radius / major_radius) ** 2 # [], (rho / a)^2, dimensionless
392370
# Equation 7 in Rosa & Cohen lacks the factor of 1e-7
393371
# because it is not in SI base units.
394-
self_inductance = (
395-
MU_0 * major_radius * ((1 + 0.125 * ra2) * np.log(8 * ar) - 0.0083 * ra2 - 1.75)
396-
) # [H]
372+
self_inductance = MU_0 * major_radius * ((1 + 0.125 * ra2) * np.log(8 * ar) - 0.0083 * ra2 - 1.75) # [H]
397373
return self_inductance # [H]
398374

399375

400376
def self_inductance_distributed_axisymmetric_conductor(
401377
current: float,
402-
grid: Tuple[NDArray, NDArray],
403-
mesh: Tuple[NDArray, NDArray],
404-
b_part: Tuple[NDArray, NDArray],
378+
grid: tuple[NDArray, NDArray],
379+
mesh: tuple[NDArray, NDArray],
380+
b_part: tuple[NDArray, NDArray],
405381
psi_part: NDArray,
406382
mask: NDArray,
407-
edge_path: Tuple[NDArray, NDArray],
408-
) -> Tuple[float, float, float]:
383+
edge_path: tuple[NDArray, NDArray],
384+
) -> tuple[float, float, float]:
409385
"""
410386
Calculation of a distributed conductor's self-inductance from two components:
411387
@@ -546,7 +522,8 @@ def self_inductance_annular_ring(r: float, a: float, b: float) -> float:
546522
and `(b/r)^2`.
547523
548524
References:
549-
[1] E. B. Rosa and F. W. Grover, “Formulas and tables for the calculation of mutual and self-inductance (Revised),”
525+
[1] E. B. Rosa and F. W. Grover,
526+
“Formulas and tables for the calculation of mutual and self-inductance (Revised),”
550527
BULL. NATL. BUR. STAND., vol. 8, no. 1, p. 1, Jan. 1912,
551528
doi: [10.6028/bulletin.185](https://doi.org/10.6028/bulletin.185)
552529

cfsem/bindings.py

Lines changed: 21 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -5,42 +5,40 @@
55
passed as contiguous and reallocating into contiguous inputs if necessary.
66
"""
77

8-
from cfsem.types import Array3xN
9-
108
from numpy import ascontiguousarray, float64, zeros_like
119
from numpy.typing import NDArray
1210

13-
from .cfsem import flux_circular_filament as em_flux_circular_filament
14-
from .cfsem import flux_density_linear_filament as em_flux_density_linear_filament
15-
from .cfsem import flux_density_circular_filament as em_flux_density_circular_filament
11+
from cfsem.types import Array3xN
12+
1613
from .cfsem import (
17-
flux_density_circular_filament_cartesian as em_flux_density_circular_filament_cartesian,
14+
body_force_density_circular_filament_cartesian as em_body_force_density_circular_filament_cartesian,
1815
)
1916
from .cfsem import (
20-
mutual_inductance_circular_to_linear as em_mutual_inductance_circular_to_linear,
17+
body_force_density_linear_filament as em_body_force_density_linear_filament,
2118
)
19+
from .cfsem import filament_helix_path as em_filament_helix_path
20+
from .cfsem import flux_circular_filament as em_flux_circular_filament
21+
from .cfsem import flux_density_circular_filament as em_flux_density_circular_filament
2222
from .cfsem import (
23-
body_force_density_circular_filament_cartesian as em_body_force_density_circular_filament_cartesian,
23+
flux_density_circular_filament_cartesian as em_flux_density_circular_filament_cartesian,
2424
)
25-
25+
from .cfsem import flux_density_dipole as em_flux_density_dipole
26+
from .cfsem import flux_density_linear_filament as em_flux_density_linear_filament
2627
from .cfsem import gs_operator_order2 as em_gs_operator_order2
2728
from .cfsem import gs_operator_order4 as em_gs_operator_order4
2829
from .cfsem import (
2930
inductance_piecewise_linear_filaments as em_inductance_piecewise_linear_filaments,
3031
)
31-
from .cfsem import filament_helix_path as em_filament_helix_path
32+
from .cfsem import (
33+
mutual_inductance_circular_to_linear as em_mutual_inductance_circular_to_linear,
34+
)
3235
from .cfsem import rotate_filaments_about_path as em_rotate_filaments_about_path
3336
from .cfsem import (
3437
vector_potential_circular_filament as em_vector_potential_circular_filament,
3538
)
3639
from .cfsem import (
3740
vector_potential_linear_filament as em_vector_potential_linear_filament,
3841
)
39-
from .cfsem import (
40-
body_force_density_linear_filament as em_body_force_density_linear_filament,
41-
)
42-
43-
from .cfsem import flux_density_dipole as em_flux_density_dipole
4442

4543

4644
def flux_circular_filament(
@@ -290,9 +288,7 @@ def inductance_piecewise_linear_filaments(
290288
xyzfil1 = _3tup_contig(xyzfil1)
291289
dlxyzfil1 = _3tup_contig(dlxyzfil1)
292290

293-
return em_inductance_piecewise_linear_filaments(
294-
xyzfil0, dlxyzfil0, xyzfil1, dlxyzfil1, self_inductance
295-
)
291+
return em_inductance_piecewise_linear_filaments(xyzfil0, dlxyzfil0, xyzfil1, dlxyzfil1, self_inductance)
296292

297293

298294
def gs_operator_order2(rs: NDArray[float64], zs: NDArray[float64]) -> Array3xN:
@@ -381,9 +377,7 @@ def filament_helix_path(
381377
return helix # [m]
382378

383379

384-
def rotate_filaments_about_path(
385-
path: Array3xN, angle_offset: float, fils: Array3xN
386-
) -> Array3xN:
380+
def rotate_filaments_about_path(path: Array3xN, angle_offset: float, fils: Array3xN) -> Array3xN:
387381
"""
388382
Rotate a path of point about another path.
389383
@@ -436,9 +430,7 @@ def flux_density_circular_filament_cartesian(
436430
"""
437431
ifil, rfil, zfil = _3tup_contig((ifil, rfil, zfil))
438432
xyzp = _3tup_contig(xyzp)
439-
bx, by, bz = em_flux_density_circular_filament_cartesian(
440-
ifil, rfil, zfil, xyzp, par
441-
) # [T]
433+
bx, by, bz = em_flux_density_circular_filament_cartesian(ifil, rfil, zfil, xyzp, par) # [T]
442434

443435
return bx, by, bz # type: ignore
444436

@@ -562,17 +554,16 @@ def body_force_density_linear_filament(
562554
ifil = ascontiguousarray(ifil).flatten()
563555
obs = _3tup_contig(obs)
564556
j = _3tup_contig(j)
565-
jxbx, jxby, jxbz = em_body_force_density_linear_filament(
566-
xyzfil, dlxyzfil, ifil, obs, j, par
567-
) # [N/m^3]
557+
jxbx, jxby, jxbz = em_body_force_density_linear_filament(xyzfil, dlxyzfil, ifil, obs, j, par) # [N/m^3]
568558

569559
return jxbx, jxby, jxbz # type: ignore
570560

571561

572562
def _3tup_contig(
573563
t: Array3xN,
574564
) -> tuple[NDArray[float64], NDArray[float64], NDArray[float64]]:
575-
"""Make contiguous references or copies to arrays in a 3-tuple. Only copies data if it is not already contiguous."""
565+
"""Make contiguous references or copies to arrays in a 3-tuple.
566+
Only copies data if it is not already contiguous."""
576567
return (
577568
ascontiguousarray(t[0]).flatten(),
578569
ascontiguousarray(t[1]).flatten(),
@@ -583,5 +574,6 @@ def _3tup_contig(
583574
def _2tup_contig(
584575
t: tuple[NDArray[float64], NDArray[float64]],
585576
) -> tuple[NDArray[float64], NDArray[float64]]:
586-
"""Make contiguous references or copies to arrays in a 2-tuple. Only copies data if it is not already contiguous."""
577+
"""Make contiguous references or copies to arrays in a 2-tuple.
578+
Only copies data if it is not already contiguous."""
587579
return (ascontiguousarray(t[0]).flatten(), ascontiguousarray(t[1]).flatten())

cfsem/types.py

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
1-
from typing import Tuple, Union
2-
from numpy.typing import NDArray
1+
from typing import Union
2+
33
from numpy import float64
4+
from numpy.typing import NDArray
45

5-
Array3xN = Union[
6-
NDArray[float64], Tuple[NDArray[float64], NDArray[float64], NDArray[float64]]
7-
]
6+
Array3xN = Union[NDArray[float64], tuple[NDArray[float64], NDArray[float64], NDArray[float64]]]
7+
"""A 3xN array expressed as either a 2D numpy array or a tuple of 1D numpy arrays"""

pyproject.toml

Lines changed: 19 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ build-backend = "maturin"
44

55
[project]
66
name = "cfsem"
7-
version = "2.4.2"
7+
version = "2.4.3"
88
description = "Quasi-steady electromagnetics including filamentized approximations, Biot-Savart, and Grad-Shafranov."
99
authors = [{name = "Commonwealth Fusion Systems", email = "jlogan@cfs.energy"}]
1010
requires-python = ">=3.9, <3.14"
@@ -40,7 +40,24 @@ features = ["pyo3/extension-module", "python"]
4040
module-name = "cfsem.cfsem"
4141

4242
[tool.ruff]
43-
target-version = "py311"
43+
target-version = "py39"
44+
line-length = 110
45+
46+
[tool.ruff.lint]
47+
select = [
48+
# pycodestyle
49+
"E",
50+
# Pyflakes
51+
"F",
52+
# pyupgrade
53+
"UP",
54+
# flake8-bugbear
55+
"B",
56+
# flake8-simplify
57+
"SIM",
58+
# isort
59+
"I",
60+
]
4461

4562
[tool.coverage.report]
4663
fail_under = 100

0 commit comments

Comments
 (0)