|
1 | | -# FMA Ions |
| 1 | +# Frequency Map Analysis for ions |
2 | 2 |
|
3 | | -[](https://badge.fury.io/py/fma-ions) |
4 | | -[](https://www.python.org/downloads/) |
5 | | -[](https://opensource.org/licenses/MIT) |
| 3 | +Non-linear effects can enhance chaotic motion and limit the performance of accelerators. Frequency Map Analysis (FMA) is a method that probes tune diffusion from particle tracking simulations and identify resonances that are excited. FMA can be used to detect chaotic behaviour in particle acceelerators, by looking at the tune diffusion $d$ |
6 | 4 |
|
7 | | -**A Python package for Frequency Map Analysis of ion beams in particle accelerators** |
| 5 | +$$d = \log \sqrt{ (Q_{x, 2} - Q_{x, 1})^2 + (Q_{y, 2} - Q_{y, 1})^2}$$ |
8 | 6 |
|
9 | | -Frequency Map Analysis (FMA) is a powerful technique for studying nonlinear dynamics and detecting chaotic motion in particle accelerators. This package provides comprehensive tools for FMA studies of ion beams at CERN, with support for space charge effects, intra-beam scattering, and tune ripple. |
| 7 | +where $Q_{x, y, 1}$ is the particle tunes in the first number of turns (e.g. first 600 turns) and $Q_{x, y, 2}$ is the tunes of the subsequent turn block (e.g. the next 600 turns). |
10 | 8 |
|
11 | | -## Key Features |
| 9 | +This repository contains FMA classes for ion beams in the CERN accelerator complex, but can also be used for other protons and other set-ups. |
12 | 10 |
|
13 | | -- **🔬 Frequency Map Analysis**: Tune diffusion calculation and resonance identification |
14 | | -- **⚡ High Performance**: GPU acceleration support for large-scale tracking |
15 | | -- **🏗️ CERN Integration**: Built-in support for SPS, PS, and LEIR accelerators |
16 | | -- **☁️ Cluster Computing**: HTCondor job submission for batch processing |
17 | | -- **📊 Visualization**: Specialized plotting tools for accelerator physics |
18 | | -- **🧮 Advanced Physics**: Space charge, IBS, and tune ripple modeling |
| 11 | + |
19 | 12 |
|
20 | | -## Installation |
| 13 | +### Quick set-up |
21 | 14 |
|
22 | | -```bash |
23 | | -pip install fma_ions |
24 | | -``` |
| 15 | +When using Python for scientific computing, it is important to be aware of dependencies and compatibility of different packages. This guide gives a good explanation: [Python dependency manager guide](https://aaltoscicomp.github.io/python-for-scicomp/dependencies/#dependency-management). An isolated environment allows installing packages without affecting the rest of your operating system or any other projects. A useful resource to handle virtual environments is [Anaconda](https://www.anaconda.com/) (or its lighter version Miniconda), when once installed has many useful commands of which many can be found in the [Conda cheat sheet](https://docs.conda.io/projects/conda/en/4.6.0/_downloads/52a95608c49671267e40c689e0bc00ca/conda-cheatsheet.pdf). A guide to manage conda environments is found [here](https://docs.conda.io/projects/conda/en/latest/user-guide/tasks/manage-environments.html). |
| 16 | + |
| 17 | +To directly start using `fma_ions`, create an isolated virtual environment with conda and perform a local install to use the `fma_ions`. Run in the terminal to clone the repository, install a virtual environment (with all requirements) and then a local editable install of `fma_ions`: |
25 | 18 |
|
26 | | -For GPU support: |
27 | | -```bash |
28 | | -pip install cupy-cuda11x # CUDA 11.x |
29 | | -pip install cupy-cuda12x # CUDA 12.x |
30 | 19 | ``` |
| 20 | +git clone https://github.com/ewaagaard/fma_ions.git |
| 21 | +conda create --name fma_env python=3.11.7 |
| 22 | +conda activate fma_env |
| 23 | +python -m pip install -r venvs/requirements.txt |
| 24 | +cd .. |
| 25 | +python -m pip install -e fma_ions |
| 26 | +``` |
| 27 | + |
| 28 | +#### Cloning repos for PS and SPS sequences |
31 | 29 |
|
32 | | -For CERN accelerator models: |
33 | | -```bash |
| 30 | +The `fma_ions` relies on sequence generators for PS and SPS ions, which requires MADX sequence files from [git submodules](https://git-scm.com/book/en/v2/Git-Tools-Submodules) from [acc-models](https://gitlab.cern.ch/acc-models). Clone these repositories as submodules inside the `fma_ions`: |
| 31 | +``` |
34 | 32 | cd fma_ions/data/ |
35 | 33 | git clone https://gitlab.cern.ch/acc-models/acc-models-sps.git |
36 | 34 | git clone https://gitlab.cern.ch/acc-models/acc-models-ps.git |
37 | 35 | ``` |
| 36 | +If this command is executed correctly, two repositories `acc-models-ps` and `acc-models-sps` should appear inside the `data` folder with content. |
38 | 37 |
|
39 | | -## Quick Start |
40 | | - |
41 | | -```python |
42 | | -from fma_ions import FMA, SPS_Flat_Bottom_Tracker |
| 38 | +#### GPU support |
43 | 39 |
|
44 | | -# Basic FMA analysis |
45 | | -fma = FMA() |
46 | | -d, Qx, Qy = fma.run_SPS() # Run default SPS analysis |
47 | | -fma.plot_tune_diagram(Qx, Qy, d) |
| 40 | +Tracking many particles for millions of turns can take a long time. Although the default context for most functions is with CPU, most of them also contain support for GPUs for faster particle tracking. If you machine supports GPU usage, check out [Xsuite GPU/Multithreading support](https://xsuite.readthedocs.io/en/latest/installation.html#gpu-multithreading-support). The `cupy` should already be installed from `venvs/requirements.txt`, but it can be useful to run the following lines again: |
48 | 41 |
|
49 | | -# Comprehensive SPS tracking with space charge |
50 | | -tracker = SPS_Flat_Bottom_Tracker() |
51 | | -tracker.track_SPS(n_turns=1000) |
52 | | -tracker.plot_tracking_data() |
| 42 | +``` |
| 43 | +conda install mamba -n base -c conda-forge |
| 44 | +pip install cupy-cuda11x |
| 45 | +mamba install cudatoolkit=11.8.0 |
53 | 46 | ``` |
54 | 47 |
|
55 | | -## Physics Background |
56 | | - |
57 | | -FMA detects chaotic motion by analyzing tune diffusion: |
58 | | - |
59 | | -$$d = \log_{10} \sqrt{(Q_{x,2} - Q_{x,1})^2 + (Q_{y,2} - Q_{y,1})^2}$$ |
60 | | - |
61 | | -Where $Q_{x,y,1}$ and $Q_{x,y,2}$ are tunes calculated from different turn blocks. |
62 | | - |
63 | | -**Interpretation:** |
64 | | -- $d < -5$: Regular motion (stable) |
65 | | -- $d > -3$: Chaotic motion (unstable) |
66 | | - |
67 | | -## Package Structure |
68 | | - |
69 | | -- **`FMA`**: Core analysis class with tune diffusion calculations |
70 | | -- **`SPS_Flat_Bottom_Tracker`**: Comprehensive SPS particle tracking |
71 | | -- **`Submitter`**: HTCondor job submission for CERN cluster |
72 | | -- **`Tune_Ripple_SPS`**: Power converter ripple simulation |
73 | | -- **Sequence makers**: PS, SPS, and LEIR lattice generation |
74 | | -- **Beam parameters**: Ion-specific configurations for different species |
75 | | - |
76 | | -## Documentation |
77 | | - |
78 | | -Comprehensive documentation is available at: https://fma-ions.readthedocs.io/ |
79 | | - |
80 | | -- [Installation Guide](https://fma-ions.readthedocs.io/en/latest/installation.html) |
81 | | -- [Quick Start Tutorial](https://fma-ions.readthedocs.io/en/latest/quickstart.html) |
82 | | -- [Physics Background](https://fma-ions.readthedocs.io/en/latest/physics.html) |
83 | | -- [API Reference](https://fma-ions.readthedocs.io/en/latest/autoapi/index.html) |
| 48 | +## FMA class |
84 | 49 |
|
85 | | -## Examples |
| 50 | +The `FMA` class contains all the methods and imports all helper functions needed to track particle objects and analyze the tune diffusion. The class is instantiated by |
| 51 | +``` |
| 52 | +import fma_ions |
| 53 | +fma = fma_ions.FMA() |
| 54 | +``` |
| 55 | +Optional arguments can be added, such as specific output destinations for turn-by-turn (TBT) data and plots, number of turns to track, shape of particle object, longitudinal position offset `z0` and so on. Arbitrary [Xsuite](https://xsuite.readthedocs.io/en/latest/) lines can be used, although helper classes provide standard PS and SPS lattice models. |
86 | 56 |
|
87 | | -See the [`examples/`](examples/) directory and [documentation examples](https://fma-ions.readthedocs.io/en/latest/examples.html) for: |
| 57 | +The FMA happens in several steps: |
| 58 | +1) first a line with space charge (SC) is returned, and the particle object to be tracked. Input is an Xsuite line (without space charge) and `beamParams`, which is a data class containing bunch intensity `Nb`, bunch length `sigma_z`, normalized emittances `exn` and `eyn`, and the integer tune of the accelerator `Q_int`, since this technique can only detect fractional tunes. An example structure for this `beamParams` class is found in `fma_ions.BeamParameters_SPS()`. |
| 59 | +2) TBT `x` and `y` data are returned, tracking for the specified attribute `num_turns` (default 1200) in the FMA class. |
| 60 | +3) The diffusion coefficient `d` and individual particle tunes `Qx` and `Qy` are returned from the NAFF algorithm used in the FMA method |
| 61 | +4) `Qx`, `Qy` and `d` can be plotted in the initial particle distribution and in the final tune diagram of the particles. |
| 62 | +``` |
| 63 | +line_with_SC, particles = fma.install_SC_and_generate_particles(line, beamParams) |
| 64 | +x, y = fma.track_particles(particles, line_with_SC) |
| 65 | +d, Qx, Qy = fma.run_FMA(x, y) |
88 | 66 |
|
89 | | -- Dynamic aperture studies |
90 | | -- Space charge effect analysis |
91 | | -- Tune ripple impact assessment |
92 | | -- Multi-species ion comparisons |
93 | | -- HTCondor batch processing |
| 67 | +# Set point, e.g for SPS |
| 68 | +Qh_set, Qv_set = 26.30, 26.25 |
94 | 69 |
|
95 | | -## Contributing |
| 70 | +# Tune footprint range |
| 71 | +plot_range = [[26.0, 26.35], [26.0, 26.35]] |
96 | 72 |
|
97 | | -We welcome contributions! Please see our [Contributing Guide](https://fma-ions.readthedocs.io/en/latest/contributing.html) for details on: |
| 73 | +# Generate plots. |
| 74 | +fma.plot_FMA(d, Qx, Qy, Qh_set, Qv_set,'SPS', plot_range) |
| 75 | +fma.plot_initial_distribution(x, y, d, case_name='SPS') |
| 76 | +``` |
| 77 | +Initial distributions provide useful insights where the tune diffusion happens inside the distribution. |
98 | 78 |
|
99 | | -- Development setup |
100 | | -- Code style guidelines |
101 | | -- Testing procedures |
102 | | -- Documentation standards |
| 79 | + |
103 | 80 |
|
104 | | -## Citation |
| 81 | +### Built-in sequences |
105 | 82 |
|
106 | | -If you use this software in your research, please cite: |
| 83 | +SPS and PS standard Pb lattice models from Xsuite are contained in helper data classes. These can be instantiated easily by using: |
| 84 | +``` |
| 85 | +import fma_ions |
| 86 | +fma_sps = fma_ions.FMA() |
| 87 | +fma_sps.run_SPS() |
107 | 88 |
|
108 | | -```bibtex |
109 | | -@software{waagaard2024fma_ions, |
110 | | - author = {Elias Waagaard}, |
111 | | - title = {fma_ions: Frequency Map Analysis for ion beams at CERN}, |
112 | | - year = {2024}, |
113 | | - publisher = {GitHub}, |
114 | | - url = {https://github.com/ewaagaard/fma_ions} |
115 | | -} |
| 89 | +fma_ps = fma_ions.FMA() |
| 90 | +fma_ps.run_PS() |
116 | 91 | ``` |
| 92 | +which call standard PS and SPS lattices, and perform the FMA described in the previous section with default parameters. If the tracking has already been done, plots can easily be generated from saved TBT data by using |
| 93 | +``` |
| 94 | +fma_sps = fma_ions.FMA() |
| 95 | +fma_sps.run_SPS(load_tbt_data=True) |
| 96 | +``` |
| 97 | +### Custom beams and tunes |
117 | 98 |
|
118 | | -## License |
| 99 | +Custom beam intensities, tunes, charge states and masses can be provided. The `FMA` class rematches provided tunes and generates the desired beam |
119 | 100 |
|
120 | | -This project is licensed under the MIT License - see the [LICENSE](LICENSE) file for details. |
| 101 | +``` |
| 102 | +import fma_ions |
121 | 103 |
|
122 | | -## Acknowledgments |
| 104 | +# Initialize FMA object and intialize beam (mass is in atomic units) |
| 105 | +fma_sps = fma_ions.FMA() |
| 106 | +fma_sps.run_custom_beam_SPS(ion_type='O', m_ion=15.99, Q_SPS=8., Q_PS=4., qx=26.30, qy=26.19, Nb=82e8) |
| 107 | +``` |
| 108 | +### Longitudinal position or momentum offset |
123 | 109 |
|
124 | | -- CERN for accelerator models and computing resources |
125 | | -- Xsuite team for tracking infrastructure |
126 | | -- NAFF library for frequency analysis algorithms |
| 110 | +To investigate tune diagram sidebands and effects of synchrotron oscillations on off-momentum particles, non-zero `z0` or `delta0` can be provided to generate the particle object. If a uniform beam is used, `n_linear` determines the resolution of the meshgrid in normalized coordinates $X$ and $Y$, so `n_linear=100` generates 10 000 particles unformly distributed up to a desired beam size (e.g. 10 $\sigma$). |
| 111 | +``` |
| 112 | +import fma_ions |
127 | 113 |
|
| 114 | +fma_sps = fma_ions.FMA(z0=0.15, n_linear=200) |
| 115 | +fma_sps.run_SPS() |
| 116 | +``` |
128 | 117 |
|
| 118 | + |
129 | 119 |
|
0 commit comments