Review pass 4 (2026-05-12)¶
| Date | 2026-05-12 |
| Recorded in | the backlog section at the end of the changelog |
| Implemented in | 0.5.0 (2026-05-14) |
| Overview | Audit history · Changelog |
The fourth review pass recorded its findings in the backlog; the implementation shipped with 0.5.0 (regression tests tests/test_audit_pass4_fixes.py).
Where this text comes from
This page was moved verbatim from CHANGELOG.md when the release notes were
condensed in 2026.11.0 (source: commit 30a122d). Only the markup was adapted:
reST roles are rendered as code or math, relative links point to the current
pages, trailing whitespace is removed, and each block stands under a heading
that names where it was published.
Paths, test names and numbers are those of the time; the code has changed since.
From the backlog section of the changelog (“Backlog (2026-05-10 audit)”)¶
Fixed (pending implementation) — fourth 2026-05-12 review pass¶
Focus of the fourth pass: discriminated-union annotation on the
Sourcere-export, boundary-condition warning semantics on reverts to the default, missing top-level re-exports vs. the sister project's flatgi.*surface, mkdocs notebook nav gap.
groundfield.sources.Source = Union[CurrentSource, VoltageSource]lacks Pydantic'sDiscriminator("kind")annotation. Pydantic falls back to attempting validation against each member in declaration order during JSON deserialisation; a malformed payload withkind="voltage"but missingmagnitudesilently falls through toCurrentSourceand is rejected there with amagnitudeerror pointing at the wrong class. Mark the union asAnnotated[Union[CurrentSource, VoltageSource], Discriminator("kind")]so the error message matches the declaredkind.World.set_boundary_conditions(...)warns only on non- default kwargs. A user who first setset_boundary_conditions(far_field="neumann")and then callsset_boundary_conditions(far_field="dirichlet")to revert sees no warning, even though the latter call silently re-arms the v0.2.0 default. Either also warn on every transition that flips a previously non-default field back to its default (because the previous non-default state was never actually consumed) or document the asymmetry.World.add_source(source)does not validateattached_toorreturn_toagainst the world's electrodes/conductors. A typoattached_to="g_1"on a world with electrode"g1"is accepted; the bug surfaces at solve time as a zero-injection result with no diagnostic. Already flagged in pass 3 — pass 4 confirms the path is still unguarded.io.groundinsight.evaluate_spec,io.groundinsight.fit_quality_summaryandcoupling.LayeredEarthare publicly importable but missing fromgroundfield.__all__(__init__.py). Users who writegf.evaluate_spec(...)get anAttributeError; consistency with thegi.*flat surface (which re-exports analogous helpers) is broken. Promote all three to top-level re-exports.solver.engine.Engine.frequenciesis silently sorted on validation, but the public docstring does not mention the reorder. Notebooks that passfrequencies=[5000, 50]because they want the dominant 5 kHz tone first in the result get a silently-reordered result array — a real surprise when joining against an external DataFrame indexed by the input order. Either preserve order on construction or document the reorder.generators.measurement.MeasurementSetupConfig.buildsetssource.return_toto the auxiliary anchor, but does not guard against aTnNetworkConfig.sourcewhosereturn_towas already explicitly set by the user (e.g. for a multi-source AP 1 study with two parallel measurements). The user-suppliedreturn_tois silently overwritten. Either copy-on-write the source spec inside the generator (already on the pass 1 backlog as a deep-copy hint) or raise a clear error.postprocess.vector_fitting.vector_fitacceptsn_poles=0and returns a constant-only fit, butfit_to_sympythen produces an expression with nosdependence — the matchinggroundinsight.BusTypeis degenerate (Z(rho, f) = const, ignoring rho and f). Validaten_poles >= 1at function entry or document the degenerate case explicitly.io.csv.save_potential_path_csvwritesabs_phi = |phi_re + 1j*phi_im|under the columnabs_phi, but the correspondingsave_cluster_impedances_csvandsave_electrode_table_csvuse the suffix_abs(abs_Z, notZ_abs). Pick one convention and apply it acrossio.csvso DataFrames produced by the three writers can be joined on a uniform column-naming scheme.mkdocs.yml:90still referenceshttps://polyfill.io/v3/polyfill.min.js?features=es6— fourth audit pass in a row that flags it.groundmeasalready removed the URL; do the same here and ingroundinsight.mkdocs.ymlnav lists the eight curatedexamples/pages but not the 29 raw notebooks (notebooks/01..29). Mirror the same gap reported forgroundinsight: the feature work innotebooks/22_tier0_speedup.ipynb,notebooks/23_safety_touch_step.ipynb,notebooks/29_io_csv_vtk.ipynbetc. is invisible to the docs-site reader unless they go to the GitHub tree.generators/__init__.pydoes not re-export thesingle_rod_grounding(rng=...)factory'srngargument contract through a short doctest. The factory's RNG default isNone(no jitter), but the only example in the docs (docs/api/generators.md) shows the deterministic call — the stochastic Monte-Carlo path is not advertised even though the rest of the generator framework's pass-3 bug list listsrngas a missing parameter.
Docs (pending implementation) — fourth 2026-05-12 review pass¶
docs/api/sources.mdstill missing (third audit pass in a row). The pass-3 entry remains in the backlog above; pass 4 confirms the file has not been created. Without the page, the discriminated-union fix above has no natural home for its migration callout.docs/api/boundary.mdstill missing (third audit pass in a row). Pass 4 confirms the gap;BoundaryConditionsand the v0.2.0 no-op contract live only in source docstrings.docs/api/references.md,docs/api/validation.md,docs/api/world.mdare all still missing — pass 4 confirms three consecutive audits have flagged them.docs/concepts.mdhas no "Engine vs. World separation" section describing whyengine.solve(world)andworld.solve(engine)are duals, whyEnginecarriesfrequencieswhileWorldcarriesboundary, and how the v0.2.0BoundaryConditionsno-op interacts with the upcoming FEM backend. The split is a deliberate part of the architecture but the only place it is documented is theWorld.solvesource docstring.docs/api/diagnostics.mddoes not document thecheck_segment_resolution-budget threshold rationale. The thresholds (5 000 soft, 20 000 hard) appear in the source code and in this changelog but the rendered doc page lists them as bare numbers. Add a short "Why 5 000?" subsection that ties them to the \(O(N^2)\) memory / \(O(N^3)\) solve scaling of the integral backends.docs/engines/index.mdhas no capability matrix. The pass-2 entry already noted the gap; pass 4 confirms it. The matrix is the natural home for theinductance_model/earth_inductive_model/ distributed- conductor support tabulation referenced in the Roadmap.READMEPython-version badge is still3.12 | 3.13. Pass 4 confirms the gap from pass 2.CLAUDE.mdversion drift is still0.1.0while the package ships0.4.0. Pass 4 confirms the gap; thescripts/release.pyhook flagged in pass 2 has not landed.- No
docs/api/coupling/sommerfeld.mddedicated page. The Sommerfeld earth-return module (coupling/ sommerfeld_inductance.py) contains six public helpers and the Pollaczek-Wait kernel; users readingdocs/api/coupling.mdfind the heading but not the kernel signature. docs/api/postprocess.mdlacks a "Safety helpers" subsection distinct from "Current sharing" and "Plotting" — the EN 50522 lookup helper is the most safety-critical function in the package and currently shows up only via the autodoc.
Tests (pending implementation) — fourth 2026-05-12 review pass¶
- No test that
SourceJSON round-trip preserves the discriminator-vs-non-discriminator union behaviour. Once theDiscriminator("kind")annotation lands, pin the resulting error message for a malformed payload so the bug cannot regress silently. - No test that
World.set_boundary_conditions(...)warns on the revert-to-default path flagged above. Assertingpytest.warns(UserWarning, match="default")on the second call locks in whatever semantics the team picks. - No test that
vector_fit(n_poles=0)is rejected. A one-linepytest.raises(ValueError)regression once the guard lands. - No test for the
evaluate_spec/fit_quality_summaryre-export. Once the helpers are promoted to the top-level__all__, assert thatgf.evaluate_spec is groundfield.io.groundinsight.evaluate_specso a future silent rename cannot break the public alias. - No test for the
Engine.frequenciessort behaviour. Passfrequencies=[5000, 50], callengine.solve(world), and assert either (a) the returned cluster impedance is indexed in the input order or (b) aUserWarningwas raised at construction time. Either way the user gets determinism. - No regression test on
MeasurementSetupConfig.buildfor a pre-setsource.return_to. Build aTnNetworkConfigwhose source already hasreturn_to="explicit_aux", run the generator with aMeasurementSetupConfig, and assert either that the user-supplied value is honoured or that the override is reported via a clear log entry.
Roadmap candidates — fourth 2026-05-12 review pass¶
gf.create_source(world, ..., validate_attached_to=True)switch — opt-in (defaultTruefrom the next minor release, defaultFalseuntil then) for the validation contract flagged repeatedly in passes 1–4. Gives the existing test suite a deprecation window before the validator becomes mandatory.gf.SourceUnionwithDiscriminator("kind")— public type alias that ships the discriminated annotation alongside the legacySource = Union[...]. Lets type checkers in downstream notebooks pick up the fix without a major-version bump.generators.tn_network.TnNetworkConfig.measurement_array( ...)— convenience accessor that returns a per-house measurement-setup catalog (Analysis 1 only, Analysis 2 only, both) so the AP 1 sweep overn_efh ∈ {5, 10, 30, 80, 200}can be expressed as a single sweep axis rather than three nested ones.solver.engine.Engine.with_frequencies(freqs, preserve_order=True)— copy-on-write factory that produces a new engine without the silent sort surprise above. Closes the order-preservation gap until the validator change lands.scripts/release.py— syncCLAUDE.mdversion frompyproject.toml— same hook every pass-1..4 of the cross- repo audit has requested. A six-linere.subinscripts/release.pyends the drift permanently.io.csv.save_field_csv(result, path, *, extent, z=0.0, n=(120, 120), frequency_index=0)— companion to the existing VTK exporter that writes a long-format(x, y, frequency_Hz, phi_re, phi_im, abs_phi)CSV. Closes the symmetry gap: today CSV exports cover paths and electrode tables, VTK covers fields; the slice export is available only as VTK.
Released in 0.5.0 (2026-05-14)¶
Changed¶
Source = Union[CurrentSource, VoltageSource]is now a Pydantic discriminated union (sources.py). The annotation isAnnotated[Union[...], Discriminator("kind")], with a companionSourceAdapter = TypeAdapter(Source)for stand-alone source-dict validation. JSON / dict round-trips now report errors against the selected sub-class (CurrentSource/VoltageSource) instead of dumping the whole union's validator chain — fourth 2026-05-12 audit pass closure. The user-facing constructor signatures are unchanged; only the error messages and the publicSourceannotation differ.Engine.frequenciesis documented and validated as order-preserving (solver/engine.py). A newfield_validator("frequencies")rejects empty or non-positive inputs and emits aUserWarningwhen the list is not strictly increasing — but the order is preserved inEngine.frequenciesand downstream inFieldResult.frequencies. The newEngine.with_frequencies(*freqs, preserve_order=True)constructor is the explicit opt-in for sweeps that intentionally iterate non-monotonically (e.g.[5000, 50]); it silences the warning and returns a freshEnginewithout mutating the receiver. Closes the fourth 2026-05-12 review pass "silent sort" finding.TnNetworkConfig.source_return_toexposes an explicit override for the source's return path (generators/tn_network.py). When set, it takes precedence over the auxiliary electrode derived fromcfg.measurement; when both are present and differ,TnNetworkGenerator.buildemits aUserWarningthat makes the precedence explicit. Previously the measurement setup silently overwrote any caller-side intent forreturn_to.
Fixed¶
World.set_boundary_conditionsnow warns on revert as well as on set (world.py). Setting a non-default value already emitted aUserWarning(v0.2.0); the same call signature now also warns when a previously-set non-default value is reverted back to the default. The previous non-default value was never consumed by any backend, so the revert is a silent no-op — the new warning makes that visible (fourth 2026-05-12 audit pass).vector_fit(n_poles=0)is rejected at the API boundary with a detailedValueError(postprocess/vector_fitting.py). A zero-pole fit produces ans-free SymPy expression whosegroundinsight.BusType.impedance_formulaconsumer cannot recover the frequency dependence; the failure mode was silent before.fit_to_sympyadditionally guards against programmatically constructedVectorFitResultobjects whose resulting expression iss-free, emitting aUserWarningwith the same diagnostic.mkdocs.ymlno longer referencespolyfill.io. The CDN's ownership change in early 2024 (malicious payloads injected via the original domain) made the URL unsafe to ship in the docs build. Modern MathJax 3 /tex-mml-chtmldoes not require an ES6 polyfill for any browser the docs target. Four audit passes in a row flagged this URL — fixed in this release.
Added¶
- Top-level re-exports
evaluate_spec,fit_quality_summaryandLayeredEarth(__init__.py). The three helpers were publicly importable from their sub-modules but were missing from the top-level surface and from__all__. They are now reachable asgf.evaluate_spec/gf.fit_quality_summary/gf.LayeredEarthand listed in__all__. - Frozen CSV column-name tuples in
groundfield.io.csv(POTENTIAL_PATH_COLUMNS,ELECTRODE_TABLE_REQUIRED_COLUMNS,CLUSTER_IMPEDANCE_REQUIRED_COLUMNS). The convention is<symbol>_re/<symbol>_im/abs_<symbol>per physical quantity (phifor potentials,Ifor currents,Zfor impedances) — magnitude columns therefore differ per writer by design. Locking the tuples makes accidental renames test-detectable and documents the join-rename requirement.
Tests¶
tests/test_audit_pass4_fixes.py— eight regression tests mapped 1:1 to the user-visible bullets above: discriminator round-trip, discriminator error path, boundary revert warning,Engineorder-preserving validator + warning, opt-inwith_frequenciessilencer,TnNetworkConfig.source_return_toprecedence with warning,vector_fit(n_poles=0)rejection, CSV column-schema lock, top-level re-export presence, andmkdocs.ymlpolyfill cleanup.
Docs¶
notebooks/30_audit_pass4_fixes.ipynb— narrative walk-through of all behaviour changes captured in this block. The notebook is short and per-fix: every cell illustrates one change in isolation so the diff is easy to verify when closing the audit.CLAUDE.md— added a "Version (do not hard-code in this file)" section that points atpyproject.toml/groundfield.__version__/CITATION.cffas the canonical sources. Closes the four-passes-in-a-row CLAUDE.md version-drift finding from the cross-cutting recommendations.mkdocs.yml— inline comment explaining whypolyfill.iowas removed.