tud_lbm.config.array_expansion
Array parameter expansion for parallel simulations.
Detects array-valued parameters in configuration and expands them into
multiple SimulationConfig objects for parallel execution.
Example usage:
from config.adapter_toml import TomlAdapter
from config.array_expansion import detect_array_fields, expand_config
# Load config (arrays are preserved in raw form)
adapter = TomlAdapter()
raw_config = adapter.load("config_parallel.toml", allow_arrays=True)
# Detect which fields have arrays
array_fields = detect_array_fields(raw_config)
# Expand into multiple configs
configs = expand_config(raw_config)
# Returns: [SimulationConfig(...), SimulationConfig(...), ...]
Attributes
Classes
Metadata about which fields had arrays in the original config. |
Functions
|
Detect which fields in a config contain array values. |
|
Expand a config dict with array fields into multiple configs. |
|
Yield (index, parameters, config) tuples for each expansion. |
Module Contents
- class tud_lbm.config.array_expansion.ArrayParameterSet[source]
Metadata about which fields had arrays in the original config.
- tud_lbm.config.array_expansion.detect_array_fields(_config: tud_lbm.config.simulation_config.SimulationConfig) ArrayParameterSet | None[source]
Detect which fields in a config contain array values.
Returns None if no arrays are present.
- Parameters:
_config – A
SimulationConfig(should only contain scalars after full expansion; this is more for validation/inspection).- Returns:
ArrayParameterSetdescribing detected arrays, or None if no arrays were found.
- tud_lbm.config.array_expansion.expand_config(config_dict: dict[str, Any], *, allow_arrays: bool = True) tuple[list[tud_lbm.config.simulation_config.SimulationConfig], ArrayParameterSet | None][source]
Expand a config dict with array fields into multiple configs.
Performs Cartesian product expansion over:
Top-level
ARRAY_ELIGIBLE_FIELDSthat carry a list value.Sub-keys inside
NESTED_SWEEPABLE_FIELDSdicts (gravity_force,electric_force,wetting_config,hysteresis_config) that carry a list value.
- Parameters:
config_dict – Raw configuration dict (typically from TomlAdapter before SimulationConfig instantiation).
allow_arrays – If False, raise ValueError if arrays are found.
- Returns:
configs: List of
SimulationConfigobjects (one per combination). If no arrays found, list contains single config.metadata:
ArrayParameterSetif arrays were detected, else None.
- Return type:
(configs, metadata)where- Raises:
ValueError – If arrays are found but allow_arrays is False.
TypeError – If array values contain incompatible types.
- tud_lbm.config.array_expansion.enumerate_configs(config_dict: dict[str, Any], *, allow_arrays: bool = True) collections.abc.Iterator[tuple[int, dict[str, Any], tud_lbm.config.simulation_config.SimulationConfig]][source]
Yield (index, parameters, config) tuples for each expansion.
parameters uses dotted-path keys for nested fields (e.g.
"gravity_force.inclination_angle_deg").- Parameters:
config_dict – Raw configuration dict.
allow_arrays – If False, raise ValueError if arrays are found.
- Yields:
(index, parameters, config)tuples where –index: 0-based position in the expansion.
parameters: Dict of parameter names and values for this combo.
config: The
SimulationConfig.