Skip to content

Commit

Permalink
manually porting over changes from #252
Browse files Browse the repository at this point in the history
  • Loading branch information
nmerket committed Jul 7, 2023
1 parent f37754c commit 3bf2adb
Show file tree
Hide file tree
Showing 7 changed files with 148 additions and 8 deletions.
5 changes: 4 additions & 1 deletion buildstockbatch/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,9 @@ 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']

# Load in OS_VERSION and OS_SHA arguments if they exist in the YAML,
# otherwise use defaults specified here.
self.os_version = self.cfg.get('os_version', self.DEFAULT_OS_VERSION)
Expand Down Expand Up @@ -856,7 +859,7 @@ def get_dask_client(self):
def process_results(self, skip_combine=False, force_upload=False):
self.get_dask_client() # noqa: F841

if self.cfg['workflow_generator']['type'] == 'residential_hpxml':
if 'residential_hpxml' in self.cfg['workflow_generator']['type']:
if 'simulation_output_report' in self.cfg['workflow_generator']['args'].keys():
if 'timeseries_frequency' in self.cfg['workflow_generator']['args']['simulation_output_report'].keys():
do_timeseries = \
Expand Down
5 changes: 4 additions & 1 deletion buildstockbatch/local.py
Original file line number Diff line number Diff line change
Expand Up @@ -127,7 +127,7 @@ def weather_dir(self):
return self._weather_dir

@classmethod
def run_building(cls, buildstock_dir, weather_dir, results_dir, measures_only,
def run_building(cls, buildstock_dir, weather_dir, os_hescore_dir, results_dir, measures_only,
n_datapoints, cfg, i, upgrade_idx=None):

upgrade_id = 0 if upgrade_idx is None else upgrade_idx + 1
Expand All @@ -143,6 +143,8 @@ def run_building(cls, buildstock_dir, weather_dir, results_dir, measures_only,
(sim_path / 'measures').symlink_to(buildstock_path / 'measures', target_is_directory=True)
(sim_path / 'lib').symlink_to(buildstock_path / "lib", target_is_directory=True)
(sim_path / 'weather').symlink_to(weather_dir, target_is_directory=True)

# ResStock-HPXML measure directory
hpxml_measures_path = buildstock_path / 'resources' / 'hpxml-measures'
if hpxml_measures_path.exists():
resources_path = sim_path / 'resources'
Expand Down Expand Up @@ -240,6 +242,7 @@ def run_batch(self, n_jobs=None, measures_only=False, sampling_only=False):
delayed(self.run_building),
self.buildstock_dir,
self.weather_dir,
self.os_hescore_dir,
self.results_dir,
measures_only,
n_datapoints,
Expand Down
10 changes: 7 additions & 3 deletions buildstockbatch/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -39,12 +39,16 @@ 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['workflow_generator']['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
3 changes: 2 additions & 1 deletion buildstockbatch/workflow_generator/__init__.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
# -*- coding: utf-8 -*-

from .commercial import CommercialDefaultWorkflowGenerator # noqa F041
from .residential_hpxml import ResidentialHpxmlWorkflowGenerator # noqa F041
from .residential_hpxml import ResidentialHpxmlWorkflowGenerator # noqa F041
from .residential_hpxml_hes import ResidentialHpxmlHesWorkflowGenerator # noqa F041
9 changes: 7 additions & 2 deletions buildstockbatch/workflow_generator/residential_hpxml.py
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ def get_measure_arguments(xml_path):
class ResidentialHpxmlWorkflowGenerator(WorkflowGeneratorBase):

@classmethod
def validate(cls, cfg):
def get_yml_schema(cls):
"""Validate arguments
:param cfg: project configuration
Expand Down Expand Up @@ -141,9 +141,14 @@ def validate(cls, cfg):
retain_schedules_csv: bool(required=False)
debug: bool(required=False)
""" # noqa E501
workflow_generator_args = cfg['workflow_generator']['args']
schema_yml = re.sub(r'^ {8}', '', schema_yml, flags=re.MULTILINE)
schema = yamale.make_schema(content=schema_yml, parser='ruamel')
return schema

@classmethod
def validate(cls, cfg):
schema = cls.get_yml_schema()
workflow_generator_args = cfg['workflow_generator']['args']
data = yamale.make_data(content=json.dumps(workflow_generator_args), parser='ruamel')
yamale.validate(schema, data, strict=True)
return cls.validate_measures_and_arguments(cfg)
Expand Down
40 changes: 40 additions & 0 deletions buildstockbatch/workflow_generator/residential_hpxml_hes.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
# -*- coding: utf-8 -*-

"""
buildstockbatch.workflow_generator.residential_hpxml_hes
~~~~~~~~~~~~~~~
This object contains the residential classes for generating OSW files from individual samples
:author: Joe Robertson
:copyright: (c) 2021 by The Alliance for Sustainable Energy
:license: BSD-3
"""

import os
import yamale
from .residential_hpxml import ResidentialHpxmlWorkflowGenerator # noqa F041


class ResidentialHpxmlHesWorkflowGenerator(ResidentialHpxmlWorkflowGenerator):

@property
def os_hescore_dir(self):
return self.cfg['workflow_generator']['args']['build_existing_model']['os_hescore_directory']

def create_osw(self, sim_id, building_id, upgrade_idx):
osw = super().create_osw(sim_id, building_id, upgrade_idx)
if 'os_hescore_directory' in osw['steps'][0]['arguments']:
osw['steps'][0]['arguments']['os_hescore_directory'] = self.os_hescore_dir

# Add measure path for reporting measure
osw['measure_paths'].insert(0, os.path.join(self.os_hescore_dir, 'hpxml-measures'))
return osw

@classmethod
def get_yml_schema(cls):
schema = super().get_yml_schema()

# Require os_hescore_directory argument
string_validator = yamale.validators.String(required=True)
schema.includes['build-existing-model-spec'].dict['os_hescore_directory'] = string_validator
return schema
84 changes: 84 additions & 0 deletions buildstockbatch/workflow_generator/test_workflow_generator.py
Original file line number Diff line number Diff line change
Expand Up @@ -146,6 +146,90 @@ def test_residential_hpxml(mocker):
assert server_dir_cleanup_step['measure_dir_name'] == 'ServerDirectoryCleanup'


def test_residential_hpxml_hes(mocker):
sim_id = 'bldb1up1'
building_id = 1
upgrade_idx = 0
cfg = {
'baseline': {
'n_buildings_represented': 100
},
'workflow_generator': {
'type': 'residential_hpxml',
'args': {
'build_existing_model': {
'simulation_control_run_period_begin_month': 2,
'simulation_control_run_period_begin_day_of_month': 1,
'simulation_control_run_period_end_month': 2,
'simulation_control_run_period_end_day_of_month': 28,
'simulation_control_run_period_calendar_year': 2010,
'os_hescore_directory': '../OpenStudio-HEScore'
},

'simulation_output_report': {
'timeseries_frequency': 'hourly',
'include_timeseries_end_use_consumptions': True,
'include_timeseries_total_loads': True,
'include_timeseries_zone_temperatures': False,
}
}
},
'upgrades': [
{
'options': [
{
'option': 'Parameter|Option',
}
],
}
]
}
n_datapoints = 10
osw_gen = ResidentialHpxmlHesWorkflowGenerator(cfg, n_datapoints)
osw = osw_gen.create_osw(sim_id, building_id, upgrade_idx)

steps = osw['steps']
assert len(steps) == 8

build_existing_model_step = steps[0]
assert build_existing_model_step['measure_dir_name'] == 'BuildExistingModel'
assert build_existing_model_step['arguments']['simulation_control_run_period_begin_month'] == 2
assert build_existing_model_step['arguments']['simulation_control_run_period_begin_day_of_month'] == 1
assert build_existing_model_step['arguments']['simulation_control_run_period_end_month'] == 2
assert build_existing_model_step['arguments']['simulation_control_run_period_end_day_of_month'] == 28
assert build_existing_model_step['arguments']['simulation_control_run_period_calendar_year'] == 2010
assert build_existing_model_step['arguments']['os_hescore_directory'] == "/opt/OpenStudio-HEScore"

apply_upgrade_step = steps[1]
assert apply_upgrade_step['measure_dir_name'] == 'ApplyUpgrade'

apply_upgrade_step = steps[2]
assert apply_upgrade_step['measure_dir_name'] == 'HPXMLtoOpenStudio'
assert apply_upgrade_step['arguments']['hpxml_path'] == '/var/simdata/openstudio/run/home.xml'
assert apply_upgrade_step['arguments']['output_dir'] == '/var/simdata/openstudio/run'
assert apply_upgrade_step['arguments']['debug'] is False
assert apply_upgrade_step['arguments']['add_component_loads'] is False

simulation_output_step = steps[3]
assert simulation_output_step['measure_dir_name'] == 'ReportSimulationOutput'
assert simulation_output_step['arguments']['timeseries_frequency'] == 'hourly'
assert simulation_output_step['arguments']['include_timeseries_end_use_consumptions'] is True
assert simulation_output_step['arguments']['include_timeseries_total_loads'] is True
assert simulation_output_step['arguments']['include_timeseries_zone_temperatures'] is False

hpxml_output_step = steps[4]
assert hpxml_output_step['measure_dir_name'] == 'ReportHPXMLOutput'

hpxml_output_step = steps[5]
assert hpxml_output_step['measure_dir_name'] == 'ReportUtilityBills'

upgrade_costs_step = steps[6]
assert upgrade_costs_step['measure_dir_name'] == 'UpgradeCosts'

server_dir_cleanup_step = steps[7]
assert server_dir_cleanup_step['measure_dir_name'] == 'ServerDirectoryCleanup'


def test_com_default_workflow_generator_basic(mocker):
sim_id = 'bldb1up1'
building_id = 1
Expand Down

0 comments on commit 3bf2adb

Please sign in to comment.