openstudiocore/src/cli/openstudio_cli.rb
# Executes the standard, or one of two custom, workflows using the workflow-gem
#
# @param [Array] sub_argv Options passed to the run command from the user input
# @return [Fixnum] Return status
#
Executes the standard, or one of two custom, workflows using the workflow-gem
Executes the standard or one of two custom workflows using the workflow - gem
def execute(sub_argv)
    $logger.info "Run, sub_argv = #{sub_argv}"
    run_options = {}
    run_options[:fast] = false
    if sub_argv.delete '--fast'
      run_options[:fast] = true
    end
    options = {}
    options[:debug] = false
    options[:no_simulation] = false
    options[:osw_path] = './workflow.osw'
    options[:post_process] = false
    opts = OptionParser.new do |o|
      o.banner = 'Usage: openstudio run [options]'
      o.separator ''
      o.separator 'Options:'
      o.separator ''
      o.on('-w', '--workflow [FILE]', 'Specify the FILE path to the workflow to run') do |osw_path|
        options[:osw_path] = osw_path
      end
      o.on('-m', '--measures_only', 'Only run the OpenStudio and EnergyPlus measures') do
        options[:no_simulation] = true
      end
      o.on('-p', '--postprocess_only', 'Only run the reporting measures') do
        options[:post_process] = true
      end
      o.on('-s', '--socket PORT', 'Pipe status messages to a socket on localhost PORT') do |port|
        options[:socket] = port
      end
      o.on('--debug', 'Includes additional outputs for debugging failing workflows and does not clean up the run directory') do |f|
        options[:debug] = f
      end
    end
    argv = parse_options(opts, sub_argv)
    return 0 if argv == nil
    $logger.debug("Run command: #{argv.inspect} #{options.inspect}")
    unless argv == []
      $logger.error 'Extra arguments passed to the run command. Please refer to the help documentation.'
      return 1
    end
    if options[:post_process] && options[:no_simulation]
      $logger.error 'Both the -m and -p flags were set, which is an invalid combination.'
      return 1
    end
    require 'openstudio-workflow'
    osw_path = options[:osw_path]
    osw_path = File.absolute_path(File.join(Dir.pwd, osw_path)) unless Pathname.new(osw_path).absolute?
    $logger.debug "Path for the OSW: #{osw_path}"
    if options[:debug]
      run_options[:debug] = true
      run_options[:cleanup] = false
    end
    if options[:socket]
      require 'openstudio/workflow/adapters/input/local'
      require 'openstudio/workflow/adapters/output/socket'
      input_adapter = OpenStudio::Workflow::InputAdapter::Local.new(osw_path)
      output_adapter = OpenStudio::Workflow::OutputAdapter::Socket.new({output_directory: input_adapter.run_dir, port: options[:socket]})
      run_options[:output_adapter] = output_adapter
    end
    if options[:no_simulation]
      run_options[:jobs] = [
        { state: :queued, next_state: :initialization, options: { initial: true } },
        { state: :initialization, next_state: :os_measures, job: :RunInitialization,
          file: 'openstudio/workflow/jobs/run_initialization.rb', options: {} },
        { state: :os_measures, next_state: :translator, job: :RunOpenStudioMeasures,
          file: 'openstudio/workflow/jobs/run_os_measures.rb', options: {} },
        { state: :translator, next_state: :ep_measures, job: :RunTranslation,
          file: 'openstudio/workflow/jobs/run_translation.rb', options: {} },
        { state: :ep_measures, next_state: :preprocess, job: :RunEnergyPlusMeasures,
          file: 'openstudio/workflow/jobs/run_ep_measures.rb', options: {} },
        { state: :preprocess, next_state: :postprocess, job: :RunPreprocess,
          file: 'openstudio/workflow/jobs/run_preprocess.rb', options: {} },
        { state: :postprocess, next_state: :finished, job: :RunPostprocess,
          file: 'openstudio/workflow/jobs/run_postprocess.rb', options: {} },
        { state: :finished },
        { state: :errored }
      ]
    elsif options[:post_process]
      run_options[:jobs] = [
        { state: :queued, next_state: :initialization, options: { initial: true } },
        { state: :initialization, next_state: :reporting_measures, job: :RunInitialization,
          file: 'openstudio/workflow/jobs/run_initialization.rb', options: {} },
        { state: :reporting_measures, next_state: :postprocess, job: :RunReportingMeasures,
          file: 'openstudio/workflow/jobs/run_reporting_measures.rb', options: {} },
        { state: :postprocess, next_state: :finished, job: :RunPostprocess,
          file: 'openstudio/workflow/jobs/run_postprocess.rb', options: {} },
        { state: :finished },
        { state: :errored }
      ]
      run_options[:preserve_run_dir] = true
    end
    $logger.debug "Initializing run method"
    k = OpenStudio::Workflow::Run.new osw_path, run_options
    $logger.debug "Beginning run"
    k.run
    0
  end
def execute ( sub_argv ) $logger . info "Run, sub_argv = #{sub_argv}" run_options = { } run_options [ :fast ] = false if sub_argv . delete '--fast' run_options [ :fast ] = true end options = { } options [ :debug ] = false options [ :no_simulation ] = false options [ :osw_path ] = './workflow.osw' options [ :post_process ] = false opts = OptionParser . new do | o | o . banner = 'Usage: openstudio run [options]' o . separator '' o . separator 'Options:' o . separator '' o . on ( '-w' , '--workflow [FILE]' , 'Specify the FILE path to the workflow to run' ) do | osw_path | options [ :osw_path ] = osw_path end o . on ( '-m' , '--measures_only' , 'Only run the OpenStudio and EnergyPlus measures' ) do options [ :no_simulation ] = true end o . on ( '-p' , '--postprocess_only' , 'Only run the reporting measures' ) do options [ :post_process ] = true end o . on ( '-s' , '--socket PORT' , 'Pipe status messages to a socket on localhost PORT' ) do | port | options [ :socket ] = port end o . on ( '--debug' , 'Includes additional outputs for debugging failing workflows and does not clean up the run directory' ) do | f | options [ :debug ] = f end end argv = parse_options ( opts , sub_argv ) return 0 if argv == nil $logger . debug ( "Run command: #{argv.inspect} #{options.inspect}" ) unless argv == [ ] $logger . error 'Extra arguments passed to the run command. Please refer to the help documentation.' return 1 end if options [ :post_process ] && options [ :no_simulation ] $logger . error 'Both the -m and -p flags were set, which is an invalid combination.' return 1 end require 'openstudio-workflow' osw_path = options [ :osw_path ] osw_path = File . absolute_path ( File . join ( Dir . pwd , osw_path ) ) unless Pathname . new ( osw_path ) . absolute? $logger . debug "Path for the OSW: #{osw_path}" if options [ :debug ] run_options [ :debug ] = true run_options [ :cleanup ] = false end if options [ :socket ] require 'openstudio/workflow/adapters/input/local' require 'openstudio/workflow/adapters/output/socket' input_adapter = OpenStudio :: Workflow :: InputAdapter :: Local . new ( osw_path ) output_adapter = OpenStudio :: Workflow :: OutputAdapter :: Socket . new ( { output_directory : input_adapter . run_dir , port : options [ :socket ] } ) run_options [ :output_adapter ] = output_adapter end if options [ :no_simulation ] run_options [ :jobs ] = [ { state : :queued , next_state : :initialization , options : { initial : true } } , { state : :initialization , next_state : :os_measures , job : :RunInitialization , file : 'openstudio/workflow/jobs/run_initialization.rb' , options : { } } , { state : :os_measures , next_state : :translator , job : :RunOpenStudioMeasures , file : 'openstudio/workflow/jobs/run_os_measures.rb' , options : { } } , { state : :translator , next_state : :ep_measures , job : :RunTranslation , file : 'openstudio/workflow/jobs/run_translation.rb' , options : { } } , { state : :ep_measures , next_state : :preprocess , job : :RunEnergyPlusMeasures , file : 'openstudio/workflow/jobs/run_ep_measures.rb' , options : { } } , { state : :preprocess , next_state : :postprocess , job : :RunPreprocess , file : 'openstudio/workflow/jobs/run_preprocess.rb' , options : { } } , { state : :postprocess , next_state : :finished , job : :RunPostprocess , file : 'openstudio/workflow/jobs/run_postprocess.rb' , options : { } } , { state : :finished } , { state : :errored } ] elsif options [ :post_process ] run_options [ :jobs ] = [ { state : :queued , next_state : :initialization , options : { initial : true } } , { state : :initialization , next_state : :reporting_measures , job : :RunInitialization , file : 'openstudio/workflow/jobs/run_initialization.rb' , options : { } } , { state : :reporting_measures , next_state : :postprocess , job : :RunReportingMeasures , file : 'openstudio/workflow/jobs/run_reporting_measures.rb' , options : { } } , { state : :postprocess , next_state : :finished , job : :RunPostprocess , file : 'openstudio/workflow/jobs/run_postprocess.rb' , options : { } } , { state : :finished } , { state : :errored } ] run_options [ :preserve_run_dir ] = true end $logger . debug "Initializing run method" k = OpenStudio :: Workflow :: Run . new osw_path , run_options $logger . debug "Beginning run" k . run 0 end
Executes the standard, or one of two custom, workflows using the workflow-gem
Executes the standard or one of two custom workflows using the workflow - gem
# options are local to this method, run_methods are what get passed to workflow gem # Hidden option shhhhh # Parse the options
None
Fixnum
sub_argv
<not_specific>
<not_specific>
sub_argv Options passed to the run command from the user input
sub_argv Options passed to the run command from the user input