# benasshauer/drlforpowersystemrecovery architecture

> Architecture diagram of the GitHub repository benasshauer/drlforpowersystemrecovery, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2025-03-30). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/benasshauer/drlforpowersystemrecovery
- Repository: https://github.com/benasshauer/drlforpowersystemrecovery

## Overview

##### Main Components to Highlight
- Environment Module: Focus on the custom gym environment. In the file tree, this is centered in the “rest-gym” package, specifically within the “gym_rest/envs” subdirectory (notably the “rest_env.py” file). This module simulates the power system's depleted state and manages state transitions after actions.
- DRL Agent and Training: The agent interacts with the environment using algorithms from the stable_baselines library. The “rest-gym/main.py” file is an entry point that likely runs training episodes; additionally, the “rest-gym/trained_agents” directory contains pre-trained agents.
- Simulation and Helper Functions: Files such as “network_creator.py” and “pp_helpers.py” likely set up or assist in simulating the power systems using pandapower. They are integral for constructing the network and performing power flow calculations.
- Data Inputs: The “time_series” folder holds CSV files with weather data for renewable energy generation. This data feeds into the simulation to determine the power output of wind and solar plants.
- Visualization / Plots: The “rest-gym/plots” directory (with an archive of images/gifs) indicates that the simulation’s output (e.g., agent decisions during restoration) is visually represented.

##### Relationships and Interactions
- The DRL Agent (using stable_baselines algorithms) sends actions/commands to the custom gym “rest_env”.
- The “rest_env” integrates helper functions (from network_creator.py and pp_helpers.py) to simulate the power network restoration, making use of pandapower for power system calculations.
- The simulation uses weather conditions drawn from the “time_series” CSV files to set the renewable energy outputs, which affect the initial conditions and dynamics.
- The simulation outputs (system state changes, restoration sequences) are recorded and visualized (plots in “rest-gym/plots”), and trained agent checkpoints are saved in “rest-gym/trained_agents”.

##### Architectural Patterns and Technologies
- Modular Design: Separation of concerns is clear—environment simulation, DRL training routines, helper modules, and data inputs are all separate, yet interconnected.
- OpenAI Gym Pattern: The custom environment follows the gym API making it compatible with standard DRL training routines.
- Use of External Libraries: Key libraries like gym, pandapower, stable_baselines, matplotlib, numpy, and pandas are used to structure the simulation, perform calculations, and support training.

## Diagram (Mermaid)

```mermaid
flowchart TD
    subgraph "DRL Agent / Training"
        TM1["Main Entry (main.py)"]:::control
        TM2["Trained Agents Archive"]:::control
    end

    ENV["Custom Gym Environment (rest_env)"]:::simulation
    HELP["Power System Simulation Helpers"]:::simulation
    DATA["Data Input (Weather Time Series)"]:::data
    VIS["Results & Visualization"]:::visualization

    TM1 -->|"actions"| ENV
    ENV -->|"state_update"| TM1
    ENV -->|"helper_calls"| HELP
    HELP -->|"helper_responses"| ENV
    DATA -->|"weather_data"| ENV
    ENV -->|"simulation_output"| VIS

    click ENV "https://github.com/benasshauer/drlforpowersystemrecovery/blob/master/rest-gym/gym_rest/envs/rest_env.py"
    click TM1 "https://github.com/benasshauer/drlforpowersystemrecovery/blob/master/rest-gym/main.py"
    click TM2 "https://github.com/benasshauer/drlforpowersystemrecovery/tree/master/rest-gym/trained_agents"
    click HELP "https://github.com/benasshauer/drlforpowersystemrecovery/blob/master/network_creator.py"
    click HELP "https://github.com/benasshauer/drlforpowersystemrecovery/blob/master/pp_helpers.py"
    click DATA "https://github.com/benasshauer/drlforpowersystemrecovery/blob/master/time_series/ninja_pv_52.4475_13.2080_corrected.csv"
    click DATA "https://github.com/benasshauer/drlforpowersystemrecovery/blob/master/time_series/ninja_wind_52.4475_13.2080_corrected.csv"
    click VIS "https://github.com/benasshauer/drlforpowersystemrecovery/tree/master/rest-gym/plots"
    click VIS "https://github.com/benasshauer/drlforpowersystemrecovery/tree/master/rest-gym/plots/archive"

    classDef control fill:#F9E79F,stroke:#F39C12,stroke-width:2px;
    classDef simulation fill:#AED6F1,stroke:#5DADE2,stroke-width:2px;
    classDef data fill:#A9DFBF,stroke:#28B463,stroke-width:2px;
    classDef visualization fill:#F5B7B1,stroke:#E74C3C,stroke-width:2px;
```
