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

How to set different working directories for parallel simulations?

asked 2019-10-24 01:20:48 -0500

scrox's avatar

updated 2019-11-27 21:59:06 -0500


I want to run simultaneously multiple simulations. The problem is that every simulation exports its files to the same folder, "Output_EPExport_Slave", in the current working directory. It therefore overwrites variables.cfg file and the first simulation fails since it cannot find the corresponding variables.

Is there are way to set different working directories? In my code you can see a work-around. I would like to avoid that. The different folder paths in the load_fmu seems not to set the working directory. Not sure whether that is a Energyplus or PyFMI problem.

from   pyfmi import load_fmu,fmi
import numpy as np
import os      
model1_fmu  = 'file1.fmu'
model2_fmu  = 'file2.fmu'
model1_path = 'path'
model2_path = 'path'
model1      = load_fmu(model1_fmu,model1_path)
model2      = load_fmu(model2_fmu,model2_path)
final_time  = 60*60*24*3
step_size   = 60*10
start_time  = 0
t_step      = start_time
res_heat1 = []
res_heat2 = []
while t_step < final_time:
    temperature = 15.
    shading     = 6
    model2.set('yShade', shading)
    status1 = model1.do_step(current_t=t_step, step_size=step_size)
    status2 = model2.do_step(current_t=t_step, step_size=step_size)
    print('Status: ',status1,' ',status2)


    t_step += step_size
edit retag flag offensive close merge delete


I know it is not what you are looking for, but you could run two different python instances pointing two different folders: you could avoid all those "chdir" commands.

Gio's avatar Gio  ( 2019-10-25 01:43:30 -0500 )edit

that is possible, maybe with acron in linux. but it would make the simulation set-up not easier and I would lose central steering options with PyFMI

scrox's avatar scrox  ( 2019-10-27 00:29:04 -0500 )edit

1 Answer

Sort by ยป oldest newest most voted

answered 2019-11-25 07:39:08 -0500

updated 2021-08-11 13:04:08 -0500

The output folder of an EnergyplusFMU is defined as Output_EPExport_+ the FMU instanceName (e.g. Output_EPExport_Slave1, Output_EPExport_Slave2). In a co-simulation scenario, the instanceName of an FMU is supposed to be unique across the FMUs. So if your FMUs have unique instance names then, their outputs should be written in different folders.

Addition when using pyFMI as the master simulator:

PyFMI doesn't seem to propagate the instanceName to the FMU when using the load_fmu() function. This leads the the challenges observed.

A workaround would be to load the FMU and then call the instantiate() function of PyFMI. This function can get as an argument the FMU instanceName. A potential implementation would look like this:

# The next line loads the FMU
model  = load_fmu('nameOfFMU.fmu')
# The next line passes the instance name to the FMU
# You could then proceed with the `initialize()` method as done earlier

By adding the instantiate() method in the loop, you would avoid overriding the output directory folders

edit flag offensive delete link more


Unfortunately, I cannot concur. Although my fmu files have unique names (there was a mistake in the example, sorry), the load_fmu function of pyfmi only creates a 'Output_EPExport_Slave' folder in the working directory. It neither creates a 'Output_EPExport_file1' nor a 'Output_EPExport_file2'. The function get_identifier() also provides me with different names.

scrox's avatar scrox  ( 2019-11-27 22:17:19 -0500 )edit

This sounds to me like a potential PyFMI issue then. The fmiInstantiateSlave() function of EnergyPlusToFMU gets the instanceName from the master as argument of the fmiInstantiateSlave(). It then uses that name to write a unique Output folder. Now the question will be to know the string which is passed to the function by PyFMI. If PyFMI doesn't pass the correct instanceName then the FMU will not be able to write a unique folder...You may want to check with PyFMI and figure out the string which is passed asinstanceName at the invocation of fmiInstantiateSlave().

Thierry Nouidui's avatar Thierry Nouidui  ( 2019-11-27 23:42:50 -0500 )edit

Hi there, @scrox, have you made any progress here? I am currently having the same issue and would be interested in any updates. Thanks.

AGeissler's avatar AGeissler  ( 2021-08-11 11:13:05 -0500 )edit

I have updated my answer. This may be helpful for you.

Thierry Nouidui's avatar Thierry Nouidui  ( 2021-08-11 13:03:33 -0500 )edit

Thank you, Thierry! That helped a lot, now the "parallel run of two instances problem" also seems to be solved. A small caveat (with hopefully no side effects, I haven't been able to do extensive tests, yet) is that a third folder with the "original" name is still created. This only contains a few files, though (one .log, and one variables.cfg). My impression would be that there could be timing or sequence-of-events issues. I will do some further tests.

AGeissler's avatar AGeissler  ( 2021-08-12 00:48:19 -0500 )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: 2019-10-24 01:20:48 -0500

Seen: 384 times

Last updated: Aug 16 '21