Skip to content

Commit

Permalink
Merge pull request #72 from NREL/download_zip
Browse files Browse the repository at this point in the history
add Download zip, etc attributes
  • Loading branch information
kflemin authored Jun 14, 2023
2 parents 9d984cd + 75e2115 commit 2b41eca
Show file tree
Hide file tree
Showing 5 changed files with 198 additions and 11 deletions.
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@ OpenStudio(R) Analysis Gem Change Log
Version 1.3.4
-------------
* Update licenses
* Add download_zip, download_osm, download_osw, download_reports attributes to OSA
* Add cli_verbose, cli_debug, initialize_worker_timeout, run_workflow_timeout, upload_results_timeout attributes to OSA

Version 1.3.3
-------------
Expand Down
7 changes: 3 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,12 @@
[![Coverage Status](https://coveralls.io/repos/NREL/OpenStudio-analysis-gem/badge.svg?branch=develop)](https://coveralls.io/r/NREL/OpenStudio-analysis-gem?branch=develop)
[![Gem Version](https://badge.fury.io/rb/openstudio-analysis.svg)](https://badge.fury.io/rb/openstudio-analysis)

The OpenStudio Analysis Gem is used to communicate files to the OpenStudio Distributed Analysis.
The OpenStudio Analysis Gem is used to communicate files to the [OpenStudio Analysis Framework](https://www.tandfonline.com/doi/full/10.1080/19401493.2020.1778788).

The purpose of this gem is to generate the analysis.json file, analysis.zip, and communicate with the server to upload
The purpose of this gem is to generate the analysis.json file, analysis.zip, convert an OSW to an OSA, and communicate with the server to upload
the simulations.

This gem does not create the cluster. Currently the only supported Cloud platform is
Amazon AWS using either [OpenStudio's PAT](https://openstudio.nrel.gov) the [openstudio-aws gem](https://rubygems.org/gems/openstudio-aws) or using [vagrant](http://www.vagrantup.com/).
This gem does not create the cluster. To manage cloud resources use the [OpenStudio Analysis Framework Helm Charts](https://github.com/NREL/openstudio-server-helm).

## Instructions

Expand Down
124 changes: 119 additions & 5 deletions lib/openstudio/analysis/formulation.rb
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,15 @@ class Formulation
attr_accessor :workflow
attr_accessor :algorithm
attr_accessor :osw_path
attr_accessor :download_zip
attr_accessor :download_reports
attr_accessor :download_osw
attr_accessor :download_osm
attr_accessor :cli_debug
attr_accessor :cli_verbose
attr_accessor :initialize_worker_timeout
attr_accessor :run_workflow_timeout
attr_accessor :upload_results_timeout

# the attributes below are used for packaging data into the analysis zip file
attr_reader :weather_files
Expand All @@ -51,6 +60,15 @@ def initialize(display_name)
@weather_file = WeatherFile.new
@seed_model = SeedModel.new
@algorithm = OpenStudio::Analysis::AlgorithmAttributes.new
@download_zip = true
@download_reports = true
@download_osw = true
@download_osm = true
@cli_debug = "--debug"
@cli_verbose = "--verbose"
@initialize_worker_timeout = 28800
@run_workflow_timeout = 28800
@upload_results_timeout = 28800

# Analysis Zip attributes
@weather_files = SupportFiles.new
Expand Down Expand Up @@ -90,6 +108,97 @@ def weather_file=(file)
@weather_file[:file] = file
end

# Set the value for 'download_zip'
#
# @param value [Boolean] The value for 'download_zip'
def download_zip=(value)
if [true, false].include?(value)
@download_zip = value
else
raise ArgumentError, "Invalid value for 'download_zip'. Only true or false allowed."
end
end

# Set the value for 'download_reports'
#
# @param value [Boolean] The value for 'download_reports'
def download_reports=(value)
if [true, false].include?(value)
@download_reports = value
else
raise ArgumentError, "Invalid value for 'download_reports'. Only true or false allowed."
end
end

# Set the value for 'download_osw'
#
# @param value [Boolean] The value for 'download_osw'
def download_osw=(value)
if [true, false].include?(value)
@download_osw = value
else
raise ArgumentError, "Invalid value for 'download_osw'. Only true or false allowed."
end
end

# Set the value for 'download_osm'
#
# @param value [Boolean] The value for 'download_osm'
def download_osm=(value)
if [true, false].include?(value)
@download_osm = value
else
raise ArgumentError, "Invalid value for 'download_osm'. Only true or false allowed."
end
end

# Set the value for 'cli_debug'
#
# @param value [Boolean] The value for 'cli_debug'
def cli_debug=(value)
@cli_debug = value
end

# Set the value for 'cli_verbose'
#
# @param value [Boolean] The value for 'cli_verbose'
def cli_verbose=(value)
@cli_verbose = value
end

# Set the value for 'run_workflow_timeout'
#
# @param value [Integer] The value for 'run_workflow_timeout'
def run_workflow_timeout=(value)
if value.is_a?(Integer)
@run_workflow_timeout = value
else
raise ArgumentError, "Invalid value for 'run_workflow_timeout'. Only integer values allowed."
end
end

# Set the value for 'initialize_worker_timeout'
#
# @param value [Integer] The value for 'initialize_worker_timeout'
def initialize_worker_timeout=(value)
if value.is_a?(Integer)
@initialize_worker_timeout = value
else
raise ArgumentError, "Invalid value for 'initialize_worker_timeout'. Only integer values allowed."
end
end

# Set the value for 'upload_results_timeout'
#
# @param value [Integer] The value for 'upload_results_timeout'
def upload_results_timeout=(value)
if value.is_a?(Integer)
@upload_results_timeout = value
else
raise ArgumentError, "Invalid value for 'upload_results_timeout'. Only integer values allowed."
end
end

# Add an output of interest to the problem formulation
#
# @param output_hash [Hash] Hash of the output variable in the legacy format
Expand Down Expand Up @@ -203,11 +312,16 @@ def to_hash(version = 1)
end

h[:analysis][:file_format_version] = version
h[:analysis][:cli_debug] = "--debug"
h[:analysis][:cli_verbose] = "--verbose"
h[:analysis][:run_workflow_timeout] = 28800
h[:analysis][:upload_results_timeout] = 28800
h[:analysis][:initialize_worker_timeout] = 28800
h[:analysis][:cli_debug] = @cli_debug
h[:analysis][:cli_verbose] = @cli_verbose
h[:analysis][:run_workflow_timeout] = @run_workflow_timeout
h[:analysis][:upload_results_timeout] = @upload_results_timeout
h[:analysis][:initialize_worker_timeout] = @initialize_worker_timeout
h[:analysis][:download_zip] = @download_zip
h[:analysis][:download_reports] = @download_reports
h[:analysis][:download_osw] = @download_osw
h[:analysis][:download_osm] = @download_osm

#-BLB I dont think this does anything. server_scripts are run if they are in
#the /scripts/analysis or /scripts/data_point directories
#but nothing is ever checked in the OSA.
Expand Down
2 changes: 1 addition & 1 deletion lib/openstudio/analysis/version.rb
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,6 @@ module OpenStudio
module Analysis
# format should be ^.*\-{1}[a-z]+[0-9]+
# for example: -rc1, -beta6, -customusecase0
VERSION = '1.3.3'.freeze
VERSION = '1.3.4'.freeze
end
end
74 changes: 73 additions & 1 deletion spec/openstudio/formulation_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -188,7 +188,79 @@

a.seed_model = 'spec/files/small_seed.osm'
a.weather_file = 'spec/files/partial_weather.epw'


# check value of download_zip
expect(a.download_zip).to be true
expect(a.to_hash[:analysis][:download_zip]).to match true
a.download_zip = false
expect(a.download_zip).to be false
expect(a.to_hash[:analysis][:download_zip]).to match false
expect { a.download_zip='bad' }.to raise_error(ArgumentError)

# check value of download_reports
expect(a.download_reports).to be true
expect(a.to_hash[:analysis][:download_reports]).to match true
a.download_reports = false
expect(a.download_reports).to be false
expect(a.to_hash[:analysis][:download_reports]).to match false
expect { a.download_reports='bad' }.to raise_error(ArgumentError)

# check value of download_osw
expect(a.download_osw).to be true
expect(a.to_hash[:analysis][:download_osw]).to match true
a.download_osw = false
expect(a.download_osw).to be false
expect(a.to_hash[:analysis][:download_osw]).to match false
expect { a.download_osw='bad' }.to raise_error(ArgumentError)

# check value of download_osm
expect(a.download_osm).to be true
expect(a.to_hash[:analysis][:download_osm]).to match true
a.download_osm = false
expect(a.download_osm).to be false
expect(a.to_hash[:analysis][:download_osm]).to match false
expect { a.download_osm='bad' }.to raise_error(ArgumentError)

# check value of cli_debug
expect(a.cli_debug).to eq "--debug"
expect(a.to_hash[:analysis][:cli_debug]).to eq "--debug"
a.cli_debug = ""
expect(a.cli_debug).to eq ""
expect(a.to_hash[:analysis][:cli_debug]).to eq ""
# we dont need to check for bad values since only the string --debug or '' are processed server side

# check value of cli_verbose
expect(a.cli_verbose).to eq "--verbose"
expect(a.to_hash[:analysis][:cli_verbose]).to eq "--verbose"
a.cli_verbose = ""
expect(a.cli_verbose).to eq ""
expect(a.to_hash[:analysis][:cli_verbose]).to eq ""
# we dont need to check for bad values since only the string --verbose or '' are processed server side

# check value of run_workflow_timeout
expect(a.run_workflow_timeout).to eq 28800
expect(a.to_hash[:analysis][:run_workflow_timeout]).to eq 28800
a.run_workflow_timeout = 0
expect(a.run_workflow_timeout).to eq 0
expect(a.to_hash[:analysis][:run_workflow_timeout]).to eq 0
expect { a.run_workflow_timeout='bad' }.to raise_error(ArgumentError)

# check value of initialize_worker_timeout
expect(a.initialize_worker_timeout).to eq 28800
expect(a.to_hash[:analysis][:initialize_worker_timeout]).to eq 28800
a.initialize_worker_timeout = 0
expect(a.initialize_worker_timeout).to eq 0
expect(a.to_hash[:analysis][:initialize_worker_timeout]).to eq 0
expect { a.initialize_worker_timeout='bad' }.to raise_error(ArgumentError)

# check value of upload_results_timeout
expect(a.upload_results_timeout).to eq 28800
expect(a.to_hash[:analysis][:upload_results_timeout]).to eq 28800
a.upload_results_timeout = 0
expect(a.upload_results_timeout).to eq 0
expect(a.to_hash[:analysis][:upload_results_timeout]).to eq 0
expect { a.upload_results_timeout='bad' }.to raise_error(ArgumentError)

expect(a.seed_model.first).to eq 'spec/files/small_seed.osm'

expect(a.to_hash[:analysis][:problem][:algorithm][:objective_functions]).to match ['total_natural_gas']
Expand Down

0 comments on commit 2b41eca

Please sign in to comment.