-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtest_grid2op.py
More file actions
60 lines (47 loc) · 1.77 KB
/
test_grid2op.py
File metadata and controls
60 lines (47 loc) · 1.77 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
"""Test script for debugging the Grid2Op environment."""
from envs.grid2op_env import Grid2opEnvWrapper
def test_grid2op_env():
"""Test basic Grid2Op environment functionality."""
# Configuration for the Grid2Op environment
env_config = {
"env_name": "l2rpn_case14_sandbox",
"env_is_test": True,
"act_type": "discrete",
"obs_attr_to_keep": ["rho", "p_or"],
"act_attr_to_keep": ["set_line_status_simple"]
}
print("Creating Grid2Op environment...")
env = Grid2opEnvWrapper(
horizon=100,
gamma=0.99,
render=False,
clip=True,
env_config=env_config
)
print(f"Observation space: {env.observation_space}")
print(f"Action space: {env.action_space}")
print(f"State dim: {env.state_dim}")
print(f"Action dim: {env.action_dim}")
# Reset the environment
print("\nResetting environment...")
obs, info = env.reset()
print(f"Initial observation shape: {obs.shape}")
print(f"Initial observation: {obs[:10]}...") # Print first 10 values
# Run a few steps with random actions
print("\nRunning 10 random steps...")
total_reward = 0
for step in range(10):
# Sample a random action
action = env.action_space.sample()
# Take a step
obs, reward, done, info = env.step(action)
total_reward += reward
print(f"Step {step + 1}: action={action}, reward={reward:.4f}, "
f"done={done}")
if done:
print("Episode ended early!")
obs, info = env.reset()
print(f"\nTotal reward over 10 steps: {total_reward:.4f}")
print("\nGrid2Op environment test completed successfully!")
if __name__ == "__main__":
test_grid2op_env()