Skip to main content

Energy-efficient and latency-aware device selection for Blockchain-Enabled Federated Learning.

Project description

bcfl-optimizer

Energy-efficient and latency-aware device selection for Blockchain-Enabled Federated Learning.

A Python library implementing the joint optimization algorithm from:

D. Kushwaha, M. Kalavadia, V. Hegde and O. J. Pandey,
"Energy-Efficient and Latency-Aware Blockchain-Enabled Federated Learning for Edge Networks,"
IEEE TCAS-II, Vol. 71, No. 3, March 2024.


Installation

pip install bcfl-optimizer

(To include optional integrations like Flower, Pandas, or plotting, use pip install bcfl-optimizer[all])

Dependencies: numpy (required), pandas (for CSV loading), matplotlib (for plotting examples).

Quick Start

from bcfl import DevicePool, MinerPool, optimize

# Create pools (from arrays, CSV, JSON, or random)
devices = DevicePool.random(n=50)
miners  = MinerPool.random(m=15)

# Select optimal 30 devices + miners (balanced latency-energy trade-off)
result = optimize(devices, miners, s_d=30, beta=0.5)

print(result)
# OptimizationResult(
#   devices=30, miners=2,
#   latency=3.2145s, energy=12.4532J,
#   fitness=0.012345, a_fork=1.2214, beta=0.5
# )

Loading Real Device Data

# From CSV
devices = DevicePool.from_csv("my_devices.csv")
# Expected columns: cpu_freq, tx_power, data_size

# From JSON
devices = DevicePool.from_json("my_devices.json")

# From NumPy arrays
devices = DevicePool(
    cpu_freq=[1.8e9, 1.2e9, ...],
    tx_power=[0.3, 0.15, ...],
    data_size=[87, 112, ...]
)

API Reference

DevicePool(cpu_freq, tx_power, data_size, ...)

Heterogeneous edge device pool. Methods:

  • .computation_cost(epochs, kappa) → latency, energy per device (Eq. 1-2)
  • .upload_cost(model_size, bandwidth, noise_power) → latency, energy (Eq. 3)
  • .total_cost(...) → combined per-device costs

MinerPool(proc_freq, ver_power)

Miner pool. Methods:

  • .verification_cost(model_size) → latency, energy per miner (Eq. 4)

optimize(device_pool, miner_pool, s_d, beta=0.5, ...)

Run Algorithm 1 to find optimal device-miner selection.
Returns OptimizationResult with selected indices, latency, energy, fitness.

sweep(device_pool, miner_pool, beta=0.5, s_d_range=None, ...)

Run optimization across multiple S_D values for parameter studies.

forking_probability(num_miners, ...) / forking_multiplier(...)

Blockchain forking model (Eq. 10).

Flower Integration

The library natively supports the Flower Federated Learning framework via a custom Strategy wrapping FedAvg.

import flwr as fl
from bcfl.flower import BCFLStrategy

# Automatically selects the mathmatically optimal devices every FL round!
strategy = BCFLStrategy(
    device_pool=devices,
    miner_pool=miners,
    s_d=10,                      # target 10 devices per round
    beta=0.5,                    # balanced latency/energy
    fraction_fit=1.0,
    fraction_evaluate=1.0,
)

fl.simulation.start_simulation(client_fn=client_fn, strategy=strategy)

Examples

python examples/quickstart.py           # Minimal usage
python examples/paper_reproduction.py   # Reproduce Fig. 3 trade-off curves

Citation

If you use this library in your research, please cite:

@article{kushwaha2024energy,
  title   = {Energy-Efficient and Latency-Aware Blockchain-Enabled Federated Learning for Edge Networks},
  author  = {Kushwaha, D. and Kalavadia, M. and Hegde, V. and Pandey, O. J.},
  journal = {IEEE Transactions on Circuits and Systems II: Express Briefs},
  volume  = {71},
  number  = {3},
  pages   = {1126--1130},
  year    = {2024},
  doi     = {10.1109/TCSII.2023.3322340}
}

License

MIT License. See LICENSE.

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

bcfl_optimizer-0.1.2.tar.gz (15.3 kB view details)

Uploaded Source

Built Distribution

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

bcfl_optimizer-0.1.2-py3-none-any.whl (14.7 kB view details)

Uploaded Python 3

File details

Details for the file bcfl_optimizer-0.1.2.tar.gz.

File metadata

  • Download URL: bcfl_optimizer-0.1.2.tar.gz
  • Upload date:
  • Size: 15.3 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.12.12

File hashes

Hashes for bcfl_optimizer-0.1.2.tar.gz
Algorithm Hash digest
SHA256 abe04db9938d26f092860a38f87da45857b39fc2c667fe4c0e7d9a1a1f3ff46d
MD5 c1c88b0e93b6c6c2a9c1fce303a462b9
BLAKE2b-256 247f784bf158f7a1e6f41ed78047dd0c37e762b170a4fe961e9fb949a9471c81

See more details on using hashes here.

File details

Details for the file bcfl_optimizer-0.1.2-py3-none-any.whl.

File metadata

  • Download URL: bcfl_optimizer-0.1.2-py3-none-any.whl
  • Upload date:
  • Size: 14.7 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.12.12

File hashes

Hashes for bcfl_optimizer-0.1.2-py3-none-any.whl
Algorithm Hash digest
SHA256 ce6432c8aebfddebf4366161a006b5bea8f61df552222cf87237442846f39972
MD5 3599db199be50637dab7ede1c4122fbb
BLAKE2b-256 769ff0d66e37f00365e5494921be0f3aa8144cff0624390652b20b0b3cae6492

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