fedbiomed.common.environ

Module: fedbiomed.common.environ

All environment/configuration variables are provided by the Environ dictionary.

Environ is a singleton class, meaning that only an instance of Environ is available.

Descriptions of global/environment variables

Researcher Global Variables:

  • RESEARCHER_ID : id of the researcher
  • ID : equals to researcher id
  • TENSORBOARD_RESULTS_DIR : path for writing tensorboard log files
  • EXPERIMENTS_DIR : folder for saving experiments
  • MESSAGES_QUEUE_DIR : Path for writing queue files

Nodes Global Variables:

  • NODE_ID : id of the node
  • ID : equals to node id
  • MESSAGES_QUEUE_DIR : Path for queues
  • DB_PATH : TinyDB database path where datasets/training_plans/loading plans are saved
  • DEFAULT_TRAINING_PLANS_DIR : Path of directory for storing default training plans
  • TRAINING_PLANS_DIR : Path of directory for storing registered training plans
  • TRAINING_PLAN_APPROVAL : True if the node enables training plan approval
  • ALLOW_DEFAULT_TRAINING_PLANS : True if the node enables default training plans for training plan approval

Common Global Variables:

  • COMPONENT_TYPE : Node or Researcher
  • CONFIG_DIR : Configuration file path
  • VAR_DIR : Var directory of Fed-BioMed
  • CACHE_DIR : Cache directory of Fed-BioMed
  • TMP_DIR : Temporary directory
  • MQTT_BROKER : MQTT broker IP address
  • MQTT_BROKER_PORT : MQTT broker port
  • UPLOADS_URL : Upload URL for file repository

Classes

Environ

CLASS
Environ(component=None, rootdir=None)

Singleton class contains all variables for researcher or node

Parameters:

Name Type Description Default
component ComponentType

Type of the component either ComponentType.NODE or ComponentType.RESEARCHER

None
rootdir str

if not provided the directory is deduced from the package location (mainly used by the test files)

None

Raises:

Type Description
FedbiomedEnvironError

If component type is invalid

Source code in fedbiomed/common/environ.py
def __init__(self, component: ComponentType = None, rootdir: str = None):
    """Class constructor

    Args:
        component: Type of the component either `ComponentType.NODE` or `ComponentType.RESEARCHER`
        rootdir: if not provided the directory is deduced from the package location
            (mainly used by the test files)

    Raises:
        FedbiomedEnvironError: If component type is invalid
    """
    # dict with contains all configuration values
    self._values = {}

    if component == ComponentType.NODE or component == ComponentType.RESEARCHER:
        self._values['COMPONENT_TYPE'] = component
    else:
        _msg = ErrorNumbers.FB600.value + ": parameter should be of ComponentType"
        logger.critical(_msg)
        raise FedbiomedEnvironError(_msg)

    # common values for all components
    self._init_common(rootdir=rootdir)

    # specific configuration values
    if component == ComponentType.RESEARCHER:
        logger.setLevel("DEBUG")
        self._init_researcher()

    if component == ComponentType.NODE:
        logger.setLevel("INFO")
        self._init_node()

    # display some information on the present environment
    self.info()

Functions

info()

Print useful information at environment creation

Source code in fedbiomed/common/environ.py
def info(self):
    """Print useful information at environment creation"""

    logger.info("Component environment:")
    if self._values['COMPONENT_TYPE'] == ComponentType.RESEARCHER:
        logger.info("type = " + str(self._values['COMPONENT_TYPE']))

    if self._values['COMPONENT_TYPE'] == ComponentType.NODE:
        logger.info("type                = " + str(self._values['COMPONENT_TYPE']))
        logger.info("training_plan_approval      = " + str(self._values['TRAINING_PLAN_APPROVAL']))
        logger.info("allow_default_training_plans = " + str(self._values['ALLOW_DEFAULT_TRAINING_PLANS']))