gemseo.algos.base_algo_factory module#
Abstract factory to create libraries of algorithms.
- class BaseAlgoFactory(use_cache=False)[source]#
Bases:
object
A base class for creating factories for objects of kind
AlgoLib
.This factory can create objects from a base class or any of its subclasses that can be imported from the given module sources. The base class and the module sources shall be defined as class attributes of the factory class, for instance:
class AFactory(BaseAlgoFactory): _CLASS = ABaseClass _PACKAGE_NAMES = ( "first.module.fully.qualified.name", "second.module.fully.qualified.name", )
A factory instance can use a cache for the objects it creates, this cache is only used by one factory instance and is not shared with another instance. The cache is activated by passing
use_cache = True
to the constructor. When the cache is activated, a factory will return an object already created when possible and will create a new object otherwise.- Parameters:
use_cache (bool) --
Whether to cache the created objects.
By default it is set to False.
- create(algo_name)[source]#
Create an algorithm library from an algorithm name.
- Parameters:
algo_name (str) -- The name of an algorithm.
- Returns:
The algorithm library.
- Raises:
ImportError -- If the algorithm is not available.
- Return type:
- execute(problem, settings_model=None, **settings)[source]#
Execute a problem with an algorithm.
- Parameters:
problem (BaseProblem) -- The problem to execute.
settings_model (BaseAlgorithmSettings | None) -- The algorithm settings as a Pydantic model. If
None
, use**settings
.**settings (Any) -- The algorithm settings. These arguments are ignored when
settings_model
is notNone
.
- Returns:
The result.
- Return type:
- get_class(name)[source]#
Return a class from its name.
- Parameters:
name (str) -- The name of the class.
- Returns:
The class.
- Raises:
ImportError -- If the class is not available.
- Return type: