error on optimization

Moderators: cyao, michael_borland

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

error on optimization

Post by marlibgin » 01 Jun 2015, 05:25

Hi all, I am probably doing something silly but I can't find a solution to this. I have initially found a similar post by user Marcello named, "Strange Dispersion Calculation" where the problem was the inability at writing a final output file after the optimization. This is well explained in the reply, where the "optimize" command is a "major action", wiping out the problem space.

In my case, however, I am trying to run an optimization with no further action.
Specifically I 'd like to find the gradients of some skew quads to give a certain coupling. When running I can see the optimization does the job,
but the last line shows some problem occurred (in red)

Dumping final properties data...done.
Optimization results:
optimization function has value 5.55359509000862e-09
Terms of equation:
emittanceRatio 0.003 - sqr: 5.553595090008622e-09
A total of 38 function evaluations were made.
Optimum values of variables and changes from initial values:
QSKEW.1B.K1: 2.356250000000001e-01 2.356250000000001e-01
QSKEW.1C.K1: -1.231562500000000e-01 -1.231562500000000e-01
QSKEW.1D.K1: -5.196875000000000e-02 -5.196875000000000e-02
QSKEW.2A.K1: 2.623437500000000e-02 2.623437500000000e-02
statistics: ET: 00:00:04 CP: 3.55 BIO:0 DIO:0 PF:0 MEM:22602
error: run_setup, run_control, and beam definition must precede track namelist

I am quite puzzled since run_setup, run_control and bunched_beam all precede the track command as recommended

Below the .ele file used.
CPL_dlsi0913_corrlen.ele
main ele file with optimization of skew quads
(3.1 KiB) Downloaded 300 times
Thanks very much for any help
Marco

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

Re: error on optimization

Post by michael_borland » 01 Jun 2015, 08:21

Marco,

The reason is that &track and &optimize are both major action commands. After your optimization finishes, you need to save the the results (e.g., using &save_lattice or using a parameter file in &run_setup). Then you start over with a new &run_setup command and invoke the just-saved lattice (or load the parameter file). You can then define a beam etc. and finally issue &track.

--Michael

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

Re: error on optimization

Post by marlibgin » 01 Jun 2015, 10:58

Thanks very much for the prompt reply!
Indeed this sorted out the problem

Continuing on the same line I have another question then.

I want to optimize now against the ratio e2/e1 from the calculation of beam_moments, so I introduce
a block like:

&moments_output
filename = %s.mom,
matched = 1,
equilibrium = 1,
radiation = 1,
output_at_each_step=1,
&end

however I am not sure how to use this information. With output_at_each_step=1 the output file .mom is empty. With output_at_each_step=0 the *.mom file is non-empty. In both cases parameters e1 and e2 are not present when doing the rpn evaluation causing an error:

unknown token: e2
unknown token: e1

too few items on stack (divide)
*stop*
too few items on stack (subtract)
*stop*
Problem evaluating expression: e2 e1 / 0.003 - sqr
RPN expression errors prevent optimization

I attach the tentative .ele file for reference
CPL_moments.ele
(3.09 KiB) Downloaded 274 times

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

Re: error on optimization

Post by michael_borland » 01 Jun 2015, 11:08

Marco,

Unfortunately, the e1, e2, and e3 parameters aren't provided for optimization in the present release. I'll add that in the next release.

Meanwhile, you can access the elements of the sigma matrix at the location of a marker. First, define a marker, e.g.,

Code: Select all

M1: mark,fitpoint=1
and put it in your beamline.
Then, use optimization terms like

Code: Select all

&optimization_term
term = "
M1#1.s33 M1#1.s44 * M1#1.s34 sqr - sqrt 
M1#1.s11 M1#1.s22 * M1#1.s12 sqr - sqrt
/ 0.003 - sqr"
&end
I know this isnt' quite the same as optimizing e2/e1, but it should be quite close.

--Michael

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

Re: error on optimization

Post by marlibgin » 02 Jun 2015, 04:39

thanks Michael
I have followed your advice, put the marker, and tried to evaluate the s11,s12 etc. terms at that point.
However MRK#1.s11 is not found, while for example MRK#1.s12 is. I have seen that moments_output saves
s1 rather than s11, so I have tried to see if I can access that term unsuccessfully.

In general I am not sure which variables I can use to define an optimization term. Is there a general rule?

Thanks
Marco

here the .ele + .lte file used for this case
Attachments
ORC_dlsi0913_corrlen.new
(22 KiB) Downloaded 277 times
CPL_moments.ele
(3.17 KiB) Downloaded 265 times

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

Re: error on optimization

Post by michael_borland » 02 Jun 2015, 14:29

Marco,

Sorry, my previous message contained an error. The symbols to use are "s11m", "s22m", "s12m", etc. The extra "m" is to distinguish the &moments_output calculation results from the similar results from tracking.

You can find a more-or-less complete list of what's available for optimization by looking at the discussion of the "equation" parameter of the &optimization_setup command and also by looking at the documentation for the MARK element.

Attached is an example of a simulation that runs based on your files. I had to allow stronger skew quads to get convergence. I also adjusted the &optimization_setup command and made one change in the lattice file.
optimization.png
optimization.png (5.5 KiB) Viewed 5606 times
--Michael
Attachments
2015-06-01.zip
(324.57 KiB) Downloaded 315 times

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

Re: error on optimization

Post by marlibgin » 03 Jun 2015, 18:31

Thanks a lot Michael! it was really useful and it' s running now

My final goal is computing the lifetime in a machine where I have introduced several effects (misalignment errors, gradient errors etc), corrected the orbit, tune, chromaticity, introduced a defined coupling (which is the reason of this post actually). I call this a "realistic lattice".

To compute the momentum aperture I load the "realistic lattice" as described above and also introduce all the previous parameters. I have notice however that -at least when running in parallel mode- I get an error
Error: unknown parameter XREFERENCE used for BB CSBEND (parse_element)

and realized that XREFERENCE is not present, nor other parameters like F1,..F8.
In practice when loading the file with the parameters
CPL_dlsi0913_corrlen.param
(1.08 MiB) Downloaded 267 times
I should exclude these specifications, XREFERENCE, F1, F2, ... F8:
BB XREFERENCE 0.000000e+00 CSBEND 48
BB F1 0.000000e+00 CSBEND 48
BB F2 0.000000e+00 CSBEND 48
BB F3 0.000000e+00 CSBEND 48
BB F4 0.000000e+00 CSBEND 48
BB F5 0.000000e+00 CSBEND 48
BB F6 0.000000e+00 CSBEND 48
BB F7 0.000000e+00 CSBEND 48
BB F8 0.000000e+00 CSBEND 48



When using load_parameters option exclude_item_pattern, it works with a single name but seems to fail (for me at least) when I try to put together two or more different names.
So for example:

exclude_item_pattern = "XREFERENCE" excludes XREFRENCE
exclude_item_pattern = "F?" should exclude F1, ...F8

but how do I exclude all of them? "XREFERENCE F?" does not work


thanks Marco

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

Re: error on optimization

Post by michael_borland » 04 Jun 2015, 08:09

Marco,

It appears that you are running a quite old version of Pelegant, which explains why those parameters are missing from the internal element definitions. It probably also explains why the exclude_item_pattern option doesn't work as expected (the ability to exclude multiple patterns was added in the last few releases). You should upgrade.

Barring that, you can use sddsprocess to remove the unwanted data from the parameter file:

Code: Select all

sddsprocess CPL_dlsi0913_corrlen.param  CPL_dlsi0913_corrlen.paramFiltered \
 '-match=column,ElementParameter=XREFERENCE,ElementParameter=F?,|,!'
--Michael

Post Reply