Skip to content

Commit

Permalink
Update definitions in preparation for restructured configuration objects
Browse files Browse the repository at this point in the history
  • Loading branch information
JMGaljaard committed Sep 4, 2022
1 parent a0f06da commit 8d36d16
Show file tree
Hide file tree
Showing 3 changed files with 46 additions and 1 deletion.
6 changes: 6 additions & 0 deletions fltk/util/config/definitions/__init__.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,8 @@
"""
Module for declaring types and definitions, including helper functions that allow to retrieve
object (types) from a definition.
"""

from .data_sampler import DataSampler
from .optim import Optimizations
from .aggregate import Aggregations
Expand All @@ -7,3 +12,4 @@
from .optim import Optimizations
from .experiment_type import ExperimentType
from .loss import Loss, get_loss_function
from .orchestrator import OrchestratorType, get_orchestrator
2 changes: 1 addition & 1 deletion fltk/util/config/definitions/data_sampler.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,4 +10,4 @@ class DataSampler(Enum):
limit_labels_q = "limit labels q"
emd_sampler = 'emd sampler'
limit_labels_flex = "limit labels flex"
n_labels = "n labels"
n_labels = "n labels"
39 changes: 39 additions & 0 deletions fltk/util/config/definitions/orchestrator.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
from __future__ import annotations
from enum import unique, Enum
from pathlib import Path
from typing import Type

from fltk.core.distributed import BatchOrchestrator, SimulatedOrchestrator, Orchestrator

from typing import TYPE_CHECKING

from fltk.util.task.generator import ArrivalGenerator

if TYPE_CHECKING:
from fltk.util.cluster import ClusterManager
from fltk.util.config import DistributedConfig


@unique
class OrchestratorType(Enum):
BATCH = 'batch'
SIMULATED = 'simulated'


def get_orchestrator(config: DistributedConfig, cluster_manager: ClusterManager, arrival_generator: ArrivalGenerator) -> Orchestrator:
"""
Retrieve Orchestrator type given a Distributed (experiment) configuration. This allows for defining the
type of experiment (Batch or Simulated arrivals) once, and letting the Orchestrator implementation
make sure that the tasks are scheduled correctly.
@param config: Distributed (cluster) configuration object for experiments.
@type config: DistributedConfig
@return: Type of Orchestrator as requested by configuration object.
@rtype: Type[Orchestrator]
"""
__lookup = {
OrchestratorType.BATCH: BatchOrchestrator,
OrchestratorType.SIMULATED: SimulatedOrchestrator
}

orchestrator_type = __lookup.get(config.cluster_config.orchestrator.orchestrator_type, None)
return orchestrator_type(cluster_manager, arrival_generator, config)

0 comments on commit 8d36d16

Please sign in to comment.