Skip to content

Commit 6707cc2

Browse files
committed
fixing a missing copy in the constructor and add some tests for leap net
1 parent 6fe917c commit 6707cc2

File tree

2 files changed

+30
-5
lines changed

2 files changed

+30
-5
lines changed

leap_net/proxy/baseProxy.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -701,7 +701,7 @@ def _get_adds_mults_from_name(self, obss, attr_nm):
701701
elif attr_nm in ["a_or", "a_ex"]:
702702
add_tmp = self.dtype(0.) # because i multiply by the line status, so i don't want any bias
703703
if hasattr(obs, "thermal_limit"):
704-
mult_tmp = obs.thermal_limit
704+
mult_tmp = 1.0 * obs.thermal_limit
705705
elif hasattr(obs, "rho"):
706706
mult_tmp = np.abs(obs.a_or / (obs.rho + 1e-2)) # which is equal to the thermal limit
707707
else:

leap_net/test/test_LeapNetProxy.py

Lines changed: 29 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -215,7 +215,9 @@ def _aux_test_tau_from_list_topo(self, proxy=None):
215215
proxy = ProxyLeapNet(attr_tau=("line_status", "topo_vect",),
216216
topo_vect_to_tau="given_list",
217217
kwargs_tau=[(0, (2, 1, 1)), (0, (1, 2, 1)), (1, (2, 1, 1, 1, 1, 1)),
218-
(12, (2, 1, 1, 2)), (13, (2, 1, 2)), (13, (1, 2, 2))]
218+
(12, (2, 1, 1, 2)), (13, (2, 1, 2)), (13, (1, 2, 2)),
219+
(1, (2, 1, 2, 1, 2, 1))
220+
]
219221
)
220222
proxy.init([self.obs])
221223

@@ -258,7 +260,7 @@ def _aux_test_tau_from_list_topo(self, proxy=None):
258260
res = proxy.topo_vect_handler(obs)
259261
assert np.sum(res) == 0
260262

261-
# test that everything on bys 2 and everything on bus 1 leads to the same result
263+
# test that everything on bus 2 and everything on bus 1 leads to the same result
262264
obs = env.reset()
263265
act = env.action_space({"set_bus": {"substations_id": [(12, (2, 2, 2, 2))]}})
264266
obs, reward, done, info = env.step(act)
@@ -271,7 +273,7 @@ def _aux_test_tau_from_list_topo(self, proxy=None):
271273
res = proxy.topo_vect_handler(obs)
272274
assert np.sum(res) == 0
273275

274-
# check the symmetry 2 <-> 1
276+
# check cumulative "actions"
275277
obs = env.reset()
276278
act = env.action_space({"set_bus": {"substations_id": [(0, (2, 1, 1))]}})
277279
obs, reward, done, info = env.step(act)
@@ -282,7 +284,7 @@ def _aux_test_tau_from_list_topo(self, proxy=None):
282284
assert res[0] == 1.
283285
assert res[4] == 1.
284286

285-
# test the symmetry (gain...) why not
287+
# test the symmetry (again...) why not
286288
obs = env.reset()
287289
act = env.action_space({"set_bus": {"substations_id": [(0, (2, 2, 2))]}})
288290
obs, reward, done, info = env.step(act)
@@ -295,7 +297,30 @@ def _aux_test_tau_from_list_topo(self, proxy=None):
295297
res = proxy.topo_vect_handler(obs)
296298
assert np.sum(res) == 1
297299
assert res[2] == 1.
300+
301+
obs = env.reset()
302+
act = env.action_space({"set_bus": {"substations_id": [(12, (1, 2, 2, 1))]}})
303+
obs, reward, done, info = env.step(act)
304+
res = proxy.topo_vect_handler(obs)
305+
assert np.sum(res) == 1
306+
assert res[3] == 1.
298307

308+
# test that if a line is disconnected, we are still able to match the topologies
309+
# see https://github.com/BDonnot/leap_net/pull/12/files
310+
obs = env.reset()
311+
act = env.action_space({"set_bus": {"substations_id": [(1, (2, 1, -1, 1, 2, 1))]}}) # (2, 1, 2, 1, 2, 1)
312+
obs, reward, done, info = env.step(act)
313+
res = proxy.topo_vect_handler(obs)
314+
assert np.sum(res) == 1
315+
assert res[6] == 1.
316+
317+
obs = env.reset()
318+
act = env.action_space({"set_bus": {"substations_id": [(1, (2, -1, 2, 1, 2, 1))]}}) # (2, 1, 2, 1, 2, 1)
319+
obs, reward, done, info = env.step(act)
320+
res = proxy.topo_vect_handler(obs)
321+
assert np.sum(res) == 1
322+
assert res[6] == 1.
323+
299324
def test_tau_from_online_topo(self):
300325
self._aux_test_tau_from_online_topo()
301326

0 commit comments

Comments
 (0)