Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 9 additions & 8 deletions examples/PoCTutorial/src/run_grow_tutorial.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
from pathlib import Path

from mesido.esdl.esdl_mixin import DBAccessType
from mesido.esdl.esdl_mixin import DBAccessType, ESDLOutputProfilesType
from mesido.esdl.esdl_parser import ESDLFileParser
from mesido.workflows import EndScenarioSizingStaged, run_end_scenario_sizing

Expand All @@ -13,16 +13,17 @@ class EndScenarioSizingStagedHighs(EndScenarioSizingStaged):
import time

kwargs = {
"write_result_db_profiles": True,
# '"esdl_profiles_output_type"=None' (default) means no profiles to DB
"esdl_profiles_output_type": ESDLOutputProfilesType.INFLUXDB,
"database_connections": [
{
"access_type": DBAccessType.WRITE, # DBAccessType.READ or DBAccessType.READ_WRITE
"influxdb_host": "localhost",
"influxdb_port": 8086,
"influxdb_username": None,
"influxdb_password": None,
"influxdb_ssl": False,
"influxdb_verify_ssl": False,
"host": "localhost",
"port": 8086,
"username": None,
"password": None,
"ssl": False,
"verify_ssl": False,
},
],
}
Expand Down
12 changes: 6 additions & 6 deletions examples/municipality/src/run_municipality.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,12 +16,12 @@
"database_connections": [
{
"access_type": DBAccessType.READ, # DBAccessType.WRITE or DBAccessType.READ_WRITE
"influxdb_host": "required_user_input",
"influxdb_port": 1234,
"influxdb_username": "required_user_input",
"influxdb_password": "required_user_input",
"influxdb_ssl": False,
"influxdb_verify_ssl": False,
"host": "required_user_input",
"port": 1234,
"username": "required_user_input",
"password": "required_user_input",
"ssl": False,
"verify_ssl": False,
},
],
}
Expand Down
697 changes: 697 additions & 0 deletions manual_run/testing_bugs/model/Delft_T.esdl

Large diffs are not rendered by default.

54 changes: 37 additions & 17 deletions manual_run/testing_bugs/src/run_grow.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

from mesido.esdl.esdl_parser import ESDLFileParser
from mesido.workflows import EndScenarioSizingStaged, run_end_scenario_sizing
from mesido.esdl.esdl_mixin import DBAccessType
from mesido.esdl.esdl_mixin import DBAccessType, ESDLOutputProfilesType

if __name__ == "__main__":
import time
Expand All @@ -12,35 +12,55 @@

kwargs = {
"use_esdl_ranged_constraint": True, # default value in the code is set to False
"esdl_profiles_output_type": ESDLOutputProfilesType.POSTGRESQL, # 'None' (default) means no profiles to DB
"database_connections": [
{
"access_type": DBAccessType.READ, # or DBAccessType.WRITE or DBAccessType.READ_WRITE
"influxdb_host": "required_user_input",
"influxdb_port": 1234,
"influxdb_username": "required_user_input",
"influxdb_password": "required_user_input",
"influxdb_ssl": False,
"influxdb_verify_ssl": False,
"host": "required_user_input",
"port": 1234,
"username": "required_user_input",
"password": "required_user_input",
"ssl": False,
"verify_ssl": False,
},
{
"access_type": DBAccessType.WRITE, # or DBAccessType.WRITE or DBAccessType.READ_WRITE
"influxdb_host": "localhost",
"influxdb_port": 8086,
"influxdb_username": None,
"influxdb_password": None,
"influxdb_ssl": False,
"influxdb_verify_ssl": False,
"access_type": DBAccessType.READ,
"host": "localhost",
"port": 8086,
"username": None,
"password": None,
"ssl": False,
"verify_ssl": False,
},
{
"access_type": DBAccessType.READ,
"host": "omotes_influxdb",
"port": 8096,
"username": "root",
"password": "9012",
"ssl": False,
"verify_ssl": False,
},
{
"access_type": DBAccessType.READ_WRITE,
"host": "postgres",
"port": 6432,
"username": "root",
"password": "1234",
},

],
}

esdl_input_file = "Delft_T.esdl"
solution = run_end_scenario_sizing(
EndScenarioSizingStaged,
base_folder=base_folder,
esdl_file_name="Base Netwerk Delft.esdl",
esdl_file_name=esdl_input_file,
esdl_parser=ESDLFileParser,
# **kwargs, # Example of usage if needed/used
**kwargs, # Example of usage if needed/used
)

with open(base_folder / "model" / esdl_input_file.replace(".esdl", "_GrowOptimized.esdl"), "w", encoding="utf-8") as f:
f.write(solution.optimized_esdl_string)

print("Execution time: " + time.strftime("%M:%S", time.gmtime(time.time() - start_time)))
2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@
# < 81.0.0 needed for pandapipes (still to be removed)
# < 82.0.0 needed for pkg_resources (used in rtctools)
"setuptools <= 80.9.0",
"pyesdl == 26.3",
"pyesdl[profiles] == 26.5",
"pandas >= 1.3.1, < 2.0",
"casadi-gil-comp == 3.6.7",
"StrEnum == 0.4.15",
Expand Down
12 changes: 6 additions & 6 deletions src/mesido/asset_sizing_mixin.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
from mesido.esdl.asset_to_component_base import AssetStateEnum
from mesido.esdl.common import Asset
from mesido.esdl.esdl_additional_vars_mixin import get_asset_contraints
from mesido.esdl.profile_parser import InfluxDBProfileReader
from mesido.esdl.profile_parser import ESDLProfileReader
from mesido.head_loss_class import HeadLossOption
from mesido.network_common import NetworkSettings
from mesido.pipe_class import CableClass, GasPipeClass, PipeClass
Expand Down Expand Up @@ -812,7 +812,7 @@ def _make_max_size_var(name, lb, ub, nominal):
if (
qty_asset_profile_constraints > 0
and hasattr(asset_profile_constraints[0], "maximum")
and InfluxDBProfileReader._get_profile_quantity_and_unit(
and ESDLProfileReader._get_profile_quantity_and_unit(
asset_profile_constraints[0].maximum
).unit
== esdl.UnitEnum.WATT
Expand Down Expand Up @@ -1907,7 +1907,7 @@ def __producer_constraints(
if (
qty_asset_profile_constraints > 0
and hasattr(asset_profile_constraints[0], "maximum")
and InfluxDBProfileReader._get_profile_quantity_and_unit(
and ESDLProfileReader._get_profile_quantity_and_unit(
asset_profile_constraints[0].maximum
).unit
== esdl.UnitEnum.WATT
Expand Down Expand Up @@ -1950,16 +1950,16 @@ def __producer_constraints(
# profile is specified without units (xlm/csv)
qty_asset_profile_constraints == 0
or (
InfluxDBProfileReader._get_profile_quantity_and_unit(
ESDLProfileReader._get_profile_quantity_and_unit(
asset_profile_constraints[0].maximum
).physicalQuantity
== esdl.PhysicalQuantityEnum.COEFFICIENT
and (
InfluxDBProfileReader._get_profile_quantity_and_unit(
ESDLProfileReader._get_profile_quantity_and_unit(
asset_profile_constraints[0].maximum
).unit
== esdl.UnitEnum.PERCENT
or InfluxDBProfileReader._get_profile_quantity_and_unit(
or ESDLProfileReader._get_profile_quantity_and_unit(
asset_profile_constraints[0].maximum
).unit
== esdl.UnitEnum.NONE
Expand Down
53 changes: 35 additions & 18 deletions src/mesido/esdl/esdl_mixin.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
from mesido.esdl.esdl_model_base import _ESDLModelBase
from mesido.esdl.esdl_parser import ESDLStringParser
from mesido.esdl.esdl_qth_model import ESDLQTHModel
from mesido.esdl.profile_parser import BaseProfileReader, InfluxDBProfileReader
from mesido.esdl.profile_parser import BaseProfileReader, ESDLProfileReader
from mesido.physics_mixin import PhysicsMixin
from mesido.pipe_class import GasPipeClass, PipeClass
from mesido.pycml.pycml_mixin import PyCMLMixin
Expand Down Expand Up @@ -57,6 +57,17 @@ class DBAccessType(StrEnum):
READ_WRITE = "read_write"


class ESDLOutputProfilesType(StrEnum):
"""
Enumeration for ESDL output profiles type
"""

INFLUXDB = "influxdb"
POSTGRESQL = "postgresql"
TIME_SERIES_PROFILE = "time_series_profile"
DATE_TIME_PROFILE = "date_time_profile"


class _ESDLInputException(Exception):
pass

Expand Down Expand Up @@ -131,7 +142,7 @@ def __init__(self, *args, **kwargs) -> None:
DBAccessType.WRITE: [],
}

profile_reader_class = kwargs.get("profile_reader", InfluxDBProfileReader)
profile_reader_class = kwargs.get("profile_reader", ESDLProfileReader)
input_file_name = kwargs.get("input_timeseries_file", None)
input_folder = kwargs.get("input_folder")
input_file_path = None
Expand All @@ -142,35 +153,41 @@ def __init__(self, *args, **kwargs) -> None:
for dbconnection in database_connection_info:
if dbconnection["access_type"] != DBAccessType.WRITE:
database_host_port = "{}:{}".format(
dbconnection["influxdb_host"],
dbconnection["influxdb_port"],
dbconnection["host"],
dbconnection["port"],
)
read_only_dbase_credentials[database_host_port] = (
dbconnection["influxdb_username"],
dbconnection["influxdb_password"],
dbconnection["username"],
dbconnection["password"],
)
if dbconnection["access_type"] != DBAccessType.READ_WRITE:
self._database_credentials[dbconnection["access_type"]].append(
{
"influxdb_host": dbconnection["influxdb_host"],
"influxdb_port": dbconnection["influxdb_port"],
"influxdb_username": dbconnection["influxdb_username"],
"influxdb_password": dbconnection["influxdb_password"],
"influxdb_ssl": dbconnection["influxdb_ssl"],
"influxdb_verify_ssl": dbconnection["influxdb_verify_ssl"],
"host": dbconnection["host"],
"port": dbconnection["port"],
"username": dbconnection["username"],
"password": dbconnection["password"],
"ssl": dbconnection["ssl"] if "ssl" in dbconnection else False,
"verify_ssl": (
dbconnection["verify_ssl"] if "verify_ssl" in dbconnection else False
),
}
)
elif dbconnection["access_type"] == DBAccessType.READ_WRITE:
both_read_and_write = [DBAccessType.READ, DBAccessType.WRITE]
for rw in both_read_and_write:
self._database_credentials[rw].append(
{
"influxdb_host": dbconnection["influxdb_host"],
"influxdb_port": dbconnection["influxdb_port"],
"influxdb_username": dbconnection["influxdb_username"],
"influxdb_password": dbconnection["influxdb_password"],
"influxdb_ssl": dbconnection["influxdb_ssl"],
"influxdb_verify_ssl": dbconnection["influxdb_verify_ssl"],
"host": dbconnection["host"],
"port": dbconnection["port"],
"username": dbconnection["username"],
"password": dbconnection["password"],
"ssl": dbconnection["ssl"] if "ssl" in dbconnection else False,
"verify_ssl": (
dbconnection["verify_ssl"]
if "verify_ssl" in dbconnection
else False
),
}
)
else:
Expand Down
Loading
Loading