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

script for multiple simulations

asked 2015-04-22 11:34:48 -0500

Alex Vlachokostas gravatar image

updated 2015-12-10 10:07:05 -0500

I have 50 idf files and 50 weather files. Each idf file corresponds to a respective epw file. I don't want to simulate them one-by-one on EP launch. Would it be possible to write a script in order to run EP on each idf file with its respective weather file? If yes, what scripting language would you recommend? Are there any available examples?

edit retag flag offensive close merge delete

Comments

Could you clarify if you are talking about 50 simulation where each idf file has one weather file that goes with it or if you are talking about 2500 simulations where each of the 50 idf files are run 50 times with different weather files each time.

JasonGlazer gravatar imageJasonGlazer ( 2015-04-22 15:56:57 -0500 )edit

it's the second case "2500 simulations where each of the 50 idf files are run 50 times with different weather files each time"

Alex Vlachokostas gravatar imageAlex Vlachokostas ( 2015-04-22 16:52:43 -0500 )edit

6 Answers

Sort by ยป oldest newest most voted
8

answered 2015-04-22 12:28:15 -0500

scottb gravatar image

updated 2015-04-23 09:26:47 -0500

If I was on a linux/mac machine I would use bash:

From command line:

for f in *idf; do runenergyplus $f WFILE; done

Where WFILE is the path to your weather file

If you want to run on all IDFs and all EPWs

for f in *idf; for w in *epw; do runenergyplus $f $w; done

You can put this into a script if you want.

This will work on windows too but you will have to install cygwin first.

edit flag offensive delete link more

Comments

Now we're cooking with cygwin!

__AmirRoth__ gravatar image__AmirRoth__ ( 2015-04-23 09:45:21 -0500 )edit
14

answered 2015-04-22 22:21:35 -0500

updated 2015-05-28 15:48:39 -0500

Shell? CYGWIN? EP-Macro? This is 2015!

python>>

for i in glob('*.idf'):
   for w in glob('*.epw'):
      subprocess.call(["EnergyPlus -p %s -w %s %s" % (i[:-len('.idf')] + '_' + w[:-len('.epw')], w, i)])

Good night, drive home safely!

PS Thanks to @scottb for pointer to 'glob' (basically a 'listdir' with regular expressions, like a shell 'ls')!

edit flag offensive delete link more

Comments

1

Shell rules! Look at all the text in this solution...

Consider simplifying your python script using glob('*idf') and glob('*epw'). Cleans things up a bit

scottb gravatar imagescottb ( 2015-04-23 08:19:39 -0500 )edit
1

@scottb, in no particular order: 1. Shell rules? I can't tell from your profile how old you are (or even who you are) but I am guessing you're over 60? See, this is why I ask that people complete their profiles, so that we can smack-talk in more personal detail and in across forums. ;) 2. Your shell answer below doesn't actually produce the requested cross-product of IDFs and EPWs. May want to fix that. ;) ;) 3. Thanks for the python knowledge! Didn't know about it and will certainly use going forward. I do wish 'glob' had a more intuitive name, e.g., 'listdirexp'.

__AmirRoth__ gravatar image__AmirRoth__ ( 2015-04-23 09:03:50 -0500 )edit
2

may need to add

import glob

to the top

JasonGlazer gravatar imageJasonGlazer ( 2015-04-23 09:13:36 -0500 )edit

details details

__AmirRoth__ gravatar image__AmirRoth__ ( 2015-04-23 09:35:10 -0500 )edit

call me old fashioned, but what's wrong with?:

from glob import glob
for f in glob('*idf'):
    for w in glob('*epw'):
        # RUN EPLUS

I mean it's not a one-liner like in shell. But, hey, what the heck. Why wait till you're 60 to start acting wise?

Amir- I know you're joking, but seriously learn shell! There is an old saying: "When the only tool you have is a hammer, everything starts to look like a nail". I am a big python fan, but there are often simpler solutions. Why reinvent a perfectly good wheel?

scottb gravatar imagescottb ( 2015-04-23 09:53:23 -0500 )edit
9

answered 2015-04-22 17:07:40 -0500

You can run each of your 50 IDF files with each of the 50 weather files (2500 total simulations) by using EP-Launch itself. Just go to the Group Input Files tab and press the New Group button. You will select the 50 IDF files on the first screen (you may have to change the path of the files by pressing the path button) then on the next screen select the 50 weather files. Using the Toggle All button is the easiest way to select a large number of files. On the fourth screen you need to select "User Defined Location" and change the location to use a file name that contains the IDF and weather file names (%H\%I_%W) or separate directories for each weather file (%H\%W\%I). Save the group file on the next step and you may want to edit it to make sure it how you want. Then it is as simple as pressing Simulate Group.

I would probably test this approach using three IDF files and three weather files to make sure it is how you want it before you commit to that many simulations.

You might want to review the documentation on EP-Launch.

edit flag offensive delete link more
3

answered 2015-12-16 07:45:14 -0500

Chandan Sharma gravatar image

updated 2015-12-17 05:10:33 -0500

Another simple cross-platform program with GUI to perform EnergyPlus batch simulations can be downloaded from this link. It was tested in Windows 7 and Ubuntu 14.04 (more info in the documentation). I used it for running batch simulations (annual) of 300 DOE reference files which took about 40 hours in my computer. It would be interesting to know how it works for running 2500 simulations. Any feedback or comments are most welcome.

edit flag offensive delete link more

Comments

Thanks for letting us know about this tool.

JasonGlazer gravatar imageJasonGlazer ( 2015-12-16 08:51:05 -0500 )edit

Yes, thanks. Might be a good candidate for GitHub as well.

MatthewSteen gravatar imageMatthewSteen ( 2015-12-16 11:10:48 -0500 )edit

Thank you. Link above now leads to GitHub.

Chandan Sharma gravatar imageChandan Sharma ( 2015-12-17 05:13:37 -0500 )edit
3

answered 2015-12-11 11:29:48 -0500

Nick Caton gravatar image

updated 2016-10-12 19:58:37 -0500

I used Amir's current answer to make a working script for doe22, v48r:

import glob
import subprocess

# Check these environment variables for running doe2 on command line
doe22batlocation = 'C:\doe22\DOE22.BAT'
doe22version = 'EXE48r'

def weatherbatch():
    for i in glob.glob('*.inp'):
        for w in glob.glob('*.BIN'):
            input = i.replace('.inp','')
            weather = w.replace('.BIN','')
            subprocess.call([doe22batlocation, doe22version, input, weather])

weatherbatch()

EDIT (10/12/2016): ... and following is a more developed, current version of the same script. I am retaining the relatively simple example above in this answer to facilitate comparison and clarity of concept for others traversing the bridges between python, doe2, and e+.

I was prompted in the answer commentary to try and make this script compatible when executed directly from notepad++. While I've pushed the module further in form/function, I'm not certain what made previous versions incompatible with notepad++ execution, and I only recently picked up the realization that was possible (I've been used to executing all python efforts to-date from powershell). The following is tested and working using Python 2.7 and the notepad++ plugin called "PyNPP" with the shortcut Alt+Shift+F5.

I was also prompted to get my act together with respect to docstring styling. As a self-learner I appreciate the encouragement, and hopefully this is a little easier on our French friends' sensibilities now =)!

"""Automate batch simulation for any number of doe2 input & weather files."""

import os
import glob
import subprocess
import shutil
import re

# Review these environment variables for running doe2 on command line
doe2_location = 'C:\doe22'
doe2_version = 'EXE48r' #<-- As would be entered for command line execution
doe2bat_location = doe2_location+'\DOE22.BAT' 
doe2_weather_directory = doe2_location+'\weather'

def weatherbatch(target_path):
    """This function will simulate every unique combination possible between a 
    group of co-located weather files (*.bin) and input files (*.inp) via doe2 
    commandline. 

    The argument 'target_path' is the directory containing the weather (*.bin) 
    and input (*.inp) files.

    When finished, BDL files and SIM output files with self-descriptive names 
    to indicate the associated weather / input combination should remain 
    alongside the targeted files.

    Be mindful limits to doe2 command line execution apply to this script as 
    well.  Excessive characters and the presence of any spaces in the input or
    weather file names will result in errors.
    """

    # store current working directory
    start_dir = os.getcwd()

    # move to the target directory containing the weather/input files
    os.chdir(target_path)

    for w in glob.glob('*.BIN'):
        # ensure a copy of the weatherfile exists in the doe2 weather directory
        shutil.copy(w, doe2_weather_directory)

        # strip '.BIN' from w for commandline execution 
        # (done via regex to make this case-insensitive)
        weather = re.sub('\.bin', '', w, flags=re.IGNORECASE)       

        for i in glob.glob('*.inp'):            
            # make a copy of 'Project.inp' called 'Project_in_weatherfile.inp'
            # (done via regex to make this case-insensitive)
            inputname = re.sub('\.inp', '', i, flags=re.IGNORECASE)
            renamedinp = inputname + '_in_' + weather + '.inp'
            shutil.copy(i, renamedinp)  

            # strip '.inp' from renamedinp for commandline execution
            input = renamedinp.replace('.inp','')

            # execute commandline doe2 for this weather + input combination
            subprocess.call ...
(more)
edit flag offensive delete link more

Comments

1

@NickCaton, I think I see a problem with your script. doe22batlocation should be 'C:\EnergyPlus-8-4-0\energyplus'. ;P

__AmirRoth__ gravatar image__AmirRoth__ ( 2015-12-12 10:36:46 -0500 )edit

@__AmirRoth__, that's actually a time saving feature! You can of course adapt this example and run 2500 eplus simulations, but by the time your batch finishes I'll already be clocked out and finishing my first round at the bar ;)!

In all seriousness, I initially wanted to post this as a longer comment to one of the other doe2 responses... But this example exceeds the character limit so I had to start a new answer... Would it make sense to add a 'doe2' tag to the question since both are now addressed in the answers?

Nick Caton gravatar imageNick Caton ( 2015-12-12 14:20:33 -0500 )edit

In general I'd say that we shouldn't. I think that may be stealing the OP's post a little bit, and there's nothing wrong in creating another question ("Batch running multiple simulations in DOE2" or something) and answering it yourself, tutorial style.

In this case there are already two answers regarding DOE2 and I think it's more of a programming question than a simulation one. So I might be ok with it if you want to add a doe-2 tag...

Julien Marrec gravatar imageJulien Marrec ( 2015-12-14 05:29:04 -0500 )edit

@ Nick Caton: is there any pathway in case i call DOE 2 from Notepad++ ?

ngkhanh gravatar imagengkhanh ( 2016-10-11 11:54:31 -0500 )edit

@ ngkhanh : I'm not clear on your question... can you provide more context or information as to the errors you're running into? I should add that to-date I haven't really embraced executing my python scripts directly from notepad++. I always use powershell...

EDIT: I've updated my answer to include a more current, polished version. Looks to be working when executed from notepad++ via the "PyNPP" plugin.

Nick Caton gravatar imageNick Caton ( 2016-10-11 18:39:36 -0500 )edit
3

answered 2015-04-24 07:52:28 -0500

Chris Jones gravatar image

updated 2015-04-24 15:18:30 -0500

I run a bunch of DOE2.1e files against a bunch of weather files using a batch file:

@echo off
setlocal EnableDelayedExpansion  

for %%a in (*.doe) do (
   for %%b in ("weather\*.bin") do (
        call rundoe2 %%a %%b" 

    )
)
edit flag offensive delete link more

Comments

Just fixed the code formatting.

__AmirRoth__ gravatar image__AmirRoth__ ( 2015-04-24 15:18:51 -0500 )edit

Yes. These methods have been around since the 1980's. However, I question the wisdom of having multiple building files. Why not have just a single building file with macros delineating the parametric variations? My rule has always been to reduce the number of input files as much as possible, saves a lot of time and insures consistency between the runs.

Joe Huang gravatar imageJoe Huang ( 2015-09-24 19:29:03 -0500 )edit

Your Answer

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

Add Answer

 

Question Tools

4 followers

Stats

Asked: 2015-04-22 11:34:48 -0500

Seen: 1,095 times

Last updated: Oct 12 '16