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

HES Workflow Generator, try 2 #378

Open
wants to merge 15 commits into
base: develop
Choose a base branch
from
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
12 changes: 11 additions & 1 deletion buildstockbatch/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,16 @@ def __init__(self, project_filename):
if not os.path.isdir(self.project_dir):
raise FileNotFoundError(f"project_directory = {self.project_dir} is not a directory.")

if self.cfg["workflow_generator"]["type"] == "residential_hpxml_hes":
self.os_hescore_dir = self.cfg["workflow_generator"]["args"]["build_existing_model"]["os_hescore_directory"]
else:
self.os_hescore_dir = None

if self.cfg["workflow_generator"]["type"] == "residential_hpxml_hes":
self.os_hescore_dir = self.cfg["workflow_generator"]["args"]["build_existing_model"]["os_hescore_directory"]
else:
self.os_hescore_dir = None

# Load in OS_VERSION and OS_SHA arguments if they exist in the YAML,
# otherwise use defaults specified here.
self.os_version = self.cfg["os_version"]
Expand Down Expand Up @@ -942,7 +952,7 @@ def process_results(self, skip_combine=False, use_dask_cluster=True):

try:
wfg_args = self.cfg["workflow_generator"].get("args", {})
if self.cfg["workflow_generator"]["type"] == "residential_hpxml":
if "residential_hpxml" in self.cfg["workflow_generator"]["type"]:
if "simulation_output_report" in wfg_args.keys():
if "timeseries_frequency" in wfg_args["simulation_output_report"].keys():
do_timeseries = wfg_args["simulation_output_report"]["timeseries_frequency"] != "none"
Expand Down
9 changes: 7 additions & 2 deletions buildstockbatch/hpc.py
Original file line number Diff line number Diff line change
Expand Up @@ -246,7 +246,9 @@ def run_job_batch(self, job_array_number):
@delayed
def run_building_d(i, upgrade_idx):
try:
return self.run_building(self.output_dir, self.cfg, args["n_datapoints"], i, upgrade_idx)
return self.run_building(
self.output_dir, self.cfg, self.os_hescore_dir, args["n_datapoints"], i, upgrade_idx
)
except Exception:
with open(traceback_file_path, "a") as f:
txt = get_error_details()
Expand Down Expand Up @@ -315,7 +317,7 @@ def run_building_d(i, upgrade_idx):
self.local_apptainer_img.unlink(missing_ok=True)

@classmethod
def run_building(cls, output_dir, cfg, n_datapoints, i, upgrade_idx=None):
def run_building(cls, output_dir, cfg, os_hescore_dir, n_datapoints, i, upgrade_idx=None):
fs = LocalFileSystem()
upgrade_id = 0 if upgrade_idx is None else upgrade_idx + 1

Expand Down Expand Up @@ -369,6 +371,9 @@ def run_building(cls, output_dir, cfg, n_datapoints, i, upgrade_idx=None):
container_mount = "/resources/hpxml-measures"
args.extend(["-B", f"{src}:{container_mount}:ro"])

if os_hescore_dir:
args.extend(["-B", "/projects/hescore/weather:/opt/OpenStudio-HEScore/weather:ro"])

# Build the openstudio command that will be issued within the
# apptainer container If custom gems are to be used in the
# apptainer container add extra bundle arguments to the cli
Expand Down
3 changes: 3 additions & 0 deletions buildstockbatch/test/test_aws.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,14 @@
import logging

from buildstockbatch.aws.aws import AwsBatch
from buildstockbatch.test.shared_testing_stuff import docker_available

here = os.path.dirname(os.path.abspath(__file__))
logging.basicConfig(level="DEBUG") # Use DEBUG, INFO, or WARNING
logger = logging.getLogger(__name__)


@docker_available
def test_custom_gem_install(basic_residential_project_file):
project_filename, results_dir = basic_residential_project_file(
update_args={
Expand Down Expand Up @@ -49,6 +51,7 @@ def test_custom_gem_install(basic_residential_project_file):
assert custom_gem in contents


@docker_available
def test_no_custom_gem_install(basic_residential_project_file):
project_filename, results_dir = basic_residential_project_file(
update_args={
Expand Down
2 changes: 2 additions & 0 deletions buildstockbatch/test/test_docker_base.py
Original file line number Diff line number Diff line change
Expand Up @@ -187,6 +187,7 @@ def test_run_simulations(basic_residential_project_file):
os.chdir(old_cwd)


@docker_available
def test_find_missing_tasks(basic_residential_project_file, mocker):
project_filename, results_dir = basic_residential_project_file()
results_dir = os.path.join(results_dir, "results")
Expand All @@ -207,6 +208,7 @@ def test_find_missing_tasks(basic_residential_project_file, mocker):
assert [int(t) for t in f.readlines()] == missing_results


@docker_available
def test_log_summary(basic_residential_project_file, mocker, caplog):
"""
Test logging a summary of simulation statuses.
Expand Down
2 changes: 1 addition & 1 deletion buildstockbatch/test/test_hpc.py
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ def test_hpc_run_building(mock_subprocess, monkeypatch, basic_residential_projec
KestrelBatch, "local_scratch", tmp_path
):
# Normal run
run_bldg_args = [results_dir, cfg, 1, None]
run_bldg_args = [results_dir, cfg, None, 1, None]
KestrelBatch.run_building(*run_bldg_args)
expected_apptainer_args = [
"apptainer",
Expand Down
9 changes: 6 additions & 3 deletions buildstockbatch/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -47,12 +47,15 @@ def get_project_configuration(project_file):

# Set absolute paths
cfg["buildstock_directory"] = path_rel_to_file(project_file, cfg["buildstock_directory"])
# if 'precomputed_sample' in cfg.get('baseline', {}):
# cfg['baseline']['precomputed_sample'] = \
# path_rel_to_file(project_file, cfg['baseline']['precomputed_sample'])

if "weather_files_path" in cfg:
cfg["weather_files_path"] = path_rel_to_file(project_file, cfg["weather_files_path"])

if cfg.get("workflow_generator", {}).get("type") == "residential_hpxml_hes":
cfg["workflow_generator"]["args"]["build_existing_model"]["os_hescore_directory"] = path_rel_to_file(
project_file, cfg["workflow_generator"]["args"]["build_existing_model"]["os_hescore_directory"]
)

return cfg


Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,16 +38,21 @@ def __init__(self, cfg, n_datapoints):
self.default_args = copy.deepcopy(DEFAULT_MEASURE_ARGS)
self.all_arg_map = copy.deepcopy(ARG_MAP)

@classmethod
def get_yml_schema(cls):
schema_yml = os.path.join(os.path.dirname(__file__), "residential_hpxml_schema.yml")
schema = yamale.make_schema(schema_yml, parser="ruamel")
return schema

def validate(self):
"""Validate arguments

:param cfg: project configuration
:type cfg: dict
"""
workflow_generator_args = self.cfg["workflow_generator"]["args"]
schema_yml = os.path.join(os.path.dirname(__file__), "residential_hpxml_schema.yml")
schema = yamale.make_schema(schema_yml, parser="ruamel")
data = yamale.make_data(content=json.dumps(workflow_generator_args), parser="ruamel")
schema = self.get_yml_schema()
yamale.validate(schema, data, strict=True)
return self.validate_measures_and_arguments()

Expand Down Expand Up @@ -166,6 +171,11 @@ def create_osw(self, sim_id, building_id, upgrade_idx):
"measure_paths": ["measures", "resources/hpxml-measures"],
"run_options": {"skip_zip_results": True},
}

# Insert the OpenStudio-HEScore measures into the workflow if we're doing a HEScore run
if os_hescore_directory := workflow_args.get("build_existing_model", {}).get("os_hescore_directory"):
osw["measure_paths"].insert(0, os.path.join(os_hescore_directory, "hpxml-measures"))

for measure in reversed(workflow_args.get("measures", [])):
osw["steps"].insert(3, measure) # After UpgradeCosts

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ build-existing-model-spec:
simulation_control_run_period_end_day_of_month: int(required=False)
simulation_control_run_period_calendar_year: int(required=False)
add_component_loads: bool(required=False)
os_hescore_directory: str(required=False)
emission-scenario-spec:
scenario_name: str(required=True)
type: str(required=True)
Expand Down
Loading