Module that initialize singleton environ object for the researcher component
[Environ
][fedbiomed.common.environ] will be initialized after the object environ
is imported from fedbiomed.researcher.environ
Typical use:
from fedbiomed.researcher.environ import environ
print(environ['RESEARCHER_ID'])
Descriptions of 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
- SERVER_HOST : Hostname or IP of gRPC server
- SERVER_PORT : TCP port of gRPC server
- SERVER_SSL_KEY : Path to certificate private key file for gRPC
- SERVER_SSL_CERT : Path to certificate PEM file for gRPC
Attributes
environ module-attribute
environ = ResearcherEnviron()
Classes
ResearcherEnviron
ResearcherEnviron(root_dir=None)
Bases: Environ
Source code in fedbiomed/researcher/environ.py
def __init__(self, root_dir: str = None):
"""Constructs ResearcherEnviron object """
super().__init__(root_dir=root_dir)
self._config = ResearcherConfig(root_dir)
logger.setLevel("DEBUG")
# Set component type
self._values["COMPONENT_TYPE"] = ComponentType.RESEARCHER
# Setup environment variables
self.set_environment()
Functions
info
info()
Print useful information at environment creation
Source code in fedbiomed/researcher/environ.py
def info(self):
"""Print useful information at environment creation"""
logger.info("Component environment:")
logger.info("type = " + str(self._values['COMPONENT_TYPE']))
set_environment
set_environment()
Source code in fedbiomed/researcher/environ.py
def set_environment(self):
super().set_environment()
# we may remove RESEARCHER_ID in the future (to simplify the code)
# and use ID instead
researcher_id = self._config.get('default', 'id')
self._values['RESEARCHER_ID'] = os.getenv('RESEARCHER_ID', researcher_id)
self._values['ID'] = self._values['RESEARCHER_ID']
# more directories
self._values['TENSORBOARD_RESULTS_DIR'] = os.path.join(self._values['ROOT_DIR'], TENSORBOARD_FOLDER_NAME)
self._values['EXPERIMENTS_DIR'] = os.path.join(self._values['VAR_DIR'], "experiments")
self._values['MESSAGES_QUEUE_DIR'] = os.path.join(self._values['VAR_DIR'], 'queue_messages')
self._values["SERVER_HOST"] = os.getenv('RESEARCHER_SERVER_HOST',
self._config.get('server', 'host'))
self._values["SERVER_PORT"] = os.getenv('RESEARCHER_SERVER_PORT',
self._config.get('server', 'port'))
self._values["FBM_CERTIFICATE_KEY"] = os.path.join(
self._values["CONFIG_DIR"], self._config.get('certificate', 'private_key')
)
self._values["FBM_CERTIFICATE_PEM"] = os.path.join(
self._values["CONFIG_DIR"], self._config.get('certificate', 'public_key')
)
for _key in 'TENSORBOARD_RESULTS_DIR', 'EXPERIMENTS_DIR':
dir = self._values[_key]
if not os.path.isdir(dir):
try:
os.makedirs(dir)
except FileExistsError as exp:
raise FedbiomedEnvironError(
f"{ErrorNumbers.FB600.value}: path already exists but is not a "
f"directory {dir}"
) from exp
except OSError as exp:
raise FedbiomedEnvironError(
f"{ErrorNumbers.FB600.value}: cannot create environment subtree in: {dir}"
) from exp