esa / pygmo2

A Python platform to perform parallel computations of optimisation tasks (global and local) via the asynchronous generalized island model.
https://esa.github.io/pygmo2/
Mozilla Public License 2.0
414 stars 56 forks source link

getting the worker id or order inside the problem function during parallelization #136

Closed ShervanGharari closed 1 year ago

ShervanGharari commented 1 year ago

Thank you very much for pygmo.

I would like to use parallelization with pygmo to optimize a problem using an external model. The problem includes input, an exe file, and output from which the objective function(s) is calculated. This means for every worker a copy of the setup should be created and models are simulated and evaluated in parallel.

I was wondering if there are examples to return worker ID inside the problem function so it can be used for folder creation in the case mentioned above.

generally speaking, my problem is in this form:

def problem (x):
    get the id or order of the worker # the question is about this feature
    if the path with the name for the id of the worker does not exist create and copy the setup to the folder.
    execute the exe to get the outputs using parameter x
    calculate the objective function based on output and pass it to pygmo algorithms

I understand that this question is not related to code issues. In that case, I would appreciate it if you direct me to the relevant forum.

Thank you in advance.

ShervanGharari commented 1 year ago

I can perhaps get that information inside the fitness function using python commands such as os.getpid() However, it would be nice to know if there are other options that can help extract the rank to similar information using the pygmo functionality inside the user-defined problem class. I'll close this issue. Thank you.