General Factory and Builder Interface

Module Factory

class orchestrator.utils.module_factory.ModuleFactory(base_class)[source]

Bases: object

Factory for spawning concrete modules given a token.

This class is not instantiated directly, but through a concrete ModuleBuilder. A factory object is used for one module type, specified at instantiation, to avoid token confusion/conflicts. Specific module factories, used by module builders, are defined in each module.

Parameters:

base_class (ABC) – The ABC base class defining the module that this factory will spawn.

__init__(base_class)[source]
add_new_module(module_type, module)[source]

Add a concrete class to the factory.

Parameters:
  • module_type (str) – Token to specify the module. The convention is to use all caps.

  • module (type(self.base_class)) – Implementation of the base_class to be added to the factory.

Raises:

ValueError – If the module_type is already registered or the module is not a subclass of the base_class.

select_module(module_type)[source]

Select the type of module to be trained.

The specified module must have been added to the factory. Available modules can be listed with the list_modules() function.

Parameters:

module_type (str) – Token to specify the desired module.

Returns:

Requested concrete implementation of a module.

Return type:

Module

Raises:

ValueError – If the module_type has not been added to the factory.

list_modules()[source]

Print the currently available modules in the factory.

This method is primarily designed as a utility for interactive use of the orchestrator.

Module Builder

Concrete implementations of the ModuleBuilder can be found in the corresponding modules, such as the oracle_builder

Abstract Base Class

class orchestrator.utils.module_factory.ModuleBuilder(factory)[source]

Bases: Recorder, ABC

Abstract base class for module constructors.

This class sets the factory to be used for the builder. The default is to use the specific module_factory generated by specific modules. A user- defined ModuleFactory can optionally be supplied instead.

Parameters:

factory (ModuleFactory) – A module factory, typically defined in specific implementations.

__init__(factory)[source]

Constructor for the ModuleBuilder, sets the factory to build from.

Parameters:

factory (ModuleFactory) – A module factory, typically defined in specific implementations.

list_modules()[source]

Print the currently available modules in the builder.

This method is primarily designed as a utility for interactive use of the orchestrator.

abstract build()[source]

Return an instance of the specified module.

The build method signature is not specified by this class, as different modules require different parameters to instantiate.