How isfons/marl_energy_flexibility works
Purpose and Entry Points
This repository studies multi-agent reinforcement learning for energy-flexibility control in prosumer microgrids with EVs, PV, batteries, and flexible thermal demand. Main operational entry points are experiment and training CLIs under scripts/, notably scripts/model_selection/run_ppo_tune.py, scripts/model_selection/run_sac_tune.py, scripts/training/run_dagger.py, and scripts/training/run_forecaster_training.py.
Data and Scenario Construction
Datasets represent prosumer populations and environment configurations, including UK and synthetic-diverse scenarios. Offline DER traces are generated through data/run_data_generation.py and component generators such as data/generator/car.py and data/generator/pv.py. Runtime scenarios are sourced from directories such as data/datasets/UK_IC/env_config and data/datasets/10_prosumers_diverse/env_config.
Multi-Agent Environment Boundary
The central simulator is marl_der/environment/environment.py, configured by marl_der/environment/config.py. It implements the multi-agent DER control episode contract: observations, translated agent actions, state transitions, and per-agent/global termination. Reward composition and penalties are separated in marl_der/environment/rewards.py; Gymnasium/RLlib adaptation occurs in marl_der/environment/wrappers.py. This is the key boundary between physical/data-driven microgrid dynamics and learning/control code.
Forecasting Stage
marl_der/environment/forecasting.py provides offline RNN forecast training and export. Forecast artifacts feed the environment’s agent observations rather than being trained within the RL loop. The dedicated entry point, scripts/training/run_forecaster_training.py, keeps forecast-model lifecycle separate from policy training and evaluation.
Expert-Control and Imitation Pipeline
Classical/expert controllers provide demonstrations and baselines: battery optimization is in marl_der/expert/mpc.py, thermal control and tuning in marl_der/expert/pid.py. Expert trajectories are exported and used for behavior cloning in marl_der/expert/behavior_cloning.py; DAgger iteratively collects learner-visited expert labels through marl_der/expert/dagger.py. marl_der/expert/rl_transfer.py transfers BC weights into PPO/SAC checkpoints for warm starts.
RL Training, Tuning, and Transfer
RLlib-facing policy/environment specifications, callbacks, splits, and history handling reside in marl_der/rl/rl_utils.py. Reusable PPO/SAC Ray Tune trainables are defined in marl_der/rl/rl_trainables.py, while trial execution, result ranking, and final-config construction are in marl_der/rl/rl_tuning.py. Residual-policy mechanisms are isolated in marl_der/rl/rl_residual.py. Training workflows include BC-initialized and residual PPO variants via scripts/run_ppo_bc_critic_tune.py and scripts/run_ppo_residual_tune.py.
Evaluation and Experiment Orchestration
Checkpoint rollout and module evaluation are centralized in marl_der/rl/rl_evaluation.py. Scripts orchestrate comparisons and final runs, including scripts/training/compare_training_methods.py, scripts/training/run_matched_shared_bc_ppo.py, and scripts/run_expert.py. Evaluation outputs are expected to compare learned, cloned, residual, and expert policies against the same environment/reward contract.
Runtime and Infrastructure
The core runtime is Python with Gymnasium-style environments and Ray RLlib/Ray Tune for distributed RL training and hyperparameter search. The repository also relies on optimization/control and neural forecasting components, with plotting and parallel utilities under marl_der/common/plotting.py and marl_der/common/parallel.py. Persistent boundaries are dataset/config directories, exported forecasting artifacts, expert rollouts, and RLlib/Tune checkpoints/results.
Main entry points: environment.py Multi-agent DER simulator · rl_trainables.py PPO/SAC trainables · mpc.py MPC and PID controllers · rl_tuning.py Trial tuning & ranking
Components 20
Data & forecasts
- DER trace generation
data/run_data_generation.py - Scenario configurations · UK and synthetic prosumer environment configurations.
data/datasets/UK_IC/env_config - Forecast training & export · Trains offline RNN forecasts for environment observations.
marl_der/environment/forecasting.py
Microgrid environment
- Multi-agent DER simulator · Episode boundary for observations, actions, dynamics, and termination.
marl_der/environment/environment.py - Environment configuration
marl_der/environment/config.py - Reward composition
marl_der/environment/rewards.py - Gymnasium/RLlib adapters
marl_der/environment/wrappers.py
Expert & imitation
- MPC and PID controllers · Produce battery and thermal-control demonstrations and baselines.
marl_der/expert/mpc.py - Behavior cloning
marl_der/expert/behavior_cloning.py - DAgger · Labels learner-visited states with expert actions.
marl_der/expert/dagger.py - BC weight transfer · Warm-starts PPO/SAC checkpoints from cloned policies.
marl_der/expert/rl_transfer.py
RL training
- RLlib integration · Defines policy/environment specs, callbacks, splits, and history.
marl_der/rl/rl_utils.py - PPO/SAC trainables
marl_der/rl/rl_trainables.py - Trial tuning & ranking
marl_der/rl/rl_tuning.py - Residual policies
marl_der/rl/rl_residual.py - Checkpoint evaluation · Evaluates learned and expert policy modules on a shared contract.
marl_der/rl/rl_evaluation.py
Experiment workflows
- Forecaster training CLI
scripts/training/run_forecaster_training.py - PPO/SAC tuning CLIs
scripts/model_selection/run_ppo_tune.py - DAgger training CLI
scripts/training/run_dagger.py - Comparison & final runs
scripts/training/compare_training_methods.py
Connections 21
- DER trace generation → Scenario configurations: produces traces/config inputs
- Scenario configurations → Environment configuration: supplies scenarios
- Environment configuration → Multi-agent DER simulator: configures
- Forecast training & export → Multi-agent DER simulator: exports observation forecasts
- Reward composition → Multi-agent DER simulator: scores transitions
- Multi-agent DER simulator → Gymnasium/RLlib adapters: adapted for RLlib
- Multi-agent DER simulator → MPC and PID controllers: provides control state
- MPC and PID controllers → Behavior cloning: exports demonstrations
- MPC and PID controllers → DAgger: provides expert labels
- Behavior cloning → BC weight transfer: provides BC weights
- Gymnasium/RLlib adapters → RLlib integration: environment interface
- RLlib integration → PPO/SAC trainables: builds RLlib policies
- PPO/SAC trainables → Trial tuning & ranking: runs trials
- Residual policies → PPO/SAC trainables: extends PPO variants
- BC weight transfer → PPO/SAC trainables: warm-starts policies
- Trial tuning & ranking → Checkpoint evaluation: selects checkpoints
- Multi-agent DER simulator → Checkpoint evaluation: shared rollout contract
- Forecaster training CLI → Forecast training & export: runs
- PPO/SAC tuning CLIs → Trial tuning & ranking: runs PPO/SAC search
- DAgger training CLI → DAgger: runs
- Comparison & final runs → Checkpoint evaluation: compares methods