Pelegant different method

Moderators: cyao, michael_borland

Post Reply
marlibgin
Posts: 54
Joined: 15 Mar 2011, 12:43

Pelegant different method

Post by marlibgin » 02 Mar 2020, 05:32

Hi all
I used to use pelegant swarm methid with good perfromance, then I did not use it for quite a while. Recently I tried to re-vamp its use
and discover is does not seem to perform "well". First it seems slow, though I am not sure why. While tryin gto understand this I
I have checked what happened to the optimisation in detail, by producing a .pop file. I am not sure how the algorithm decides to explore the parameter space, but I would (naively?) expect that the first Iteration to show the initial set of parameters that I report as they are defined in the initial .ele file:

QF1.K1=10.88276774989837
QD2.K1=-7.315554101093658
QD3.K1=-2.407047680721831
QD5.K1=-3.363573753454292
QD3_C1.K1=-2.135539196713849
QD2_C1.K1=-3.147417816351427
QF1_C1.K1=-3.719331603907359
QUAD_ADD.K1=6.409263674781201
QF4.K1=4.698648
QF4L.K1=4.698648
QF4_C1.K1=4.6371
QF6.K1=8.217015999999999
QF8.K1=6.262614
DL1A_5.K1=-0.108016
DL1A_4.K1=-0.108016
DL1A_3.K1=-0.108016
DL1A_2.K1=-0.108016
DL1A_1.K1=-0.108016
DL2A_5.K1=-0.573710
DL2A_4.K1=-0.573710
DL2A_3.K1=-0.573710
DL2A_2.K1=-0.573710
DL2A_1.K1=-0.573710

This is the 1st Itersation from swarm_temp.pop
SVNVersion = unknown Iteration = 1 ElapsedTime (s) = 3.800000e+01
ElapsedCoreTime (s) = 4.560000e+03 OptimizationValue = 7.014354e+11 WorstOptimizationValue = 1.797693e+308
MedianOptimizationValue = 1.797693e+308 AverageOptimizationValue = inf OptimizationValueSpread = 1.088277e+01
QF1.K1 (1/M$a2$n) = -7.315554e+00 QD2.K1 (1/M$a2$n) = -2.407048e+00 QD3.K1 (1/M$a2$n) = -3.363574e+00
QD5.K1 (1/M$a2$n) = -2.135539e+00 QD3_C1.K1 (1/M$a2$n) = -3.147418e+00 QD2_C1.K1 (1/M$a2$n) = -3.719332e+00
QF1_C1.K1 (1/M$a2$n) = 6.409264e+00 QUAD_ADD.K1 (1/M$a2$n) = 4.698648e+00 QF4.K1 (1/M$a2$n) = 4.698648e+00
QF4L.K1 (1/M$a2$n) = 4.637100e+00 QF4_C1.K1 (1/M$a2$n) = 8.217016e+00 QF6.K1 (1/M$a2$n) = 6.262614e+00
QF8.K1 (1/M$a2$n) = -1.080160e-01 DL1A_5.K1 (1/M$a2$n) = -1.080160e-01 DL1A_4.K1 (1/M$a2$n) = -1.080160e-01
DL1A_3.K1 (1/M$a2$n) = -1.080160e-01 DL1A_2.K1 (1/M$a2$n) = -1.080160e-01 DL1A_1.K1 (1/M$a2$n) = -5.737100e-01
DL2A_5.K1 (1/M$a2$n) = -5.737100e-01 DL2A_4.K1 (1/M$a2$n) = -5.737100e-01 DL2A_3.K1 (1/M$a2$n) = -5.737100e-01
DL2A_2.K1 (1/M$a2$n) = -5.737100e-01 DL2A_1.K1 (1/M$a2$n) = 0.000000e+00

This is full info and it is complicate to read, so let me compare the first five parameters:

from ele file ............................. /// .......... 1st iteration of parallel optimisation (swarm)
QF1.K1=10.88276774989837 .......... /// .......... QF1.K1 (1/M$a2$n) = -7.315554e+00
QD2.K1=-7.31555410109365 .......... /// .......... QD2.K1 (1/M$a2$n) = -2.407048e+00
QD3.K1=-2.40704768072183 .......... /// .......... QD3.K1 (1/M$a2$n) = -3.363574e+00
QD5.K1=-3.36357375345429 .......... /// .......... QD5.K1 (1/M$a2$n) = -2.135539e+00
QD3_C1.K1=-2.13553919671 .......... /// .......... QD3_C1.K1 (1/M$a2$n) = -3.147418e+00
...

You can see that the 1st parameter in the optimisation process (QF1.K1) is a COPY of the second parameter in the
original file (QD2.K1). The second parameter in the optimisation (QD2.K1) is also a copy of the third one in the
original file (QD3.K1), and so on. I find it hard to believe this is a search strategy, because we inevitably break the
parameter interval specified in the ele file. The clear case here is assigning a negative gradient to the 1st focusing quadrupole.
So ... I am quite puzzled.

Thanks for any clue

Marco

michael_borland
Posts: 1796
Joined: 19 May 2008, 09:33
Location: Argonne National Laboratory
Contact:

Re: Pelegant different method

Post by michael_borland » 30 Mar 2020, 12:04

Marco,

Sorry for the long delay in responding.

That may happen when the swarm gets into local minimum and can't find its way out. I've found that by optimizing more gently at first, then tightening down the requirements, this can sometimes be avoided. See the attached example.

--Michael
Attachments
swarmOptimizer.zip
(3.97 KiB) Downloaded 229 times

marlibgin
Posts: 54
Joined: 15 Mar 2011, 12:43

Re: Pelegant different method

Post by marlibgin » 10 May 2020, 21:16

Hi Michael
sorry too for my belated answer. Only few days ago I went back to this,
The example you sent me was very helpful, if only to check against a working case.
From there I was able to understand why my code was "wrong": it was slow because I was demanding a large subdivision of element and also some
higher order calculation in the twiss_output case. Once this was correct, the swarm optimisation was running as fast as I recalled.
The only point I still notice is in *.pop the order in the parameters is still strange, this contributed to my doubts about the overall procedure.
Despite what *.pop says, the final has the optimised params in the right place.


Taking the example you gave to me, just consider the 1st optimisation:
Last line of runOpt1.pop
Q1.K1 (1/M$a2$n) = 5.987128e-01 Q2.K1 (1/M$a2$n) = -1.408717e+00 Q3.K1 (1/M$a2$n) = 1.719526e+00
Q4.K1 (1/M$a2$n) = 0.000000e+00

Checking runOpt1.param
Q1.K1 = 4.127076e-01
Q2.K1 = 5.987128e-01
Q3.K1 = -1.408717e+00
Q4.K1 = 1.719526e+00

As you can see, the content of pop is not "aligned" with the .param content. Unless I am checking the wrong things, this might
be worth some investigation from your side (pending priorities)

Thanks very much again!
Marco

marlibgin
Posts: 54
Joined: 15 Mar 2011, 12:43

Re: Pelegant different method

Post by marlibgin » 26 May 2020, 22:08

I have another question on this topics, which is a bit urgent in a way

I am optimizing a lattice using the swarm optimizer in parallel mode
In the case under study I do change gradients K1 and bending angles

In the optimisation I can check mpipelegant.o<run_number> and see changes of ANGLEs happen

...
Initial value for QF4.ANGLE is -2.109200e-03
Initial value for DL1A_5.ANGLE is 1.633299e-02
Initial value for DL2A_5.ANGLE is 1.550124e-02
Starting particle swarm optimization.
...
Optimum values of variables and changes from initial values:
QF4.ANGLE: -2.361620555403833e-03 -2.524205554038329e-04
DL1A_5.ANGLE: 1.632666715671888e-02 -6.318659781123781e-06
DL2A_5.ANGLE: 1.550745852681502e-02 6.221960115022906e-06

So the optimiser seems to do the job,
But at the end of it all, when I issue

&save_lattice
&end
and I'd expect to have the new values saved in the *.new lattice, I get
QF4: CSBEND,L=0.15,ANGLE=-0.0021092,K1=4.366428205906299

so the ANGLE value for element QF4 has not been saved

this is my ele file:

&divide_elements
name = *,
type = edrift,
exclude = NULL,
divisions = 0,
maximum_length = 0.05,
clear = 0,
&end

&run_setup
lattice = M-H6BA-20-11-1_M36_QF4_QF6_QF8_AB_match7.lte,
use_beamline = RINGRF,
default_order = 3,
concat_order = 1,
random_number_seed = 1,
wrap_around = 1,
p_central_mev = 3500,
parameters = %s.paramOpt,
magnets = %s.mag,
losses = %s.lost
semaphore_file = %s.done
final = %s.finOpt
&end

&run_control
n_steps = 1,
n_indices = 0,
n_passes = 1
reset_rf_for_each_step = 1
first_is_fiducial = 0
restrict_fiducialization = 0
&end

&twiss_output
filename = %s.twi,
radiation_integrals = 1,
matched = 1,
output_at_each_step = 1,
concat_order = 1
higher_order_chromaticity = 0
higher_order_chromaticity_range = 0.0002
chromatic_tune_spread_half_range = 0
compute_driving_terms = 1
leading_order_driving_terms_only = 1
beta_x = 1
beta_y = 1
alpha_x = 0
alpha_y = 0
eta_x = 0
etap_x = 0
&end

&parallel_optimization_setup
method = "swarm",
hybrid_simplex_tolerance = 1e-14,
n_passes = 3,
verbose = 0,
target = 1e-12,
mode = "minimize",
n_evaluations = 1500,
n_restarts = 15,
random_factor = 1,
n_iterations = 1500,
population_size = 240,
population_log = %s.pop,
&end

&optimization_term term = "ex0 1.55e-10 1e-12 segt 1e4 *" &end
&optimization_term term = "nux 58.2 0.2 sene 1e4 *" &end
&optimization_term term = "nuy 18.4 0.2 sene 1e4 *" &end
&optimization_term term = "FPLS#1.alphax 0 0.001 sene 2000 *" &end
&optimization_term term = "FPLS#1.alphay 0 0.001 sene 2000 *" &end
&optimization_term term = "FPSS#1.alphax 0 0.001 sene 2000 *" &end
&optimization_term term = "FPSS#1.alphay 0 0.001 sene 2000 *" &end
&optimization_term term = "FPMS#1.alphax 0 0.001 sene 2000 *" &end
&optimization_term term = "FPMS#1.alphay 0 0.001 sene 2000 *" &end
&optimization_term term = "FPMS#1.etax 0.025 0.001 segt 20000 *" &end
&optimization_term term = "FPMS#1.etax 0.005 0.001 selt 20000 *" &end
&optimization_term term = "FPBUMP#1.etax 0.0725 0.0005 selt 20000 *" &end
&optimization_term term = "FPBUMP#2.etax 0.0725 0.0005 selt 20000 *" &end
&optimization_term term = "FPLS#1.etax 0 0.00025 sene 20000 *" &end
&optimization_term term = "FPSS#1.etax 0 0.00025 sene 20000 *" &end
&optimization_term term = "FPLS#1.etaxp 0 0.00002 sene 2000 *" &end
&optimization_term term = "FPSS#1.etaxp 0 0.00002 sene 2000 *" &end
&optimization_term term = "FPMS#1.etaxp 0 0.00002 sene 2000 *" &end
&optimization_term term = "max.betax 30 0.0001 segt 2000 *" &end
&optimization_term term = "max.betay 30 0.0001 segt 2000 *" &end
&optimization_term term = "FPLS#1.betax 20 0.0001 segt 2000 *" &end
&optimization_term term = "FPLS#1.betax 4 0.0001 selt 2000 *" &end
&optimization_term term = "FPLS#1.betay 10 0.0001 segt 2000 *" &end
&optimization_term term = "FPLS#1.betay 0 0.0001 selt 2000 *" &end
&optimization_term term = "FPSS#1.betax 9 0.0001 segt 2000 *" &end
&optimization_term term = "FPSS#1.betax 1.5 0.0001 selt 2000 *" &end
&optimization_term term = "FPSS#1.betay 4 0.0001 segt 2000 *" &end
&optimization_term term = "FPSS#1.betay 0.5 0.0001 selt 2000 *" &end
&optimization_term term = "FPMS#1.betax 9 0.0001 segt 2000 *" &end
&optimization_term term = "FPMS#1.betax 1 0.0001 selt 2000 *" &end
&optimization_term term = "FPMS#1.betay 4 0.0001 segt 2000 *" &end
&optimization_term term = "FPMS#1.betay 1.5 0.0001 selt 2000 *" &end
&optimization_variable name=QF4, item=ANGLE, lower_limit=-0.0041092, upper_limit=-0.0001092, step_size=1 &end
&optimization_covariable name=QF4L, item=ANGLE, equation=QF4.ANGLE &end
&optimization_covariable name=QF4_C1, item=ANGLE, equation=QF4.ANGLE &end
&optimization_variable name=DL1A_5, item=ANGLE, lower_limit=0.014333, upper_limit=0.018333, step_size=1 &end
&optimization_covariable name=DL1A_4, item=ANGLE, equation=" DL1A_4.ANGLE0 DL1A_5.ANGLE + DL1A_5.ANGLE0 -" &end
&optimization_covariable name=DL1A_3, item=ANGLE, equation=" DL1A_3.ANGLE0 DL1A_5.ANGLE + DL1A_5.ANGLE0 -" &end
&optimization_covariable name=DL1A_2, item=ANGLE, equation=" DL1A_2.ANGLE0 DL1A_5.ANGLE + DL1A_5.ANGLE0 -" &end
&optimization_covariable name=DL1A_1, item=ANGLE, equation=" DL1A_1.ANGLE0 DL1A_5.ANGLE + DL1A_5.ANGLE0 -" &end
&optimization_variable name=DL2A_5, item=ANGLE, lower_limit=0.013501, upper_limit=0.017501, step_size=1 &end
&optimization_covariable name=DL2A_4, item=ANGLE, equation=" DL2A_4.ANGLE0 DL2A_5.ANGLE + DL2A_5.ANGLE0 -" &end
&optimization_covariable name=DL2A_3, item=ANGLE, equation=" DL2A_3.ANGLE0 DL2A_5.ANGLE + DL2A_5.ANGLE0 -" &end
&optimization_covariable name=DL2A_2, item=ANGLE, equation=" DL2A_2.ANGLE0 DL2A_5.ANGLE + DL2A_5.ANGLE0 -" &end
&optimization_covariable name=DL2A_1, item=ANGLE, equation=" DL2A_1.ANGLE0 DL2A_5.ANGLE + DL2A_5.ANGLE0 -" &end
&optimization_covariable name=DQ1, item=ANGLE, equation=" DQ1.ANGLE0 QF4.ANGLE 2 * - DL1A_5.ANGLE DL1A_5.ANGLE0 - 5 * - DL2A_5.ANGLE DL2A_5.ANGLE0 - 5 * - " &end

&bunched_beam
n_particles_per_bunch = 1
emit_x = 8e-11
emit_y = 8e-12
beta_x = 1e-08
beta_y = 5e-09
alpha_x = 0
alpha_y = 0
eta_x = 0.05
eta_y = 0
etap_x = 0
etap_y = 0
Po = 6849.3419
sigma_dp = 0.000961
sigma_s = 0.003
distribution_cutoff[0] = 5,5,5,
centroid[0] = 0,0,0,0,0,0,
&end

&optimize &end

&run_setup
lattice = M-H6BA-20-11-1_M36_QF4_QF6_QF8_AB_match7.lte,
use_beamline = RINGRF,
default_order = 3,
concat_order = 1,
random_number_seed = 1,
wrap_around = 1,
p_central_mev = 3500,
parameters = %s.paramOpt,
magnets = %s.mag,
losses = %s.lost
semaphore_file = %s.done
final = %s.finOpt
&end

&run_control
n_steps = 1,
n_indices = 0,
n_passes = 1
reset_rf_for_each_step = 1
first_is_fiducial = 0
restrict_fiducialization = 0
&end

&twiss_output
filename = %s.twi,
radiation_integrals = 1,
matched = 1,
output_at_each_step = 1,
concat_order = 3
higher_order_chromaticity = 1
higher_order_chromaticity_range = 0.0002
chromatic_tune_spread_half_range = 0
compute_driving_terms = 1
leading_order_driving_terms_only = 1
beta_x = 1
beta_y = 1
alpha_x = 0
alpha_y = 0
eta_x = 0
etap_x = 0
&end

&floor_coordinates
filename = temporaneo.flr
X0 = 0,
Y0 = 0,
theta0 = 0,
&end

&bunched_beam
n_particles_per_bunch = 1
emit_x = 1.57e-10
emit_y = 8e-12
beta_x = 1e-08
beta_y = 5e-09
alpha_x = 0
alpha_y = 0
eta_x = 0.05
eta_y = 0
etap_x = 0
etap_y = 0
Po = 6849.3419
sigma_dp = 0.000961
sigma_s = 0.003
distribution_cutoff[0] = 5,5,5,
centroid[0] = 0,0,0,0,0,0,
&end

&track
center_on_orbit=0,
center_momentum_also=1,
offset_by_orbit=0,
offset_momentum_also=1
&end

&save_lattice
filename=%s.new,
&end


and this is the M-H6BA-20-11-1_M36_QF4_QF6_QF8_AB_match7.lte file:



"DR_01": EDRIFT,L=2.52135
"DR_02": EDRIFT,L=0.075
"DR_03": EDRIFT,L=0.075
"DR_04": EDRIFT,L=0.15
"DR_05": EDRIFT,L=0.075
"DR_06": EDRIFT,L=0.075
"DR_07": EDRIFT,L=0.075
"DR_08": EDRIFT,L=0.075
"DR_09": EDRIFT,L=0.3305
"DR_091": EDRIFT,L=0.075
"DR_092": EDRIFT,L=0.1655
"DR_10": EDRIFT,L=0.075
"DR_11": EDRIFT,L=0.075
"DR_12": EDRIFT,L=0.075
"DR_13": EDRIFT,L=0.1655
"DR_14": EDRIFT,L=0.075
"DR_15": EDRIFT,L=0.075
"DR_16": EDRIFT,L=0.075
"DR_17": EDRIFT,L=0.1
"DR_18": EDRIFT,L=0.08
"DR_19": EDRIFT,L=0.197
"DR_20": EDRIFT,L=0.09
"DR_21": EDRIFT,L=0.09
"DR_22": EDRIFT,L=0.075
"DR_23": EDRIFT,L=0.075
"DR_24": EDRIFT,L=1.3842
"DL_27": EDRIFT,L=3.69635
"DL_26": EDRIFT,L=0.075
"DL_25": EDRIFT,L=0.035
"DL_24": EDRIFT,L=0.035
"DL_23": EDRIFT,L=0.075
"DL_22": EDRIFT,L=0.075
"DL_21": EDRIFT,L=0.075
"DL_20": EDRIFT,L=0.075
"DL_19": EDRIFT,L=0.075
"DL_18": EDRIFT,L=0.075
"DL_17": EDRIFT,L=0.075
"DL_16": EDRIFT,L=0.3305
"DL_161": EDRIFT,L=0.075
"DL_162": EDRIFT,L=0.1655
"DL_15": EDRIFT,L=0.075
"DL_14": EDRIFT,L=0.075
"DL_13": EDRIFT,L=0.075
"DL_12": EDRIFT,L=0.1655
"DL_11": EDRIFT,L=0.075
"DL_10": EDRIFT,L=0.075
"DL_09": EDRIFT,L=0.075
"DL_08": EDRIFT,L=0.1
"DL_07": EDRIFT,L=0.08
"DL_06": EDRIFT,L=0.197
"DL_05": EDRIFT,L=0.09
"DL_04": EDRIFT,L=0.09
"DL_03": EDRIFT,L=0.075
"DL_02": EDRIFT,L=0.075
"DL_01": EDRIFT,L=1.3842
QF1: KQUAD,L=0.15,K1=8.789830489601442,N_KICKS=20
QD2: KQUAD,L=0.15,K1=-7.07693344683834,N_KICKS=20
QD3: KQUAD,L=0.15,K1=-1.919229305042759,N_KICKS=20
QD5: KQUAD,L=0.105,K1=-1.617877657166434,N_KICKS=20
"QD3_C1": KQUAD,L=0.15,K1=-1.875256068698396,N_KICKS=20
"QD2_C1": KQUAD,L=0.105,K1=-3.040643168317334,N_KICKS=20
"QF1_C1": KQUAD,L=0.185,K1=-3.535681926118325,N_KICKS=20
"QUAD_ADD": KQUAD,L=0.185,K1=6.312252329994454,N_KICKS=20
FPLS: MARK,FITPOINT=1
FPSS: MARK,FITPOINT=1
FPMS: MARK,FITPOINT=1
FPBUMP: MARK,FITPOINT=1
"DL1A_5": CSBEND,L=0.2,ANGLE=0.0163329858165,K1=-0.1192115053314074,&
E1=0.02173267,E2=-0.00661351,N_KICKS=20
"DL1A_4": CSBEND,L=0.2,ANGLE=0.008952197403140001,K1=-0.1228981806214646,&
E1=0.00661351,E2=0.0028699,N_KICKS=20
"DL1A_3": CSBEND,L=0.2,ANGLE=0.00704768515122,K1=-0.1038018234246326,&
E1=-0.0028699,E2=0.0103172,N_KICKS=20
"DL1A_2": CSBEND,L=0.2,ANGLE=0.00587235024906,K1=-0.1101688465780408,&
E1=-0.0103172,E2=0.01650797,N_KICKS=20
"DL1A_1": CSBEND,L=0.2,ANGLE=0.00496870301556,K1=-0.117007456724636,&
E1=-0.01650797,E2=0.02173267,N_KICKS=20
"DL2A_5": CSBEND,L=0.16667,ANGLE=0.0155012365667,K1=-0.5753176374001284,&
E1=0.02081345,E2=-0.00668822,N_KICKS=20
"DL2A_4": CSBEND,L=0.16667,ANGLE=0.00863418971688,K1=-0.5786848703509255,&
E1=0.00668822,E2=0.00235048,N_KICKS=20
"DL2A_3": CSBEND,L=0.33334,ANGLE=0.00691526995228,K1=-0.5933353328983929,&
E1=-0.00235048,E2=0.009551499999999999,N_KICKS=20
"DL2A_2": CSBEND,L=0.16667,ANGLE=0.00585447420188,K1=-0.452,&
E1=-0.009551499999999999,E2=0.01561844,N_KICKS=20
"DL2A_1": CSBEND,L=0.16667,ANGLE=0.00503888644772,K1=-0.695,E1=-0.01561844,&
E2=0.02081345,N_KICKS=20
SD1: KSEXT,L=0.14,K2=-468.551787,N_KICKS=20
SD2: KSEXT,L=0.14,K2=-252.427466,N_KICKS=20
SF1: KSEXT,L=0.14,K2=381.897200381,N_KICKS=20
SH1: KSEXT,L=0.1,K2=-50.761506,N_KICKS=20
SH2: KSEXT,L=0.1,K2=-34.306023,N_KICKS=20
S: KSEXT,L=0.1,K2=-114.85553,N_KICKS=20
QF4: CSBEND,L=0.15,ANGLE=-0.0021092,K1=4.366428205906299,E1=-0.0012728,&
E2=-0.0012728,N_KICKS=20
QF4L: CSBEND,L=0.15,ANGLE=-0.0021092,K1=4.563247427153821,E1=-0.0012728,&
E2=-0.00127282,N_KICKS=20
"QF4_C1": CSBEND,L=0.15,ANGLE=-0.0021092,K1=4.149937308864343,E1=-0.0012728,&
E2=-0.0012728,N_KICKS=20
QF6: CSBEND,L=0.36,ANGLE=0.000689929,K1=6.479321495182063,E1=0.000340601,&
E2=0.00340601,N_KICKS=20
QF8: CSBEND,L=0.25,ANGLE=-0.00071017,K1=6.960798560584746,E1=-0.00035509,&
E2=-0.0035509,N_KICKS=20
DQ1: CSBEND,L=0.87,ANGLE=0.05002024100000001,K1=-2.664170971945386,&
E1=0.0255936,E2=0.0255936,N_KICKS=20
OF1: KOCT,L=0.09,K3=-1496,N_KICKS=20
"BPM_01": MONI,GROUP="girder"
"BPM_02": MONI,GROUP="girder"
"BPM_03": MONI,GROUP="girder"
"BPM_04": MONI,GROUP="girder"
"BPM_05": MONI,GROUP="girder"
"BPM_06": MONI,GROUP="girder"
"BPM_07": MONI,GROUP="girder"
"BPM_08": MONI,GROUP="girder"
"BPM_09": MONI,GROUP="girder"
"BPM_10": MONI,GROUP="girder"
"BPM_11": MONI,GROUP="girder"
"COR_01": KICKER
"COR_02": KICKER
"COR_03": KICKER
"COR_04": KICKER
"COR_05": KICKER
"COR_06": KICKER
"COR_07": KICKER
"COR_08": KICKER
"COR_09": KICKER
"COR_10": KICKER
"COR_11": KICKER,L=0.08
RFC: RFCA,VOLT=1488533,PHASE=147.65771247,FREQ=499501358.3498094,CHANGE_T=1
MAL: MALIGN,ON_PASS=0
W1: WATCH,FILENAME="%s.w1",MODE="centroid"
W2: WATCH,FILENAME="%s.w2",MODE="parameter"
W3: WATCH,FILENAME="%s.w3",MODE="coordinate"
RAD: SREFFECTS
DL1A: LINE=(DL1A_5,DL1A_4,DL1A_3,DL1A_2,DL1A_1)
DL2A: LINE=(DL2A_5,DL2A_4,DL2A_3,DL2A_2,DL2A_1)
"ARCA_C2R": LINE=(DR_24,BPM_05,DR_23,COR_05,SH2,DR_22,QF8,DR_21,DQ1,DR_20,QF6,&
DR_19,BPM_04,DR_18,S,COR_04,DR_17,DL2A,DR_16,QD5,DR_15,SD2,COR_03,DR_14,&
BPM_03,DR_13,OF1,DR_12,QF4,DR_11,SF1,FPBUMP,DR_10,QF4,DR_091,OF1,DR_092,&
BPM_02,DR_08,COR_02,SD1,DR_07,QD3,DR_06,-DL1A,DR_05,QD2,DR_04,COR_01,SH1,&
DR_03,QF1,DR_02,BPM_01,DR_01)
"ARCA_C1R": LINE=(DL_01,BPM_06,DL_02,COR_06,SH2,DL_03,QF8,DL_04,DQ1,DL_05,QF6,&
DL_06,BPM_07,DL_07,S,COR_07,DL_08,DL2A,DL_09,QD5,DL_10,SD2,COR_08,DL_11,&
BPM_08,DL_12,OF1,DL_13,QF4L,DL_14,FPBUMP,SF1,DL_15,QF4_C1,DL_161,OF1,DL_162,&
BPM_09,DL_17,COR_09,SD1,DL_18,QD3_C1,DL_19,-DL1A,DL_20,QD2_C1,DL_21,BPM_10,&
DL_22,COR_10,SH1,DL_23,QF1_C1,DL_24,COR_11,DL_25,QUAD_ADD,DL_26,BPM_11,DL_27)
"ARCA_C2": LINE=(ARCA_C2R,-ARCA_C2R)
"ARCA_C21": LINE=(ARCA_C2R,-ARCA_C2R)
"ARCA_C21M": LINE=(-ARCA_C2R,ARCA_C2R)
"ARCA_C1": LINE=(ARCA_C2R,-ARCA_C1R)
"ARCA_C11": LINE=(-ARCA_C1R,ARCA_C1R)
SP: LINE=(FPLS,-ARCA_C1R,FPMS,ARCA_C2R,FPSS,-ARCA_C2R,ARCA_C2R,-ARCA_C2R,&
ARCA_C2R,-ARCA_C2R,ARCA_C1R)
RING: LINE=(6*SP)
RINGRF: LINE=(W3,MAL,RAD,RFC,6*SP,W1,W2)
C2: LINE=(RAD,RFC,-ARCA_C2R,ARCA_C2R)
C2C2: LINE=(RAD,RFC,ARCA_C21M,ARCA_C21M)
USE,"RINGRF"
RETURN


The final file, temporaneo.new, should have the ANGLEs changed, but they are not.
So Only gradients are modified and indeed if I restart an already optimized case, the penaly function is not zero at the beginning.
This is because the ANGLEs have been modified during the optimisation, but are not saved in the final file.
How do I save bending ANGLEs in the *.new output of save_lattice?


Thanks
Marco

michael_borland
Posts: 1796
Joined: 19 May 2008, 09:33
Location: Argonne National Laboratory
Contact:

Re: Pelegant different method

Post by michael_borland » 27 May 2020, 19:25

Marco,

You need to perform the &save_lattice command right after &optimize. Otherwise, elegant starts a new problem with a clean copy of everything, read from your lattice file. In the second &run_setup, use the lattice file you created with &save_lattice.

--Michael

marlibgin
Posts: 54
Joined: 15 Mar 2011, 12:43

Re: Pelegant different method

Post by marlibgin » 01 Dec 2020, 09:34

Hi, some time ago I posted about the use (and few issues) I had when using the parallel (swarm) optimizer.
Thanks to the indications of the forum I had managed to make it run. In the meanwhile our cluster have been changed
and ... I can't run it properly anymore. I am not sure whether this is a cluster problem or my elegant implementation.
I tried my best to get some sort of comprehension but I get stuck at a point

I am attaching few files if anyone can find some time to investigate.

In a nutshell I am trying to reduce the emittance of a given lattice, which can easily be performed in "serial" mode, i.e. without submitting a parallel job. This is a simplex minimization that reaches a 0 penalty function in few minutes.
./serial_LDtemp_run.sh should be enough to run the case (./serial_LDtemp_clean.sh is used to clean the directory if you wish a terse start)

A typical tail of the output reads:

Computing twiss parameters for optimization
Updating radiation integral values for optimization
Tracking for optimization
equation evaluates to 1.041957156806486e+01
Terms of equation:
1*(ex0 1.596e-10 1e-12 segt 1e4 *): 1.041957156806486e+01

new variable values for evaluation 20 of pass 1:
QF8_22.K1: 8.429845219712531e+00
QF6_22.K1: 6.047048339941936e+00
QD5_22.K1: -8.149842282504519e+00
QF4_22B.K1: 3.523989057628731e+00
QF4_22A.K1: 6.994577081333489e+00
10 matrices (re)computed
...
Computing twiss parameters for optimization
Updating radiation integral values for optimization
Tracking for optimization
equation evaluates to 0.000000000000000e+00
Terms of equation:
1*(ex0 1.596e-10 1e-12 segt 1e4 *): 0.000000000000000e+00

Completed post-tracking output
new variable values for evaluation 24 of pass 2:
QF8_22.K1: 8.429845219712531e+00
QF6_22.K1: 6.047048339941936e+00
QD5_22.K1: -8.149842282504519e+00
QF4_22B.K1: 3.523989057628731e+00
QF4_22A.K1: 6.999021525777933e+00
10 matrices (re)computed
Computing twiss parameters for optimization
Updating radiation integral values for optimization
Tracking for optimization
equation evaluates to 0.000000000000000e+00
Terms of equation:
1*(ex0 1.596e-10 1e-12 segt 1e4 *): 0.000000000000000e+00

Completed post-tracking output
Optimization results:
optimization function has value 0
Terms of equation:
ex0 1.596e-10 1e-12 segt 1e4 *: 0.000000000000000e+00
A total of 24 function evaluations were made.
Optimum values of variables and changes from initial values:
QF8_22.K1: 8.429845219712531e+00 9.999999999999787e-03 (was 8.419845219712531e+00)
QF6_22.K1: 6.047048339941936e+00 -1.111111111111285e-03 (was 6.048159451053047e+00)
QD5_22.K1: -8.149842282504519e+00 1.299999999999990e-01 (was -8.279842282504518e+00)
QF4_22B.K1: 3.523989057628731e+00 -3.999999999999959e-02 (was 3.563989057628731e+00)
QF4_22A.K1: 6.999021525777933e+00 1.111111111111285e-03 (was 6.997910414666822e+00) (near limit)




I have also produced a similar case exploiting the parallel_optimization capabilities of elegant.
./parallel_LDtemp_run.sh is the script used to launch/submit a job over 100 nodes, clearly one has to adapt it to his/her relevant architecture, but in my case all seems to run ... however the output does not make sense

Examining the parallel_LDtemp.pop file (sddsprintout -par=Opt* -par=It*)
Printout for SDDS file parallel_LDtemp.pop
OptimizationValue = 2.587839e+01 OptimizationValueSpread = 8.419845e+00 Iteration = 1
OptimizationValue = 2.587839e+01 OptimizationValueSpread = 8.419845e+00 Iteration = 2
OptimizationValue = 2.587839e+01 OptimizationValueSpread = 8.419845e+00 Iteration = 3
OptimizationValue = 0.000000e+00 OptimizationValueSpread = 9.000000e+00 Iteration = 4


it seems like nothing happens in the first 3 iterations, then all of a sudden the penalty function collapses to zero.
Despite being a small initial number, typically one sees the attempts made by the algorithm to reach a minimum.

The analysis of the output from the submitted job is even more puzzling, what follows are the final lines
of the para_LDtemp.o<run_number> log file produced during the job submission:

Initial value for QF8_22.K1 is 8.419845e+00
Initial value for QF6_22.K1 is 6.048159e+00
Initial value for QD5_22.K1 is -8.279842e+00
Initial value for QF4_22B.K1 is 3.563989e+00
Initial value for QF4_22A.K1 is 6.997910e+00

Starting particle swarm optimization.
generating bunch 0
SReffects set up:
Pref=6849.33, Jx/y/delta=1.37484/1/1.62516
ex/ey=1.59651e-10/0 Sdelta=0.000773927 Ddelta=-0.000190219
Writing population statistics
Writing population statistics
Writing population statistics
Writing population statistics
Exited optimization loop
warning: beamline unstable for y plane--can't match beta functions.
Optimization results:
optimization function has value 0
Terms of equation:
ex0 1.596e-10 1e-12 segt 1e4 *: 2.587839371900322e+01
A total of 500 function evaluations were made with an average of 5 function evaluations per processor
Optimum values of variables and changes from initial values:
QF8_22.K1: 9.000000000000000e+00 5.801547802874687e-01
QF6_22.K1: 8.000000000000000e+00 1.951840548946953e+00
QD5_22.K1: -9.000000000000000e+00 -7.201577174954821e-01
QF4_22B.K1: 3.000000000000000e+00 -5.639890576287310e-01
QF4_22A.K1: 7.000000000000000e+00 2.089585333178157e-03

Saving lattice parameters to parallel_LDtemp.paramOpt...done.

I see 3 anomalies here:
- the penalty function is "declared" to be zero
- then the only line defining the penalty (the value of the emittance), is clearly non-zero
- the final values of the parameters (5 quad gradients) are set to a random choice of their upper/lower limits. Why?

There is also an instability warning, and I am not sure which role this is playing

Well this is it, as said I am attaching the files if anyone has some time to give it a go.
I use:
- elegant 34.3.1, Apr 12 2019
- /dls_sw/apps/openmpi/1.6.5/64//bin/mpirun --version
orterun (OpenRTE) 1.6.5


Thanks for any comment

Marco
Attachments
README.txt
(189 Bytes) Downloaded 211 times
SERIAL_test.tar.gz
interactive case
(568.62 KiB) Downloaded 221 times
PARALLEL_test.tar.gz
job submission (requires adaptation to local cluster)
(582.72 KiB) Downloaded 218 times

michael_borland
Posts: 1796
Joined: 19 May 2008, 09:33
Location: Argonne National Laboratory
Contact:

Re: Pelegant different method

Post by michael_borland » 04 Jan 2021, 11:00

Marco,

I'm not able to replicate your results. One issue with the swarm optimizer is that it doesn't handle unstable lattices well. I'm actually surprised that it didn't just abort.

I'm seeing if there is a way to resolve this. For now, you might want to use the hybrid simplex optimizer, which is more robust.

--Michael

michael_borland
Posts: 1796
Joined: 19 May 2008, 09:33
Location: Argonne National Laboratory
Contact:

Re: Pelegant different method

Post by michael_borland » 04 Jan 2021, 12:29

Marco,

I was able to replicate some similar behavior, which I tracked to how the particle swarm optimizer handles invalid function values, such as you'd get if a lattice evaluation point was unstable.

If you build from source, you can use the attached file. Otherwise, the fix will appear in 2021.1.

Thanks for reporting the issues.

--Michael
Attachments
swarm.c
(7.06 KiB) Downloaded 208 times

Post Reply