flip

FLIP - Federated Learning and Interoperability Platform

This package provides the core functionality for federated learning in the FLIP platform, built on NVIDIA FLARE (NVFLARE).

Main exports:
  • FLIP: Factory function that returns the appropriate FLIP implementation based on job type

  • FLIPBase: Abstract base class for FLIP implementations

Example usage:

from flip import FLIP

flip = FLIP()  # Uses default "standard" job type

df = flip.get_dataframe(project_id, query)

Submodules

Classes

FLIPBase

Abstract base class for FLIP functionality across all job types.

Functions

FLIP(→ flip.core.base.FLIPBase)

Factory function to create appropriate FLIP instance based on job type.

Package Contents

class flip.FLIPBase[source]

Bases: abc.ABC

Abstract base class for FLIP functionality across all job types.

This class defines the interface that all FLIP implementations must follow. Concrete implementations handle the differences between development and production environments, as well as job-type-specific behavior.

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

Returns a dataframe for the project/query.

Parameters:
  • project_id (str) – The project identifier

  • query (str) – SQL query string

Returns:

pd.DataFrame – Dataframe containing the query results

abstractmethod 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 data for the given accession number.

Parameters:
  • project_id (str) – The project identifier

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

  • resource_type (Union[ResourceType, List[ResourceType]]) – Type(s) of resources to download

Returns:

Path – Path to the downloaded data

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

Adds specific image to XNAT for an accession ID.

Parameters:
  • project_id (str) – The project identifier

  • accession_id (str) – The accession ID

  • scan_id (str) – The scan ID

  • resource_id (str) – The resource type ID

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

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

Updates training status in Central Hub.

Parameters:
  • model_id (str) – The model UUID

  • new_model_status (ModelStatus) – The new status to set

abstractmethod 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 client name sending the metric

  • model_id (str) – The model UUID

  • label (str) – The label of the metric

  • value (float) – The value of the metric

  • round (int) – The local round number

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

Sends a training-related exception to Central Hub.

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

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

  • model_id (str) – The model UUID

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

Uploads results to S3 bucket.

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

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

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

Cleans up local files.

Parameters:

path (Path) – The path to the file or directory to clean up

check_query(query: str) None[source]

Check whether the query is a string type.

Parameters:

query (str) – The query to validate

Raises:

TypeError – If query is not a string

check_project_id(project_id: str) None[source]

Checks whether the project id is a string type.

Parameters:

project_id (str) – The project ID to validate

Raises:

TypeError – If project_id is not a string

check_accession_id(accession_id: str) None[source]

Checks whether accession_id is a string type.

Parameters:

accession_id (str) – The accession ID to validate

Raises:

TypeError – If accession_id is not a string

check_resource_type(resource_type: flip.constants.flip_constants.ResourceType | List[flip.constants.flip_constants.ResourceType]) List[flip.constants.flip_constants.ResourceType][source]

Check whether resource type is valid and returns them reformatted.

Parameters:

resource_type (Union[ResourceType, List[ResourceType]]) – Single ResourceType or list of ResourceTypes

Returns:

List[ResourceType] – List of validated resource types

Raises:

TypeError – If resource_type is not valid

flip.FLIP(job_type: flip.constants.job_types.JobType | flip.constants.job_types.JobTypeStr = JobType.STANDARD, **kwargs) flip.core.base.FLIPBase[source]

Factory function to create appropriate FLIP instance based on job type.

This is the main entry point for users to create FLIP instances. The factory automatically selects the correct implementation based on:

  1. The job type (standard, evaluation, fed_opt, diffusion_model)

  2. The environment (LOCAL_DEV or production)

Parameters:
  • job_type – One of “standard”, “evaluation”, “fed_opt”, “diffusion_model” or a JobType enum value. Defaults to “standard”.

  • **kwargs – Additional arguments passed to the constructor

Returns:

FLIPBase – Appropriate FLIP instance for the job type and environment

Examples

Create a standard FLIP instance:

flip = FLIP()
df = flip.get_dataframe(project_id, query)

Create an evaluation-specific FLIP instance:

flip = FLIP(job_type="evaluation")

Use the enum-based job type:

from flip.constants import JobType
flip = FLIP(job_type=JobType.DIFFUSION)