Skip to main content

FLIP - Federated Learning and Interoperability Platform library built on NVIDIA FLARE

Project description

About flip-utils

flip-utils is the pip-installable distribution published from this repository. Its Python import package is flip, which contains the shared platform logic used by FLIP jobs and services including core training logic, NVFLARE components, and utility helpers.

The FLIP platform uses this package to power federated learning applications across multiple job types: standard federated training, distributed evaluation, diffusion model training, and custom federated optimization.

Hosted documentation is available on Read the Docs.

Installation

Install the published package from PyPI:

pip install flip-utils
# or with uv
uv add flip-utils

To use the latest development version, clone the repository and install from source:

git clone https://github.com/londonaicentre/flip-fl-base.git
git checkout develop   # or the desired branch/commit
cd flip-fl-base
uv sync
# or
pip install .

To build a distributable wheel for development:

uv build

Package Structure & Modules

The flip package is organized into logical modules:

flip.core

Core classes and abstractions:

  • FLIPBase — Abstract base class with common FL logic

  • FLIPStandardProd — Production implementation using FLIP platform APIs

  • FLIPStandardDev — Development implementation using local CSV/filesystem

  • FLIP() factory — Automatically selects the correct implementation based on environment

flip.constants

Configuration and enumerations:

  • FlipConstants — Pydantic-settings configuration singleton

  • ResourceType — Enum for imaging resource types (DICOM, NIFTI, etc.)

  • ModelStatus — Enum for model training states

  • JobType — Enum for supported FL job types

  • PTConstants — PyTorch-specific constants and settings

flip.utils

Utility helpers:

  • Utils — General utility functions

  • model_weights_handling — Model weight aggregation and manipulation

flip.nvflare

NVFLARE-specific components:

  • executors/ — RUN_TRAINER, RUN_VALIDATOR, RUN_EVALUATOR wrappers

  • controllers/ — Workflow controllers (ScatterAndGather, CrossSiteModelEval, etc.)

  • components/ — Event handlers, persistors, privacy filters, model locators, etc.

  • metrics.py — Metrics collection and reporting

Using the FLIP Factory

The FLIP() factory automatically selects between development and production implementations based on the LOCAL_DEV environment variable:

from flip import FLIP

# Uses FLIPStandardProd in production or FLIPStandardDev in local dev
flip = FLIP()
df = flip.get_dataframe(project_id, query)

See the API reference for detailed method documentation.

Job Types

Set the job type via the JOB_TYPE environment variable:

Type

Description

standard

Federated training with FedAvg aggregation (default)

evaluation

Distributed model evaluation without training

diffusion_model

Two-stage training: VAE encoder followed by diffusion model training

fed_opt

Custom federated optimization with flexible aggregation strategies

User Application Requirements

User-provided application code goes in the job’s custom/ directory. The executor wrappers dynamically import these files:

File

Description

trainer.py

Training logic — must export FLIP_TRAINER class

validator.py

Validation logic — must export FLIP_VALIDATOR class

models.py

Model definitions — must export get_model() function

config.json

Hyperparameters — must include LOCAL_ROUNDS and LEARNING_RATE

transforms.py

Data transforms (optional)

Development Mode

To test FL applications locally before deploying to production:

  1. Set environment variables in .env.development:

    LOCAL_DEV=true
    DEV_IMAGES_DIR=../data/accession-resources
    DEV_DATAFRAME=../data/sample_get_dataframe.csv
    JOB_TYPE=standard
  2. Place your application files in src/<JOB_TYPE>/app/custom/.

  3. Run the simulator in Docker:

    make run-container

Running Tests

Run unit tests for the flip package:

make unit-test
# or
uv run pytest -s -vv

Tests use pytest with coverage reporting and are located in tests/unit/.

Building the Docs Locally

From the repository root, run:

make docs

The generated HTML site will be written to docs/_build/html. To clean previous builds:

make docs-clean

How the API Reference is Generated

The API reference is built with sphinx-autoapi and points directly at the flip/ source tree. That keeps the reference pages aligned with the code without maintaining hand-written module stubs. See the API Reference for complete documentation of all public classes and functions.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

flip_utils-0.1.4.tar.gz (47.5 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

flip_utils-0.1.4-py3-none-any.whl (82.8 kB view details)

Uploaded Python 3

File details

Details for the file flip_utils-0.1.4.tar.gz.

File metadata

  • Download URL: flip_utils-0.1.4.tar.gz
  • Upload date:
  • Size: 47.5 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: uv/0.10.11 {"installer":{"name":"uv","version":"0.10.11","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"Ubuntu","version":"24.04","id":"noble","libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":true}

File hashes

Hashes for flip_utils-0.1.4.tar.gz
Algorithm Hash digest
SHA256 6eae278d9432421741d595eefdb509200a1850e8354f4a0cd7d07fc2778c90e1
MD5 1fdd5357bf8dc1c399d11555ad132cdd
BLAKE2b-256 57829874b053f5ba8d03fb7fa810f58f053a97839ad53390b2df9cfb61ee371d

See more details on using hashes here.

File details

Details for the file flip_utils-0.1.4-py3-none-any.whl.

File metadata

  • Download URL: flip_utils-0.1.4-py3-none-any.whl
  • Upload date:
  • Size: 82.8 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: uv/0.10.11 {"installer":{"name":"uv","version":"0.10.11","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"Ubuntu","version":"24.04","id":"noble","libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":true}

File hashes

Hashes for flip_utils-0.1.4-py3-none-any.whl
Algorithm Hash digest
SHA256 9dd1b1d7cbd5d5b7b39a991ae540bf55e17912f063b4e7a6d326e5f98c917f1e
MD5 8326597b03d82f409616ef0d7b4ea740
BLAKE2b-256 af6d4a136eaa22ee39c214061a1f6ad558b030ffcb52f1782e7a8250a928fbd1

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page