Optimisation de l'optique pour une résonance du troisième ordre¶

In [1]:
import matplotlib.pyplot as plt
import numpy as np
import xplt
import xtrack as xt

%config InlineBackend.figure_format = "retina"

Chargement de la maille exportée précédemment¶

In [2]:
env = xt.Environment.from_json("pimms.json")
ring = env["ring"]
In [3]:
# Attribuons de faibles valeurs pour obtenir un Twiss stable
env["kqfa"] = 1e-2
env["kqfb"] = 1e-2
env["kqd"] = -2e-2
In [4]:
twiss = ring.twiss4d(compute_chromatic_properties=False)
xplt.TwissPlot(twiss, ["d", "bet"]);
No description has been provided for this image

Ajustement des nombres d'onde¶

In [5]:
opt_tune = ring.match(
    solve=False,  # <- prépare uniquement
    vary=[
        xt.Vary("kqfa", limits=(0, 10), step=1e-3),
        xt.Vary("kqfb", limits=(0, 10), step=1e-3),
        xt.Vary("kqd", limits=(-10, 0), step=1e-3),
    ],
    targets=[  # à proximité d'une résonance du 3ème ordre (3qx~5, 2qx+qy~5, qx+2qy~5)
        xt.TargetSet(qx=1.665, qy=1.72, tol=1e-4),
    ],
    compute_chromatic_properties=False,
    method="4d",
)
In [6]:
opt_tune.run_jacobian(30)
                                             
Matching: model call n. 1 penalty = 1.6354e+01              
Optimize - start penalty: 16.35                         
Matching: model call n. 2 penalty = 1.6354e+01              
Matching: model call n. 3 penalty = 1.5901e+01              
Matching: model call n. 4 penalty = 1.5902e+01              
Matching: model call n. 5 penalty = 1.5908e+01              
Matching: model call n. 6 penalty = 8.5666e+00              
Matching: model call n. 7 penalty = 8.5666e+00              
Matching: model call n. 8 penalty = 8.5545e+00              
Matching: model call n. 9 penalty = 8.5555e+00              
Matching: model call n. 10 penalty = 8.5363e+00              
Matching: model call n. 11 penalty = 8.4719e-01              
Matching: model call n. 12 penalty = 8.4719e-01              
Matching: model call n. 13 penalty = 8.3800e-01              
Matching: model call n. 14 penalty = 8.3917e-01              
Matching: model call n. 15 penalty = 8.2100e-01              
Matching: model call n. 16 penalty = 1.2875e-02              
Matching: model call n. 17 penalty = 1.2875e-02              
Matching: model call n. 18 penalty = 2.6505e-02              
Matching: model call n. 19 penalty = 2.7799e-02              
Matching: model call n. 20 penalty = 2.1943e-02              
Matching: model call n. 21 penalty = 5.5530e-06              
Optimize - end penalty:  5.55305e-06                            
In [7]:
opt_tune.target_status()
Matching: model call n. 22 penalty = 5.5530e-06              
Target status:               
id state tag tol_met       residue   current_val    target_val description                           
0  ON    qx     True  -4.86058e-07         1.665         1.665 'qx', val=1.665, tol=0.0001, weight=10
1  ON    qy     True   2.68534e-07          1.72          1.72 'qy', val=1.72, tol=0.0001, weight=10 
In [8]:
opt_tune.vary_status()
Vary status:                 
id state tag met name lower_limit   current_val upper_limit val_at_iter_0          step        weight
0  ON        OK  kqfa           0      0.440823          10          0.01         0.001             1
1  ON        OK  kqfb           0      0.448292          10          0.01         0.001             1
2  ON        OK  kqd          -10     -0.588114           0         -0.02         0.001             1
In [9]:
# Inspection de l'optique
twiss = ring.twiss4d()
plot = xplt.TwissPlot(twiss, ["d", "bet"])
plot.axis("dx").set(ylim=(-1, 10))
plot.axis("betx").set(ylim=(0, 20));
No description has been provided for this image

Addition d'une contrainte de dispersion nulle au centre des sections droites longues¶

In [10]:
# On clone l'optimiseur pour préserver les contraintes précédentes
opt_disp = opt_tune.clone(
    add_targets=[
        xt.TargetSet(dx=0, at="mid.lss.0"),
        xt.TargetSet(dx=0, at="mid.lss.1"),
    ]
)
opt_disp.target_status()
Matching: model call n. 1 penalty = 6.9037e+01              
Target status:               
id state tag          tol_met       residue   current_val    target_val description                                 
0  ON    qx              True  -4.86058e-07         1.665         1.665 'qx', val=1.665, tol=0.0001, weight=10      
1  ON    qy              True   2.68534e-07          1.72          1.72 'qy', val=1.72, tol=0.0001, weight=10       
2  ON    mid.lss.0_dx   False       4.88163       4.88163             0 ('dx', 'mid.lss.0'), val=0, tol=1e-09, w ...
3  ON    mid.lss.1_dx   False       4.88163       4.88163             0 ('dx', 'mid.lss.1'), val=0, tol=1e-09, w ...
In [11]:
opt_disp.run_simplex(100)  # Nelder-Mead optimisation algorithm
                                             
Matching: model call n. 2 penalty = 6.9037e+01              
Optimize - start penalty: 69.04                         
Matching: model call n. 3 penalty = 6.9037e+01              
Matching: model call n. 4 penalty = 7.4097e+01              
Matching: model call n. 5 penalty = 5.7927e+01              
Matching: model call n. 6 penalty = 7.1245e+01              
Matching: model call n. 7 penalty = 5.8824e+01              
Matching: model call n. 8 penalty = 5.1966e+01              
Matching: model call n. 9 penalty = 4.4987e+01              
Matching: model call n. 10 penalty = 3.7398e+01              
Matching: model call n. 11 penalty = 2.5885e+01              
Matching: model call n. 12 penalty = 2.4642e+01              
Matching: model call n. 13 penalty = 8.6021e+00              
Matching: model call n. 14 penalty = 9.0376e+00              
Matching: model call n. 15 penalty = 4.0710e+01              
Matching: model call n. 16 penalty = 1.7278e+01              
Matching: model call n. 17 penalty = 2.0000e+100              
Matching: model call n. 18 penalty = 1.4506e+01              
Matching: model call n. 19 penalty = 2.4009e+01              
Matching: model call n. 20 penalty = 8.1387e+00              
Matching: model call n. 21 penalty = 3.1137e+01              
Matching: model call n. 22 penalty = 8.1214e+00              
Matching: model call n. 23 penalty = 1.5314e+01              
Matching: model call n. 24 penalty = 5.0274e+00              
Matching: model call n. 25 penalty = 7.9244e+00              
Matching: model call n. 26 penalty = 4.2209e+00              
Matching: model call n. 27 penalty = 6.8789e+00              
Matching: model call n. 28 penalty = 1.2159e+01              
Matching: model call n. 29 penalty = 4.1288e+00              
Matching: model call n. 30 penalty = 1.1650e+01              
Matching: model call n. 31 penalty = 4.7262e+00              
Matching: model call n. 32 penalty = 5.1769e+00              
Matching: model call n. 33 penalty = 3.2657e+00              
Matching: model call n. 34 penalty = 8.3969e+00              
Matching: model call n. 35 penalty = 2.9146e+00              
Matching: model call n. 36 penalty = 5.2649e+00              
Matching: model call n. 37 penalty = 3.1559e+00              
Matching: model call n. 38 penalty = 4.6878e+00              
Matching: model call n. 39 penalty = 3.0196e+00              
Matching: model call n. 40 penalty = 3.6418e+00              
Matching: model call n. 41 penalty = 2.6754e+00              
Matching: model call n. 42 penalty = 3.8437e+00              
Matching: model call n. 43 penalty = 2.6519e+00              
Matching: model call n. 44 penalty = 3.4746e+00              
Matching: model call n. 45 penalty = 2.5952e+00              
Matching: model call n. 46 penalty = 3.7019e+00              
Matching: model call n. 47 penalty = 2.5454e+00              
Matching: model call n. 48 penalty = 2.6841e+00              
Matching: model call n. 49 penalty = 2.5215e+00              
Matching: model call n. 50 penalty = 2.8896e+00              
Matching: model call n. 51 penalty = 2.4996e+00              
Matching: model call n. 52 penalty = 2.6646e+00              
Matching: model call n. 53 penalty = 2.4889e+00              
Matching: model call n. 54 penalty = 2.8699e+00              
Matching: model call n. 55 penalty = 2.4569e+00              
Matching: model call n. 56 penalty = 2.4601e+00              
Matching: model call n. 57 penalty = 2.4151e+00              
Matching: model call n. 58 penalty = 2.4437e+00              
Matching: model call n. 59 penalty = 2.3600e+00              
Matching: model call n. 60 penalty = 2.3613e+00              
Matching: model call n. 61 penalty = 2.7350e+00              
Matching: model call n. 62 penalty = 2.3915e+00              
Matching: model call n. 63 penalty = 2.3405e+00              
Matching: model call n. 64 penalty = 2.3425e+00              
Matching: model call n. 65 penalty = 2.3075e+00              
Matching: model call n. 66 penalty = 2.2943e+00              
Matching: model call n. 67 penalty = 2.2312e+00              
Matching: model call n. 68 penalty = 2.1840e+00              
Matching: model call n. 69 penalty = 2.2848e+00              
Matching: model call n. 70 penalty = 2.1275e+00              
Matching: model call n. 71 penalty = 2.0642e+00              
Matching: model call n. 72 penalty = 2.0073e+00              
Matching: model call n. 73 penalty = 1.9125e+00              
Matching: model call n. 74 penalty = 1.8751e+00              
Matching: model call n. 75 penalty = 1.8208e+00              
Matching: model call n. 76 penalty = 1.6169e+00              
Matching: model call n. 77 penalty = 1.4587e+00              
Matching: model call n. 78 penalty = 1.3966e+00              
Matching: model call n. 79 penalty = 1.2755e+00              
Matching: model call n. 80 penalty = 1.1390e+00              
Matching: model call n. 81 penalty = 1.0632e+00              
Matching: model call n. 82 penalty = 4.4545e-01              
Matching: model call n. 83 penalty = 2.3806e-01              
Matching: model call n. 84 penalty = 1.2684e+00              
Matching: model call n. 85 penalty = 1.2921e+00              
Matching: model call n. 86 penalty = 9.6148e-01              
Matching: model call n. 87 penalty = 1.1570e+00              
Matching: model call n. 88 penalty = 8.2990e-01              
Matching: model call n. 89 penalty = 4.4198e-01              
Matching: model call n. 90 penalty = 6.9883e-01              
Matching: model call n. 91 penalty = 9.4029e-01              
Matching: model call n. 92 penalty = 5.3456e-01              
Matching: model call n. 93 penalty = 7.4013e-01              
Matching: model call n. 94 penalty = 4.7583e-01              
Matching: model call n. 95 penalty = 4.7478e-01              
Matching: model call n. 96 penalty = 2.5714e-01              
Matching: model call n. 97 penalty = 4.6895e-01              
Matching: model call n. 98 penalty = 3.0285e-01              
Matching: model call n. 99 penalty = 6.3571e-01              
Matching: model call n. 100 penalty = 2.5757e-01              
Matching: model call n. 101 penalty = 3.3484e-01              
Matching: model call n. 102 penalty = 2.2311e-01              
Matching: model call n. 103 penalty = 4.5547e-01              
Matching: model call n. 104 penalty = 1.8381e-01              

Matching: model call n. 105 penalty = 2.7564e-01              
Matching: model call n. 106 penalty = 2.1019e-01              
Matching: model call n. 107 penalty = 2.2685e-01              
Matching: model call n. 108 penalty = 1.9609e-01              
Matching: model call n. 109 penalty = 1.6969e-01              
Matching: model call n. 110 penalty = 1.9718e-01              
Matching: model call n. 111 penalty = 2.6403e-01              
Matching: model call n. 112 penalty = 1.7650e-01              
Matching: model call n. 113 penalty = 2.0530e-01              
Matching: model call n. 114 penalty = 1.7522e-01              
Matching: model call n. 115 penalty = 1.8033e-01              
Matching: model call n. 116 penalty = 1.6916e-01              
Matching: model call n. 117 penalty = 1.6303e-01              
Matching: model call n. 118 penalty = 1.7310e-01              
Matching: model call n. 119 penalty = 1.9644e-01              
Matching: model call n. 120 penalty = 1.6359e-01              
Matching: model call n. 121 penalty = 1.6457e-01              
Matching: model call n. 122 penalty = 1.8983e-01              
Matching: model call n. 123 penalty = 1.6098e-01              
Matching: model call n. 124 penalty = 1.6768e-01              
Matching: model call n. 125 penalty = 1.6091e-01              
Matching: model call n. 126 penalty = 1.5559e-01              
Matching: model call n. 127 penalty = 1.5507e-01              
Matching: model call n. 128 penalty = 1.6607e-01              
Matching: model call n. 129 penalty = 1.5860e-01              
Matching: model call n. 130 penalty = 1.5802e-01              
Matching: model call n. 131 penalty = 1.6320e-01              
Matching: model call n. 132 penalty = 1.5736e-01              
Matching: model call n. 133 penalty = 1.5159e-01              
Matching: model call n. 134 penalty = 1.4938e-01              
Matching: model call n. 135 penalty = 1.5548e-01              
Matching: model call n. 136 penalty = 1.5297e-01              
Matching: model call n. 137 penalty = 1.5108e-01              
Matching: model call n. 138 penalty = 1.4347e-01              
Matching: model call n. 139 penalty = 1.3964e-01              
Matching: model call n. 140 penalty = 1.4905e-01              
Matching: model call n. 141 penalty = 1.4306e-01              
Matching: model call n. 142 penalty = 1.3651e-01              
Matching: model call n. 143 penalty = 1.3381e-01              
Matching: model call n. 144 penalty = 1.2682e-01              
Matching: model call n. 145 penalty = 1.2194e-01              
Matching: model call n. 146 penalty = 1.2084e-01              
Matching: model call n. 147 penalty = 1.1886e-01              
Matching: model call n. 148 penalty = 1.0178e-01              
Matching: model call n. 149 penalty = 9.0329e-02              
Matching: model call n. 150 penalty = 9.9413e-02              
Matching: model call n. 151 penalty = 9.0499e-02              
Matching: model call n. 152 penalty = 5.4400e-02              
Matching: model call n. 153 penalty = 3.3206e-02              
Matching: model call n. 154 penalty = 6.6426e-02              
Matching: model call n. 155 penalty = 6.6152e-02              
Matching: model call n. 156 penalty = 4.0658e-02              
Matching: model call n. 157 penalty = 3.7557e-02              
Matching: model call n. 158 penalty = 4.5534e-02              
Matching: model call n. 159 penalty = 2.3044e-02              
Matching: model call n. 160 penalty = 5.3781e-02              
Matching: model call n. 161 penalty = 2.1475e-02              
Matching: model call n. 162 penalty = 4.6596e-02              
Matching: model call n. 163 penalty = 2.0016e-02              
Matching: model call n. 164 penalty = 5.9314e-02              
Matching: model call n. 165 penalty = 1.3920e-02              
Matching: model call n. 166 penalty = 3.2503e-02              
Matching: model call n. 167 penalty = 1.2537e-02              
Matching: model call n. 168 penalty = 2.5908e-02              
Matching: model call n. 169 penalty = 1.2331e-02              
Matching: model call n. 170 penalty = 2.0160e-02              
Matching: model call n. 171 penalty = 1.1747e-02              
Matching: model call n. 172 penalty = 3.1578e-02              
Matching: model call n. 173 penalty = 4.5791e-03              
Matching: model call n. 174 penalty = 1.6250e-02              
Matching: model call n. 175 penalty = 7.9682e-03              
Matching: model call n. 176 penalty = 1.2392e-02              
Matching: model call n. 177 penalty = 8.1644e-03              
Matching: model call n. 178 penalty = 8.0183e-03              

Matching: model call n. 179 penalty = 1.0880e-02              
Matching: model call n. 180 penalty = 4.6860e-03              
Matching: model call n. 181 penalty = 4.5791e-03              
Matching: model call n. 182 penalty = 4.5791e-03              
Optimize - end penalty:  0.0045791                            
In [12]:
# Inspect the optics
twiss = ring.twiss4d()
plot = xplt.TwissPlot(twiss, ["d", "bet"])
plot.axis("dx").set(ylim=(-1, 10))
plot.axis("betx").set(ylim=(0, 20));
No description has been provided for this image

Ajustement de la chromaticité¶

In [13]:
opt_chrom = ring.match(
    solve=False,
    method="4d",
    vary=xt.VaryList(["ksf", "ksd"], step=1e-3),
    targets=xt.TargetSet(dqx=-0.01, dqy=-0.01, tol=1e-3),
)
In [14]:
opt_chrom.run_ls_dogbox(30)  # Least squares, dobgox algorithm
opt_chrom.target_status()
Matching: model call n. 1 penalty = 1.2107e+00              
Matching: model call n. 2 penalty = 1.2107e+00              
Matching: model call n. 3 penalty = 1.2104e+00              
Matching: model call n. 4 penalty = 1.2120e+00              
Matching: model call n. 5 penalty = 9.2934e-05              
Matching: model call n. 6 penalty = 9.2934e-05              
Matching: model call n. 7 penalty = 1.6326e-03              
Matching: model call n. 8 penalty = 1.7756e-03              
Matching: model call n. 9 penalty = 8.2382e-08              
Matching: model call n. 10 penalty = 8.2382e-08              
Matching: model call n. 11 penalty = 1.7205e-03              
Matching: model call n. 12 penalty = 1.8007e-03              
Matching: model call n. 13 penalty = 1.3762e-07              
Matching: model call n. 14 penalty = 6.1641e-08              
Matching: model call n. 15 penalty = 6.1641e-08              
Matching: model call n. 16 penalty = 1.7208e-03              
Matching: model call n. 17 penalty = 1.8006e-03              
Matching: model call n. 18 penalty = 3.4042e-07              
Matching: model call n. 19 penalty = 2.2214e-07              
Matching: model call n. 20 penalty = 3.3353e-07              
Matching: model call n. 21 penalty = 4.9973e-08              
Matching: model call n. 22 penalty = 4.9973e-08              
Matching: model call n. 23 penalty = 1.7208e-03              
Matching: model call n. 24 penalty = 1.8006e-03              
Matching: model call n. 25 penalty = 3.3669e-08              
Matching: model call n. 26 penalty = 3.3669e-08              
Matching: model call n. 27 penalty = 1.7206e-03              
Matching: model call n. 28 penalty = 1.8006e-03              
Matching: model call n. 29 penalty = 1.3897e-07              
Matching: model call n. 30 penalty = 2.2932e-07              
Matching: model call n. 31 penalty = 1.8535e-08              
Matching: model call n. 32 penalty = 1.8535e-08              
Matching: model call n. 33 penalty = 1.7207e-03              
Matching: model call n. 34 penalty = 1.8007e-03              
Matching: model call n. 35 penalty = 1.9033e-08              
Matching: model call n. 36 penalty = 3.2041e-08              
Matching: model call n. 37 penalty = 5.8290e-08              
Matching: model call n. 38 penalty = 3.3866e-08              
Matching: model call n. 39 penalty = 2.1110e-08              

Matching: model call n. 40 penalty = 1.8539e-08              
Matching: model call n. 41 penalty = 1.8535e-08              
Matching: model call n. 42 penalty = 1.8535e-08              
Matching: model call n. 43 penalty = 1.8535e-08              
Target status:               
id state tag tol_met       residue   current_val    target_val description                          
0  ON    dqx    True  -1.15255e-08         -0.01         -0.01 'dqx', val=-0.01, tol=0.001, weight=1
1  ON    dqy    True   1.45159e-08   -0.00999999         -0.01 'dqy', val=-0.01, tol=0.001, weight=1

Déformation de l'espace des phases lors de l'excitation de la résonance¶

In [15]:
# Alimentation du sextupôle d'extraction
env["kse"] = 6
In [16]:
# Génération de 20 particules sur l'axe horizontal
x_gen = np.linspace(0, 0.5e-2, 20)
parts = ring.build_particles(x=x_gen, px=0, y=0, py=0, zeta=0, delta=0)

# Tracking des particules pour 1000 tours
ring.track(parts, num_turns=1000, turn_by_turn_monitor=True)
record = ring.record_last_track
In [17]:
plt.figure()
plt.plot(record.x.T, record.px.T, ".", markersize=1, color="C0")
plt.xlim(-2e-2, 2e-2)
plt.ylim(-2e-3, 2e-3)
plt.xlabel(r"$x$ [m]")
plt.ylabel(r"$p_x$")
plt.title("Espace des phases horizontal")
plt.subplots_adjust(left=0.15)
plt.show()
No description has been provided for this image

Export des alimentations en fichier JSON¶

In [18]:
# Valeurs des résultats des optimiseurs
quad_strengths: dict[str, float] = opt_disp.get_knob_values()
sext_strengths: dict[str, float] = opt_chrom.get_knob_values()
In [19]:
# Fusion et export en fichier
strengths = quad_strengths | sext_strengths
xt.json.dump(strengths, "pimms_strengths.json")