Skip to content
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

34: Add new Grow workflows. #39

Merged
merged 1 commit into from
Mar 4, 2024
Merged
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
2 changes: 1 addition & 1 deletion .env-template
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ POSTGRESQL_HOSTNAME=localhost
POSTGRESQL_PORT=5432
POSTGRESQL_DATABASE=omotes_celery

# May be grow_optimizer or grow_simulator
# May be grow_optimizer, grow_simulator, grow_optimizer_no_heat_losses, grow_optimizer_no_heat_losses_discounted_capex
GROW_TASK_TYPE=grow_optimizer
LOG_LEVEL=INFO

Expand Down
4 changes: 2 additions & 2 deletions dev-requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -192,7 +192,7 @@ pyecore==0.12.1
# -c requirements.txt
# pyesdl
# rtc-tools-heat-network
pyesdl==23.11.1
pyesdl==24.2
# via
# -c requirements.txt
# rtc-tools-heat-network
Expand Down Expand Up @@ -243,7 +243,7 @@ rtc-tools-channel-flow==1.1.2
# via
# -c requirements.txt
# rtc-tools
rtc-tools-heat-network==0.4.5
rtc-tools-heat-network==0.4.6
# via
# -c requirements.txt
# omotes-grow-worker (pyproject.toml)
Expand Down
2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ requires-python = ">=3.10"

dependencies = [
"python-dotenv ~= 1.0.0",
"rtc-tools-heat-network ~= 0.4.5",
"rtc-tools-heat-network ~= 0.4.6",
"omotes-sdk-python ~= 0.0.9"
]

Expand Down
4 changes: 2 additions & 2 deletions requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ pyecore==0.12.1
# via
# pyesdl
# rtc-tools-heat-network
pyesdl==23.11.1
pyesdl==24.2
# via rtc-tools-heat-network
pymoca==0.9.0
# via
Expand All @@ -107,7 +107,7 @@ rtc-tools==2.6.0a3
# via rtc-tools-heat-network
rtc-tools-channel-flow==1.1.2
# via rtc-tools
rtc-tools-heat-network==0.4.5
rtc-tools-heat-network==0.4.6
# via omotes-grow-worker (pyproject.toml)
scipy==1.10.1
# via rtc-tools
Expand Down
10 changes: 7 additions & 3 deletions src/grow_worker/worker.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,13 @@
# from celery.signals import after_setup_logger

from omotes_sdk.internal.worker.worker import initialize_worker, UpdateProgressHandler
from rtctools_heat_network.workflows import run_end_scenario_sizing

from grow_worker.worker_types import GrowTaskType, GROWProblem, get_problem_type
from grow_worker.worker_types import (
GrowTaskType,
GROWProblem,
get_problem_type,
get_problem_function,
)

logger = logging.getLogger("grow_worker")
GROW_TASK_TYPE = GrowTaskType(os.environ.get("GROW_TASK_TYPE"))
Expand Down Expand Up @@ -41,7 +45,7 @@ def grow_worker_task(
f"At {influxdb_host}:{influxdb_port}"
)

solution: GROWProblem = run_end_scenario_sizing(
solution: GROWProblem = get_problem_function(GROW_TASK_TYPE)(
get_problem_type(GROW_TASK_TYPE),
base_folder=base_folder,
esdl_string=base64.encodebytes(input_esdl.encode("utf-8")),
Expand Down
49 changes: 46 additions & 3 deletions src/grow_worker/worker_types.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,15 @@
from enum import Enum
from typing import Type, Union
from typing import Type, Union, Callable

from rtctools_heat_network.workflows import (
EndScenarioSizingHIGHS,
NetworkSimulatorHIGHSWeeklyTimeStep,
EndScenarioSizingStagedHIGHS,
EndScenarioSizingDiscountedHIGHS,
)
from rtctools_heat_network.workflows import (
run_end_scenario_sizing,
run_end_scenario_sizing_no_heat_losses,
)


Expand All @@ -13,10 +19,21 @@ class GrowTaskType(Enum):
GROW_OPTIMIZER = "grow_optimizer"
"""Run the Grow Optimizer."""
GROW_SIMULATOR = "grow_simulator"
"""Run the Grow simulator."""
"""Run the Grow Simulator."""
GROW_OPTIMIZER_NO_HEAT_LOSSES = "grow_optimizer_no_heat_losses"
"""Run the Grow Optimizer without heat losses."""
GROW_OPTIMIZER_NO_HEAT_LOSSES_DISCOUNTED_CAPEX = (
"grow_optimizer_no_heat_losses_discounted_capex"
)
"""Run the Grow Optimizer without heat losses and a discounted CAPEX."""


GROWProblem = Union[Type[EndScenarioSizingHIGHS], Type[NetworkSimulatorHIGHSWeeklyTimeStep]]
GROWProblem = Union[
Type[EndScenarioSizingHIGHS],
Type[NetworkSimulatorHIGHSWeeklyTimeStep],
Type[EndScenarioSizingStagedHIGHS],
Type[EndScenarioSizingDiscountedHIGHS],
]


def get_problem_type(task_type: GrowTaskType) -> GROWProblem:
Expand All @@ -30,6 +47,32 @@ def get_problem_type(task_type: GrowTaskType) -> GROWProblem:
result = EndScenarioSizingHIGHS
elif task_type == GrowTaskType.GROW_SIMULATOR:
result = NetworkSimulatorHIGHSWeeklyTimeStep
elif task_type == GrowTaskType.GROW_OPTIMIZER_NO_HEAT_LOSSES:
result = EndScenarioSizingStagedHIGHS
elif task_type == GrowTaskType.GROW_OPTIMIZER_NO_HEAT_LOSSES_DISCOUNTED_CAPEX:
result = EndScenarioSizingDiscountedHIGHS
else:
raise RuntimeError(f"Unknown workflow type, please implement {task_type}")

return result


def get_problem_function(
task_type: GrowTaskType,
) -> Callable[..., GROWProblem]:
"""Convert the Grow task type to the Grow function that should be run.

:param task_type: Grow task type.
:return: Grow problem function.
"""
result: GROWProblem
if task_type in [GrowTaskType.GROW_OPTIMIZER, GrowTaskType.GROW_SIMULATOR]:
result = run_end_scenario_sizing
elif task_type in [
GrowTaskType.GROW_OPTIMIZER_NO_HEAT_LOSSES,
GrowTaskType.GROW_OPTIMIZER_NO_HEAT_LOSSES_DISCOUNTED_CAPEX,
]:
result = run_end_scenario_sizing_no_heat_losses
else:
raise RuntimeError(f"Unknown workflow type, please implement {task_type}")

Expand Down
Loading