A new approach for Canadian Light Source future orbit correction system driven by neural network

The orbit correction system (OCS) of the Canadian Light Source (CLS) comprises of 48 sets of BERGOZ beam position monitors (BPM). Each BPM has the ability to measure the position of the beam in both the X and Y directions and can record data at a rate of 1000 times per second. Inverse Response Matrix (IRM) is utilized to determine the optimal strength of the 48 sets of orbit correctors in both the X and Y directions, in order to ensure that the beam follows its desired path. The suggestion in this study is to replace the singular value decomposition (SVD) function with a neural network algorithm, which will act as the central processing unit of the orbit correction system. The training model’s design includes three hidden layers, and within each layer, there are 96 nodes. The neural network’s outputs for regular operations in CLS exhibit a mean square error (MSE) of 10 −7 . Various difficult scenarios were created to test the OCS at 8.0 mA, using offsets in different sections of the storage ring. However, the new model was able to produce the necessary orbit correctors (OC) signals without any trouble.


Introduction
The CLS synchrotron light source storage ring consists of twelve sections and operates at a 2.9 GeV energy level.To maintain the stability of the beam position in the storage ring, an Orbit Correction System is utilized to correct any disturbances.
In 2000, the Motorola single-board computer was the initial implementation of a real-time controller [1].It utilizes the Matlab channel access library to establish a connection with the fundamental EPICS control system [2].CLS developed and tested a new orbit correction system the CLS Matlab application, known as CLSORB, with a high-speed capability [3].This system offerd an adjustable rate range of 20 Hz to 100 Hz.The OCS at CLS comprised a computer that ran Matlab, along with four Versa Module Eurocards (VMEs).Each VME corresponded to three sections of the storage ring.Additionally, the system also incorporated a Real-Time Executive for Multiprocessor System (RTEMS).In 2021, the OCS underwent a significant upgrade [4].As part of this upgrade, the previous RTEMS-VME system was retired and replaced with new components.The recently developed orbit correction system integrates D-tAcq Analog to Digital Converters (ADCs) for monitoring BPM positions.It also features Nuclear Instrument Modules (NIM) utilizing PoLabs single board controllers for the parallel distribution of magnet power supply setpoints and a scientific Linux 7 operating system is used to run the new software.The purpose of this advanced system is to ensure that any disturbances caused by electron perturbations are immediately detected and corrected to maintain beam stability and optimal light quality at the beamlines.Hardware and software of the orbit control systems were developed until the RMS deviation of beam motion was reduced to less than one micrometer in both the X and Y directions.The Accelerator Operations and Development (AOD) team is currently working on upgrading this system.This involves improving its efficiency, increasing its accuracy and adding new features to meet the evolving needs of users.With technological advancements being made every day, it is important to keep upgrading existing systems to stay relevant and efficient in a rapidly changing landscape.The AOD team has embarked on new research to design a Dynamic Orbit Correction System (DOCS) based on Neural Network (NN) algorithm for the orbit correction system.The NN correction system offers advantages over the IRM algorithm, excelling in dynamic adaptability, flexible programming, and computation speed.Unlike the static IRM, the NN system learns from data, making it accurate in changing conditions.Its adaptable nature handles misalignments effectively.The NN's efficient script allows customization and rapid computations, while IRM's matrix recalculations slow it down.The precision and real-time capabilities of this DOCS have been reported [5].The aim of this research is to improve the accuracy of the neural network model by incorporating deep learning techniques.To achieve this goal, we will conduct experiments and analyze the data to determine the effects of deep learning methods on accuracy.

Neural network
A neural network is a type of machine-learning model inspired by the structure and function of the human brain.It consists of interconnected nodes or neurons that process information to make predictions or decisions [6].Also, Deep learning is a subfield of machine learning that uses neural networks with multiple layers to extract and learn features from data.It is capable of automatically discovering complex patterns and relationships in large datasets [7].
The following sections will briefly discuss the neural network architecture and parameters utilized in the CLS orbit correction system model, and also provide a definition of deep learning loops.

Network architecture
Designing a neural network architecture requires a significant amount of information about the real system it will be applied to, as the architecture is highly dependent on the specific characteristics and structure of the system.In brief, the CLS orbit correction system is comprised of 96 Bergoz Beam Position Monitors (BPMs) that transmit the beam's position to the IRM at a frequency of 1000 measurements per second.The IRM serves as the central processing unit of the OCS, responsible for computing the strength of the Orbit Correctors.Ultimately, the 96 outputs from the IRM are transmitted to the 96 orbit correctors at a rate of 18 transmissions per second.
In the first step, we designed a neural network algorithm instead of using IRM.For this case, we utilized the TensorFlow-Keras library in Python, which is renowned for its speed and is considered one of the fastest AI modules.The neural network consists of three hidden layers with 96 nodes, and the best activation function was found to be hyperbolic tangent.After a single learning step with 20 epochs, the model achieved a MSE of (3.152 * 10 −7 ).The Mean Squared Error is a loss function that measures the average squared difference between the predicted values and the actual target values in the training dataset.

Deep learning loops
The initial model performed well, and its real-time capabilities were tested on actual data, exhibiting negligible error when the system was in a stable mode.In addition to the aforementioned scenario, there is another situation that should be taken into account, when the beam position changes significantly.In this case, the neural network model must be capable of adapting to these changes in order to provide accurate predictions.Therefore, it is essential to ensure that the model is trained using a diverse set of data that encompasses a wide range of beam positions and conditions.This will enable the model to effectively learn and generalize to new and unseen scenarios, including cases where the beam position changes drastically.In this study, a learning loop was designed to address the issue at hand.The loop begins by loading the initial model, after which a new dataset is evaluated using the model.If the error of the model's output exceeds the expected value, the model is updated with new epochs and activation functions as necessary.Finally, Fig. 1 the accuracy of the updated model is checked, and it replaces the previous model if it performs better.

Experiments and results
The CLS storage ring is comprised of twelve distinct sections, each of which contains four BPMs and four OCs with both x and y directions.This configuration yields a total of 96 inputs and 96 outputs for the orbit correction system.Figure 2 shows a schematic of BPMs configuration in the storage ring.Ninety-six inputs, which correspond to BPMs, are recorded at a rate of 1000 Hz, while the system generates ninety-six outputs, which correspond to OCs, at a rate of 18 Hz.There are two scenarios that we have assumed for the system.In the first scenario, the system operates in a stable mode, and the learning loop attempts to improve its model accuracy.In the second scenario, the stable mode changes to varying positions, and the learning loop modifies the  In the first scenario, when the system is functioning normally, we conducted the learning loop four times.During the first phase, we developed the model, while the second to fourth phases involved updating the model.In addition, we introduced a metric called Accumulated Error (AE), which represents the sum of errors across all OCs.The calculation of AE involves taking the absolute difference between the real value of the orbit corrector and the predicted OC, divided by the real data.Our developed model demonstrates excellent performance, with an AE of 109.72%.When applied to the 96 OCs, the error rate per OC is estimated to be approximately 1.1%.Figure 3(a) suggests that the model is robust and reliable in predicting values for the given dataset.We implemented the deep learning loops step by step, beginning with an upgrade without any changes in the epochs and architecture.Remarkably, the AE decreased to 73.06%, indicating a significant improvement in performance.This corresponds to an error rate of approximately 0.76% per orbit corrector, which is substantially lower than the previous error rate.Figure 3(b) demonstrates the efficacy of the deep learning approach in improving the accuracy of the model.Continuing with the upgrade, we observed in the Fig. 3(c) a further improvement in the model's performance.The AE decreased to 50.59%, which equals an error rate of approximately 0.53% per OC.4th upgrade, we observed in the Fig. 3(d In the following scenario, the beam position is expected to undergo a sudden change, presenting a challenging situation for the OCS.We aim to investigate whether this loop can update a model with memorized coefficients, furthermore, we will calculate the error that arises during this process.The objective of this experiment is to evaluate the effectiveness of the updates to the NN model, and to assess whether they result in a decreasing or increasing trend in performance. At the CLS, a total of four BPMs and four OCs are installed in each section of the storage ring.Each BPM measurement includes both Horizontal (H) and Vertical (V) beam position.Specifically, BPM01 -04 are located in section one, and BPM05 -08 are installed in section two, and similarly, the BPMs configuration is repeated throughout the remaining sections as shown in Fig. 2.
In this experiment, the BPM's values in different sections of the storage ring (SR) were changed by adjusting the reference (offset) to create a desired beam position situation (+1 and -1 mm) for the OC system.The system was tested at a beam current of 8.0 mA.Table (1) displays the alterations to the reference (offset) and how they reveal variations in BPM values across distinct SR sections.
Table 1.Some of the adjustments made to the reference or offset (µm) were shown to demonstrate the change in BPM values across different sections of the SR.'H' and 'V' refer to the horizontal and vertical detectors, respectively.Rand refers to random offsets utilized for all BPMs, ranging between -1000 µm and 1000 µm.Rand.

Experiment
The OCS's performance was recorded in the aforementioned scenarios for both BPMs and OCs.This data was subsequently utilized to learn, train, test, and develop DOCS.
In this research, we tested several assumptions and found that the results of all of them were the same.Here, we present one of these results.In the first scenario, the beam is in the position that corresponds to test 1 in the table (1).The NN model was developed (with 80 epochs and the same architecture) for this situation, and we consider it to be our initial model which has 1.184% error per OC as shown in Fig. 4  Following that, a disturbance occurs, and the system transitions into the mode detailed in test 20 of Table 1.The NN model was updated twice during this period, as depicted in Figs.4(c

Conclusion
Two conditions of the NN model's effectiveness were investigated, a stable mode and a complex mode.The results for the stable mode demonstrate that error rates decrease over time, from 1.1% per OC in the first experiment to 0.42% per OC after four steps.While this result was expected, it provides further confirmation of the effective operation of the deep learning loops in the NN model, which successfully reduce error rates over time in the stable mode condition.The results of the second scenario are less definitive than those of the stable mode upgrade, as shown in Fig. 5.However, they do display a decreasing trend in error rates despite some fluctuations.Figure 5 shows a decreasing trend in prediction errors for a specific data set (upgrades 1 and 2), but the deep learning model is unable to generalize its performance to new data sets (upgrade 3) without further training.However, next step training result in reduced errors on new data sets (upgrades 4 and 5).This cycle continues, and the errors decrease smoothly over time.The results demonstrate that the NN model is highly effective, and the Deep Learning loop successfully increasing the model's precision.While the results show promise and suggest that the NN model could be a valuable technology for various applications, it is important to acknowledge the limitations of our study and the need for further research to thoroughly explore its capabilities and potential applications.The current findings, while encouraging, should be viewed with a degree of restraint, and additional studies are warranted to establish the full extent of the NN model's benefits and limitations.

Figure 1 .
Figure 1.The BPM and OC datasets from the real system are fed into the learning loops.The NN model uses the BPMs to generate new OCs, and the error between the predicted and real OCs is calculated.If the error exceeds the expected threshold, the NN model is updated with the current dataset and replaces the old NN model.This loop is repeated periodically to refine the NN model.

Figure 2 .
Figure 2. A schematic of the CLS (Canadian Light Source) storage ring that comprises twelve sections and 48 BPMs.

12th
International Beam Instrumentation Conference, IBIC23 Journal of Physics: Conference Series 2681 (2024) 012005 IOP Publishing doi:10.1088/1742-6596/2681/1/0120054model to prepare for the future.In this research, we investigated the deep learning capabilities of the DOCS platform.Due to the lack of available real-time data, we collected data from the CLS using a sampling frequency of 1000 Hz for BPMs and 18 Hz for OCs.The collected data was saved in large JSON files, which were then split into smaller files for use in our deep-learning model.

Figure 3 .
Figure 3.The blue line represents the actual data for 96 OCs obtained through the SVD algorithm.The orange line represents the predicted values for the same OCs obtained through NN models.The green line shows the difference between the actual and predicted values.The green value corresponds to the total error (AE) calculated across all 96 OCs.The horizontal axis shows the 96 orbit correctors.(a) The first model (b) The first upgrade (c) The 2nd modification (d) The 3rd upgrade.
(a).The learning loop attempts one upgrade and generates an NN-upgraded model with 0.515% error per OC as shown in Fig. 4(b).

Figure 4 .
Figure 4.The blue line represents the actual data for 96 OCs obtained through the SVD algorithm.The orange line represents the predicted values for the same OCs obtained through NN models.The green line shows the difference between the actual and predicted values.The green value corresponds to the mean error for each OC.The horizontal axis shows the 96 orbit correctors.(a) The first model (b) 1st upgrade (c) 2nd upgrade (d) 3rd upgrade (e) 4th upgrade (f) 5th upgrade (g) 6th upgrade (h) 7th upgrade.
) and 4(d).The turbulence is controlled, and the perturbation sequence returns to mode 1, the NN model has upgraded twice again shown in Figs.4(e) and 4(f).Finally, the system experiences a period of instability, during which the perturbation sequence exhibits unpredictable behavior.As a result, the learning loop generates two new updates for the NN model, as shown in Figs.4(g) and 4(h).The scenario described, demonstrates that updates to 12th International Beam Instrumentation Conference, IBIC23 Journal of Physics: Conference Series 2681 (2024) 012005 IOP Publishing doi:10.1088/1742-6596/2681/1/0120057 the NN model's weight parameters are effective, resulting in a statistically significant decrease in error rates over time.

Figure 5 .
Figure 5. Errors (percentage per OC) are displayed in eight upgraded steps.The blue dots represent the mean errors in each step, the red line shows the trend of the errors.