Clients#

Web Client file.

class fma_connect.clients.WebClient(federated_model_id, uuid=None, url=None)#

Bases: object

REST API Wrapper to interact with the federated learning service.

Initialization function for WebClient.

Parameters:
  • federated_model_id (int) – id of the federated model for which to send updates

  • uuid (str) – client uuid, None if not previously registered

  • url (str) – url of the api, by default uses settings

property uuid#

Client uuid.

property url#

URL of the API.

property federated_model_id#

ID of the federated model for which to send updates.

register()#

Registers client with federated model.

Registers the client with the federated model. If the client is already registered, no changes will be made.

Raises:

APIException – response is something other than 200 or 201

Returns:

string of the registered uuid

Return type:

str

send_update(data: Any, base_aggregate=None) dict#

Sends updates to the API service.

Parameters:
  • data (Any) – the updates to the weights you intend of sending to API

  • base_aggregate (Any, optional) – the starting aggregate which your updates are based on, defaults to None

Raises:

APIException – response status code is something other than 201

Returns:

a dictionary of the response from the FMA Service :model_data: The stored weights that now exist within the service’s database

Return type:

Dict[(‘model_data’: Any)]

check_for_new_model_aggregate(update_after=None)#

Retrieves the latest model aggregate for the model.

Parameters:

update_after (int, optional) – aggregate id that any new aggregate has to be more than, defaults to None

Raises:

APIException – response status code is something other than 200

Returns:

response of the api in json format :id: model aggregate object identifier :results: output of the aggregation function (ie updated model weights) :validation_score: output of the specified evaluation function

Return type:

Optional[Dict[(‘id’: int), (‘results’: Any), (‘validation_score’: float)]]

get_current_artifact()#

Retrieves the latest artifact for the model.

Raises:

APIException – response status code is something other than 200

Returns:

response of the API in json format :id: id of the artifact object :values: model weights of the published artifact :version: version of the model artifact published to production

inference environment

created_on:

timestamp

federated_model:

id of the base federated model object}

Return type:

Optional[Dict[(‘id’: int), (‘values’: Any), (‘created_on’: str), (‘federated_model’: int)]]

check_for_latest_model(update_after=None)#

Retrieves latest update to Federated Model.

Retrieves latest update to Federated model based on timestamp regardless of artifact or aggregate.

Parameters:

update_after (int, optional) – aggregate id that any new aggregate has to be more than, defaults to None

Raises:

APIException – response status code is something other than 200

Returns:

response of the api in json format :values: The data to be loaded into model schema :aggregate: the id of the aggregate the values were pulled from

(None if pulling from artifact)

Return type:

Optional[Dict[(‘values’: Any), (‘aggregate’: int)]]

send_val_results(results: Any, aggregate_id: int) dict#

Sends updates to the FMA service.

Parameters:
  • results (Any) – the updates to the weights you intend of sending to FMA

  • aggregate_id (int) – the starting aggregate your updates are based on

Raises:

APIException – response status code is something other than 201

Returns:

a dictionary of the response from the FMA Service in json format :results: a copy of the pushed results including the status of the API call

Return type:

Dict