fastoad.module_management.service_registry module
Module for registering services.
- class fastoad.module_management.service_registry.RegisterService(service_id: str, provider_id: str, desc=None)[source]
Bases:
object
Decorator class that allows to register services and associated providers.
This class also provides class methods for getting service providers and information about them.
The basic registering of a class is done with:
@RegisterService("my.service.id", "id.of.the.provider") class MyService: ...
A child of this class may define a particular base class or interface that should be parent to all registered service providers.
The definition of the base class is done when subclassing, e.g.:
class RegisterSomeService( RegisterService, base_class=ISomeService): "Allows to register classes that implement interface ISomeService."
- Parameters:
service_id – the identifier of the provided service
provider_id – the identifier of the service provider to register
desc – description of the service provider. If not provided, the docstring of decorated class will be used.
- get_properties(service_class: Type[T]) dict [source]
Override this method to modify the properties that will be associated to the registered service provider.
This basic version ensures the associated description property is the one provided when instantiating this decorator class, if it is provided. Otherwise, it will be the docstring of the decorated class.
- Parameters:
service_class – the class that will be registered as service provider
- Returns:
the dictionary of properties that will be associated to the registered service provider
- classmethod explore_folder(folder_path: str)[source]
Explores provided folder and looks for service providers to register.
- Parameters:
folder_path –
- classmethod get_provider_ids(service_id: str) List[str] [source]
- Parameters:
service_id –
- Returns:
the list of identifiers of providers of the service.
- classmethod get_provider(service_provider_id: str, options: dict = None) Any [source]
Instantiates the desired service provider.
- Parameters:
service_provider_id – identifier of a registered service provider
options – options that should be associated to the created instance
- Returns:
the created instance
- classmethod get_provider_description(instance_or_id: str | T) str [source]
- Parameters:
instance_or_id – an identifier or an instance of a registered service provider
- Returns:
the description associated to given instance or identifier
- classmethod get_provider_domain(instance_or_id: str | System) ModelDomain [source]
- Parameters:
instance_or_id – an identifier or an instance of a registered service provider
- Returns:
the model domain associated to given instance or identifier
- class fastoad.module_management.service_registry.RegisterSpecializedService(provider_id: str, desc=None, domain: ModelDomain = None, options: dict = None)[source]
Bases:
RegisterService
Base class for decorator classes that allow to register a particular service.
The service may be associated to a base class (or interface). The registered class must inherit from this base class.
Unlike
RegisterService
, this class has to be subclassed, because the service identifier is defined when subclassing.The definition of the base class is done by subclassing, e.g.:
class RegisterSomeService( RegisterSpecializedService, base_class=ISomeService, service_id="my.particularservice"): "Allows to register classes that implement interface ISomeService."
Then basic registering of a class is done with:
@RegisterSomeService("my.particularservice.provider") class ParticularService(ISomeService): ...
- Parameters:
provider_id – the identifier of the service provider to register
desc – description of the service. If not provided, the docstring will be used.
domain – a category for the registered service provider
options – a dictionary of options that can be associated to the service provider
- get_properties(service_class: Type[T]) dict [source]
Override this method to modify the properties that will be associated to the registered service provider.
This basic version ensures the associated description property is the one provided when instantiating this decorator class, if it is provided. Otherwise, it will be the docstring of the decorated class.
- Parameters:
service_class – the class that will be registered as service provider
- Returns:
the dictionary of properties that will be associated to the registered service provider
- class fastoad.module_management.service_registry.RegisterPropulsion(provider_id: str, desc=None, domain: ModelDomain = None, options: dict = None)[source]
Bases:
_RegisterSpecializedOpenMDAOService
Decorator class for registering an OpenMDAO wrapper of a propulsion-dedicated model.
- Parameters:
provider_id – the identifier of the service provider to register
desc – description of the service. If not provided, the docstring will be used.
domain – a category for the registered service provider
options – a dictionary of options that can be associated to the service provider
- class fastoad.module_management.service_registry.RegisterOpenMDAOSystem(provider_id: str, desc=None, domain: ModelDomain = None, options: dict = None)[source]
Bases:
_RegisterSpecializedOpenMDAOService
Decorator class for registering an OpenMDAO system for use in FAST-OAD configuration.
If a variable_descriptions.txt file is in the same folder as the class module, its content is loaded (once, even if several classes are registered at the same level).
- Parameters:
provider_id – the identifier of the service provider to register
desc – description of the service. If not provided, the docstring will be used.
domain – a category for the registered service provider
options – a dictionary of options that can be associated to the service provider
- class fastoad.module_management.service_registry.RegisterSubmodel(service_id: str, provider_id: str, desc=None, options: dict = None)[source]
Bases:
_RegisterOpenMDAOService
Decorator class that allows to submodels.
Submodels are OpenMDAO systems that fulfill a requirement (service id) in a FAST-OAD module.
active_models
defines the submodel to be used for any service identifier it has as key. Seeget_submodel()
for more details.The registering of a class is done with:
@RegisterSubmodel("my.service", "id.of.the.provider") class MyService: ...
Then the submodel can be instantiated and used with:
submodel_instance = RegisterSubmodel.get_submodel("my.service") some_model.add_subsystem("my_submodel", submodel_instance, promotes=["*"]) ...
- Parameters:
service_id – the identifier of the provided service
provider_id – the identifier of the service provider to register
desc – description of the service. If not provided, the docstring will be used.
options – a dictionary of options that will be defaults when instantiating the system
- active_models: Dict[str, str | None] = {}
Dictionary (key = service id, value=provider id) that defines submodels to be used for associated services.
- classmethod get_submodel(service_id: str, options: dict = None)[source]
Provides a submodel for the given service identifier.
- If
active_models
has service_id as key: if the associated value is a non-empty string, a submodel will be instantiated with this string as submodel identifier. If the submodel identifier matches nothing, an error will be raised.
if the associated value is None, an empty submodel (om.Group()) will be instantiated. You may see it as a way to deactivate a particular submodel.
- If
active_models
has service_id has NOT as key: if no submodel is declared for this service_id, an error will be raised.
if one and only one submodel is declared for this service_id, it will be instantiated.
if several submodels are declared for this service_id, an error will be raised.
If an actual (not empty) submodel is defined, provided options will be used.
- Parameters:
service_id –
options –
- Returns:
the instantiated submodel
- If