openstudio-workflow 1.0.0 → 1.1.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/openstudio/workflow/adapters/input/local.rb +156 -13
- data/lib/openstudio/workflow/jobs/run_initialization.rb +12 -3
- data/lib/openstudio/workflow/jobs/run_os_measures.rb +11 -1
- data/lib/openstudio/workflow/jobs/run_preprocess.rb +2 -14
- data/lib/openstudio/workflow/jobs/run_reporting_measures.rb +18 -6
- data/lib/openstudio/workflow/jobs/run_translation.rb +12 -0
- data/lib/openstudio/workflow/run.rb +69 -50
- data/lib/openstudio/workflow/util/measure.rb +35 -13
- data/lib/openstudio/workflow/version.rb +1 -1
- data/lib/openstudio/workflow_json.rb +5 -0
- metadata +3 -5
- data/bin/openstudio_cli +0 -786
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: d9d68b3e07b560c00048d9804bc0b335616b4ff6
|
4
|
+
data.tar.gz: 48da479660bf59a3f06297a4b80917c9ad8fb534
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 4e2fd88631224d04ca0f347863ab5ed19817f08e3edf05c3a1109a3e54be82a71ae3d88040e3a7ff91d2507762a22adc919be436bd9c05744478127434543525
|
7
|
+
data.tar.gz: a9fa849f8c5d4e0534c25a223764486356eafb1d4ef9f10e7e8525c64ad38a5ea01556180e57ad9ab9c9d70ff0e7a28e0534f06b5b1587ae529be9924e7ce22f
|
@@ -27,9 +27,27 @@ module OpenStudio
|
|
27
27
|
def initialize(osw_path = './workflow.osw')
|
28
28
|
@osw_abs_path = File.absolute_path(osw_path, Dir.pwd)
|
29
29
|
|
30
|
-
@workflow =
|
31
|
-
|
32
|
-
|
30
|
+
@workflow = nil
|
31
|
+
if File.exist? @osw_abs_path
|
32
|
+
@workflow = ::JSON.parse(File.read(@osw_abs_path), symbolize_names: true)
|
33
|
+
end
|
34
|
+
|
35
|
+
@workflow_json = nil
|
36
|
+
@run_options = nil
|
37
|
+
if @workflow
|
38
|
+
begin
|
39
|
+
# Create a temporary WorkflowJSON, will not be same one used in registry during simulation
|
40
|
+
@workflow_json = OpenStudio::WorkflowJSON.new(JSON.fast_generate(workflow))
|
41
|
+
@workflow_json.setOswDir(osw_dir)
|
42
|
+
rescue NameError => e
|
43
|
+
@workflow_json = WorkflowJSON_Shim.new(workflow, osw_dir)
|
44
|
+
end
|
45
|
+
|
46
|
+
begin
|
47
|
+
@run_options = @workflow_json.runOptions
|
48
|
+
rescue
|
49
|
+
end
|
50
|
+
end
|
33
51
|
end
|
34
52
|
|
35
53
|
# Get the OSW file from the local filesystem
|
@@ -55,23 +73,147 @@ module OpenStudio
|
|
55
73
|
#
|
56
74
|
def run_dir
|
57
75
|
result = File.join(osw_dir, 'run')
|
58
|
-
if
|
76
|
+
if @workflow_json
|
59
77
|
begin
|
60
|
-
|
61
|
-
begin
|
62
|
-
# Create a temporary WorkflowJSON to compute run directory
|
63
|
-
workflow_json = OpenStudio::WorkflowJSON.new(JSON.fast_generate(workflow))
|
64
|
-
workflow_json.setOswDir(osw_dir)
|
65
|
-
rescue Exception => e
|
66
|
-
workflow_json = WorkflowJSON_Shim.new(workflow, osw_dir)
|
67
|
-
end
|
68
|
-
result = workflow_json.absoluteRunDir.to_s
|
78
|
+
result = @workflow_json.absoluteRunDir.to_s
|
69
79
|
rescue
|
70
80
|
end
|
71
81
|
end
|
72
82
|
result
|
73
83
|
end
|
84
|
+
|
85
|
+
def output_adapter(user_options, default, logger)
|
86
|
+
|
87
|
+
# user option trumps all others
|
88
|
+
return user_options[:output_adapter] if user_options[:output_adapter]
|
89
|
+
|
90
|
+
# try to read from OSW
|
91
|
+
if @run_options && !@run_options.empty?
|
92
|
+
custom_adapter = @run_options.get.customOutputAdapter
|
93
|
+
if !custom_adapter.empty?
|
94
|
+
begin
|
95
|
+
custom_file_name = custom_adapter.get.customFileName
|
96
|
+
class_name = custom_adapter.get.className
|
97
|
+
options = ::JSON.parse(custom_adapter.get.options, :symbolize_names => true)
|
98
|
+
|
99
|
+
# merge with user options, user options will replace options loaded from OSW
|
100
|
+
options.merge!(user_options)
|
101
|
+
|
102
|
+
# stick output_directory in options
|
103
|
+
options[:output_directory] = run_dir
|
104
|
+
|
105
|
+
p = @workflow_json.findFile(custom_file_name)
|
106
|
+
if !p.empty?
|
107
|
+
load(p.get.to_s)
|
108
|
+
output_adapter = eval("#{class_name}.new(options)")
|
109
|
+
return output_adapter
|
110
|
+
else
|
111
|
+
log_message = "Failed to load custom adapter file '#{custom_file_name}'"
|
112
|
+
logger.error log_message
|
113
|
+
raise log_message
|
114
|
+
end
|
115
|
+
rescue
|
116
|
+
log_message = "Failed to load custom adapter '#{class_name}' from file '#{custom_file_name}'"
|
117
|
+
logger.error log_message
|
118
|
+
raise log_message
|
119
|
+
end
|
120
|
+
end
|
121
|
+
end
|
122
|
+
|
123
|
+
return default
|
124
|
+
end
|
125
|
+
|
126
|
+
def jobs(user_options, default, logger)
|
127
|
+
|
128
|
+
# user option trumps all others
|
129
|
+
return user_options[:jobs] if user_options[:jobs]
|
74
130
|
|
131
|
+
# try to read from OSW
|
132
|
+
begin
|
133
|
+
#log_message = "Reading custom job states from OSW is not currently supported'"
|
134
|
+
#logger.info log_message
|
135
|
+
rescue
|
136
|
+
end
|
137
|
+
|
138
|
+
return default
|
139
|
+
end
|
140
|
+
|
141
|
+
def debug(user_options, default)
|
142
|
+
|
143
|
+
# user option trumps all others
|
144
|
+
return user_options[:debug] if user_options[:debug]
|
145
|
+
|
146
|
+
# try to read from OSW
|
147
|
+
if @run_options && !@run_options.empty?
|
148
|
+
return @run_options.get.debug
|
149
|
+
end
|
150
|
+
|
151
|
+
return default
|
152
|
+
end
|
153
|
+
|
154
|
+
def preserve_run_dir(user_options, default)
|
155
|
+
|
156
|
+
# user option trumps all others
|
157
|
+
return user_options[:preserve_run_dir] if user_options[:preserve_run_dir]
|
158
|
+
|
159
|
+
# try to read from OSW
|
160
|
+
if @run_options && !@run_options.empty?
|
161
|
+
return @run_options.get.preserveRunDir
|
162
|
+
end
|
163
|
+
|
164
|
+
return default
|
165
|
+
end
|
166
|
+
|
167
|
+
def cleanup(user_options, default)
|
168
|
+
|
169
|
+
# user option trumps all others
|
170
|
+
return user_options[:cleanup] if user_options[:cleanup]
|
171
|
+
|
172
|
+
# try to read from OSW
|
173
|
+
if @run_options && !@run_options.empty?
|
174
|
+
return @run_options.get.cleanup
|
175
|
+
end
|
176
|
+
|
177
|
+
return default
|
178
|
+
end
|
179
|
+
|
180
|
+
def energyplus_path(user_options, default)
|
181
|
+
|
182
|
+
# user option trumps all others
|
183
|
+
return user_options[:energyplus_path] if user_options[:energyplus_path]
|
184
|
+
|
185
|
+
return default
|
186
|
+
end
|
187
|
+
|
188
|
+
def profile(user_options, default)
|
189
|
+
|
190
|
+
# user option trumps all others
|
191
|
+
return user_options[:profile] if user_options[:profile]
|
192
|
+
|
193
|
+
return default
|
194
|
+
end
|
195
|
+
|
196
|
+
def verify_osw(user_options, default)
|
197
|
+
|
198
|
+
# user option trumps all others
|
199
|
+
return user_options[:verify_osw] if user_options[:verify_osw]
|
200
|
+
|
201
|
+
return default
|
202
|
+
end
|
203
|
+
|
204
|
+
def weather_file(user_options, default)
|
205
|
+
|
206
|
+
# user option trumps all others
|
207
|
+
return user_options[:weather_file] if user_options[:weather_file]
|
208
|
+
|
209
|
+
# try to read from OSW
|
210
|
+
if !@workflow_json.weatherFile.empty?
|
211
|
+
return @workflow_json.weatherFile.get.to_s
|
212
|
+
end
|
213
|
+
|
214
|
+
return default
|
215
|
+
end
|
216
|
+
|
75
217
|
# Get the associated OSD (datapoint) file from the local filesystem
|
76
218
|
#
|
77
219
|
def datapoint
|
@@ -91,6 +233,7 @@ module OpenStudio
|
|
91
233
|
::JSON.parse(File.read(osa_abs_path), symbolize_names: true)
|
92
234
|
end
|
93
235
|
end
|
236
|
+
|
94
237
|
end
|
95
238
|
end
|
96
239
|
end
|
@@ -70,8 +70,6 @@ class RunInitialization < OpenStudio::Workflow::Job
|
|
70
70
|
@registry.register(:runner) { WorkflowRunner.new(@registry[:logger], @registry[:workflow_json], @registry[:openstudio_2]) }
|
71
71
|
@logger.debug 'Initialized runner'
|
72
72
|
|
73
|
-
workflow_json.start
|
74
|
-
|
75
73
|
# Validate the OSW measures if the flag is set to true, (the default state)
|
76
74
|
if @options[:verify_osw]
|
77
75
|
@logger.info 'Attempting to validate the measure workflow'
|
@@ -100,6 +98,14 @@ class RunInitialization < OpenStudio::Workflow::Job
|
|
100
98
|
@registry.register(:model) { OpenStudio::Model::Model.new }
|
101
99
|
end
|
102
100
|
|
101
|
+
if @registry[:openstudio_2]
|
102
|
+
if @registry[:model]
|
103
|
+
@registry[:model].setWorkflowJSON(workflow_json.clone)
|
104
|
+
end
|
105
|
+
end
|
106
|
+
|
107
|
+
# DLM: TODO, load weather_file from options so it can be overriden by user_options
|
108
|
+
|
103
109
|
# Find the weather file, should it exist and be findable
|
104
110
|
@logger.debug 'Getting the initial weather file'
|
105
111
|
weather_path = workflow_json.weatherFile
|
@@ -123,14 +129,17 @@ class RunInitialization < OpenStudio::Workflow::Job
|
|
123
129
|
end
|
124
130
|
|
125
131
|
if weather_full_path.empty?
|
126
|
-
raise "Weather file #{weather_path} specified but cannot be found"
|
132
|
+
raise "Weather file '#{weather_path}' specified but cannot be found"
|
127
133
|
end
|
128
134
|
weather_full_path = weather_full_path.get
|
129
135
|
|
130
136
|
@registry.register(:wf) { weather_full_path.to_s }
|
137
|
+
|
131
138
|
end
|
132
139
|
@logger.warn 'No valid weather file defined in either the osm or osw.' unless @registry[:wf]
|
133
140
|
|
141
|
+
workflow_json.start
|
142
|
+
|
134
143
|
nil
|
135
144
|
end
|
136
145
|
end
|
@@ -30,7 +30,17 @@ class RunOpenStudioMeasures < OpenStudio::Workflow::Job
|
|
30
30
|
|
31
31
|
def perform
|
32
32
|
@logger.debug "Calling #{__method__} in the #{self.class} class"
|
33
|
-
|
33
|
+
|
34
|
+
# set weather file
|
35
|
+
if @registry[:wf] && @registry[:model]
|
36
|
+
epwFile = OpenStudio::EpwFile.load(@registry[:wf])
|
37
|
+
if !epwFile.empty?
|
38
|
+
OpenStudio::Model::WeatherFile.setWeatherFile(@registry[:model], epwFile.get)
|
39
|
+
else
|
40
|
+
@logger.warn "Could not load weather file from '#{weather_full_path.to_s}'"
|
41
|
+
end
|
42
|
+
end
|
43
|
+
|
34
44
|
# Ensure output_attributes is initialized in the registry
|
35
45
|
@registry.register(:output_attributes) { {} } unless @registry[:output_attributes]
|
36
46
|
|
@@ -34,25 +34,13 @@ class RunPreprocess < OpenStudio::Workflow::Job
|
|
34
34
|
# Ensure that the directory is created (but it should already be at this point)
|
35
35
|
FileUtils.mkdir_p(@registry[:run_dir])
|
36
36
|
|
37
|
-
# Copy in the weather file defined in the registry, or alternately in the options
|
38
|
-
if @registry[:wf]
|
39
|
-
@logger.info "Weather file for EnergyPlus simulation is #{@registry[:wf]}"
|
40
|
-
FileUtils.copy(@registry[:wf], "#{@registry[:run_dir]}/in.epw")
|
41
|
-
elsif @options[:simulation_weather_file]
|
42
|
-
@logger.warn "Using weather file defined in options: #{@options[:simulation_weather_file]}"
|
43
|
-
FileUtils.copy(@options[:simulation_weather_file], "#{@registry[:run_dir]}/in.epw")
|
44
|
-
else
|
45
|
-
@logger.warn "EPW file not found or not sent to #{self.class}"
|
46
|
-
end
|
47
|
-
|
48
37
|
# save the pre-preprocess file
|
49
38
|
File.open("#{@registry[:run_dir]}/pre-preprocess.idf", 'w') { |f| f << @registry[:model_idf].to_s }
|
50
39
|
|
51
40
|
# Add any EnergyPlus Output Requests from Reporting Measures
|
52
41
|
@logger.info 'Beginning to collect output requests from Reporting measures.'
|
53
|
-
|
54
|
-
apply_measures('ReportingMeasure'.to_MeasureType, @registry, @options)
|
55
|
-
@options[:energyplus_output_requests] = nil
|
42
|
+
energyplus_output_requests = true
|
43
|
+
apply_measures('ReportingMeasure'.to_MeasureType, @registry, @options, energyplus_output_requests)
|
56
44
|
@logger.info('Finished collect output requests from Reporting measures.')
|
57
45
|
|
58
46
|
# Perform pre-processing on in.idf to capture logic in RunManager
|
@@ -44,25 +44,37 @@ class RunReportingMeasures < OpenStudio::Workflow::Job
|
|
44
44
|
@registry.register(:output_attributes) { {} } unless @registry[:output_attributes]
|
45
45
|
|
46
46
|
# Load simulation files as required
|
47
|
-
if @
|
47
|
+
if @registry[:model].nil?
|
48
48
|
osm_path = File.absolute_path(File.join(@registry[:run_dir], 'in.osm'))
|
49
49
|
@logger.debug "Attempting to load #{osm_path}"
|
50
50
|
@registry.register(:model) { load_osm('.', osm_path) }
|
51
51
|
raise "Unable to load #{osm_path}" unless @registry[:model]
|
52
52
|
@logger.debug "Successfully loaded #{osm_path}"
|
53
53
|
end
|
54
|
-
if @
|
54
|
+
if @registry[:model_idf].nil?
|
55
55
|
idf_path = File.absolute_path(File.join(@registry[:run_dir], 'in.idf'))
|
56
56
|
@logger.debug "Attempting to load #{idf_path}"
|
57
57
|
@registry.register(:model_idf) { load_idf('.', idf_path) }
|
58
58
|
raise "Unable to load #{idf_path}" unless @registry[:model_idf]
|
59
59
|
@logger.debug "Successfully loaded #{idf_path}"
|
60
60
|
end
|
61
|
-
if @
|
62
|
-
|
63
|
-
|
61
|
+
if @registry[:sql].nil?
|
62
|
+
sql_path = File.absolute_path(File.join(@registry[:run_dir], 'eplusout.sql'))
|
63
|
+
if File.exists?(sql_path)
|
64
|
+
@registry.register(:sql) { sql_path }
|
65
|
+
@logger.debug "Registered the sql filepath as #{@registry[:sql]}"
|
66
|
+
end
|
67
|
+
#raise "Unable to load #{sql_path}" unless @registry[:sql]
|
64
68
|
end
|
65
|
-
|
69
|
+
if @registry[:wf].nil?
|
70
|
+
epw_path = File.absolute_path(File.join(@registry[:run_dir], 'in.epw'))
|
71
|
+
if File.exists?(epw_path)
|
72
|
+
@registry.register(:wf) { epw_path }
|
73
|
+
@logger.debug "Registered the wf filepath as #{@registry[:wf]}"
|
74
|
+
end
|
75
|
+
#raise "Unable to load #{epw_path}" unless @registry[:wf]
|
76
|
+
end
|
77
|
+
|
66
78
|
# Apply reporting measures
|
67
79
|
@options[:output_adapter] = @output_adapter
|
68
80
|
@logger.info 'Beginning to execute Reporting measures.'
|
@@ -28,7 +28,19 @@ class RunTranslation < OpenStudio::Workflow::Job
|
|
28
28
|
|
29
29
|
def perform
|
30
30
|
@logger.debug "Calling #{__method__} in the #{self.class} class"
|
31
|
+
|
32
|
+
# Ensure that the run directory is created
|
33
|
+
FileUtils.mkdir_p(@registry[:run_dir])
|
31
34
|
|
35
|
+
# Copy in the weather file defined in the registry, or alternately in the options
|
36
|
+
if @registry[:wf]
|
37
|
+
@logger.info "Weather file for EnergyPlus simulation is #{@registry[:wf]}"
|
38
|
+
FileUtils.copy(@registry[:wf], "#{@registry[:run_dir]}/in.epw")
|
39
|
+
@registry.register(:wf) { "#{@registry[:run_dir]}/in.epw" }
|
40
|
+
else
|
41
|
+
@logger.warn "EPW file not found or not sent to #{self.class}"
|
42
|
+
end
|
43
|
+
|
32
44
|
# Translate the OSM to an IDF
|
33
45
|
@logger.info 'Beginning the translation to IDF'
|
34
46
|
@registry[:time_logger].start('Translating to EnergyPlus') if @registry[:time_logger]
|
@@ -22,6 +22,7 @@ require_relative 'adapters/input/local'
|
|
22
22
|
require_relative 'adapters/output/local'
|
23
23
|
|
24
24
|
require 'logger'
|
25
|
+
require 'pathname'
|
25
26
|
|
26
27
|
# Run Class for OpenStudio workflow. All comments here need some love, as well as the code itself
|
27
28
|
module OpenStudio
|
@@ -66,37 +67,43 @@ module OpenStudio
|
|
66
67
|
#
|
67
68
|
# @param [String] osw_path the path to the OSW file to run. It is highly recommended that this be an absolute
|
68
69
|
# path, however if not it will be made absolute relative to the current working directory
|
69
|
-
# @param [Hash]
|
70
|
-
#
|
71
|
-
# @option
|
72
|
-
# @option
|
73
|
-
# @option
|
74
|
-
# @
|
75
|
-
#
|
76
|
-
|
70
|
+
# @param [Hash] user_options ({}) A set of user-specified options that are used to override default behaviors.
|
71
|
+
# @option user_options [Hash] :cleanup Remove unneccessary files during post processing, overrides OSW option if set, defaults to true
|
72
|
+
# @option user_options [Hash] :debug Print debugging messages, overrides OSW option if set, defaults to false
|
73
|
+
# @option user_options [Hash] :energyplus_path Specifies path to energyplus executable, defaults to empty
|
74
|
+
# @option user_options [Hash] :jobs Simulation workflow, overrides jobs in OSW if set, defaults to default_jobs
|
75
|
+
# @option user_options [Hash] :output_adapter Output adapter to use, overrides output adapter in OSW if set, defaults to local adapter
|
76
|
+
# @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
|
77
|
+
# @option user_options [Hash] :profile Produce additional output for profiling simulations, defaults to false
|
78
|
+
# @option user_options [Hash] :targets Log targets to write to, defaults to standard out and run.log
|
79
|
+
# @option user_options [Hash] :verify_osw Check OSW for correctness, defaults to true
|
80
|
+
# @option user_options [Hash] :weather_file Initial weather file to load, overrides OSW option if set, defaults to empty
|
81
|
+
def initialize(osw_path, user_options = {})
|
77
82
|
# DLM - what is final_message?
|
78
83
|
@final_message = ''
|
79
84
|
@current_state = nil
|
80
|
-
|
81
|
-
|
82
|
-
#
|
83
|
-
# -
|
85
|
+
@options = {}
|
86
|
+
|
87
|
+
# Registry is a large hash of objects that are populated during the run, the number of objects in the registry should be reduced over time, especially if the functionality can be added to the WorkflowJSON class
|
88
|
+
# - analysis - the current OSA parsed as a Ruby Hash
|
89
|
+
# - datapoint - the current OSD parsed as a Ruby Hash
|
84
90
|
# - log_targets - IO devices that are being logged to
|
85
|
-
# -
|
86
|
-
# -
|
87
|
-
# -
|
91
|
+
# - logger - general logger
|
92
|
+
# - model - the current OpenStudio Model object, updated after each step
|
93
|
+
# - model_idf - the current EnergyPlus Workspace object, updated after each step
|
94
|
+
# - openstudio_2 - true if we are running in OpenStudio 2.X environment
|
95
|
+
# - osw_path - the path the OSW was loaded from as a string
|
88
96
|
# - osw_dir - the directory the OSW was loaded from as a string
|
97
|
+
# - output_attributes - added during simulation time
|
98
|
+
# - results - objective function values
|
89
99
|
# - root_dir - the root directory in the OSW as a string
|
90
100
|
# - run_dir - the run directory for the simulation as a string
|
91
|
-
# - datapoint - the current OSD parsed as a Ruby Hash
|
92
|
-
# - analysis - the current OSA parsed as a Ruby Hash
|
93
101
|
# - runner - the current OSRunner object
|
94
|
-
# - results - the output of the run_extract_inputs_and_outputs method
|
95
|
-
# - model - the current OpenStudio Model object, updated after each step
|
96
|
-
# - model_idf - the current EnergyPlus Workspace object, updated after each step
|
97
|
-
# - wf - the path to the current weather file as a string, updated after each step
|
98
|
-
# - output_attributes - ? - deprecate
|
99
102
|
# - sql - the path to the current EnergyPlus SQL file as a string
|
103
|
+
# - time_logger - logger for doing profiling - time to run each step will be captured in OSResult, deprecate
|
104
|
+
# - wf - the path to the current weather file as a string, updated after each step
|
105
|
+
# - workflow - the current OSW parsed as a Ruby Hash
|
106
|
+
# - workflow_json - the current WorkflowJSON object
|
100
107
|
@registry = Registry.new
|
101
108
|
|
102
109
|
openstudio_2 = false
|
@@ -110,26 +117,28 @@ module OpenStudio
|
|
110
117
|
|
111
118
|
# get the input osw
|
112
119
|
@input_adapter = OpenStudio::Workflow::InputAdapter::Local.new(osw_path)
|
113
|
-
|
114
|
-
# create the output adapter
|
115
|
-
@output_adapter = nil
|
116
|
-
if options[:output_adapter]
|
117
|
-
@output_adapter = options[:output_adapter]
|
118
|
-
else
|
119
|
-
@output_adapter = OpenStudio::Workflow::OutputAdapter::Local.new(output_directory: @input_adapter.run_dir)
|
120
|
-
end
|
121
|
-
|
122
|
-
@registry.register(:osw_path) { @input_adapter.osw_path }
|
123
|
-
@registry.register(:osw_dir) { @input_adapter.osw_dir }
|
124
|
-
@registry.register(:run_dir) { @input_adapter.run_dir }
|
125
|
-
|
120
|
+
|
126
121
|
# DLM: need to check that we have correct permissions to all these paths
|
122
|
+
@registry.register(:osw_path) { Pathname.new(@input_adapter.osw_path).realpath }
|
123
|
+
@registry.register(:osw_dir) { Pathname.new(@input_adapter.osw_dir).realpath }
|
124
|
+
@registry.register(:run_dir) { Pathname.new(@input_adapter.run_dir).cleanpath } # run dir might not yet exist, calling realpath will throw
|
125
|
+
|
126
|
+
# get info to set up logging first in case of failures later
|
127
|
+
@options[:debug] = @input_adapter.debug(user_options, false)
|
128
|
+
@options[:preserve_run_dir] = @input_adapter.preserve_run_dir(user_options, false)
|
129
|
+
@options[:profile] = @input_adapter.profile(user_options, false)
|
130
|
+
|
131
|
+
# if running in osw dir, force preserve run dir
|
132
|
+
if @registry[:osw_dir] == @registry[:run_dir]
|
133
|
+
# force preserving the run directory
|
134
|
+
@options[:preserve_run_dir] = true
|
135
|
+
end
|
127
136
|
|
128
137
|
# By default blow away the entire run directory every time and recreate it
|
129
|
-
unless options[:preserve_run_dir]
|
138
|
+
unless @options[:preserve_run_dir]
|
130
139
|
if File.exist?(@registry[:run_dir])
|
131
140
|
# logger is not initialized yet (it needs run dir to exist for log)
|
132
|
-
puts "Removing existing run directory #{@registry[:run_dir]}" if options[:debug]
|
141
|
+
puts "Removing existing run directory #{@registry[:run_dir]}" if @options[:debug]
|
133
142
|
|
134
143
|
# DLM: this is dangerous, we are calling rm_rf on a user entered directory, need to check this first
|
135
144
|
# TODO: Echoing Dan's comment
|
@@ -138,17 +147,14 @@ module OpenStudio
|
|
138
147
|
end
|
139
148
|
FileUtils.mkdir_p(@registry[:run_dir])
|
140
149
|
|
141
|
-
|
142
|
-
|
143
|
-
|
144
|
-
|
145
|
-
|
146
|
-
|
147
|
-
|
148
|
-
# DLM: need to make sure that run.log will be closed later
|
149
|
-
defaults[:targets] = [STDOUT, File.open(File.join(@registry[:run_dir], 'run.log'), 'a')]
|
150
|
+
# set up logging after cleaning run dir
|
151
|
+
if user_options[:targets]
|
152
|
+
@options[:targets] = user_options[:targets]
|
153
|
+
else
|
154
|
+
# don't create these files unless we want to use them
|
155
|
+
# DLM: TODO, make sure that run.log will be closed later
|
156
|
+
@options[:targets] = [STDOUT, File.open(File.join(@registry[:run_dir], 'run.log'), 'a')]
|
150
157
|
end
|
151
|
-
@options = defaults.merge(options)
|
152
158
|
|
153
159
|
@registry.register(:log_targets) { @options[:targets] }
|
154
160
|
@registry.register(:time_logger) { TimeLogger.new } if @options[:profile]
|
@@ -158,9 +164,23 @@ module OpenStudio
|
|
158
164
|
@logger = ::Logger.new(MultiDelegator.delegate(:write, :close).to(*@options[:targets])) # * is the splat operator
|
159
165
|
@logger.level = logger_level
|
160
166
|
@registry.register(:logger) { @logger }
|
161
|
-
|
167
|
+
|
162
168
|
@logger.info "openstudio_2 = #{@registry[:openstudio_2]}"
|
163
169
|
|
170
|
+
# get the output adapter
|
171
|
+
default_output_adapter = OpenStudio::Workflow::OutputAdapter::Local.new(output_directory: @input_adapter.run_dir)
|
172
|
+
@output_adapter = @input_adapter.output_adapter(user_options, default_output_adapter, @logger)
|
173
|
+
|
174
|
+
# get the jobs
|
175
|
+
default_jobs = OpenStudio::Workflow::Run.default_jobs
|
176
|
+
@jobs = @input_adapter.jobs(user_options, default_jobs, @logger)
|
177
|
+
|
178
|
+
# get other run options out of user_options and into permanent options
|
179
|
+
@options[:cleanup] = @input_adapter.cleanup(user_options, true)
|
180
|
+
@options[:energyplus_path] = @input_adapter.energyplus_path(user_options, nil)
|
181
|
+
@options[:verify_osw] = @input_adapter.verify_osw(user_options, true)
|
182
|
+
@options[:weather_file] = @input_adapter.weather_file(user_options, nil)
|
183
|
+
|
164
184
|
openstudio_dir = "unknown"
|
165
185
|
begin
|
166
186
|
openstudio_dir = $OpenStudio_Dir
|
@@ -175,7 +195,6 @@ module OpenStudio
|
|
175
195
|
|
176
196
|
# Define the state and transitions
|
177
197
|
@current_state = :queued
|
178
|
-
@jobs = @options[:jobs]
|
179
198
|
end
|
180
199
|
|
181
200
|
# execute the workflow defined in the state object
|
@@ -232,7 +251,7 @@ module OpenStudio
|
|
232
251
|
def step
|
233
252
|
step_instance = @jobs.find { |h| h[:state] == @current_state }
|
234
253
|
require step_instance[:file]
|
235
|
-
klass = OpenStudio::Workflow.new_class(step_instance[:job], @input_adapter, @output_adapter, @registry, options)
|
254
|
+
klass = OpenStudio::Workflow.new_class(step_instance[:job], @input_adapter, @output_adapter, @registry, @options)
|
236
255
|
@output_adapter.communicate_transition("Starting state #{@current_state}", :state)
|
237
256
|
state_return = klass.perform
|
238
257
|
if state_return
|