Initial Application of Machine Learning for Beam Parameter Optimization at the Hefei Light Source II

Machine learning (ML) has become a valuable tool in particle accelerator control, with growing potential for beam parameter correction. In this study, we present preliminary ML applications at HLS-II, using Lasso regression for online tune correction and a neural network (NN) for beta function simulation correction. Both models were trained with supervised learning on measured beam parameter data, while an improved genetic algorithm optimized the NN structure. Our results show that the ML-based approach achieves competitive correction quality with fewer steps, making it a promising method for future particle accelerator applications and other fields.


Introduction
Beam stability is of paramount importance, particularly for modern synchrotron light sources.In this context, machine learning approaches have been employed in a wide variety of accelerator control tasks.Recent advancements in the field of accelerators include the development of a machine-learning system for optical correction by the operators of Europe's Large Hadron Collider.The efficacy of machine-learning method for optical correction surpasses that of the standard response matrix approach.Subsequent research has explored the application of both local and global corrections [1,2].At the Stanford Positron Electron Asymmetric Ring, an adaptive feedback technique is employed to swiftly and consistently optimize magnets to reduce betatron oscillations [3].In this work, we concentrate on beam parameter correction using machine learning for the Hefei Light Source (HLS-II).

NEW Beam optical parameter correction process
In this section, we present our specific strategy for particle accelerator calibration, which forms the foundation for our subsequent work.The HLS-II machine learning application schematic, shown in Fig. 1, comprises three components: data collection, supervised training, and feedback correction, which we will detail below.
Data Collection: The initial step involves gathering a large dataset to enable our proposed machine-learning method to generalize and produce accurate results.We use the MATLAB toolbox AT [4] to create a virtual storage ring by integrating real parameters and environmental factors for simulated data generation.We adjust our quadrupole strength within an error interval to obtain a large amount of simulated data from the virtual storage ring.During tuning and machine study periods, we periodically vary the quadrupole strength and collect it using EPICS [5,6,7] for real data acquisition at HLS-II.Both simulated and real data are combined to create training data, with each data pair consisting of quadrupole strength error and beam parameter error.Supervised Learning: Various ML algorithms are employed to address specific problems.For instance, we use a neural network for beta function correction and the Lasso regression for tune correction.In beta correction, to tackle the challenges of neural network structure design and hyperparameter selection, we propose an Improved Genetic Algorithm (IGA) to optimize the neural network structure, resulting in the IGA-NN model.The training data for this model is based on the data obtained from step 1.

Errors in quadrupoles
Feedback Correction: The feedback correction process can be broken down into the following steps: • Read the current beam parameter values and the theoretical design values to calculate the residuals.
• Feed the residuals into trained ML model.
• Obtain the prediction of the quadrupole error.
• Add the prediction to the current quadrupole.
• Repeat this process until the correction is complete.Based on the method proposed above, we have successfully carried out the simulation and online calibration of the tune, as well as the simulation calibration of the beta function at HLS-II.These two examples are described in detail below:

Beta Function Correction Based on Deep Learning 3.1.1. Neural Network Structure Definition
To design a neural network architecture and hyperparameters for particle accelerator problems, we employ an improved genetic algorithm for optimization.We define basic chromosome units, including fully connected, dropout, and batch normalization layers, learning rate, and optimizer.Our approach introduces three improvements over traditional genetic algorithms: • Proportional Elite Retention Strategy: Preserves superior individuals to refine solutions across generations.
• Hierarchical Clustering-based Selection Operator: Prevents invalid crossovers in comparison to roulette-based selection.
• Q-Learning for Dynamic Adjustment: Adapts crossover and mutation probabilities for efficient search space exploration and exploitation.
The optimized network structure includes a 54-neuron fully connected layer, a dropout layer, a batch normalization layer, an Adam optimizer, and a 0.0001 learning rate(see Figure2).This architecture, compared to our previous 6-layer, 256-node design, substantially reduces training time from 600 s to 30 s and improves Mean Squared Error (MSE) from e-05 to e-08, better meeting our requirements.This demonstrates that achieving higher accuracy is a challenging task.

Simulation Analysis
We utilize the AT to generate beta functions with random errors.From Fig3, we can intuitively see the effect of only one step of correction, from the largest,∆ β x /β x of about 0.089 to 0.0046 after correction and ∆ β y /β y of about 0.014 to 0.002 after correction.This indicates that it is very close to the theoretical value.Currently, we only perform simulation correction of the beta function, as real data collection presents challenges.In future work, we will strive to address this issue and incorporate real data into our analysis.Regularization is incorporated to prevent overfitting during the fitting process.The Lasso regression introduces the ℓ 1 -norm, with the loss function expression given as follows: Here, Xw − y represents the predicted and true value difference, n samples is the sample count, α is a tunable constant, and ||w|| 1 is the L1 regularization term [8].Lasso regression uses the coordinate descent method [9,10] with continuous iterations to determine parameters.
Of the 60,000 samples, 50,000 are simulated and 10,000 are real machine data, split into 70% and 30% portions for training and testing.Each sample pair has two inputs (tune error) and 32 outputs (quadrupole errors), resulting in a mean squared error value of 7.419 × 10 −5 .

Simulation Verification of Tune Feedback Correction
The HLS-II storage ring operated at 800 MeV with a tune (4.4448, 2.3598) [11].We use the AT to generate tune with random errors.Figure 4 displays the results using the Storage Ring Tune Model (STM).The tune rapidly approaches the theoretical value after several correction steps.From this extensive dataset, four exemplary datasets were extracted, chosen to have the most significant potential error in each direction.They encompass all likely scenarios that may arise during actual operation (see Fig. 4, Table1).We conducted online experiments: (1) Disabling tune feedback correction, changing IDs gap(gap on), causing significant tune drift, with horizontal tune range (0.3934-0.5) and vertical tune range (0.3048-0.4159).
(3) Enabling tune feedback correction, observing the tune for 20 minutes without changing IDs gap(gap off), achieving excellent stability with horizontal tune range (0.4444-0.4464) and vertical tune range (0.3577-0.3617).It is crucial to emphasize that the change in the IDs represents a load test, and the actual situation will not experience such drastic fluctuations.
Experimental results are in Fig. 5

Conclusion
Machine learning shows great potential in the accelerator field, enabling real-time analysis and prediction of machine and beam states.While some progress has been made, development remains in early stages, offering room for growth.For HLS-II, we've conducted initial machine learning applications, using deep learning for simulation beta function correction and Lasso regression for tune simulation and online correction.Future work will focus on online beta function correction and large-scale collective parameter correction for more impactful research results.

Figure 1 :
Figure1: Schematic of the beam parameters feedback system using a machine-learning method.The whole process is divided into three parts: Conceptual representation of data generation and supervised model creation and feedback correction.

Figure 4 :
Figure 4: Four representative datasets were extracted from this larger dataset.

Table 1 :
Tune before and after STM correction Online Verification of Tune Feedback Correction Five insertion devices (IDs) on the HLS-II produce high-quality synchrotron light.ID changes cause tune shifts and beam quality alterations, impacting user experiments.We first verify the method's feasibility through simulation and then validate it on real machines with ID changes.

Table 2 :
and Table2.Measured tune with feedback off and on.The red curve is for horizontal tune, and the blue curve is for vertical tune.The changes in the ID gap are very complicated.This is equivalent to the load test.Tune before and after STM correction online