gemseo / algos

Hide inherited members

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.

clear_lib_cache()[source]

Clear the library cache.

Return type:

None

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:

DriverLibrary

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:

OptimizationResult

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:

type

get_library_name(name)[source]

Return the name of the library related to the name of a class.

Parameters:

name (str) – The name of the class.

Returns:

The name of the library.

Return type:

str

is_available(name)[source]

Check the availability of a library name or algorithm name.

Parameters:

name (str) – The name of the library name or algorithm name.

Returns:

Whether the library or algorithm is available.

Return type:

bool

property algo_names_to_libraries: dict[str, str]

The mapping from the algorithm names to the libraries.

property algorithms: list[str]

The available algorithms names.

property libraries: list[str]

List the available library names in the present configuration.

Returns:

The names of the available libraries.

Examples using BaseAlgoFactory

Analytical test case # 2

Analytical test case # 2

Analytical test case # 3

Analytical test case # 3

Solve an ODE: the Van der Pol problem

Solve an ODE: the Van der Pol problem

Optimal LHS vs LHS

Optimal LHS vs LHS

Pareto front on Binh and Korn problem

Pareto front on Binh and Korn problem