Skip to content

Initializing models in parallel #28

@missermann

Description

@missermann

Hi!
I want to use pyfmi to simulate individual time steps (with do_step) in EnergyPlus. I recognized that initializing the individual EnergyPlus models takes quite some time. Therefore, I hope to find a way to initialize the models in parallel. If it matters, I am on Ubuntu 16.10 and use Python 3.6. Here is what I want to get done in serial:

fmus        = {}
for id in id_list:
    chdir(fmu_path+str(id))
    fmus[id]  = load_fmu('f_' + str(id)+'.fmu',fmu_path+str(id))
    fmus[id].initialize(start_time,final_time)

The result is a dictionary with ids as key and the models as value: {id1:FMUModelCS1,id2:FMUModelCS1}

I tried multiprocessing:

from   multiprocessing               import Process, Manager
from   pyfmi                         import load_fmu

def ep_intialization(bldg,lproxy):
    fmu         = {}
    final_time  = 60*60*24*7
    start_time  = 0
    chdir(fmu_path+str(bldg))
    fmu[bldg]   = load_fmu('f_' + str(bldg)+'.fmu',fmu_path+str(bldg))
    fmu[bldg].initialize(start_time,final_time)
    lproxy.append(fmu)

if __name__ == '__main__':
    manager = Manager()
    lproxy  = manager.list()
    jobs    = []
    for bldg in osmids_list:
        p   = Process(target=ep_intialization, args=(bldg,lproxy))
        jobs.append(p)
        p.start()
    for j in jobs:
        j.join()

This code sucessfully starts several processes on different cores (see in the system monitor), but when the fmus are dumped in the multiprocessing list, I get a pickling error. The multithreading with python's threading works, but the performance gains are marginal. I already tried different parallel processing/serialization approaches, such as dask, joblib, cloudpickle,pathos,dill, but to no avail.

I am aware that the FMUModels are cython classes, and thus really difficult to serialize. Pyfmi has pyfmi.master.Master which allows parallel simulation but not for FMUModelCS1 and with no do_step. There is an interesting point in the changelog:

— PyFMI-2.3 —
Allow do steps to be performed in parallel (ticket:4541).

However, I couldnt find any other reference.

Any ideas on this issue?

Metadata

Metadata

Assignees

No one assigned

    Labels

    questionIssue only concerns a or multiple questions.

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions