nirs4all.controllers.models.components.identifier_generator module

Model Identifier Generator - Generate consistent model identifiers

This component centralizes all model naming and identification logic. Extracted from launch_training() lines 329-345 to improve maintainability.

Generates:
  • classname: from model config or instance.__class__.__name__

  • name: custom name from config or classname

  • model_id: name + operation counter (unique for run)

  • display_name: model_id with fold suffix if applicable

class nirs4all.controllers.models.components.identifier_generator.ModelIdentifierGenerator(helper=None)[source]

Bases: object

Generates consistent model identifiers for training and persistence.

This component extracts and centralizes all the naming logic that was previously scattered in launch_training().

Example

>>> generator = ModelIdentifierGenerator()
>>> identifiers = generator.generate(
...     model_config={'name': 'MyPLS', 'class': 'sklearn.cross_decomposition.PLSRegression'},
...     runner=runner,
...     context={'step_id': 5},
...     fold_idx=0
... )
>>> identifiers.model_id
'MyPLS_10'
>>> identifiers.display_name
'MyPLS_10_fold0'
extract_classname_from_config(model_config: Dict[str, Any]) str[source]

Extract classname from model configuration.

Based on the model declared in config or instance.__class__.__name__ or function name.

Parameters:

model_config – Model configuration dictionary.

Returns:

Class name of the model.

Return type:

str

extract_core_name(model_config: Dict[str, Any]) str[source]

Extract core name from model configuration.

User-provided name or class name. This is the base name provided by the user or derived from the class.

Parameters:

model_config – Model configuration dictionary.

Returns:

Core name extracted from config.

Return type:

str

generate(model_config: Dict[str, Any], runner: PipelineRunner, context: ExecutionContext, fold_idx: int | None = None) ModelIdentifiers[source]

Generate all model identifiers from configuration and context.

Parameters:
  • model_config – Model configuration dictionary

  • runner – Pipeline runner for operation counter

  • context – Execution context with step_number

  • fold_idx – Optional fold index for cross-validation

Returns:

Container with all generated identifiers

Return type:

ModelIdentifiers

generate_binary_key(model_id: str, fold_idx: int | None = None) str[source]

Generate the binary storage key for a model.

Parameters:
  • model_id – Base model identifier (e.g., “MyModel_10”)

  • fold_idx – Optional fold index

Returns:

Binary key string (e.g., “MyModel_10” or “MyModel_10_fold0”)

class nirs4all.controllers.models.components.identifier_generator.ModelIdentifiers(classname: str, name: str, model_id: str, display_name: str, operation_counter: int, step_id: int, fold_idx: int | None)[source]

Bases: object

Container for all model identifiers.

classname: str
display_name: str
fold_idx: int | None
model_id: str
name: str
operation_counter: int
step_id: int