Skip to content

Commit

Permalink
fixing broken imports after renaming
Browse files Browse the repository at this point in the history
  • Loading branch information
BDonnot committed Jan 10, 2024
1 parent cbe0b1b commit b5646dd
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 27 deletions.
30 changes: 15 additions & 15 deletions lightsim2grid/tests/test_SecurityAnlysis.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
import numpy as np
import grid2op

from lightsim2grid import SecurityAnalysis
from lightsim2grid import ContingencyAnalysis
from lightsim2grid import LightSimBackend
import warnings
import pdb
Expand All @@ -28,10 +28,10 @@ def tearDown(self) -> None:
return super().tearDown()

def test_can_create(self):
sa = SecurityAnalysis(self.env)
sa = ContingencyAnalysis(self.env)

def test_clear(self):
sa = SecurityAnalysis(self.env)
sa = ContingencyAnalysis(self.env)

# add simple contingencies
sa.add_multiple_contingencies(0, 1, 2, 3)
Expand All @@ -46,7 +46,7 @@ def test_clear(self):
assert len(sa._contingency_order) == 0

def test_add_single_contingency(self):
sa = SecurityAnalysis(self.env)
sa = ContingencyAnalysis(self.env)
with self.assertRaises(RuntimeError):
sa.add_single_contingency("toto")
with self.assertRaises(RuntimeError):
Expand All @@ -64,7 +64,7 @@ def test_add_single_contingency(self):
assert len(sa._contingency_order) == 4

def test_add_multiple_contingencies(self):
sa = SecurityAnalysis(self.env)
sa = ContingencyAnalysis(self.env)
# add simple contingencies
sa.add_multiple_contingencies(0, 1, 2, 3)
all_conts = sa.computer.my_defaults()
Expand All @@ -91,7 +91,7 @@ def test_add_multiple_contingencies(self):
assert len(sa._contingency_order) == 4

def test_add_all_n1_contingencies(self):
sa = SecurityAnalysis(self.env)
sa = ContingencyAnalysis(self.env)
sa.add_all_n1_contingencies()
all_conts = sa.computer.my_defaults()
assert len(all_conts) == self.env.n_line
Expand All @@ -100,7 +100,7 @@ def test_add_all_n1_contingencies(self):
def test_get_flows_simple(self):
"""test the get_flows method in the most simplest way: ask for all contingencies,
contingencies are given in the right order"""
sa = SecurityAnalysis(self.env)
sa = ContingencyAnalysis(self.env)
sa.add_multiple_contingencies(0, 1, 2)
res_p, res_a, res_v = sa.get_flows()
assert res_a.shape == (3, self.env.n_line)
Expand All @@ -111,7 +111,7 @@ def test_get_flows_simple(self):
def test_get_flows_1(self):
"""test the get_flows method: ask for all contingencies ,
contingencies are NOT given in the right order"""
sa = SecurityAnalysis(self.env)
sa = ContingencyAnalysis(self.env)
sa.add_multiple_contingencies(0, 2, 1)
res_p, res_a, res_v = sa.get_flows()
assert res_a.shape == (3, self.env.n_line)
Expand All @@ -122,7 +122,7 @@ def test_get_flows_1(self):
def test_get_flows_2(self):
"""test the get_flows method: don't ask for all contingencies (same order as given),
contingencies are given in the right order"""
sa = SecurityAnalysis(self.env)
sa = ContingencyAnalysis(self.env)
sa.add_multiple_contingencies(0, 1, 2)
res_p, res_a, res_v = sa.get_flows(0, 1)
assert res_a.shape == (2, self.env.n_line)
Expand All @@ -132,7 +132,7 @@ def test_get_flows_2(self):
def test_get_flows_3(self):
"""test the get_flows method in the most simplest way: not all contingencies (not same order as given),
contingencies are given in the right order"""
sa = SecurityAnalysis(self.env)
sa = ContingencyAnalysis(self.env)
sa.add_multiple_contingencies(0, 1, 2)
res_p, res_a, res_v = sa.get_flows(0, 2)
assert res_a.shape == (2, self.env.n_line)
Expand All @@ -142,7 +142,7 @@ def test_get_flows_3(self):
def test_get_flows_4(self):
"""test the get_flows method: don't ask for all contingencies (same order as given),
contingencies are NOT given in the right order"""
sa = SecurityAnalysis(self.env)
sa = ContingencyAnalysis(self.env)
sa.add_multiple_contingencies(0, 2, 1)
res_p, res_a, res_v = sa.get_flows(0, 2)
assert res_a.shape == (2, self.env.n_line)
Expand All @@ -152,7 +152,7 @@ def test_get_flows_4(self):
def test_get_flows_5(self):
"""test the get_flows method in the most simplest way: not all contingencies (not same order as given),
contingencies are NOT given in the right order"""
sa = SecurityAnalysis(self.env)
sa = ContingencyAnalysis(self.env)
sa.add_multiple_contingencies(0, 2, 1)
res_p, res_a, res_v = sa.get_flows(0, 1)
assert res_a.shape == (2, self.env.n_line)
Expand All @@ -161,7 +161,7 @@ def test_get_flows_5(self):

def test_get_flows_multiple(self):
"""test the get_flows function when multiple contingencies"""
sa = SecurityAnalysis(self.env)
sa = ContingencyAnalysis(self.env)
sa.add_multiple_contingencies(0, [0, 4], [5, 7], 4)

# everything
Expand Down Expand Up @@ -197,11 +197,11 @@ def test_get_flows_multiple(self):

def test_change_injection(self):
"""test the capacity of the things to handle different steps"""
sa1 = SecurityAnalysis(self.env)
sa1 = ContingencyAnalysis(self.env)
conts = [0, [0, 4], [5, 7], 4]
sa1.add_multiple_contingencies(*conts)
self.env.reset()
sa2 = SecurityAnalysis(self.env)
sa2 = ContingencyAnalysis(self.env)
sa2.add_multiple_contingencies(*conts)

res_p1, res_a1, res_v1 = sa1.get_flows()
Expand Down
24 changes: 12 additions & 12 deletions lightsim2grid/tests/test_SecurityAnlysis_cpp.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
import numpy as np
import grid2op

from lightsim2grid_cpp import SecurityAnalysisCPP
from lightsim2grid_cpp import ContingencyAnalysisCPP
from lightsim2grid import LightSimBackend
import warnings
import pdb
Expand All @@ -29,11 +29,11 @@ def tearDown(self) -> None:
return super().tearDown()

def test_can_create(self):
SA = SecurityAnalysisCPP(self.env.backend._grid)
SA = ContingencyAnalysisCPP(self.env.backend._grid)
assert len(SA.my_defaults()) == 0

def test_add_n1(self):
SA = SecurityAnalysisCPP(self.env.backend._grid)
SA = ContingencyAnalysisCPP(self.env.backend._grid)
SA.add_n1(0)
all_def = SA.my_defaults()
assert len(all_def) == 1
Expand Down Expand Up @@ -64,7 +64,7 @@ def test_add_n1(self):
SA.add_n1(20)

def test_add_multiple_n1(self):
SA = SecurityAnalysisCPP(self.env.backend._grid)
SA = ContingencyAnalysisCPP(self.env.backend._grid)
SA.add_multiple_n1([0])
all_def = SA.my_defaults()
assert len(all_def) == 1
Expand Down Expand Up @@ -99,7 +99,7 @@ def test_add_multiple_n1(self):
SA.add_multiple_n1([20])

def test_add_nk(self):
SA = SecurityAnalysisCPP(self.env.backend._grid)
SA = ContingencyAnalysisCPP(self.env.backend._grid)
SA.add_nk([0])
all_def = SA.my_defaults()
assert len(all_def) == 1
Expand Down Expand Up @@ -132,13 +132,13 @@ def test_add_nk(self):
SA.add_nk([20])

def test_add_all_n1(self):
SA = SecurityAnalysisCPP(self.env.backend._grid)
SA = ContingencyAnalysisCPP(self.env.backend._grid)
SA.add_all_n1()
all_def = SA.my_defaults()
assert len(all_def) == self.env.n_line

def test_remove_n1(self):
SA = SecurityAnalysisCPP(self.env.backend._grid)
SA = ContingencyAnalysisCPP(self.env.backend._grid)
SA.add_all_n1()
assert SA.remove_n1(0) # this should remove it and return true (because the removing is a success)
all_def = SA.my_defaults()
Expand All @@ -148,7 +148,7 @@ def test_remove_n1(self):
assert len(all_def) == self.env.n_line - 1

def test_clear(self):
SA = SecurityAnalysisCPP(self.env.backend._grid)
SA = ContingencyAnalysisCPP(self.env.backend._grid)
SA.add_all_n1()
all_def = SA.my_defaults()
assert len(all_def) == self.env.n_line
Expand All @@ -157,7 +157,7 @@ def test_clear(self):
assert len(all_def) == 0

def test_remove_multiple_n1(self):
SA = SecurityAnalysisCPP(self.env.backend._grid)
SA = ContingencyAnalysisCPP(self.env.backend._grid)
SA.add_all_n1()
nb_removed = SA.remove_multiple_n1([0, 1, 2])
assert nb_removed == 3
Expand All @@ -169,7 +169,7 @@ def test_remove_multiple_n1(self):
assert len(all_def) == self.env.n_line - 5

def test_remove_nk(self):
SA = SecurityAnalysisCPP(self.env.backend._grid)
SA = ContingencyAnalysisCPP(self.env.backend._grid)
SA.add_nk([0, 1])
SA.add_nk([0, 2])
SA.add_nk([0, 3])
Expand All @@ -188,7 +188,7 @@ def test_remove_nk(self):
assert len(all_def) == 2

def test_compute(self):
SA = SecurityAnalysisCPP(self.env.backend._grid)
SA = ContingencyAnalysisCPP(self.env.backend._grid)
lid_cont = [0, 1, 2, 3]
nb_sub = self.env.n_sub
SA.add_multiple_n1(lid_cont)
Expand All @@ -207,7 +207,7 @@ def test_compute(self):
assert np.max(np.abs(res_flows[cont_id] - sim_obs.a_or*1e-3)) <= 1e-6, f"error in flows when disconnecting line {l_id} (contingency nb {cont_id})"

def test_compute_nonconnected_graph(self):
SA = SecurityAnalysisCPP(self.env.backend._grid)
SA = ContingencyAnalysisCPP(self.env.backend._grid)
lid_cont = [17, 18, 19] # 17 is ok, 18 lead to divergence, i need to check then that 19 is correct (no divergence)
nb_sub = self.env.n_sub
SA.add_multiple_n1(lid_cont)
Expand Down

0 comments on commit b5646dd

Please sign in to comment.