Utilities¶
groundfield.utils holds the helpers that the other subpackages share:
the logger names, the "did you mean …?" suggestions in error messages,
and the two warning helpers of the public API — one for deprecated names
and one for settings that no backend reads. Read this page when you
configure logging or want to know where a warning comes from. What each
warning means and what to do about it is on
Warnings and errors; the deprecated names and their
replacements are listed on Deprecations.
| Helper | Purpose |
|---|---|
get_logger, configure |
loggers below groundfield; a default stream handler |
suggest, did_you_mean |
closest valid names for an unknown name |
warn_deprecated, REMOVAL_VERSION, DEPRECATED_SINCE |
the deprecation policy of the calendar releases |
warn_inert, InertConfigurationWarning |
a setting is stored, but no backend reads it |
Logging¶
Every module logs through get_logger(__name__), so all messages sit
below the logger groundfield. The library installs no handler;
configure(level) adds one stream handler to groundfield when it has
none and sets its level. Any standard logging set-up works as well,
for example logging.getLogger("groundfield.solver").setLevel(logging.DEBUG).
Name suggestions¶
The factories reject an unknown name with the closest valid one:
import groundfield as gf
from groundfield.utils import did_you_mean, suggest
world = gf.create_world(soil=gf.HomogeneousSoil(rho=100.0))
try:
gf.create_electrode(world, "rnig", name="a", center=(0.0, 0.0, 0.5), radius=1.0)
except ValueError as error:
message = str(error) # "Unknown electrode kind 'rnig'. Did you mean 'ring'? ..."
assert "Did you mean 'ring'?" in message
assert suggest("rnig", ["rod", "ring", "strip", "star"]) == ["ring"]
assert did_you_mean("rnig", ["rod", "ring"]) == " Did you mean 'ring'?"
Deprecation policy¶
A deprecated name keeps working, emits a DeprecationWarning that names
its replacement and is removed no earlier than two releases and six
months after the announcement: for the names deprecated in
DEPRECATED_SINCE (2026.11) that is REMOVAL_VERSION (2027.5) at the
earliest. Both helpers point the warning at the first caller outside
groundfield and pydantic, the line the user can change, and stay silent
when groundfield's own code is the caller.
API reference¶
utils ¶
Helper utilities.
Cross-cutting helpers used by several subpackages:
- structured logging configuration (
get_logger(),configure()), - name suggestions for error messages (
suggest(),did_you_mean()), - warnings of the public API: deprecated names (
warn_deprecated(), removal no earlier thanREMOVAL_VERSION) and settings that no backend reads (warn_inert(),InertConfigurationWarning).
DEPRECATED_SINCE
module-attribute
¶
First calendar-versioned release; the deprecations listed in its changelog start here.
REMOVAL_VERSION
module-attribute
¶
Earliest release that removes the names deprecated in DEPRECATED_SINCE.
Two releases and six months later.
InertConfigurationWarning ¶
Bases: UserWarning
A public setting is stored, but no backend reads it.
Examples are a non-default BoundaryConditions
field or a soil relative_permittivity: every backend uses the
quasi-static conduction-current formulation with remote-earth
boundary conditions, so these values do not change any result.
Filter it like any warning category, e.g.
warnings.simplefilter("ignore", InertConfigurationWarning).
configure ¶
Install a simple default logging configuration.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
level
|
int
|
Log level for the root logger |
INFO
|
Source code in src/groundfield/utils/logging.py
did_you_mean ¶
Return a " Did you mean 'x'?" sentence, or "".
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
name
|
str
|
See |
required |
candidates
|
str
|
See |
required |
n
|
str
|
See |
required |
cutoff
|
str
|
See |
required |
Returns:
| Type | Description |
|---|---|
str
|
A sentence with a leading space, ready to be appended to an error message, or the empty string when nothing is close. |
Examples:
Source code in src/groundfield/utils/suggest.py
get_logger ¶
Return a logger with the consistent naming scheme.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
name
|
str
|
Usually |
required |
Returns:
| Type | Description |
|---|---|
Logger
|
The standard-library logger of that name. |
Source code in src/groundfield/utils/logging.py
warn_deprecated ¶
Emit a DeprecationWarning for a renamed or replaced name.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
old
|
str
|
What the caller used, e.g. |
required |
new
|
str
|
Its replacement, e.g. |
required |
Notes
The message states the replacement and the earliest removal
release (REMOVAL_VERSION). See the module docstring for who
is warned.
Source code in src/groundfield/utils/deprecation.py
warn_inert ¶
Emit an InertConfigurationWarning with message.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
message
|
str
|
Complete sentence(s) naming the setting, its value and why it has no effect. |
required |
Source code in src/groundfield/utils/deprecation.py
groundfield.utils.suggest is also the name of the submodule that
defines the function, so the function is rendered here separately:
suggest ¶
Return the candidates closest to name, best match first.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
name
|
str
|
The name that was not found. |
required |
candidates
|
Iterable[str]
|
Valid names. Duplicates are ignored; the original spelling of a candidate is returned. |
required |
n
|
int
|
Maximum number of suggestions. |
3
|
cutoff
|
float
|
Similarity threshold in |
0.6
|
Returns:
| Type | Description |
|---|---|
list of str
|
Up to |