-
Notifications
You must be signed in to change notification settings - Fork 19
/
Copy pathgenerate_sample.py
executable file
·123 lines (104 loc) · 3.81 KB
/
generate_sample.py
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
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
# Copyright (C) 2021, RTE (http://www.rte-france.com/)
# See AUTHORS.txt
# SPDX-License-Identifier: MPL-2.0
import os
import grid2op
from grid2op.operator_attention import LinearAttentionBudget
from grid2op.Agent import TopologyGreedy, DoNothingAgent
from grid2op.Runner import Runner
from grid2op import make,make_from_dataset_path
from CustomAgent import RandomRedispatchAgent, MultipleTopologyAgent, DoNothing_Attention_Agent
from grid2op.Parameters import Parameters
dataset_path = "tests/data/rte_case14_realistic"#"rte_case14_realistic"
# use lightsim2grid to go a lot faster if available
try:
from lightsim2grid.LightSimBackend import LightSimBackend
backend = LightSimBackend()
except:
from grid2op.Backend import PandaPowerBackend
backend = PandaPowerBackend()
print(
"You might need to install the LightSimBackend (provisory name) to gain massive speed up"
)
#
params = Parameters()
params.init_from_dict({"NO_OVERFLOW_DISCONNECTION": True})
params.MAX_SUB_CHANGED = 999 # to have unlimited sub actions at a timestep
params.MAX_LINE_STATUS_CHANGED = 999 # to have unlimited line actions at a timestep
print("MultiTopology")
path_save = "grid2viz/data/agents/multiTopology-baseline"
os.makedirs(path_save, exist_ok=True)
env=make_from_dataset_path(dataset_path, param=params, backend=backend, has_attention_budget=True,
attention_budget_class=LinearAttentionBudget,
kwargs_attention_budget={"max_budget": 3.,
"budget_per_ts": 1. / (12. * 16),
"alarm_cost": 1.,
"init_budget": 2.})
#with make(dataset, param=params, backend=backend) as env:
agent = MultipleTopologyAgent(env.action_space, env.observation_space)
runner = Runner(**env.get_params_for_runner(), agentClass=None, agentInstance=agent)
# need to be seeded for reproducibility as this takes random redispatching actions
runner.run(
nb_episode=1,
path_save="grid2viz/data/agents/multiTopology-baseline",
nb_process=1,
max_iter=30,
env_seeds=[0],
agent_seeds=[0],
pbar=True,
)
#env.close() #problem closing for now: says already closed
print("redispatching")
#with make(dataset, param=params, backend=backend2) as env2:
agent = RandomRedispatchAgent(env.action_space, env)
runner = Runner(**env.get_params_for_runner(), agentClass=None, agentInstance=agent)
# need to be seeded for reproducibility as this takes random redispatching actions
runner.run(
nb_episode=1,
path_save="grid2viz/data/agents/redispatching-baseline",
nb_process=1,
max_iter=100,
env_seeds=[0],
agent_seeds=[0],
pbar=True,
)
#env2.close()
print("do-nothing")
#with make(dataset, param=params, backend=backend) as env:
agent = DoNothingAgent(env.action_space)
runner = Runner(**env.get_params_for_runner(), agentClass=None, agentInstance=agent)
runner.run(
nb_episode=2,
path_save="grid2viz/data/agents/do-nothing-baseline",
nb_process=1,
max_iter=2000,
pbar=True,
)
#env.close()
print("greedy")
#with make(dataset, param=params, backend=backend) as env:
agent = TopologyGreedy(env.action_space)
runner = Runner(**env.get_params_for_runner(), agentClass=None, agentInstance=agent)
runner.run(
nb_episode=2,
path_save="grid2viz/data/agents/greedy-baseline",
nb_process=1,
max_iter=2000,
pbar=True,
)
print("alarm-agent")
agent = DoNothing_Attention_Agent(env)
runner = Runner(
**env.get_params_for_runner(), agentClass=None, agentInstance=agent
)
# need to be seeded for reproducibility as this takes random redispatching actions
runner.run(
nb_episode=1,
path_save="grid2viz/data/agents/alarm-baseline",
nb_process=1,
max_iter=10,
env_seeds=[0],
agent_seeds=[0],
pbar=True,
)
env.close()