How ganmocai/power_gym works
Project Type and Purpose
• This is a research/engineering tool that trains and evaluates a reinforcement-learning (RL) agent (PPO) to manage distributed energy resources (DER) on power distribution networks.
• It combines:
• A custom OpenAI-Gym-style environment (“powergym”) that wraps OpenDSS circuit definitions (in systems/) plus load and EV-demand models.
• An EV-demand generator (ev_demand/ev_demand.py) that produces time-series demand profiles.
• A PPO agent implementation (ppo_agent.py) that drives control actions (e.g., BMS setpoints) and learns from environment feedback.
• Prebuilt circuit definitions and loadshape data under systems/ for various test feeders (13Bus, 123Bus, 34Bus, 8500-Node).
A. Data Sources
• EV Demand Generator: ev_demand/ev_demand.py + CSV inputs in ev_demand/
• Load Profiles & DER Profiles: powergym/loadprofile.py, rate files under systems/*/loadshape/
• Circuit Definitions: .dss files in systems/13Bus, 123Bus, 34Bus, 8500-Node/
B. Simulation Environment (“powergym”)
• env.py: the Gym environment interface (step(), reset())
• circuit.py: OpenDSS API wrapper to load and solve circuits
• ev_bms.py: battery management system model for each DER
• env_register.py: Gym registration and configuration
C. RL Agent (ppo_agent.py)
• Policy network and training loop (collect batches, compute rewards, backprop)
• Interfaces to Gym (action selection, state ingestion)
D. Visualization & Analysis
• Plots: generated PDFs and scripts under plots/ppo_model/
• convert_freq.py: utility to process time-series frequency or power data
Relationships and Data Flow
• EV Demand Generator produces time-series profiles → fed into Gym environment as part of observation.
• powergym.env uses circuit.py to load a chosen system’s .dss files and loadshape CSVs, builds the simulation model.
• ppo_agent interacts with env:
action ← policy(state) → env.step(action) → next_state, reward → policy update
• env.step() calls circuit.solutions via OpenDSS, applies control from ev_bms, returns voltages, power flows, rewards.
• Training logs & performance plots are saved under plots/ppo_model/.
Architectural Patterns and Principles
• Modular separation:
• Data generation (ev_demand)
• Simulation core (powergym)
• Learning algorithm (ppo_agent)
• Visualization (plots/)
• Clear API boundaries: Gym’s step/reset interface shields agent from low-level OpenDSS calls.
• Extensibility: New circuits can be added under systems/ without changing code.
Checklist
• [ ] Clear component names matching file-tree modules
• [ ] Labels for interfaces (Gym API, OpenDSS API)