mad_collider
This class is used to build a Xsuite collider from a madx sequence and optics.
MadCollider
MadCollider class is responsible for setting up and managing the collider environment using MAD-X and xsuite.
Attributes:
| Name | Type | Description |
|---|---|---|
sanity_checks |
bool
|
Flag to enable or disable sanity checks. |
links |
str
|
Path to the links configuration. |
beam_config |
dict
|
Configuration for the beam. |
optics |
str
|
Path to the optics file. |
enable_imperfections |
bool
|
Flag to enable or disable imperfections. |
enable_knob_synthesis |
bool
|
Flag to enable or disable knob synthesis. |
rename_coupling_knobs |
bool
|
Flag to enable or disable renaming of coupling knobs. |
pars_for_imperfections |
dict
|
Parameters for imperfections. |
ver_lhc_run |
float | None
|
Version of LHC run. |
ver_hllhc_optics |
float | None
|
Version of HL-LHC optics. |
ions |
bool
|
Flag to indicate if ions are used. |
phasing |
dict
|
Phasing configuration. |
path_collider_file_for_configuration_as_output |
str
|
Path to save the collider. |
compress |
bool
|
Flag to enable or disable compression of collider file. |
Methods:
| Name | Description |
|---|---|
ost |
Property to get the appropriate optics specific tools. |
prepare_mad_collider |
Prepares the MAD-X collider environment. |
build_collider |
Madx, mad_b4: Madx) -> xt.Multiline: Builds the xsuite collider. |
activate_RF_and_twiss |
xt.Multiline) -> None: Activates RF and performs twiss analysis. |
check_xsuite_lattices |
xt.Line) -> None: Checks the xsuite lattices. |
write_collider_to_disk |
xt.Multiline) -> None: Writes the collider to disk and optionally compresses it. |
clean_temporary_files |
Cleans up temporary files created during the process. |
Source code in study_da/generate/master_classes/mad_collider.py
33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 | |
ost: Any
property
Determines and returns the appropriate optics-specific tools (OST) based on the version of HLLHC optics or LHC run configuration.
Raises:
| Type | Description |
|---|---|
ValueError
|
If both |
ValueError
|
If no optics-specific tools are available for the given configuration. |
Returns:
| Name | Type | Description |
|---|---|---|
Any |
Any
|
The appropriate OST module based on the configuration. |
__init__(configuration)
Initializes the MadCollider class with the given configuration.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
configuration
|
dict
|
A dictionary containing the following keys: - sanity_checks (bool): Flag to enable or disable sanity checks. - links (str): Path to the links configuration. - beam_config (dict): Configuration for the beam. - optics_file (str): Path to the optics file. - enable_imperfections (bool): Flag to enable or disable imperfections. - enable_knob_synthesis (bool): Flag to enable or disable knob synthesis. - rename_coupling_knobs (bool): Flag to enable or disable renaming of coupling knobs. - pars_for_imperfections (dict): Parameters for imperfections. - ver_lhc_run (float | None): Version of the LHC run, if applicable. - ver_hllhc_optics (float | None): Version of the HL-LHC optics, if applicable. - ions (bool): Flag to indicate if ions are used. - phasing (dict): Configuration for phasing. - path_collider_file_for_configuration_as_output (str): Path to the collider. - compress (bool): Flag to enable or disable compression. |
required |
Source code in study_da/generate/master_classes/mad_collider.py
activate_RF_and_twiss(collider)
Activates RF and Twiss parameters for the given collider.
This method sets the RF knobs for the collider using the values specified
in the phasing attribute. It also performs sanity checks on the collider
lattices if the sanity_checks attribute is set to True.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
collider
|
Multiline
|
The collider object to configure. |
required |
Returns:
| Type | Description |
|---|---|
None
|
None |
Source code in study_da/generate/master_classes/mad_collider.py
build_collider(mad_b1b2, mad_b4)
Build an xsuite collider using provided MAD-X sequences and configuration.
Parameters: mad_b1b2 (Madx): MAD-X instance containing sequences for beam 1 and beam 2. mad_b4 (Madx): MAD-X instance containing sequence for beam 4.
Returns: xt.Multiline: Constructed xsuite collider.
Notes:
- Converts ver_lhc_run and ver_hllhc_optics to float if they are not None.
- Builds the xsuite collider with the specified sequences and configuration.
- Optionally performs sanity checks by computing Twiss parameters for beam 1 and beam 2.
Source code in study_da/generate/master_classes/mad_collider.py
check_xsuite_lattices(line)
Check the Twiss parameters and tune values for a given xsuite Line object.
This method computes the Twiss parameters for the provided line using the
6-dimensional method with a specified matrix stability tolerance. It then
prints the Twiss results at all interaction points (IPs) and the horizontal
(Qx) and vertical (Qy) tune values.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
line
|
Line
|
The xsuite Line object for which to compute and display the Twiss parameters and tune values. |
required |
Returns:
| Type | Description |
|---|---|
None
|
None |
Source code in study_da/generate/master_classes/mad_collider.py
clean_temporary_files()
staticmethod
Remove all the temporary files created in the process of building the collider.
This function deletes the following files and directories: - "mad_collider.log" - "mad_b4.log" - "temp" directory - "errors" - "acc-models-lhc"
Source code in study_da/generate/master_classes/mad_collider.py
prepare_mad_collider()
Prepares the MAD-X collider environment and sequences for beam 1/2 and beam 4.
This method performs the following steps: 1. Creates the MAD-X environment using the provided links. 2. Initializes MAD-X instances for beam 1/2 and beam 4 with respective command logs. 3. Builds the sequences for both beams using the provided beam configuration. 4. Applies the specified optics to the beam 1/2 sequence. 5. Optionally performs sanity checks on the beam 1/2 sequence by running TWISS and checking the MAD-X lattices. 6. Applies the specified optics to the beam 4 sequence. 7. Optionally performs sanity checks on the beam 4 sequence by running TWISS and checking the MAD-X lattices.
Returns:
| Type | Description |
|---|---|
tuple[Madx, Madx]
|
tuple[Madx, Madx]: A tuple containing the MAD-X instances for beam 1/2 and beam 4. |
Source code in study_da/generate/master_classes/mad_collider.py
write_collider_to_disk(collider)
Writes the collider object to disk in JSON format and optionally compresses it into a ZIP file.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
collider
|
Multiline
|
The collider object to be saved. |
required |
Returns:
| Type | Description |
|---|---|
None
|
None |
Raises:
| Type | Description |
|---|---|
OSError
|
If there is an issue creating the directory or writing the file. |
Notes
- The method ensures that the directory specified in
self.path_collider_file_for_configuration_as_outputexists. - If
self.compressis True, the JSON file is compressed into a ZIP file to reduce storage usage.