Skip to content

Commit

Permalink
implement configs for bs execution
Browse files Browse the repository at this point in the history
  • Loading branch information
k-rieck committed Sep 26, 2024
1 parent 59e4607 commit 645e000
Show file tree
Hide file tree
Showing 10,519 changed files with 799,052 additions and 335 deletions.
The diff you're trying to view is too large. We only load the first 3000 changed files.
3 changes: 2 additions & 1 deletion .github/workflows/codequality.yml
Original file line number Diff line number Diff line change
Expand Up @@ -32,4 +32,5 @@ jobs:
- name: Lint with prospector
working-directory: ./
run: |
prospector building_sizer/
prospector building_sizer_execution/
prospector building_sizer_preparation/
7 changes: 3 additions & 4 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -131,9 +131,8 @@ dmypy.json
# Pyre type checker
.pyre/

/building_sizer/bs_request*
/building_sizer/default_module_config.json
/building_sizer/*.txt
/building_sizer/*.prof
/building_sizer_results/bs_request*
/building_sizer_execution/*.txt
/building_sizer_execution/*.prof

/cluster_requests/slurm_output_files
File renamed without changes.
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,10 @@
TimeSeriesRequest,
)

from building_sizer import individual_encoding, evolutionary_algorithm as evo_alg
from building_sizer_execution import (
individual_encoding,
evolutionary_algorithm as evo_alg,
)


@dataclasses_json.dataclass_json
Expand Down

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
from typing import List, Tuple
import random

from building_sizer import individual_encoding
from building_sizer_execution import individual_encoding


def unique(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
from typing import List, Tuple
import random

from building_sizer import individual_encoding_no_utsp
from building_sizer_execution import individual_encoding_no_utsp


def unique(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
import os
import json
from typing import Dict, Optional

sys.path.append("/fast/home/k-rieck/repositories/HiSim")
from hisim.building_sizer_utils.interface_configs.system_config import (
EnergySystemConfig,
Expand All @@ -25,47 +26,31 @@
)
from hisim import log


def run_hisim_simulation_and_collect_kpis(
hisim_config_path: str, household_module: str, main_building_sizer_request_directory: str, result_dict_path: str) -> Dict[str, Dict]:
hisim_config_path: str,
household_module: str,
main_building_sizer_request_directory: str,
result_dict_path: str,
my_simulation_parameters_json_string: str,
) -> Dict[str, Dict]:
"""
Collects the results from the HiSim request.
"""
# run HiSim for each config and get kpis and store in dictionary
# set simulation parameters here
year = 2021
seconds_per_timestep = 60 * 15
my_simulation_parameters = SimulationParameters.one_day_only(
year=year, seconds_per_timestep=seconds_per_timestep
)
# set postprocessing options
my_simulation_parameters.post_processing_options.append(
PostProcessingOptions.PREPARE_OUTPUTS_FOR_SCENARIO_EVALUATION
)
my_simulation_parameters.post_processing_options.append(
PostProcessingOptions.COMPUTE_OPEX
)
my_simulation_parameters.post_processing_options.append(
PostProcessingOptions.COMPUTE_CAPEX
)
my_simulation_parameters.post_processing_options.append(
PostProcessingOptions.COMPUTE_KPIS)
my_simulation_parameters.post_processing_options.append(
PostProcessingOptions.WRITE_KPIS_TO_JSON
)
my_simulation_parameters.post_processing_options.append(
PostProcessingOptions.WRITE_KPIS_TO_JSON_FOR_BUILDING_SIZER
# get simulation paramters
my_simulation_parameters = SimulationParameters.from_json(
my_simulation_parameters_json_string
)
# set logging level to 1
my_simulation_parameters.logging_level = 3
# run HiSim for each config and get kpis and store in dictionary
household_module = household_module
path_to_module = f"/fast/home/k-rieck/repositories/HiSim/system_setups/{household_module}.py"
path_to_module = (
f"/fast/home/k-rieck/repositories/HiSim/system_setups/{household_module}.py"
)
# set hisim results directory
# if requisite_hisim_config_path is given, get hash number and sampling mode for result path
if hisim_config_path is not None:
config_filename_splitted = hisim_config_path.split("/")
scenario_hash_string = re.findall(r"\-?\d+", config_filename_splitted[-1])[
0
]
scenario_hash_string = re.findall(r"\-?\d+", config_filename_splitted[-1])[0]
further_result_folder_description = config_filename_splitted[-2]

hisim_result_directory = os.path.join(
Expand Down Expand Up @@ -103,22 +88,23 @@ def run_hisim_simulation_and_collect_kpis(
encoding="utf-8",
) as result_file:
kpis_building_sizer = json.load(result_file)
print("KPIs building sizer", kpis_building_sizer)
# add configs and respective kpis to dictionary
current_result_dict = {hisim_config_path: kpis_building_sizer}


# Step 2: Open the JSON file, read the content, and load it into a Python dictionary
with open(result_dict_path, 'r') as file:
with open(result_dict_path, "r") as file:
data = json.load(file)

# Step 3: Append the new dictionary (this assumes `data` is a dictionary)
data.update(current_result_dict)

# Step 4: Write the updated dictionary back to the JSON file
with open(result_dict_path, 'w') as file:
with open(result_dict_path, "w") as file:
json.dump(data, file, indent=4)
print(f"write {data} to {result_dict_path}")


if __name__ == "__main__":
if len(sys.argv) < 5:
log.information("HiSim simulation script needs four arguments.")
Expand All @@ -127,11 +113,20 @@ def run_hisim_simulation_and_collect_kpis(
HOUSEHOLD_MODULE = sys.argv[2]
MAIN_REQUEST_DIRECTORY = sys.argv[3]
RESULT_DICT_PATH = sys.argv[4]
SIMULATION_PARAMETERS_JSON_STRING = sys.argv[5]

print("calling " + HOUSEHOLD_MODULE + " with config " + HISIM_CONFIG_PATH + " and request directory " + MAIN_REQUEST_DIRECTORY)
run_hisim_simulation_and_collect_kpis(hisim_config_path=HISIM_CONFIG_PATH,
household_module=HOUSEHOLD_MODULE,
main_building_sizer_request_directory=MAIN_REQUEST_DIRECTORY,
result_dict_path=RESULT_DICT_PATH)


print(
"calling "
+ HOUSEHOLD_MODULE
+ " with config "
+ HISIM_CONFIG_PATH
+ " and request directory "
+ MAIN_REQUEST_DIRECTORY
)
run_hisim_simulation_and_collect_kpis(
hisim_config_path=HISIM_CONFIG_PATH,
household_module=HOUSEHOLD_MODULE,
main_building_sizer_request_directory=MAIN_REQUEST_DIRECTORY,
result_dict_path=RESULT_DICT_PATH,
my_simulation_parameters_json_string=SIMULATION_PARAMETERS_JSON_STRING,
)
File renamed without changes.
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
from typing import List

from dataclasses_json import dataclass_json

sys.path.append("/fast/home/k-rieck/repositories/HiSim")
from hisim.building_sizer_utils.interface_configs.system_config import (
EnergySystemConfig,
Expand All @@ -32,26 +33,19 @@ class SizingOptions:
share_of_maximum_pv_potential: List[float] = field(
default_factory=lambda: [round(i * 0.1, 1) for i in range(11)]
)
#: list of heating system for space heating
space_heating_system: List[HeatingSystems] = field(
default_factory=lambda: [HeatingSystems.HEAT_PUMP, HeatingSystems.GAS_HEATING]
)
#: list of heating system for domestic hot water
domestic_hot_water_heating_system: List[HeatingSystems] = field(
#: list of heating system for space heating and domestic hot water
heating_system: List[HeatingSystems] = field(
default_factory=lambda: [HeatingSystems.HEAT_PUMP, HeatingSystems.GAS_HEATING]
)

# these lists define the layout of the individual vectors
#: list of technologies (boolean attributes) considered in the optimization
# bool_attributes: List[str] = field(
# default_factory=lambda: ["pv_included", "battery_included"]
# )
#: list of technologies with different sizing options (discrete attributes) used within the optimization
discrete_attributes: List[str] = field(
default_factory=lambda: [
"share_of_maximum_pv_potential",
"domestic_hot_water_heating_system",
"space_heating_system",
]
default_factory=lambda: ["share_of_maximum_pv_potential", "heating_system",]
)
# this list defines the probabilites of each component to be included at the beginning
#: defines probability of each component to be considered at the initial configurations
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,8 @@
from utspclient import client # type: ignore
from utspclient.datastructures import TimeSeriesRequest # type: ignore

from building_sizer import building_sizer_algorithm, individual_encoding
from building_sizer.building_sizer_algorithm import (
from building_sizer_execution import building_sizer_algorithm, individual_encoding
from building_sizer_execution.building_sizer_algorithm import (
BuildingSizerRequest,
BuildingSizerResult,
)
Expand Down
Loading

0 comments on commit 645e000

Please sign in to comment.