1
1 Response Matrix Analytical Implementation of TwissResponse - - PowerPoint PPT Presentation
1 Response Matrix Analytical Implementation of TwissResponse - - PowerPoint PPT Presentation
1 Response Matrix Analytical Implementation of TwissResponse Joschua Dilly VIA at CERN 2 Analytical Formulas Implementation Testing Setup Response Comparison MAD-X Comparison Conclusions Response Matrix - Analytical Implementation of
Response Matrix
Analytical Implementation of TwissResponse
Joschua Dilly VIA at CERN
2
Analytical Formulas Implementation Testing Setup Response Comparison MAD-X Comparison Conclusions
- J. Dilly
Response Matrix - Analytical Implementation of TwissResponse
3
Analytical Formulas Implementation Testing Setup Response Comparison MAD-X Comparison Conclusions
- J. Dilly
Response Matrix - Analytical Implementation of TwissResponse
4
Phase Advances
ΔΦz,wj ΔΦz,wj τz,wj Πwj = ( − ) Φz,j Φz,w = ( − ) + 2π Φz,j Φz,w Qz = Δ − π Φz,wj Qz = < sw sj , if > Φz,j Φz,w , if <= Φz,j Φz,w
- J. Dilly
Response Matrix - Analytical Implementation of TwissResponse
5
Advances
Hints:
- : plane or
- : elements of interest
- : magnets contibuting to K
- : in our case
∝ δK1
δQz δβz,j δΦz,wj = = = ± δ ∑
m
K1,m βz,m 4π ∓ δ × βz,j ∑
m
K1,m βz,m 2 cos(2 ) τz,mj sin(2π ) Qz ± δ × ∑
m
K1,m βz,m 4 {2 [ − + ] + } Πmj Πmw Πjw sin(2 ) − sin(2 ) τz,mj τz,mw sin(2π ) Qz z x y j m δ w ≡ j − 1
- J. Dilly
Response Matrix - Analytical Implementation of TwissResponse
6
Dispersion Advances
Hints:
- : plane or
- : elements of interest
- : magnets contibuting to K
δDx,j δDy,j = = + δ × βx,j ‾ ‾ ‾ √ ∑
m
K0,m βx,m ‾ ‾ ‾‾ √ 2 cos( ) τx,mj sin(π ) Qx + δ × βx,j ‾ ‾ ‾ √ ∑
m
K1S,mDy,m βx,m ‾ ‾ ‾‾ √ 2 cos( ) τx,mj sin(π ) Qx − δ × βy,j ‾ ‾ ‾ √ ∑
m
K0S,m βy,m ‾ ‾ ‾‾ √ 2 cos( ) τy,mj sin(π ) Qy + δ × βy,j ‾ ‾ ‾ √ ∑
m
K1S,mDx,m βy,m ‾ ‾ ‾‾ √ 2 cos( ) τy,mj sin(π ) Qy z x y j m δ
- J. Dilly
Response Matrix - Analytical Implementation of TwissResponse
7
Analytical Formulas Implementation Testing Setup Response Comparison MAD-X Comparison Conclusions
- J. Dilly
Response Matrix - Analytical Implementation of TwissResponse
8
TwissResponse Class
twiss = TwissResponse(path_sequence, path_model, path_variables, exclude_categories)
where:
- path_sequence: madx-sequence file, e.g. saved from madx by
save, sequence=lhcb1, file=lhcb1_full.seq;
- path_model: tfs model file, e.g. saved from madx by
twiss, sequence=lhcb1, file=twiss_lhcb1.dat;
- path_variables: .json file, containing the different madx-variables that will be used. The
variables are assumed to be in categories (or at least one category). An easy way to create such a file can be found in twiss_optics/sequence_parser.py:
sequence_parser.varpmap_variables_to_json(path_sequence)
- exclude_categories: Categories of the json file, that will not be used.
- J. Dilly
Response Matrix - Analytical Implementation of TwissResponse
9
TwissResponse Class
- Generates response matrices for beta, dispersion, phase and tune.
- Via analytical formulas from previous section.
- A mapping is a applied: From the MadX-variables to the actual magnets, hence the
return is not a response of but .
- Response is returned via getter-functions of class-object:
twiss.get_beta()
- Return of the K response via:
twiss.get_beta(mapped=False)
Returns dictionaries with X and Y entries, containing the response matrices as
- dataframes. (In case of dispersion there are: X_K0L, X_K1SL, Y_K0SL, Y_K1SL
entries)
- Imitating behavoiur of response_pandas.py also possible:
twiss.get_fullresponse()
Returns a dictionary with BETX, BETY, MUX, MUY, DX, DY and Q dataframes.
δK δVar δ
- J. Dilly
Response Matrix - Analytical Implementation of TwissResponse
10
Hints
- Generating the response matrices takes a few seconds, but is about 4 times faster
than MadX (on my setup 30s analytical vs 130s MadX).
- TwissResponse is not parallelized (as is MadX), so maybe some tuning is possible (e.g.
parallel calculation for the different beam parameters.) Yet: Half of the time is dedicated to phase advance response calculation.
- To perform matrix multiplication
for all paramters automatically, use from twiss_optics/response_class.py:
fullresponse = twiss.get_fullresponse() response_class.get_delta(fullresponse, delta_k)
⋅ δK Mresp
- J. Dilly
Response Matrix - Analytical Implementation of TwissResponse
11
Sequence parsing assumptions:
- Magnets defined as "mb" are characterized by their bending radius and are hence
immutable!
- Sequence is saved in a way, that magnets definitions contain 'knl:={}', 'ksl:={}' or
'K#:='.
- There is only one value in each knl/ksl array.
- Zero-offset, i.e. no fixed number summation (e.g. no 'magnet := 2 + kq.xxx').*
- linearity, i.e. variables do not multiply with each other (will result in zeros).*
- the variable-name is final (i.e. it is not reassigned by ':=' somewhere else).
- the variable-name does not start with "l." (reserved for length multiplier).
- the length multiplier is given by l.<magnettype>.
- apart from the length, there are no other named multipliers (numbers are fine).
- If a magnet is redefined, last definition is used.
* this is due to the way the mapping is found. All variables apart from one are set to zero, and then the magnet values are checked. It is of course possible to implement it in a different, way e.g. with multiple values for the variables.
- J. Dilly
Response Matrix - Analytical Implementation of TwissResponse
12
Analytical Formulas Implementation Testing Setup Response Comparison MAD-X Comparison Conclusions
- J. Dilly
Response Matrix - Analytical Implementation of TwissResponse
13
Error Function
The physical parameter-functions can be arbitrarily close to zero, e.g. dispersion:
5000 10,000 15,000 20,000 25,000 −3 −2 −1 1 2 3 twiss results madx results
Position [m] Dispersion X [m]
- J. Dilly
Response Matrix - Analytical Implementation of TwissResponse
14
Error Function
Hence, the relative error between two different calculation methods, can be arbitrarily large: A solution can be to use a "normalized" error instead:
5000 10,000 15,000 20,000 25,000 −12 −10 −8 −6 −4 −2 2 4 error relative error mean-normalized
Position [m] Error
- J. Dilly
Response Matrix - Analytical Implementation of TwissResponse
15
Processing math: 100%
Gathering Statistics
- 25x: Pick 1(="single") or 10(="multi") variables at random from list (e.g. "K1L").
- 5x: Change variable strength(s) by
"gaussian w/ cutoff" distributed around , i.e. for .
- 12x: Increase stepwise:
- At each step: Calculate the
via twiss response, madx response and madx directly.
- Calculate RMS-Error of the statistics.
- Average over the different variable sets. Min/Max define error-bars.
- Plot over
±ϵ 10λ ϵ ∈ [.4 ⋅ , 1.6 ⋅ ] 10λ 10λ λ λ ∈ [−6 : .5 : 0) δ(D/β/ΔΦ/Q) ⇒ λ
- J. Dilly
Response Matrix - Analytical Implementation of TwissResponse
16
Analytical Formulas Implementation Testing Setup Response Comparison MAD-X Comparison Conclusions
- J. Dilly
Response Matrix - Analytical Implementation of TwissResponse
17
Comparison Analytical- and Mad-X Response Matrices
- J. Dilly
Response Matrix - Analytical Implementation of TwissResponse
18
Single Variable Change
- BET-Y shows the most differences between results (max ~5% RMS)
- Still all results in agreement with each other.
δK1L
−6 −5 −4 −3 −2 −1
10
−7
10
−6
10
−5
10
−4
10
−3
10
−2
10
−1
1 10 10
2
BETX BETY DX DY MUX MUY QX QY
Approximate log(10) of δK RMS Error
- J. Dilly
Response Matrix - Analytical Implementation of TwissResponse
19
Multi Variable Change
- Tunes show wider spread, disagreement up to 40% RMS
- Other parameters in agreement
δK1L
−6 −5 −4 −3 −2 −1
10
−7
10
−6
10
−5
10
−4
10
−3
10
−2
10
−1
1 10 10
2
BETX BETY DX DY MUX MUY QX QY
Approximate log(10) of δK RMS Error
- J. Dilly
Response Matrix - Analytical Implementation of TwissResponse
20
Single Variable Change
- DX values agree with each other
δK0L
−6 −5 −4 −3 −2 −1
10
−7
10
−6
10
−5
10
−4
10
−3
10
−2
10
−1
1 10 10
2
BETX BETY DX DY MUX MUY QX QY
Approximate log(10) of δK RMS Error
- J. Dilly
Response Matrix - Analytical Implementation of TwissResponse
21
Multi Variable Change
- Wider spread compared to single-
test, but still good agreement of DX
δK0L
δK
−6 −5 −4 −3 −2 −1
10
−7
10
−6
10
−5
10
−4
10
−3
10
−2
10
−1
1 10 10
2
BETX BETY DX DY MUX MUY QX QY
Approximate log(10) of δK RMS Error
- J. Dilly
Response Matrix - Analytical Implementation of TwissResponse
22
Single Variable Change
- DY results are in full agreement
δK1SL
−6 −5 −4 −3 −2 −1
10
−7
10
−6
10
−5
10
−4
10
−3
10
−2
10
−1
1 10 10
2
BETX BETY DX DY MUX MUY QX QY
Approximate log(10) of δK RMS Error
- J. Dilly
Response Matrix - Analytical Implementation of TwissResponse
23
Multi Variable Change
- Mean of DY raised a bit compared to single-
test, still in perfect agreement
δK1SL
δK
−6 −5 −4 −3 −2 −1
10
−7
10
−6
10
−5
10
−4
10
−3
10
−2
10
−1
1 10 10
2
BETX BETY DX DY MUX MUY QX QY
Approximate log(10) of δK RMS Error
- J. Dilly
Response Matrix - Analytical Implementation of TwissResponse
24
Analytical Formulas Implementation Testing Setup Response Comparison MAD-X Comparison Conclusions
- J. Dilly
Response Matrix - Analytical Implementation of TwissResponse
25
Comparison to Mad-X results
- J. Dilly
Response Matrix - Analytical Implementation of TwissResponse
26
Single Variable Change
- Compared to MAD-X calculations the results are actually pretty bad
- But "at least" equally bad for both response matrices
- Best for
~ [10 , 10 ]
δK1L
δK
- 4.5
- 3.5
10
−6
10
−4
10
−2
1 10
2
BETX BETY DX DY MUX MUY QX QY
Analytical RMS Error
−6 −5 −4 −3 −2 −1
10
−6
10
−4
10
−2
1 10
2
BETX BETY DX DY MUX MUY QX QY
Approximate log(10) of δK Mad-X Resp. RMS Error
- J. Dilly
Response Matrix - Analytical Implementation of TwissResponse
27
Multi Variable Change
- Compared to MAD-X calculations the results are actually pretty bad
- But "at least" equally bad for both response matrices
- Best for
~ [10 , 10 ]
δK1L
δK
- 4.5
- 3.5
10
−6
10
−4
10
−2
1 10
2
BETX BETY DX DY MUX MUY QX QY
Analytical RMS Error
−6 −5 −4 −3 −2 −1
10
−6
10
−4
10
−2
1 10
2
BETX BETY DX DY MUX MUY QX QY
Approximate log(10) of δK Mad-X Resp. RMS Error
- J. Dilly
Response Matrix - Analytical Implementation of TwissResponse
28
Single Variable Change
δK0L
10
−6
10
−4
10
−2
1 10
2
BETX BETY DX DY MUX MUY QX QY
Analytical RMS Error
−6 −5 −4 −3 −2 −1
10
−6
10
−4
10
−2
1 10
2
BETX BETY DX DY MUX MUY QX QY
Approximate log(10) of δK Mad-X Resp. RMS Error
- J. Dilly
Response Matrix - Analytical Implementation of TwissResponse
29
Multi Variable Change
δK0L
10
−6
10
−4
10
−2
1 10
2
BETX BETY DX DY MUX MUY QX QY
Analytical RMS Error
−6 −5 −4 −3 −2 −1
10
−6
10
−4
10
−2
1 10
2
BETX BETY DX DY MUX MUY QX QY
Approximate log(10) of δK Mad-X Resp. RMS Error
- J. Dilly
Response Matrix - Analytical Implementation of TwissResponse
30
Single Variable Change
δK1SL
10
−6
10
−4
10
−2
1 10
2
BETX BETY DX DY MUX MUY QX QY
Analytical RMS Error
−6 −5 −4 −3 −2 −1
10
−6
10
−4
10
−2
1 10
2
BETX BETY DX DY MUX MUY QX QY
Approximate log(10) of δK Mad-X Resp. RMS Error
- J. Dilly
Response Matrix - Analytical Implementation of TwissResponse
31
Multi Variable Change
δK1SL
10
−6
10
−4
10
−2
1 10
2
BETX BETY DX DY MUX MUY QX QY
Analytical RMS Error
−6 −5 −4 −3 −2 −1
10
−6
10
−4
10
−2
1 10
2
BETX BETY DX DY MUX MUY QX QY
Approximate log(10) of δK Mad-X Resp. RMS Error
- J. Dilly
Response Matrix - Analytical Implementation of TwissResponse
32
Analytical Formulas Implementation Testing Setup Response Comparison MAD-X Comparison Conclusions
- J. Dilly
Response Matrix - Analytical Implementation of TwissResponse
33
Conclusions & Summary
- Analytical response matrices fully implemented and tested
- Accuracy wise MAD-X response and analytical response show similar results, for
"expected" parameters
- Influences on other parameters not more accurate in MAD-X response
Switch to analytical response possible
- Using response matrices always incorporates an error
- Should be coupled to an appropriate optimization algorithm
⇒
- J. Dilly
Response Matrix - Analytical Implementation of TwissResponse
34
Questions ?
35