  Encoding frequency stability constraints in the operation problem is
challenging due to its complex dynamics. Recently, data-driven approaches have
been proposed to learn the stability criteria offline with the trained model
embedded as a constraint of online optimization. However, random sampling of
stationary operation points is less efficient in generating balanced stable and
unstable samples. Meanwhile, the performance of such a model is strongly
dependent on the quality of the training dataset. Observing this research gap,
we propose a gradient-based data generation method via forward-mode automatic
differentiation. In this method, the original dynamic system is augmented with
new states that represent the dynamic of sensitivities of the original states,
which can be solved by invoking any ODE solver for a single time. To compensate
for the contradiction between the gradient of various frequency stability
criteria, gradient surgery is proposed by projecting the gradient on the normal
plane of the other. In the end, we demonstrate the superior performance of the
proposed sampling algorithm, compared with the unrolling differentiation and
finite difference. All codes are available at
https://github.com/xuwkk/frequency_sample_ad.
