Views
No views yet
1from gymnasium_wrapper import PowerGridGymEnv
2
3# Initialize the environment (Ensure server is running on port 8001)
4env = PowerGridGymEnv(endpoint="http://localhost:8001")
5
6obs, info = env.reset()
7print(f"Initial State: {obs}")
8
9# Take a step with a random action (0: Solar, 1: Wind, 2: Battery)
10action = env.action_space.sample()
11obs, reward, terminated, truncated, info = env.step(action)
12
13print(f"Action Taken: {action} | Reward: {reward}")
14
15🛠️ Installation & Setup
161. Install Dependencies
17Ensure you have your virtual environment active, then run:
18
19Bash
20pip install -r requirements.txt
21
222. Run the Environment ServerStart the FastAPI/OpenEnv server to host the simulation:Bash# Windows (PowerShell)
23$env:PYTHONPATH = "."
24python -m server.app --port 8001
25
26# Linux/Mac
27PYTHONPATH=. python3 -m server.app --port 8001
28
293. Run the AI Stability Test
30In a second terminal, run the training script to verify the RL loop:
31
32Bash
33
34python train.py
35📊 Environment Details
36
37Action Space: Discrete(3)
38Value Action Description
390 Toggle Solar Activates/Deactivates Solar panel arrays
401 Toggle Wind Activates/Deactivates Wind turbine clusters
412 Toggle Battery Switches between Charging/Discharging states
42
43Observation
44
45Space: Box(3)
46
47Index Feature Unit
480 Demand Met Boolean (1.0 = Yes, 0.0 = No)
491 Carbon FootprintMetric Tons (Lower is better)
502 Grid Stability 1.0 = Stable, 0.0 = Unstable
51
52
53Reward Function
54
55The agent is rewarded for maintaining a stable grid while reducing emissions:
56
57Success: $+1.0$ (Demand met with 0 carbon)Sustainability Penalty: Reward is scaled by carbon footprint: $1.0 - (Carbon \times 0.5)$Failure: $-1.0$ (Grid blackout/demand not met)
58
59🐳 Docker Support
60Building the Image
61
62Bash
63docker build -t industrial_power_grid-env:latest -f server/Dockerfile .
64
65Deploying to Hugging Face Spaces
66
67Bash
68
69openenv push --repo-id your-username/industrial-power-grid --private
70
71
72📡 API Documentation
73Once the server is running, you can explore the interactive API docs at:
74
75http://localhost:8001/docs
76
77## Project Structure
78