Getting Started with flip-utils
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, Flower helpers, 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.
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 monorepo and install from source:
git clone https://github.com/londonaicentre/FLIP.git
cd FLIP/flip-utils
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.coreCore classes and abstractions:
FLIPBase— Abstract base class with common FL logicFLIPStandardProd— Production implementation using FLIP platform APIsFLIPStandardDev— Development implementation using local CSV/filesystemFLIP()factory — Automatically selects the correct implementation based on environment
flip.constantsConfiguration and enumerations:
FlipConstants— Pydantic-settings configuration singletonResourceType— Enum for imaging resource types (DICOM, NIFTI, etc.)ModelStatus— Enum for model training statesJobType— Enum for supported FL job typesPTConstants— PyTorch-specific constants and settings
flip.utilsUtility helpers:
Utils— General utility functionsmodel_weights_handling— Model weight aggregation and manipulation
flip.nvflareNVFLARE-specific components:
executors/— RUN_TRAINER, RUN_VALIDATOR, RUN_EVALUATOR wrapperscontrollers/— Workflow controllers (ScatterAndGather, CrossSiteModelEval, etc.)components/— Event handlers, persistors, privacy filters, model locators, etc.metrics.py— Metrics collection and reporting
flip.flowerFlower-specific helpers:
metrics.py— Server-side metrics collection and reporting for Flower runs
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 |
|---|---|
|
Federated training with FedAvg aggregation (default; NVFLARE Executor API) |
|
Federated training via the NVFLARE Client API (Client-API path used for Ark+ etc.) |
|
Distributed model evaluation without training (NVFLARE Executor API) |
|
Distributed model evaluation via the NVFLARE Client API (head-only eval path) |
|
Two-stage training: VAE encoder followed by diffusion model training |
|
Custom federated optimization with flexible aggregation strategies |
The Flower backend ships its own standard and evaluation templates under
fl-apps/flower/ — selected at the deploy layer by FL_BACKEND=flower.
User Application Requirements
User-provided application code goes in the job’s custom/ directory. The
executor wrappers dynamically import these files:
File |
Description |
|---|---|
|
Training logic — must export |
|
Validation logic — must export |
|
Model definitions — must export |
|
Hyperparameters — must include |
|
Data transforms (optional) |
Development Mode
To test FL applications locally before deploying to production:
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
Place your application files in
fl-apps/nvflare/<JOB_TYPE>/app/custom/(e.g. fl-apps/nvflare/standard/app/custom/).Run one of the shipped tutorials against the NVFLARE simulator from the repository root:
make -C fl-tutorials run-tutorial TUTORIAL=xray_classification # list every available tutorial with: make -C fl-tutorials list-tutorials
The simulator harness is documented in
fl-tutorials/nvflare/testing/and is driven per-tutorial via that tutorial’s.env.app. Seefl-services/nvflare/README.mdfor building the local:devFL images the harness uses.
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
flip-utils is documented as part of the FLIP documentation. From the
repository root, run:
cd docs && make docs
The generated HTML site will be written to docs/build/html. To clean
previous builds:
cd docs && make 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 section of
the built documentation for complete coverage of all public classes and functions.
Note
The flip-utils package lives under flip-utils/ in the FLIP repository, and its documentation is published as part of the
FLIP documentation.