Skip to content

wsoussi/MTDFedX

Repository files navigation

MTDFedX: Multi-Task Distributed Federated Learning with OptSFC

This repository contains a federated learning framework for multi-objective reinforcement learning using the OptSFC (Optimal Service Function Chaining) environment.

Package Structure

The project is now split into two main packages:

1. OptSFC Package (./OptSFC/)

Optimal Service Function Chaining Environment and Training Framework

  • Purpose: Multi-objective 5G network environment and RL training utilities

  • Key Components:

    • optsfc.envs.mo_fiveg_mdp: Core MO 5G network environment
    • optsfc.envs.morl_train: MORL training utilities (EUPG, Envelope)
    • optsfc.envs.short_simulated_testbed: Testing and validation
    • optsfc.envs.short_space_dict: Environment space definitions
  • Dependencies: gymnasium, stable-baselines3, sb3-contrib, morl-baselines, torch, numpy, matplotlib, scipy

2. MTDFed Package (./MTDFed/)

Federated Learning Framework

  • Purpose: Flower-based federated learning with OptSFC environment

  • Key Components:

    • MTDFed.client_rl_mtd: Federated learning client implementation
    • MTDFed.server_rl_mtd: Federated learning server
    • MTDFed.custom_strategy: Custom aggregation strategies
  • Dependencies: flwr, torch, optsfc (as dependency)

Installation

Option 1: Install Both Packages (Recommended)

# Install OptSFC first
cd OptSFC
pip install -e .

# Install MTDFed 
cd ../MTDFed
pip install -e .

Option 2: Install from Requirements

# OptSFC
cd OptSFC
pip install -r requirements.txt
pip install -e .

# MTDFed  
cd ../MTDFed
pip install -r requirements.txt
pip install -e .

Quick Start

Using OptSFC Standalone

from optsfc import MOfiveG_net, train_eupg

# Create environment
env = MOfiveG_net("MlpPolicy", budget_reset="episodic")

# Train EUPG agent
train_eupg(
    total_timesteps=100000,
    model_name="eupg_model", 
    budget_reset="episodic"
)

Using MTDFed for Federated Learning

# Start server
flwr run MTDFed

# Or use individual components
python -c "from MTDFed.server_rl_mtd import app; app.run()"

Development

Requirements Generation

Requirements were generated using:

# Auto-detect dependencies 
pipreqs OptSFC --force --savepath OptSFC.requirements.in
pipreqs . --force --savepath MTDFed.requirements.in --ignore OptSFC

# Pin to current versions
pip freeze > requirements.full.txt

Testing Package Separation

python test_package_separation.py

Migration Notes

  • Before: All code was in fedl/fedl/mofiveg_momdp/
  • After: OptSFC is independent package, MTDFed imports from optsfc
  • Imports Changed:
    • From: from .OptSFC.envs.mo_fiveg_mdp import ...
    • To: from optsfc.envs.mo_fiveg_mdp import ...

Package Benefits

  • Modularity: OptSFC can be reused in other projects
  • Clean Dependencies: Each package has minimal, focused dependencies
  • Independent Development: OptSFC and MTDFed can be versioned separately
  • Better Testing: Each package can have its own test suite
  • Distribution: OptSFC can be published to PyPI independently

File Structure

MTDFedX/
├── OptSFC/                  # OptSFC Package
│   ├── optsfc/
│   │   ├── __init__.py
│   │   └── envs/
│   │       ├── mo_fiveg_mdp.py
│   │       ├── morl_train.py  
│   │       ├── short_simulated_testbed.py
│   │       └── short_space_dict.py
│   ├── pyproject.toml
│   ├── requirements.txt
│   └── README.md
├── MTDFed/                  # MTDFed Package  
│   ├── MTDFed/
│   │   ├── __init__.py
│   │   ├── client_rl_mtd.py
│   │   ├── server_rl_mtd.py
│   │   └── custom_strategy.py
│   ├── pyproject.toml
│   ├── requirements.txt
│   └── README.md
├── test_package_separation.py
└── README.md               # This file

About

Federated Learning framework to optimize Moving Target Defense (MTD) strategies applied on telco cloud network services.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors

Languages