florist.api.db.entities module

Definitions for the MongoDB database entities.

class ClientInfo(**data)[source]

Bases: BaseModel

Define the information of an FL client.

class Config[source]

Bases: object

MongoDB config for the ClientInfo DB entity.

allow_population_by_field_name = True
schema_extra = {'example': {'client': 'MNIST', 'data_path': 'path/to/data', 'metrics': '{"host_type": "client", "initialized": "2024-03-25 11:20:56.819569", "rounds": {"1": {"fit_start": "2024-03-25 11:20:56.827081"}}}', 'redis_host': 'localhost', 'redis_port': '6380', 'service_address': 'localhost:8001', 'uuid': '0c316680-1375-4e07-84c3-a732a2e6d03f'}}
client: Client
data_path: str
id: str
metrics: Optional[Annotated[str]]
redis_host: str
redis_port: str
service_address: str
uuid: Optional[Annotated[str]]
class Job(**data)[source]

Bases: BaseModel

Define the Job DB entity.

class Config[source]

Bases: object

MongoDB config for the Job DB entity.

allow_population_by_field_name = True
schema_extra = {'example': {'_id': '066de609-b04a-4b30-b46c-32537c7f1f6e', 'clients_info': [{'client': 'MNIST', 'client_uuid': '0c316680-1375-4e07-84c3-a732a2e6d03f', 'data_path': 'path/to/data', 'redis_host': 'localhost', 'redis_port': '6380', 'service_address': 'localhost:8001'}], 'model': 'MNIST', 'redis_host': 'localhost', 'redis_port': '6379', 'server_address': 'localhost:8000', 'server_config': '{"n_server_rounds": 3, "batch_size": 8, "local_epochs": 1}', 'server_metrics': '{"host_type": "server", "fit_start": "2024-04-23 15:33:12.865604", "rounds": {"1": {"fit_start": "2024-04-23 15:33:12.869001"}}}', 'server_uuid': 'd73243cf-8b89-473b-9607-8cd0253a101d', 'status': 'NOT_STARTED'}}
clients_info: Optional[Annotated[List[ClientInfo]]]
config_parser: Optional[Annotated[ConfigParser]]
async create(database)[source]

Save this instance under a new record in the database.

Parameters:

database (AsyncIOMotorDatabase) – (motor.motor_asyncio.AsyncIOMotorDatabase) The database where the job collection is stored.

Return type:

str

Returns:

(str) the new job record’s id.

async classmethod find_by_id(job_id, database)[source]

Find a job in the database by its id.

Parameters:
  • job_id (str) – (str) the job’s id.

  • database (AsyncIOMotorDatabase) – (motor.motor_asyncio.AsyncIOMotorDatabase) The database where the job collection is stored.

Return type:

Optional[Job]

Returns:

(Optional[Job]) An instance of the job record with the given ID, or None if it can’t be found.

async classmethod find_by_status(status, limit, database)[source]

Return all jobs with the given status.

Parameters:
  • status (JobStatus) – (JobStatus) The status of the jobs to be returned.

  • limit (int) – (int) the limit amount of records that should be returned.

  • database (AsyncIOMotorDatabase) – (motor.motor_asyncio.AsyncIOMotorDatabase) The database where the job collection is stored.

Return type:

List[Job]

Returns:

(List[Job]) The list of jobs with the given status in the database.

id: str
model: Optional[Annotated[Model]]
redis_host: Optional[Annotated[str]]
redis_port: Optional[Annotated[str]]
server_address: Optional[Annotated[str]]
server_config: Optional[Annotated[str]]
server_metrics: Optional[Annotated[str]]
server_uuid: Optional[Annotated[str]]
set_client_metrics(client_uuid, client_metrics, database)[source]

Sync function to save a clients’ metrics in the database under the current job’s id.

Parameters:
  • client_uuid (str) – (str) the client’s uuid whose produced the metrics.

  • client_metrics (Dict[str, Any]) – (Dict[str, Any]) the client’s metrics to be saved.

  • database (Database[Dict[str, Any]]) – (pymongo.database.Database) The database where the job collection is stored.

Return type:

None

set_server_metrics(server_metrics, database)[source]

Sync function to save the server’s metrics in the database under the current job’s id.

Parameters:
  • server_metrics (Dict[str, Any]) – (Dict[str, Any]) the server metrics to be saved.

  • database (Database[Dict[str, Any]]) – (pymongo.database.Database) The database where the job collection is stored.

Return type:

None

async set_status(status, database)[source]

Save the status in the database under the current job’s id.

Parameters:
  • status (JobStatus) – (JobStatus) the status to be saved in the database.

  • database (AsyncIOMotorDatabase) – (motor.motor_asyncio.AsyncIOMotorDatabase) The database where the job collection is stored.

Return type:

None

set_status_sync(status, database)[source]

Sync function to save the status in the database under the current job’s id.

Parameters:
  • status (JobStatus) – (JobStatus) the status to be saved in the database.

  • database (Database[Dict[str, Any]]) – (pymongo.database.Database) The database where the job collection is stored.

Return type:

None

async set_uuids(server_uuid, client_uuids, database)[source]

Save the server and clients’ UUIDs in the database under the current job’s id.

Parameters:
  • server_uuid (str) – [str] the server_uuid to be saved in the database.

  • client_uuids (List[str]) – List[str] the list of client_uuids to be saved in the database.

  • database (AsyncIOMotorDatabase) – (motor.motor_asyncio.AsyncIOMotorDatabase) The database where the job collection is stored.

Return type:

None

status: JobStatus
class JobStatus(value)[source]

Bases: Enum

Enumeration of all possible statuses of a Job.

FINISHED_SUCCESSFULLY = 'FINISHED_SUCCESSFULLY'
FINISHED_WITH_ERROR = 'FINISHED_WITH_ERROR'
IN_PROGRESS = 'IN_PROGRESS'
NOT_STARTED = 'NOT_STARTED'
classmethod list()[source]

List all the valid statuses.

Return type:

List[str]

Returns:

(List[str]) a list of valid job statuses.

assert_updated_successfully(update_result)[source]

Assert an update result has updated exactly one record.

Parameters:

update_result (UpdateResult) – (pymongo.results.UpdateResult) the result object from an update.

Return type:

None