Skip to main content

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.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.

  • recipes/ — High-level NVFLARE job recipes

  • runtime.py — Runtime helpers for NVFLARE apps

  • metrics.py — Metrics collection and reporting

flip.flower

Flower-specific helpers:

  • strategy.py — Flower Strategy implementations (e.g. FedAvgWithClientMetrics)

  • metrics.py — Server-side metrics collection and reporting for Flower runs

  • progress.py — Progress/status reporting helpers 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

Pass the job type to the FLIP() factory (FLIP(job_type=...)). The JobType enum (flip.constants.job_types) defines the values recognised by FLIP():

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

The NVFLARE backend additionally ships template directories under fl-apps/nvflare/ for the Client-API variants (standard_client_api, evaluation_client_api); these are selected as app templates and are not JobType enum values. 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

The executor wrappers dynamically import user-provided code from the job’s custom/ directory. For most templates that directory is materialised at run time by the tutorial harness (fl-tutorials/nvflare/testing/app_organiser.sh), which copies each file from the tutorial’s app_files/ into ./tmp/app/custom/; the diffusion_model template already carries a git-tracked custom/ with baseline files that the same overlay extends.

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
  2. Place your application files in the tutorial’s app_files/ directory (e.g. fl-tutorials/nvflare/image_classification/xray_classification/app_files/). At run time the harness copies them into ./tmp/app/custom/ on top of the matching fl-apps/nvflare/<template>/app/ template.

  3. 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. See fl-services/nvflare/README.md for building the local :dev FL 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.

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.4.1.tar.gz (96.7 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.4.1-py3-none-any.whl (142.8 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: flip_utils-0.4.1.tar.gz
  • Upload date:
  • Size: 96.7 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: uv/0.12.2 {"installer":{"name":"uv","version":"0.12.2","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.4.1.tar.gz
Algorithm Hash digest
SHA256 e16647f69c7a5e1e453cdccef9da76c2e49e5e4c935ef8e4c0b661a5e256e7a3
MD5 24c2eb5a2c249f5fb043cf6b770c02bc
BLAKE2b-256 92313ec42ed4f2ba9ca7a12c1ff3897832b974d9d542cdba8be1c4db8d3599b6

See more details on using hashes here.

File details

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

File metadata

  • Download URL: flip_utils-0.4.1-py3-none-any.whl
  • Upload date:
  • Size: 142.8 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: uv/0.12.2 {"installer":{"name":"uv","version":"0.12.2","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.4.1-py3-none-any.whl
Algorithm Hash digest
SHA256 d247c807e45e96aa0a6676ee09e20ed9beafb36e57bfe222efc1d33b1c802627
MD5 1d54584b37fdd5ef816a35d8b5b8e7b9
BLAKE2b-256 738412e9f331168f920f874eb9a23426f7dcd7e22670c99f396833e5d6cfb636

See more details on using hashes here.

Release history Release notifications | RSS feed

0.5.0

2 files

This release

0.4.1 This release

2 files

0.1.8

2 files

0.1.7

2 files

0.1.6

2 files

0.1.5

2 files

0.1.4

2 files

0.1.3

2 files

0.1.2

2 files

0.1.1

2 files

0.1.0

2 files

Supported by

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