def add_task(self, task_name, task_definition): """ Create a Federated ML task. :param credentials: json file containing credentials. :type credentials: `str` :param user: user name for authentication as task creator. :type user: `str` :param password: password for authentication as task creator. :type password: `str` :param task_name: name of the task (must be unique). :type task_name: `str` :param task_definition: definition of the task. :type task_definition: `dict` """ try: context = utils.platform(self.credentials, self.user, self.password) user = ffl.Factory.user(context) with user: result = user.create_task(task_name, ffl.Topology.star, task_definition) LOGGER.debug(result) LOGGER.info('Task ' + task_name + ' created.') return result except Exception as err: LOGGER.error('error: %s', err) raise err
def create_aggregator_communication(credentials, user, password, task_name, platform='cloud'): context = utils.platform(credentials, user, password, platform) user = ffl.Factory.user(context) with user: task_definition = json.loads(user.task_info(task_name)['definition']) return ffl.Factory.aggregator(context, task_name=task_name), task_definition
def registration(credentials, user, password, org): try: context = utils.platform(credentials) ffl_user = ffl.Factory.user(context) with ffl_user: ffl_user.create_user(user, password, org) except Exception as err: LOGGER.error('error: %s', err) raise err return
def login(credentials, user, password): try: context = utils.platform(credentials, user, password) ffl_user = ffl.Factory.user(context) with ffl_user: ffl_user.connect() except Exception as err: LOGGER.error('error: %s', err) raise err return True
def get_tasks(self): """ Get a list of all the tasks. :param credentials: json file containing credentials. :type credentials: `str` :return: list of all the tasks, each of which is a dictionary. :rtype: `list` """ try: context = utils.platform(self.credentials, self.user, self.password) user = ffl.Factory.user(context) with user: tasks = user.get_tasks() return tasks except Exception as err: LOGGER.error('error: %s', err) raise err
def get_user_assignments(self): """ Retrieve a list of all the tasks the user is participating in. :param credentials: json file containing credentials. :type credentials: `str` :param user: user name for authentication as task creator. :type user: `str` :param password: password for authentication as task creator. :type password: `str` :return: list of all the tasks the user is participating in. :rtype: `list` """ try: context = utils.platform(self.credentials, self.user, self.password) user = ffl.Factory.user(context) with user: return user.get_joined_tasks() except Exception as err: LOGGER.error('error: %s', err) raise err
def join_task(self, task_name): """ Join a Federated ML task. :param credentials: json file containing credentials. :type credentials: `str` :param user: user name for authentication as task creator. :type user: `str` :param password: password for authentication as task creator. :type password: `str` :param task_name: name of the task (must be unique). :type task_name: `str` """ try: context = utils.platform(self.credentials, self.user, self.password) user = ffl.Factory.user(context) with user: return user.join_task(task_name) LOGGER.debug('joined task') except Exception as err: LOGGER.error('error: %s', err) raise err