Validation (cross-engine)¶
The :mod:groundfield.validation module contains
:func:compare_engines, the cross-engine consistency check that
underpins ADR-0001. Given two :class:Engine instances and a
:class:World, it solves both and reports a structured
:class:EngineComparison summarising the agreement of
cluster impedances, electrode currents and surface potentials.
This is the post-solve counterpart of :mod:groundfield.diagnostics
(pre-solve structural checks).
Frequency-order behaviour¶
Since 0.5.0 :class:Engine.frequencies is order-preserving. A
non-monotonic frequency list raises a dedicated
:class:EngineFrequencyOrderWarning (subclass of
:class:UserWarning) so a single
warnings.simplefilter("once", EngineFrequencyOrderWarning) will
collapse a compare_engines 4 × 4 matrix to one emission. The
opt-in :meth:Engine.with_frequencies(*, preserve_order=True)
constructor silences the warning explicitly.
API reference¶
validation ¶
Cross-engine comparison for self-validation.
This module provides :func:compare_engines — a small convenience
helper that runs the same :class:World through several
:class:Engine configurations and checks the consistency of the
results. It implements ADR-0001 (docs/adr/0001-two-layer-method.md):
two engines side by side, validating each other.
Usage
import groundfield as gf world = gf.create_world(soil=gf.HomogeneousSoil(resistivity=100.0)) gf.create_electrode(world, "rod", name="g1", ... position=(0, 0, 0.0), length=1.5) gf.create_source(world, attached_to="g1", magnitude=1.0) report = gf.compare_engines( ... world, ... engines={ ... "image": gf.create_engine(backend="image", segment_length=0.05), ... # "image_2layer": gf.create_engine(backend="image_2layer", ...), ... }, ... rel_tolerance=0.05, ... ) report.is_consistent True
EngineComparison
dataclass
¶
EngineComparison(
results: dict[str, "FieldResult"],
rel_tolerance: float,
cluster_impedance_table: dict[
str, dict[str, float]
] = dict(),
deviations: dict[str, float] = dict(),
is_consistent: bool = False,
notes: list[str] = list(),
)
Outcome of a cross-engine comparison.
Attributes:
| Name | Type | Description |
|---|---|---|
results |
dict[str, 'FieldResult']
|
Mapping |
rel_tolerance |
float
|
Relative tolerance the results were checked against. |
cluster_impedance_table |
dict[str, dict[str, float]]
|
|
deviations |
dict[str, float]
|
|
is_consistent |
bool
|
|
notes |
list[str]
|
Diagnostic strings (e.g. "stub backend", "frequency lists do not match"). |
summary ¶
Return a line-oriented textual summary.
Source code in src/groundfield/validation.py
compare_engines ¶
compare_engines(
world: "World",
engines: dict[str, "Engine"],
*,
rel_tolerance: float = 0.05,
sample_points: np.ndarray | None = None
) -> EngineComparison
Run world through every engine and compare the results.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
world
|
'World'
|
World to evaluate. Not modified by this function. |
required |
engines
|
dict[str, 'Engine']
|
Mapping |
required |
rel_tolerance
|
float
|
Maximum allowed relative deviation of the cluster impedances (default 5 %). The tolerance applies to every cluster present in the result. |
0.05
|
sample_points
|
ndarray | None
|
Optional. Array of shape |
None
|
Returns:
| Type | Description |
|---|---|
EngineComparison
|
Structured report (see :class: |
Notes
The check uses the real part of the cluster impedance at the
first frequency. Clusters with Σ I = 0 (purely passive
observers) have an undefined impedance and are skipped; the skip
is recorded in notes.
Source code in src/groundfield/validation.py
104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 | |