Question-and-Answer Resource for the Building Energy Modeling Community
Get started with the Help page
Ask Your Question

Is there a best or preferred workflow for complex OpenStudio Ruby script development including interactive debugging and execution tracing?

asked 2014-11-24 09:05:23 -0600

Mike Sahm's avatar

updated 2017-08-05 13:26:17 -0600

I am developing measures for OpenStudio on a Windows 8.1 platform using Ruby. I have followed the Measures Writing Guide and this was very helpful to get started and am now moving to an extended integrated workflow. I have set up the Eclipse IDE with the Dynamic Language Toolkit (DLTK) for editing scripts and to check Ruby syntax. Does anyone have experience using this or another IDE to interactively debug and trace script execution and to provide OS library Ruby bindings completions? Is there another approach that allows interactive development and debugging? Is there a best or preferred workflow for complex script development?

Question update[11/25/14]

I have now installed RubyMine v7.0 and created a full measure case folder. I set the configuration options following the answers provided, adapted to my local installation. The configuration dialog that I located looks similar to the answer dialog but was in a different location at >Run>Edit Configurations>Defaults>Ruby. Maybe this is a RubyMine version issue or there is another similar dialog somewhere else? The parameters used are shown below and include the installed dev version of OS 1.5.2. I also have the source files installed and I have tried both “-e $stdout.sync=true;$stderr.sync=true;load($0=ARGV.shift) -I ‘C:\Program Files (x86)\OpenStudio 1.5.2\Ruby’ “ and “-e $stdout.sync=true;$stderr.sync=true;load($0=ARGV.shift) -I ‘C:\Program Files (x86)\OpenStudio 1.5.2\Ruby’ -I 'D:\OpenStudio\10 Local Repositories\OpenStudio\developer\ruby' ” for the Ruby arguments. It appears that the OpenStudio:: references are still unresolved. I have searched RubyMine help but not found how to add external libraries to the RubyMine Project. What other settings are needed to resolve the OS references? Thanks

edit retag flag offensive close merge delete


Thank you all very much for your very fast and thorough answers. I will install RubyMine and try these approaches and come back with any questions.

Mike Sahm's avatar Mike Sahm  ( 2014-11-24 13:55:37 -0600 )edit

The ruby arguments input should help it to find OpenStudio.

-e $stdout.sync=true;$stderr.sync=true;load($0=ARGV.shift) -I 'C:\Program Files (x86)\OpenStudio 1.5.2\Ruby'

I don't think I mentioned it before, but if you use command line to run tests, you can create a file at a path similar to this "C:\Ruby200\lib\ruby\site_ruby\openstudio.rb" with the following content.

require 'C:\Program Files (x86)\OpenStudio 1.5.2\Ruby\openstudio.rb'

Paths to openstudio would be different when using newer 64bit version

David Goldwasser's avatar David Goldwasser  ( 2015-01-09 01:26:45 -0600 )edit

3 Answers

Sort by » oldest newest most voted

answered 2014-11-24 11:47:56 -0600

updated 2014-11-24 12:45:07 -0600

@Mike Sahm, that is a good question. As Larry mentioned, you can test your measures using the Apply measure now features. I typically test measures via RubyMine while I write them, and then do additional testing with the Apply measure now. There are a number of nice things about testing outside of the GUI.

  1. You can automate testing so you can batch run when new versions of OpenStudio come out
  2. You can run multiple input and source model combinations, for example seeing that the measures fails gracefully if the user provides bad input such as a negative value for a multiplier.
  3. You can sanity check not just that the measure run, but you can inspect the resulting model and confirm that the values were changed as you expected.
  4. For reporting measure you can save the SQL output so you can cycle very quickly without having to re-run EnergyPlus.

I write my test in parallel with my measure. If you make a new measure in the OpenStudio GUI it comes with a working test. I first update the arguments in the measure to be what I want, strip out all of the run section between the "Initial Condition" and "Final Condition" and then I update the test until it passes. Then I start to fill out the run section of the measure, and just test every time I add a new section. I don't have to stop what I'm doing, it is just a click to run. Some screenshots and additional configuration details are below.

image description This is a screenshot of a new measure opened in Ruby Mine. Notice how there is a "tests" folder next to measure.rb. I have the newmeasuretest.rb file open in the right. That is what I run to test the measure. I don't call the measure directly. This will pass it a model (or in this case make a new model) along with the user argument values.

image description Under the run menu you can edit and create configuration. This shows my configuration. The only one I change for each test is the "Ruby script" which points the specific test file I'm running. The other values help it to find OpenStudio and Ruby. You can setup various ruby versions under "File/Settings/Ruby SDK and Gems". The screenshot above is setup to use my developer build of OpenStudio, but it is perfectly fine to use this workflow with an installed version of OpenStudio. In other words, any user can write and test ruby scripts without having to compile the software.

Here is what the "Ruby arguments" would look like for an installed version of OpenStudio.

-e $stdout.sync=true;$stderr.sync=true;load($0=ARGV.shift) -I 'C:\Program Files (x86)\OpenStudio 1.5.0\Ruby'

There are a few other things I always do that are not in the default new measure test.

  1. I add "show_output(result)". This shows all the info, warning and initial/final condition messages that you ...
edit flag offensive delete link more



I'm glad David mentioned the test file. We try to include one or more test cases with each measure uploaded in the BCL, and PAT tries to encourage you to prepare tests when you create a measure within the GUI. In the future, we expect that the BCL will execute any tests included within a measure zip automatically against multiple versions of OS and report results on our continuous integration dashboard. That will help identify issues in the SDK or Measures as quickly as possible. It doesn't exist yet, but it's definitely on our minds.

ljbrackney's avatar ljbrackney  ( 2014-11-24 12:22:07 -0600 )edit

answered 2014-11-24 09:15:34 -0600

updated 2014-11-24 09:17:22 -0600

A number of the folks on the development team use RubyMine for editing and development. Depending upon the type of measure you're writing, it may be easiest to use the "Apply Measures Now" feature in the OpenStudio Application to quickly apply your code to a simple model. You'll get the standard reporting from the measure as it's running on your model, and you can visually inspect what it did right there in the application. If it's a reporting measure or something designed to run as part of a complex workflow, that's probably easiest to run at the command line. David, Andrew, or one of the other developers will probably chime in with tips on how they develop measures.

edit flag offensive delete link more

answered 2015-01-08 06:47:53 -0600

LSurf's avatar

I've been playing around with RubyMine for some time now to write and test an EnergyPlus measure. I ran into some problems, hopefully my findings can help some other users.

The MiniTest that came with ruby in Openstudio gave me some errors, I was able to fix by inheriting from MiniTest::Unit::TestCase, i.e.:

class TestMeasure_Test < MiniTest::Unit::TestCase
#class TestMeasure_Test < MiniTest::Test # wrong

Every run needs to have the -I option supplied, I got tired of this and fixed by adding an absolute path in the require:

require 'C:\Program Files (x86)\OpenStudio 1.5.0\Ruby\openstudio'
require 'C:\Program Files (x86)\OpenStudio 1.5.0\Ruby\openstudio\ruleset\ShowRunnerOutput'

In an effort to debug the code, I couldn't find anything working. At least not in combination with MiniTest, and minitest/debugger kept failing in every way. I decided to write plain Ruby code without the minitest to see if my measure works for my EnergyPlus measure. This is all based on samples provided above and in the documentation. I left some lines commented out in case someone wants to convert it back to an OpenStudio measure. Not clean code, but it might help some people out.

require 'C:\Program Files (x86)\OpenStudio 1.5.0\Ruby\openstudio'
require 'C:\Program Files (x86)\OpenStudio 1.5.0\Ruby\openstudio\ruleset\ShowRunnerOutput'
require_relative '../measure.rb'

# Input parameters
osmfile = "file.osm"

# create an instance of the measure
measure =

path = + "/" + osmfile)
# load the test model
# translator =
#model = translator.loadModel(path)
#if model.empty?
#  raise("Model not loaded correctly")
#model = model.get

# load the workspace, for EnergyPlus measure
workspace = OpenStudio::Workspace::load(path,"EnergyPlus".to_IddFileType)
raise "Unable to load OpenStudio Workspace from '" + input_path.to_s + "'." if workspace.empty?
workspace = workspace.get

# Get arguments and set to valid values
arguments = measure.arguments(workspace)
argument_map = OpenStudio::Ruleset.convertOSArgumentVectorToMap(arguments)
# Set valid value
zone_name = arguments[0].clone
zone_name.setValue("New Zone")
argument_map["zone_name"] = zone_name

# create an instance of a runner
runner =

# run the measure
#, runner, argument_map), runner, argument_map)
result = runner.result
#assert(result.value.valueName == "Success")

#save the model
output_dir = File.expand_path('output', File.dirname(__FILE__))
#FileUtils.mkdir output_dir unless Dir.exist? output_dir
#output_file_path ="#{output_dir}/test_imported_idf_model_results.osm"),true)
output_file_path ="#{output_dir}/output"),true)
edit flag offensive delete link more


@LSurf thanks for the feedback, the change from MiniTest::Test to MiniTest::Unit::TestCase was a really obnoxious breaking change that Ruby made sometime in the 2.0 series. OpenStudio is now updated to Ruby 2.0.0-p594 and all of the measures in 1.6.0 will be updated to use MiniTest::Unit::TestCase.

macumber's avatar macumber  ( 2015-01-09 10:06:15 -0600 )edit

Your Answer

Please start posting anonymously - your entry will be published after you log in or create a new account.

Add Answer

Training Workshops

Question Tools



Asked: 2014-11-24 09:05:23 -0600

Seen: 878 times

Last updated: Jan 08 '15