13.9.2. Macro “reoptimizeHollowBarCodeMultiStart.py”
13.9.2.1. Objective
The objective of the macro is to optimize the section of the hollow bar defined in Sizing of a hollow bar example problem using the NLopt solvers (reducing it to a single-criterion optimisation as already explained in Local solver. It is largely based on the previous macro, the main change being the fact that we allow different starting points.
13.9.2.2. Macro Uranie
"""
Example of hollow bar optimisation in multistart mode
"""
import numpy as np
from URANIE import DataServer, Relauncher, Reoptimizer
import ROOT
# variables
x = DataServer.TAttribute("x", 0.0, 1.0)
y = DataServer.TAttribute("y", 0.0, 1.0)
thick = DataServer.TAttribute("thick") # thickness
sect = DataServer.TAttribute("sect") # section of the pipe
dist = DataServer.TAttribute("dist") # distortion
# Creating the TCodeEval, dumping output of the dummy python in an output file
python_exec = "python3"
if ROOT.gSystem.GetBuildArch() == "win64":
python_exec = python_exec[:-1]
code = Relauncher.TCodeEval(python_exec + " bar.py > bartoto.dat")
# Pass the python script itself as input. inputs are modified in bar.py
inputfile = Relauncher.TKeyScript("bar.py")
inputfile.addInput(x, "x")
inputfile.addInput(y, "y")
code.addInputFile(inputfile)
# precise the name of the output file in which to read the three output
outputfile = Relauncher.TFlatResult("bartoto.dat")
outputfile.addOutput(thick)
outputfile.addOutput(sect)
outputfile.addOutput(dist)
code.addOutputFile(outputfile)
# Create a runner
runner = Relauncher.TSequentialRun(code)
runner.startSlave() # Usual Relauncher construction
if runner.onMaster():
# Create the TDS
tds = DataServer.TDataServer("vizirDemo", "Param de l'opt vizir")
tds.addAttribute(x)
tds.addAttribute(y)
# Choose a solver
solv = Reoptimizer.TNloptCobyla()
# solv = Reoptimizer.TNloptBobyqa()
# solv = Reoptimizer.TNloptPraxis()
# solv = Reoptimizer.TNloptNelderMead()
# solv = Reoptimizer.TNloptSubplexe()
# Create the single-objective constrained optimizer
opt = Reoptimizer.TNlopt(tds, runner, solv)
# add the objective
opt.addObjective(sect) # minimizing the section
# and the constrains
constrDist = Reoptimizer.TLesserFit(14)
opt.addConstraint(dist, constrDist) # distortion (dist < 14)
positiv = Reoptimizer.TGreaterFit(0.4)
opt.addConstraint(thick, positiv) # thickness (thick > 0.4)
# Starting point
p1 = np.array([0.9, 0.2])
p2 = np.array([0.7, 0.1])
p3 = np.array([0.5, 0.4])
opt.setStartingPoint(len(p1), p1)
opt.setStartingPoint(len(p2), p2)
opt.setStartingPoint(len(p3), p3)
# Set maximum evaluation
opt.setMaximumEval(1000)
opt.solverLoop() # running the optimization
# Stop the slave processes
runner.stopSlave()
# solution
tds.getTuple().Scan("*", "", "colsize=9 col=:::5:4")
As stated previously, the purpose of this macro is to use different starting points for optimisation fully based on the macro shown in Macro “reoptimizeHollowBarCode.py”. The only difference is highlighted here:
# Starting point
p1 = np.array([0.9, 0.2])
p2 = np.array([0.7, 0.1])
p3 = np.array([0.5, 0.4])
opt.setStartingPoint(len(p1), p1)
opt.setStartingPoint(len(p2), p2)
opt.setStartingPoint(len(p3), p3)
The results of this is that optimisation is performed three times, using the three starting points provided. Here it is done sequentially, but obviously, the main idea is that it is a convenient way to parallelise these optimisation. This could be done for instance, simply by changing the runner line from
runner = Relauncher.TSequentialRun(code)
to, for instance in our case with 3 starting points
runner=Relauncher.TThreadedRun(code,4)
13.9.2.3. Console
This macro leads to the following result
--- Uranie v4.11/0 --- Developed with ROOT (6.36.06)
Copyright (C) 2013-2026 CEA/DES
Contact: support-uranie@cea.fr
Date: Thu Feb 12, 2026
|....:....|....:....|....:....|....:....|....:....0050
|....:....|....:....
|....:....|....:....|....:....0100
|..
..:....|....:....|....:...
***************************************************************************
* Row * vizirDemo * x.x * y.y * thick * sect * dist.dist *
***************************************************************************
* 0 * 0 * 0.5173155 * 0.1173213 * 0.399 * 0.25 * 14.000005 *
* 1 * 1 * 0.5173156 * 0.1173173 * 0.399 * 0.25 * 13.999986 *
* 2 * 2 * 0.5173155 * 0.1173155 * 0.4 * 0.25 * 14 *
***************************************************************************