Skip to content

Commit 2ec5123

Browse files
author
elwaagaa
committed
Revert "First clean-up and improved documentation"
This reverts commit 63f1a05.
1 parent 6dcc738 commit 2ec5123

File tree

15 files changed

+407
-1341
lines changed

15 files changed

+407
-1341
lines changed

.github/workflows/pypi-publish.yml

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
name: Publish Python Package
2+
3+
on:
4+
release:
5+
types: [created]
6+
workflow_dispatch:
7+
8+
jobs:
9+
deploy:
10+
runs-on: ubuntu-latest
11+
permissions:
12+
contents: read
13+
id-token: write # This is required for trusted publishing
14+
15+
steps:
16+
- uses: actions/checkout@v4
17+
18+
- name: Set up Python
19+
uses: actions/setup-python@v5
20+
with:
21+
python-version: '3.10'
22+
23+
- name: Install build tools
24+
run: |
25+
python -m pip install --upgrade pip
26+
pip install build twine
27+
28+
- name: Build package
29+
run: |
30+
python -m build
31+
32+
- name: Publish to PyPI
33+
uses: pypa/gh-action-pypi-publish@release/v1
34+
with:
35+
user: __token__
36+
password: ${{ secrets.PYPI_API_TOKEN }}
37+
skip_existing: true
38+
verbose: true

.github/workflows/tests.yml

Lines changed: 59 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,59 @@
1+
name: Tests
2+
3+
on:
4+
push:
5+
branches: [ main, master ]
6+
pull_request:
7+
branches: [ main, master ]
8+
schedule:
9+
- cron: '0 0 * * 0' # Weekly on Sundays
10+
11+
defaults:
12+
run:
13+
shell: bash -l {0}
14+
15+
jobs:
16+
test:
17+
name: Python ${{ matrix.python-version }} on ${{ matrix.os }}
18+
runs-on: ${{ matrix.os }}
19+
strategy:
20+
fail-fast: false
21+
matrix:
22+
os: [ubuntu-latest]
23+
python-version: ['3.8', '3.9', '3.10', '3.11']
24+
25+
steps:
26+
- uses: actions/checkout@v4
27+
28+
- name: Set up Python ${{ matrix.python-version }}
29+
uses: actions/setup-python@v5
30+
with:
31+
python-version: ${{ matrix.python-version }}
32+
33+
- name: Install dependencies
34+
run: |
35+
python -m pip install --upgrade pip
36+
pip install -e .[dev]
37+
38+
- name: Run tests
39+
run: |
40+
python -m pytest tests/ -v --cov=fma_ions --cov-report=xml
41+
42+
- name: Upload coverage to Codecov
43+
uses: codecov/codecov-action@v4
44+
with:
45+
token: ${{ secrets.CODECOV_TOKEN }}
46+
file: ./coverage.xml
47+
fail_ci_if_error: false
48+
49+
- name: Run type checking
50+
run: |
51+
mypy fma_ions/
52+
53+
- name: Lint with flake8
54+
run: |
55+
flake8 fma_ions/
56+
57+
- name: Check formatting with black
58+
run: |
59+
black --check fma_ions/

.readthedocs.yml

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
# .readthedocs.yml
2+
# Minimal Read the Docs configuration
3+
version: 2
4+
5+
# Build documentation with Sphinx
6+
sphinx:
7+
configuration: docs/conf.py
8+
fail_on_warning: false
9+
10+
# Python configuration
11+
python:
12+
version: "3.11"
13+
install:
14+
- method: pip
15+
path: .
16+
extra_requirements: ["docs"]
17+
- requirements: requirements-docs.txt
18+
19+
# Build configuration
20+
build:
21+
os: ubuntu-22.04
22+
tools:
23+
python: "3.11"
24+
25+
# Optional: Uncomment to build PDF as well
26+
# formats: [pdf]

README.md

Lines changed: 83 additions & 93 deletions
Original file line numberDiff line numberDiff line change
@@ -1,129 +1,119 @@
1-
# FMA Ions
1+
# Frequency Map Analysis for ions
22

3-
[![PyPI version](https://badge.fury.io/py/fma-ions.svg)](https://badge.fury.io/py/fma-ions)
4-
[![Python 3.8+](https://img.shields.io/badge/python-3.8+-blue.svg)](https://www.python.org/downloads/)
5-
[![License: MIT](https://img.shields.io/badge/License-MIT-yellow.svg)](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$
64

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}$$
86

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).
108

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.
1210

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+
![FMA_plot_SPS](https://github.com/ewaagaard/fma_ions/assets/68541324/ed6676c6-9812-486e-81c6-6f6ea0b411de)
1912

20-
## Installation
13+
### Quick set-up
2114

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`:
2518

26-
For GPU support:
27-
```bash
28-
pip install cupy-cuda11x # CUDA 11.x
29-
pip install cupy-cuda12x # CUDA 12.x
3019
```
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
3129

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+
```
3432
cd fma_ions/data/
3533
git clone https://gitlab.cern.ch/acc-models/acc-models-sps.git
3634
git clone https://gitlab.cern.ch/acc-models/acc-models-ps.git
3735
```
36+
If this command is executed correctly, two repositories `acc-models-ps` and `acc-models-sps` should appear inside the `data` folder with content.
3837

39-
## Quick Start
40-
41-
```python
42-
from fma_ions import FMA, SPS_Flat_Bottom_Tracker
38+
#### GPU support
4339

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:
4841

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
5346
```
5447

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
8449

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.
8656

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)
8866
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
9469
95-
## Contributing
70+
# Tune footprint range
71+
plot_range = [[26.0, 26.35], [26.0, 26.35]]
9672
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.
9878

99-
- Development setup
100-
- Code style guidelines
101-
- Testing procedures
102-
- Documentation standards
79+
![SPS_Initial_distribution](https://github.com/ewaagaard/fma_ions/assets/68541324/35a343bf-fc7d-4215-a4a2-08fe2e43be19)
10380

104-
## Citation
81+
### Built-in sequences
10582

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()
10788
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()
11691
```
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
11798

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
119100

120-
This project is licensed under the MIT License - see the [LICENSE](LICENSE) file for details.
101+
```
102+
import fma_ions
121103
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
123109

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
127113
114+
fma_sps = fma_ions.FMA(z0=0.15, n_linear=200)
115+
fma_sps.run_SPS()
116+
```
128117

118+
![FMA_plot_SPS](https://github.com/ewaagaard/fma_ions/assets/68541324/d1d69eec-fc0d-4ccd-a34c-a1820cc6f604)
129119

0 commit comments

Comments
 (0)