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

Revision history [back]

click to hide/show revision 1
initial version

I got something working in python with a few blemishes. Python's recommended subprocess was interfering with multiprocessing, so I had to use the ill advised os instead.

rungroup.py

from multiprocessing import Pool
import os
import time

def run_energyplus_cmd(command_string):
    print('starting ' + command_string)
    start_seconds = time.time()
    os.system(command_string + ' >NUL 2>&1') #concatenated string for suppressing energyplus output
    elapsed_minutes = int((time.time() - start_seconds)/60*100.0)/100.0 #two decimal places
    print(str(elapsed_minutes) + ' min for ' + command_string)

if __name__ == '__main__':
    number_of_simultaneous_simulations = 4

    #read commands.txt and split lines into array
    commands_file = open('commands.txt', 'r')
    commands_array = commands_file.read()
    commands_file.close()
    commands_array = commands_array.splitlines()

    #run all commands in parallel up to number_of_simultaneous_simulations at a time
    with Pool(number_of_simultaneous_simulations) as p:
        p.map(run_energyplus_cmd, commands_array)

    #using energyplus on the command line versus EP-Launch had different output
    #cmd made <idf_name>out.eio but EP-Launch made <idf_name>.eio output files
    #this is to remove all the "out" strings from the output files
    folder = 'runs'
    for filename in os.listdir(folder):
        filename = os.path.join(folder,filename)
        if not os.path.isfile(filename): continue
        new_filename = filename.replace('out.', '.')
        try:
            os.rename(filename, new_filename)
        except WindowsError:
            os.remove(new_filename)
            os.rename(filename, new_filename)


Here is my file organization. Folder "runs" contains all my IDFs, "weather files" contained my EPWs, and commands.txt contains the Windows cmd input. image description

image description

commands.txt

C:/EnergyPlusV9-3-0/energyplus -w "weather files/CZ03/CZ03.epw" -p run0 -d runs runs/run0.idf C:/EnergyPlusV9-3-0/energyplus -w "weather files/CZ03/CZ03.epw" -p run1 -d runs runs/run1.idf C:/EnergyPlusV9-3-0/energyplus -w "weather files/CZ03/CZ03.epw" -p run2 -d runs runs/run2.idf C:/EnergyPlusV9-3-0/energyplus -w "weather files/CZ03/CZ03.epw" -p run3 -d runs runs/run3.idf C:/EnergyPlusV9-3-0/energyplus -w "weather files/CZ03/CZ03.epw" -p run4 -d runs runs/run4.idf

Lastly, the output.

C:\Users\<YOUR NAME>\Desktop\multiprocessing>python rungroup.py
starting C:/EnergyPlusV9-3-0/energyplus -w "weather files/CZ03/CZ03.epw" -p run0 -d runs runs/run0.idf
starting C:/EnergyPlusV9-3-0/energyplus -w "weather files/CZ03/CZ03.epw" -p run1 -d runs runs/run1.idf
starting C:/EnergyPlusV9-3-0/energyplus -w "weather files/CZ03/CZ03.epw" -p run2 -d runs runs/run2.idf
starting C:/EnergyPlusV9-3-0/energyplus -w "weather files/CZ03/CZ03.epw" -p run3 -d runs runs/run3.idf
0.26 min for C:/EnergyPlusV9-3-0/energyplus -w "weather files/CZ03/CZ03.epw" -p run2 -d runs runs/run2.idf
starting C:/EnergyPlusV9-3-0/energyplus -w "weather files/CZ03/CZ03.epw" -p run4 -d runs runs/run4.idf
0.27 min for C:/EnergyPlusV9-3-0/energyplus -w "weather files/CZ03/CZ03.epw" -p run3 -d runs runs/run3.idf
0.27 min for C:/EnergyPlusV9-3-0/energyplus -w "weather files/CZ03/CZ03.epw" -p run0 -d runs runs/run0.idf
0.27 min for C:/EnergyPlusV9-3-0/energyplus -w "weather files/CZ03/CZ03.epw" -p run1 -d runs runs/run1.idf
0.16 min for C:/EnergyPlusV9-3-0/energyplus -w "weather files/CZ03/CZ03.epw" -p run4 -d runs runs/run4.idf

C:\Users\<YOUR NAME>\Desktop\multiprocessing>

image description