Beta Beating Correction in presence of errors

Moderators: cyao, michael_borland

Post Reply
SDastan
Posts: 38
Joined: 21 May 2018, 07:08

Beta Beating Correction in presence of errors

Post by SDastan » 30 Jun 2022, 06:19

Dear all,

I am doing optimization for the Elettra 2.0 lattice with MOGA in Elegant. I need to do beta beating correction after optimization and apply errors to compare the result with AT. I know there is a simplex method that matches the ref twiss function of bare lattice to perturbed ones, but it doesn't show a good result to me. I mean it reached %8 and %12 in both planes and does not show a good result for dispersion function at all. Does anybody have any experience to correct beta beating in Elegant?

Regards,
Sara
Sara

sajaev
Posts: 6
Joined: 11 Jun 2008, 11:58

Re: Beta Beating Correction in presence of errors

Post by sajaev » 06 Jul 2022, 09:37

Dear Sara,

We do not use Elegant itself for beta beating correction. We use an external script that works much like orbit correction. First, it calculates beta function response matrix with respect to quadrupoles. The beta function response matrix is constructed this way: every column is a change due to a single quadrupole in horizontal beta function, vertical beta function, and horizontal dispersion. Then the quadrupole corrections are calculated by multiplying the pseudoinverse beta function response matrix with the vector of beta function errors (constructed the same way as the matrix columns). The achievable accuracy could be well below 1%, but depends on the number of singular values used for matrix inversion.

Vadim

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

Re: Beta Beating Correction in presence of errors

Post by michael_borland » 06 Jul 2022, 16:37

Sara,

The SR LOCO Response Matrix Fitting, at the bottom of our software page, might be a good starting point.

--Michael

SDastan
Posts: 38
Joined: 21 May 2018, 07:08

Re: Beta Beating Correction in presence of errors

Post by SDastan » 07 Sep 2022, 06:40

Dear all,

I used Elegant for beta beating and coupling correction in the presence of errors with the wonderful and great support of Vadim Sajaev and I think It could be helpful for others so I share the process and steps here. The method is precious and much faster than the simplex method. I try to explain it by all the details, so I did as below:

1. Get the "SR LOCO Response Matrix Fitting" APS website.

2. Copy all the command files in the SRLOCOFitting to the bin of your Elegant or alternatively add the parent folder of these files to the PATH environment variable using your own preferred method, e.g. from CalculateLOCOFit to SRLOCOFitting.

3. Add these lines to the .bashrc or run it in the terminal that you want to use srlocofitting:

Code: Select all

export LOCO_BINDIR=path_to_where_you_placed_CalculateLOCOFit_and_other_command_files
export LOCO_CONFDIR=path_to_where_you_placed_SRLOCOFitting/SRLOCOFitting/work
4. Now the system is prepared for LOCOFitting to do beta and coupling correction, so get the files from the attachment.

5. Copy the "calculateTwissCorrection" file in the attachment to the Elegant bin.

Now, You can do the correction with the attached files, each file can be explained as below:

calculateTwissCorrection -- correction program
converted.lte -- the lte file
elements.sdds -- list of elements to use by correction program for correction created by step 2 in running procedure.
elettra.ele -- the closed orbit correction in the presence of errors
errors.param -- the error files
fittingProcedures.tcl -- required file for calculateTwissCorrection
makeElementListFile -- short script to create elements.sdds file
result.beta.param -- quadrupole corrections calculated by the correction program created by step 3 in the running procedure.
result.coupling.param -- contains skew quadrupole corrections created by step 4 in the running procedure.
runCorrection -- short script to run calculateTwissCorrection
/tmp -- subdirectory with results of the correction calculations created during the correction.

For running the correction, do as below:

1. elegant elettra.ele
2. ./makeElementListFile -listFile elements.sdds
3. Beta function correction: ./runCorrection -workDir `pwd` -correctionMode beta -measLatticeParamFile step3.param -outputFile result.beta.param
4. Coupling correction: ./runCorrection -workDir `pwd` -correctionMode coupling -measLatticeParamFile "step3.param result.beta.param" -outputFile result.coupling.param

The corrected lattice is presented by three files: "step3.param result.beta.param result.coupling.param". I should mention that I worked in ubuntu with Elegant version of 2021.4.0.

I hope you find it helpful.

Regards,
Sara
Attachments
Beta_Couling_Correction.zip
(278 KiB) Downloaded 94 times
Last edited by SDastan on 13 Oct 2022, 01:41, edited 4 times in total.
Sara

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

Re: Beta Beating Correction in presence of errors

Post by michael_borland » 19 Sep 2022, 13:22

Sara,

Thanks for your post!

--Michael

SDastan
Posts: 38
Joined: 21 May 2018, 07:08

Re: Beta Beating Correction in presence of errors

Post by SDastan » 13 Sep 2023, 05:59

Dear Vadim and all,

I try to use shifted quadruples+normal quads for correcting the beta beating. I added my shifted quads in the element list, but when I run for the beta mode correction I faced with the error as below:

Code: Select all

error: column bqf4_1L not found in file /net/phase/store/users/sara.dastan/Elegant-2021.4.0/SRLOCOFitting/Full_correction/try_with_skew_quads/with_skew_quads/betaCorrectionMatrix.sdds take_columns 192 SDDS_ref[z] 0

Error for sddsconvert:
Unable to read layout--no header lines found (SDDS_ReadLayout) 
Interrupt iterations.
child process exited abnormally
    while executing
"exec /net/phase/store/users/sara.dastan/Elegant-2021.4.0/SRLOCOFitting/Full_correction/try_with_skew_quads/with_skew_quads/calculateTwissCorrection  -..."
    ("eval" body line 1)
    invoked from within
"eval exec $command >&@ stdout"
    (file "./runCorrection" line 80)
would you mind if I ask you to take a look at on it and let me know what is my problem? I attached my files too. Thanks in advance.

Regards,
Sara
Attachments
correcting_with_skew_quads.zip
(1.72 MiB) Downloaded 20 times
Sara

sajaev
Posts: 6
Joined: 11 Jun 2008, 11:58

Re: Beta Beating Correction in presence of errors

Post by sajaev » 14 Sep 2023, 12:39

Sara,

you made a mistake in adding new elements to the element list. You modified makeElementListFile like this:

lappend quadList QD1_${i}L#1 QF1_${i}L#1 QD2_${i}L#1 QF2_${i}L#1
lappend quadList QF2_${i}R#1 QD2_${i}R#1 QF1_${i}R#1 QD1_${i}R#1
lappend quadList bqf4_${i}L bqf3_${i}L bqf2_${i}L bqf1_${i}L
lappend quadList bqf4_${i}R bqf3_${i}R bqf2_${i}R bqf1_${i}R

There is a couple of mistakes here:

First, all element names need to be in capital letters.

Second, the names you give for BQFs are wrong. First, you need to remember that the elements are referred inside calculateTwissCorrection as ElementName#ElementOccurence. For QD (and QF) you have elements QD1_1L in cell 1, QD1_2L in cell 2, etc. That's why the first two lines in the program above are QD1_${i}L#1 where ${i} changes from 1 to 12, but it always remains #1 because it is always the first (and only) occurrence of the element. So your element list will have elements QD1_1L#1 (for cell 1), QD1_2L#1 (for cell 2) , etc. For BQF elements, you have the same name BQF1_L for all cells, so your list should have elements BQF1_L#1 (for BQF1_L in cell 1), BQF1_L#2 (for BQF1_L in cell 2 because it is the second occurrence of element BQF1_L), etc. Therefore, the last 2 lines in the above should be:

lappend quadList BQF1_L#$i BQF2_L#$i BQF3_L#$i BQF4_L#$i
lappend quadList BQF4_R#$i BQF3_R#$i BQF2_R#$i BQF1_R#$i

I also changed the order of elements to follow the order in the lattice. I am not sure it is required, but definetely would not hurt.

After this change the program works fine for me.


Also since now you have 192 quads instead of 96, you should change the number of singular values in the matrix inversion from 80 to something like 180. Modify runCorrection "set SVratio 80" to "set SVratio 180"

Vadim

SDastan
Posts: 38
Joined: 21 May 2018, 07:08

Re: Beta Beating Correction in presence of errors

Post by SDastan » 20 Sep 2023, 09:53

Dear Vadim,

Thanks for the help and suggestion. Yes, it's worked perfectly after the changes.

Regards,
Sara

Post Reply