base_algo_factory module¶
Abstract factory to create drivers.
- class gemseo.algos.base_algo_factory.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 _MODULE_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(name)[source]¶
Create a driver library from an algorithm name.
- Parameters:
name (str) – The name of an algorithm.
- Returns:
The driver.
- Raises:
ImportError – If the library is not available.
- Return type:
- execute(problem, algo_name, **options)[source]¶
Execute a problem with an algorithm.
- Parameters:
problem (BaseProblem) – The problem to execute.
algo_name (str) – The name of the algorithm.
**options (Any) – The options of the algorithm.
- Returns:
The optimization 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:
Examples using BaseAlgoFactory¶
Solve an ODE: the Van der Pol problem
Pareto front on Binh and Korn problem