xcoll 0.6.2__tar.gz → 0.6.3__tar.gz

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.

Potentially problematic release.


This version of xcoll might be problematic. Click here for more details.

Files changed (66) hide show
  1. {xcoll-0.6.2 → xcoll-0.6.3}/PKG-INFO +15 -11
  2. xcoll-0.6.3/pyproject.toml +63 -0
  3. {xcoll-0.6.2 → xcoll-0.6.3}/xcoll/__init__.py +1 -1
  4. {xcoll-0.6.2 → xcoll-0.6.3}/xcoll/general.py +1 -1
  5. xcoll-0.6.3/xcoll/prebuild_kernels/__init__.py +7 -0
  6. xcoll-0.6.3/xcoll/prebuild_kernels/element_inits.py +6 -0
  7. xcoll-0.6.3/xcoll/prebuild_kernels/elements.py +20 -0
  8. xcoll-0.6.3/xcoll/rf_sweep.py +182 -0
  9. xcoll-0.6.2/pyproject.toml +0 -52
  10. xcoll-0.6.2/xcoll/rf_sweep.py +0 -197
  11. {xcoll-0.6.2 → xcoll-0.6.3}/LICENSE +0 -0
  12. {xcoll-0.6.2 → xcoll-0.6.3}/NOTICE +0 -0
  13. {xcoll-0.6.2 → xcoll-0.6.3}/README.md +0 -0
  14. {xcoll-0.6.2 → xcoll-0.6.3}/xcoll/beam_elements/__init__.py +0 -0
  15. {xcoll-0.6.2 → xcoll-0.6.3}/xcoll/beam_elements/absorber.py +0 -0
  16. {xcoll-0.6.2 → xcoll-0.6.3}/xcoll/beam_elements/base.py +0 -0
  17. {xcoll-0.6.2 → xcoll-0.6.3}/xcoll/beam_elements/blowup.py +0 -0
  18. {xcoll-0.6.2 → xcoll-0.6.3}/xcoll/beam_elements/elements_src/black_absorber.h +0 -0
  19. {xcoll-0.6.2 → xcoll-0.6.3}/xcoll/beam_elements/elements_src/black_crystal.h +0 -0
  20. {xcoll-0.6.2 → xcoll-0.6.3}/xcoll/beam_elements/elements_src/blowup.h +0 -0
  21. {xcoll-0.6.2 → xcoll-0.6.3}/xcoll/beam_elements/elements_src/emittance_monitor.h +0 -0
  22. {xcoll-0.6.2 → xcoll-0.6.3}/xcoll/beam_elements/elements_src/everest_block.h +0 -0
  23. {xcoll-0.6.2 → xcoll-0.6.3}/xcoll/beam_elements/elements_src/everest_collimator.h +0 -0
  24. {xcoll-0.6.2 → xcoll-0.6.3}/xcoll/beam_elements/elements_src/everest_crystal.h +0 -0
  25. {xcoll-0.6.2 → xcoll-0.6.3}/xcoll/beam_elements/elements_src/transparent_collimator.h +0 -0
  26. {xcoll-0.6.2 → xcoll-0.6.3}/xcoll/beam_elements/elements_src/transparent_crystal.h +0 -0
  27. {xcoll-0.6.2 → xcoll-0.6.3}/xcoll/beam_elements/everest.py +0 -0
  28. {xcoll-0.6.2 → xcoll-0.6.3}/xcoll/beam_elements/monitor.py +0 -0
  29. {xcoll-0.6.2 → xcoll-0.6.3}/xcoll/beam_elements/transparent.py +0 -0
  30. {xcoll-0.6.2 → xcoll-0.6.3}/xcoll/colldb.py +0 -0
  31. {xcoll-0.6.2 → xcoll-0.6.3}/xcoll/headers/checks.h +0 -0
  32. {xcoll-0.6.2 → xcoll-0.6.3}/xcoll/headers/particle_states.py +0 -0
  33. {xcoll-0.6.2 → xcoll-0.6.3}/xcoll/initial_distribution.py +0 -0
  34. {xcoll-0.6.2 → xcoll-0.6.3}/xcoll/interaction_record/__init__.py +0 -0
  35. {xcoll-0.6.2 → xcoll-0.6.3}/xcoll/interaction_record/interaction_record.py +0 -0
  36. {xcoll-0.6.2 → xcoll-0.6.3}/xcoll/interaction_record/interaction_record_src/interaction_record.h +0 -0
  37. {xcoll-0.6.2 → xcoll-0.6.3}/xcoll/interaction_record/interaction_types.py +0 -0
  38. {xcoll-0.6.2 → xcoll-0.6.3}/xcoll/line_tools.py +0 -0
  39. {xcoll-0.6.2 → xcoll-0.6.3}/xcoll/lossmap.py +0 -0
  40. {xcoll-0.6.2 → xcoll-0.6.3}/xcoll/plot.py +0 -0
  41. {xcoll-0.6.2 → xcoll-0.6.3}/xcoll/scattering_routines/engine.py +0 -0
  42. {xcoll-0.6.2 → xcoll-0.6.3}/xcoll/scattering_routines/environment.py +0 -0
  43. {xcoll-0.6.2 → xcoll-0.6.3}/xcoll/scattering_routines/everest/__init__.py +0 -0
  44. {xcoll-0.6.2 → xcoll-0.6.3}/xcoll/scattering_routines/everest/amorphous.h +0 -0
  45. {xcoll-0.6.2 → xcoll-0.6.3}/xcoll/scattering_routines/everest/channelling.h +0 -0
  46. {xcoll-0.6.2 → xcoll-0.6.3}/xcoll/scattering_routines/everest/constants.h +0 -0
  47. {xcoll-0.6.2 → xcoll-0.6.3}/xcoll/scattering_routines/everest/crystal_parameters.h +0 -0
  48. {xcoll-0.6.2 → xcoll-0.6.3}/xcoll/scattering_routines/everest/everest.h +0 -0
  49. {xcoll-0.6.2 → xcoll-0.6.3}/xcoll/scattering_routines/everest/everest.py +0 -0
  50. {xcoll-0.6.2 → xcoll-0.6.3}/xcoll/scattering_routines/everest/ionisation_loss.h +0 -0
  51. {xcoll-0.6.2 → xcoll-0.6.3}/xcoll/scattering_routines/everest/jaw.h +0 -0
  52. {xcoll-0.6.2 → xcoll-0.6.3}/xcoll/scattering_routines/everest/materials.py +0 -0
  53. {xcoll-0.6.2 → xcoll-0.6.3}/xcoll/scattering_routines/everest/multiple_coulomb_scattering.h +0 -0
  54. {xcoll-0.6.2 → xcoll-0.6.3}/xcoll/scattering_routines/everest/nuclear_interaction.h +0 -0
  55. {xcoll-0.6.2 → xcoll-0.6.3}/xcoll/scattering_routines/everest/properties.h +0 -0
  56. {xcoll-0.6.2 → xcoll-0.6.3}/xcoll/scattering_routines/geometry/__init__.py +0 -0
  57. {xcoll-0.6.2 → xcoll-0.6.3}/xcoll/scattering_routines/geometry/collimator_geometry.h +0 -0
  58. {xcoll-0.6.2 → xcoll-0.6.3}/xcoll/scattering_routines/geometry/crystal_geometry.h +0 -0
  59. {xcoll-0.6.2 → xcoll-0.6.3}/xcoll/scattering_routines/geometry/geometry.py +0 -0
  60. {xcoll-0.6.2 → xcoll-0.6.3}/xcoll/scattering_routines/geometry/get_s.h +0 -0
  61. {xcoll-0.6.2 → xcoll-0.6.3}/xcoll/scattering_routines/geometry/methods.h +0 -0
  62. {xcoll-0.6.2 → xcoll-0.6.3}/xcoll/scattering_routines/geometry/objects.h +0 -0
  63. {xcoll-0.6.2 → xcoll-0.6.3}/xcoll/scattering_routines/geometry/rotation.h +0 -0
  64. {xcoll-0.6.2 → xcoll-0.6.3}/xcoll/scattering_routines/geometry/segments.h +0 -0
  65. {xcoll-0.6.2 → xcoll-0.6.3}/xcoll/scattering_routines/geometry/sort.h +0 -0
  66. {xcoll-0.6.2 → xcoll-0.6.3}/xcoll/xaux.py +0 -0
@@ -1,15 +1,13 @@
1
1
  Metadata-Version: 2.3
2
2
  Name: xcoll
3
- Version: 0.6.2
3
+ Version: 0.6.3
4
4
  Summary: Xsuite collimation package
5
- License: Apache 2.0
5
+ License: Apache-2.0
6
6
  Author: Frederik F. Van der Veken
7
7
  Author-email: frederik@cern.ch
8
- Requires-Python: >=3.8
9
- Classifier: License :: Other/Proprietary License
8
+ Requires-Python: >=3.10
9
+ Classifier: License :: OSI Approved :: Apache Software License
10
10
  Classifier: Programming Language :: Python :: 3
11
- Classifier: Programming Language :: Python :: 3.8
12
- Classifier: Programming Language :: Python :: 3.9
13
11
  Classifier: Programming Language :: Python :: 3.10
14
12
  Classifier: Programming Language :: Python :: 3.11
15
13
  Classifier: Programming Language :: Python :: 3.12
@@ -17,13 +15,19 @@ Classifier: Programming Language :: Python :: 3.13
17
15
  Provides-Extra: tests
18
16
  Requires-Dist: numpy (>=1.0)
19
17
  Requires-Dist: pandas (>=1.4)
20
- Requires-Dist: ruamel-yaml (>=0.17.31,<0.18.0) ; extra == "tests"
21
- Requires-Dist: xdeps (>=0.10.5)
22
- Requires-Dist: xobjects (>=0.5.0)
23
- Requires-Dist: xpart (>=0.23.0)
24
- Requires-Dist: xtrack (>=0.84.8)
18
+ Requires-Dist: pytest ; extra == "tests"
19
+ Requires-Dist: pytest-html ; extra == "tests"
20
+ Requires-Dist: pytest-xdist ; extra == "tests"
21
+ Requires-Dist: ruamel-yaml (>=0.17.31,<0.18.15)
22
+ Requires-Dist: xdeps (>=0.10.6)
23
+ Requires-Dist: xobjects (>=0.5.2)
24
+ Requires-Dist: xpart (>=0.23.1)
25
+ Requires-Dist: xtrack (>=0.89.3)
26
+ Project-URL: Bug Tracker, https://github.com/xsuite/xsuite/issues
27
+ Project-URL: Documentation, https://xsuite.readthedocs.io/
25
28
  Project-URL: Homepage, https://github.com/xsuite/xcoll
26
29
  Project-URL: Repository, https://github.com/xsuite/xcoll
30
+ Project-URL: download, https://pypi.python.org/pypi/xcoll
27
31
  Description-Content-Type: text/markdown
28
32
 
29
33
  # xcoll
@@ -0,0 +1,63 @@
1
+ [project]
2
+ name = "xcoll"
3
+ version = "0.6.3"
4
+ description = "Xsuite collimation package"
5
+ authors = [
6
+ {name="Frederik F. Van der Veken", email="frederik@cern.ch"},
7
+ {name="Simone O. Solstrand", email="simone.otelie.solstrand@cern.ch"},
8
+ {name="Björn Lindstrom", email="bjorn.lindstrom@cern.ch"},
9
+ {name="Giacomo Broggi", email="giacomo.broggi@cern.ch"},
10
+ {name="André Donadon Servelle", email="andre.donadon.servelle@cern.ch"},
11
+ {name="Dora E. Veres", email="dora.erzsebet.veres@cern.ch"},
12
+ {name="Despina Demetriadou", email="despina.demetriadou@cern.ch"},
13
+ {name="Andrey Abramov", email="andrey.abramov@cern.ch"},
14
+ {name="Giovanni Iadarola", email="giovanni.iadarola@cern.ch"}
15
+ ]
16
+ readme = "README.md"
17
+ license = {text="Apache-2.0"}
18
+
19
+ requires-python = ">=3.10"
20
+
21
+ dependencies = [
22
+ "ruamel-yaml (>=0.17.31,<0.18.15)",
23
+ "numpy>=1.0",
24
+ "pandas>=1.4",
25
+ "xobjects>=0.5.2",
26
+ "xdeps>=0.10.6",
27
+ "xpart>=0.23.1",
28
+ "xtrack>=0.89.3",
29
+ ]
30
+
31
+ [project.optional-dependencies]
32
+ tests = ["pytest", "pytest-html", "pytest-xdist"]
33
+
34
+ [project.urls]
35
+ homepage = "https://github.com/xsuite/xcoll"
36
+ repository = "https://github.com/xsuite/xcoll"
37
+ documentation = "https://xsuite.readthedocs.io/"
38
+ "Bug Tracker" = "https://github.com/xsuite/xsuite/issues"
39
+ download = "https://pypi.python.org/pypi/xcoll"
40
+
41
+ [project.entry-points.xobjects]
42
+ include = "xcoll"
43
+
44
+ [tool.poetry]
45
+ exclude = ["xcoll/lib", "xcoll/config"]
46
+
47
+ [poetry.group.dev.dependencies]
48
+ pytest = ">=7.3"
49
+ xaux = ">=0.3.5"
50
+
51
+ [build-system]
52
+ # Needed for pip install -e (BTW: need pip version 22)
53
+ requires = ["poetry-core>=1.0.8"]
54
+ build-backend = "poetry.core.masonry.api"
55
+
56
+ # pyproject.toml
57
+ #[tool.pytest.ini_options]
58
+ #addopts = "-ra --durations=10 --durations-min=1"
59
+ #python_functions = ["test_"]
60
+ #testpaths = [
61
+ # "tests",
62
+ #]
63
+
@@ -11,7 +11,7 @@ from .beam_elements import BlackAbsorber, BlackCrystal, TransparentCollimator, T
11
11
  from .scattering_routines.everest import materials, Material, CrystalMaterial
12
12
  from .colldb import CollimatorDatabase
13
13
  from .interaction_record import InteractionRecord
14
- from .rf_sweep import RFSweep
14
+ from .rf_sweep import RFSweep, prepare_rf_sweep
15
15
  from .lossmap import LossMap, MultiLossMap
16
16
 
17
17
 
@@ -12,5 +12,5 @@ citation = "F.F. Van der Veken, et al.: Recent Developments with the New Tools f
12
12
  # ======================
13
13
  # Do not change
14
14
  # ======================
15
- __version__ = '0.6.2'
15
+ __version__ = '0.6.3'
16
16
  # ======================
@@ -0,0 +1,7 @@
1
+ # copyright ############################### #
2
+ # This file is part of the Xcoll package. #
3
+ # Copyright (c) CERN, 2025. #
4
+ # ######################################### #
5
+
6
+ from .elements import DEFAULT_XCOLL_ELEMENTS
7
+ from .element_inits import XCOLL_ELEMENTS_INIT_DEFAULTS
@@ -0,0 +1,6 @@
1
+ # copyright ############################### #
2
+ # This file is part of the Xcoll package. #
3
+ # Copyright (c) CERN, 2025. #
4
+ # ######################################### #
5
+
6
+ XCOLL_ELEMENTS_INIT_DEFAULTS = {}
@@ -0,0 +1,20 @@
1
+ # copyright ############################### #
2
+ # This file is part of the Xcoll package. #
3
+ # Copyright (c) CERN, 2025. #
4
+ # ######################################### #
5
+
6
+ from ..beam_elements import *
7
+
8
+
9
+ DEFAULT_XCOLL_ELEMENTS = [
10
+ BlackAbsorber,
11
+ BlackCrystal,
12
+ TransparentCollimator,
13
+ TransparentCrystal,
14
+ EverestBlock,
15
+ EverestCollimator,
16
+ EverestCrystal,
17
+ BlowUp,
18
+ # ParticleStatsMonitor,
19
+ EmittanceMonitor
20
+ ]
@@ -0,0 +1,182 @@
1
+ # copyright ############################### #
2
+ # This file is part of the Xcoll package. #
3
+ # Copyright (c) CERN, 2025. #
4
+ # ######################################### #
5
+
6
+ import numpy as np
7
+ import scipy.constants as sc
8
+
9
+ import xtrack as xt
10
+
11
+
12
+ def prepare_rf_sweep(line, cavities=None, sweep=None, sweep_per_turn=None, num_turns=None):
13
+ rf_sweep = RFSweep(line=line, cavities=cavities)
14
+ rf_sweep.prepare(sweep=sweep, sweep_per_turn=sweep_per_turn, num_turns=num_turns)
15
+
16
+
17
+ class RFSweep:
18
+ def __init__(self, line, cavities=None):
19
+ self.line = line
20
+ if line._var_management is None:
21
+ raise ValueError("Line must have a `var_management` to use RFSweep!" \
22
+ + "Do not use `optimize_for_tracking` as it will "
23
+ + "disable expressions, which are needed for RFSweep.")
24
+ self.env = line.env
25
+ self.cavities = cavities
26
+ self.env['rf_sweep_df'] = 0
27
+
28
+ @property
29
+ def current_sweep_value(self):
30
+ return self.env['rf_sweep_df']
31
+
32
+ def prepare(self, sweep=None, sweep_per_turn=None, num_turns=None):
33
+ if sweep_per_turn is not None:
34
+ if np.isclose(sweep_per_turn, 0):
35
+ raise ValueError("Variable `sweep_per_turn` must be non-zero!")
36
+ if sweep is not None:
37
+ raise ValueError("Provide either `sweep` or `sweep_per_turn`, not both.")
38
+ if num_turns is not None:
39
+ raise ValueError("Variable `num_turns` cannot be set when using `sweep_per_turn`.")
40
+ self.sweep_per_turn = sweep_per_turn
41
+ elif sweep is not None:
42
+ if np.isclose(sweep, 0):
43
+ raise ValueError("Variable `sweep` must be non-zero!")
44
+ if num_turns is None:
45
+ num_turns = int(abs(sweep))
46
+ if num_turns <= 0:
47
+ raise ValueError("When using `sweep`, `num_turns` must be a positive integer.")
48
+ self.sweep_per_turn = sweep / num_turns
49
+ else:
50
+ raise ValueError("Either `sweep` or `sweep_per_turn` must be provided.")
51
+ self._get_cavity_data(self.sweep_per_turn)
52
+ self._install_zeta_shift()
53
+ self.tw = self.line.twiss()
54
+ self.reset() # Initialize rf_sweep_df
55
+ self.env['rf_sweep'].dzeta = f"{self.L} * rf_sweep_df / ({self.f_RF} + rf_sweep_df)"
56
+ for cavs in self.cavities:
57
+ for cav in cavs['names']:
58
+ scale_factor = int(np.round(cavs['freq'] / self.f_RF))
59
+ if scale_factor == 1:
60
+ self.env.ref[cav].frequency += self.env.ref["rf_sweep_df"]
61
+ else:
62
+ self.env.ref[cav].frequency += scale_factor * self.env.ref["rf_sweep_df"]
63
+ self.line.enable_time_dependent_vars = True
64
+ print("Enabled time-dependent variables in the line.")
65
+
66
+
67
+ def reset(self):
68
+ if self.sweep_per_turn is None:
69
+ raise ValueError("RFSweep not prepared. Call `prepare` first.")
70
+ t_turn = self.tw.T_rev0
71
+ current_time = self.env['t_turn_s']
72
+ if current_time == 0:
73
+ self.env['rf_sweep_df'] = f"(t_turn_s + {t_turn}) / {t_turn} * {self.sweep_per_turn}"
74
+ else:
75
+ self.env['rf_sweep_df'] = f"(t_turn_s - {current_time} + {t_turn}) / {t_turn} * {self.sweep_per_turn}"
76
+
77
+
78
+ def info(self, sweep=None, num_turns=None):
79
+ if sweep is not None:
80
+ raise DeprecationWarning("The `sweep` argument is deprecated.")
81
+ if num_turns is not None:
82
+ raise DeprecationWarning("The `num_turns` argument is deprecated.")
83
+ if self.sweep_per_turn is None:
84
+ raise ValueError("RFSweep not prepared. Call `prepare` first.")
85
+ existing_sweep = self.current_sweep_value
86
+
87
+ beta0 = self.line.particle_ref.beta0[0]
88
+ E = self.line.particle_ref.energy0[0]
89
+ q = self.line.particle_ref.q0
90
+ h = self.f_RF * self.L / beta0 / sc.c
91
+ eta = self.tw.slip_factor
92
+
93
+ bucket_height = np.sqrt(abs(q*self.V*beta0**2 / (np.pi*h*eta*E) * (
94
+ 2*np.cos(self.phi) + (2*self.phi-np.pi)*np.sin(self.phi)
95
+ )))
96
+ delta_shift = -self.sweep_per_turn / self.f_RF / eta
97
+ bucket_turns = bucket_height * 2 / abs(delta_shift)
98
+ print(f"The current frequency is {self.f_RF + existing_sweep}Hz, adding "
99
+ + f"{self.sweep_per_turn}Hz per turn.")
100
+ print(f"This sweep will move the center of the bucket with \u0394\u03B4 = "
101
+ + f"{delta_shift} per turn.")
102
+ print(f"This implies one bucket shift every {bucket_turns} turns.")
103
+ if self.tw.qs * bucket_turns < 3:
104
+ print(f"Warning: This is a very fast sweep, moving ~1 bucket in "
105
+ + f"~{round(self.tw.qs * bucket_turns, 2)} synchrotron oscillations "
106
+ + f"(on average). If the bucket moves faster than a particle "
107
+ + f"can follow, that particle will move out of the bucket and "
108
+ + f"remain uncaptured.")
109
+
110
+
111
+ # For backward compatibility
112
+ def track(self, sweep=0, particles=None, num_turns=0, verbose=True, *args, **kwargs):
113
+ self.prepare(sweep, num_turns)
114
+ self.line.track(particles=particles, *args, **kwargs)
115
+
116
+
117
+ def _get_cavity_data(self, sweep):
118
+ tt = self.line.get_table()
119
+ tt_c = tt.rows[[nn for nn, ttt in zip(tt.name, tt.element_type)
120
+ if 'Cavity' in ttt and 'CrabCavity' not in ttt]]
121
+ mask = tt_c.parent_name == None # Unsliced cavities
122
+ if self.cavities is None:
123
+ self.cavities = np.unique(list(tt_c.name[mask]) + list(tt_c.parent_name[~mask]))
124
+ else:
125
+ if isinstance(self.cavities, str):
126
+ self.cavities = [self.cavities]
127
+ for cav in self.cavities:
128
+ if cav not in self.env.elements:
129
+ raise ValueError(f"Cavity `{cav}` not found in environment!")
130
+ if len(self.cavities) == 0:
131
+ raise ValueError("No cavities found in the line!")
132
+ freq = np.array([self.env[cav].frequency for cav in self.cavities])
133
+ volt = np.array([self.env[cav].voltage for cav in self.cavities])
134
+ lag = np.array([self.env[cav].lag for cav in self.cavities])
135
+ s_pos = []
136
+ name_first_in_line = []
137
+ for cav in self.cavities:
138
+ if cav in tt_c.name:
139
+ s_pos.append(tt_c.rows[cav].s_start[0])
140
+ name_first_in_line.append(cav)
141
+ elif cav in tt_c.parent_name:
142
+ s_pos.append(tt_c.rows[tt_c.parent_name == cav].s_start.min())
143
+ name_first_in_line.append(tt_c.rows[tt_c.parent_name == cav].name[0])
144
+ else:
145
+ raise ValueError(f"Cavity `{cav}` not found in the line!")
146
+ idx = np.argsort(freq)
147
+ boundaries = np.where(~np.isclose(freq[idx][1:], freq[idx][:-1],
148
+ rtol=1e-8, atol=1e-12)
149
+ )[0] + 1
150
+ groups = []
151
+ for gidx in np.split(idx, boundaries):
152
+ groups.append({
153
+ 'names': self.cavities[gidx],
154
+ 'freq': np.mean(freq[gidx]),
155
+ 'voltage': volt[gidx].sum(),
156
+ 's_pos': np.array(s_pos)[gidx],
157
+ 'lag': lag[gidx],
158
+ 'name_first_in_line': np.array(name_first_in_line)[gidx],
159
+ })
160
+ self.cavities = sorted(groups, key=lambda g: (g['voltage'], g['freq']), reverse=True)
161
+ if np.isclose(self.cavities[0]['voltage'], 0):
162
+ raise ValueError("No active cavity found!")
163
+ self.f_RF = self.cavities[0]['freq']
164
+ self.phi = np.deg2rad(self.cavities[0]['lag'].mean())
165
+ self.V = self.cavities[0]['voltage']
166
+ self.L = self.line.get_length()
167
+ if len(self.cavities) > 1:
168
+ print("Found multiple cavities with different frequencies:")
169
+ for g in self.cavities:
170
+ print(f"{g['freq']}Hz at {g['voltage']}V: {g['names']}")
171
+ print(r"The sweep ($\Delta f$ = " + f"{sweep}Hz per turn) will be "
172
+ + f"performed with respect to the highest voltage cavity at "
173
+ + f"{self.f_RF}Hz. The other cavities will be shifted "
174
+ + f"accordingly.")
175
+
176
+
177
+ def _install_zeta_shift(self):
178
+ if 'rf_sweep' not in self.env.elements:
179
+ idx = np.argsort(self.cavities[0]['s_pos'])
180
+ first_cavity = self.cavities[0]['name_first_in_line'][idx[0]]
181
+ self.env.elements['rf_sweep'] = xt.ZetaShift(dzeta=0)
182
+ self.line.insert('rf_sweep', at=f'{first_cavity}@start')
@@ -1,52 +0,0 @@
1
- [tool.poetry]
2
- name = "xcoll"
3
- version = "0.6.2"
4
- description = "Xsuite collimation package"
5
- homepage = "https://github.com/xsuite/xcoll"
6
- repository = "https://github.com/xsuite/xcoll"
7
- authors = [
8
- "Frederik F. Van der Veken <frederik@cern.ch>",
9
- "Simone O. Solstrand <simone.otelie.solstrand@cern.ch>",
10
- "Björn Lindstrom <bjorn.lindstrom@cern.ch>",
11
- "Giacomo Broggi <giacomo.broggi@cern.ch>",
12
- "André Donadon Servelle <andre.donadon.servelle@cern.ch>",
13
- "Dora E. Veres <dora.erzsebet.veres@cern.ch>",
14
- "Despina Demetriadou <despina.demetriadou@cern.ch>",
15
- "Andrey Abramov <andrey.abramov@cern.ch>",
16
- "Giovanni Iadarola <giovanni.iadarola@cern.ch>"
17
- ]
18
- readme = "README.md"
19
- license = "Apache 2.0"
20
- exclude = ["xcoll/lib", "xcoll/config"]
21
-
22
-
23
- [tool.poetry.dependencies]
24
- python = ">=3.8"
25
- ruamel-yaml = { version = "^0.17.31", optional = true }
26
- numpy = ">=1.0"
27
- pandas = ">=1.4"
28
- xobjects = ">=0.5.0"
29
- xdeps = ">=0.10.5"
30
- xpart = ">=0.23.0"
31
- xtrack = ">=0.84.8"
32
-
33
- [poetry.group.dev.dependencies]
34
- pytest = ">=7.3"
35
- xaux = ">=0.3.5"
36
-
37
- [tool.poetry.extras]
38
- tests = ["pytest", "ruamel-yaml", "pytest-html", "pytest-xdist"]
39
-
40
- [build-system]
41
- # Needed for pip install -e (BTW: need pip version 22)
42
- requires = ["poetry-core>=1.0.8"]
43
- build-backend = "poetry.core.masonry.api"
44
-
45
- # pyproject.toml
46
- [tool.pytest.ini_options]
47
- addopts = "-ra --durations=10 --durations-min=1"
48
- python_functions = ["test_"]
49
- testpaths = [
50
- "tests",
51
- ]
52
-
@@ -1,197 +0,0 @@
1
- # copyright ############################### #
2
- # This file is part of the Xcoll package. #
3
- # Copyright (c) CERN, 2024. #
4
- # ######################################### #
5
-
6
- import numpy as np
7
- import scipy.constants as sc
8
- from time import perf_counter
9
-
10
- import xtrack as xt
11
- from xtrack.progress_indicator import progress
12
-
13
- class RFSweep:
14
-
15
- def __init__(self, line):
16
- self.line = line
17
- self._get_base_frequency()
18
- self._install_zeta_shift()
19
- self.reset()
20
-
21
- def _get_base_frequency(self):
22
- self.cavities = self.line.get_elements_of_type(xt.Cavity)[1]
23
- freq = np.unique([round(self.line[cav].frequency, 9) for cav in self.cavities])
24
- if len(freq) > 1:
25
- raise NotImplementedError(f"Cannot sweep multiple cavities with different frequencies!")
26
- elif abs(freq[0]) < 1e-9 :
27
- raise ValueError(f"Cavity frequency not set!")
28
- self.f_RF = freq[0]
29
- phi = np.unique(np.array([self.line[cav].lag for cav in self.cavities])*np.pi/180.)
30
- if len(phi) > 1:
31
- raise NotImplementedError(f"Cannot sweep multiple cavities with different phases!")
32
- self.phi = phi[0]
33
- self.V = np.array([self.line[cav].voltage for cav in self.cavities]).sum()
34
- self.L = self.line.get_length()
35
-
36
- def _install_zeta_shift(self):
37
- if 'rf_sweep' in self.line.element_names:
38
- print(f"Found existing RF sweep in line.")
39
- else:
40
- s_cav = min([self.line.get_s_position(cav) for cav in self.cavities])
41
- if self.line.tracker is not None:
42
- self.line.unfreeze()
43
- line_was_built = True
44
- else:
45
- line_was_built = False
46
- self.line.insert_element(element=xt.ZetaShift(dzeta=0), name='rf_sweep', at_s=s_cav)
47
- if line_was_built:
48
- self.line.build_tracker()
49
-
50
- @property
51
- def current_sweep_value(self):
52
- dzeta = self.line['rf_sweep'].dzeta
53
- return round(self.f_RF * dzeta/(self.L-dzeta), 6)
54
-
55
-
56
- def info(self, sweep=0, num_turns=0):
57
- if abs(sweep) > 1e-9:
58
- existing_sweep = self.current_sweep_value
59
-
60
- beta0 = self.line.particle_ref.beta0[0]
61
- E = self.line.particle_ref.energy0[0]
62
- q = self.line.particle_ref.q0
63
- h = self.f_RF * self.L / beta0 / sc.c
64
- tw = self.line.twiss()
65
- eta = tw.slip_factor
66
-
67
- bucket_height = np.sqrt(abs(q*self.V*beta0**2 / (np.pi*h*eta*E) * (
68
- 2*np.cos(self.phi) + (2*self.phi-np.pi)*np.sin(self.phi)
69
- )))
70
- delta_shift = -sweep / self.f_RF / eta
71
- bucket_shift = delta_shift / bucket_height / 2
72
- if num_turns > 0:
73
- rf_shift_per_turn = sweep / num_turns
74
- print(f"The current frequency is {self.f_RF + existing_sweep}Hz, adding {rf_shift_per_turn}Hz "
75
- + f"per turn until {self.f_RF + existing_sweep + sweep} (for {num_turns} turns).")
76
- print(f"This sweep will move the center of the bucket with \u0394\u03B4 = "
77
- + f"{delta_shift} ({bucket_shift} buckets).")
78
- if num_turns > 0 and num_turns < 3*bucket_shift/tw.qs:
79
- print(f"Warning: This is a very fast sweep, moving ~{round(bucket_shift, 2)} buckets in "
80
- + f"~{round(num_turns*tw.qs, 2)} synchrotron oscillations (on average). If the "
81
- + f"bucket moves faster than a particle can follow, that particle will move out of "
82
- + f"the bucket and remain uncaptured.")
83
-
84
-
85
- def track(self, sweep=0, particles=None, num_turns=0, verbose=True, *args, **kwargs):
86
-
87
- # Was there a previous sweep?
88
- # If yes, we do not overwrite it but continue from there
89
- existing_sweep = self.current_sweep_value
90
-
91
- # Just set the new RF frequency, no tracking
92
- if num_turns == 0:
93
- sweep += existing_sweep
94
- if verbose:
95
- print(f"The current frequency is {self.f_RF + existing_sweep}Hz, moving to {self.f_RF + sweep}Hz."
96
- + "No tracking performed.")
97
- self.line['rf_sweep'].dzeta = self.L * sweep / (self.f_RF + sweep)
98
-
99
- # Sweep and track
100
- else:
101
- if self.line.tracker is None:
102
- raise ValueError("Need to build tracker first!")
103
- if particles is None:
104
- raise ValueError("Need particles to track!")
105
- time = kwargs.pop('time', False)
106
- with_progress = kwargs.pop('with_progress', False)
107
- rf_shift_per_turn = sweep / num_turns
108
-
109
- # This is taken from xtrack.tracker.Tracker._track
110
- if time:
111
- t0 = perf_counter()
112
- if with_progress:
113
- if self.line.tracker.enable_pipeline_hold:
114
- raise ValueError("Progress indicator is not supported with pipeline hold")
115
- if num_turns < 2:
116
- raise ValueError('Tracking with progress indicator is only '
117
- 'possible over more than one turn.')
118
- if with_progress is True:
119
- batch_size = scaling = 100
120
- else:
121
- batch_size = int(with_progress)
122
- scaling = with_progress if batch_size > 1 else None
123
- if kwargs.get('turn_by_turn_monitor') is True:
124
- ele_start = kwargs.get('ele_start') or 0
125
- ele_stop = kwargs.get('ele_stop')
126
- if ele_stop is None:
127
- ele_stop = len(self.line)
128
- if ele_start >= ele_stop:
129
- # we need an additional turn and space in the monitor for
130
- # the incomplete turn
131
- num_turns += 1
132
- _, monitor, _, _ = self.line.tracker._get_monitor(particles, True, num_turns)
133
- kwargs['turn_by_turn_monitor'] = monitor
134
-
135
- for ii in progress(
136
- range(0, num_turns, batch_size),
137
- desc='Tracking',
138
- unit_scale=scaling,
139
- ):
140
- one_turn_kwargs = kwargs.copy()
141
- is_first_batch = ii == 0
142
- is_last_batch = ii + batch_size >= num_turns
143
-
144
- if is_first_batch and is_last_batch:
145
- # This is the only batch, we track as normal
146
- pass
147
- elif is_first_batch:
148
- # Not the last batch, so track until the last element
149
- one_turn_kwargs['ele_stop'] = None
150
- one_turn_kwargs['num_turns'] = batch_size
151
- elif is_last_batch:
152
- # Not the first batch, so track from the first element
153
- one_turn_kwargs['ele_start'] = None
154
- remaining_turns = num_turns % batch_size
155
- if remaining_turns == 0:
156
- remaining_turns = batch_size
157
- one_turn_kwargs['num_turns'] = remaining_turns
158
- one_turn_kwargs['_reset_log'] = False
159
- elif not is_first_batch and not is_last_batch:
160
- # A 'middle batch', track from first to last element
161
- one_turn_kwargs['num_turns'] = batch_size
162
- one_turn_kwargs['ele_start'] = None
163
- one_turn_kwargs['ele_stop'] = None
164
- one_turn_kwargs['_reset_log'] = False
165
- self._tracking_func(particles, rf_shift_per_turn, **one_turn_kwargs)
166
- if not np.any(particles.state == 1):
167
- break
168
-
169
- else:
170
- self._tracking_func(particles, rf_shift_per_turn, num_turns=num_turns, *args, **kwargs)
171
-
172
- if not np.any(particles.state == 1):
173
- print(f"All particles lost at turn {particles.at_turn.max()}, stopped sweep at "
174
- + f"{self.current_sweep_value}Hz.")
175
-
176
- if time:
177
- t1 = perf_counter()
178
- self.line.tracker._context.synchronize()
179
- self.line.tracker.time_last_track = t1 - t0
180
- else:
181
- self.line.tracker.time_last_track = None
182
-
183
-
184
- def reset(self):
185
- self.line['rf_sweep'].dzeta = 0
186
-
187
-
188
- def _tracking_func(self, particles, rf_shift_per_turn, num_turns=1, *args, **kwargs):
189
- existing_sweep = self.current_sweep_value
190
- for i in range(num_turns):
191
- sweep = existing_sweep + i*rf_shift_per_turn
192
- self.line['rf_sweep'].dzeta = self.L * sweep / (self.f_RF + sweep)
193
- # for cav in cavities:
194
- # self.line[cav].frequency = freq + sweep
195
- self.line.track(particles, num_turns=1, *args, **kwargs)
196
- if not np.any(particles.state == 1):
197
- break
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes