Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2026-04-28 07:12:52

0001 """Registry for algorithm-specific optimization config models.
0002 
0003 Optimizers can register their Pydantic models keyed by algorithm name.
0004 Utilities can look up the model to parse `optimizer.parameters`.
0005 """
0006 from typing import Dict, Type, Optional
0007 from pydantic import BaseModel
0008 
0009 _algorithm_configs: Dict[str, Type[BaseModel]] = {}
0010 
0011 
0012 def register_algorithm_config(name: str, model: Type[BaseModel]) -> None:
0013     """Register a Pydantic model for an optimization algorithm.
0014 
0015     Args:
0016         name: Algorithm identifier (e.g., "nsga2", "mobo").
0017         model: Pydantic model class that validates algorithm-specific params.
0018     """
0019     _algorithm_configs[name.lower()] = model
0020 
0021 
0022 def get_algorithm_config_model(name: str) -> Optional[Type[BaseModel]]:
0023     """Retrieve a registered algorithm config model by name."""
0024     return _algorithm_configs.get(name.lower())