コード例 #1
0
def run(credentials, user, password, task_name):
    """
    Run the algorithm for the given task as participant.
    :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: training task to be performed
    :type task_name: `str`
    """
    context = fflapi.Context.from_credentials_file(credentials, user, password)
    user = fflapi.User(context, task_name=task_name)

    with user:
        import json
        task_definition = json.loads(user.task_info()['definition'])

    participant = fflapi.Participant(context,
                                     task_name=task_name,
                                     download_models=False)

    import sys
    sys.path.append("../fl_algorithm")

    alg_class = get_class(task_definition['participant'])
    algorithm = alg_class(task_definition, participant)

    try:
        algorithm.start()
    except Exception as e:
        LOGGER.error(str(e))

    LOGGER.info('Completed training')
コード例 #2
0
 def test_get_tasks(self):
     context = fflapi.Context.from_credentials_file(self.credentials)
     user = fflapi.User(context)
     with user:
         result = user.get_tasks()
         for r in result:
             LOGGER.info(f"{r['task_name']}")
コード例 #3
0
def get_tasks(credentials):
    """
    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`

    """
    context = fflapi.Context.from_credentials_file(credentials)
    with fflapi.User(context) as ffl:
        tasks = ffl.get_tasks()

    return tasks
コード例 #4
0
def get_user_assignments(credentials, user, password):
    """
    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`
    """
    context = fflapi.Context.from_credentials_file(credentials, user, password)
    user = fflapi.User(context)

    with user:
        return user.messenger.user_assignments()
コード例 #5
0
def join_task(credentials, user, password, 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`
    """
    context = fflapi.Context.from_credentials_file(credentials, user, password)
    user = fflapi.User(context, task_name=task_name)

    with user:
        user.join_task()
コード例 #6
0
def run(credentials, user, password, task_name):
    """
    Run the algorithm for the given task as aggregator.
    :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: training task to be performed
    :type task_name: `str`
    """
    context = fflapi.Context.from_credentials_file(credentials, user, password)
    user = fflapi.User(context, task_name=task_name)

    with user:
        import json
        task_definition = json.loads(user.task_info()['definition'])

    aggregator = fflapi.Aggregator(context,
                                   task_name=task_name,
                                   download_models=False)

    import sys
    sys.path.append("../fl_algorithm")

    alg_class = get_class(task_definition['aggregator'])
    algorithm = alg_class(task_definition, aggregator)
    model = None

    try:
        model = algorithm.start()
    except Exception as e:
        traceback.print_exc()
        LOGGER.error(str(e))

    LOGGER.info('Dispatch final model to participants...')

    with aggregator:
        aggregator.stop_task(model)

    LOGGER.info('Completed training')
コード例 #7
0
def get_task_participants(credentials, user, password, task_name):
    """
    Retrieve a list with details of all the task participants.
    If called by a participant different from the task creator, the returned list will be empty.
    :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`
    :return: list with the details of all the task participants
    :rtype: `list`
    """
    context = fflapi.Context.from_credentials_file(credentials, user, password)
    user = fflapi.User(context)

    with user:
        return user.messenger.task_assignments(task_name)
コード例 #8
0
def create_task(credentials, user, password, 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`
    """
    creator_context = fflapi.Context.from_credentials_file(
        credentials, user, password)

    creator = fflapi.User(creator_context, task_name=task_name)
    topology = fflapi.Topology.star

    with creator:
        result = creator.create_task(topology, task_definition)

    return result