6

OpenStudio measure interactive debugging

I am writing my OpenStudio measures and then testing them with some test code like shown in the writing openstudio measures guide.

Everything works fine but the time that the code takes to run can be up to 40 seconds, this means that debugging or testing can take a lot longer than it should.

Is it possible to set up the tests in an interactive environment where code snippets can be run one at a time? So that I only need to run the code that I want to test. Is this what Ruby mine does?

Has anyone done this? Any advice would be most appreciated!

antonszilasi's avatar
1.5k
antonszilasi
asked 2016-12-12 13:13:48 -0500
Julien Marrec's avatar
29.7k
Julien Marrec
updated 2016-12-21 12:12:03 -0500
edit flag offensive 0 remove flag close merge delete

Comments

40 seconds sounds like a long time for a measure to run unless it is a reporting measure that runs EnergyPlus or is doing sizing runs. If it is a reporting measure, you can configure the test to save the simulation results so the test can be re-run quickly. We do have a few model measures that can take that longer than a few seconds but only if they are doing more complex operations or are tested on very large models.

David Goldwasser's avatar David Goldwasser (2016-12-12 16:30:38 -0500) edit

@DavidGoldWasser it is a modified form of the space and construction wizard and it is most certainly taking more than 40 seconds, isn't this to be expected when you are modifying an existing osm model? I've posted the code here:

and the test file can be seen here

antonszilasi's avatar antonszilasi (2016-12-28 11:45:32 -0500) edit
add a comment see more comments

1 Answer

6

you could always run your code bit by bit in interactive ruby. Or save parts of it to a ruby script and run that from terminal. For interactive ruby, irb in the command terminal will take you into ruby. Then:

require 'openstudio'

# Helper to load a model in one line
def osload(path)
  translator = OpenStudio::OSVersion::VersionTranslator.new
  ospath = OpenStudio::Path.new(path)
  model = translator.loadModel(ospath)
  if model.empty?
      raise "Path '#{path}' is not a valid path to an OpenStudio Model.  Did you remember to use backlashes / instead of forward slashes \ ?"
  else
      model = model.get
  end  
  return model
end

load_path = "C:/Users/me/path/to/your/model/with/backslashes.osm"
model = osload(load_path)

and then do whatever modeling you want

mdahlhausen's avatar
9.5k
mdahlhausen
answered 2016-12-12 15:36:58 -0500
edit flag offensive 0 remove flag delete link

Comments

2

This seems like a good place to plug UnmetHours' resident karma kingpin @Julien Marrec's custom OpenStudio Powershell profile (which I haven't used but looks really handy for this stuff).

ericringold's avatar ericringold (2016-12-12 15:52:40 -0500) edit

nice! looking forward to trying that out.

mdahlhausen's avatar mdahlhausen (2016-12-12 16:24:13 -0500) edit

Thanks for the plug @Eric Ringold. If you guys try it and hit some roadblocks, don't hesitate to ping me directly or open a github issue.

Julien Marrec's avatar Julien Marrec (2016-12-21 12:11:41 -0500) edit

@mdahlhausen

it works thanks! a note however make sure you declare model as a global variable otherwise it doesnt show up in the ruby interactive console so change model to $model

antonszilasi's avatar antonszilasi (2016-12-28 14:03:11 -0500) edit
add a comment see more comments