Correction¶
Entry Points Correction¶
Module correction.correct¶
Created on ??
Single beam correction of phase, beta and horizontal dispersion. TODO: get better description (vimaier)
Usage example:
python correct_coupleDy.py --accel=LHCB1
--Variables=Q
--ncorr=5
--rpath=C:\eclipse_4_2_2_python\workspace\Beta-Beat.src
--modelcut=0.3,0.3
--weight=1,1,0,0,0,10
--MinStr=0.00003
--path=C:\eclipse_4_2_2_python\workspace\Beta-Beat.src\Correction\test\correct\data\input\run1
--errorcut=0.5,0.5
--cut=0.01
--tech=SVD
--opt=C:\eclipse_4_2_2_python\workspace\Beta-Beat.src\Correction\test\correct\data\input
Hint: JustOneBeam is not used in the script except of a print. The reason is possibly the author wanted to have the same set of arguments for all correction scripts due to GUI compatibility(vimaier).
Options:
-h, --help show this help message and exit
-a ACCEL, --accel=ACCEL
What accelerator: LHCB1 LHCB2 SPS RHIC
-t TECH, --tech=TECH Which algorithm: SVD MICADO
-n NCORR, --ncorr=NCORR
Number of Correctors for MICADO
-p PATH, --path=PATH Path to experimental files
-c CUT, --cut=CUT Singular value cut for the generalized inverse
-e ERRORCUT, --errorcut=ERRORCUT
Maximum error allowed for the phase and dispersion
measurements, separated by commas; e.g. -e 0.013,0.2
-m MODELCUT, --modelcut=MODELCUT
Maximum difference allowed between model and measured
phase and dispersion, separated by commas; e.g. -e
0.02,0.2
-r RPATH, --rpath=RPATH
Path to BetaBeat repository (default is the afs
repository)
-o opt, --optics=opt optics
-s MinStr, --MinStr=MinStr
Minimum strength of correctors in SVD correction
(default is 1e-6)
-v var, --Variables=var
variables split with ,
-j JUSTONEBEAM, --JustOneBeam=JUSTONEBEAM
0 Just quads from one beam are used, 1 all quads
(default is 0)
-w WGT, --weight=WGT Weighting factor (phasex, phasey, betax, betay,
dispersion, tunes)
Module correction.correct_ChromCoup¶
Created on ??
Single beam correction of chromatic coupling using skew sextupoles at dispersive locations. TODO: get better description (vimaier)
Usage example:
python correct_ChromCoup.py --accel=LHCB1
--Variables=kss
--rpath=/afs/cern.ch/work/v/vimaier/public/Beta-Beat.src
--modelcut=100,100
--MinStr=0.000001
--path=/afs/cern.ch/work/v/vimaier/public/Beta-Beat.src/Correction/test/chrom_coup/data/input/run2
--errorcut=20,20
--Dy=1,1,0,0,0
--cut=0.01
--opt=/afs/cern.ch/work/v/vimaier/public/Beta-Beat.src/Correction/test/chrom_coup/data/input/run2
Hint: The latter parts of modelcut and errorcut and MinStr are not used in the script except of a print. The reason is possibly the author wanted to have the same set of arguments for all correction scripts due to GUI compatibility(vimaier).
Options:
-a ACCEL, --accelerator=ACCEL
What accelerator: LHCB1 LHCB2
-p PATH, --path=PATH Path to experimental files
-c CUT, --cut=CUT Singular value cut for the generalised inverse
-e ERRORCUT, --errorcut=ERRORCUT
Maximum error allowed for the coupling measurement and
Dy measurement
-m MODELCUT, --modelcut=MODELCUT
Maximum difference allowed between model and measured
phase
-r RPATH, --rpath=RPATH
Path to BetaBeat repository (default is the afs
repository)
-s MinStr, --MinStr=MinStr
Minimum strength of correctors in SVD correction
-d Dy, --Dy=Dy weight on corrections (f1001.re, f1001.im, f1010.re,
f1010.im, Dy)
-o OPT, --opt=OPT To specify the optics
-v var, --Variables=var
variables split with , - if coupling_knobs is given,
the modelcut will be calculated automatically
Module correction.correct_coupleDy¶
Created on ??
Single beam correction of coupling resonances and vertical dispersion. TODO: get better description (vimaier)
Usage example:
python correct_coupleDy.py --accel=LHCB1
--path=C:\MyTemp\correct_coupleDy_out\
--cut=0.01
--errorcut=0.02,0.02
--modelcut=0.0,0.01
--rpath=H:\work/v/vimaier/public/Beta-Beat.src/
--MinStr=0.000001
--Dy=1,1,0,0,1
--opt=C:\MyTemp\correct_coupleDy_out\
--Variables=coupling_knobs
Hint: MinStr is not used in the script except of a print. The reason is possibly the author wanted to have the same set of arguments for all correction scripts due to GUI compatibility(vimaier).
Options:
-a ACCEL, --accelerator=ACCEL
What accelerator: LHCB1 LHCB2 SPS RHIC
-p PATH, --path=PATH Path to experimental files
-c CUT, --cut=CUT Singular value cut for the generalised inverse
-e ERRORCUT, --errorcut=ERRORCUT
Maximum error allowed for the coupling measurement and
Dy measurement
-m MODELCUT, --modelcut=MODELCUT
Maximum difference allowed between model and measured
phase
-r RPATH, --rpath=RPATH
Path to BetaBeat repository (default is the afs
repository)
-s MinStr, --MinStr=MinStr
Minimum strength of correctors in SVD correction
-d Dy, --Dy=Dy weight on corrections (f1001.re, f1001.im, f1010.re,
f1010.im, Dy)
-o OPT, --opt=OPT To specify the optics
-v var, --Variables=var
variables split with , - if coupling_knobs is given,
the modelcut will be calculated automatically
Helpers Correction¶
Module correction.GenMatrix¶
Module correction.getdiff¶
module: | correction.getdiff |
---|
Created on 24/02/18
author: | Lukas Malina |
---|
Calculates the difference between GetLLM output and correction plugged in the model. Provide as first argument the path to the output files of GetLLM.
- model inputs:
- twiss_cor.dat and twiss_no.dat
- outputs in measurement directory:
- phasex.out and phasey.out bbx.out and bby.out dx.out, dy.out and ndx.out couple.out and chromatic_coupling.out
- TODOs and Notes:
- OpticsMeasurement: possibly extend and use with measurement filters from global correction
- to be used in sbs, new corrections, getdiff, plot_export
Expected values after correction to be put in, little tricky with phase column names No coupling in twiss_no.dat? not used
- Some hints:
MEA, MODEL, EXPECT are usually the names for the differences between the values and the model. Apart from phase, where these differences are called DIFF and DIFF_MDL (EXPECT is still the same) while MEA and MODEL are the actual measurement and model values respectively.
Don’t look into the coupling and chromatic coupling namings.
-
correction.getdiff.
getdiff
(meas_path=None, beta_file_name='getbeta')[source]¶ Calculates the differences between measurement, corrected and uncorrected model.
After running madx and creating the model with (twiss_cor) and without (twiss_no) corrections, run this functions to get tfs-files with the differences between measurements and models.
Parameters: - meas_path (str) -- Path to the measurement folder.
- to contain twiss_cor.dat and twiss_no.dat. (Needs) --
Helpers Response Creation¶
Module correction.fullresponse.response_madx¶
Provides a function to create the responses of beta, phase, dispersion, tune and coupling via iterative madx calls.
The variables under investigation need to be provided as a list (which can be gotten from accelerator class).
For now, the response matrix is stored in a ‘pickled’ file.
author: | Lukas Malina, Joschua Dilly, Jaime (…) Coello de Portugal |
---|
-
correction.fullresponse.response_madx.
generate_fullresponse
(accel_inst, variable_categories, delta_k=2e-05, num_proc=2, temp_dir=None)[source]¶ Generate a dictionary containing response matrices for beta, phase, dispersion, tune and coupling and saves it to a file.
Parameters: - accel_inst -- Accelerator Instance.
- variable_categories (list) -- Categories of the variables/knobs to use. (from .json)
- delta_k (float) -- delta K1L to be applied to quads for sensitivity matrix
- num_proc (int) -- Number of processes to use in parallel.
- temp_dir (str) -- temporary directory. If
None
, uses folder of original_jobfile.
Module correction.fullresponse.response_twiss¶
Provides Class to get response matrices from Twiss parameters.
The calculation is based on formulas in [1], [2].
Only works properly for on-orbit twiss files.
- Beta Response: Eq. A35 inserted into Eq. B45 in [1]
- Dispersion Response: Eq. 25-27 in [1] + K1 (see Eq. B17)
- Norm. Dispersion Response: similar as above but with \(\frac{1}{\sqrt{\beta}}\) linearized
- Phase Advance Response: Eq. 28 in [1]
- Tune Response: Eq. 7 in [2]
- Coupling Response: Eq. 10 in [1]
For people reading the code, the response matrices are first calculated like:
| Elements of interest (j) --> ... |
|Magnets (m) |
| | |
| v |
| . |
| . |
| . |
| |
This avoids transposing all vectors individually in the beginning. At the end (of the calculation) the matrix is then transposed to fit the \(M \cdot \delta K\) orientation.
Also \(\Delta \Phi_{z,wj}\) needs to be multiplied by \(2\pi\) to be consistent.
References
[1] | (1, 2, 3, 4, 5) A. Franchi et al., Analytic formulas for the rapid evaluation of the orbit response matrix and chromatic functions from lattice parameters in circular accelerators https://arxiv.org/abs/1711.06589 |
[2] | (1, 2) R. Tomas, et al., ‘Review of linear optics measurement and correction for charged particle accelerators.’ Physical Review Accelerators and Beams, 20(5), 54801. (2017) https://doi.org/10.1103/PhysRevAccelBeams.20.054801 |
-
class
correction.fullresponse.response_twiss.
TwissResponse
(accel_inst, variable_categories, varmap_or_path, at_elements='bpms')[source]¶ Provides Response Matrices calculated from sequence, model and given variables.
Parameters: - accel_inst (accelerator) -- Accelerator Instance (needs to contain elements model).
- variable_categories (list) -- List of variable categories to get from the accelerator class.
- varmap_or_path (dict, string) -- mapping of the variables, either as dict-structure of Series or path to a pickled-file.
- at_elements (str) -- Get response matrix for these elements. Can be: ‘bpms’: All BPMS (Default) ‘bpms+’: BPMS+ used magnets (== magnets defined by variables in varfile) ‘all’: All BPMS and Magnets given in the model (Markers are removed)
-
correction.fullresponse.response_twiss.
create_response
(accel_inst, vars_categories, optics_params)[source]¶ Wrapper to create response via TwissResponse
-
correction.fullresponse.response_twiss.
dict_mul
(number, dictionary)[source]¶ Multiply an int with a dict of dataframes (or anything multiplyable)
-
correction.fullresponse.response_twiss.
get_delta
(response, delta_k)[source]¶ Returns the deltas of \(response_matrix \cdot delta_k\).
Parameters: - response -- Response dictionary
- delta_k -- Pandas Series of variables and their delta-value
Returns: TFS_DataFrame with elements as indices and the calculated deltas in the columns
Module correction.fullresponse.generateFullResponse_parallel¶
Created on ??
This Python script produces the responses of the beta, phase and horizontal dispersion on the quadrupole strengths or on other variables as horizontal orbit bumps at sextupoles. The fullresponse.couple does the corresponding calculation for the coupling and the vertical dispersion.
- The response matrices are stored it in the following ‘pickled’ files:
- FullResponse
- FullResponse_couple
- FullResponse_chromcouple
The files are saved in option -p(output_path).
These response matrices are used to calculate the corrections by the correction scripts.
Parallel execution: multiprocessing from Python stdlib is used to spwan subprocesses and run MADX in parallel. Further the loading of the MADX outputfiles will be executed in parallel.
- Possible improvements:
- The order of the three _gen*_for_*() functions are irrelevant and they do not depend on each other. Thus the execution could be parallelized. Therefore the created iter.madx and twiss files need an unique prefix. E.g.: ‘beta_iter.madx’. All three functions would need own process pools and the handling of the input data have to be considered. For test_fullresponse_parallel.py the comparing of *iter.madx should then be avoided since the ‘valid’ script does not produce them.
- The three functions in the main function do basically the same. A good pattern to handle this is the template method: http://en.wikipedia.org/wiki/Template_method_pattern
- Removing of the exec statements. This is very ugly and could be replaced with a function get_variables_for_accel_and_fullresponse_type(accel, type). The function could import the corresponding module by checking function parameters in if/else statements and deliver the appropriate list.
Usage example:
python generateFullResponse_parallel.py --accel=LHCB1 --path=/afs/cern.ch/work/v/vimaier/public/betabeatGui/temp/2013-10-22/models/LHCB1/a_mod --core=/afs/cern.ch/work/v/vimaier/public/Beta-Beat.src/MODEL/LHCB1/fullresponse --deltak=0.00002
Options:
-a ACCEL, --accel=ACCEL
Which accelerator: LHCB1 LHCB2 SPS RHIC SOLEIL
-p PATH, --path=PATH path to save. Have to contain 'job.iterate.madx' and 'modifiers.madx'
-c CORE, --core=CORE core files
-k K, --deltak=K delta k to be applied to quads for sensitivity matrix