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, 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" diff --git a/src/pymgrid/__init__.py b/src/pymgrid/__init__.py index 249978f5..fa578c74 100644 --- a/src/pymgrid/__init__.py +++ b/src/pymgrid/__init__.py @@ -4,6 +4,7 @@ PROJECT_PATH = Path(__file__).parent -from .non_modular_microgrid import NonModularMicrogrid -from .microgrid import Microgrid +from ._deprecated.non_modular_microgrid import NonModularMicrogrid +from .modular_microgrid import Microgrid from .MicrogridGenerator import MicrogridGenerator + 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 99% rename from src/pymgrid/Environments/pymgrid_csca.py rename to src/pymgrid/_deprecated/Environments/pymgrid_csca.py index e6538fa5..3d5684d1 100644 --- a/src/pymgrid/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/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 diff --git a/src/pymgrid/microgrid/convert/__init__.py b/src/pymgrid/_deprecated/__init__.py similarity index 100% rename from src/pymgrid/microgrid/convert/__init__.py rename to src/pymgrid/_deprecated/__init__.py diff --git a/src/pymgrid/non_modular_microgrid.py b/src/pymgrid/_deprecated/non_modular_microgrid.py similarity index 99% rename from src/pymgrid/non_modular_microgrid.py rename to src/pymgrid/_deprecated/non_modular_microgrid.py index c604b823..1d982071 100644 --- a/src/pymgrid/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/microgrid/envs/base/__init__.py b/src/pymgrid/convert/__init__.py similarity index 100% rename from src/pymgrid/microgrid/envs/base/__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 87% rename from src/pymgrid/microgrid/convert/convert.py rename to src/pymgrid/convert/convert.py index 31bbe2b8..4bea83c4 100644 --- a/src/pymgrid/microgrid/convert/convert.py +++ b/src/pymgrid/convert/convert.py @@ -1,7 +1,7 @@ -from pymgrid.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 pymgrid._deprecated.non_modular_microgrid import NonModularMicrogrid +from pymgrid.modular_microgrid.modular_microgrid import Microgrid +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/microgrid/convert/get_module.py b/src/pymgrid/convert/get_module.py similarity index 97% rename from src/pymgrid/microgrid/convert/get_module.py rename to src/pymgrid/convert/get_module.py index cbe17e99..2409b713 100644 --- a/src/pymgrid/microgrid/convert/get_module.py +++ b/src/pymgrid/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/convert/to_nonmodular_ops.py similarity index 98% rename from src/pymgrid/microgrid/convert/to_nonmodular_ops.py rename to src/pymgrid/convert/to_nonmodular_ops.py index 4b703b78..c6a3f3f3 100644 --- a/src/pymgrid/microgrid/convert/to_nonmodular_ops.py +++ b/src/pymgrid/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/envs/__init__.py b/src/pymgrid/envs/__init__.py new file mode 100644 index 00000000..1d86a8b7 --- /dev/null +++ b/src/pymgrid/envs/__init__.py @@ -0,0 +1,2 @@ +from .discrete.discrete import DiscreteMicrogridEnv +from .continuous.continuous import ContinuousMicrogridEnv diff --git a/src/pymgrid/envs/base/__init__.py b/src/pymgrid/envs/base/__init__.py new file mode 100644 index 00000000..47ce3c70 --- /dev/null +++ b/src/pymgrid/envs/base/__init__.py @@ -0,0 +1 @@ +from .base import BaseMicrogridEnv diff --git a/src/pymgrid/microgrid/envs/base/base.py b/src/pymgrid/envs/base/base.py similarity index 97% rename from src/pymgrid/microgrid/envs/base/base.py rename to src/pymgrid/envs/base/base.py index cd1ec185..f64e8cd7 100644 --- a/src/pymgrid/microgrid/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.skip_init import skip_init class BaseMicrogridEnv(Microgrid, Env): 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 96% rename from src/pymgrid/microgrid/envs/continuous/continuous.py rename to src/pymgrid/envs/continuous/continuous.py index 24fb005d..e45805b1 100644 --- a/src/pymgrid/microgrid/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/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 98% rename from src/pymgrid/microgrid/envs/discrete/discrete.py rename to src/pymgrid/envs/discrete/discrete.py index b911af02..b2593a8d 100644 --- a/src/pymgrid/microgrid/envs/discrete/discrete.py +++ b/src/pymgrid/envs/discrete/discrete.py @@ -4,8 +4,8 @@ from gym.spaces import Discrete from math import isclose -from pymgrid.microgrid.envs.base.base import BaseMicrogridEnv -from pymgrid.microgrid.utils.logger import ModularLogger +from pymgrid.envs.base import BaseMicrogridEnv +from pymgrid.utils.logger import ModularLogger class DiscreteMicrogridEnv(BaseMicrogridEnv): diff --git a/src/pymgrid/forecast/__init__.py b/src/pymgrid/forecast/__init__.py new file mode 100644 index 00000000..05be0939 --- /dev/null +++ b/src/pymgrid/forecast/__init__.py @@ -0,0 +1 @@ +from .forecaster import get_forecaster, OracleForecaster, GaussianNoiseForecaster, UserDefinedForecaster, NoForecaster \ No newline at end of file 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/__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/envs/__init__.py b/src/pymgrid/microgrid/envs/__init__.py deleted file mode 100644 index 8ea1f0a8..00000000 --- a/src/pymgrid/microgrid/envs/__init__.py +++ /dev/null @@ -1,2 +0,0 @@ -from .discrete.discrete import DiscreteMicrogridEnv -from .continuous.continuous import ContinuousMicrogridEnv \ No newline at end of file diff --git a/src/pymgrid/microgrid/modules/base/__init__.py b/src/pymgrid/microgrid/modules/base/__init__.py deleted file mode 100644 index c2922879..00000000 --- a/src/pymgrid/microgrid/modules/base/__init__.py +++ /dev/null @@ -1,2 +0,0 @@ -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 diff --git a/src/pymgrid/modular_microgrid/__init__.py b/src/pymgrid/modular_microgrid/__init__.py new file mode 100644 index 00000000..2fc11389 --- /dev/null +++ b/src/pymgrid/modular_microgrid/__init__.py @@ -0,0 +1 @@ +from .modular_microgrid import Microgrid \ No newline at end of file diff --git a/src/pymgrid/microgrid/modular_microgrid/modular_microgrid.py b/src/pymgrid/modular_microgrid/modular_microgrid.py similarity index 96% rename from src/pymgrid/microgrid/modular_microgrid/modular_microgrid.py rename to src/pymgrid/modular_microgrid/modular_microgrid.py index d058a654..64e8fe36 100644 --- a/src/pymgrid/microgrid/modular_microgrid/modular_microgrid.py +++ b/src/pymgrid/modular_microgrid/modular_microgrid.py @@ -6,11 +6,10 @@ 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.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.modules import ModuleContainer, UnbalancedEnergyModule +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): @@ -279,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 diff --git a/src/pymgrid/microgrid/modular_microgrid/__init__.py b/src/pymgrid/modular_microgrid/utils/__init__.py similarity index 100% rename from src/pymgrid/microgrid/modular_microgrid/__init__.py rename to src/pymgrid/modular_microgrid/utils/__init__.py 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/modules/__init__.py b/src/pymgrid/modules/__init__.py similarity index 84% rename from src/pymgrid/microgrid/modules/__init__.py rename to src/pymgrid/modules/__init__.py index fc69d927..c3fda508 100644 --- a/src/pymgrid/microgrid/modules/__init__.py +++ b/src/pymgrid/modules/__init__.py @@ -1,6 +1,8 @@ from .battery_module import BatteryModule -from .renewable_module import RenewableModule +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 .grid_module import GridModule -from .genset_module import GensetModule + +from .module_container import ModuleContainer diff --git a/src/pymgrid/modules/base/__init__.py b/src/pymgrid/modules/base/__init__.py new file mode 100644 index 00000000..2a1e3bc5 --- /dev/null +++ b/src/pymgrid/modules/base/__init__.py @@ -0,0 +1,2 @@ +from .base_module import BaseMicrogridModule +from .timeseries.base_timeseries_module import BaseTimeSeriesMicrogridModule diff --git a/src/pymgrid/microgrid/modules/base/base_module.py b/src/pymgrid/modules/base/base_module.py similarity index 98% rename from src/pymgrid/microgrid/modules/base/base_module.py rename to src/pymgrid/modules/base/base_module.py index 01197456..fd1b9715 100644 --- a/src/pymgrid/microgrid/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__) diff --git a/src/pymgrid/microgrid/modules/base/timeseries/__init__.py b/src/pymgrid/modules/base/timeseries/__init__.py similarity index 100% rename from src/pymgrid/microgrid/modules/base/timeseries/__init__.py rename to src/pymgrid/modules/base/timeseries/__init__.py 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 94% rename from src/pymgrid/microgrid/modules/base/timeseries/base_timeseries_module.py rename to src/pymgrid/modules/base/timeseries/base_timeseries_module.py index dd73637b..e4d88dff 100644 --- a/src/pymgrid/microgrid/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/microgrid/modules/battery_module.py b/src/pymgrid/modules/battery_module.py similarity index 98% rename from src/pymgrid/microgrid/modules/battery_module.py rename to src/pymgrid/modules/battery_module.py index 7fa3f181..b2b5a2cd 100644 --- a/src/pymgrid/microgrid/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/microgrid/modules/genset_module.py b/src/pymgrid/modules/genset_module.py similarity index 99% rename from src/pymgrid/microgrid/modules/genset_module.py rename to src/pymgrid/modules/genset_module.py index 5f8ec4b5..3a99331f 100644 --- a/src/pymgrid/microgrid/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/microgrid/modules/grid_module.py b/src/pymgrid/modules/grid_module.py similarity index 99% rename from src/pymgrid/microgrid/modules/grid_module.py rename to src/pymgrid/modules/grid_module.py index ea2697b2..e5184cf3 100644 --- a/src/pymgrid/microgrid/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/microgrid/modules/load_module.py b/src/pymgrid/modules/load_module.py similarity index 96% rename from src/pymgrid/microgrid/modules/load_module.py rename to src/pymgrid/modules/load_module.py index c08d98f3..39d220b3 100644 --- a/src/pymgrid/microgrid/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/microgrid/modules/module_container.py b/src/pymgrid/modules/module_container.py similarity index 99% rename from src/pymgrid/microgrid/modules/module_container.py rename to src/pymgrid/modules/module_container.py index c4bded5a..f3ab2d21 100644 --- a/src/pymgrid/microgrid/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/microgrid/modules/renewable_module.py b/src/pymgrid/modules/renewable_module.py similarity index 96% rename from src/pymgrid/microgrid/modules/renewable_module.py rename to src/pymgrid/modules/renewable_module.py index 8fb39dd0..4a2aff40 100644 --- a/src/pymgrid/microgrid/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/microgrid/modules/unbalanced_energy_module.py b/src/pymgrid/modules/unbalanced_energy_module.py similarity index 97% rename from src/pymgrid/microgrid/modules/unbalanced_energy_module.py rename to src/pymgrid/modules/unbalanced_energy_module.py index fcfc4eed..7060f665 100644 --- a/src/pymgrid/microgrid/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): diff --git a/src/pymgrid/microgrid/utils/__init__.py b/src/pymgrid/modules/utils/__init__.py similarity index 100% rename from src/pymgrid/microgrid/utils/__init__.py rename to src/pymgrid/modules/utils/__init__.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 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/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): 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/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 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