How future-power-networks/mapdn works
Project Type and Purpose
• This is a research-oriented full-stack Python project implementing a multi-agent reinforcement learning (MARL) environment and training framework for active voltage control in power distribution networks.
• It bundles:
• A multi-agent environment conforming to PyMARL APIs (“environments/…”)
• Implementations of 10 state-of-the-art actor-critic MARL algorithms (“learning_algorithms/…”, “agents/…”, “critics/…”, “models/…”)
• Configuration and orchestration scripts (“args/…”, train.py, test.py, bash wrappers)
• Traditional control baselines in MATLAB (“traditional_control/…”).
File Structure Analysis
Top-Level Directories
• agents/ – agent policy classes
• critics/ – critic networks for centralized or decentralized learning
• learning_algorithms/ – algorithm wrappers (DDPG, PPO, RL base)
• models/ – high-level algorithm implementations and model registry
• environments/ – voltage control environment and barrier functions
• args/ – YAML configs for algorithms and environments
• utilities/ – replay buffer, trainers, testers
• traditional_control/ – MATLAB scripts using MATPOWER
• img/, README.md, train.py, test.py, code_examples.py
Key Patterns
• Modular separation of environment, agent, critic, model, and algorithm
• Registry patterns for models and voltage barrier functions
• Config-driven orchestration via YAML files and CLI scripts
Extracted Architecture Insights
• The core loop: train.py / test.py load YAML configs → instantiate VoltageControl env → select MARL algorithm from models/model_registry → run training/testing via utilities/trainer or tester → save models, logs.
• Agents and critics interact through learning_algorithms decorators, accessing per-agent observations and centralized state (Dec-POMDP).
• Data inputs: time-series data in environments/var_voltage_control/data/<scenario>; MATLAB-based OPF/droop baselines.
• External dependencies: PyTorch/TensorFlow (depending on algorithm), PyMARL API conventions, MATPOWER, Anaconda environments.
Components
a. Environment Layer
• VoltageControl Env (environments/var_voltage_control)
• Data loader (scenario files under data/)
• Voltage barrier registry & functions
b. Agent & Network Layer
• Agent classes (agents/mlp_agent.py, rnn_agent.py variants)
• Critic classes (critics/*.py)
• Models (models/*.py & model_registry)
c. Algorithm Layer
• Learning algorithm wrappers (learning_algorithms/…)
• RL core (actor_critic, rl_algorithms, ppo, ddpg)
d. Orchestration & Configuration
• CLI scripts (train.py, test.py, code_examples.py)
• Config files (args/env_args/*.yaml, args/alg_args/*.yaml)
• Bash wrappers (train_case*.sh)
e. Utilities & Support
• utilities/trainer.py → training loop, gradient updates
• utilities/replay_buffer.py → experience storage
• utilities/tester.py → evaluation pipelines
• utilities/util.py → common helpers
f. Traditional Control (optional view)
• MATLAB scripts (traditional_control/*.m)
• MATPOWER dependency
Relationships and Data Flows
• At runtime, train.py reads algorithm + env config → creates VoltageControl env instance → queries number of agents, action/state spaces → instantiates Agent & Critic networks via model_registry → enters training loop in utilities/trainer → for each step:
1. env.get_obs() / step(actions)
2. collect transitions → replay_buffer
3. sample batch → compute actor/critic losses → backprop via learning_algorithms
4. update model parameters
• Models and logs are saved to disk (--save-path).
• test.py loads saved models, runs evaluation in utilities/tester, optionally renders via rendering_voltage_control_env.py.
Architectural Patterns and Principles
• Modular layering: environment ↔ agent/critic ↔ algorithm wrapper ↔ orchestration scripts
• Registry and factory patterns (model_registry, voltage_barrier_registry) for extensibility
• Config-driven design: YAML files decouple code from parameters
• Separation of concerns: MATLAB baselines isolated under traditional_control