Skip to content

Commit

Permalink
Merge pull request #971 from NREL/workflow-refactor
Browse files Browse the repository at this point in the history
Move HPXMLtoOpenStudio to top level
  • Loading branch information
joseph-robertson committed Sep 23, 2022
2 parents 7a31b85 + 37a8811 commit 6820973
Show file tree
Hide file tree
Showing 20 changed files with 27,441 additions and 27,425 deletions.
7 changes: 4 additions & 3 deletions docs/read_the_docs/source/tutorial/run_project.rst
Original file line number Diff line number Diff line change
Expand Up @@ -47,12 +47,13 @@ Run ``openstudio workflow/run_analysis.rb -h`` to see all available commands/arg
-y, --yml <FILE> YML file
-n, --threads N Number of parallel simulations (defaults to processor count)
-m, --measures_only Only run the OpenStudio and EnergyPlus measures
-d, --debug Save both existing and upgraded xml/osw files
-i, --building_id ID Only run this building ID; can be called multiple times
-i, --building_id ID Only run this building ID; can be called multiple times
-k, --keep_run_folders Preserve run folder for all datapoints
-s, --samplingonly Run the sampling only
-h, --help Display help
-d, --debug Preserve lib folder and "existing" xml/osw files
-o, --overwrite Overwrite existing project directory
-v, --version Display version
-h, --help Display help
.. note::
At this time the ``residential_quota_downselect`` sampler with ``resample`` is not supported.
2 changes: 0 additions & 2 deletions docs/read_the_docs/source/tutorial/setup_analysis_project.rst
Original file line number Diff line number Diff line change
Expand Up @@ -30,8 +30,6 @@ This measure creates the baseline scenario. Set the following inputs:
#. ``Simulation Control: Run Period End Month``: This numeric field should contain the end month number (1 = January, 2 = February, etc.) for the annual run period desired.
#. ``Simulation Control: Run Period End Day of Month``: This numeric field should contain the ending day of the ending month (must be valid for month) for the annual run period desired.
#. ``Simulation Control: Run Period Calendar Year``: This numeric field should contain the calendar year that determines the start day of week (e.g., 2007 sets the start day of week to Monday). If you are running simulations using AMY weather files, the value entered for calendar year will not be used; it will be overridden by the actual year found in the AMY weather file.
#. ``Debug Mode?``: If true: 1) Writes in.osm file, 2) Generates additional log output, and 3) Creates all EnergyPlus output files.
#. ``Annual Component Loads?``: If true, output the annual component loads.
#. ``Emissions: Scenario Names``: Names of emissions scenarios. If multiple scenarios, use a comma-separated list.
#. ``Emissions: Types``: Types of emissions (e.g., CO2e, NOx, etc.). If multiple scenarios, use a comma-separated list.
#. ``Emissions: Electricity Folders``: Relative paths of electricity emissions factor schedule files with hourly values. Paths are relative to the resources folder (see `this example yml file <https://github.com/NREL/resstock/blob/develop/project_national/national_baseline.yml>`_). If multiple scenarios, use a comma-separated list. File names must contain GEA region names. Units are kg/MWh.
Expand Down
20 changes: 11 additions & 9 deletions measures/ApplyUpgrade/measure.rb
Original file line number Diff line number Diff line change
Expand Up @@ -217,7 +217,7 @@ def run(model, runner, user_arguments)
end

# Get defaulted hpxml
hpxml_path = File.expand_path('../in.xml') # this is the defaulted hpxml
hpxml_path = File.expand_path('../existing.xml') # this is the defaulted hpxml
if File.exist?(hpxml_path)
hpxml = HPXML.new(hpxml_path: hpxml_path)
else
Expand Down Expand Up @@ -322,7 +322,6 @@ def run(model, runner, user_arguments)
hpxml_path = File.expand_path('../upgraded.xml')
measures['BuildResidentialHPXML'] = [{ 'hpxml_path' => hpxml_path }]
measures['BuildResidentialScheduleFile'] = [{ 'hpxml_path' => hpxml_path, 'hpxml_output_path' => hpxml_path }]
measures['HPXMLtoOpenStudio'] = [{ 'hpxml_path' => hpxml_path }]

new_runner.result.stepValues.each do |step_value|
value = get_value_from_workflow_step_value(step_value)
Expand Down Expand Up @@ -420,15 +419,12 @@ def run(model, runner, user_arguments)
measures['BuildResidentialScheduleFile'][0]['schedules_random_seed'] = values['building_id']
measures['BuildResidentialScheduleFile'][0]['output_csv_path'] = File.expand_path('../schedules.csv')

# Get registered values and pass them to HPXMLtoOpenStudio
measures['HPXMLtoOpenStudio'][0]['output_dir'] = File.expand_path('..')
measures['HPXMLtoOpenStudio'][0]['debug'] = values['debug']
measures['HPXMLtoOpenStudio'][0]['add_component_loads'] = values['add_component_loads']

measures_to_apply_hash = { hpxml_measures_dir => { 'BuildResidentialHPXML' => measures['BuildResidentialHPXML'], 'BuildResidentialScheduleFile' => measures['BuildResidentialScheduleFile'], 'HPXMLtoOpenStudio' => measures['HPXMLtoOpenStudio'] },
# Specify measures to run
measures['BuildResidentialHPXML'][0]['apply_defaults'] = true
measures_to_apply_hash = { hpxml_measures_dir => { 'BuildResidentialHPXML' => measures['BuildResidentialHPXML'], 'BuildResidentialScheduleFile' => measures['BuildResidentialScheduleFile'] },
measures_dir => {} }

upgrade_measures = measures.keys - ['ResStockArguments', 'BuildResidentialHPXML', 'BuildResidentialScheduleFile', 'HPXMLtoOpenStudio']
upgrade_measures = measures.keys - ['ResStockArguments', 'BuildResidentialHPXML', 'BuildResidentialScheduleFile']
upgrade_measures.each do |upgrade_measure|
measures_to_apply_hash[measures_dir][upgrade_measure] = measures[upgrade_measure]
end
Expand All @@ -451,6 +447,12 @@ def run(model, runner, user_arguments)
return false
end

# Copy upgraded.xml to home.xml for downstream HPXMLtoOpenStudio
# This will overwrite home.xml from BuildExistingModel
# We need upgraded.xml (and not just home.xml) for UpgradeCosts
in_path = File.expand_path('../home.xml')
FileUtils.cp(hpxml_path, in_path)

return true
end

Expand Down
6 changes: 3 additions & 3 deletions measures/ApplyUpgrade/measure.xml
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@
<schema_version>3.0</schema_version>
<name>apply_upgrade</name>
<uid>33f1654c-f734-43d1-b35d-9d2856e41b5a</uid>
<version_id>b3527288-4721-4237-a024-9bbe70744caf</version_id>
<version_modified>20220908T020038Z</version_modified>
<version_id>bbc2ca5f-4f0f-4baa-8b89-4df062c9eae1</version_id>
<version_modified>20220912T204948Z</version_modified>
<xml_checksum>9339BE01</xml_checksum>
<class_name>ApplyUpgrade</class_name>
<display_name>Apply Upgrade</display_name>
Expand Down Expand Up @@ -6342,7 +6342,7 @@
<filename>measure.rb</filename>
<filetype>rb</filetype>
<usage_type>script</usage_type>
<checksum>7C582801</checksum>
<checksum>ADB8265D</checksum>
</file>
</files>
</measure>
62 changes: 9 additions & 53 deletions measures/BuildExistingModel/measure.rb
Original file line number Diff line number Diff line change
Expand Up @@ -50,11 +50,6 @@ def arguments(model) # rubocop:disable Lint/UnusedMethodArgument
arg.setDescription("Logic that specifies the subset of the building stock to be considered in the analysis. Specify one or more parameter|option as found in resources\\options_lookup.tsv. When multiple are included, they must be separated by '||' for OR and '&&' for AND, and using parentheses as appropriate. Prefix an option with '!' for not.")
args << arg

arg = OpenStudio::Ruleset::OSArgument.makeStringArgument('measures_to_ignore', false)
arg.setDisplayName('Measures to Ignore')
arg.setDescription("Measures to exclude from the OpenStudio Workflow specified by listing one or more measure directories separated by '|'. Core ResStock measures cannot be ignored (this measure will fail). INTENDED FOR ADVANCED USERS/WORKFLOW DEVELOPERS.")
args << arg

arg = OpenStudio::Measure::OSArgument::makeIntegerArgument('simulation_control_timestep', false)
arg.setDisplayName('Simulation Control: Timestep')
arg.setUnits('min')
Expand Down Expand Up @@ -91,16 +86,6 @@ def arguments(model) # rubocop:disable Lint/UnusedMethodArgument
arg.setDescription('This numeric field should contain the calendar year that determines the start day of week. If you are running simulations using AMY weather files, the value entered for calendar year will not be used; it will be overridden by the actual year found in the AMY weather file.')
args << arg

arg = OpenStudio::Measure::OSArgument.makeBoolArgument('debug', false)
arg.setDisplayName('Debug Mode?')
arg.setDescription('If true: 1) Writes in.osm file, 2) Generates additional log output, and 3) Creates all EnergyPlus output files.')
args << arg

arg = OpenStudio::Measure::OSArgument.makeBoolArgument('add_component_loads', false)
arg.setDisplayName('Annual Component Loads?')
arg.setDescription('If true, output the annual component loads.')
args << arg

arg = OpenStudio::Ruleset::OSArgument.makeStringArgument('os_hescore_directory', false)
arg.setDisplayName('HEScore Workflow: OpenStudio-HEScore directory path')
arg.setDescription('Path to the OpenStudio-HEScore directory. If specified, the HEScore workflow will run.')
Expand Down Expand Up @@ -252,7 +237,6 @@ def run(model, runner, user_arguments)

if args['os_hescore_directory'].is_initialized
os_hescore_directory = args['os_hescore_directory'].get
hes_hpxml_measures_dir = File.join(os_hescore_directory, 'hpxml-measures')
hes_ruleset_measures_dir = File.join(os_hescore_directory, 'rulesets')
run_hescore_workflow = true
end
Expand Down Expand Up @@ -333,24 +317,6 @@ def run(model, runner, user_arguments)
end
end

# Remove any measures_to_ignore from the list of measures to run
if args['measures_to_ignore'].is_initialized
measures_to_ignore = args['measures_to_ignore'].get
# core ResStock measures are those specified below
# those should not be ignored ...
core_measures = ['ResStockArguments', 'BuildResidentialHPXML', 'BuildResidentialScheduleFile', 'HPXMLtoOpenStudio']
measures_to_ignore.split('|').each do |measure_dir|
if core_measures.include? measure_dir
# fail if core ResStock measure is ignored
msg = "Core ResStock measure #{measure_dir} cannot be ignored"
runner.registerError(msg)
fail msg
end
runner.registerInfo("Ignoring/not running measure #{measure_dir}")
measures.delete(measure_dir)
end
end

# Get the absolute paths relative to this meta measure in the run directory
new_runner = OpenStudio::Measure::OSRunner.new(OpenStudio::WorkflowJSON.new) # we want only ResStockArguments registered argument values
if not apply_measures(measures_dir, { 'ResStockArguments' => measures['ResStockArguments'] }, new_runner, model, true, 'OpenStudio::Measure::ModelMeasure', nil)
Expand All @@ -362,7 +328,6 @@ def run(model, runner, user_arguments)
hpxml_path = File.expand_path('../existing.xml')
measures['BuildResidentialHPXML'] = [{ 'hpxml_path' => hpxml_path }]
measures['BuildResidentialScheduleFile'] = [{ 'hpxml_path' => hpxml_path, 'hpxml_output_path' => hpxml_path }]
measures['HPXMLtoOpenStudio'] = [{ 'hpxml_path' => hpxml_path }]

new_runner.result.stepValues.each do |step_value|
value = get_value_from_workflow_step_value(step_value)
Expand Down Expand Up @@ -572,31 +537,29 @@ def run(model, runner, user_arguments)
measures['BuildResidentialScheduleFile'][0]['schedules_random_seed'] = args['building_id']
measures['BuildResidentialScheduleFile'][0]['output_csv_path'] = File.expand_path('../schedules.csv')

# Get registered values and pass them to HPXMLtoOpenStudio
measures['HPXMLtoOpenStudio'][0]['output_dir'] = File.expand_path('..')
measures['HPXMLtoOpenStudio'][0]['debug'] = args['debug'].get if args['debug'].is_initialized
measures['HPXMLtoOpenStudio'][0]['add_component_loads'] = args['add_component_loads'].get if args['add_component_loads'].is_initialized

# Specify measures to run
measures['BuildResidentialHPXML'][0]['apply_defaults'] = true # for apply_hvac_sizing
if run_hescore_workflow
measures['BuildResidentialHPXML'][0]['apply_defaults'] = true
measures_hash = { 'BuildResidentialHPXML' => measures['BuildResidentialHPXML'] }
else
measures_hash = { 'BuildResidentialHPXML' => measures['BuildResidentialHPXML'], 'BuildResidentialScheduleFile' => measures['BuildResidentialScheduleFile'], 'HPXMLtoOpenStudio' => measures['HPXMLtoOpenStudio'] }
measures_hash = { 'BuildResidentialHPXML' => measures['BuildResidentialHPXML'], 'BuildResidentialScheduleFile' => measures['BuildResidentialScheduleFile'] }
end

if not apply_measures(hpxml_measures_dir, measures_hash, new_runner, model, true, 'OpenStudio::Measure::ModelMeasure', 'existing.osw')
register_logs(runner, new_runner)
return false
end

# Copy existing.xml to home.xml for downstream HPXMLtoOpenStudio
# We need existing.xml (and not just home.xml) for UpgradeCosts
in_path = File.expand_path('../home.xml')
FileUtils.cp(hpxml_path, in_path)

# Run HEScore Measures
if run_hescore_workflow
hes_json_path = File.expand_path('../hes.json')
hes_hpxml_path = File.expand_path('../hes.xml')
measures['HPXMLtoHEScore'] = [{ 'hpxml_path' => hpxml_path, 'output_path' => hes_json_path }]
measures['HEScoreRuleset'] = [{ 'json_path' => hes_json_path, 'hpxml_output_path' => hes_hpxml_path }]
measures['HPXMLtoOpenStudio'][0]['hpxml_path'] = hes_hpxml_path
measures['HPXMLtoHEScore'] = [{ 'hpxml_path' => in_path, 'output_path' => hes_json_path }]
measures['HEScoreRuleset'] = [{ 'json_path' => hes_json_path, 'hpxml_output_path' => in_path }]

# HPXMLtoHEScore and HEScoreRuleset
measures_hash = { 'HPXMLtoHEScore' => measures['HPXMLtoHEScore'], 'HEScoreRuleset' => measures['HEScoreRuleset'] }
Expand All @@ -605,13 +568,6 @@ def run(model, runner, user_arguments)
register_logs(runner, new_runner)
return false
end

# HPXMLtoOpenStudio
measures_hash = { 'HPXMLtoOpenStudio' => measures['HPXMLtoOpenStudio'] }
if not apply_measures(hes_hpxml_measures_dir, measures_hash, new_runner, model, true, 'OpenStudio::Measure::ModelMeasure')
register_logs(runner, new_runner)
return false
end
end

# Report some additional location and model characteristics
Expand Down
50 changes: 3 additions & 47 deletions measures/BuildExistingModel/measure.xml
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@
<schema_version>3.0</schema_version>
<name>build_existing_model</name>
<uid>dedf59bb-3b88-4f16-8755-2c1ff5519cbf</uid>
<version_id>e32720a9-1323-402a-9112-cec7a055cb1d</version_id>
<version_modified>20220907T192923Z</version_modified>
<version_id>0d1f6325-f179-4ec8-9ada-26499f6c4c53</version_id>
<version_modified>20220912T204948Z</version_modified>
<xml_checksum>2C38F48B</xml_checksum>
<class_name>BuildExistingModel</class_name>
<display_name>Build Existing Model</display_name>
Expand Down Expand Up @@ -43,14 +43,6 @@
<required>false</required>
<model_dependent>false</model_dependent>
</argument>
<argument>
<name>measures_to_ignore</name>
<display_name>Measures to Ignore</display_name>
<description>Measures to exclude from the OpenStudio Workflow specified by listing one or more measure directories separated by '|'. Core ResStock measures cannot be ignored (this measure will fail). INTENDED FOR ADVANCED USERS/WORKFLOW DEVELOPERS.</description>
<type>String</type>
<required>false</required>
<model_dependent>false</model_dependent>
</argument>
<argument>
<name>simulation_control_timestep</name>
<display_name>Simulation Control: Timestep</display_name>
Expand Down Expand Up @@ -105,42 +97,6 @@
<required>false</required>
<model_dependent>false</model_dependent>
</argument>
<argument>
<name>debug</name>
<display_name>Debug Mode?</display_name>
<description>If true: 1) Writes in.osm file, 2) Generates additional log output, and 3) Creates all EnergyPlus output files.</description>
<type>Boolean</type>
<required>false</required>
<model_dependent>false</model_dependent>
<choices>
<choice>
<value>true</value>
<display_name>true</display_name>
</choice>
<choice>
<value>false</value>
<display_name>false</display_name>
</choice>
</choices>
</argument>
<argument>
<name>add_component_loads</name>
<display_name>Annual Component Loads?</display_name>
<description>If true, output the annual component loads.</description>
<type>Boolean</type>
<required>false</required>
<model_dependent>false</model_dependent>
<choices>
<choice>
<value>true</value>
<display_name>true</display_name>
</choice>
<choice>
<value>false</value>
<display_name>false</display_name>
</choice>
</choices>
</argument>
<argument>
<name>os_hescore_directory</name>
<display_name>HEScore Workflow: OpenStudio-HEScore directory path</display_name>
Expand Down Expand Up @@ -364,7 +320,7 @@
<filename>measure.rb</filename>
<filetype>rb</filetype>
<usage_type>script</usage_type>
<checksum>DABDA659</checksum>
<checksum>BB3171DA</checksum>
</file>
</files>
</measure>
9 changes: 4 additions & 5 deletions measures/ServerDirectoryCleanup/measure.rb
Original file line number Diff line number Diff line change
Expand Up @@ -108,6 +108,7 @@ def arguments(model) # rubocop:disable Lint/UnusedMethodArgument
arg = OpenStudio::Measure::OSArgument.makeBoolArgument('debug', false)
arg.setDisplayName('Debug Mode?')
arg.setDescription('If true, retain all files.')
arg.setDefaultValue(false)
args << arg

return args
Expand Down Expand Up @@ -147,12 +148,10 @@ def run(runner, user_arguments)
stdout_energyplus = runner.getBoolArgumentValue('retain_stdout_energyplus', user_arguments)
stdout_expandobject = runner.getBoolArgumentValue('retain_stdout_expandobject', user_arguments)
schedules_csv = runner.getBoolArgumentValue('retain_schedules_csv', user_arguments)
debug = runner.getOptionalBoolArgumentValue('debug', user_arguments)
debug = runner.getBoolArgumentValue('debug', user_arguments)

if debug.is_initialized
if debug.get
in_osm = in_idf = pre_process_idf = eplusout_audit = eplusout_bnd = eplusout_eio = eplusout_end = eplusout_err = eplusout_eso = eplusout_mdd = eplusout_mtd = eplusout_rdd = eplusout_shd = eplusout_msgpack = stdout_energyplus = stdout_expandobject = schedules_csv = true
end
if debug
in_osm = in_idf = pre_process_idf = eplusout_audit = eplusout_bnd = eplusout_eio = eplusout_end = eplusout_err = eplusout_eso = eplusout_mdd = eplusout_mtd = eplusout_rdd = eplusout_shd = eplusout_msgpack = stdout_energyplus = stdout_expandobject = schedules_csv = true
end

Dir.glob('./../in.osm').each do |f|
Expand Down
7 changes: 4 additions & 3 deletions measures/ServerDirectoryCleanup/measure.xml
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@
<schema_version>3.0</schema_version>
<name>server_directory_cleanup</name>
<uid>ec7d04ad-0b7b-495b-825a-e1b6d28d1d3f</uid>
<version_id>310687e6-484f-4215-81c1-61e7768ed1c9</version_id>
<version_modified>20220610T181705Z</version_modified>
<version_id>25943705-c32d-4496-b94d-6aa84d0a95f9</version_id>
<version_modified>20220725T214601Z</version_modified>
<xml_checksum>5F1EDF75</xml_checksum>
<class_name>ServerDirectoryCleanup</class_name>
<display_name>Server Directory Cleanup</display_name>
Expand Down Expand Up @@ -342,6 +342,7 @@
<type>Boolean</type>
<required>false</required>
<model_dependent>false</model_dependent>
<default_value>false</default_value>
<choices>
<choice>
<value>true</value>
Expand Down Expand Up @@ -381,7 +382,7 @@
<filename>measure.rb</filename>
<filetype>rb</filetype>
<usage_type>script</usage_type>
<checksum>B6140923</checksum>
<checksum>98A888E1</checksum>
</file>
</files>
</measure>

0 comments on commit 6820973

Please sign in to comment.