pySimBlocks.blocks.sources.function_source¶
- class pySimBlocks.blocks.sources.function_source.FunctionSource(name: str, function: Callable, output_keys: List[str] | None = None, sample_time: float | None = None)[source]¶
Bases:
BlockSourceUser-defined source block driven by a callable.
Computes outputs at each step by calling a user-provided function:
y = f(t, dt)
The function must accept exactly
(t, dt)as positional arguments and return adictmapping each key inoutput_keysto a scalar, 1D, or 2D array-like value. Output shapes are frozen after the first call and must remain constant throughout the simulation.- output_keys¶
List of output port names produced by the function.
- classmethod adapt_params(params: Dict[str, Any], params_dir: Path | None = None) Dict[str, Any][source]¶
Load a callable from
file_pathandfunction_nameYAML keys.If
functionis already present inparams, it is returned as-is. Otherwise, the callable is loaded dynamically from the specified file.- Parameters:
params – Raw parameter dict loaded from the YAML project file.
params_dir – Directory of the project file, for resolving relative paths. None if not applicable.
- Returns:
Parameter dict with
functionset to the loaded callable andfile_path/function_namekeys removed.- Raises:
ValueError – If only one of
file_pathorfunction_nameis provided.FileNotFoundError – If the function file does not exist.
AttributeError – If the named function is not found in the module.
TypeError – If the resolved attribute is not callable.