Question about parallel computation in OpenTurns Pareto frontier optimization

Dear all,

I’m using OpenTurns to compute the Pareto frontier of some problems with two objective (cost) functions. I’ve managed to use it as intended, but I’m struggling with the computational burden. Currently, all runs are executed sequentially, regardless of the population size.

As I understand it, an initial population is generated, and then the next generation is formed by selecting the best individuals from the previous one to perform genetic crossover, and so on. However, I haven’t been able to make use of parallel computation within each population. The blockSize option doesn’t seem to have any effect.

Could you please confirm whether I’ve understood the algorithm correctly? And is there a way to make it more time-efficient by using parallel computing (i.e., evaluating several individuals in parallel)?

Thank you very much for any help.

Best Regards

Hello,

First, check that the Pagmo algorithm you are using supports batch evaluation (“Batch” column of the algorithm tab in the notes section):

Then as you noticed, you must use of the setBlockSize method to send multiple points at once to the function.

Finally, your function must support parallel evaluation, for example by setting the n_cpus option of the PythonFunction (using multiprocessing):

But there are other parallelization options for Python models using the otwrapy or othpc external modules:

j

Hi, I’m coming back on this topic but with a slightly different issue. I found a way to parallelize my function, but now I’d like to save the process and start it again later. I need to save the current state of the optimization but setting the max number of iteration simply to 1 doesn’t exit the *.run() function and it seems that the optimization is going on endless. I can see some convergence while looking at the saved output files of each run, so things are going pretty well inside, but if I kill the process, I also loose the entire convergence knowledge so I cannot stop and resume a studied case… Any idea on how I could handle this ? (chatGPT or other tools seems also useless as *.setMaximumIterationNumber doesn’t seem to do the expected job…)

thanks in advance for any help.

here is an example how you can save the optimization evaluations at each iterations into csv files
if you stop the script during the optimization and rerun it, it will restart from the last completed block

import openturns as ot
from pathlib import Path
import time
import math

def zdt1(X):
    x1, x2 = X
    g = 1.0 + 9.0 * (x1 + x2)
    y = g * (1.0 - math.sqrt(x1 / g))
    time.sleep(0.1)
    print("--", [x1, x2], y)
    return [x1, y]
f = ot.PythonFunction(2, 2, zdt1)
memoize = ot.MemoizeFunction(f)

if Path("input.csv").exists():
    X = ot.Sample.ImportFromCSVFile("input.csv")
    Y = ot.Sample.ImportFromCSVFile("output.csv")
    memoize.addCacheContent(X, Y)

def progress(prog):
    X = memoize.getCacheInput()
    Y = memoize.getCacheOutput()
    X.exportToCSVFile("input.csv")
    Y.exportToCSVFile("output.csv")

problem = ot.OptimizationProblem(memoize)
problem.setBounds(ot.Interval([0.0] * 2, [1.0] * 2))
pop0 = ot.JointDistribution([ot.Uniform(0.0, 1.0)] * 2).getSample(50)
algo = ot.Pagmo(problem, "nsga2", pop0)
algo.setBlockSize(8)
algo.setProgressCallback(progress)
algo.setMaximumIterationNumber(10)
algo.run()

pop1 = algo.getResult().getFinalPoints()
fronts = algo.getResult().getParetoFrontsIndices()
1 Like

I’m surprised about how the output file is appended as it does not seems to correspond to step by step runs (to visualized the convergence process). Am I missing something ?

I’ve got my answer, the order is sorted regarding the cost function. I’ve add some extra files to store and check the iterations. We can close this subject I guess