How to Install Measures to Run Models in Script?

So I’m just getting started with scripting with HB and DF. I’ve experimented building a very simple model and am trying to run it. I’ve written:

osw = to_openstudio_osw('/oswmodel', 
                        model_path=hbjson_loc,
                        epw_file='/mount/weather/USA_IL_Chicago.OHare.Intl.AP.725300_TMYx.epw',
                        additional_measures=['reports'],
                        report_units='ip',
                        schedule_directory='/scheds')

Which returns

AssertionError: OpenStudio report requested but the openstudio_results measure is not installed.

But I’m not sure where/how to install measures.

If I try to avoid installing measures and just run

osw = to_openstudio_osw('/oswmodel', 
                        model_path=hbjson_loc,
                        epw_file='/mount/weather/USA_IL_Chicago.OHare.Intl.AP.725300_TMYx.epw',
                        schedule_directory='/scheds')

It returns (0,0), so I have an error somewhere. But it fails silently. I think the issue is when it try to run the file run_workflow.sh - if I navigate and run that file myself, I get:

 Found error in state 'initialization' with message ["Cannot find measure from_honeybee_model::/ruby/2.7.0/gems/openstudio-workflow-2.3.1/lib/openstudio/workflow/util/measure.rb:155:in `block in validate_measures'\n:/ruby/2.7.0/gems/openstudio-workflow-2.3.1/lib/openstudio/workflow/util/measure.rb:141:in `each'\n:/ruby/2.7.0/gems/openstudio-workflow-2.3.1/lib/openstudio/workflow/util/measure.rb:141:in `each_with_index'\n:/ruby/2.7.0/gems/openstudio-workflow-2.3.1/lib/openstudio/workflow/util/measure.rb:141:in `validate_measures'\n:/ruby/2.7.0/gems/openstudio-workflow-2.3.1/lib/openstudio/workflow/jobs/run_initialization.rb:122:in `perform'\n:/ruby/2.7.0/gems/openstudio-workflow-2.3.1/lib/openstudio/workflow/run.rb:291:in `step'\n:/ruby/2.7.0/gems/openstudio-workflow-2.3.1/lib/openstudio/workflow/run.rb:233:in `run'\n:/openstudio_cli.rb:1067:in `execute'\n:/openstudio_cli.rb:803:in `execute'\n:/openstudio_cli.rb:1855:in `<main>'\neval:186:in `eval'\neval:186:in `require_embedded_absolute'\neval:171:in `block in require_embedded'\neval:165:in `each'\neval:165:in `require_embedded'\neval:124:in `require'\neval:3:in `<main>'"]

So again, it appears I’m not properly installing measures. Any tips or can someone point me in the direction of the documentation for this?

Thank you!

Shoot, I realized I didn’t complete the code; what returns the empty tuple is:

osw = to_openstudio_osw('/oswmodel', 
                        model_path=hbjson_loc,
                        epw_file='/mount/weather/USA_IL_Chicago.OHare.Intl.AP.725300_TMYx.epw',
                        schedule_directory='/scheds')
run_out = run_osw(osw)

Any thoughts here would be appreciated!

Hey @ericoneill ,

I see you are trying to use this method in the honeybee-energy library here and I would recommend not using report_units or additional_measures until you get the method to work correctly in the first place. The method is ectacting actual Measure Python objects as you see here.

Looking at the code, it’s not possible for the to_openstudio_osw command to return (0, 0) so I don’t know what you are referring to here. If you want a good sample for how to use this method, I would check the source code of the “Model To OSM” component:

Hey @chris!

Thank you! I realized that I had mistakenly omitted a section and tried to correct myself in my followup post.

The code that returns (0,0) is

from honeybee_energy.run import run_osw

run_osw(osw)

I agree I shouldn’t use measures until I get the original function working, and that’s what I was trying to do in the second part of my original post.

Once I figure that out, it seems like the measures should be pretty straightforward. Something like:

from honeybee_energy import measure

measure_1 = measure("path/to/measure_1")
measure_2 = measure("path/to/measure_2")
measures = [measure_1, measure 2]

Which then can be passed into the addtional_measures parameter of to_openstudio_osw, I’m assuming, correct?

If so, that makes sense, and I’d love to get feedback on why run_osw(osw) returns (0,0).

Thanks!
Eric

It’s still not possible to get (0, 0) out of that function but you can get (None, None) and so I imagine that is what you mean.

You will get (None, None) if running the OSW failed and you should check the .log file in the input osw_json’s folder to see why OpenStudio CLI failed.

And, yes, that is how you add additional measures except that the class is called Measure (with a capital M) instead of 'measure`.

Ah, yes, sorry, (None, None) is what that returns.

run.log contains the same output from the run_workflow.sh file I included above:

[08:30:14.175866 ERROR] Found error in state 'initialization' with message ["Cannot find measure from_honeybee_model::/ruby/2.7.0/gems/openstudio-workflow-2.3.1/lib/openstudio/workflow/util/measure.rb:155:in `block in validate_measures'\n:/ruby/2.7.0/gems/openstudio-workflow-2.3.1/lib/openstudio/workflow/util/measure.rb:141:in `each'\n:/ruby/2.7.0/gems/openstudio-workflow-2.3.1/lib/openstudio/workflow/util/measure.rb:141:in `each_with_index'\n:/ruby/2.7.0/gems/openstudio-workflow-2.3.1/lib/openstudio/workflow/util/measure.rb:141:in `validate_measures'\n:/ruby/2.7.0/gems/openstudio-workflow-2.3.1/lib/openstudio/workflow/jobs/run_initialization.rb:122:in `perform'\n:/ruby/2.7.0/gems/openstudio-workflow-2.3.1/lib/openstudio/workflow/run.rb:291:in `step'\n:/ruby/2.7.0/gems/openstudio-workflow-2.3.1/lib/openstudio/workflow/run.rb:233:in `run'\n:/openstudio_cli.rb:1067:in `execute'\n:/openstudio_cli.rb:803:in `execute'\n:/openstudio_cli.rb:1855:in `<main>'\neval:186:in `eval'\neval:186:in `require_embedded_absolute'\neval:171:in `block in require_embedded'\neval:165:in `each'\neval:165:in `require_embedded'\neval:124:in `require'\neval:3:in `<main>'"]}

For more context, I’m running this all in a container built on the OpenStudio docker base image. My actual codebase with the ipynb file is here:

Ah, that’s probably why you have this issue, then. It looks like your docker image does not have the measures of the honeybee-openstudio-gem installed in it and so OpenStudio CLI complains. Why not just use the honeybee-energy docker image instead, which has all of the honeybee-energy Python libraries, the honeybee-openstudio-gem and a compatible copy of OpenStudio:

https://hub.docker.com/r/ladybugtools/honeybee-energy/

… plus it’s a lot smaller than the OpenStudio docker image as we’ve trimmed out a lot of the parts of the OpenStudio image that have specialized use-cases.

1 Like

Hey @chris - I appologize for the long delay, but I had just started to get around to trying this out. It does seem like a good solution, but it leads me to running into a new issue:

I’ve tried to chmod myself permissions (to both myself as well as the ladybugbot user) in the docker build file to no avail.

I’m running a jupyter notebook from docker with the following command:

docker run --rm -it -p 8888:8888 -v ${PWD}:/mount lbt jupyter notebook --ip 0.0.0.0 --no-browser --allow-root

And my docker file looks like:

FROM ladybugtools/honeybee-energy:latest

RUN pip3 install --upgrade pip

WORKDIR /pypip
ADD requirements.txt .
RUN pip3 install -r requirements.txt

WORKDIR /mount

I know enough docker to be dangerous, but it’s got me a bit stuck here. Any suggestions?

Thank you!
Eric