GargiG15/SOLAR_MICROGRID
0
☀️ SolarMicrogridEnv — OpenEnv-Compliant Solar Energy RL Environment
An OpenEnv-compliant environment simulating a solar-powered microgrid serving multiple homes. An AI agent learns to optimally allocate solar-generated electricity between direct use and battery storage, while reacting to weather patterns and demand peaks.
🌍 Real-World Task
Managing a solar microgrid is a genuine engineering challenge:
- Solar generation is intermittent and weather-dependent
- Home demand peaks at morning and evening hours
- Battery storage has limited capacity and degrades with overuse
- Grid import is costly (especially at peak hours)
- Blackouts cause serious harm to residents
This environment trains agents that could control real residential microgrids, with direct application to home energy management systems (HEMS), virtual power plants (VPPs), and rural electrification projects.
🎯 Tasks
🔧 Action Space
{
"battery_charge_kw": 2.5, // Positive=charge, negative=discharge
"grid_import_kw": 0.0, // Extra power from utility grid
"grid_export_kw": 0.5, // Surplus to sell to grid
"load_priority": [0, 1, 2, 3] // Home priority during shortage
}👁️ Observation Space
{
"hour": 14,
"day": 2,
"solar_generation_kw": 3.2,
"weather": "partly_cloudy",
"battery_soc": 0.65,
"battery_health": 0.998,
"battery_capacity_kwh": 40.0,
"home_demand_kw": [1.2, 0.8, 1.5, 0.9],
"total_demand_kw": 4.4,
"grid_import_kw": 0.0,
"grid_export_kw": 0.0,
"grid_price_per_kwh": 0.12,
"blackout_homes": [],
"solar_forecast": [2.8, 1.5, 0.2],
"demand_forecast": [4.6, 5.2, 4.0],
"episode_step": 32,
"max_steps": 72,
"cumulative_reward": 21.4
}🏆 Reward Function
The reward signal provides partial progress at every step:
🚀 Quick Start
Run locally
# Clone and install
pip install -r requirements.txt
# Run tests
python tests/test_env.py
# Run baseline
python scripts/run_baseline.py
# Start server
python server/app.pyRun with Docker
docker build -t solar-microgrid-env .
docker run -p 7860:7860 solar-microgrid-envAPI Usage
# Reset environment
curl -X POST http://localhost:7860/reset \
-H "Content-Type: application/json" \
-d '{"task": "single_home_basic", "seed": 42}'
# Take a step
curl -X POST http://localhost:7860/step \
-H "Content-Type: application/json" \
-d '{"battery_charge_kw": 2.0, "grid_import_kw": 0.0, "grid_export_kw": 0.5}'
# Get state
curl http://localhost:7860/state
# Get score
curl http://localhost:7860/scoreRun AI agent
# Start server first
python server/app.py &
# Set your API credentials
export HF_TOKEN=hf_your_token
export MODEL_NAME=Qwen/Qwen2.5-72B-Instruct
export SOLAR_TASK=single_home_basic
# Run inference
python inference.py📊 Baseline Scores (Heuristic Policy)
Scores will vary slightly by seed. Run `python scripts/run_baseline.py` to reproduce.
📁 Project Structure
solar_microgrid_env/
├── solar_microgrid_env.py # Core environment (models + physics)
├── graders.py # Task graders (easy/medium/hard)
├── inference.py # OpenAI-client inference script
├── openenv.yaml # OpenEnv metadata
├── requirements.txt
├── Dockerfile
├── server/
│ └── app.py # FastAPI HTTP server
├── tests/
│ └── test_env.py # Full test suite
├── scripts/
│ └── run_baseline.py # Baseline scoring script
└── README.md📝 License
MIT License — free to use for research and training.
