flip.core.standard

Standard FLIP Implementation.

This module contains the production and development implementations of FLIP for the standard, evaluation, and fed_opt job types.

Classes

FLIPStandardProd

Production implementation of FLIP for standard job types.

FLIPStandardDev

Development implementation of FLIP for standard job types.

Module Contents

class flip.core.standard.FLIPStandardProd[source]

Bases: flip.core.base.FLIPBase

Production implementation of FLIP for standard job types.

Method usage by FL role:

Server-only (fl-server on Central Hub → calls flip-api):
  • update_status() — update model training status

  • send_metrics() — forward per-client training/evaluation metrics

  • send_handled_exception() — forward client exception logs

  • upload_results_to_s3() — upload trained model to S3

Client-only (fl-client on trust side → calls local trust APIs):
  • get_dataframe() — fetch cohort data from data-access-api

  • get_images() — download images from imaging-api

  • download_data_from_s3() — download federated data from S3

logger[source]
get_dataframe(project_id: str, query: str) pandas.DataFrame[source]

Retrieves the dataframe from the trust OMOP using the SQL query. Calls the FLIP data-access-api.

Parameters:
  • project_id (str) – Project identifier

  • query (str) – SQL query

Returns:

pd.DataFrame – Dataframe containing the resulting accession ids and additional data.

get_by_accession_number(project_id: str, accession_id: str, resource_type: flip.constants.flip_constants.ResourceType | List[flip.constants.flip_constants.ResourceType] = ResourceType.NIFTI) pathlib.Path[source]

Calls the imaging-service to return a filepath that contains images downloaded from XNAT based on the accession number.

Parameters:
  • project_id (str) – The ID of the project.

  • accession_id (str) – The accession ID of the imaging study.

  • resource_type (Union[ResourceType, List[ResourceType]]) – The type of resource to download. Defaults to

  • ResourceType.NIFTI.

Returns:

Path – Path to the downloaded data for that accession_id.

add_resource(project_id: str, accession_id: str, scan_id: str, resource_id: str, files: List[str]) None[source]

Calls the imaging-service to upload image(s) to XNAT based on the accession number, scan ID, and resource ID.

Parameters:
  • project_id (str) – Unique project identifier

  • accession_id (str) – Accession ID to upload the resource to

  • scan_id (str) – ID of the scan to upload

  • resource_id (str) – Type of resource that is being uploaded (e.g. NIFTI)

  • files (List[str]) – List of files to upload

update_status(model_id: str, new_model_status: flip.constants.flip_constants.ModelStatus) None[source]

Updates the model status on the Central Hub.

Parameters:
  • model_id (str) – Unique model identifier.

  • new_model_status (ModelStatus) – New model status value.

send_metrics(client_name: str, model_id: str, label: str, value: float, round: int) None[source]

Sends a metric value to the Central Hub.

Parameters:
  • client_name (str) – The name of the client.

  • model_id (str) – The ID of the model.

  • label (str) – The label of the metric.

  • value (float) – The value of the metric.

  • round (int) – The round number.

send_handled_exception(formatted_exception: str, client_name: str, model_id: str) None[source]

Sends a handled exception to the Central Hub.

Parameters:
  • formatted_exception (str) – The formatted exception message.

  • client_name (str) – The name of the client that raised the exception.

  • model_id (str) – The ID of the model associated with the exception.

upload_results_to_s3(results_folder: pathlib.Path, model_id: str) None[source]

Uploads results to S3 bucket in standard mode.

Parameters:
  • results_folder (Path) – The folder containing results to upload

  • model_id (str) – The model UUID for which results are being uploaded

cleanup(path: pathlib.Path) None[source]

Cleans up local files by deleting the specified path.

class flip.core.standard.FLIPStandardDev[source]

Bases: flip.core.base.FLIPBase

Development implementation of FLIP for standard job types.

logger[source]
get_dataframe(project_id: str, query: str) pandas.DataFrame[source]

Retrieves the dataframe from the specified CSV path.

Parameters:
  • project_id (str) – Project identifier (validated but not used in dev)

  • query (str) – SQL query (validated but not used in dev)

Returns:

pd.DataFrame – Dataframe from the DEV_DATAFRAME CSV file.

get_by_accession_number(project_id: str, accession_id: str, resource_type: flip.constants.flip_constants.ResourceType | List[flip.constants.flip_constants.ResourceType] = ResourceType.NIFTI) pathlib.Path[source]

Returns the path to the image directory for a specific accession ID.

Parameters:
  • project_id (str) – Project identifier

  • accession_id (str) – Accession ID to retrieve

  • resource_type (Union[ResourceType, List[ResourceType]]) – Type of imaging resource (not used in dev)

Returns:

Path – Path to the accession_id folder within the images folder.

add_resource(project_id: str, accession_id: str, scan_id: str, resource_id: str, files: List[str]) None[source]

Log only in dev mode - no actual upload.

update_status(model_id: str, new_model_status: flip.constants.flip_constants.ModelStatus) None[source]

Log only in dev mode - no actual status update.

send_metrics(client_name: str, model_id: str, label: str, value: float, round: int) None[source]

Log only in dev mode - no actual metrics sending.

send_handled_exception(formatted_exception: str, client_name: str, model_id: str) None[source]

Log only in dev mode - no actual exception sending.

upload_results_to_s3(results_folder: pathlib.Path, model_id: str) None[source]

Log only in dev mode - no actual upload.

cleanup(path: pathlib.Path) None[source]

Log only in dev mode - no actual deletion of any files.