An optimization method to compensate accelerator performance drifts

Accelerator performance often deteriorates with time during a long period of operation due to secular changes in the machine components or the surrounding environment. In many cases some tuning knobs are effective in compensating the performance drifts and optimization methods can be used to find the ideal machine setting. However, such intervention usually cannot be done without interrupting user operation as the optimization algorithms can substantially impact the machine performance. We propose an optimization algorithm, Safe Robust Conjugate Direction Search (RCDS-S), which can perform accelerator tuning while keeping the machine performance within a designated safe envelope. The algorithm builds probability models of the objective function using Lipschitz continuity of the function as well as characteristics of the drifts and applies to the selection of trial solutions to ensure the machine operates safely during tuning. The algorithm can run during normal user operation constantly, or periodically, to compensate the performance drifts. Simulation and online tests have been done to validate the performance of the algorithm.


I. INTRODUCTION
Online optimization is an effective approach to find accelerator settings with high performance. In online optimization, a number of machine control parameters (i.e., tuning knobs) are varied by an optimization algorithm to minimize or maximize the objective function, which represents the machine performance and is measured experimentally for each machine setting. Efficient optimization algorithms are key to online optimization. Popular optimization algorithms for online accelerator applications include Nelder-Mead simplex [1], robust conjugate direction search (RCDS) [2], particle swarm [3], and Bayesian optimization [4].
Typically, when the algorithm suggests new trial solutions, the step size from known solutions is not restricted and the performance of the trial solution is not guaranteed. During an optimization run, as the algorithm gradually discovers machine settings with high performance, it can also produce solutions with poor performance, which cannot be tolerated for normal user operation. Therefore, online optimization is usually performed during dedicated machine development or study shifts. Often times, after the ideal machine setting is found, it is delivered to user operation for days or weeks, until the next window for tuning becomes available.
However, in many cases, an ideal machine setting will not maintain the high performance during the long period of user operation. Small variations in the accelerator components, caused by or coupled with variations of the surrounding environment, can cause the machine performance to drift with time. The underlying causes of the performance drift are not always known; even if a connection with certain environmental factors can be established, the relationship is often not adequately deterministic to build reliable feedforward control. On the * Also at Illinois Institute of Technology, Chicago, IL 60616. † xiahuang@slac.stanford.edu other hand, the performance drift can usually be compensated by tuning some control knobs. Unfortunately, as such tuning can only be done during dedicated shifts, one has to either tolerate the deteriorating machine performance or interrupt the operation schedule to add a tuning session.
In this study, we propose a safe tuning method that can be used during user operation. The new algorithm is called safe robust conjugate direction search (RCDS-S). It employs iterative one-dimensional (1-D) optimization over a conjugate direction set in a similar manner as the RCDS method. However, its 1-D optimization is done by a more prudent and informed fashion, which employs a probability model of the objective function to assess the risk of exceeding a safety threshold by the trial solution. The probability model includes the combined effect of the innate variation of the objective function and the slow drift with time.
The proposed method is similar to an earlier method [5,6], in that both studies make use of the Lipschitz continuity properties of the objective function. However, there are significant differences between the two methods. In Ref. [6], a safe domain is identified through the Lipschitz continuous condition, over which Gaussian process optimization is performed. In our method, the Lipschitz continuity condition is used to select trial solutions based on the need to explore the parameter space and the safety requirement; the trial solutions are used in a parabolic fitting to determine the location of the minimum.
The new method has been successfully tested with a real-life problem in both simulations and experiments. The test problem is kicker bump matching of a storage ring. In the tests, the amplitude of a kicker is modulated independently, while the amplitudes of the other two kickers are tuned by the algorithm. It was shown that the objective function can be kept below a pre-specified threshold during the tunig period. A beam steering for optimal injection efficiency problem is also used to test the algorithm in simulation.
This paper is organized as follows. Section II describes the RCDS-S algorithm. Section III shows the application of RCDS-S to two simulated drifting accelerator problems. Section IV presents experimental results when the method is applied to a real accelerator. Section V discusses an alternative approach to model the system drift and shows a few preliminary test results. Section VI gives the conclusion.

II. THE RCDS-S METHOD
Our goal of the study is to develop an optimization method that can be used to optimize accelerator performance during user operation by keeping the performance above a certain threshold. Such a method could be termed "safe" optimization algorithm. A safe optimization algorithm could be used to compensate the performance drift with time, as it can run in the background continuously, periodically, or as needed. To achieve the goal, it is necessary to first understand the sources of the danger in the usual "unsafe" methods, before a cure can be found.
In the following, we first discuss the uncertainty of the objective function as it is probed. By constructing a probability model of the uncertainty and using it to guide the selection of new trial solutions, we devised a safe 1-D optimization method. Combining this safe 1-D optimization method and the conjugate direction search method, we arrived at the new algorithm, RCDS-S.

A. Modeling uncertainty of objective function
In this study, we cast an optimization problem as to minimize the objective function with a set of tuning knobs, f (x), where elements of x are the knob values. An online optimization problem has measurement errors, therefore, where ∼ N (0, σ 2 n ), σ n is the standard deviation of measurement errors.
In online optimization, the optimization algorithm continues to sample the objective function by evaluating new trial solutions. The sampling results are used by the algorithm to determine the next trial solution. Depending on the efficiency of the algorithm, the overall trend among all the trial solutions is to improve the objective function. However, for the traditional algorithms, a trial solution at any time could correspond to a poor performance, as they typically do not limit the step size with the predicted performance. In this case, the intrinsic variation of the objective function in the parameter space poses as a danger.
To be able to suggest a safe trial solution, the algorithm has to have a sort of model about the unknown objective function. Our approach is to simply limit the gradient of the function. Mathematically, the objective function is assumed to be L-Lipschitz continuous, which means for any x, x 0 ∈ D, where D is the domain of the function, we have, Considering noise, it leads to wereˆ ∼ N (0, 1). Clearly, the expectation of y satisfies The goal of the safety search method is to keep the objective function below a certain safety threshold, for any trial solutions the algorithm proposes during the optimization. Let the safety threshold be h, point x would be a safe point, i.e., y ≤ h, if The probability for Eq. (1) to hold for point x is where erf(·) is the error function.
A second source of danger in online tuning is the drift, or the time-dependent variation, of the objective function. Without further information about the specific optimization problem, the drift can be modeled as a random walk process. Under this assumption, the uncertainty of the measurement becomes a time varying random variable, When the drift at one point x is treated as a Gaussian random walk process, the measured function value differs from the original value by a random amount, whose standard deviation increases with time according to where σ d is the drift rate, with σ 2 d representing the increase of the variance within a unit time interval, and t the time elapsed from a reference point. It would be reasonable to assume that noise and drift are not coupled, which is used to update Eq. (2).

B. 1-D safety exploration without drift
By applying the probability model of the objective function to the 1-D subspace, i.e., along a line in the parameter space, we can develop a strategy to safely explore the linear space. The idea is that we calculate the safety probability for all points (i.e., potential trial solutions) along the full viable range, using each previous observation point based on Eq. (2). For any candidate point, we take the maximum of all the calculated probabilities as the estimated safety probability for that point. For example, if 5 observations are given, we have 5 probabilities, p 1 ∼ p 5 , calculated from the observations at position x, and the final assigned safety probability of x is p(x) = max(p 1 , p 2 , p 3 , p 4 , p 5 ). In this way, we obtain a safety probability curve along the line. To determine the next point to sample, we introduce a performance indicator (PI): safety probability threshold p s , which indicates the required safety probability for safe exploration. For example, p s = 0.99 means the algorithm should only choose the point as the candidate where the assigned safety probability is higher than 0.99. With safety probability threshold defined, the safety region can be computed.
To illustrate the 1-D safety exploration strategy, we introduce a simple test function, where σ n the standard deviation of a Gaussian noise,ˆ a random variable that obeys the standard normal distribution. This test function f (x) is L-Lipschitz continuous.
In this case study, we choose Lipschitz constant L = 1 and safety threshold h = 0.2. Fig. 1 shows an example of the safety probability curve and the safety region (highlighted in green), when 7 observation points are given.
Similar to the RCDS method, the purpose of line exploration is to collect enough data points to bracket the minimum and to perform a parabola fitting. Before the minimum is bracketed, it would be preferred to expand the sample coverage region as far as possible. Therefore, the next data point is chosen to be one of two edge points of the safety region, usually the one further away from the known observation points. When the trial solution is evaluated, it becomes an observation point. The exploration process described above repeats until we have enough data points to do a parabola fitting (as shown in Fig. 3). More detailed logic and the implementation of safety exploration along one direction can be found in Algorithm 1. The safety exploration algorithm has three exit conditions, which indicate the exploration is successful, aborted as no safe candidates are available, or the maximum number of trial solutions are attempted but without success, respectively.

C. 1-D safety exploration with drift
As discussed earlier, when drift to the objective function is introduced, the calculation of the safety probability changes (see Eq. (3)). Intuitively, an older observations would become less reliable than the newer observations. As a consequence, the contribution of each observation to the safety probability calculation differ with measurement time. The 1-D safety exploration procedure is applicable to the case with drift, only with the changes to the safety probability calculation.
We will use the same test problem, shown in Eq. (4), for illustrating and testing, but with modulation to the  minimum position µ to simulate the systematic drift, where p and σ d are the period and amplitude of the modulation, respectively.
The test function with drift, f (x, t), is shown in Fig 4, where the red line indicates the drifting of the minimum position. Fig. 5 is the snapshot of the safety probability at the end of the safety exploration. Clearly, the calculated safety probability curve is altered significantly compared to the case without drift (see Fig. 1). The observation points (orange triangles) to the right side are older samples, which have less impact on the safety curve, as expected. The evolution of the safety probability over the test problem domain during the safety exploration is shown in Fig. 6.

D. The RCDS-S algorithm
Combining the scheme of iterative 1-D optimization over conjugate directions [7], the safety 1-D exploration discussed in previous sections and the use of parabolic fitting to determine the minimum [2], we arrive at the RCDS-S algorithm. The algorithm logic flow is provided in Algorithm 2. In the algorithm implemenation, we choose to normalize all parameters to within the range of [0, 1]. In the following we discuss two aspects regarding the application of the method in more details.
First, after each iteration, when the algorithm has gone through all directions, one could replace one of the existing directions with the new direction that goes from the previous minimum to the new minimum. In the traditional Powell method, this decision is done by assessing an additional point on the new direction and using the result to estimate the potential gain from the direction [8]. However, the additional evaluation could be unsafe. As a simple solution, the RCDS-S algorithm provides an option to always replace or not replace the direction. The option of not to replace the direction is expected to be more suitable in cases where a conjugate direction set is available through model calculation or analysis of past measurement data.
The second important aspect is about the choice of the hyper-parameters for safety exploration. Two most critical hyper-parameters in the modeling of the safety probability are the Lipschitz constant L v in normalized decision space and the drift rate σ d in time. Choosing good values for these two parameters is crucial to the safety performance of the proposed algorithm. Compared to the ideal value, a smaller L would result in less safe exploration by increasing the chance of sampling an unsafe point. On the other hand, a larger L encourages more conservative exploration that wastes more points for each direction and would lead to slower convergence. Slow convergence is problematic, especially for the drifting case, as it can cause the algorithm to fail to follow the drifting optimum.
The hyper-parameters can be obtained before applying the algorithm to a specific problem by analyzing historic data or performing additional measurements. For example, the maximum drifting rate σ d can be estimated by observing the variation of the objective function in a long period of time when no knobs are varied. The Lipschitz L parameter can be determined through conjugate direction scans, which are to perform full-range linear scans over the directions in the initial conjugate direction set of the normalized decision space. The maximum absolute gradient of all the scanned directions can be used as the L v parameter. In the algorithm we use one L parameter for all directions. In the case when no direction is replaced during execution of the algorithm, a different L value could be provided for each direction. The more accurate hyper parameter could lead to better safety and efficiency. Because the RCDS-S algorithm relies on probability models to choose trial solutions and these models strongly depend on the accuracy of hyper-parameters, we do not expect all trial solutions are guaranteed to be safe. There could be times when the algorithm fails to follow the drift. In other times, even when the algorithm is following the drift, there could be occasional trial solutions that exceed the safety threshold. Therefore, while the algorithm tends to allow safe exploration of the parameter space, it is not recommended for high risk applications.

III. SIMULATION TESTS
Simulation studies were conducted to test the performance of the RCDS-S algorithm in online optimizations for drifting problems. Two simulated accelerator test problems are used. The first problem is kicker-bump matching for a storage ring, with a 2-D decision space. The second one is the steering of the injected beam in the booster to storage ring (BTS) transport line to maximize injection efficiency [2], which is a 4-D problem.

A. Kicker-bump matching safety optimization
The Stanford Positron and Electron Asymmetric Ring-III (SPEAR3) storage ring has three injection kickers that, ideally, form a closed orbit bump when fired. In reality, the kicker bump is not strictly closed, leading to residual oscillations after the kickers are fired. The purpose of the kicker bump matching program is to find the kicker setting that minimize the residual oscillations.
In the test, the strength of one kicker, K1, is modulated in a sinusoidal form to simulate the systematic drift, as where p is the drifting period, σ d the drifting amplitude, t 0 the time origin, v 0 the initial value of the modulated variable.
The strengths of the other two kickers, K2 and K3, are used as tuning knobs of the optimization problem. The rms turn-by-turn horizontal orbit from 256 turns of residual oscillations is used as the objective function. A Gaussian noise with strength σ n is added to the objective. The problem is normalized so that the knob values vary between 0 and 1.
For the algorithm tests, we set p = 800, σ n = 3 µm, σ d = 0.1 µm per evaluation period. Based on the two prescans discussed in the last section, the Lipschitz constant L and strength of Gaussian random walk σ g are chosen to be 2000 and 0.2, respectively. The safety threshold h can be varied to change the safety search difficulty. In the tests, the safety threshold is set to 40 µm, which is only slightly higher than most of the observed values of the noisy objective at the initial solution.
The tests have been run multiple times, and the performance is stable. A typical test is shown in Fig. 8. The top plot compares the objective function over one modulation period for three cases: no optimization, tuning with RCDS, and tuning with RCDS-S. The test result shows that RCDS-S is able to follow the drift and seek the optimum while keeping the objectives of the trial solutions well below the safety threshold. RCDS is also very efficient for the test problem. However, since it is not aware of the safety threshold, the proposed solutions are not guaranteed to be safe.

B. BTS injection efficiency safety optimization
The RCDS-S algorithm has also been tested with a 4-D problem in simulation. The test problem is to maximize the injection efficiency with steering knobs in the BTS transport line. Two pairs of upstream correctors, one pair in each transverse plane, are modulated according to Eq. (5) to simulate systematic drift. Two pairs of correctors, also one pair for each plane, toward the end of transport line are used as tuning knobs to compensate the trajectory drift and its impact to injection efficiency. The objective function is the negated injection efficiency. The noise level σ n is set to 0.05 and drift period p = 800. The drift amplitude is large enough such that the injection efficiency drops to zero for half of the modulation period. The safety threshold is set to −0.5 (i.e., corresponding to a 50% injection efficiency). Fig. 9 shows the results of a typical test run. The RCDS-S algorithm keeps the injection efficiency near the maximum and its trial solutions are mostly within the safe region. In comparison, the RCDS algorithm not only exceeds the safety threshold, but also occasionally fails to follow the drifting.

IV. EXPERIMENTAL APPLICATION OF THE RCDS-S ALGORITHM
The RCDS-S method has been applied experimentally to the kicker bump matching problem on the SPEAR3 storage ring to demonstrate its capability to compensate drifts in online optimization. The setup of the problem is the same as was discussed in the previous section in simulation.
The goal is to minimize the residual oscillation as seen by a turn-by-turn beam position monitor. The voltage amplitude of one kicker (K1) is modulated with a period of 800 data points, with an interval of 2 seconds between data points. The noise level was measured right before the algorithm test and was found to be 5 µm. The initial solution is the same as the operation setting which would give the best objective if the system is not drifting.
Two rounds of tests were performed with the experimental setup. For the first round, the safety threshold is set to 60 µm. As it succeeded, we set the safety threshold to 50 µm for the second round. The results for the second round are shown in Fig. 10, where the objective function for RCDS-S for one modulation period is compared to the results of RCDS and the case without tuning. The objective function for the first round is shown in Fig. 11. The experimental performance is similar to the simulation cases for both RCDS-S and RCDS. The objective function has a larger variance for the evaluated trail solutions in experiments. This could be due to the higher measurement noise level. RCDS-S would explore until it brackets the peak of the objective curve, and hence, the higher noise level is, the wider the exploration range would be, for the 1-D exploration to gain the same level of confidence that a peak has been bracketed. Another behavior that has been observed in experiment is that RCDS-S had a few small violation solutions for both rounds. This could be due to a mismatch between the true L v of the experiment problem and the one we applied in the algorithm (that comes from the simulation). Using a larger L v could reduce the violation rate at the expense of more trial solutions per direction, and consequently would increase the probability of RCDS-S failing to follow the systematic drift.

V. ALTERNATIVE APPROACH TO MODEL DRIFT
In Sec. II A, the systematic drift is modeled as an increasing uncertainty with time. With this model we are not incorporating any prior knowledge about the drift behavior of the system. It may be possible to improve the predictive capability of the model if the drift trend is included. In the general case, the objective function can be seen as a function of both the tuning knobs and time, Similar to the variation of knobs, one simple assumption about the dependence on time is that the rate of change has an upper limit. In this case, in addition to the L-Lipschitz continuous condition on x, we also assume the objective function to be σ d -Lipschitz continuous on t: Therefore, based on the observation on a point x 0 that was measured at time −t (relative to the current time), we have: Following the same path as in the derivation of Eq. (1), we have:ˆ where E max is as defined previously, which is the maximum expected value at point x without drift.
FIG. 12. Snapshot of the safety probability along the viable range at the end of 1D safety exploration. Safety probability curve is calculated based on the alt drift model with the given observations. Orange triangles denote the observations, the order of sampling is denoted by the number on top of each observation. Blue curve is the calculated safety probability and the green shaded area shows the safety region with the safety probability threshold ps = 0.9.
This alternative approach to perform a 1D safety exploration is applied to the test problem discussed in Sec.II C. The efficiency is found to be similar to the Gaussian random walk approach. However, the evolution of the safety prob curves, and consequently the sampled points, are quite different for the two cases. The timesensitivity of the alternative approach is higher than the original one, i.e., the impact of the older data points to the safety prob curve decays faster, as shown in Fig. 12. For example, the three points on the right side almost have no impact on the safety prob curve. The evolution of the safety probability during the 1D exploration is visualized in Fig. 13.

VI. CONCLUSIONS
In this study, we propose an optimization algorithm (RCDS-S) that combines robust conjugate direction search and a new 1-D safety exploration algorithm to optimize noisy, drifting machine performances online, while keeping the machine performance within a designated safe envelope. The 1-D safety exploration algorithm makes use of Lipschitz continuity of the objective function and properties of a Gaussian random walk process for the drift to build a probability model of the drifting function, with which to suggest safe trial solutions. The proposed algorithm has been successfully tested on simulated and experimental accelerator tuning problems.