utils Module
General-purpose utilities for the simulation framework.
Overview
The utils subpackage provides Sex, Age, GameteLabel type aliases,
ParamDescriptor for the parameter registry, and helper functions.
Complete Module Reference
natal.utils
Utility modules — types, helpers, and parameter descriptors.
ParamDescriptor
dataclass
ParamDescriptor(domain: str, name: str, config_field: str | None, config_path: tuple[int, ...], dtype: type, bounds: tuple[float, float], doc: str = '', aliases: tuple[str, ...] = (), is_tensor: bool = False, is_0d: bool = False, is_array: bool = False, target: str = 'config')
A single estimable parameter mapping a user-facing name to a config field.
Attributes:
| Name | Type | Description |
|---|---|---|
domain |
str
|
Category this parameter belongs to (e.g. |
name |
str
|
User-facing name (e.g. |
config_field |
str | None
|
|
config_path |
tuple[int, ...]
|
Index tuple into the config array. Scalars use |
dtype |
type
|
Python type ( |
bounds |
tuple[float, float]
|
Plausible range |
doc |
str
|
One-line description. |
aliases |
tuple[str, ...]
|
Historical names mapped to this parameter. |
is_tensor |
bool
|
Multi-dimensional array (e.g. fitness tensors). |
is_0d |
bool
|
0-d ndarray, writable via |
is_array |
bool
|
1-D or 2-D slice, written by Configurator directly. |
target |
str
|
|
Sex
Bases: IntEnum
Sex enum backed by integers.
Using :class:IntEnum makes values directly usable as array indices and
compatible with Numba-friendly code.
resolve_sex_label
Convert sex label to PopulationConfig sex index.
Convention follows Sex enum and PopulationConfig:
- female/f -> 0
- male/m -> 1
Source code in src/natal/utils/helpers.py
validate_name
Validate if a name is valid.
A valid name consists of only letters, numbers, and underscores.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
name
|
str
|
The name to validate. |
required |
Returns:
| Name | Type | Description |
|---|---|---|
bool |
bool
|
True if the name is valid, False otherwise. |