Skip to content

Commit

Permalink
Merge pull request #134 from NREL/develop
Browse files Browse the repository at this point in the history
Prepare Release 2.2.1
  • Loading branch information
nllong authored Jun 2, 2021
2 parents d0b0f47 + e569f91 commit 6f8ca20
Show file tree
Hide file tree
Showing 39 changed files with 15,868 additions and 93 deletions.
5 changes: 2 additions & 3 deletions .rubocop.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ AllCops:
- 'spec/files/pat_project/data_point_*/**/*'
- 'spec/files/pat_project/run/**/*'
- 'spec/files/mongo_pat1/run/**/*'

require: rubocop-performance
inherit_from:
- http://s3.amazonaws.com/openstudio-resources/styles/rubocop_v3.yml

- http://s3.amazonaws.com/openstudio-resources/styles/rubocop_v4.yml
7 changes: 7 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,13 @@
OpenStudio::Workflow Change Log
==================================

Version 2.2.1
-------------
* Fixes [#4150](https://github.com/NREL/OpenStudio/issues/4150) LoadError changes current working directory in CLI
* Add skip option to not zip up datapoint results
* Update measure tester gem which upgrades Rubocop to 1.15
* Update styles to v4 based on new version of Rubocop

Version 2.2.0
-------------
* Minimum Ruby version upgraded to 2.7.0
Expand Down
2 changes: 1 addition & 1 deletion Jenkinsfile
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
//Jenkins pipelines are stored in shared libaries. Please see: https://github.com/NREL/cbci_jenkins_libs

@Library('cbci_shared_libs@ruby_270') _
@Library('cbci_shared_libs') _

// Build for PR to develop branch only.
if ((env.CHANGE_ID) && (env.CHANGE_TARGET) ) { // check if set
Expand Down
18 changes: 18 additions & 0 deletions lib/openstudio/workflow/adapters/input/local.rb
Original file line number Diff line number Diff line change
Expand Up @@ -192,6 +192,24 @@ def fast(user_options, default)
return default
end

def skip_zip_results(user_options, default)
# user option trumps all others
return user_options[:skip_zip_results] if user_options[:skip_zip_results]

# try to read from OSW
if @run_options && !@run_options.empty?
if @run_options.get.respond_to?(:skipZipResults)
return @run_options.get.skipZipResults
else
if @workflow[:run_options]
return @workflow[:run_options][:skip_zip_results]
end
end
end

return default
end

def preserve_run_dir(user_options, default)
# user option trumps all others
return user_options[:preserve_run_dir] if user_options[:preserve_run_dir]
Expand Down
6 changes: 4 additions & 2 deletions lib/openstudio/workflow/adapters/output/local.rb
Original file line number Diff line number Diff line change
Expand Up @@ -136,8 +136,10 @@ def communicate_objective_function(objectives, _ = nil)

# Write the results of the workflow to the filesystem
#
def communicate_results(directory, results)
zip_results(directory)
def communicate_results(directory, results, skip_zip_results)
if !skip_zip_results
zip_results(directory)
end

if results.is_a? Hash
# DLM: don't we want this in the results zip?
Expand Down
6 changes: 1 addition & 5 deletions lib/openstudio/workflow/adapters/output/socket.rb
Original file line number Diff line number Diff line change
Expand Up @@ -55,10 +55,6 @@ def communicate_started
@socket.write("Started\n")
end

def communicate_results(directory, results)
super
end

def communicate_complete
super
@socket.write("Complete\n")
Expand All @@ -75,7 +71,7 @@ def communicate_objective_function(objectives, options = {})

def communicate_transition(message, type, options = {})
super
@socket.write(message + "\n")
@socket.write("#{message}\n")
end

def communicate_energyplus_stdout(line, options = {})
Expand Down
16 changes: 0 additions & 16 deletions lib/openstudio/workflow/adapters/output/web.rb
Original file line number Diff line number Diff line change
Expand Up @@ -47,22 +47,6 @@ def initialize(options = {})
raise 'The required :url option was not passed to the web output adapter' unless options[:url]
end

def communicate_started
super
end

def communicate_results(directory, results)
super
end

def communicate_complete
super
end

def communicate_failure
super
end

def communicate_objective_function(objectives, options = {})
super
end
Expand Down
11 changes: 5 additions & 6 deletions lib/openstudio/workflow/adapters/output_adapter.rb
Original file line number Diff line number Diff line change
Expand Up @@ -113,19 +113,18 @@ def add_directory_to_zip(zip_file, local_directory, root_directory)
end

# skip x-large directory
if File.size?(file)
next if File.size?(file) >= 15000000
if File.size?(file) && (File.size?(file) >= 15000000)
next
end

add_directory_to_zip(zf, file, directory)
else
next if File.extname(file) =~ /\.rb.*/
next if File.extname(file) =~ /\.zip.*/

# skip large non-osm/idf files
if File.size(file)
if File.size(file) >= 100000000
next unless File.extname(file) == '.osm' || File.extname(file) == '.idf'
end
if File.size(file) && (File.size(file) >= 100000000) && !(File.extname(file) == '.osm' || File.extname(file) == '.idf')
next
end

zip_file_to_add = file.gsub("#{directory}/", '')
Expand Down
2 changes: 1 addition & 1 deletion lib/openstudio/workflow/jobs/run_initialization.rb
Original file line number Diff line number Diff line change
Expand Up @@ -181,7 +181,7 @@ def perform

unless weather_path.empty?
weather_path = weather_path.get
@logger.debug 'Searching for weather file #{weather_path}'
@logger.debug "Searching for weather file #{weather_path}"

weather_full_path = workflow_json.findFile(weather_path)
if weather_full_path.empty?
Expand Down
6 changes: 2 additions & 4 deletions lib/openstudio/workflow/jobs/run_reporting_measures.rb
Original file line number Diff line number Diff line change
Expand Up @@ -69,10 +69,8 @@ def perform
workflow = nil
if File.exist? @registry[:osw_path]
workflow = ::JSON.parse(File.read(@registry[:osw_path]), symbolize_names: true)
if !workflow.nil?
if !workflow[:urbanopt].nil?
@registry.register(:urbanopt) { workflow[:urbanopt] }
end
if !workflow.nil? && !workflow[:urbanopt].nil?
@registry.register(:urbanopt) { workflow[:urbanopt] }
end
end
end
Expand Down
29 changes: 12 additions & 17 deletions lib/openstudio/workflow/run.rb
Original file line number Diff line number Diff line change
Expand Up @@ -48,12 +48,7 @@ module Workflow
class Run
attr_accessor :registry

attr_reader :options
attr_reader :input_adapter
attr_reader :output_adapter
attr_reader :final_message
attr_reader :job_results
attr_reader :current_state
attr_reader :options, :input_adapter, :output_adapter, :final_message, :job_results, :current_state

# Define the default set of jobs. Note that the states of :queued of :finished need to exist for all job arrays.
#
Expand Down Expand Up @@ -90,6 +85,7 @@ def self.default_jobs
# @option user_options [Hash] :debug Print debugging messages, overrides OSW option if set, defaults to false
# @option user_options [Hash] :energyplus_path Specifies path to energyplus executable, defaults to empty
# @option user_options [Hash] :fast Speeds up workflow by skipping steps not needed for running simulations, defaults to false
# @option user_options [Hash] :skip_zip_results Skips creating the data_point.zip file. Setting to `true` can cause issues with workflows expecting .zip files to signal completion (e.g., OpenStudio Analysis Framework), defaults to false
# @option user_options [Hash] :jobs Simulation workflow, overrides jobs in OSW if set, defaults to default_jobs
# @option user_options [Hash] :output_adapter Output adapter to use, overrides output adapter in OSW if set, defaults to local adapter
# @option user_options [Hash] :preserve_run_dir Prevents run directory from being cleaned prior to run, overrides OSW option if set, defaults to false - DLM, Deprecate
Expand Down Expand Up @@ -158,15 +154,13 @@ def initialize(osw_path, user_options = {})
end

# By default blow away the entire run directory every time and recreate it
unless @options[:preserve_run_dir]
if File.exist?(@registry[:run_dir])
# logger is not initialized yet (it needs run dir to exist for log)
puts "Removing existing run directory #{@registry[:run_dir]}" if @options[:debug]

# DLM: this is dangerous, we are calling rm_rf on a user entered directory, need to check this first
# TODO: Echoing Dan's comment
FileUtils.rm_rf(@registry[:run_dir])
end
if !@options[:preserve_run_dir] && File.exist?(@registry[:run_dir])
# logger is not initialized yet (it needs run dir to exist for log)
puts "Removing existing run directory #{@registry[:run_dir]}" if @options[:debug]

# DLM: this is dangerous, we are calling rm_rf on a user entered directory, need to check this first
# TODO: Echoing Dan's comment
FileUtils.rm_rf(@registry[:run_dir])
end
FileUtils.mkdir_p(@registry[:run_dir])

Expand All @@ -176,7 +170,7 @@ def initialize(osw_path, user_options = {})
else
# don't create these files unless we want to use them
# DLM: TODO, make sure that run.log will be closed later
@options[:targets] = [STDOUT, File.open(File.join(@registry[:run_dir], 'run.log'), 'a')]
@options[:targets] = [$stdout, File.open(File.join(@registry[:run_dir], 'run.log'), 'a')]
end

@registry.register(:log_targets) { @options[:targets] }
Expand Down Expand Up @@ -204,6 +198,7 @@ def initialize(osw_path, user_options = {})
@options[:verify_osw] = @input_adapter.verify_osw(user_options, true)
@options[:weather_file] = @input_adapter.weather_file(user_options, nil)
@options[:fast] = @input_adapter.fast(user_options, false)
@options[:skip_zip_results] = @input_adapter.skip_zip_results(user_options, false)

openstudio_dir = 'unknown'
begin
Expand Down Expand Up @@ -236,7 +231,7 @@ def run

if !@options[:fast]
@logger.info 'Finished workflow - communicating results and zipping files'
@output_adapter.communicate_results(@registry[:run_dir], @registry[:results])
@output_adapter.communicate_results(@registry[:run_dir], @registry[:results], @options[:skip_zip_results])
end
rescue StandardError => e
@logger.info "Error occurred during running with #{e.message}"
Expand Down
28 changes: 12 additions & 16 deletions lib/openstudio/workflow/util/energyplus.rb
Original file line number Diff line number Diff line change
Expand Up @@ -125,7 +125,7 @@ def prepare_energyplus_dir(run_directory, logger, energyplus_path = nil)
# @return [Void]
#
def call_energyplus(run_directory, energyplus_path = nil, output_adapter = nil, logger = nil, workflow_json = nil)
logger ||= ::Logger.new(STDOUT) unless logger
logger ||= ::Logger.new($stdout) unless logger

current_dir = Dir.pwd
energyplus_path ||= find_energyplus
Expand Down Expand Up @@ -231,7 +231,7 @@ def energyplus_preprocess(idf, logger)
end

# merge in monthly reports
EnergyPlus.monthly_report_idf_text.split(/^[\s]*$/).each do |object|
EnergyPlus.monthly_report_idf_text.split(/^\s*$/).each do |object|
object = object.strip
next if object.empty?

Expand Down Expand Up @@ -278,11 +278,9 @@ def self.add_energyplus_output_request(workspace, idf_object)
allowed_objects << 'Meter:CustomDecrement'
allowed_objects << 'EnergyManagementSystem:OutputVariable'

if allowed_objects.include?(idd_object.name)
unless check_for_object(workspace, idf_object, idd_object.type)
workspace.addObject(idf_object)
num_added += 1
end
if allowed_objects.include?(idd_object.name) && !check_for_object(workspace, idf_object, idd_object.type)
workspace.addObject(idf_object)
num_added += 1
end

allowed_unique_objects = []
Expand All @@ -293,15 +291,13 @@ def self.add_energyplus_output_request(workspace, idf_object)
# OutputControl:ReportingTolerances # not allowed
# Output:SQLite # not allowed

if allowed_unique_objects.include?(idf_object.iddObject.name)
if idf_object.iddObject.name == 'Output:Table:SummaryReports'
summary_reports = workspace.getObjectsByType(idf_object.iddObject.type)
if summary_reports.empty?
workspace.addObject(idf_object)
num_added += 1
else
merge_output_table_summary_reports(summary_reports[0], idf_object)
end
if allowed_unique_objects.include?(idf_object.iddObject.name) && (idf_object.iddObject.name == 'Output:Table:SummaryReports')
summary_reports = workspace.getObjectsByType(idf_object.iddObject.type)
if summary_reports.empty?
workspace.addObject(idf_object)
num_added += 1
else
merge_output_table_summary_reports(summary_reports[0], idf_object)
end
end

Expand Down
2 changes: 2 additions & 0 deletions lib/openstudio/workflow/util/measure.rb
Original file line number Diff line number Diff line change
Expand Up @@ -342,6 +342,8 @@ def apply_measure(registry, step, options = {}, energyplus_output_requests = fal
result = nil
begin
load measure_path.to_s
# load.c in ruby can result in changing dir to root / so preserve cwd here. happens in openstudio cli
Dir.chdir measure_run_dir
measure_object = Object.const_get(class_name).new
rescue => e

Expand Down
2 changes: 1 addition & 1 deletion lib/openstudio/workflow/util/model.rb
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,7 @@ def load_idf(idf_path, logger)
# @todo (rhorsey) rescue errors here
#
def translate_to_energyplus(model, logger = nil)
logger ||= ::Logger.new(STDOUT)
logger ||= ::Logger.new($stdout)
logger.info 'Translate object to EnergyPlus IDF in preparation for EnergyPlus'
a = ::Time.now
# ensure objects exist for reporting purposes
Expand Down
4 changes: 2 additions & 2 deletions lib/openstudio/workflow/util/post_process.rb
Original file line number Diff line number Diff line change
Expand Up @@ -138,10 +138,10 @@ def run_extract_inputs_and_outputs(run_dir, logger)
#
def rename_hash_keys(hash, logger)
# @todo should we log the name changes?
regex = %r{[|!@#\$%^&\*\(\)\{\}\\\[\];:'",<.>/?\+=]+}
regex = %r{[|!@#$%^&*()\{\}\\\[\];:'",<.>/?+=]+}

rename_keys = lambda do |h|
if Hash === h
if h.is_a?(Hash)
h.each_key do |key|
if key.to_s =~ regex
logger.warn "Renaming result key '#{key}' to remove invalid characters"
Expand Down
2 changes: 1 addition & 1 deletion lib/openstudio/workflow/util/weather_file.rb
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ module WeatherFile
#
def get_weather_file(directory, wf, wf_search_array, model, logger = nil)
# TODO: this logic needs some updating, weather file should come from current model, found using search paths
logger ||= ::Logger.new(STDOUT) unless logger
logger ||= ::Logger.new($stdout) unless logger
if wf
weather_file = get_weather_file_from_fs(directory, wf, wf_search_array, logger)
raise 'Could not locate the weather file in the filesystem. Please see the log' if weather_file == false
Expand Down
2 changes: 1 addition & 1 deletion lib/openstudio/workflow/version.rb
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,6 @@

module OpenStudio
module Workflow
VERSION = '2.2.0'.freeze # Suffixes must have periods (not dashes)
VERSION = '2.2.1' # Suffixes must have periods (not dashes)
end
end
6 changes: 2 additions & 4 deletions lib/openstudio/workflow_json.rb
Original file line number Diff line number Diff line change
Expand Up @@ -89,9 +89,7 @@ def initialize(name, value, type)
@type = type
end

attr_reader :name

attr_reader :value
attr_reader :name, :value

def variantType
@type
Expand Down Expand Up @@ -162,7 +160,7 @@ def stepResult

def setStepResult(step_result)
@result[:step_result] = step_result
end
end
end

# WorkflowStep_Shim provides a shim interface to the WorkflowStep class in OpenStudio 2.X when running in OpenStudio 1.X
Expand Down
4 changes: 1 addition & 3 deletions lib/openstudio/workflow_runner.rb
Original file line number Diff line number Diff line change
Expand Up @@ -65,14 +65,12 @@ def timeString
::Time.now.utc.strftime('%Y%m%dT%H%M%SZ')
end

attr_reader :datapoint
attr_reader :datapoint, :analysis

def setDatapoint(datapoint)
@datapoint = datapoint
end

attr_reader :analysis

def setAnalysis(analysis)
@analysis = analysis
end
Expand Down
7 changes: 3 additions & 4 deletions openstudio-workflow.gemspec
Original file line number Diff line number Diff line change
Expand Up @@ -27,12 +27,11 @@ Gem::Specification.new do |s|
s.add_development_dependency 'ci_reporter_rspec', '~> 1.0.0'
s.add_development_dependency 'coveralls', '~> 0.8.21'
s.add_development_dependency 'json-schema', '~> 2.8.0'
s.add_development_dependency 'openstudio-standards', '~> 0.2.12'
s.add_development_dependency 'openstudio_measure_tester', '~> 0.3.1'
s.add_development_dependency 'openstudio-standards', '~> 0.2.14'
s.add_development_dependency 'parallel', '~> 1.19.1'
s.add_development_dependency 'public_suffix', '~> 4.0.3'
s.add_development_dependency 'rainbow', '~> 3.0.0'
s.add_development_dependency 'rake', '~> 12.3'
s.add_development_dependency 'rake', '~> 13.0'
s.add_development_dependency 'rspec', '~> 3.9'
s.add_development_dependency 'rubocop', '~> 0.54.0'
s.add_development_dependency 'rubocop-checkstyle_formatter', '~> 0.4.0'
end
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

module ColorString
class Colorize
REGEX = /\[[a-z0-9_-]+\]/i
REGEX = /\[[a-z0-9_-]+\]/i.freeze
CODES = {
'default' => '39',

Expand Down
Loading

0 comments on commit 6f8ca20

Please sign in to comment.