-
Notifications
You must be signed in to change notification settings - Fork 3
Feature/Check subsystem graphs in sanity check #24
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
8b4f496
7ed256d
0dab8e3
0d9d625
c90d12b
b896924
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,10 +1,12 @@ | ||
| import json | ||
| import pathlib | ||
| import unittest | ||
|
|
||
| from helpers.gdf_component_creator import GdfTestComponentCreator | ||
|
|
||
| from epowcore.gdf.bus import Bus, LFBusType | ||
| from epowcore.gdf.core_model import CoreModel | ||
| from epowcore.gdf.subsystem import Subsystem | ||
| from epowcore.gdf.utils import get_connected_bus | ||
|
|
||
| PATH = pathlib.Path(__file__).parent.resolve() | ||
|
|
@@ -13,7 +15,6 @@ | |
| class UtilsTest(unittest.TestCase): | ||
| """Test the utility functions of the gdf package.""" | ||
|
|
||
| # @unittest.skip("tmp") | ||
| def test_get_connected_bus(self) -> None: | ||
| core_model = CoreModel(base_frequency=50.0) | ||
|
|
||
|
|
@@ -33,6 +34,83 @@ def test_get_connected_bus(self) -> None: | |
| bus = get_connected_bus(core_model.graph, tline) | ||
| self.assertIn(bus, (bus_a, bus_b)) | ||
|
|
||
| def test_sanity_check_IEEE39(self) -> None: | ||
| path = pathlib.Path(__file__).parent.parent.resolve() | ||
|
|
||
| with open( | ||
| path.parent.parent / "tests/models/gdf/IEEE39_gdf.json", | ||
| "r", | ||
| encoding="utf-8", | ||
| ) as file: | ||
| data_str = file.read() | ||
| data = json.loads(data_str) | ||
| core_model = CoreModel.import_dict(data) | ||
|
|
||
| self.assertFalse(core_model.sanity_check()) | ||
|
|
||
| def test_sanity_check_IEEE39_flat(self) -> None: | ||
| path = pathlib.Path(__file__).parent.parent.resolve() | ||
|
|
||
| with open( | ||
| path.parent.parent / "tests/models/gdf/IEEE39-flat_gdf.json", | ||
| "r", | ||
| encoding="utf-8", | ||
| ) as file: | ||
| data_str = file.read() | ||
| data = json.loads(data_str) | ||
| core_model = CoreModel.import_dict(data) | ||
|
|
||
| self.assertFalse(core_model.sanity_check()) | ||
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. We can keep the old models as a regression test just to make sure, but before merging I would like to generate some new, correct GDF models, with the (hopefully soon) fix in #25 (Issue: #16) and add those as tests as well, were the sanity actually correctly approves on a larger model. The current state of only having sanity check tests on actual models where failure is asserted is IMO not sufficient.
Collaborator
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Keeping the old models as regression tests makes sense, but we should also add tests with newly generated, correct GDF models where the sanity check is expected to pass. At the moment, I’m blocked on generating those models because although my VM is up and running, PowerFactory is no longer working on my side. Once that is resolved, I can generate the new models using the fix from #25 / #16 and add them as additional sanity-check tests. |
||
|
|
||
| def test_sanity_check_valid_subsystem(self) -> None: | ||
| """Sanity check succeeds when a subsystem graph is valid.""" | ||
|
|
||
| creator = GdfTestComponentCreator(50.0) | ||
| core_model = creator.core_model | ||
|
|
||
| tline = creator.create_tline("Line") | ||
| bus_a = creator.create_bus("Bus A") | ||
| bus_b = creator.create_bus("Bus B") | ||
|
|
||
| core_model.add_connection(tline, bus_a, "A", "") | ||
| core_model.add_connection(tline, bus_b, "B", "") | ||
|
|
||
| Subsystem.from_components(core_model, [tline]) | ||
|
|
||
| self.assertTrue(core_model.sanity_check()) | ||
|
|
||
| def test_sanity_check_invalid_subsystem(self) -> None: | ||
| """Sanity check fails when a required connector is missing inside a subsystem.""" | ||
|
|
||
| creator = GdfTestComponentCreator(50.0) | ||
| core_model = creator.core_model | ||
|
|
||
| tline = creator.create_tline("Line") | ||
| bus_a = creator.create_bus("Bus A") | ||
| bus_b = creator.create_bus("Bus B") | ||
|
|
||
| core_model.add_connection(tline, bus_a, "A", "") | ||
| core_model.add_connection(tline, bus_b, "B", "") | ||
|
|
||
| subsystem = Subsystem.from_components(core_model, [tline]) | ||
|
|
||
| port = next(iter(subsystem.graph.neighbors(tline))) | ||
| subsystem.graph.edges[tline, port][tline.uid] = [] | ||
|
|
||
| self.assertFalse(core_model.sanity_check()) | ||
|
|
||
| def test_sanity_check_IEEE399_valid(self) -> None: | ||
| path = pathlib.Path(__file__).parent.parent.resolve() | ||
|
|
||
| with open( | ||
| path.parent.parent / "tests/models/gdf/IEEE399_gdf.json", | ||
| "r", | ||
| encoding="utf-8", | ||
| ) as file: | ||
| data = json.load(file) | ||
| core_model = CoreModel.import_dict(data) | ||
|
|
||
| self.assertTrue(core_model.sanity_check()) | ||
|
|
||
| if __name__ == "__main__": | ||
| unittest.main() | ||
| unittest.main() | ||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I do not understand why this doc string was removed.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Restored the return documentation and updated the docstring to mention recursive subsystem validation.