openstudio-workflow 1.3.3 → 1.3.4

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (35) hide show
  1. checksums.yaml +4 -4
  2. data/CHANGELOG.md +77 -72
  3. data/README.md +93 -93
  4. data/Rakefile +36 -36
  5. data/lib/openstudio-workflow.rb +65 -49
  6. data/lib/openstudio/workflow/adapters/input/local.rb +324 -301
  7. data/lib/openstudio/workflow/adapters/output/local.rb +161 -97
  8. data/lib/openstudio/workflow/adapters/output/socket.rb +107 -91
  9. data/lib/openstudio/workflow/adapters/output/web.rb +82 -66
  10. data/lib/openstudio/workflow/adapters/output_adapter.rb +163 -147
  11. data/lib/openstudio/workflow/job.rb +57 -22
  12. data/lib/openstudio/workflow/jobs/resources/monthly_report.idf +222 -222
  13. data/lib/openstudio/workflow/jobs/run_energyplus.rb +70 -54
  14. data/lib/openstudio/workflow/jobs/run_ep_measures.rb +73 -57
  15. data/lib/openstudio/workflow/jobs/run_initialization.rb +203 -171
  16. data/lib/openstudio/workflow/jobs/run_os_measures.rb +89 -73
  17. data/lib/openstudio/workflow/jobs/run_postprocess.rb +73 -57
  18. data/lib/openstudio/workflow/jobs/run_preprocess.rb +104 -80
  19. data/lib/openstudio/workflow/jobs/run_reporting_measures.rb +118 -102
  20. data/lib/openstudio/workflow/jobs/run_translation.rb +84 -68
  21. data/lib/openstudio/workflow/multi_delegator.rb +62 -46
  22. data/lib/openstudio/workflow/registry.rb +172 -137
  23. data/lib/openstudio/workflow/run.rb +328 -312
  24. data/lib/openstudio/workflow/time_logger.rb +96 -53
  25. data/lib/openstudio/workflow/util.rb +49 -14
  26. data/lib/openstudio/workflow/util/energyplus.rb +605 -570
  27. data/lib/openstudio/workflow/util/io.rb +68 -33
  28. data/lib/openstudio/workflow/util/measure.rb +650 -615
  29. data/lib/openstudio/workflow/util/model.rb +151 -100
  30. data/lib/openstudio/workflow/util/post_process.rb +238 -187
  31. data/lib/openstudio/workflow/util/weather_file.rb +143 -108
  32. data/lib/openstudio/workflow/version.rb +40 -24
  33. data/lib/openstudio/workflow_json.rb +476 -443
  34. data/lib/openstudio/workflow_runner.rb +268 -252
  35. metadata +23 -23
@@ -1,97 +1,161 @@
1
- ######################################################################
2
- # Copyright (c) 2008-2014, Alliance for Sustainable Energy.
3
- # All rights reserved.
4
- #
5
- # This library is free software; you can redistribute it and/or
6
- # modify it under the terms of the GNU Lesser General Public
7
- # License as published by the Free Software Foundation; either
8
- # version 2.1 of the License, or (at your option) any later version.
9
- #
10
- # This library is distributed in the hope that it will be useful,
11
- # but WITHOUT ANY WARRANTY; without even the implied warranty of
12
- # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13
- # Lesser General Public License for more details.
14
- #
15
- # You should have received a copy of the GNU Lesser General Public
16
- # License along with this library; if not, write to the Free Software
17
- # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
18
- ######################################################################
19
-
20
- require 'openstudio/workflow/adapters/output_adapter'
21
-
22
- # Local file based workflow
23
- module OpenStudio
24
- module Workflow
25
- module OutputAdapter
26
- class Local < OutputAdapters
27
- def initialize(options = {})
28
- raise 'The required :output_directory option was not passed to the local output adapter' unless options[:output_directory]
29
- super
30
- end
31
-
32
- # Write to the filesystem that the process has started
33
- #
34
- def communicate_started
35
- File.open("#{@options[:output_directory]}/started.job", 'w') { |f| f << "Started Workflow #{::Time.now}" }
36
- end
37
-
38
- # Write to the filesystem that the process has completed
39
- #
40
- def communicate_complete
41
- File.open("#{@options[:output_directory]}/finished.job", 'w') { |f| f << "Finished Workflow #{::Time.now}" }
42
- end
43
-
44
- # Write to the filesystem that the process has failed
45
- #
46
- def communicate_failure
47
- File.open("#{@options[:output_directory]}/failed.job", 'w') { |f| f << "Failed Workflow #{::Time.now}" }
48
- end
49
-
50
- # Do nothing on a state transition
51
- #
52
- def communicate_transition(_ = nil, _ = nil, _ = nil)
53
- end
54
-
55
- # Do nothing on EnergyPlus stdout
56
- #
57
- def communicate_energyplus_stdout(_ = nil, _ = nil)
58
- end
59
-
60
- # Do nothing on Measure result
61
- #
62
- def communicate_measure_result(_ = nil, _ = nil)
63
- end
64
-
65
- # Write the measure attributes to the filesystem
66
- #
67
- def communicate_measure_attributes(measure_attributes, _ = nil)
68
- File.open("#{@options[:output_directory]}/measure_attributes.json", 'w') do |f|
69
- f << JSON.pretty_generate(measure_attributes)
70
- end
71
- end
72
-
73
- # Write the objective function results to the filesystem
74
- #
75
- def communicate_objective_function(objectives, _ = nil)
76
- obj_fun_file = "#{@options[:output_directory]}/objectives.json"
77
- FileUtils.rm_f(obj_fun_file) if File.exist?(obj_fun_file)
78
- File.open(obj_fun_file, 'w') { |f| f << JSON.pretty_generate(objectives) }
79
- end
80
-
81
- # Write the results of the workflow to the filesystem
82
- #
83
- def communicate_results(directory, results)
84
- zip_results(directory)
85
-
86
- if results.is_a? Hash
87
- # DLM: don't we want this in the results zip?
88
- # DLM: deprecate in favor of out.osw
89
- File.open("#{@options[:output_directory]}/data_point_out.json", 'w') { |f| f << JSON.pretty_generate(results) }
90
- else
91
- #puts "Unknown datapoint result type. Please handle #{results.class}"
92
- end
93
- end
94
- end
95
- end
96
- end
97
- end
1
+ # *******************************************************************************
2
+ # OpenStudio(R), Copyright (c) 2008-2018, Alliance for Sustainable Energy, LLC.
3
+ # All rights reserved.
4
+ # Redistribution and use in source and binary forms, with or without
5
+ # modification, are permitted provided that the following conditions are met:
6
+ #
7
+ # (1) Redistributions of source code must retain the above copyright notice,
8
+ # this list of conditions and the following disclaimer.
9
+ #
10
+ # (2) Redistributions in binary form must reproduce the above copyright notice,
11
+ # this list of conditions and the following disclaimer in the documentation
12
+ # and/or other materials provided with the distribution.
13
+ #
14
+ # (3) Neither the name of the copyright holder nor the names of any contributors
15
+ # may be used to endorse or promote products derived from this software without
16
+ # specific prior written permission from the respective party.
17
+ #
18
+ # (4) Other than as required in clauses (1) and (2), distributions in any form
19
+ # of modifications or other derivative works may not use the "OpenStudio"
20
+ # trademark, "OS", "os", or any other confusingly similar designation without
21
+ # specific prior written permission from Alliance for Sustainable Energy, LLC.
22
+ #
23
+ # THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
24
+ # AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
25
+ # IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
26
+ # DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER, THE UNITED STATES
27
+ # GOVERNMENT, OR ANY CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
28
+ # INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
29
+ # LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
30
+ # PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
31
+ # LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
32
+ # NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE,
33
+ # EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
34
+ # *******************************************************************************
35
+
36
+ require 'openstudio/workflow/adapters/output_adapter'
37
+
38
+ # Local file based workflow
39
+ module OpenStudio
40
+ module Workflow
41
+ module OutputAdapter
42
+ class Local < OutputAdapters
43
+ def initialize(options = {})
44
+ raise 'The required :output_directory option was not passed to the local output adapter' unless options[:output_directory]
45
+ super
46
+ end
47
+
48
+ # Write to the filesystem that the process has started
49
+ #
50
+ def communicate_started
51
+ File.open("#{@options[:output_directory]}/started.job", 'w') do |f|
52
+ f << "Started Workflow #{::Time.now}"
53
+ # make sure data is written to the disk one way or the other
54
+ begin
55
+ f.fsync
56
+ rescue
57
+ f.flush
58
+ end
59
+ end
60
+ end
61
+
62
+ # Write to the filesystem that the process has completed
63
+ #
64
+ def communicate_complete
65
+ File.open("#{@options[:output_directory]}/finished.job", 'w') do |f|
66
+ f << "Finished Workflow #{::Time.now}"
67
+ # make sure data is written to the disk one way or the other
68
+ begin
69
+ f.fsync
70
+ rescue
71
+ f.flush
72
+ end
73
+ end
74
+ end
75
+
76
+ # Write to the filesystem that the process has failed
77
+ #
78
+ def communicate_failure
79
+ File.open("#{@options[:output_directory]}/failed.job", 'w') do |f|
80
+ f << "Failed Workflow #{::Time.now}"
81
+ # make sure data is written to the disk one way or the other
82
+ begin
83
+ f.fsync
84
+ rescue
85
+ f.flush
86
+ end
87
+ end
88
+ end
89
+
90
+ # Do nothing on a state transition
91
+ #
92
+ def communicate_transition(_ = nil, _ = nil, _ = nil)
93
+ end
94
+
95
+ # Do nothing on EnergyPlus stdout
96
+ #
97
+ def communicate_energyplus_stdout(_ = nil, _ = nil)
98
+ end
99
+
100
+ # Do nothing on Measure result
101
+ #
102
+ def communicate_measure_result(_ = nil, _ = nil)
103
+ end
104
+
105
+ # Write the measure attributes to the filesystem
106
+ #
107
+ def communicate_measure_attributes(measure_attributes, _ = nil)
108
+ attributes_file = "#{@options[:output_directory]}/measure_attributes.json"
109
+ FileUtils.rm_f(attributes_file) if File.exist?(attributes_file)
110
+ File.open(attributes_file, 'w') do |f|
111
+ f << JSON.pretty_generate(measure_attributes)
112
+ # make sure data is written to the disk one way or the other
113
+ begin
114
+ f.fsync
115
+ rescue
116
+ f.flush
117
+ end
118
+ end
119
+ end
120
+
121
+ # Write the objective function results to the filesystem
122
+ #
123
+ def communicate_objective_function(objectives, _ = nil)
124
+ obj_fun_file = "#{@options[:output_directory]}/objectives.json"
125
+ FileUtils.rm_f(obj_fun_file) if File.exist?(obj_fun_file)
126
+ File.open(obj_fun_file, 'w') do |f|
127
+ f << JSON.pretty_generate(objectives)
128
+ # make sure data is written to the disk one way or the other
129
+ begin
130
+ f.fsync
131
+ rescue
132
+ f.flush
133
+ end
134
+ end
135
+ end
136
+
137
+ # Write the results of the workflow to the filesystem
138
+ #
139
+ def communicate_results(directory, results)
140
+ zip_results(directory)
141
+
142
+ if results.is_a? Hash
143
+ # DLM: don't we want this in the results zip?
144
+ # DLM: deprecate in favor of out.osw
145
+ File.open("#{@options[:output_directory]}/data_point_out.json", 'w') do |f|
146
+ f << JSON.pretty_generate(results)
147
+ # make sure data is written to the disk one way or the other
148
+ begin
149
+ f.fsync
150
+ rescue
151
+ f.flush
152
+ end
153
+ end
154
+ else
155
+ #puts "Unknown datapoint result type. Please handle #{results.class}"
156
+ end
157
+ end
158
+ end
159
+ end
160
+ end
161
+ end
@@ -1,91 +1,107 @@
1
- ######################################################################
2
- # Copyright (c) 2008-2014, Alliance for Sustainable Energy.
3
- # All rights reserved.
4
- #
5
- # This library is free software; you can redistribute it and/or
6
- # modify it under the terms of the GNU Lesser General Public
7
- # License as published by the Free Software Foundation; either
8
- # version 2.1 of the License, or (at your option) any later version.
9
- #
10
- # This library is distributed in the hope that it will be useful,
11
- # but WITHOUT ANY WARRANTY; without even the implied warranty of
12
- # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13
- # Lesser General Public License for more details.
14
- #
15
- # You should have received a copy of the GNU Lesser General Public
16
- # License along with this library; if not, write to the Free Software
17
- # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
18
- ######################################################################
19
-
20
- require_relative 'local'
21
- require 'socket'
22
-
23
- # Local file based workflow
24
- module OpenStudio
25
- module Workflow
26
- module OutputAdapter
27
- class Socket < Local
28
- def initialize(options = {})
29
- super
30
- raise 'The required :port option was not passed to the socket output adapter' unless options[:port]
31
-
32
- @socket = TCPSocket.open 'localhost', options[:port]
33
- end
34
-
35
- def communicate_started
36
- super
37
- @socket.write("Started\n")
38
- end
39
-
40
- def communicate_results(directory, results)
41
- super
42
- end
43
-
44
- def communicate_complete
45
- super
46
- @socket.write("Complete\n")
47
- end
48
-
49
- def communicate_failure
50
- super
51
- @socket.write("Failure\n")
52
- end
53
-
54
- def communicate_objective_function(objectives, options = {})
55
- super
56
- end
57
-
58
- def communicate_transition(message, type, options = {})
59
- super
60
- @socket.write(message + "\n")
61
- end
62
-
63
- def communicate_energyplus_stdout(line, options = {})
64
- super
65
- @socket.write(line)
66
- end
67
-
68
- def communicate_measure_result(result, options = {})
69
- super
70
-
71
- step_result = result.stepResult
72
- initial_condition = result.stepInitialCondition
73
- final_condition = result.stepFinalCondition
74
- errors = result.stepErrors
75
- warnings = result.stepWarnings
76
- infos = result.stepInfo
77
-
78
- # Mirrors WorkflowStepResult::string
79
- tab = ' '
80
- @socket.write("#{tab}Result: #{step_result.get.valueName}\n") if !step_result.empty?
81
- @socket.write("#{tab}Initial Condition: #{initial_condition.get}\n") if !initial_condition.empty?
82
- @socket.write("#{tab}Final Condition: #{final_condition.get}\n") if !final_condition.empty?
83
- errors.each {|error| @socket.write("#{tab}Error: #{error}\n") }
84
- warnings.each {|warning| @socket.write("#{tab}Warn: #{warning}\n") }
85
- infos.each {|info| @socket.write("#{tab}Info: #{info}\n") }
86
- end
87
-
88
- end
89
- end
90
- end
91
- end
1
+ # *******************************************************************************
2
+ # OpenStudio(R), Copyright (c) 2008-2018, Alliance for Sustainable Energy, LLC.
3
+ # All rights reserved.
4
+ # Redistribution and use in source and binary forms, with or without
5
+ # modification, are permitted provided that the following conditions are met:
6
+ #
7
+ # (1) Redistributions of source code must retain the above copyright notice,
8
+ # this list of conditions and the following disclaimer.
9
+ #
10
+ # (2) Redistributions in binary form must reproduce the above copyright notice,
11
+ # this list of conditions and the following disclaimer in the documentation
12
+ # and/or other materials provided with the distribution.
13
+ #
14
+ # (3) Neither the name of the copyright holder nor the names of any contributors
15
+ # may be used to endorse or promote products derived from this software without
16
+ # specific prior written permission from the respective party.
17
+ #
18
+ # (4) Other than as required in clauses (1) and (2), distributions in any form
19
+ # of modifications or other derivative works may not use the "OpenStudio"
20
+ # trademark, "OS", "os", or any other confusingly similar designation without
21
+ # specific prior written permission from Alliance for Sustainable Energy, LLC.
22
+ #
23
+ # THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
24
+ # AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
25
+ # IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
26
+ # DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER, THE UNITED STATES
27
+ # GOVERNMENT, OR ANY CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
28
+ # INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
29
+ # LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
30
+ # PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
31
+ # LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
32
+ # NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE,
33
+ # EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
34
+ # *******************************************************************************
35
+
36
+ require_relative 'local'
37
+ require 'socket'
38
+
39
+ # Local file based workflow
40
+ module OpenStudio
41
+ module Workflow
42
+ module OutputAdapter
43
+ class Socket < Local
44
+ def initialize(options = {})
45
+ super
46
+ raise 'The required :port option was not passed to the socket output adapter' unless options[:port]
47
+
48
+ @socket = TCPSocket.open 'localhost', options[:port]
49
+ end
50
+
51
+ def communicate_started
52
+ super
53
+ @socket.write("Started\n")
54
+ end
55
+
56
+ def communicate_results(directory, results)
57
+ super
58
+ end
59
+
60
+ def communicate_complete
61
+ super
62
+ @socket.write("Complete\n")
63
+ end
64
+
65
+ def communicate_failure
66
+ super
67
+ @socket.write("Failure\n")
68
+ end
69
+
70
+ def communicate_objective_function(objectives, options = {})
71
+ super
72
+ end
73
+
74
+ def communicate_transition(message, type, options = {})
75
+ super
76
+ @socket.write(message + "\n")
77
+ end
78
+
79
+ def communicate_energyplus_stdout(line, options = {})
80
+ super
81
+ @socket.write(line)
82
+ end
83
+
84
+ def communicate_measure_result(result, options = {})
85
+ super
86
+
87
+ step_result = result.stepResult
88
+ initial_condition = result.stepInitialCondition
89
+ final_condition = result.stepFinalCondition
90
+ errors = result.stepErrors
91
+ warnings = result.stepWarnings
92
+ infos = result.stepInfo
93
+
94
+ # Mirrors WorkflowStepResult::string
95
+ tab = ' '
96
+ @socket.write("#{tab}Result: #{step_result.get.valueName}\n") if !step_result.empty?
97
+ @socket.write("#{tab}Initial Condition: #{initial_condition.get}\n") if !initial_condition.empty?
98
+ @socket.write("#{tab}Final Condition: #{final_condition.get}\n") if !final_condition.empty?
99
+ errors.each {|error| @socket.write("#{tab}Error: #{error}\n") }
100
+ warnings.each {|warning| @socket.write("#{tab}Warn: #{warning}\n") }
101
+ infos.each {|info| @socket.write("#{tab}Info: #{info}\n") }
102
+ end
103
+
104
+ end
105
+ end
106
+ end
107
+ end