Skip to content

Python-based simulation and training environment for xDRL-driven RAN slicing used to evaluate the developed algorithms.

Notifications You must be signed in to change notification settings

iThermAI/xDRL-RCS-Python

Repository files navigation

xDRL-RCS-Python

Docker License: MIT GitHub repo size GitHub last commit

xDRL-RCS-Python is a Python-based simulation and training environment designed for xDRL-driven RAN slicing.
It enables simulation, training, and evaluation of advanced Reinforcement Learning (RL) algorithms with SHAP-based explainability and XAI-PPO integration.
The framework provides visual and quantitative KPI comparisons, supporting end-to-end explainable AI evaluation for 5G RAN slicing scenarios.

📖 Overview

In multi-slice 5G networks, maintaining high performance and efficiency across diverse service types requires continuous monitoring and intelligent resource management.
This project provides a Deep Reinforcement Learning (DRL)–based xApp integrated into the O-RAN architecture to achieve automated and adaptive RAN slicing optimization.

The xApp dynamically adjusts Physical Resource Block (PRB) and bandwidth allocations across multiple network slices to ensure fairness, performance stability, and optimal utilization.
It operates in coordination with a customized KPM (Key Performance Measurement) monitoring xApp, which continuously collects real-time KPI metrics - such as throughput, latency, and PRB usage - from connected User Equipment (UE) devices.

All collected KPIs are stored in a MySQL database, forming the data backbone for DRL training, evaluation, and decision-making.
This architecture enables a closed-loop control system, where measured performance metrics directly inform learning-based optimization decisions, resulting in self-adaptive, explainable, and data-driven RAN management.

The xDRL-RCS-Python environment extends this framework by simulating the 5G RAN slicing process, incorporating explainable AI (XAI) techniques such as SHAP and XAI-PPO to provide deeper interpretability and transparency in DRL-based network control decisions.

🧠 Complete XAI Pipeline and Evaluation

The XAI pipeline in xDRL-RCS-Python consists of several structured steps that together form a full simulation, explainability, and evaluation workflow.

Step 1: Environment Setup and Feature Definition

Description:

  • Initialize the working environment and runtime configuration.
  • Import and configure all required dependencies.
  • Define and register the feature names used throughout the pipeline for training, evaluation, and interpretability tasks.

This step ensures a reproducible environment and consistent feature mapping across all modules.

Step 2: Core Function and SHAP Sampler Definition

Description:

  • Implement the evaluation functions responsible for model assessment and performance scoring.
  • Define sampling utilities to generate representative feature subsets for SHAP analysis.
  • Provide supporting utilities for:
    • Feature preprocessing and encoding.
    • Seamless integration between the RL models and SHAP explainability components.

The SHAP sampler acts as a bridge between the trained RL model and the interpretability layer, allowing for precise estimation of feature importance.

Step 3: SHAP-Based Feature Importance and Environment Pruning

Description:

  • Compute SHAP values to determine per-feature contribution to the model’s decisions.
  • Use the SHAP-derived attributions to prune the environment, removing less relevant features or states.
  • Instantiate a new, pruned environment optimized for XAI-specific training and evaluation.

This selective pruning enhances interpretability while preserving essential performance characteristics.

Step 4: XAI Pipeline Execution and Evaluation

Description:

  • Execute the complete XAI workflow, including:

    1. Training of baseline RL algorithms.
    2. Performance evaluation on initial (non-pruned) environment.
    3. SHAP analysis and environment pruning.
    4. Re-training of XAI-augmented models (e.g., XAI-PPO).
    5. Comparative evaluation between baseline and explainable models.
  • Visualization and Comparative Analysis:

    • Generate detailed plots illustrating:
      • Feature attributions.
      • KPI trends.
      • Slice-wise performance differences across methods.
    • Present side-by-side comparisons for better interpretability and explainability insights.

The final outcome is a transparent and analytically rich view of how explainable RL models behave in dynamic 5G RAN slicing environments.

🗂️ Repository Contents

DRL and xDRL Learning

The drl_learning_service and xdrl_learning_service directories contain two modular, end-to-end Python service frameworks designed for DRL and xDRL model development. These modules include:

  • Complete DRL/xDRL pipelines
    Full implementations covering environment configuration, model training loops, evaluation routines, and experiment orchestration.

  • Explainability & Interpretation Toolkit
    Integrated XAI components - SHAP, XAI, and XAI-PPO - to provide feature attribution, policy interpretation, and insight into model decision-making.

  • Utility & Helper Modules
    Tools for dataset preprocessing, KPI extraction/management, logging, and visualization of training dynamics and learned policies.

  • Reproducible Environment Setup
    Clearly defined package and dependency specifications required to recreate the experimental environment.

  • Inline Documentation & Workflow Guidance
    Concise notes throughout the codebase outlining the logic, workflow stages, and function responsibilities to improve readability, onboarding, and reproducibility.

xDRL Inference

The xdrl_inference_service directory contains a lightweight, production-oriented Python module for running inference with pretrained xDRL models. This component is designed to operate independently from the training pipeline while seamlessly consuming its outputs.

After executing the xDRL learning service, a trained model is stored under the trained_models directory inside xdrl_learning_service. The inference module loads this pretrained model and performs:

  • A continuous decision-making loop, applying the learned policy to incoming data.
  • A short-term adaptive learning phase triggered approximately every 50 iterations, allowing the agent to refine its decisions based on recent observations.
  • Final output generation, produced after the quick adaptation phase stabilizes, enabling real-time or near-real-time decision support.

This structure enables efficient deployment of xDRL models with minimal overhead while preserving adaptability during operation.

▶️ Run Services

Before running any service, ensure that all required Python dependencies are installed. Each service directory includes its own requirements.txt, so installation should be done per service:

pip install --upgrade pip
pip install -r requirements.txt

Once dependencies are installed, you can launch the xDRL or DRL learning services by simply executing:

python3 main.py

Each service will initialize its internal modules, load configurations, and begin the corresponding training or inference workflow.

To run the inference service, first place the pretrained model directory (trained_models) - produced by the xDRL learning service - inside the xdrl_inference_service folder.

The main.py file includes three example scenario functions, each demonstrating a different inference workflow. You may comment/uncomment these functions to experiment with the scenarios individually.

To execute the inference module, use the same run command:

python3 main.py

The service will load the pretrained model, run the decision-making loop, and perform short-term adaptive learning during inference.

Note: All learning and inference modules involve computationally intensive operations, especially during training and short-term adaptation phases.
For optimal performance, it is strongly recommended to run these services on a machine equipped with a GPU (preferably CUDA-enabled).

📊 Output Samples

Below are representative outputs generated from running the xDRL-RCS-Python simulation and training environment.
These examples illustrate the training process, model performance, and slice-level KPI evaluations across various DRL algorithms.

Run Log

Shows the runtime progress and performance updates during model training and evaluation.

Training Accuracy and Loss

Demonstrates the convergence behavior of the DRL agent by visualizing accuracy trends and loss reduction over time.

SLA Compliance per Slice

Comparative visualization of Service Level Agreement (SLA) compliance across different DRL algorithms (PPO, A2C, and DQN).
Each plot represents slice-level KPI performance and the effectiveness of the corresponding learning policy.

PPO A2C DQN

These visual results collectively demonstrate the explainable, performance-driven optimization achieved by the DRL-based xApp within the 5G RAN slicing simulation environment.

About

Python-based simulation and training environment for xDRL-driven RAN slicing used to evaluate the developed algorithms.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages