From 9e5c756d9356528e144ff790f5b03ab33275419e Mon Sep 17 00:00:00 2001 From: ahalev Date: Tue, 22 Nov 2022 15:13:32 -0500 Subject: [PATCH 01/26] refactor modules to src/pymgrid/modules --- .../{microgrid/modules/base/timeseries => forecast}/__init__.py | 0 .../{microgrid/modules/base/timeseries => forecast}/forecaster.py | 0 src/pymgrid/{microgrid => }/modules/base/__init__.py | 0 src/pymgrid/{microgrid => }/modules/base/base_module.py | 0 src/pymgrid/modules/base/timeseries/__init__.py | 0 .../modules/base/timeseries/base_timeseries_module.py | 0 src/pymgrid/{microgrid => }/modules/battery_module.py | 0 src/pymgrid/{microgrid => }/modules/genset_module.py | 0 src/pymgrid/{microgrid => }/modules/grid_module.py | 0 src/pymgrid/{microgrid => }/modules/load_module.py | 0 src/pymgrid/{microgrid => }/modules/module_container.py | 0 src/pymgrid/{microgrid => }/modules/renewable_module.py | 0 src/pymgrid/{microgrid => }/modules/unbalanced_energy_module.py | 0 13 files changed, 0 insertions(+), 0 deletions(-) rename src/pymgrid/{microgrid/modules/base/timeseries => forecast}/__init__.py (100%) rename src/pymgrid/{microgrid/modules/base/timeseries => forecast}/forecaster.py (100%) rename src/pymgrid/{microgrid => }/modules/base/__init__.py (100%) rename src/pymgrid/{microgrid => }/modules/base/base_module.py (100%) create mode 100644 src/pymgrid/modules/base/timeseries/__init__.py rename src/pymgrid/{microgrid => }/modules/base/timeseries/base_timeseries_module.py (100%) rename src/pymgrid/{microgrid => }/modules/battery_module.py (100%) rename src/pymgrid/{microgrid => }/modules/genset_module.py (100%) rename src/pymgrid/{microgrid => }/modules/grid_module.py (100%) rename src/pymgrid/{microgrid => }/modules/load_module.py (100%) rename src/pymgrid/{microgrid => }/modules/module_container.py (100%) rename src/pymgrid/{microgrid => }/modules/renewable_module.py (100%) rename src/pymgrid/{microgrid => }/modules/unbalanced_energy_module.py (100%) diff --git a/src/pymgrid/microgrid/modules/base/timeseries/__init__.py b/src/pymgrid/forecast/__init__.py similarity index 100% rename from src/pymgrid/microgrid/modules/base/timeseries/__init__.py rename to src/pymgrid/forecast/__init__.py diff --git a/src/pymgrid/microgrid/modules/base/timeseries/forecaster.py b/src/pymgrid/forecast/forecaster.py similarity index 100% rename from src/pymgrid/microgrid/modules/base/timeseries/forecaster.py rename to src/pymgrid/forecast/forecaster.py diff --git a/src/pymgrid/microgrid/modules/base/__init__.py b/src/pymgrid/modules/base/__init__.py similarity index 100% rename from src/pymgrid/microgrid/modules/base/__init__.py rename to src/pymgrid/modules/base/__init__.py diff --git a/src/pymgrid/microgrid/modules/base/base_module.py b/src/pymgrid/modules/base/base_module.py similarity index 100% rename from src/pymgrid/microgrid/modules/base/base_module.py rename to src/pymgrid/modules/base/base_module.py diff --git a/src/pymgrid/modules/base/timeseries/__init__.py b/src/pymgrid/modules/base/timeseries/__init__.py new file mode 100644 index 00000000..e69de29b diff --git a/src/pymgrid/microgrid/modules/base/timeseries/base_timeseries_module.py b/src/pymgrid/modules/base/timeseries/base_timeseries_module.py similarity index 100% rename from src/pymgrid/microgrid/modules/base/timeseries/base_timeseries_module.py rename to src/pymgrid/modules/base/timeseries/base_timeseries_module.py diff --git a/src/pymgrid/microgrid/modules/battery_module.py b/src/pymgrid/modules/battery_module.py similarity index 100% rename from src/pymgrid/microgrid/modules/battery_module.py rename to src/pymgrid/modules/battery_module.py diff --git a/src/pymgrid/microgrid/modules/genset_module.py b/src/pymgrid/modules/genset_module.py similarity index 100% rename from src/pymgrid/microgrid/modules/genset_module.py rename to src/pymgrid/modules/genset_module.py diff --git a/src/pymgrid/microgrid/modules/grid_module.py b/src/pymgrid/modules/grid_module.py similarity index 100% rename from src/pymgrid/microgrid/modules/grid_module.py rename to src/pymgrid/modules/grid_module.py diff --git a/src/pymgrid/microgrid/modules/load_module.py b/src/pymgrid/modules/load_module.py similarity index 100% rename from src/pymgrid/microgrid/modules/load_module.py rename to src/pymgrid/modules/load_module.py diff --git a/src/pymgrid/microgrid/modules/module_container.py b/src/pymgrid/modules/module_container.py similarity index 100% rename from src/pymgrid/microgrid/modules/module_container.py rename to src/pymgrid/modules/module_container.py diff --git a/src/pymgrid/microgrid/modules/renewable_module.py b/src/pymgrid/modules/renewable_module.py similarity index 100% rename from src/pymgrid/microgrid/modules/renewable_module.py rename to src/pymgrid/modules/renewable_module.py diff --git a/src/pymgrid/microgrid/modules/unbalanced_energy_module.py b/src/pymgrid/modules/unbalanced_energy_module.py similarity index 100% rename from src/pymgrid/microgrid/modules/unbalanced_energy_module.py rename to src/pymgrid/modules/unbalanced_energy_module.py From fbd487d2fe41cbdcbd53852579aec538deaab1d9 Mon Sep 17 00:00:00 2001 From: ahalev Date: Tue, 22 Nov 2022 15:15:45 -0500 Subject: [PATCH 02/26] update import in README --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index cd9b743f..a694e533 100644 --- a/README.md +++ b/README.md @@ -29,7 +29,7 @@ to a microgrid: ```python import numpy as np from pymgrid import Microgrid -from pymgrid.microgrid.modules import GensetModule, BatteryModule, LoadModule, RenewableModule +from pymgrid.modules import GensetModule, BatteryModule, LoadModule, RenewableModule genset = GensetModule(running_min_production=10, From e989a76423b2441c19c675b204d9579d09a9bdb4 Mon Sep 17 00:00:00 2001 From: ahalev Date: Tue, 22 Nov 2022 15:16:21 -0500 Subject: [PATCH 03/26] add module __init__ --- src/pymgrid/modules/__init__.py | 8 ++++++++ 1 file changed, 8 insertions(+) create mode 100644 src/pymgrid/modules/__init__.py diff --git a/src/pymgrid/modules/__init__.py b/src/pymgrid/modules/__init__.py new file mode 100644 index 00000000..c3fda508 --- /dev/null +++ b/src/pymgrid/modules/__init__.py @@ -0,0 +1,8 @@ +from .battery_module import BatteryModule +from .genset_module import GensetModule +from .grid_module import GridModule +from .load_module import LoadModule +from .renewable_module import RenewableModule +from .unbalanced_energy_module import UnbalancedEnergyModule + +from .module_container import ModuleContainer From 751bd800d2492abe8c7eddb17ae84b97bd723eb5 Mon Sep 17 00:00:00 2001 From: ahalev Date: Tue, 22 Nov 2022 15:17:24 -0500 Subject: [PATCH 04/26] update demo notebook --- notebooks/modular_microgrid_demo.ipynb | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/notebooks/modular_microgrid_demo.ipynb b/notebooks/modular_microgrid_demo.ipynb index 63b757ed..32852231 100644 --- a/notebooks/modular_microgrid_demo.ipynb +++ b/notebooks/modular_microgrid_demo.ipynb @@ -9,7 +9,7 @@ "source": [ "from pymgrid.MicrogridGenerator import MicrogridGenerator\n", "from pymgrid import Microgrid\n", - "from pymgrid.microgrid.modules import *\n", + "from pymgrid.modules import *\n", "import numpy as np\n" ] }, @@ -1010,7 +1010,7 @@ "text": [ "\n", "_modules\n", - "{'fixed': {'sources': {'genset': []}, 'sinks': {'load': []}, 'source_and_sinks': {'battery': []}}, 'sources': {'fixed': {'genset': []}, 'flex': {'PV': []}}, 'sinks': {'fixed': {'load': []}, 'flex': {}}, 'source_and_sinks': {'fixed': {'battery': []}, 'flex': {'unbalanced_energy': []}}, 'flex': {'sources': {'PV': []}, 'sinks': {}, 'source_and_sinks': {'unbalanced_energy': []}}}\n", + "{'fixed': {'sources': {'genset': []}, 'sinks': {'load': []}, 'source_and_sinks': {'battery': []}}, 'sources': {'fixed': {'genset': []}, 'flex': {'PV': []}}, 'sinks': {'fixed': {'load': []}, 'flex': {}}, 'source_and_sinks': {'fixed': {'battery': []}, 'flex': {'unbalanced_energy': []}}, 'flex': {'sources': {'PV': []}, 'sinks': {}, 'source_and_sinks': {'unbalanced_energy': []}}}\n", "\n", "_balance_logger\n", "{}\n" From 274eb46f61c8a1a12b94ad8a15a37763776839c7 Mon Sep 17 00:00:00 2001 From: ahalev Date: Tue, 22 Nov 2022 15:19:13 -0500 Subject: [PATCH 05/26] move forecast to new dir --- src/pymgrid/forecast/__init__.py | 1 + 1 file changed, 1 insertion(+) diff --git a/src/pymgrid/forecast/__init__.py b/src/pymgrid/forecast/__init__.py index e69de29b..05be0939 100644 --- a/src/pymgrid/forecast/__init__.py +++ b/src/pymgrid/forecast/__init__.py @@ -0,0 +1 @@ +from .forecaster import get_forecaster, OracleForecaster, GaussianNoiseForecaster, UserDefinedForecaster, NoForecaster \ No newline at end of file From 5e2df86ac5c03171e31ea57036160c6c2d94c6e9 Mon Sep 17 00:00:00 2001 From: ahalev Date: Tue, 22 Nov 2022 15:19:26 -0500 Subject: [PATCH 06/26] refactor forecast and module imports --- src/pymgrid/microgrid/convert/get_module.py | 2 +- src/pymgrid/microgrid/convert/to_nonmodular_ops.py | 2 +- .../microgrid/modular_microgrid/modular_microgrid.py | 3 +-- src/pymgrid/microgrid/modules/__init__.py | 7 +------ src/pymgrid/modules/base/__init__.py | 4 ++-- .../modules/base/timeseries/base_timeseries_module.py | 8 ++++---- src/pymgrid/modules/battery_module.py | 2 +- src/pymgrid/modules/genset_module.py | 2 +- src/pymgrid/modules/grid_module.py | 2 +- src/pymgrid/modules/load_module.py | 2 +- src/pymgrid/modules/module_container.py | 2 +- src/pymgrid/modules/renewable_module.py | 2 +- src/pymgrid/modules/unbalanced_energy_module.py | 2 +- 13 files changed, 17 insertions(+), 23 deletions(-) diff --git a/src/pymgrid/microgrid/convert/get_module.py b/src/pymgrid/microgrid/convert/get_module.py index cbe17e99..2409b713 100644 --- a/src/pymgrid/microgrid/convert/get_module.py +++ b/src/pymgrid/microgrid/convert/get_module.py @@ -1,5 +1,5 @@ import pandas as pd -from pymgrid.microgrid.modules import LoadModule, RenewableModule, BatteryModule, GridModule, GensetModule, UnbalancedEnergyModule +from pymgrid.modules import LoadModule, RenewableModule, BatteryModule, GridModule, GensetModule, UnbalancedEnergyModule def get_module(component, nonmodular, raise_errors): diff --git a/src/pymgrid/microgrid/convert/to_nonmodular_ops.py b/src/pymgrid/microgrid/convert/to_nonmodular_ops.py index 4b703b78..c6a3f3f3 100644 --- a/src/pymgrid/microgrid/convert/to_nonmodular_ops.py +++ b/src/pymgrid/microgrid/convert/to_nonmodular_ops.py @@ -1,4 +1,4 @@ -from pymgrid.microgrid.modules import LoadModule, RenewableModule, BatteryModule, GridModule, GensetModule, UnbalancedEnergyModule +from pymgrid.modules import LoadModule, RenewableModule, BatteryModule, GridModule, GensetModule, UnbalancedEnergyModule from copy import deepcopy import pandas as pd import numpy as np diff --git a/src/pymgrid/microgrid/modular_microgrid/modular_microgrid.py b/src/pymgrid/microgrid/modular_microgrid/modular_microgrid.py index d058a654..7e5541fc 100644 --- a/src/pymgrid/microgrid/modular_microgrid/modular_microgrid.py +++ b/src/pymgrid/microgrid/modular_microgrid/modular_microgrid.py @@ -6,8 +6,7 @@ from warnings import warn from pymgrid.microgrid import DEFAULT_HORIZON -from pymgrid.microgrid.modules import * -from pymgrid.microgrid.modules.module_container import ModuleContainer +from pymgrid.modules import ModuleContainer, UnbalancedEnergyModule from pymgrid.microgrid.utils.logger import ModularLogger from pymgrid.microgrid.utils.step import MicrogridStep from pymgrid.microgrid.utils.serialize import add_numpy_pandas_representers, add_numpy_pandas_constructors, dump_data diff --git a/src/pymgrid/microgrid/modules/__init__.py b/src/pymgrid/microgrid/modules/__init__.py index fc69d927..8b137891 100644 --- a/src/pymgrid/microgrid/modules/__init__.py +++ b/src/pymgrid/microgrid/modules/__init__.py @@ -1,6 +1 @@ -from .battery_module import BatteryModule -from .renewable_module import RenewableModule -from .load_module import LoadModule -from .unbalanced_energy_module import UnbalancedEnergyModule -from .grid_module import GridModule -from .genset_module import GensetModule + diff --git a/src/pymgrid/modules/base/__init__.py b/src/pymgrid/modules/base/__init__.py index c2922879..2a1e3bc5 100644 --- a/src/pymgrid/modules/base/__init__.py +++ b/src/pymgrid/modules/base/__init__.py @@ -1,2 +1,2 @@ -from pymgrid.microgrid.modules.base.base_module import BaseMicrogridModule -from pymgrid.microgrid.modules.base.timeseries.base_timeseries_module import BaseTimeSeriesMicrogridModule \ No newline at end of file +from .base_module import BaseMicrogridModule +from .timeseries.base_timeseries_module import BaseTimeSeriesMicrogridModule diff --git a/src/pymgrid/modules/base/timeseries/base_timeseries_module.py b/src/pymgrid/modules/base/timeseries/base_timeseries_module.py index dd73637b..e4d88dff 100644 --- a/src/pymgrid/modules/base/timeseries/base_timeseries_module.py +++ b/src/pymgrid/modules/base/timeseries/base_timeseries_module.py @@ -1,9 +1,9 @@ -from abc import ABC, abstractmethod +from abc import abstractmethod import numpy as np from pymgrid.microgrid import DEFAULT_HORIZON -from pymgrid.microgrid.modules.base import BaseMicrogridModule -from pymgrid.microgrid.modules.base.timeseries.forecaster import get_forecaster +from pymgrid.modules.base import BaseMicrogridModule +from pymgrid.forecast.forecaster import get_forecaster class BaseTimeSeriesMicrogridModule(BaseMicrogridModule): @@ -107,7 +107,7 @@ def forecast_horizon(self, value): self._forecast_horizon = value else: from warnings import warn - from pymgrid.microgrid.modules.base.timeseries.forecaster import OracleForecaster + from pymgrid.forecast.forecaster import OracleForecaster warn("Setting forecast_horizon requires a non-null forecaster. Implementing OracleForecaster.") self.forecaster = OracleForecaster() self._forecast_horizon = value diff --git a/src/pymgrid/modules/battery_module.py b/src/pymgrid/modules/battery_module.py index 7fa3f181..b2b5a2cd 100644 --- a/src/pymgrid/modules/battery_module.py +++ b/src/pymgrid/modules/battery_module.py @@ -1,4 +1,4 @@ -from pymgrid.microgrid.modules.base import BaseMicrogridModule +from pymgrid.modules.base import BaseMicrogridModule import numpy as np import yaml from warnings import warn diff --git a/src/pymgrid/modules/genset_module.py b/src/pymgrid/modules/genset_module.py index 5f8ec4b5..3a99331f 100644 --- a/src/pymgrid/modules/genset_module.py +++ b/src/pymgrid/modules/genset_module.py @@ -2,7 +2,7 @@ import numpy as np from warnings import warn -from pymgrid.microgrid.modules.base import BaseMicrogridModule +from pymgrid.modules.base import BaseMicrogridModule class GensetModule(BaseMicrogridModule): diff --git a/src/pymgrid/modules/grid_module.py b/src/pymgrid/modules/grid_module.py index ea2697b2..e5184cf3 100644 --- a/src/pymgrid/modules/grid_module.py +++ b/src/pymgrid/modules/grid_module.py @@ -2,7 +2,7 @@ import yaml from pymgrid.microgrid import DEFAULT_HORIZON -from pymgrid.microgrid.modules.base import BaseTimeSeriesMicrogridModule +from pymgrid.modules.base import BaseTimeSeriesMicrogridModule class GridModule(BaseTimeSeriesMicrogridModule): diff --git a/src/pymgrid/modules/load_module.py b/src/pymgrid/modules/load_module.py index c08d98f3..39d220b3 100644 --- a/src/pymgrid/modules/load_module.py +++ b/src/pymgrid/modules/load_module.py @@ -2,7 +2,7 @@ import yaml from pymgrid.microgrid import DEFAULT_HORIZON -from pymgrid.microgrid.modules.base import BaseTimeSeriesMicrogridModule +from pymgrid.modules.base import BaseTimeSeriesMicrogridModule class LoadModule(BaseTimeSeriesMicrogridModule): diff --git a/src/pymgrid/modules/module_container.py b/src/pymgrid/modules/module_container.py index c4bded5a..f3ab2d21 100644 --- a/src/pymgrid/modules/module_container.py +++ b/src/pymgrid/modules/module_container.py @@ -1,6 +1,6 @@ import json from collections import UserDict, UserList -from pymgrid.microgrid.modules.base import BaseMicrogridModule +from pymgrid.modules.base import BaseMicrogridModule class ModuleContainer(UserDict): diff --git a/src/pymgrid/modules/renewable_module.py b/src/pymgrid/modules/renewable_module.py index 8fb39dd0..4a2aff40 100644 --- a/src/pymgrid/modules/renewable_module.py +++ b/src/pymgrid/modules/renewable_module.py @@ -2,7 +2,7 @@ import yaml from pymgrid.microgrid import DEFAULT_HORIZON -from pymgrid.microgrid.modules.base import BaseTimeSeriesMicrogridModule +from pymgrid.modules.base import BaseTimeSeriesMicrogridModule class RenewableModule(BaseTimeSeriesMicrogridModule): diff --git a/src/pymgrid/modules/unbalanced_energy_module.py b/src/pymgrid/modules/unbalanced_energy_module.py index fcfc4eed..7060f665 100644 --- a/src/pymgrid/modules/unbalanced_energy_module.py +++ b/src/pymgrid/modules/unbalanced_energy_module.py @@ -1,7 +1,7 @@ import numpy as np import yaml -from pymgrid.microgrid.modules.base import BaseMicrogridModule +from pymgrid.modules.base import BaseMicrogridModule class UnbalancedEnergyModule(BaseMicrogridModule): From 312cb52a6c35fc0cd71bfa017dc686d735f82e46 Mon Sep 17 00:00:00 2001 From: ahalev Date: Tue, 22 Nov 2022 15:19:38 -0500 Subject: [PATCH 07/26] refactor test imports --- tests/control/test_mpc.py | 8 ++++---- tests/helpers/genset_module_testing_utils.py | 2 +- tests/helpers/modular_microgrid.py | 12 ++++++++++-- .../modules/forecaster_tests/test_forecaster.py | 2 +- .../modules/module_tests/test_renewable_module.py | 2 +- 5 files changed, 17 insertions(+), 9 deletions(-) diff --git a/tests/control/test_mpc.py b/tests/control/test_mpc.py index 5921be06..b7f69244 100644 --- a/tests/control/test_mpc.py +++ b/tests/control/test_mpc.py @@ -14,7 +14,7 @@ def test_init(self): self.assertEqual(mpc.horizon, 1) def test_run_with_load_pv_battery_grid(self): - from pymgrid.microgrid.modules import RenewableModule, LoadModule + from pymgrid.modules import RenewableModule, LoadModule forecast_steps = 10 pv_const = 50 @@ -35,7 +35,7 @@ def test_run_with_load_pv_battery_grid(self): ) def test_run_with_load_pv_battery_genset(self): - from pymgrid.microgrid.modules import RenewableModule, LoadModule + from pymgrid.modules import RenewableModule, LoadModule forecast_steps = 10 pv_const = 50 @@ -56,7 +56,7 @@ def test_run_with_load_pv_battery_genset(self): [10.] * mpc_output.shape[0]) def test_run_twice_with_load_pv_battery_genset(self): - from pymgrid.microgrid.modules import RenewableModule, LoadModule + from pymgrid.modules import RenewableModule, LoadModule forecast_steps = 10 pv_const = 50 @@ -83,7 +83,7 @@ def test_run_twice_with_load_pv_battery_genset(self): self.assertEqual(mpc_output[("genset", 0, "genset_production")].values, [10.] * mpc_output.shape[0]) def test_run_with_load_pv_battery_grid_different_names(self): - from pymgrid.microgrid.modules import RenewableModule, LoadModule + from pymgrid.modules import RenewableModule, LoadModule forecast_steps = 10 pv_const = 50 diff --git a/tests/helpers/genset_module_testing_utils.py b/tests/helpers/genset_module_testing_utils.py index 74b60953..f8a44138 100644 --- a/tests/helpers/genset_module_testing_utils.py +++ b/tests/helpers/genset_module_testing_utils.py @@ -1,4 +1,4 @@ -from pymgrid.microgrid.modules import GensetModule +from pymgrid.modules import GensetModule default_params = dict(running_min_production=10, diff --git a/tests/helpers/modular_microgrid.py b/tests/helpers/modular_microgrid.py index dec83041..27dd0d15 100644 --- a/tests/helpers/modular_microgrid.py +++ b/tests/helpers/modular_microgrid.py @@ -1,7 +1,15 @@ -from pymgrid.microgrid.modular_microgrid.modular_microgrid import Microgrid -from pymgrid.microgrid.modules import * import numpy as np +from pymgrid import Microgrid + +from pymgrid.modules import ( + BatteryModule, + GensetModule, + GridModule, + LoadModule, + RenewableModule +) + def get_modular_microgrid(remove_modules=(), additional_modules=None, add_unbalanced_module=True): diff --git a/tests/microgrid/modules/forecaster_tests/test_forecaster.py b/tests/microgrid/modules/forecaster_tests/test_forecaster.py index b5fd764e..4fcc6e31 100644 --- a/tests/microgrid/modules/forecaster_tests/test_forecaster.py +++ b/tests/microgrid/modules/forecaster_tests/test_forecaster.py @@ -1,6 +1,6 @@ import numpy as np from tests.helpers.test_case import TestCase -from pymgrid.microgrid.modules.base.timeseries.forecaster import ( +from pymgrid.forecast import ( get_forecaster, OracleForecaster, GaussianNoiseForecaster, UserDefinedForecaster, NoForecaster) diff --git a/tests/microgrid/modules/module_tests/test_renewable_module.py b/tests/microgrid/modules/module_tests/test_renewable_module.py index f6d16e97..30e02548 100644 --- a/tests/microgrid/modules/module_tests/test_renewable_module.py +++ b/tests/microgrid/modules/module_tests/test_renewable_module.py @@ -1,7 +1,7 @@ import numpy as np from gym.spaces import Box -from pymgrid.microgrid.modules.renewable_module import RenewableModule +from pymgrid.modules import RenewableModule from tests.helpers.test_case import TestCase From dd5c827009f24126898766b7e25a59b4175a8a63 Mon Sep 17 00:00:00 2001 From: ahalev Date: Tue, 22 Nov 2022 15:27:10 -0500 Subject: [PATCH 08/26] add _deprecated --- src/pymgrid/_deprecated/__init__.py | 0 1 file changed, 0 insertions(+), 0 deletions(-) create mode 100644 src/pymgrid/_deprecated/__init__.py diff --git a/src/pymgrid/_deprecated/__init__.py b/src/pymgrid/_deprecated/__init__.py new file mode 100644 index 00000000..e69de29b From 31a91f582471e878d575db07bf649068eaaff452 Mon Sep 17 00:00:00 2001 From: ahalev Date: Tue, 22 Nov 2022 15:27:58 -0500 Subject: [PATCH 09/26] move old environments to _deprecated --- src/pymgrid/{ => _deprecated}/Environments/Environment.py | 0 src/pymgrid/{ => _deprecated}/Environments/Preprocessing.py | 0 src/pymgrid/{ => _deprecated}/Environments/__init__.py | 0 src/pymgrid/{ => _deprecated}/Environments/pymgrid_csca.py | 0 src/pymgrid/{ => _deprecated}/Environments/pymgrid_csca_old.py | 0 src/pymgrid/{ => _deprecated}/Environments/pymgrid_csda.py | 0 src/pymgrid/{ => _deprecated}/Environments/pymgrid_cspla.py | 0 7 files changed, 0 insertions(+), 0 deletions(-) rename src/pymgrid/{ => _deprecated}/Environments/Environment.py (100%) rename src/pymgrid/{ => _deprecated}/Environments/Preprocessing.py (100%) rename src/pymgrid/{ => _deprecated}/Environments/__init__.py (100%) rename src/pymgrid/{ => _deprecated}/Environments/pymgrid_csca.py (100%) rename src/pymgrid/{ => _deprecated}/Environments/pymgrid_csca_old.py (100%) rename src/pymgrid/{ => _deprecated}/Environments/pymgrid_csda.py (100%) rename src/pymgrid/{ => _deprecated}/Environments/pymgrid_cspla.py (100%) diff --git a/src/pymgrid/Environments/Environment.py b/src/pymgrid/_deprecated/Environments/Environment.py similarity index 100% rename from src/pymgrid/Environments/Environment.py rename to src/pymgrid/_deprecated/Environments/Environment.py diff --git a/src/pymgrid/Environments/Preprocessing.py b/src/pymgrid/_deprecated/Environments/Preprocessing.py similarity index 100% rename from src/pymgrid/Environments/Preprocessing.py rename to src/pymgrid/_deprecated/Environments/Preprocessing.py diff --git a/src/pymgrid/Environments/__init__.py b/src/pymgrid/_deprecated/Environments/__init__.py similarity index 100% rename from src/pymgrid/Environments/__init__.py rename to src/pymgrid/_deprecated/Environments/__init__.py diff --git a/src/pymgrid/Environments/pymgrid_csca.py b/src/pymgrid/_deprecated/Environments/pymgrid_csca.py similarity index 100% rename from src/pymgrid/Environments/pymgrid_csca.py rename to src/pymgrid/_deprecated/Environments/pymgrid_csca.py diff --git a/src/pymgrid/Environments/pymgrid_csca_old.py b/src/pymgrid/_deprecated/Environments/pymgrid_csca_old.py similarity index 100% rename from src/pymgrid/Environments/pymgrid_csca_old.py rename to src/pymgrid/_deprecated/Environments/pymgrid_csca_old.py diff --git a/src/pymgrid/Environments/pymgrid_csda.py b/src/pymgrid/_deprecated/Environments/pymgrid_csda.py similarity index 100% rename from src/pymgrid/Environments/pymgrid_csda.py rename to src/pymgrid/_deprecated/Environments/pymgrid_csda.py diff --git a/src/pymgrid/Environments/pymgrid_cspla.py b/src/pymgrid/_deprecated/Environments/pymgrid_cspla.py similarity index 100% rename from src/pymgrid/Environments/pymgrid_cspla.py rename to src/pymgrid/_deprecated/Environments/pymgrid_cspla.py From 5ebaad7a4c5c94c91cf0c2b3a2ff2b1b12ad3575 Mon Sep 17 00:00:00 2001 From: ahalev Date: Tue, 22 Nov 2022 15:30:54 -0500 Subject: [PATCH 10/26] move non_modular_microgrid to deprecated dir --- src/pymgrid/{ => _deprecated}/non_modular_microgrid.py | 0 1 file changed, 0 insertions(+), 0 deletions(-) rename src/pymgrid/{ => _deprecated}/non_modular_microgrid.py (100%) diff --git a/src/pymgrid/non_modular_microgrid.py b/src/pymgrid/_deprecated/non_modular_microgrid.py similarity index 100% rename from src/pymgrid/non_modular_microgrid.py rename to src/pymgrid/_deprecated/non_modular_microgrid.py From 180fde6297d4de05abbcf9b01e38122be4606b93 Mon Sep 17 00:00:00 2001 From: ahalev Date: Tue, 22 Nov 2022 15:31:08 -0500 Subject: [PATCH 11/26] update imports to reflect non_modular_microgrid move --- src/pymgrid/__init__.py | 2 +- src/pymgrid/_deprecated/Environments/pymgrid_csca.py | 2 +- src/pymgrid/microgrid/convert/convert.py | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/src/pymgrid/__init__.py b/src/pymgrid/__init__.py index 249978f5..68da1fd2 100644 --- a/src/pymgrid/__init__.py +++ b/src/pymgrid/__init__.py @@ -4,6 +4,6 @@ PROJECT_PATH = Path(__file__).parent -from .non_modular_microgrid import NonModularMicrogrid +from pymgrid._deprecated.non_modular_microgrid import NonModularMicrogrid from .microgrid import Microgrid from .MicrogridGenerator import MicrogridGenerator diff --git a/src/pymgrid/_deprecated/Environments/pymgrid_csca.py b/src/pymgrid/_deprecated/Environments/pymgrid_csca.py index e6538fa5..3d5684d1 100644 --- a/src/pymgrid/_deprecated/Environments/pymgrid_csca.py +++ b/src/pymgrid/_deprecated/Environments/pymgrid_csca.py @@ -1,7 +1,7 @@ from abc import ABC import gym, logging, numpy as np, pandas as pd from gym import Env -from pymgrid.non_modular_microgrid import NonModularMicrogrid +from pymgrid._deprecated.non_modular_microgrid import NonModularMicrogrid from pymgrid.MicrogridGenerator import MicrogridGenerator from copy import deepcopy from pymgrid.algos.saa.saa import SampleAverageApproximation diff --git a/src/pymgrid/microgrid/convert/convert.py b/src/pymgrid/microgrid/convert/convert.py index 31bbe2b8..9a432c11 100644 --- a/src/pymgrid/microgrid/convert/convert.py +++ b/src/pymgrid/microgrid/convert/convert.py @@ -1,4 +1,4 @@ -from pymgrid.non_modular_microgrid import NonModularMicrogrid +from pymgrid._deprecated.non_modular_microgrid import NonModularMicrogrid from pymgrid.microgrid.modular_microgrid.modular_microgrid import Microgrid from pymgrid.microgrid.convert.get_module import get_module from pymgrid.microgrid.convert.to_nonmodular_ops import check_viability, add_params_from_module, get_empty_params, finalize_params From e3fa348990864bdf48c6b433528455c6f0830275 Mon Sep 17 00:00:00 2001 From: ahalev Date: Tue, 22 Nov 2022 15:33:57 -0500 Subject: [PATCH 12/26] move modular_microgrid dir up level --- src/pymgrid/{microgrid => }/modular_microgrid/__init__.py | 0 .../{microgrid => }/modular_microgrid/modular_microgrid.py | 0 2 files changed, 0 insertions(+), 0 deletions(-) rename src/pymgrid/{microgrid => }/modular_microgrid/__init__.py (100%) rename src/pymgrid/{microgrid => }/modular_microgrid/modular_microgrid.py (100%) diff --git a/src/pymgrid/microgrid/modular_microgrid/__init__.py b/src/pymgrid/modular_microgrid/__init__.py similarity index 100% rename from src/pymgrid/microgrid/modular_microgrid/__init__.py rename to src/pymgrid/modular_microgrid/__init__.py diff --git a/src/pymgrid/microgrid/modular_microgrid/modular_microgrid.py b/src/pymgrid/modular_microgrid/modular_microgrid.py similarity index 100% rename from src/pymgrid/microgrid/modular_microgrid/modular_microgrid.py rename to src/pymgrid/modular_microgrid/modular_microgrid.py From a6f1f374e3d9b65dc325da21023f9e338724a94d Mon Sep 17 00:00:00 2001 From: ahalev Date: Tue, 22 Nov 2022 15:34:05 -0500 Subject: [PATCH 13/26] refactor Microgrid imports --- src/pymgrid/__init__.py | 2 +- src/pymgrid/microgrid/__init__.py | 1 - src/pymgrid/microgrid/convert/convert.py | 2 +- src/pymgrid/modular_microgrid/__init__.py | 1 + 4 files changed, 3 insertions(+), 3 deletions(-) diff --git a/src/pymgrid/__init__.py b/src/pymgrid/__init__.py index 68da1fd2..c2a5e7d6 100644 --- a/src/pymgrid/__init__.py +++ b/src/pymgrid/__init__.py @@ -5,5 +5,5 @@ PROJECT_PATH = Path(__file__).parent from pymgrid._deprecated.non_modular_microgrid import NonModularMicrogrid -from .microgrid import Microgrid +from .modular_microgrid import Microgrid from .MicrogridGenerator import MicrogridGenerator diff --git a/src/pymgrid/microgrid/__init__.py b/src/pymgrid/microgrid/__init__.py index f0dd5af4..46a54881 100644 --- a/src/pymgrid/microgrid/__init__.py +++ b/src/pymgrid/microgrid/__init__.py @@ -1,3 +1,2 @@ DEFAULT_HORIZON = 23 -from .modular_microgrid.modular_microgrid import Microgrid diff --git a/src/pymgrid/microgrid/convert/convert.py b/src/pymgrid/microgrid/convert/convert.py index 9a432c11..9a6a4fff 100644 --- a/src/pymgrid/microgrid/convert/convert.py +++ b/src/pymgrid/microgrid/convert/convert.py @@ -1,5 +1,5 @@ from pymgrid._deprecated.non_modular_microgrid import NonModularMicrogrid -from pymgrid.microgrid.modular_microgrid.modular_microgrid import Microgrid +from pymgrid.modular_microgrid.modular_microgrid import Microgrid from pymgrid.microgrid.convert.get_module import get_module from pymgrid.microgrid.convert.to_nonmodular_ops import check_viability, add_params_from_module, get_empty_params, finalize_params diff --git a/src/pymgrid/modular_microgrid/__init__.py b/src/pymgrid/modular_microgrid/__init__.py index e69de29b..2fc11389 100644 --- a/src/pymgrid/modular_microgrid/__init__.py +++ b/src/pymgrid/modular_microgrid/__init__.py @@ -0,0 +1 @@ +from .modular_microgrid import Microgrid \ No newline at end of file From 55924460438fc67003472d2b7926dfb553a2e172 Mon Sep 17 00:00:00 2001 From: ahalev Date: Tue, 22 Nov 2022 15:34:55 -0500 Subject: [PATCH 14/26] remove old modules dir --- src/pymgrid/microgrid/modules/__init__.py | 1 - 1 file changed, 1 deletion(-) delete mode 100644 src/pymgrid/microgrid/modules/__init__.py diff --git a/src/pymgrid/microgrid/modules/__init__.py b/src/pymgrid/microgrid/modules/__init__.py deleted file mode 100644 index 8b137891..00000000 --- a/src/pymgrid/microgrid/modules/__init__.py +++ /dev/null @@ -1 +0,0 @@ - From 91938abdbab90f238c719a8741c66286b99a6f21 Mon Sep 17 00:00:00 2001 From: ahalev Date: Tue, 22 Nov 2022 15:35:45 -0500 Subject: [PATCH 15/26] move envs up level --- src/pymgrid/{microgrid => }/envs/__init__.py | 0 src/pymgrid/{microgrid => }/envs/base/__init__.py | 0 src/pymgrid/{microgrid => }/envs/base/base.py | 0 src/pymgrid/{microgrid => }/envs/base/skip_init.py | 0 src/pymgrid/{microgrid => }/envs/continuous/__init__.py | 0 src/pymgrid/{microgrid => }/envs/continuous/continuous.py | 0 src/pymgrid/{microgrid => }/envs/discrete/__init__.py | 0 src/pymgrid/{microgrid => }/envs/discrete/discrete.py | 0 8 files changed, 0 insertions(+), 0 deletions(-) rename src/pymgrid/{microgrid => }/envs/__init__.py (100%) rename src/pymgrid/{microgrid => }/envs/base/__init__.py (100%) rename src/pymgrid/{microgrid => }/envs/base/base.py (100%) rename src/pymgrid/{microgrid => }/envs/base/skip_init.py (100%) rename src/pymgrid/{microgrid => }/envs/continuous/__init__.py (100%) rename src/pymgrid/{microgrid => }/envs/continuous/continuous.py (100%) rename src/pymgrid/{microgrid => }/envs/discrete/__init__.py (100%) rename src/pymgrid/{microgrid => }/envs/discrete/discrete.py (100%) diff --git a/src/pymgrid/microgrid/envs/__init__.py b/src/pymgrid/envs/__init__.py similarity index 100% rename from src/pymgrid/microgrid/envs/__init__.py rename to src/pymgrid/envs/__init__.py diff --git a/src/pymgrid/microgrid/envs/base/__init__.py b/src/pymgrid/envs/base/__init__.py similarity index 100% rename from src/pymgrid/microgrid/envs/base/__init__.py rename to src/pymgrid/envs/base/__init__.py diff --git a/src/pymgrid/microgrid/envs/base/base.py b/src/pymgrid/envs/base/base.py similarity index 100% rename from src/pymgrid/microgrid/envs/base/base.py rename to src/pymgrid/envs/base/base.py diff --git a/src/pymgrid/microgrid/envs/base/skip_init.py b/src/pymgrid/envs/base/skip_init.py similarity index 100% rename from src/pymgrid/microgrid/envs/base/skip_init.py rename to src/pymgrid/envs/base/skip_init.py diff --git a/src/pymgrid/microgrid/envs/continuous/__init__.py b/src/pymgrid/envs/continuous/__init__.py similarity index 100% rename from src/pymgrid/microgrid/envs/continuous/__init__.py rename to src/pymgrid/envs/continuous/__init__.py diff --git a/src/pymgrid/microgrid/envs/continuous/continuous.py b/src/pymgrid/envs/continuous/continuous.py similarity index 100% rename from src/pymgrid/microgrid/envs/continuous/continuous.py rename to src/pymgrid/envs/continuous/continuous.py diff --git a/src/pymgrid/microgrid/envs/discrete/__init__.py b/src/pymgrid/envs/discrete/__init__.py similarity index 100% rename from src/pymgrid/microgrid/envs/discrete/__init__.py rename to src/pymgrid/envs/discrete/__init__.py diff --git a/src/pymgrid/microgrid/envs/discrete/discrete.py b/src/pymgrid/envs/discrete/discrete.py similarity index 100% rename from src/pymgrid/microgrid/envs/discrete/discrete.py rename to src/pymgrid/envs/discrete/discrete.py From 9e983ef801d56ce2e44a3d262144a6058fbc4f0c Mon Sep 17 00:00:00 2001 From: ahalev Date: Tue, 22 Nov 2022 15:38:42 -0500 Subject: [PATCH 16/26] refactor envs --- src/pymgrid/envs/base/base.py | 2 +- src/pymgrid/envs/continuous/continuous.py | 2 +- src/pymgrid/envs/discrete/discrete.py | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/src/pymgrid/envs/base/base.py b/src/pymgrid/envs/base/base.py index cd1ec185..1a4d225a 100644 --- a/src/pymgrid/envs/base/base.py +++ b/src/pymgrid/envs/base/base.py @@ -3,7 +3,7 @@ from abc import abstractmethod from pymgrid import NonModularMicrogrid, Microgrid -from pymgrid.microgrid.envs.base.skip_init import skip_init +from pymgrid.envs.base import skip_init class BaseMicrogridEnv(Microgrid, Env): diff --git a/src/pymgrid/envs/continuous/continuous.py b/src/pymgrid/envs/continuous/continuous.py index 24fb005d..e45805b1 100644 --- a/src/pymgrid/envs/continuous/continuous.py +++ b/src/pymgrid/envs/continuous/continuous.py @@ -1,7 +1,7 @@ from gym.spaces import Dict, Tuple, flatten_space from warnings import warn -from pymgrid.microgrid.envs.base.base import BaseMicrogridEnv +from pymgrid.envs.base import BaseMicrogridEnv class ContinuousMicrogridEnv(BaseMicrogridEnv): diff --git a/src/pymgrid/envs/discrete/discrete.py b/src/pymgrid/envs/discrete/discrete.py index b911af02..ed22f563 100644 --- a/src/pymgrid/envs/discrete/discrete.py +++ b/src/pymgrid/envs/discrete/discrete.py @@ -4,7 +4,7 @@ from gym.spaces import Discrete from math import isclose -from pymgrid.microgrid.envs.base.base import BaseMicrogridEnv +from pymgrid.envs.base import BaseMicrogridEnv from pymgrid.microgrid.utils.logger import ModularLogger From b06461d69bb425553c891060203b39ccf22665ca Mon Sep 17 00:00:00 2001 From: ahalev Date: Tue, 22 Nov 2022 15:39:09 -0500 Subject: [PATCH 17/26] refactor env test imports --- tests/envs/discrete.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/envs/discrete.py b/tests/envs/discrete.py index cad4e0d0..c1a2e6fb 100644 --- a/tests/envs/discrete.py +++ b/tests/envs/discrete.py @@ -1,7 +1,7 @@ from tests.helpers.test_case import TestCase from tests.helpers.modular_microgrid import get_modular_microgrid -from pymgrid.microgrid.envs import DiscreteMicrogridEnv +from pymgrid.envs import DiscreteMicrogridEnv class TestDiscreteEnv(TestCase): From bdb5456116801436950c4e4d430566c6aea15186 Mon Sep 17 00:00:00 2001 From: ahalev Date: Tue, 22 Nov 2022 15:40:50 -0500 Subject: [PATCH 18/26] refactor deprecated imports --- src/pymgrid/__init__.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/pymgrid/__init__.py b/src/pymgrid/__init__.py index c2a5e7d6..fa578c74 100644 --- a/src/pymgrid/__init__.py +++ b/src/pymgrid/__init__.py @@ -4,6 +4,7 @@ PROJECT_PATH = Path(__file__).parent -from pymgrid._deprecated.non_modular_microgrid import NonModularMicrogrid +from ._deprecated.non_modular_microgrid import NonModularMicrogrid from .modular_microgrid import Microgrid from .MicrogridGenerator import MicrogridGenerator + From cb8e953b20d9efad262e40ee6abd3ee61c663a79 Mon Sep 17 00:00:00 2001 From: ahalev Date: Tue, 22 Nov 2022 15:51:10 -0500 Subject: [PATCH 19/26] add nl at end of file --- src/pymgrid/envs/__init__.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/pymgrid/envs/__init__.py b/src/pymgrid/envs/__init__.py index 8ea1f0a8..1d86a8b7 100644 --- a/src/pymgrid/envs/__init__.py +++ b/src/pymgrid/envs/__init__.py @@ -1,2 +1,2 @@ from .discrete.discrete import DiscreteMicrogridEnv -from .continuous.continuous import ContinuousMicrogridEnv \ No newline at end of file +from .continuous.continuous import ContinuousMicrogridEnv From a66325892694b9f6eeb28b7ce9bb6677afc57e50 Mon Sep 17 00:00:00 2001 From: ahalev Date: Tue, 22 Nov 2022 15:51:23 -0500 Subject: [PATCH 20/26] fix base env imports --- src/pymgrid/envs/base/__init__.py | 1 + src/pymgrid/envs/base/base.py | 2 +- 2 files changed, 2 insertions(+), 1 deletion(-) diff --git a/src/pymgrid/envs/base/__init__.py b/src/pymgrid/envs/base/__init__.py index e69de29b..47ce3c70 100644 --- a/src/pymgrid/envs/base/__init__.py +++ b/src/pymgrid/envs/base/__init__.py @@ -0,0 +1 @@ +from .base import BaseMicrogridEnv diff --git a/src/pymgrid/envs/base/base.py b/src/pymgrid/envs/base/base.py index 1a4d225a..f64e8cd7 100644 --- a/src/pymgrid/envs/base/base.py +++ b/src/pymgrid/envs/base/base.py @@ -3,7 +3,7 @@ from abc import abstractmethod from pymgrid import NonModularMicrogrid, Microgrid -from pymgrid.envs.base import skip_init +from pymgrid.envs.base.skip_init import skip_init class BaseMicrogridEnv(Microgrid, Env): From a5468d78dd5946bd88e446f02b67e2fdfdf5ef34 Mon Sep 17 00:00:00 2001 From: ahalev Date: Tue, 22 Nov 2022 21:08:06 -0500 Subject: [PATCH 21/26] refactor microgrid/convert->convert --- src/pymgrid/{microgrid => }/convert/__init__.py | 0 src/pymgrid/{microgrid => }/convert/convert.py | 0 src/pymgrid/{microgrid => }/convert/get_module.py | 0 src/pymgrid/{microgrid => }/convert/to_nonmodular_ops.py | 0 4 files changed, 0 insertions(+), 0 deletions(-) rename src/pymgrid/{microgrid => }/convert/__init__.py (100%) rename src/pymgrid/{microgrid => }/convert/convert.py (100%) rename src/pymgrid/{microgrid => }/convert/get_module.py (100%) rename src/pymgrid/{microgrid => }/convert/to_nonmodular_ops.py (100%) diff --git a/src/pymgrid/microgrid/convert/__init__.py b/src/pymgrid/convert/__init__.py similarity index 100% rename from src/pymgrid/microgrid/convert/__init__.py rename to src/pymgrid/convert/__init__.py diff --git a/src/pymgrid/microgrid/convert/convert.py b/src/pymgrid/convert/convert.py similarity index 100% rename from src/pymgrid/microgrid/convert/convert.py rename to src/pymgrid/convert/convert.py diff --git a/src/pymgrid/microgrid/convert/get_module.py b/src/pymgrid/convert/get_module.py similarity index 100% rename from src/pymgrid/microgrid/convert/get_module.py rename to src/pymgrid/convert/get_module.py diff --git a/src/pymgrid/microgrid/convert/to_nonmodular_ops.py b/src/pymgrid/convert/to_nonmodular_ops.py similarity index 100% rename from src/pymgrid/microgrid/convert/to_nonmodular_ops.py rename to src/pymgrid/convert/to_nonmodular_ops.py From f85d012ea3ae40cddceb925da084c30c8584a0a0 Mon Sep 17 00:00:00 2001 From: ahalev Date: Tue, 22 Nov 2022 21:08:26 -0500 Subject: [PATCH 22/26] refactor conversion imports --- src/pymgrid/_deprecated/non_modular_microgrid.py | 8 ++------ src/pymgrid/convert/convert.py | 4 ++-- src/pymgrid/modular_microgrid/modular_microgrid.py | 4 ++-- 3 files changed, 6 insertions(+), 10 deletions(-) diff --git a/src/pymgrid/_deprecated/non_modular_microgrid.py b/src/pymgrid/_deprecated/non_modular_microgrid.py index c604b823..1d982071 100644 --- a/src/pymgrid/_deprecated/non_modular_microgrid.py +++ b/src/pymgrid/_deprecated/non_modular_microgrid.py @@ -23,12 +23,8 @@ import pandas as pd import numpy as np from copy import copy -import cvxpy as cp -import operator -import sys from plotly.offline import init_notebook_mode, iplot import matplotlib.pyplot as plt -import cufflinks as cf from IPython.display import display from IPython import get_ipython @@ -1263,10 +1259,10 @@ def penalty(self, coef = 1): @classmethod def from_modular(cls, modular): - from pymgrid.microgrid.convert.convert import to_nonmodular + from pymgrid.convert.convert import to_nonmodular return to_nonmodular(modular) def to_modular(self): - from pymgrid.microgrid.convert.convert import to_modular + from pymgrid.convert.convert import to_modular return to_modular(self) diff --git a/src/pymgrid/convert/convert.py b/src/pymgrid/convert/convert.py index 9a6a4fff..4bea83c4 100644 --- a/src/pymgrid/convert/convert.py +++ b/src/pymgrid/convert/convert.py @@ -1,7 +1,7 @@ from pymgrid._deprecated.non_modular_microgrid import NonModularMicrogrid from pymgrid.modular_microgrid.modular_microgrid import Microgrid -from pymgrid.microgrid.convert.get_module import get_module -from pymgrid.microgrid.convert.to_nonmodular_ops import check_viability, add_params_from_module, get_empty_params, finalize_params +from pymgrid.convert.get_module import get_module +from pymgrid.convert.to_nonmodular_ops import check_viability, add_params_from_module, get_empty_params, finalize_params def to_modular(nonmodular, raise_errors=False): diff --git a/src/pymgrid/modular_microgrid/modular_microgrid.py b/src/pymgrid/modular_microgrid/modular_microgrid.py index 7e5541fc..a57d2f3f 100644 --- a/src/pymgrid/modular_microgrid/modular_microgrid.py +++ b/src/pymgrid/modular_microgrid/modular_microgrid.py @@ -278,11 +278,11 @@ def serialize(self, dumper_stream): @classmethod def from_nonmodular(cls, nonmodular): - from pymgrid.microgrid.convert.convert import to_modular + from pymgrid.convert.convert import to_modular return to_modular(nonmodular) def to_nonmodular(self): - from pymgrid.microgrid.convert.convert import to_nonmodular + from pymgrid.convert.convert import to_nonmodular return to_nonmodular(self) @classmethod From 82d611e24f60210422e044cc71236864fa3c2f60 Mon Sep 17 00:00:00 2001 From: ahalev Date: Tue, 22 Nov 2022 21:08:44 -0500 Subject: [PATCH 23/26] refactor conversion imports in tests --- .../microgrid/modules/conversion_test/test_modular_conversion.py | 1 - 1 file changed, 1 deletion(-) diff --git a/tests/microgrid/modules/conversion_test/test_modular_conversion.py b/tests/microgrid/modules/conversion_test/test_modular_conversion.py index 85de5ea9..153cfe23 100644 --- a/tests/microgrid/modules/conversion_test/test_modular_conversion.py +++ b/tests/microgrid/modules/conversion_test/test_modular_conversion.py @@ -15,7 +15,6 @@ def setUp(self) -> None: self.strong_grid_and_genset = [microgrid for microgrid in mgen.microgrids if microgrid.architecture["genset"] and self.is_strong_grid(microgrid)] - @staticmethod def is_weak_grid(microgrid): return microgrid.architecture["grid"] and microgrid._grid_status_ts.min().item() < 1 From 8804e66930e9fc76a18919163e5cf11a89d81daf Mon Sep 17 00:00:00 2001 From: ahalev Date: Tue, 22 Nov 2022 21:33:11 -0500 Subject: [PATCH 24/26] move the rest of the utils --- src/pymgrid/microgrid/utils/__init__.py | 0 src/pymgrid/{microgrid => modular_microgrid}/utils/step.py | 0 src/pymgrid/{microgrid => modules}/utils/normalize.py | 0 src/pymgrid/{microgrid => }/utils/logger.py | 0 src/pymgrid/{microgrid => }/utils/serialize.py | 0 5 files changed, 0 insertions(+), 0 deletions(-) delete mode 100644 src/pymgrid/microgrid/utils/__init__.py rename src/pymgrid/{microgrid => modular_microgrid}/utils/step.py (100%) rename src/pymgrid/{microgrid => modules}/utils/normalize.py (100%) rename src/pymgrid/{microgrid => }/utils/logger.py (100%) rename src/pymgrid/{microgrid => }/utils/serialize.py (100%) diff --git a/src/pymgrid/microgrid/utils/__init__.py b/src/pymgrid/microgrid/utils/__init__.py deleted file mode 100644 index e69de29b..00000000 diff --git a/src/pymgrid/microgrid/utils/step.py b/src/pymgrid/modular_microgrid/utils/step.py similarity index 100% rename from src/pymgrid/microgrid/utils/step.py rename to src/pymgrid/modular_microgrid/utils/step.py diff --git a/src/pymgrid/microgrid/utils/normalize.py b/src/pymgrid/modules/utils/normalize.py similarity index 100% rename from src/pymgrid/microgrid/utils/normalize.py rename to src/pymgrid/modules/utils/normalize.py diff --git a/src/pymgrid/microgrid/utils/logger.py b/src/pymgrid/utils/logger.py similarity index 100% rename from src/pymgrid/microgrid/utils/logger.py rename to src/pymgrid/utils/logger.py diff --git a/src/pymgrid/microgrid/utils/serialize.py b/src/pymgrid/utils/serialize.py similarity index 100% rename from src/pymgrid/microgrid/utils/serialize.py rename to src/pymgrid/utils/serialize.py From e46b7a4b330ab887634844158669c9ba38c4d369 Mon Sep 17 00:00:00 2001 From: ahalev Date: Tue, 22 Nov 2022 21:33:58 -0500 Subject: [PATCH 25/26] refactor util imports --- src/pymgrid/envs/discrete/discrete.py | 2 +- src/pymgrid/modular_microgrid/modular_microgrid.py | 6 +++--- src/pymgrid/modules/base/base_module.py | 6 +++--- 3 files changed, 7 insertions(+), 7 deletions(-) diff --git a/src/pymgrid/envs/discrete/discrete.py b/src/pymgrid/envs/discrete/discrete.py index ed22f563..b2593a8d 100644 --- a/src/pymgrid/envs/discrete/discrete.py +++ b/src/pymgrid/envs/discrete/discrete.py @@ -5,7 +5,7 @@ from math import isclose from pymgrid.envs.base import BaseMicrogridEnv -from pymgrid.microgrid.utils.logger import ModularLogger +from pymgrid.utils.logger import ModularLogger class DiscreteMicrogridEnv(BaseMicrogridEnv): diff --git a/src/pymgrid/modular_microgrid/modular_microgrid.py b/src/pymgrid/modular_microgrid/modular_microgrid.py index a57d2f3f..64e8fe36 100644 --- a/src/pymgrid/modular_microgrid/modular_microgrid.py +++ b/src/pymgrid/modular_microgrid/modular_microgrid.py @@ -7,9 +7,9 @@ from pymgrid.microgrid import DEFAULT_HORIZON from pymgrid.modules import ModuleContainer, UnbalancedEnergyModule -from pymgrid.microgrid.utils.logger import ModularLogger -from pymgrid.microgrid.utils.step import MicrogridStep -from pymgrid.microgrid.utils.serialize import add_numpy_pandas_representers, add_numpy_pandas_constructors, dump_data +from pymgrid.utils.logger import ModularLogger +from pymgrid.modular_microgrid.utils.step import MicrogridStep +from pymgrid.utils.serialize import add_numpy_pandas_representers, add_numpy_pandas_constructors, dump_data class Microgrid(yaml.YAMLObject): diff --git a/src/pymgrid/modules/base/base_module.py b/src/pymgrid/modules/base/base_module.py index 01197456..fd1b9715 100644 --- a/src/pymgrid/modules/base/base_module.py +++ b/src/pymgrid/modules/base/base_module.py @@ -7,9 +7,9 @@ from gym.spaces import Box from warnings import warn -from pymgrid.microgrid.utils.logger import ModularLogger -from pymgrid.microgrid.utils.normalize import Normalize, IdentityNormalize -from pymgrid.microgrid.utils.serialize import add_numpy_pandas_representers, add_numpy_pandas_constructors, dump_data +from pymgrid.utils.logger import ModularLogger +from pymgrid.modules.utils.normalize import Normalize, IdentityNormalize +from pymgrid.utils.serialize import add_numpy_pandas_representers, add_numpy_pandas_constructors, dump_data script_logger = logging.getLogger(__name__) From 853a0d8d52c0938c635c86a06a09a84ea2387d56 Mon Sep 17 00:00:00 2001 From: ahalev Date: Tue, 22 Nov 2022 21:34:08 -0500 Subject: [PATCH 26/26] add __init__ files --- src/pymgrid/modular_microgrid/utils/__init__.py | 0 src/pymgrid/modules/utils/__init__.py | 0 2 files changed, 0 insertions(+), 0 deletions(-) create mode 100644 src/pymgrid/modular_microgrid/utils/__init__.py create mode 100644 src/pymgrid/modules/utils/__init__.py diff --git a/src/pymgrid/modular_microgrid/utils/__init__.py b/src/pymgrid/modular_microgrid/utils/__init__.py new file mode 100644 index 00000000..e69de29b diff --git a/src/pymgrid/modules/utils/__init__.py b/src/pymgrid/modules/utils/__init__.py new file mode 100644 index 00000000..e69de29b