Skip to content

Specify upgrade_names for run_analysis.rb #1275

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

Merged
merged 9 commits into from
Jul 20, 2024
3 changes: 2 additions & 1 deletion docs/read_the_docs/source/basic_tutorial/run_project.rst
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,8 @@ 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
-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
-u, --upgrade_name NAME Only run this upgrade; can be called multiple times
-k, --keep_run_folders Preserve run folder for all datapoints; also populates run folder in cli_output.log and results-xxx.csv files
-s, --samplingonly Run the sampling only
-d, --debug Preserve lib folder and xml/osw files for existing building
Expand Down
14 changes: 14 additions & 0 deletions test/test_run_analysis.rb
Original file line number Diff line number Diff line change
Expand Up @@ -170,6 +170,20 @@ def test_building_id
assert(!File.exist?(File.join(@testing_baseline, 'run2')))
end

def test_upgrade_name
yml = ' -y test/tests_yml_files/yml_valid/testing_upgrades.yml'
@command += yml
@command += ' -u "Foundation Type" -u Walls'

system(@command)

_test_measure_order(File.join(@testing_upgrades, 'testing_upgrades-FoundationType.osw'))
assert(File.exist?(File.join(@testing_upgrades, 'results-FoundationType.csv')))
_test_measure_order(File.join(@testing_upgrades, 'testing_upgrades-Walls.osw'))
assert(File.exist?(File.join(@testing_upgrades, 'results-Walls.csv')))
assert(!File.exist?(File.join(@testing_upgrades, 'results-Baseline.csv')))
end

def test_threads_and_keep_run_folders
yml = ' -y test/tests_yml_files/yml_valid/testing_baseline.yml'
@command += yml
Expand Down
9 changes: 0 additions & 9 deletions test/tests_yml_files/yml_bad_value/testing_baseline.yml
Original file line number Diff line number Diff line change
Expand Up @@ -37,12 +37,3 @@ workflow_generator:
baseline:
n_buildings_represented: 110000000

eagle:
n_jobs: 2
minutes_per_sim: 1
account: <account you are authorized to use>
sampling:
time: 10
postprocessing:
time: 10
n_workers: 1
9 changes: 0 additions & 9 deletions test/tests_yml_files/yml_downsampler/testing_baseline.yml
Original file line number Diff line number Diff line change
Expand Up @@ -38,12 +38,3 @@ workflow_generator:
baseline:
n_buildings_represented: 110000000

eagle:
n_jobs: 2
minutes_per_sim: 1
account: <account you are authorized to use>
sampling:
time: 10
postprocessing:
time: 10
n_workers: 1
9 changes: 0 additions & 9 deletions test/tests_yml_files/yml_missing_key/testing_baseline.yml
Original file line number Diff line number Diff line change
Expand Up @@ -30,12 +30,3 @@ workflow_generator:
baseline:
n_buildings_represented: 110000000

eagle:
n_jobs: 2
minutes_per_sim: 1
account: <account you are authorized to use>
sampling:
time: 10
postprocessing:
time: 10
n_workers: 1
9 changes: 0 additions & 9 deletions test/tests_yml_files/yml_precomputed/testing_baseline.yml
Original file line number Diff line number Diff line change
Expand Up @@ -37,12 +37,3 @@ workflow_generator:
baseline:
n_buildings_represented: 110000000

eagle:
n_jobs: 2
minutes_per_sim: 1
account: <account you are authorized to use>
sampling:
time: 10
postprocessing:
time: 10
n_workers: 1
Original file line number Diff line number Diff line change
Expand Up @@ -36,13 +36,3 @@ workflow_generator:

baseline:
n_buildings_represented: 110000000

eagle:
n_jobs: 2
minutes_per_sim: 1
account: <account you are authorized to use>
sampling:
time: 10
postprocessing:
time: 10
n_workers: 1
Original file line number Diff line number Diff line change
Expand Up @@ -36,13 +36,3 @@ workflow_generator:

baseline:
n_buildings_represented: 110000000

eagle:
n_jobs: 2
minutes_per_sim: 1
account: <account you are authorized to use>
sampling:
time: 10
postprocessing:
time: 10
n_workers: 1
10 changes: 0 additions & 10 deletions test/tests_yml_files/yml_precomputed_weight/testing_baseline.yml
Original file line number Diff line number Diff line change
Expand Up @@ -36,13 +36,3 @@ workflow_generator:

baseline:
n_buildings_represented: 110000000

eagle:
n_jobs: 2
minutes_per_sim: 1
account: <account you are authorized to use>
sampling:
time: 10
postprocessing:
time: 10
n_workers: 1
Original file line number Diff line number Diff line change
Expand Up @@ -36,13 +36,3 @@ workflow_generator:

baseline:
n_buildings_represented: 110000000

eagle:
n_jobs: 2
minutes_per_sim: 1
account: <account you are authorized to use>
sampling:
time: 10
postprocessing:
time: 10
n_workers: 1
10 changes: 0 additions & 10 deletions test/tests_yml_files/yml_resample/testing_baseline.yml
Original file line number Diff line number Diff line change
Expand Up @@ -37,13 +37,3 @@ workflow_generator:

baseline:
n_buildings_represented: 110000000

eagle:
n_jobs: 2
minutes_per_sim: 1
account: <account you are authorized to use>
sampling:
time: 10
postprocessing:
time: 10
n_workers: 1
10 changes: 0 additions & 10 deletions test/tests_yml_files/yml_valid/testing_baseline.yml
Original file line number Diff line number Diff line change
Expand Up @@ -36,13 +36,3 @@ workflow_generator:

baseline:
n_buildings_represented: 110000000

eagle:
n_jobs: 2
minutes_per_sim: 1
account: <account you are authorized to use>
sampling:
time: 10
postprocessing:
time: 10
n_workers: 1
87 changes: 87 additions & 0 deletions test/tests_yml_files/yml_valid/testing_upgrades.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,87 @@
schema_version: '0.3'
buildstock_directory: ../../../ # Relative to this file or absolute
project_directory: project_testing # Relative to buildstock_directory
output_directory: testing_upgrades
weather_files_url: https://data.nrel.gov/system/files/156/Buildstock_TMY3_FIPS-1678817889.zip
# weather_files_path: c:/OpenStudio/BuildStock_TMY3_FIPS.zip

sampler:
type: residential_quota
args:
n_datapoints: 2

workflow_generator:
type: residential_hpxml
args:
build_existing_model:
simulation_control_timestep: 60
simulation_control_run_period_begin_month: 1
simulation_control_run_period_begin_day_of_month: 1
simulation_control_run_period_end_month: 12
simulation_control_run_period_end_day_of_month: 31
simulation_control_run_period_calendar_year: 2007

simulation_output_report:
timeseries_frequency: hourly
include_timeseries_fuel_consumptions: true
include_timeseries_end_use_consumptions: true
include_timeseries_emissions: true
include_timeseries_total_loads: true

reporting_measures:
- measure_dir_name: QOIReport

server_directory_cleanup:
debug: true

baseline:
n_buildings_represented: 110000000

upgrades:
- upgrade_name: Windows
options:
- &windows_triple_low_e_non_metal_l_gain
option: Windows|Triple, Low-E, Non-metal, Air, L-Gain
costs:
- value: 45.77
multiplier: Window Area (ft^2)
lifetime: 30

- upgrade_name: Walls
options:
- &insulation_wall_wood_stud_r_13
option: Insulation Wall|Wood Stud, R-13
costs:
- value: 2.21
multiplier: Wall Area, Above-Grade, Conditioned (ft^2)
lifetime: 999

- upgrade_name: Sheathing
options:
- &insulation_sheathing_r_5
option: Insulation Sheathing|R-5
costs:
- value: 2.01
multiplier: Wall Area, Above-Grade, Conditioned (ft^2)
lifetime: 999

- upgrade_name: Foundation Type
package_apply_logic:
and:
- Geometry Foundation Type|Vented Crawlspace
- or: # Ensure that the dwelling unit being modeled is either (1) not in a multifamily building, or (2) on the bottom floor of a multifamily building and therefore above the crawlspace.
- Geometry Building Level MF|None
- Geometry Building Level MF|Bottom
options:
- &geometry_foundation_type_unvented_crawlspace
option: Geometry Foundation Type|Unvented Crawlspace
costs:
- value: 0.84
multiplier: Floor Area, Foundation (ft^2)
lifetime: 999
- &insulation_foundation_wall_wall_r_10_exterior
option: Insulation Foundation Wall|Wall R-10, Exterior
costs:
- value: 1.05
multiplier: Wall Area, Below-Grade (ft^2)
lifetime: 999
10 changes: 0 additions & 10 deletions test/tests_yml_files/yml_weather_files/testing_baseline.yml
Original file line number Diff line number Diff line change
Expand Up @@ -36,13 +36,3 @@ workflow_generator:

baseline:
n_buildings_represented: 110000000

eagle:
n_jobs: 2
minutes_per_sim: 1
account: <account you are authorized to use>
sampling:
time: 10
postprocessing:
time: 10
n_workers: 1
32 changes: 21 additions & 11 deletions workflow/run_analysis.rb
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@

$start_time = Time.now

def run_workflow(yml, in_threads, measures_only, debug_arg, overwrite, building_ids, keep_run_folders, samplingonly)
def run_workflow(yml, in_threads, measures_only, debug_arg, overwrite, building_ids, upgrade_names, keep_run_folders, samplingonly)
if !File.exist?(yml)
puts "Error: YML file does not exist at '#{yml}'."
return false
Expand Down Expand Up @@ -100,10 +100,17 @@ def run_workflow(yml, in_threads, measures_only, debug_arg, overwrite, building_
xml_dir = File.join(results_dir, 'xml')
Dir.mkdir(xml_dir)

upgrade_names = ['Baseline']
upgrades = []
upgrades += ['Baseline'] if upgrade_names.empty? || upgrade_names.include?('Baseline')
if cfg.keys.include?('upgrades')
cfg['upgrades'].each do |upgrade|
upgrade_names << upgrade['upgrade_name'].gsub(/[^0-9A-Za-z]/, '')
upgrade_name = upgrade['upgrade_name']

if !upgrade_names.empty?
next if !upgrade_names.include?(upgrade_name)
end

upgrades << upgrade_name.gsub(/[^0-9A-Za-z]/, '')
end
end

Expand Down Expand Up @@ -223,7 +230,7 @@ def run_workflow(yml, in_threads, measures_only, debug_arg, overwrite, building_
end

osw_paths = {}
upgrade_names.each_with_index do |upgrade_name, upgrade_idx|
upgrades.each do |upgrade_name|
scenario_osw_dir = File.join(results_dir, 'osw', upgrade_name)
Dir.mkdir(scenario_osw_dir)

Expand Down Expand Up @@ -315,13 +322,11 @@ def run_workflow(yml, in_threads, measures_only, debug_arg, overwrite, building_
}
]

if upgrade_idx > 0
measure_d = cfg['upgrades'][upgrade_idx - 1]
if upgrade_name != 'Baseline'
apply_upgrade_measure = { 'measure_dir_name' => 'ApplyUpgrade',
'arguments' => { 'run_measure' => 1 } }
if measure_d.include?('upgrade_name')
apply_upgrade_measure['arguments']['upgrade_name'] = measure_d['upgrade_name']
end
measure_d = cfg['upgrades'].find { |u| u['upgrade_name'].gsub(/[^0-9A-Za-z]/, '') == upgrade_name }
apply_upgrade_measure['arguments']['upgrade_name'] = measure_d['upgrade_name']
measure_d['options'].each_with_index do |option, opt_num|
opt_num += 1
apply_upgrade_measure['arguments']["option_#{opt_num}"] = option['option']
Expand Down Expand Up @@ -366,7 +371,7 @@ def run_workflow(yml, in_threads, measures_only, debug_arg, overwrite, building_
File.open(osw_paths[upgrade_name], 'w') do |f|
f.write(JSON.pretty_generate(osw))
end
end # end upgrade_names.each_with_index do |upgrade_name, upgrade_idx|
end # end upgrades.each do |upgrade_name|

measures = []
cfg['workflow_generator']['args'].keys.each do |wfg_arg|
Expand Down Expand Up @@ -679,6 +684,11 @@ def make_apply_logic_arg(logic)
options[:building_ids] << t
end

options[:upgrade_names] = []
opts.on('-u', '--upgrade_name NAME', 'Only run this upgrade; can be called multiple times') do |t|
options[:upgrade_names] << t
end

options[:keep_run_folders] = false
opts.on('-k', '--keep_run_folders', 'Preserve run folder for all datapoints; also populates run folder in cli_output.log and results-xxx.csv files') do |_t|
options[:keep_run_folders] = true
Expand Down Expand Up @@ -724,7 +734,7 @@ def make_apply_logic_arg(logic)
# Run analysis
puts "YML: #{options[:yml]}"
success = run_workflow(options[:yml], options[:threads], options[:measures_only], options[:debug], options[:overwrite],
options[:building_ids], options[:keep_run_folders], options[:samplingonly])
options[:building_ids], options[:upgrade_names], options[:keep_run_folders], options[:samplingonly])

puts "\nCompleted in #{get_elapsed_time(Time.now, $start_time)}." if success
end