fix: enforce strict ruff lint (17 rule sets) across entire repo
- Expand ruff config from E/F to 17 rule sets (B, RUF, SIM, PIE, T20, ARG, ERA, A, BLE, RET, ISC, TCH, UP, C4, PERF) - Fix 907 lint errors across all Python files (GUI, FPGA cosim, schematics scripts, simulations, utilities, tools) - Replace all blind except-Exception with specific exception types - Remove commented-out dead code (ERA001) from cosim/simulation files - Modernize typing: deprecated typing.List/Dict/Tuple to builtins - Fix unused args/loop vars, ambiguous unicode, perf anti-patterns - Delete legacy GUI files V1-V4 - Add V7 test suite, requirements files - All CI jobs pass: ruff (0 errors), py_compile, pytest (92/92), MCU tests (20/20), FPGA regression (25/25)
This commit is contained in:
@@ -91,9 +91,9 @@ z_edges = np.concatenate([z_centers - slot_L/2.0, z_centers + slot_L/2.0])
|
||||
# -------------------------
|
||||
# Mesh lines — EXPLICIT (no GetLine calls)
|
||||
# -------------------------
|
||||
x_lines = sorted(set([x_min, -t_metal, 0.0, a, a+t_metal, x_max] + list(x_edges)))
|
||||
x_lines = sorted({x_min, -t_metal, 0.0, a, a + t_metal, x_max, *list(x_edges)})
|
||||
y_lines = [y_min, 0.0, b, b+t_metal, y_max]
|
||||
z_lines = sorted(set([z_min, 0.0, L, z_max] + list(z_edges)))
|
||||
z_lines = sorted({z_min, 0.0, L, z_max, *list(z_edges)})
|
||||
|
||||
mesh.AddLine('x', x_lines)
|
||||
mesh.AddLine('y', y_lines)
|
||||
@@ -123,7 +123,7 @@ pec.AddBox([-t_metal,-t_metal,0],[a+t_metal,0, L]) # bottom
|
||||
pec.AddBox([-t_metal, b, 0], [a+t_metal,b+t_metal,L]) # top
|
||||
|
||||
# Slots = AIR boxes overriding the top metal
|
||||
for zc, xc in zip(z_centers, x_centers):
|
||||
for zc, xc in zip(z_centers, x_centers, strict=False):
|
||||
x1, x2 = xc - slot_w/2.0, xc + slot_w/2.0
|
||||
z1, z2 = zc - slot_L/2.0, zc + slot_L/2.0
|
||||
prim = air.AddBox([x1, b, z1], [x2, b+t_metal, z2])
|
||||
@@ -181,7 +181,7 @@ if simulate:
|
||||
# Post-processing: S-params & impedance
|
||||
# -------------------------
|
||||
freq = np.linspace(f_start, f_stop, 401)
|
||||
ports = [p for p in FDTD.ports] # Port 1 & Port 2 in creation order
|
||||
ports = list(FDTD.ports) # Port 1 & Port 2 in creation order
|
||||
for p in ports:
|
||||
p.CalcPort(Sim_Path, freq)
|
||||
|
||||
@@ -226,9 +226,6 @@ mismatch = 1.0 - np.abs(S11[idx_f0])**2 # (1 - |S11|^2)
|
||||
Gmax_lin = Dmax_lin * float(mismatch)
|
||||
Gmax_dBi = 10*np.log10(Gmax_lin)
|
||||
|
||||
print(f"Max directivity @ {f0/1e9:.3f} GHz: {10*np.log10(Dmax_lin):.2f} dBi")
|
||||
print(f"Mismatch term (1-|S11|^2) : {float(mismatch):.3f}")
|
||||
print(f"Estimated max realized gain : {Gmax_dBi:.2f} dBi")
|
||||
|
||||
# 3D normalized pattern
|
||||
E = np.squeeze(res.E_norm) # shape [f, th, ph] -> [th, ph]
|
||||
@@ -254,7 +251,7 @@ plt.figure(figsize=(8.4,2.8))
|
||||
plt.fill_between(
|
||||
[0, a], [0, 0], [L, L], color='#dddddd', alpha=0.5, step='pre', label='WG aperture (top)'
|
||||
)
|
||||
for zc, xc in zip(z_centers, x_centers):
|
||||
for zc, xc in zip(z_centers, x_centers, strict=False):
|
||||
plt.gca().add_patch(plt.Rectangle((xc - slot_w/2.0, zc - slot_L/2.0),
|
||||
slot_w, slot_L, fc='#3355ff', ec='k'))
|
||||
plt.xlim(-2, a + 2)
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
# openems_quartz_slotted_wg_10p5GHz.py
|
||||
# Slotted rectangular waveguide (quartz-filled, εr=3.8) tuned to 10.5 GHz.
|
||||
# Builds geometry, meshes (no GetLine calls), sweeps S-params/impedance over 9.5–11.5 GHz,
|
||||
# Builds geometry, meshes (no GetLine calls), sweeps S-params/impedance over 9.5-11.5 GHz,
|
||||
# computes 3D far-field, and reports estimated max realized gain.
|
||||
|
||||
import os
|
||||
@@ -15,14 +15,14 @@ from openEMS.physical_constants import C0
|
||||
try:
|
||||
from CSXCAD import ContinuousStructure, AppCSXCAD_BIN
|
||||
HAVE_APP = True
|
||||
except Exception:
|
||||
except ImportError:
|
||||
from CSXCAD import ContinuousStructure
|
||||
AppCSXCAD_BIN = None
|
||||
HAVE_APP = False
|
||||
|
||||
#Set PROFILE to "sanity" first; run and check [mesh] cells: stays reasonable.
|
||||
|
||||
#If it’s small, move to "balanced"; once happy, go "full".
|
||||
#If it's small, move to "balanced"; once happy, go "full".
|
||||
|
||||
#Toggle VIEW_GEOM=True if you want the 3D viewer (requires AppCSXCAD_BIN available).
|
||||
|
||||
@@ -123,9 +123,9 @@ x_edges = np.concatenate([x_centers - slot_w/2.0, x_centers + slot_w/2.0])
|
||||
z_edges = np.concatenate([z_centers - slot_L/2.0, z_centers + slot_L/2.0])
|
||||
|
||||
# Mesh lines: explicit (NO GetLine calls)
|
||||
x_lines = sorted(set([x_min, -t_metal, 0.0, a, a+t_metal, x_max] + list(x_edges)))
|
||||
x_lines = sorted({x_min, -t_metal, 0.0, a, a + t_metal, x_max, *list(x_edges)})
|
||||
y_lines = [y_min, 0.0, b, b+t_metal, y_max]
|
||||
z_lines = sorted(set([z_min, 0.0, guide_length_mm, z_max] + list(z_edges)))
|
||||
z_lines = sorted({z_min, 0.0, guide_length_mm, z_max, *list(z_edges)})
|
||||
|
||||
mesh.AddLine('x', x_lines)
|
||||
mesh.AddLine('y', y_lines)
|
||||
@@ -134,13 +134,10 @@ mesh.AddLine('z', z_lines)
|
||||
# Print complexity and rough memory (to help stay inside 16 GB)
|
||||
Nx, Ny, Nz = len(x_lines)-1, len(y_lines)-1, len(z_lines)-1
|
||||
Ncells = Nx*Ny*Nz
|
||||
print(f"[mesh] cells: {Nx} × {Ny} × {Nz} = {Ncells:,}")
|
||||
mem_fields_bytes = Ncells * 6 * 8 # rough ~ (Ex,Ey,Ez,Hx,Hy,Hz) doubles
|
||||
print(f"[mesh] rough field memory: ~{mem_fields_bytes/1e9:.2f} GB (solver overhead extra)")
|
||||
dx_min = min(np.diff(x_lines))
|
||||
dy_min = min(np.diff(y_lines))
|
||||
dz_min = min(np.diff(z_lines))
|
||||
print(f"[mesh] min steps (mm): dx={dx_min:.3f}, dy={dy_min:.3f}, dz={dz_min:.3f}")
|
||||
|
||||
# Optional smoothing to limit max cell size
|
||||
mesh.SmoothMeshLines('all', mesh_res, ratio=1.4)
|
||||
@@ -165,7 +162,7 @@ pec.AddBox(
|
||||
) # top (slots will pierce)
|
||||
|
||||
# Slots (AIR) overriding top metal
|
||||
for zc, xc in zip(z_centers, x_centers):
|
||||
for zc, xc in zip(z_centers, x_centers, strict=False):
|
||||
x1, x2 = xc - slot_w/2.0, xc + slot_w/2.0
|
||||
z1, z2 = zc - slot_L/2.0, zc + slot_L/2.0
|
||||
prim = airM.AddBox([x1, b, z1], [x2, b+t_metal, z2])
|
||||
@@ -215,7 +212,6 @@ if VIEW_GEOM and HAVE_APP and AppCSXCAD_BIN:
|
||||
t0 = time.time()
|
||||
FDTD.Run(Sim_Path, cleanup=True, verbose=2, numThreads=THREADS)
|
||||
t1 = time.time()
|
||||
print(f"[timing] FDTD solve elapsed: {t1 - t0:.2f} s")
|
||||
|
||||
# ... right before NF2FF (far-field):
|
||||
t2 = time.time()
|
||||
@@ -224,14 +220,12 @@ try:
|
||||
except AttributeError:
|
||||
res = FDTD.CalcNF2FF(nf2ff, Sim_Path, [f0], theta, phi) # noqa: F821
|
||||
t3 = time.time()
|
||||
print(f"[timing] NF2FF (far-field) elapsed: {t3 - t2:.2f} s")
|
||||
|
||||
# ... S-parameters postproc timing (optional):
|
||||
t4 = time.time()
|
||||
for p in ports: # noqa: F821
|
||||
p.CalcPort(Sim_Path, freq) # noqa: F821
|
||||
t5 = time.time()
|
||||
print(f"[timing] Port/S-params postproc elapsed: {t5 - t4:.2f} s")
|
||||
|
||||
|
||||
# =======
|
||||
@@ -240,11 +234,8 @@ print(f"[timing] Port/S-params postproc elapsed: {t5 - t4:.2f} s")
|
||||
if SIMULATE:
|
||||
FDTD.Run(Sim_Path, cleanup=True, verbose=2, numThreads=THREADS)
|
||||
|
||||
# ==========================
|
||||
# POST: S-PARAMS / IMPEDANCE
|
||||
# ==========================
|
||||
freq = np.linspace(f_start, f_stop, profiles[PROFILE]["freq_pts"])
|
||||
ports = [p for p in FDTD.ports] # Port 1 & 2 in creation order
|
||||
freq = np.linspace(f_start, f_stop, profiles[PROFILE]["freq_pts"])
|
||||
ports = list(FDTD.ports) # Port 1 & 2 in creation order
|
||||
for p in ports:
|
||||
p.CalcPort(Sim_Path, freq)
|
||||
|
||||
@@ -288,9 +279,6 @@ mismatch = 1.0 - np.abs(S11[idx_f0])**2
|
||||
Gmax_lin = Dmax_lin * float(mismatch)
|
||||
Gmax_dBi = 10*np.log10(Gmax_lin)
|
||||
|
||||
print(f"[far-field] Dmax @ {f0/1e9:.3f} GHz: {10*np.log10(Dmax_lin):.2f} dBi")
|
||||
print(f"[far-field] mismatch (1-|S11|^2): {float(mismatch):.3f}")
|
||||
print(f"[far-field] est. max realized gain: {Gmax_dBi:.2f} dBi")
|
||||
|
||||
# Normalized 3D pattern
|
||||
E = np.squeeze(res.E_norm) # [th, ph]
|
||||
@@ -324,7 +312,7 @@ plt.fill_between(
|
||||
step='pre',
|
||||
label='WG top aperture',
|
||||
)
|
||||
for zc, xc in zip(z_centers, x_centers):
|
||||
for zc, xc in zip(z_centers, x_centers, strict=False):
|
||||
plt.gca().add_patch(plt.Rectangle((xc - slot_w/2.0, zc - slot_L/2.0),
|
||||
slot_w, slot_L, fc='#3355ff', ec='k'))
|
||||
plt.xlim(-2, a + 2)
|
||||
|
||||
Reference in New Issue
Block a user