Short question: Is there a way to change K1 for a quad using the -macro function? Or change the initial value used (in optimization_variable I suppose) when performing simplex optimization?
Long question:
I'm trying to optimize a set of four quads. A simple problem of take in twiss parameters and match them to some desired output set of twiss parameters. I am finding that depending on the settings of the quad K1 values in the lattice file the simplex optimizer will either find a really good match (FDFD, optimization function has value 2.16018011905043e-11) or really bad match (FFFF, optimization function has value 1.129994256216170e-01). The latter result seems immune to increasing n_passes, n_evaluations or n_restarts. It appears elegant is using the K1 values in the .lte file to start the search. What I'd like to be able to do is use a macro to iterate over setting the start points when starting the simplex optimizer. Is this possible? The documentation for optimize_variable doesn't seem to have that option:
Code: Select all
&optimization_variable
STRING name = NULL;
STRING item = NULL;
double lower_limit = 0;
double upper_limit = 0;
double step_size = 1;
long disable = 0;
long force_inside = 0;
&end
Other options I've tried:
include_simplex_1d_scans = 1,
simplex_pass_range_factor = 0.001, 0.01, 0.1, 1, 10
simplex_divisor = 0.01, 0.1, 1, 10
restart_worst_term_factor = 2, 5, 10
and I can't get it to change the signs on the quads appropriately. I've tried randomwalk and grid but it will be much faster to go through all 16 permutations of the possible start values than it would to wait for those guys to search - if I could get them to the right answer anyway. I haven't spent too much time on them and I really like the -macro function so I was hoping to find a solution using it.
.lte file
Code: Select all
! 4 Quads, no LSC stuff, for inital optimization work.
L1: DRIF,L=14.5843
L2: DRIF,L=6.39492
L3: DRIF,L=8.14492
L4: DRIF,L=4.14492
L5: DRIF,L=7.07246
QUM1: QUAD,L= 1.580000000E-01,K1=0.5 ! change me to -0.5 for good opt.
QUM2: QUAD,L= 1.580000000E-01,K1=0.5
QUM3: QUAD,L= 1.580000000E-01,K1=0.5 ! change me to -0.5 for good opt.
QUM4: QUAD,L= 1.580000000E-01,K1=0.5
UndMatch: LINE = (L1, QUM1, QUM1, L2, QUM2, QUM2, &
L3, QUM3, QUM3, L4, QUM4, QUM4, L5)
Code: Select all
! A simple 4 quad match
! ----------------------------------
! Setup the optimizer
! ----------------------------------
&run_setup
lattice = simple_4_quad.lte,
default_order = 1,
use_beamline = UndMatch,
p_central_mev = 8000,
final = %s.fin,
&end
&twiss_output
matched = 0,
beta_x = 30.7723, alpha_x = -0.8882 ,
beta_y = 63.39, alpha_y = 1.1676,
output_at_each_step=0,
&end
&run_control
n_steps = 1
&end
&optimization_setup
mode = "minimize",
method = "simplex",
target = 1e-10,
tolerance = 1e-16,
n_passes = 5,
n_evaluations = 500,
log_file = /dev/tty,
n_restarts = 10,
verbose = 0,
output_sparsing_factor = 10,
&end
&optimization_term
term = "betax 34.35574 - sqr"
&end
&optimization_term
term = "alphax 1.432320 - sqr"
&end
&optimization_term
term = "betay 30.15917 - sqr"
&end
&optimization_term
term = "alphay -0.9522622 - sqr"
&end
&optimization_variable
name = QUM1, item=K1, lower_limit=-1.1859, upper_limit=1.1859, step_size = 0.001
&end
&optimization_variable
name = QUM2, item=K1, lower_limit=-1.1859, upper_limit=1.1859, step_size = 0.001
&end
&optimization_variable
name = QUM3, item=K1, lower_limit=-1.1859, upper_limit=1.1859, step_size = 0.001
&end
&optimization_variable
name = QUM4, item=K1, lower_limit=-1.1859, upper_limit=1.1859, step_size = 0.001
&end
&bunched_beam
n_particles_per_bunch = 1
&end
&optimize summarize_setup=0
&end
&save_lattice
filename = %s.new
&end
! ----------------------------------
! Run the guess beam through the (potentially) optimized lattice
! ----------------------------------
&run_setup
lattice = simple_4_quad.new,
default_order = 1,
use_beamline = UndMatch,
p_central_mev = 8000,
parameters = %s.param
magnets = %s.mag
&end
&twiss_output
matched = 0,
beta_x = 30.7723, alpha_x = -0.8882 ,
beta_y = 63.39, alpha_y = 1.1676,
statistics = 1,
filename = %s.twi
&end
&run_control
n_steps = 1
&end
! ----------------------------------
! Run elegant and...other stuff?
! ----------------------------------
&bunched_beam &end
&track &end
&stop &end