Power flow calculation methods, systems, and equipment based on graph neural networks
By constructing a cross-topology transferable power flow calculation system based on graph neural networks, the problems of computational burden and iterative convergence in large-scale power grids are solved, achieving fast and reliable power flow calculation applicable to different power grid topologies.
Patent Information
- Application Number
- CN202611611367.6
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Filing Date
- 2026-10-19
- Publication Date
- 2026-11-17
AI Technical Summary
Existing power flow calculation methods for power systems are computationally burdensome when dealing with large-scale power grids or massive scenarios. Their iterative convergence depends on initial values and they lack cross-topology generalization capabilities, making it difficult to meet the real-time requirements of online applications.
By employing a graph neural network-based approach, a graph neural network model is constructed. This model utilizes an edge aggregation message passing layer and a topology adaptive graph convolutional layer to process power grid data. The model is then trained using a composite loss function to generate a cross-topology transferable power flow calculation system capable of performing rapid calculations under different power grid topologies.
It enables power flow calculations without retraining under different power grid topologies, significantly improving computational efficiency and meeting the high-frequency calculation requirements such as N-1 security scan and Monte Carlo analysis, with highly reliable results.
Smart Images

Figure CN123116877A_ABST
Abstract
Description
Technical Field
[0001] This application relates to the field of power system power flow calculation technology, and in particular to a power system power flow calculation method, system and computer equipment based on graph neural networks. Background Technology
[0002] Power flow calculation is a fundamental tool for power system planning, operation, dispatching, and security analysis. Its core task is to solve for the voltage magnitude, voltage phase angle, and branch power distribution of each bus under boundary conditions, given the grid topology, line parameters, and injected power (or voltage) at each node. With the large-scale integration of new energy sources, the operation mode of the power system is becoming increasingly complex. The grid topology changes frequently due to maintenance, faults, or the connection of new energy sources. Dispatch and operation departments need to obtain approximate solutions for power flow quickly and stably under massive operating scenarios to support high-frequency calculation requirements such as N-1 security scans, Monte Carlo uncertainty analysis, and repeated calls to the inner layer of optimized dispatching.
[0003] Currently, fast power flow solution schemes for power systems can be broadly categorized into two types. The first type is traditional numerical methods, represented by the Newton-Raphson method, fast decoupling method, and DC power flow method. These methods are based on rigorous physical models of the power system and obtain high-precision power flow solutions by iteratively solving a set of nonlinear power balance equations. However, these methods require independently constructing the node admittance matrix for each operating scenario and iteratively solving it repeatedly. When dealing with large-scale power grids or massive scenarios, the computational burden increases dramatically. Furthermore, their iterative convergence heavily depends on the initial value selection; unreasonable initial values may lead to iteration divergence or slow convergence, making it difficult to meet the real-time requirements of online applications.
[0004] The second category is early data-driven methods. Researchers attempted to use fully connected networks or convolutional neural networks, manually preparing a small number of power flow cases as training samples to establish a regression mapping model from grid inputs to outputs. However, fully connected networks require flattening the grid topology into a fixed-length feature vector, failing to effectively utilize the inherent graph structure information of the grid; while convolutional neural networks can extract local features, their input requires a regular grid structure. Once such models are trained, they become tied to the number of buses and topology of a specific grid. If the grid size or connectivity changes, samples must be collected again and the model retrained, lacking cross-topology generalization ability. Summary of the Invention
[0005] Therefore, it is necessary to provide a power system power flow calculation method, system, and computer device based on graph neural networks to address the above-mentioned technical problems, which can realize fast AC power flow calculation that is transferable across topologies.
[0006] Firstly, this application provides a power system power flow calculation method based on graph neural networks, including:
[0007] Using the IEEE standard example as the base network, random perturbations are applied to the topology and electrical parameters of the base network to simulate multiple operating conditions;
[0008] The Newton-Raphson method is used to solve the AC power flow for each operating condition, and convergent samples are selected from multiple operating conditions based on the solved AC power flow. Each convergent sample is exported as graph structure data. The graph structure data includes node features and edge features. The node features include at least the voltage magnitude, voltage phase angle, injected active power and injected reactive power of each node, and the edge features include at least the resistance and reactance of each branch.
[0009] Based on graph structure data, a graph neural network model is constructed. The graph neural network model includes an edge aggregation message passing layer and a topology adaptive graph convolutional layer. The edge aggregation message passing layer is used to process the source node features, target node features and edge features of each edge using a multilayer perceptron, and then normalizes and aggregates them to the target node according to the degree of symmetry.
[0010] A prediction mask is generated according to the bus type, and the prediction mask is encoded and superimposed on the node input features of the graph neural network model; the bus types include balanced nodes, PV nodes and PQ nodes.
[0011] A composite loss function is used to train the graph neural network model; the composite loss function includes at least a masked regression loss term, which is used to calculate the mean square error based on the electrical quantity to be predicted at each node;
[0012] The trained graph neural network model is used for inference, and the prediction results of each node are output; the prediction results include at least the voltage magnitude and voltage phase angle of each node.
[0013] Based on the prediction results, the power flow calculation results for each node are determined.
[0014] In one embodiment, the method further includes:
[0015] The graph neural network model trained on the first example is applied to a second example with a different number of nodes and a different topology than the first example for inference, and the normalized parameters from the training phase are reused.
[0016] In one embodiment, the topology and electrical parameters of the base network are randomly perturbed, including at least one of the following:
[0017] Randomly add or remove lines to change the topology;
[0018] The line impedance parameters are randomly scaled according to a preset ratio range;
[0019] Randomly select a value for the generator terminal voltage within a preset voltage range;
[0020] The active power of power generation, the active power of load, and the reactive power of load are randomly disturbed according to a preset probability distribution, which includes the normal distribution.
[0021] In one embodiment, a prediction mask is generated according to the bus type, and the prediction mask is encoded and superimposed on the node input features of the graph neural network model, including:
[0022] The electrical quantities to be predicted at the balancing node are configured to include injected active power and injected reactive power, the electrical quantities to be predicted at the PV node are configured to include voltage phase angle and injected reactive power, and the electrical quantities to be predicted at the PQ node are configured to include voltage amplitude and voltage phase angle.
[0023] Mark the mask bits corresponding to the known electrical quantities as 0, and mark the mask bits corresponding to the electrical quantities to be predicted as 1;
[0024] The predicted mask is mapped into a continuous vector through a fully connected layer and then fused with the node input features in an additive manner.
[0025] In one embodiment, the composite loss function further includes a known quantity retention loss term, which is used to apply a regularization constraint to the mean square error between the predicted values of electrical quantities that are known by the prediction mask at each node and the input values.
[0026] In one embodiment, the composite loss function further includes a power imbalance loss term, which is used to calculate the active and reactive power of each node through the AC power flow equation based on the voltage amplitude and voltage phase angle predicted by the model, and to calculate the mean square error between the node power output by the model or the assembled power and the power calculated by the AC power flow equation.
[0027] The total loss of the composite loss function is the weighted sum of the mask regression loss term, the known quantity preservation loss term, and the power imbalance loss term. The weight of the power imbalance loss term is gradually increased during training using a weight scheduling strategy.
[0028] In one embodiment, after constructing a graph neural network model based on graph structure data, the method further includes:
[0029] Multiple graph neural network architectures are registered through a model registry center; the model registry center is configured with architecture identifiers corresponding to different graph neural network architectures.
[0030] When it is necessary to switch model architectures, the model registry can automatically call the corresponding graph neural network architecture to build the model by modifying the architecture identifier in the configuration file or specifying the target architecture identifier through command line parameters, thereby realizing the switching of multiple graph neural network architectures.
[0031] In one embodiment, after performing inference using a trained graph neural network model and outputting the prediction results for each node, the method further includes:
[0032] Based on the prediction results of each node, the mask L1 error and / or mask L2 error are calculated; the mask L1 error and mask L2 error are used to calculate the electrical quantities marked as to be predicted by the prediction mask in each node.
[0033] The L1 and / or L2 errors of the mask are statistically analyzed separately according to the bus type to obtain the electrical quantity errors of the ballast node, PV node and PQ node respectively.
[0034] The computational accuracy of the graph neural network model is compared with that of the power flow solution method based on the physics model, and / or the computational speed of the graph neural network model is compared with that of the power flow solution method based on the physics model to obtain the model evaluation results.
[0035] Secondly, this application also provides a power system power flow calculation system based on graph neural networks, comprising:
[0036] The data generation module is used to simulate multiple operating conditions by randomly perturbing the topology and electrical parameters of the base network based on the IEEE standard example. For each operating condition, the Newton-Raphson method is used to solve the AC power flow, and convergent samples are selected from multiple operating conditions based on the solved AC power flow. Each convergent sample is exported as graph structure data. The graph structure data includes node features and edge features. The node features include at least the voltage magnitude, voltage phase angle, injected active power, and injected reactive power of each node, and the edge features include at least the resistance and reactance of each branch.
[0037] The model building module is used to build a graph neural network model based on graph structure data. The graph neural network model includes an edge aggregation message passing layer and a topology adaptive graph convolutional layer. The edge aggregation message passing layer is used to process the source node features, target node features and edge features of each edge using a multilayer perceptron, and then normalizes and aggregates them to the target node according to symmetry.
[0038] The mask embedding module is used to generate prediction masks according to the bus type, and then superimpose the encoded prediction masks onto the node input features of the graph neural network model; the bus types include balanced nodes, PV nodes and PQ nodes.
[0039] The model training module is used to train the graph neural network model using a composite loss function; the composite loss function includes at least a masked regression loss term, which is used to calculate the mean square error based on the electrical quantity to be predicted at each node;
[0040] The inference and evaluation module is used to perform inference using a trained graph neural network model and output the prediction results for each node. The prediction results include at least the voltage magnitude and voltage phase angle of each node. Based on the prediction results, the power flow calculation results for each node are determined.
[0041] Thirdly, this application also provides a computer device, including a memory and a processor, wherein the memory stores a computer program, and the processor executes the computer program to implement the steps of the method described in the first aspect above.
[0042] The aforementioned power system flow calculation method, system, and computer equipment based on graph neural networks use the IEEE standard example as the base network. Random perturbations are applied to the topology and electrical parameters of the base network to simulate multiple operating conditions. For each operating condition, the Newton-Raphson method is used to solve the AC power flow. Based on the solved AC power flow, convergent samples are selected from multiple operating conditions, and each convergent sample is exported as graph structure data. The graph structure data includes node features and edge features. Node features include at least the voltage magnitude, voltage phase angle, injected active power, and injected reactive power of each node. Edge features include at least the resistance and reactance of each branch. Based on the graph structure data, a graph neural network model is constructed. The graph neural network model includes an edge aggregation message passing layer and a topology adaptive graph convolution. The layer, the edge aggregation message passing layer, is used to process the source node features, target node features, and edge features of each edge using a multilayer perceptron, and then aggregates them to the target node after normalization according to symmetry. A prediction mask is generated according to the bus type, and the encoded prediction mask is superimposed on the node input features of the graph neural network model. Bus types include balanced nodes, PV nodes, and PQ nodes. A composite loss function is used to train the graph neural network model. The composite loss function includes at least a mask regression loss term, which is used to calculate the mean square error based on the electrical quantities to be predicted for each node. The trained graph neural network model is used for inference, and the prediction results for each node are output. The prediction results include at least the voltage amplitude and voltage phase angle of each node. Based on the prediction results, the power flow calculation results for each node are determined. Through the above method, by randomly perturbing the IEEE standard examples and combining Newton-Raphson convergence screening, graph structure training samples covering diverse operating conditions and containing physical truth values can be automatically and standardized in batches, without relying on manual preparation or historical data accumulation. A graph neural network model can obtain an approximate solution for the entire power flow with a single forward propagation, eliminating the need for iterative solutions for each operational scenario. This significantly improves computational efficiency when dealing with massive scenarios such as N-1 security scans and Monte Carlo analysis. The graph neural network model uses shared parameters at both the node and edge levels. The multilayer perceptron in the edge aggregation message passing layer is repeatedly used to process each branch, and the parameters of the topology adaptive graph convolutional layer are applied to all nodes, with model weights independent of the total number of nodes. When applied to power grids of different sizes, only new graph structure data needs to be input, and the model can automatically perform neighborhood aggregation and feature updates on the new topology without retraining. By generating differentiated prediction masks according to bus type and superimposing them on the node input features, a single model can adaptively handle different known-to-predict boundary conditions for balanced nodes, PV nodes, and PQ nodes, without requiring separate sub-network design for each bus type. A composite loss function including a mask regression loss term guides the model to fit only the electrical quantities to be predicted. Combined with the consistency between the graph neural network message passing mechanism and the physical processes of the power system, the output results satisfy basic physical laws such as node power balance, resulting in high reliability. Attached Figure Description
[0043] To more clearly illustrate the technical solutions in the embodiments of this application or related technologies, the drawings used in the description of the embodiments of this application or related technologies will be briefly introduced below. Obviously, the drawings described below are only some embodiments of this application. For those skilled in the art, other related drawings can be obtained based on these drawings without creative effort.
[0044] Figure 1 This is a flowchart illustrating a power system power flow calculation method based on a graph neural network in one embodiment.
[0045] Figure 2 This is a schematic diagram of a graph neural network model in one embodiment;
[0046] Figure 3 This is a block diagram of a power flow calculation system based on a graph neural network in one embodiment;
[0047] Figure 4 This is an internal structural diagram of a computer device in one embodiment. Detailed Implementation
[0048] To make the objectives, technical solutions, and advantages of this application clearer, the following detailed description is provided in conjunction with the accompanying drawings and embodiments. It should be understood that the specific embodiments described herein are merely illustrative and not intended to limit the scope of this application.
[0049] It should be noted that the terms "first," "second," etc., used in this application can be used to describe various elements, but these elements are not limited by these terms. These terms are only used to distinguish the first element from the second element. The terms "comprising" and "having," and any variations thereof, used in this application, are intended to cover non-exclusive inclusion. The term "multiple" used in this application refers to two or more. The term "and / or" used in this application refers to one of the embodiments, or any combination of multiple embodiments.
[0050] It is understood that, for ease of understanding of this invention, the following descriptions of key terms used in this application are provided:
[0051] Power Flow / Load Flow Calculation: Given the power grid topology and partial boundary conditions of each bus (node), this is a steady-state analysis of the power system that solves for the voltage magnitude, voltage phase angle of each bus, and power flow of each branch. It is a fundamental calculation for power grid planning, operation, and dispatch.
[0052] GNN (Graph Neural Network): A type of neural network that directly learns representations on graph-structured data. In this embodiment, buses are treated as nodes, and lines and transformers as edges, using a GNN to approximate the power flow solution.
[0053] MPN (Message Passing Network): A typical paradigm of graph neural networks, which updates node representations by repeatedly exchanging and aggregating information along edges between nodes.
[0054] IEEE benchmark cases: Standard power system test systems provided by IEEE (Institute of Electrical and Electronics Engineers), such as the IEEE 14-bus system and the IEEE 118-bus system, are used for general verification of power system algorithms.
[0055] NR (Newton-Raphson method): a traditional iterative nonlinear power flow equation solving algorithm, which is used in this application embodiment to calculate the true power flow value for the generated samples.
[0056] Bus type: In power flow calculation, there are three types of buses, including slack (0), generation (PV) node (1), and load (PQ) node (2). The known quantities and quantities to be calculated are different for different types of buses.
[0057] Edge aggregation: A message passing operation that uses a multilayer perceptron to process messages obtained by splicing source node features, target node features, and edge features (branch impedances), and then aggregates them to nodes after symmetry normalization, injecting branch electrical parameters into the node representation.
[0058] TAGConv (Topology Adaptive Graph Convolution): A graph convolution operator that can aggregate K-hop neighborhood information.
[0059] Mask Embedding: The flags (prediction masks) indicating which features are known and which features are to be predicted for each node are mapped into vectors by a multilayer perceptron and superimposed on the node input features, enabling the same model to adapt to boundary conditions of different bus types.
[0060] Power Imbalance Loss: Based on Kirchhoff's power balance equations, this is a physical constraint loss constructed by back-calculating the power residuals injected into each node from the model output. It is used to improve the physical consistency of the prediction results.
[0061] Cross-topology generalization: A model trained on one power grid topology (such as IEEE 14 nodes) can be used directly for power flow reasoning on a power grid of another size / topology (such as IEEE 118 nodes) without retraining.
[0062] Per unit (pu): A dimensionless electrical quantity normalized to a set reference value (reference capacity 100MVA and reference voltage 345kV in this application embodiment).
[0063] run_id: A unique identifier for each training run, used for full-process traceability (configuration snapshots, model weights, normalization parameters, and logs are named after it).
[0064] In one exemplary embodiment, such as Figure 1 As shown, a power flow calculation method for power systems based on graph neural networks is provided. The method is illustrated using a server as an example, including:
[0065] Step 102: Using the IEEE standard example as the base network, randomly perturb the topology and electrical parameters of the base network to simulate multiple operating conditions.
[0066] The base network is a benchmark power system model used to generate training samples, containing a complete topology, line parameters, and typical operating data. In this embodiment, the base network uses standard examples published by IEEE, such as the IEEE 14-bus system or the IEEE 118-bus system. Optionally, a uniform per-unit reference value is set to eliminate the influence of dimensions: the reference capacity is 100 MVA, and the reference voltage is 345 kV. The operating condition is a complete power grid state description formed by applying a set of perturbations to the base network, including topological connections, loads and generating power of each node, line impedance parameters, etc. Random perturbations are applied to the topology and electrical parameters of the base network to simulate diverse operating conditions. The topology is the set of connections between buses in the power grid; the electrical parameters include line resistance and reactance, generator terminal voltage, generating active power, load active power, and load reactive power.
[0067] In one alternative implementation, the IEEE standard examples used in the foregoing embodiments are merely illustrative and not intended to limit the scope of protection of this invention. In practical applications, the data base network can be replaced according to specific application scenarios and requirements. The data base network is a benchmark power system model used to generate training samples. It can adopt standard test systems published by IEEE (such as IEEE 3-node, 14-node, 57-node, 118-node, and 300-node systems), internationally public examples such as the European 6470rte system, or power grid model data in formats such as BPA or DSP from actual power grids. Regardless of the base network used, the technical solution of this invention can be achieved by constructing the graph structure data and performing subsequent steps as described in the foregoing embodiments.
[0068] In an exemplary embodiment, the topology and electrical parameters of the base network are randomly perturbed, including at least one of the following: randomly adding or deleting lines to change the topology; randomly scaling the line impedance parameters according to a preset ratio range; randomly selecting the generator terminal voltage within a preset voltage range; and randomly perturbing the generator active power, load active power, and load reactive power according to a preset probability distribution, wherein the preset probability distribution includes a normal distribution.
[0069] The specific implementation methods for adding random perturbations include at least one of the following four perturbation strategies:
[0070] Firstly, topology disturbance: randomly adding or removing one or more lines to change the grid's connectivity. The addition or removal operations must ensure that the grid remains connected after the disturbance, meaning there is at least one path between any two buses to avoid creating isolated grid islands. This disturbance simulates topology changes in a real power grid caused by maintenance, faults, or adjustments to operating modes.
[0071] Secondly, line impedance parameter disturbance: the resistance and reactance of each branch are randomly scaled according to a preset ratio range. For example, the preset ratio range is 0.8 to 1.2 times, with values taken in a uniform distribution. This disturbance simulates the uncertainty of line parameters caused by temperature, aging, or measurement errors.
[0072] Third, generator terminal voltage disturbance: The generator terminal voltage of each generator node is randomly selected within a preset voltage range. For example, the preset voltage range is 1.00 to 1.05 per unit value, and the values are selected in a uniform distribution. This disturbance simulates the change of generator operating point under different voltage control strategies.
[0073] Fourth, power generation and load disturbance: The active power of power generation, the active power of load, and the reactive power of load are randomly disturbed according to a preset probability distribution. For example, the preset probability distribution is a normal distribution, and the standard deviation is 10% of the corresponding rated value. This disturbance simulates the fluctuation of new energy output and the random changes of load.
[0074] The above-mentioned disturbance methods can be executed individually or in any combination, with each disturbance generating a candidate operating condition. Through multiple independent disturbances, a large number of candidate samples covering the normal operating boundary of the power grid and various extreme operating conditions can be generated in batches, providing a data foundation for subsequent power flow calculation and convergence screening.
[0075] In one optional implementation, the disturbance methods described in the foregoing embodiments are merely illustrative and do not constitute a limitation on the scope of protection of this invention. In other optional embodiments, the disturbance methods can be extended according to specific application scenarios. For example, in addition to normal distribution, disturbances to active power generation and load power can also employ uniform distribution, log-normal distribution, or other preset probability distributions; in addition to random addition or deletion of lines, disturbances to the topology can also employ N-1 or N-2 line disconnection methods, or be dynamically adjusted according to changes in the renewable energy output scenario. All of the above alternative solutions fall within the scope of protection covered by this invention.
[0076] Step 104: Solve the AC power flow using the Newton-Raphson method for each operating condition, and select convergent samples from multiple operating conditions based on the solved AC power flow. Export each convergent sample as graph structure data. The graph structure data includes node features and edge features. The node features include at least the voltage magnitude, voltage phase angle, injected active power, and injected reactive power of each node. The edge features include at least the resistance and reactance of each branch.
[0077] For each candidate operating condition generated by random perturbation, the Newton-Raphson method is used to solve its AC power flow. The basic principle of the Newton-Raphson method is to perform a Taylor expansion of the power flow equations near the initial value and retain the first-order terms, and update the state variables by repeatedly solving the correction equations until the convergence criterion is met.
[0078] For example, the power flow solution process for each operating condition is as follows: Based on the line connection relationships and impedance parameters under that condition, construct the node admittance matrix. Set initial values for the voltage magnitude and phase angle of each node (e.g., voltage magnitude of 1.0 per unit and phase angle of 0). Enter the iterative loop: calculate the power imbalance of each node (the difference between the given injected power and the injected power calculated from the current voltage); if the maximum value of the power imbalance is less than the preset convergence accuracy (e.g., 1e-6 per unit), then the operating condition is determined to be converged, and the iteration exits; otherwise, construct the Jacobian matrix, solve for the voltage correction, update the voltage magnitude and phase angle of each node, and enter the next iteration. If the iteration count exceeds the preset upper limit and convergence is still not achieved, then the operating condition is determined to be non-convergent.
[0079] After solving the power flow for all candidate operating conditions, all converged conditions are selected as convergence samples, and non-convergent conditions are discarded. The convergence samples are the operating conditions that achieve convergence accuracy within a preset number of iterations using the Newton-Raphson method, and their corresponding power flow solutions are physically feasible steady-state operating points.
[0080] Each converged sample is exported as graph-structured data. The graph-structured data is constructed as follows: buses in the power grid are nodes, and lines and transformers are edges. Node features include at least the voltage magnitude, voltage phase angle, injected active power, and injected reactive power for each node; edge features include at least the resistance and reactance of each branch. The exported format is a convenient .npy file, with each sample stored independently.
[0081] The above convergence filtering mechanism ensures that every sample in the training dataset is a physically feasible, high-quality power flow solution, providing a reliable supervision signal for the graph neural network to learn physically consistent mapping relationships.
[0082] In one alternative implementation, the solver used to determine the true power flow value is not limited to the Newton-Raphson method. In other alternative implementations, the power flow truth solver can choose the fast decoupling method, the DC power flow method, or directly call commercial power flow calculation software (such as PSASP, BPA, MATPOWER, etc.) to complete the power flow calculation, as long as the solver can output complete power flow results such as the voltage magnitude, voltage phase angle, and branch power of each node for subsequent convergence screening and sample export.
[0083] In one optional implementation, after exporting the graph structure data of all converged samples, the datasets of each sample are encapsulated and preprocessed. Exemplarily, this includes the following steps: The graph structure data of all converged samples are uniformly encapsulated into a graph dataset, with each sample containing a set of node feature matrices and edge feature matrices. Then, the graph dataset is divided into a training set, a validation set, and a test set according to a preset ratio. Exemplarily, the ratio can be 0.5:0.2:0.3, where the training set is used for learning model parameters, the validation set is used for hyperparameter tuning and early stopping during training, and the test set is used to finally evaluate the model's generalization performance. Z-score standardization is performed on the node and edge features. Z-score standardization means subtracting the mean from the value of each feature dimension and dividing by the standard deviation, so that the transformed data has zero mean and unit variance. The mean and standard deviation used for standardization are calculated from the training set data and stored as normalization parameters. The validation and test sets directly reuse the normalization parameters of the training set during standardization to ensure consistency in data transformation. Optionally, the Z-score normalization used in the foregoing embodiments is merely illustrative and does not constitute a limitation on the scope of protection of this invention. In practical applications, the normalization method can be replaced according to the characteristics of the data distribution. For example, min-max normalization can be used to linearly scale the values of each feature dimension to the [0,1] interval; robust normalization can also be used, scaling based on the median and interquartile range to reduce the impact of outliers on the normalization parameters. All of the above alternatives fall within the scope of protection covered by this invention.
[0084] Step 106: Based on the graph structure data, construct a graph neural network model. The graph neural network model includes an edge aggregation message passing layer and a topology adaptive graph convolutional layer. The edge aggregation message passing layer is used to process the source node features, target node features and edge features of each edge using a multilayer perceptron, and then normalizes and aggregates them to the target node according to the degree of symmetry.
[0085] The edge aggregation message passing layer is the core network component in this embodiment for injecting branch information into the bus. Its function is to fuse the electrical parameters of the edges (branches) into the representation of the nodes (buses). For each directed edge, this layer uses a multilayer perceptron (i.e., a neural network composed of multiple fully connected layers and nonlinear activation functions) to process the joint vector formed by concatenating the source node features, target node features, and edge features, generating the message vector corresponding to that edge. Subsequently, all edge messages pointing to the same target node are normalized according to their symmetry and then summed and aggregated to obtain the updated node representation. Symmetry normalization refers to dividing the aggregation result by the square root of the product of the source node degree and the target node degree. The purpose is to eliminate the influence of differences in node degree on the aggregation numerical scale, so that the model can treat nodes with different connection densities fairly, which helps to stabilize training.
[0086] The topology-adaptive graph convolutional layer is a graph convolution operator capable of multi-hop neighborhood information aggregation. This layer uses a K-hop adjacency matrix, allowing each node to receive information from all its neighbors within a K-hop range in a single convolution operation, thereby capturing long-distance electrical couplings in power systems. The hop distance K is a configurable hyperparameter, for example, K=3, which can be adjusted according to the power grid size.
[0087] Optionally, the model alternately stacks multiple layers of edge aggregation message passing layers and topology adaptive graph convolutional layers to gradually fuse local branch information and long-distance topology information in the node representation, ultimately outputting the predicted voltage magnitude and phase angle of each node. This structural design enables the model to simultaneously utilize branch impedance details and the overall network topology for power flow inference.
[0088] In one alternative implementation, the graph neural network backbone is the core network module responsible for information propagation and feature updating between nodes, and its specific implementation can be flexibly chosen. For example, the topology-adaptive graph convolutional layer used in the aforementioned implementation can be replaced with other graph convolution operators, including but not limited to Graph Convolutional Networks (GCN), Chebyshev Graph Convolution (ChebConv), Graph Attention Networks (GAT), GraphSAGE, and Graph Isomorphic Networks (GINE). All of these graph operators can realize the propagation and aggregation of information between nodes, but the methods of information aggregation and attention calculation mechanisms are different.
[0089] Furthermore, the edge aggregation message passing layer is not limited to the multilayer perceptron processing method described in the aforementioned embodiments. In other optional embodiments, edge aggregation can employ other edge-aware aggregation strategies, such as edge aggregation based on attention mechanisms or edge aggregation based on gating mechanisms. The number of model layers, the dimension of hidden layers, and the number of hops K of the topology adaptive graph convolution are all configurable hyperparameters that can be flexibly adjusted according to the power grid scale and computing resources.
[0090] Furthermore, the backbone of the graph neural network can also adopt various variant structures, including but not limited to graph neural networks with residual connections, multi-step hybrid message passing networks, and multi-level parallel graph convolutional networks. All of the above alternatives fall within the scope of protection of this invention.
[0091] In one alternative implementation, refer to Figure 2The graph neural network model comprises an input layer, a feature encoding layer, an edge information aggregation layer, a topology propagation layer, and a node output layer. The input to the input layer includes: 1. A node state matrix X, with dimensions N×4, where N is the total number of nodes in the power grid. The four feature dimensions correspond to the voltage amplitude Vm, voltage phase angle Va, injected active power P, and injected reactive power Q of each node, respectively. 2. A prediction mask matrix M, also with dimensions N×4. Each element takes a value of 0 or 1, used to identify whether the electrical quantity at the corresponding location is a known quantity (marked as 0) or an electrical quantity to be predicted (marked as 1). 3. Topology and edge attributes, represented by a sparse edge index matrix edge_index with dimensions |E|×2, where |E| is the total number of branches, and each row stores the node numbers at both ends of a branch. After the graph structure data is input into the model, the node features and masks are initialized through their respective encoding layers.
[0092] The feature encoding layer consists of a node encoder and a mask encoder. The node feature matrix X is first input to the node encoder. The node encoder is a linear layer that maps the 4-dimensional input features of each node to a 128-dimensional hidden space, obtaining the initial node embedding with a dimension of N×128. Simultaneously, the prediction mask matrix M is input to the mask encoder (Mask MLP), which is a multilayer perceptron. It also maps the 4-dimensional binary mask of each node to a 128-dimensional continuous vector, obtaining the mask embedding vector with a dimension of N×128. Subsequently, the outputs of the node encoder and the mask encoder are element-wise added together, and the fused result serves as the initial node representation of the graph neural network backbone. The dimension is N×128. Through the above method, the model simultaneously obtains the electrical quantity information of the nodes and the boundary condition information of the bus type at the input end.
[0093] In the edge information aggregation layer, the initial node representation The input edge aggregation message passing layer is responsible for injecting branch impedance information into the node representation. For each directed edge... (From node j to node i), the edge aggregation layer first obtains the features of the source node. Target node features and the characteristics of that edge (Including resistance r and reactance x), then the three are concatenated and input into a shared multilayer perceptron. Generate edge messages The calculation process can be represented as follows: .
[0094] After obtaining the edge messages of all edges, for each target node i, the edge messages of all its incoming edges are normalized according to symmetry and then summed and aggregated to obtain the edge aggregation result of that node. , can be represented as ,in This is the symmetry normalization coefficient. Through this aggregation operation, the impedance information of the branch is injected into the representation of the target node it connects to, so that the updated node representation incorporates the electrical characteristics of the local branch.
[0095] The topology propagation layer includes a topology-adaptive graph convolutional layer (TAGConv), with the output of the edge aggregation layer serving as the input to the topology-adaptive graph convolutional layer. The model stacks four TAGConv layers, with each layer maintaining a hidden dimension of 128. TAGConv is a graph convolution operator capable of multi-hop neighborhood information aggregation. Its core feature is that each convolutional operation simultaneously aggregates the information of the node itself and all nodes within its 1-hop to K-hop neighborhood, where K is a configurable hyperparameter (K=3 in this example). Through this design, each TAGConv layer can capture topological dependencies within a K-hop range without needing to progressively expand the receptive field through layer stacking as in ordinary graph convolutional networks.
[0096] In each layer of TAGConv, the model automatically calculates the powers of the normalized adjacency matrix based on the adjacency matrix A of the current input graph (constructed from edge_index), multiplies the aggregation results of each order of neighborhood by a learnable weight matrix, sums them, and then applies a non-linear activation function (ReLU in this example) and Dropout regularization with a dropout rate of 0.2 to output the updated node representation. Since the convolution parameters of TAGConv are shared among all nodes and do not depend on the total number of nodes N, the same set of parameters is used for convolution operations regardless of whether the power grid contains 14 or 118 nodes.
[0097] After four layers of TAGConv propagation and aggregation, the final node hidden representation of the node output layer has a dimension of N×128. The output layer is a linear layer that maps the 128-dimensional hidden representation of each node to a 4-dimensional output space, corresponding to the predicted values of the node voltage amplitude Vm, voltage phase angle Va, injected active power P, and injected reactive power Q, respectively. The weight matrix of the output layer has a dimension of 128×4, which is independent of the total number of nodes. Therefore, the same set of output layer parameters can be applied to power grids of any size.
[0098] The inference process based on the graph neural network model includes: inputting arbitrary power grid graph structure data containing N nodes (N×4 node features and |E|×2 edge indices), initializing and fusing it through node encoders and mask encoders to obtain an initial node representation of N×128; the edge aggregation layer processes each branch through a shared MLP, injecting branch impedance information into the node representation; the 4-layer TAGConv uses multi-hop neighborhood aggregation with shared parameters to fuse long-distance topology information into the node representation; the output layer maps each node back to a 4-dimensional electrical quantity prediction. Throughout the process, all learnable parameters of the model are independent of N and |E|, and are only related to the feature dimensions (4, 2) and the hidden dimension (128).
[0099] Step 108: Generate a prediction mask according to the bus type, and superimpose the prediction mask onto the node input features of the graph neural network model after encoding; the bus types include balanced nodes, PV nodes and PQ nodes.
[0100] Among them, the bus type refers to the three types of buses in power system power flow calculation: Slack node, whose voltage amplitude and phase angle are known, and the quantities to be determined are injected active power and injected reactive power; PV node (generator node), whose active power and voltage amplitude are known, and the quantities to be determined are injected reactive power and voltage phase angle; PQ node (load node), whose active power and reactive power are known, and the quantities to be determined are voltage amplitude and voltage phase angle.
[0101] The prediction mask is a vector with the same dimension as the node's features, where each element has a value of 0 or 1. It is used to identify whether each electrical quantity is the target quantity that the node needs to predict. The rule for the mask bits is: the mask bits corresponding to known electrical quantities are marked as 0, and the mask bits corresponding to electrical quantities to be predicted are marked as 1.
[0102] For example, the specific generation method is as follows: For each node, the set of electrical quantities to be predicted is determined according to its bus type. The electrical quantities to be predicted for a ballast node are injected active power and injected reactive power; for a PV node, the electrical quantities to be predicted are voltage phase angle and injected reactive power; for a PQ node, the electrical quantities to be predicted are voltage amplitude and voltage phase angle. Based on this rule, a binary mask vector with a length equal to the feature dimension is generated for each node.
[0103] After obtaining the prediction mask, it is input into an encoder consisting of fully connected layers, which maps it into a continuous vector with the same dimension as the node input features. Then, it is superimposed on the node input features of the graph neural network model in an element-wise addition manner.
[0104] Through the mask embedding mechanism described above, the model can know at the input end which electrical quantities of each node are given boundary conditions and which are target quantities that need to be predicted. Thus, it can adaptively handle different bus types within the same model framework without designing a separate sub-network or training multiple models for each bus type.
[0105] In one alternative implementation, the boundary condition injection method involves passing the bus type and its corresponding known-to-predict boundary information to the graph neural network model. Besides the aforementioned mask embedding method, any of the following alternatives can be used: 1. One-hot concatenation of bus types: The bus type is encoded as a one-hot vector (e.g., balanced nodes are encoded as [1,0,0], PV nodes as [0,1,0], and PQ nodes as [0,0,1]), and this one-hot vector is concatenated with the original node feature vectors as input to the graph neural network model. 2. Independent input channel method: The bus type information is treated as an independent feature channel and input into the model in parallel with the node electrical quantity features. At the first layer of the model, the type information is projected into the same space as the electrical quantity features through an independent linear transformation before fusion. 3. Type-specific sub-network method: An independent sub-network branch is designed for each bus type. Each sub-network processes the features of the corresponding type nodes, and information fusion is performed at higher levels of the network. All of the above alternative solutions can effectively transfer bus type boundary condition information to the model, enabling the model to distinguish between known and predicted electrical quantities at different nodes, and all fall within the scope of protection covered by this invention.
[0106] Step 110: Train the graph neural network model using a composite loss function; the composite loss function includes at least a masked regression loss term, which is used to calculate the mean square error based on the electrical quantity to be predicted at each node.
[0107] The composite loss function is a weighted combination of multiple loss terms with different optimization objectives, used to simultaneously optimize the model's performance across multiple dimensions. The mask regression loss term calculates the mean squared error for the electrical quantities marked as to be predicted by the prediction mask at each node. Its purpose is to guide the model to accurately fit the target quantity to be predicted, while avoiding interference from fitting known input quantities to the model's learning.
[0108] For example, the mask regression loss term is calculated as follows: For each node, the location of the electrical quantity to be predicted is determined according to the prediction mask corresponding to its bus type; the squared difference between each predicted electrical quantity output by the model and its corresponding true value is calculated item by item; the squared differences of only the locations marked as 1 (to be predicted) are summed and averaged to obtain the mask regression loss of that node; the losses of all nodes are averaged to obtain the mask regression loss value of the current batch. Optionally, the mask regression loss term can be calculated using the following formula:
[0109] ;
[0110] In the formula, This represents the total number of elements in the set of electrical quantities to be predicted. The graph neural network model predicts the electrical quantities of the nodes. The actual value obtained from the calculation of the current.
[0111] Optionally, the composite loss function may also include a known quantity retention loss term and a power imbalance loss term. The known quantity retention loss term is used to constrain the known electrical quantities output by the model to be consistent with the input values, achieved by applying mean square error regularization to the mask bits marked as 0 (known). The power imbalance loss term is used to substitute the voltage magnitude and phase angle predicted by the model into the AC power flow equations to calculate the injected power residuals at each node, thereby improving the physical consistency of the prediction results. The weighting coefficients of each loss term can be adjusted based on the prediction error on the validation set to achieve a balance between accuracy and physical plausibility.
[0112] For example, the graph neural network model is trained based on the training set determined in the aforementioned steps.
[0113] For example, the AdamW optimizer is used in the training strategy, with an initial learning rate of 1×10⁻⁶. -3 The OneCycleLR learning rate scheduling strategy was used, with a batch size of 128 and 100 training epochs. A fixed random seed was used to ensure reproducibility of the experiments. During training, the optimal model weights were saved based on the loss values on the validation set, and run_id, configuration snapshots, and epoch-by-epoch loss curves were recorded throughout the process.
[0114] In an alternative implementation, the AdamW optimizer and OneCycleLR learning rate scheduling strategy used in the foregoing embodiments are merely illustrative and do not constitute a limitation on the scope of protection of this invention. In practical applications, the optimizer and learning rate scheduler can be replaced according to the model size and the amount of training data. For example, the optimizer can be Adam, stochastic gradient descent (SGD), or variants thereof; the learning rate scheduling strategy can be cosine annealing scheduling, step descent scheduling, or linear decay scheduling, etc. All of the above alternatives fall within the scope of protection covered by this invention.
[0115] Step 112: Use the trained graph neural network model to perform inference and output the prediction results of each node; the prediction results include at least the voltage amplitude and voltage phase angle of each node.
[0116] Inference refers to the process of applying the trained graph neural network model to new input data and obtaining the output result through a forward propagation. During this process, the model parameters remain fixed and no gradient updates or backpropagation are performed.
[0117] For example, the specific implementation of inference is as follows: The power grid to be analyzed is constructed as graph-structured data in the same way as in the training phase, including node features (at least including known quantities such as injected active power and injected reactive power of each node) and edge features (resistance and reactance of each branch), and corresponding prediction masks are generated. The graph-structured data and its corresponding masks are input into the trained graph neural network model. The model performs one forward propagation: after the node input features are superimposed with the mask and embedded, they pass sequentially through the edge aggregation message passing layer (injecting branch impedance information into the node representation) and the topology adaptive graph convolutional layer (performing K-hop neighborhood information aggregation), and finally the output layer generates the prediction result for each node.
[0118] The prediction results include at least the voltage magnitude and phase angle of each node. For slack nodes, the injected active and reactive power can also be obtained from the model output; for PV and PQ nodes, the quantities to be predicted have been defined in the aforementioned masking mechanism. Since the forward propagation of the graph neural network only involves matrix multiplication and nonlinear activation function operations, no iterative solution is required, and the entire inference process can be completed in milliseconds. The output prediction results can be directly used for subsequent power grid security analysis, dispatch decisions, or as initial values for more refined power flow calculations.
[0119] Optionally, the output and deployment format of the inference results provided in this embodiment can be flexibly selected according to the actual application scenario. The output and deployment format refers to the way the inference results of the trained graph neural network model are provided to the end user or downstream system. Specifically, any one or more combinations of the following methods can be used: 1. Command line method: The user executes the inference command through the terminal command line, and the result is output in text or file format. This is suitable for offline analysis, batch processing scenarios, and algorithm debugging stages. 2. Web platform method: An interactive interface is provided through a front-end and back-end separated web application. After the user uploads data or configures parameters, the system calls the model to perform inference and visualizes the results in charts or tables. This is suitable for daily monitoring and decision analysis scenarios for dispatchers. 3. REST / WebSocket interface method: The inference service is encapsulated into a standardized application programming interface, which can be called by other software systems (such as energy management systems, dispatch automation systems, etc.) through network requests. This is suitable for inter-system integration and automated business process scenarios. 4. Batch processing method: Multiple power grid data to be inferred are input into the model in batches, all calculations are completed at once, and the summary results are output. This is suitable for large-scale offline calculations and N-1 batch safety analysis scenarios. All the above alternative solutions fall within the scope of protection covered by this invention.
[0120] Step 114: Based on the prediction results, determine the power flow calculation results for each node.
[0121] Among them, the power flow calculation results are a complete dataset of voltage amplitude, voltage phase angle, injected active power, injected reactive power and power distribution of each branch of the entire network under steady-state operation conditions. It is the basic data for power system analysis.
[0122] Since the graph neural network model outputs normalized values, while actual power system analysis requires electrical quantities in physical units, the prediction results of each node output by the model are denormalized. The specific method of denormalization is as follows: read the mean and standard deviation of each electrical quantity saved during the training phase, multiply the normalized value output by the standard deviation, add the mean, and restore it to the per-unit value or the electrical quantity in actual physical units.
[0123] After inverse normalization, the prediction results are assembled into a complete node power flow profile based on the bus type of each node. Specifically, for slack nodes, the voltage amplitude and voltage phase angle are model predicted values, as are the injected active power and injected reactive power; for PV nodes, the voltage amplitude and active power are given values, while the voltage phase angle and injected reactive power are model predicted values; for PQ nodes, the active power and reactive power are given values, while the voltage amplitude and voltage phase angle are model predicted values.
[0124] After assembly, complete power flow calculation results for all nodes in the entire power grid are obtained, including the voltage magnitude (per unit or kV), voltage phase angle (rad or degree), injected active power (MW), and injected reactive power (MVar) for each node. These results can be directly used for subsequent power system applications such as power grid security analysis, voltage limit detection, and economic dispatch.
[0125] In the aforementioned power system power flow calculation method based on graph neural networks, the IEEE standard example is used as the base network. Random perturbations are applied to the topology and electrical parameters of the base network to simulate multiple operating conditions. For each operating condition, the Newton-Raphson method is used to solve the AC power flow. Based on the solved AC power flow, convergent samples are selected from multiple operating conditions, and each convergent sample is exported as graph structure data. The graph structure data includes node features and edge features. Node features include at least the voltage magnitude, voltage phase angle, injected active power, and injected reactive power of each node. Edge features include at least the resistance and reactance of each branch. Based on the graph structure data, a graph neural network model is constructed. The graph neural network model includes an edge aggregation message passing layer and a topology adaptive graph convolutional layer. The message passing layer is used to process the source node features, target node features, and edge features of each edge using a multilayer perceptron, and then normalizes and aggregates them to the target node according to symmetry. A prediction mask is generated according to the bus type, and the encoded prediction mask is superimposed on the node input features of the graph neural network model. Bus types include balanced nodes, PV nodes, and PQ nodes. A composite loss function is used to train the graph neural network model. The composite loss function includes at least a mask regression loss term, which is used to calculate the mean square error based on the electrical quantities to be predicted for each node. The trained graph neural network model is used for inference, and the prediction results for each node are output. The prediction results include at least the voltage magnitude and voltage phase angle of each node. Based on the prediction results, the power flow calculation results for each node are determined. Through the above method, by randomly perturbing the IEEE standard examples and combining Newton-Raphson convergence screening, graph structure training samples covering diverse operating conditions and containing physical truth values can be automatically and standardized in batches, without relying on manual preparation or historical data accumulation. A graph neural network model can obtain an approximate solution for the entire power flow with a single forward propagation, eliminating the need for iterative solutions for each operational scenario. This significantly improves computational efficiency when dealing with massive scenarios such as N-1 security scans and Monte Carlo analysis. The graph neural network model uses shared parameters at both the node and edge levels. The multilayer perceptron in the edge aggregation message passing layer is repeatedly used to process each branch, and the parameters of the topology adaptive graph convolutional layer are applied to all nodes, with model weights independent of the total number of nodes. When applied to power grids of different sizes, only new graph structure data needs to be input, and the model can automatically perform neighborhood aggregation and feature updates on the new topology without retraining. By generating differentiated prediction masks according to bus type and superimposing them on the node input features, a single model can adaptively handle different known-to-predict boundary conditions for balanced nodes, PV nodes, and PQ nodes, without requiring separate sub-network design for each bus type. A composite loss function including a mask regression loss term guides the model to fit only the electrical quantities to be predicted. Combined with the consistency between the graph neural network message passing mechanism and the physical processes of the power system, the output results satisfy basic physical laws such as node power balance, resulting in high reliability.
[0126] In an exemplary embodiment, the method further includes: applying the graph neural network model trained on the first instance to a second instance with a different number of nodes and a different topology than the first instance for inference, and reusing the normalized parameters from the training phase.
[0127] In this application, the embodiments support cross-topology generalization evaluation. Cross-topology generalization refers to directly applying a graph neural network model trained on one power grid topology (first example) to another power grid (second example) with a different number of nodes and a different topology for inference, and the model parameters remain fixed during the inference process without the need for retraining or fine-tuning. The first example is the power grid used during model training, such as the IEEE 14-node system; the second example is the target power grid used during model inference, such as the IEEE 118-node system.
[0128] For example, the weight parameters of the trained graph neural network model are fixed and not updated. Following the same method as the training phase, the power grid of the second example is constructed as graph-structured data, including extracting node and edge features. During feature normalization, the normalization parameters (i.e., the mean and standard deviation of each feature dimension) saved during the training phase are directly reused, rather than recalculating the normalization parameters based on the data of the second example, to ensure that the numerical distribution of the input data is consistent with that of the training phase. The constructed graph-structured data is input into the model, and a forward propagation is performed to obtain the prediction results for each node of the second example. Since the weight parameters of the graph neural network model are independent of the total number of nodes, and the model learns the general rules of electrical quantity propagation between nodes through branches rather than a fixed mapping of a specific power grid, the model can directly handle graph-structured inputs of different scales.
[0129] This embodiment avoids the repetitive work of collecting training samples and retraining the model for each new power grid or each new topology, significantly reducing modeling costs and deployment time. Especially in application scenarios where power grid topology changes frequently (such as new energy grid connection and line maintenance), training once can be applied to power grids of various sizes and topologies, significantly improving the practicality of the method and the efficiency of engineering deployment.
[0130] In an exemplary embodiment, step 108 includes: configuring the electrical quantities to be predicted for the balancing node to include injected active power and injected reactive power, configuring the electrical quantities to be predicted for the PV node to include voltage phase angle and injected reactive power, and configuring the electrical quantities to be predicted for the PQ node to include voltage amplitude and voltage phase angle; marking the mask bits corresponding to the known electrical quantities as 0 and marking the mask bits corresponding to the electrical quantities to be predicted as 1; and after mapping the prediction mask into a continuous vector through a fully connected layer, fusing it with the node input features in an additive manner.
[0131] The prediction mask is a binary vector with the same dimension as the node feature dimension. It is used to identify whether each electrical quantity is a known quantity or a quantity to be predicted. A mask bit of 0 indicates that the electrical quantity is known, and a mask bit of 1 indicates that the electrical quantity is to be predicted.
[0132] For example, the specific configuration rules are as follows: For a balun node, its voltage amplitude and voltage phase angle are known quantities, and the injected active power and injected reactive power are electrical quantities to be predicted. Therefore, the positions corresponding to active and reactive power in the mask are marked as 1, and the positions corresponding to voltage amplitude and phase angle are marked as 0. For a PV node, its active power and voltage amplitude are known quantities, and the voltage phase angle and injected reactive power are electrical quantities to be predicted. Therefore, the positions corresponding to phase angle and reactive power in the mask are marked as 1, and the positions corresponding to active power and voltage amplitude are marked as 0. For a PQ node, its active power and reactive power are known quantities, and the voltage amplitude and voltage phase angle are electrical quantities to be predicted. Therefore, the positions corresponding to voltage amplitude and phase angle in the mask are marked as 1, and the positions corresponding to active power and reactive power are marked as 0.
[0133] After obtaining the prediction mask, it is input into an encoder consisting of fully connected layers, which maps the mask into a continuous vector with the same dimension as the node input features. This vector is then added to the node input features element-wise. The fused features serve as the input to the graph neural network model.
[0134] In this embodiment, the boundary condition information of the bus type is directly encoded and injected into the model input through a masking mechanism, enabling a single graph neural network to adaptively process known-to-predict combinations of three different bus types without designing an independent network structure or training strategy for each bus type. At the same time, the mask is mapped to a continuous vector through a learnable fully connected layer, enabling it to participate in end-to-end backpropagation optimization and improving the model's ability to fit data of different bus types.
[0135] In one exemplary embodiment, the composite loss function further includes a known quantity retention loss term, which is used to apply a regularization constraint to the mean square error between the predicted values of electrical quantities that are known by the prediction mask at each node and the input values.
[0136] Among them, the known quantity retention loss term is a regularization term used to constrain the deviation between the known electrical quantities output by the model and the input values. Its function is to ensure that the model does not violate or change the given boundary conditions when learning to predict unknown quantities.
[0137] For example, during training, for each node, the location of known electrical quantities (i.e., the dimensions marked as 0 in the mask) is determined based on its prediction mask. For these known electrical quantities, the mean squared error between the model's output and input values is calculated as the known quantity preservation loss for that node. Optionally, this loss term is equal to the average of the sum of the squares of the differences between the predicted and input values of all known electrical quantities, which measures the accuracy with which the model "reproduces" the known quantities at the output. The calculation formula is as follows:
[0138] ;
[0139] In the formula, This represents the total number of elements in the set of known electrical quantities. The graph neural network model predicts the electrical quantities of the nodes. The actual value obtained from the calculation of the current.
[0140] The known quantity retention loss term is added as a regularization term to the total loss function. Its weight coefficient is usually set to a small value to ensure that the main optimization direction of the model is still to reduce the regression error of the quantity to be predicted, while constraining the known quantity output by the model to not deviate from the input value. This loss term complements the masked regression loss term: the masked regression loss term constrains the model to accurately fit the electrical quantity to be predicted, while the known quantity retention loss term constrains the model to keep the output value of the known electrical quantity consistent with the input value. Together, they guide the model to generate a complete and self-consistent full-node electrical quantity profile at the output.
[0141] In this embodiment, by explicitly constraining the output value of the known quantity to be consistent with the input value in the loss function, the model can clearly distinguish the role boundary between the known quantity and the quantity to be predicted during the training process, avoiding unintentional deviation from the known input value when fitting the electrical quantity to be predicted, thereby improving the physical consistency and numerical reliability of the prediction results.
[0142] In an exemplary embodiment, the composite loss function further includes a power imbalance loss term, which is used to calculate the active and reactive power of each node using the AC power flow equation based on the voltage amplitude and voltage phase angle predicted by the model, and to calculate the mean square error between the node power output by the model or the assembled power and the power calculated by the AC power flow equation. The total loss of the composite loss function is a weighted sum of the mask regression loss term, the known quantity preservation loss term, and the power imbalance loss term, wherein the weight of the power imbalance loss term is gradually increased during training using a weight scheduling strategy.
[0143] The power imbalance loss term is a physical constraint loss constructed based on Kirchhoff's power balance equations. It means that by substituting the model-predicted voltage magnitude and phase angle into the AC power flow equations, the active and reactive power (referred to as rebuilt power) of each node is calculated. Then, the mean square error between this rebuilt power and the node power output or assembly by the model is calculated. The smaller this error, the more the model predictions satisfy the power balance equations, and the higher the physical consistency.
[0144] Optionally, for each node, based on its bus type, the corresponding voltage amplitude and voltage phase angle are extracted or assembled from the predicted results output by the model; these values are substituted into the AC power flow equation to calculate the injected active and reactive power of the node; the mean square error between these powers and the node power output or assembled by the model is calculated to obtain the power imbalance loss of the node. The calculation formula is as follows:
[0145] ;
[0146] In the formula, N is the total number of system nodes. The injected active power prediction value for node i in the model output or assembly. The predicted injected reactive power value for node i in the model output or assembly. The active power value is obtained by back-calculating the AC power flow equations based on the voltage magnitude and phase angle of node i predicted by the model. The reactive power value is obtained by back-calculating the AC power flow equation based on the voltage amplitude and voltage phase angle of node i predicted by the model.
[0147] The total loss of the composite loss function is a weighted sum of the masked regression loss term, the known quantity preservation loss term, and the power imbalance loss term. The weight of the power imbalance loss term is gradually increased during training using a weight scheduling strategy. This weight scheduling strategy is a mechanism that dynamically adjusts the weights of the loss terms according to preset rules during training, for example, starting from an initial value of 0 and gradually increasing the weights to the target value in a linear or exponential manner as the training epochs increase. The total loss of the composite loss function is calculated as follows:
[0148] ;
[0149] In the formula, Maintain the weight of the loss for the known quantity. This is the weight for the power imbalance loss. For example, when using only the default masked L2 loss, we can let... When it is necessary to enhance the physical consistency of the prediction results, it can be made Each weight can be determined based on the prediction error on the validation set.
[0150] In one optional implementation, the composite loss function used in the aforementioned embodiments is merely illustrative and does not constitute a limitation on the scope of protection of this invention. In practical applications, the loss function can be extended and adjusted according to specific task objectives and application scenarios, and multi-objective optimization of model training can be achieved by introducing more constraint terms. In addition to the aforementioned mask regression loss term, known quantity preservation loss term, and power imbalance loss term, the loss function can also be extended to include one or more of the following loss terms: mask L1 loss (replacing the L2 distance in the mask regression loss term with the L1 distance, which is insensitive to outliers and helps improve the robustness of the model in the presence of data noise), branch power flow error loss (calculating the power flow of each branch based on the voltage amplitude and phase angle predicted by the model, comparing it with the branch power flow in the true power flow value, and calculating the mean square error to improve the model's prediction accuracy of branch power distribution), and voltage limit violation penalty loss (imposing a penalty on the case where the predicted voltage amplitude exceeds the upper and lower limits of safe operation, guiding the model to output prediction results that meet voltage safety constraints). The above loss terms can be configured with different weight coefficients according to actual needs and added to the total loss function in the form of a weighted sum. For example, in application scenarios with low tolerance for voltage over-limit, the weight of voltage over-limit penalty loss can be increased; in scenarios with high requirements for branch power accuracy, the weight of branch power flow error loss can be increased.
[0151] In this embodiment, the physical equations are embedded as soft constraints into the training process through a power imbalance loss term. This guides the model to satisfy the physical laws of power balance while fitting the data distribution, avoiding purely data-driven model outputs infeasible solutions that violate physical laws. The weight scheduling strategy prioritizes data fitting in the early stages of training to ensure model convergence and stability, while gradually strengthening physical constraints in the later stages to improve the physical rationality of the prediction results. This phased optimization balances training stability and output reliability.
[0152] In an exemplary embodiment, after step 114, the method further includes: registering multiple graph neural network architectures through a model registry center; the model registry center is configured with architecture identifiers corresponding to different graph neural network architectures; when it is necessary to switch model architectures, by modifying the architecture identifier in the configuration file or specifying the target architecture identifier through command line parameters, the model registry center automatically calls the corresponding graph neural network architecture to build the model according to the target architecture identifier, thereby realizing the switching of multiple graph neural network architectures.
[0153] In this application embodiment, a model registry center is also provided to enable flexible switching between multiple graph neural network architectures. The model registry center is a software module for managing and scheduling multiple graph neural network architectures. Its core function is to register different graph neural network architectures with identifiable identifiers and support automatically calling the corresponding architecture to complete model construction based on external instructions.
[0154] For example, during the system initialization phase, different graph neural network architectures are registered through a model registry, with each architecture configured with a unique architecture identifier. Registerable architectures include at least basic message passing networks, message passing network variants with residual connections, multi-step hybrid message passing networks, multi-step message passing networks with masked embeddings, and multilayer perceptrons or graph convolutional networks as benchmarks. After registration, the model registry maintains a mapping table between architecture identifiers and corresponding model classes.
[0155] When a user needs to switch the currently used model architecture, no code modification is required. They can simply modify the architecture identifier parameter in the configuration file or specify the target architecture identifier directly via command-line arguments when executing the command. Upon receiving this identifier, the model registry finds and instantiates the corresponding graph neural network architecture from the mapping table, automatically completing the model construction and replacing the current model.
[0156] In this embodiment, the selection of model architecture is decoupled from the model building process. Users can quickly switch between different architectures without writing additional conditional branch code, facilitating ablation experiments and algorithm comparison studies, reducing experimental management complexity, and improving algorithm iteration efficiency. Simultaneously, the command-line parameter overriding mechanism makes temporary switching of model architectures more convenient, which is beneficial for rapid verification and debugging.
[0157] In an alternative implementation, this application also provides an integrated trend modeling platform architecture for unified management of the entire process of data generation, model training, and evaluation inference, enabling configurable, switchable, and traceable experiments. The platform includes a three-level configuration coverage mechanism, a model registry center, and a run_id traceability mechanism. In the three-level configuration coverage mechanism, "configuration" refers to the set of all adjustable parameters controlling program behavior, including data paths, model hyperparameters, training hyperparameters (such as learning rate, batch size, and number of training epochs), and normalization parameters. Configurations are stored in a structured manner using YAML format files, with three priority levels: the default configuration (providing basic default values for all parameters) is level one, the experiment configuration file (covering certain parameters for a specific experiment) is level two, and the command-line parameters (parameters specified by the user when starting the command) are level three, with priority increasing at each level. When the program starts, the default configuration, experiment configuration, and command-line parameters are loaded sequentially, with later-loaded configurations overriding parameters with the same name, achieving flexible and controllable experiment configuration management. In the run_id traceability mechanism, run_id refers to a unique identifier for each independent run, such as a string containing the date, time, and experiment number. Each time the platform starts, it automatically generates a run_id and names and stores all outputs related to that run using the run_id. These outputs include: a snapshot of the currently active complete configuration (YAML file), the trained model weight file (.pt or .h5 format), the mean and standard deviation parameters used for data standardization, and loss curve logs from the training process. Using the run_id, users can precisely trace back the complete environment and results of any experiment, ensuring the entire process is reproducible.
[0158] In an exemplary embodiment, after step 112, the method further includes: calculating mask L1 error and / or mask L2 error based on the prediction results of each node; the mask L1 error and mask L2 error are used to calculate the electrical quantities marked as to be predicted by the prediction mask in each node; the mask L1 error and / or mask L2 error are statistically analyzed by bus type to obtain the electrical quantity errors of slack nodes, PV nodes and PQ nodes respectively; the calculation accuracy of the graph neural network model is compared with the power flow solution method based on the physical model, and / or the calculation speed of the graph neural network model is compared with the power flow solution method based on the physical model to obtain the model evaluation result.
[0159] The L1 mask error is the average absolute error calculated only for the electrical quantities marked as to be predicted by the prediction mask at each node; it is the average of the absolute values of the differences between the predicted and actual values. The L2 mask error is the root mean square error calculated for the electrical quantities to be predicted; it is the square root of the average of the squares of the differences between the predicted and actual values. These two error metrics measure prediction accuracy from different perspectives: the L1 error is insensitive to outliers, while the L2 error penalizes larger deviations more severely.
[0160] For example, on the test set, the prediction results of each node output by the model are denormalized to restore them to physical units. The location of the electrical quantity to be predicted is determined based on the prediction mask of each node, and L1 and L2 errors are calculated only for these locations, rather than calculating them equally for all four electrical quantities, thus more accurately reflecting the model's true performance on their respective prediction tasks.
[0161] After obtaining the mask error of each node, the errors are statistically analyzed by bus type (balanced node, PV node, PQ node) to obtain the electrical quantity errors for each of the three types of nodes. By comparing the error differences between different bus types, it is possible to identify which type of node the model performs better or worse, guiding the direction of subsequent model optimization.
[0162] Furthermore, the computational accuracy of the graph neural network model is compared with that of power flow solution methods based on physical models (such as the Newton-Raphson method and the fast decoupling method) to verify whether the model meets the requirements of engineering applications in terms of accuracy. At the same time, the computational speed (time taken for a single forward propagation) of the graph neural network model is compared with the aforementioned power flow solution methods based on physical models to quantify the acceleration effect of the model.
[0163] In this embodiment, a refined evaluation of the model's prediction accuracy is achieved through mask error and component statistics, avoiding interference from invalid error calculations of known quantities. By comparing the accuracy and speed with power flow solution methods based on physical models, a quantitative basis is provided for determining whether the model meets the requirements of actual engineering applications.
[0164] In one exemplary embodiment, this embodiment uses the IEEE 14-node standard computational example as the base network, sets the reference capacity to 100MVA and the reference voltage to 345kV, in order to verify the feasibility and effectiveness of the method provided in this application embodiment.
[0165] First, the data generation step is executed. Multiple parallel processes are started (e.g., 10 processes, each using independent random number streams), with a target sample size of 30,000. For each candidate operating condition, random perturbations are applied to the base network: line resistance, reactance, and line length are randomly scaled uniformly within a range of 0.8 to 1.2 times; generator terminal voltage is randomly selected uniformly within a range of 1.00 to 1.05 per unit; and generator active power, load active power, and load reactive power are randomly perturbed according to a normal distribution, with the standard deviation set to 10% of the corresponding rated value. Subsequently, the Newton-Raphson method is used to solve the AC power flow for each perturbed operating condition. If the iteration converges, the sample and its true power flow value are retained; if it does not converge, the sample is discarded and a new perturbation is generated to supplement the sample size.
[0166] After convergence screening, each converged sample is exported as graph-structured data. The node feature array has a dimension of 6 (number of nodes), containing bus number, bus type, voltage amplitude, voltage phase angle, injected active power, and injected reactive power. The edge feature array has a dimension of 4 (number of edges), containing the first-end bus number, the last-end bus number, resistance, and reactance. Lines and transformers are uniformly represented as edges. All samples are saved in .npy format.
[0167] The following data preprocessing and partitioning steps are then performed. All converged samples are packaged into a graph dataset and partitioned into training, validation, and test sets in a ratio of 0.5:0.2:0.3. Z-score standardization is performed on node and edge features. The mean and standard deviation of each feature dimension on the training set are calculated and saved as normalization parameters. The validation and test sets reuse the normalization parameters from the training set. Prediction masks are generated according to bus type: the electrical quantities to be predicted for ballast nodes are injected active power P and injected reactive power Q; the electrical quantities to be predicted for PV nodes are voltage phase angle Va and injected reactive power Q; and the electrical quantities to be predicted for PQ nodes are voltage amplitude Vm and voltage phase angle Va.
[0168] Next, we construct a graph neural network model. In this embodiment, we choose a multi-step message passing network with masked embedding as the default model architecture, with a hidden layer dimension of 128, 4 layers in the graph neural network, a hop count K of the topology adaptive graph convolution, and a dropout rate of 0.2. The specific structure of the model is as follows: the node input features are first superimposed with masked embedding, and then sequentially passed through an edge aggregation message passing layer (injecting branch impedance information into the node representation) and 4 layers of topology adaptive graph convolutional layers (performing multi-hop neighborhood information aggregation). Finally, the output layer generates the predicted values of Vm, Va, P, and Q for each node.
[0169] Then, model training was performed. The AdamW optimizer was used, with an initial learning rate set to 1×10⁻⁶. -3The OneCycleLR learning rate scheduling strategy was used, with a batch size of 128 and 100 training epochs. The loss function employed was masked regression loss, which calculates the mean squared error for each electrical quantity marked as to be predicted by the prediction mask in each node. During training, the optimal model weights were saved based on the loss values on the validation set, and run_id, configuration snapshot, and epoch-by-epoch loss curves were recorded.
[0170] After training, the model is evaluated on the IEEE 14-node test set. The model's predictions are inversely normalized to physical units, and the masking errors for voltage amplitude, voltage phase angle, active power, and reactive power are calculated. The sub-item errors for each electrical quantity are also calculated separately for each bus type (balanced node, PV node, PQ node). The reproducible command-line procedure for this embodiment is: generate --case 14 --num-samples 30000; train --case 14 --modelMaskEmbdMultiMPN; test --run_id<RUN_ID> .
[0171] In one exemplary embodiment, the weights of the graph neural network model trained on the IEEE 14-node system and the normalized parameters saved during the training phase are reused from the previous embodiment to directly perform power flow inference on the larger IEEE 118-node system with a different topology, without the need for retraining or fine-tuning.
[0172] First, following the same data generation process as the previous embodiment, evaluation samples for the IEEE 118-node system are generated, with the corresponding command-line example being `generate --case 118`. Then, the model weights trained on the IEEE 14-node system are loaded, and the graph structure data of the IEEE 118-node system is input into the model. Since the edge aggregation message passing layer and the topology adaptive graph convolutional layer of the graph neural network both employ a node-level and edge-level parameter sharing mechanism, the model parameters are independent of the total number of nodes. Therefore, this model can directly process the graph structure input of 118 nodes, automatically performing neighborhood aggregation and feature updates on the new topology during forward propagation.
[0173] During evaluation, the normalized statistics saved in the IEEE 14 training phase are uniformly used to standardize the input features of the IEEE 118-bus system to ensure the consistency of data transformation. After model inference is completed, the prediction results are denormalized to physical units, the error of each electrical quantity on the IEEE 118-bus system is calculated, and the evaluation results are written to a separate file (e.g., test_metrics_case118.json), which will not overwrite the default evaluation results of the IEEE 14-bus system. A corresponding reproducible command line example is: test --run_id <RUN_ID of IEEE14> --test_case 118.
[0174] This embodiment shows that the graph neural network model trained by the embodiments of the present application can realize one-time training and multi-topology evaluation, which is significantly different from the traditional method that must perform separate modeling and training for each power grid, and effectively reduces modeling cost and deployment time.
[0175] It should be understood that although the various steps in the flowcharts involved in the above-described embodiments are displayed in sequence according to the indications of the arrows, these steps are not necessarily executed in the order indicated by the arrows. Unless explicitly stated herein, there is no strict sequence restriction on the execution of these steps, and these steps may be executed in other orders. Moreover, at least part of the steps in the flowcharts involved in the above-described embodiments may include multiple steps or multiple stages, these steps or stages are not necessarily completed at the same moment, but may be executed at different moments, and the execution order of these steps or stages is not necessarily sequential, but may be executed in turn or alternately with at least a part of other steps or steps or stages in other steps. It can be understood that the steps in different embodiments can be freely combined as needed, and various non-contradictory solutions formed by the combination all fall within the protection scope of the present application.
[0176] Based on the same inventive concept, the embodiments of the present application further provide a power system power flow calculation system based on graph neural network for implementing the above-mentioned power system power flow calculation method based on graph neural network. The problem-solving implementation scheme provided by this system is similar to the implementation scheme described in the above method, so the specific limitations in one or more embodiments of the power system power flow calculation system based on graph neural network provided below can refer to the above limitations for the power system power flow calculation method based on graph neural network, which will not be repeated here.
[0177] In an exemplary embodiment, as Figure 3 shown, a power system power flow calculation system based on graph neural network is provided, comprising:
[0178] The data generation module 302 is used to simulate multiple operating conditions by randomly perturbing the topology and electrical parameters of the base network using the IEEE standard example as the base network. For each operating condition, the Newton-Raphson method is used to solve the AC power flow, and convergent samples are selected from multiple operating conditions based on the solved AC power flow. Each convergent sample is exported as graph structure data. The graph structure data includes node features and edge features. The node features include at least the voltage magnitude, voltage phase angle, injected active power, and injected reactive power of each node, and the edge features include at least the resistance and reactance of each branch.
[0179] The model building module 304 is used to build a graph neural network model based on graph structure data. The graph neural network model includes an edge aggregation message passing layer and a topology adaptive graph convolutional layer. The edge aggregation message passing layer is used to process the source node features, target node features and edge features of each edge using a multilayer perceptron, and then normalizes and aggregates them to the target node according to the degree of symmetry.
[0180] The mask embedding module 306 is used to generate a prediction mask according to the bus type, and then superimpose the prediction mask onto the node input features of the graph neural network model after encoding; the bus types include balanced nodes, PV nodes and PQ nodes.
[0181] The model training module 308 is used to train a graph neural network model using a composite loss function; the composite loss function includes at least a masked regression loss term, which is used to calculate the mean square error based on the electrical quantity to be predicted at each node;
[0182] The inference evaluation module 310 is used to perform inference using a trained graph neural network model and output the prediction results of each node. The prediction results include at least the voltage magnitude and voltage phase angle of each node. Based on the prediction results, the power flow calculation results of each node are determined.
[0183] In the aforementioned power flow calculation device based on graph neural networks, by randomly perturbing IEEE standard examples and combining Newton-Raphson convergence screening, it can automatically and systematically generate batches of graph structure training samples covering diverse operating conditions and containing physical truth values, without relying on manual preparation or historical data accumulation. A single forward propagation using the graph neural network model can obtain an approximate solution for the entire network power flow, eliminating the need for iterative solutions for each operating scenario. This significantly improves computational efficiency when dealing with massive scenarios such as N-1 security scans and Monte Carlo analysis. The graph neural network model uses shared parameters at the node and edge levels. The multilayer perceptron in the edge aggregation message passing layer is repeatedly used to process each branch, and the parameters of the topology adaptive graph convolutional layer are applied to all nodes, with model weights independent of the total number of nodes. When applied to power grids of different sizes, only new graph structure data needs to be input, and the model can automatically perform neighborhood aggregation and feature updates on the new topology without retraining. By generating differentiated prediction masks based on bus type and superimposing them on the node input features, a single model can adaptively handle different known-to-predict boundary conditions for balanced nodes, PV nodes, and PQ nodes, without requiring separate sub-networks for each bus type. A composite loss function including a masked regression loss term guides the model to fit only the electrical quantities to be predicted. Combined with the consistency between the graph neural network message passing mechanism and the physical processes of the power system, the output results satisfy fundamental physical laws such as node power balance, resulting in high reliability.
[0184] In an exemplary embodiment, the system further includes a reuse module for applying a graph neural network model trained on a first instance to a second instance with a different number of nodes and a different topology for inference, and for reusing the normalized parameters from the training phase.
[0185] In an exemplary embodiment, the data generation module 302 is further configured to randomly perturb the topology and electrical parameters of the base network, including at least one of the following methods: randomly adding or deleting lines to change the topology; randomly scaling the line impedance parameters according to a preset ratio range; randomly selecting the generator terminal voltage within a preset voltage range; and randomly perturbing the generator active power, load active power, and load reactive power according to a preset probability distribution, wherein the preset probability distribution includes a normal distribution.
[0186] In an exemplary embodiment, the mask embedding module 306 is further configured to configure the electrical quantities to be predicted for the balancing node as including injected active power and injected reactive power, the electrical quantities to be predicted for the PV node as including voltage phase angle and injected reactive power, and the electrical quantities to be predicted for the PQ node as including voltage amplitude and voltage phase angle; mark the mask bits corresponding to the known electrical quantities as 0 and mark the mask bits corresponding to the electrical quantities to be predicted as 1; and after mapping the prediction mask into a continuous vector through a fully connected layer, fuse it with the node input features in an additive manner.
[0187] In one exemplary embodiment, the composite loss function further includes a known quantity retention loss term, which is used to apply a regularization constraint to the mean square error between the predicted values of electrical quantities that are known by the prediction mask at each node and the input values.
[0188] In an exemplary embodiment, the composite loss function further includes a power imbalance loss term, which is used to calculate the active and reactive power of each node using the AC power flow equation based on the voltage amplitude and voltage phase angle predicted by the model, and to calculate the mean square error between the node power output by the model or the assembled power and the power calculated by the AC power flow equation. The total loss of the composite loss function is a weighted sum of the mask regression loss term, the known quantity preservation loss term, and the power imbalance loss term, wherein the weight of the power imbalance loss term is gradually increased during training using a weight scheduling strategy.
[0189] In an exemplary embodiment, the system further includes a switching module, which is used to register multiple graph neural network architectures through a model registry center. The model registry center is configured with architecture identifiers corresponding to different graph neural network architectures. When it is necessary to switch model architectures, the model registry center automatically calls the corresponding graph neural network architecture to build the model by modifying the architecture identifier in the configuration file or specifying the target architecture identifier through command line parameters, thereby realizing the switching of multiple graph neural network architectures.
[0190] In an exemplary embodiment, the system further includes an evaluation module, which is used to calculate mask L1 error and / or mask L2 error based on the prediction results of each node; the mask L1 error and mask L2 error are used to calculate the electrical quantities marked as to be predicted by the prediction mask in each node; the mask L1 error and / or mask L2 error are statistically analyzed by bus type to obtain the electrical quantity errors of slack nodes, PV nodes and PQ nodes respectively; the computational accuracy of the graph neural network model is compared with the power flow solution method based on the physical model, and / or the computational speed of the graph neural network model is compared with the power flow solution method based on the physical model to obtain the model evaluation result.
[0191] The modules in the aforementioned power flow calculation system based on graph neural networks can be implemented entirely or partially through software, hardware, or a combination thereof. These modules can be embedded in or independent of the processor in a computer device, or stored in the computer device's memory as software, so that the processor can call and execute the corresponding operations of each module.
[0192] In one exemplary embodiment, a computer device is provided, which may be a server, and its internal structure diagram may be as follows: Figure 4 As shown, this computer device includes a processor, memory, input / output (I / O) interfaces, and a communication interface. The processor, memory, and I / O interfaces are connected via a system bus, and the communication interface is also connected to the system bus via the I / O interfaces. The processor provides computational and control capabilities. The memory includes non-volatile storage media and internal memory. The non-volatile storage media stores the operating system, computer programs, and a database. The internal memory provides the environment for the operating system and computer programs stored in the non-volatile storage media. The database stores model data, sample data, etc. The I / O interfaces are used for exchanging information between the processor and external devices. The communication interface is used for communication with external terminals via a network connection. When executed by the processor, the computer program implements a power flow calculation method based on a graph neural network.
[0193] Those skilled in the art will understand that Figure 4 The structure shown is merely a block diagram of a portion of the structure related to the present application and does not constitute a limitation on the computer device to which the present application is applied. Specific computer devices may include more or fewer components than those shown in the figure, or combine certain components, or have different component arrangements.
[0194] In an exemplary embodiment, a computer device is provided, including a memory and a processor. The memory stores a computer program, and the processor executes the computer program to perform the following steps: using an IEEE standard example as a base network, randomly perturbs the topology and electrical parameters of the base network to simulate multiple operating conditions; for each operating condition, solves the AC power flow using the Newton-Raphson method, and based on the solved AC power flow, selects convergent samples from the multiple operating conditions, and derives each convergent sample as graph structure data; the graph structure data includes node features and edge features; the node features include at least the voltage magnitude, voltage phase angle, injected active power, and injected reactive power of each node, and the edge features include at least the resistance and reactance of each branch; based on the graph structure data, a graph neural network model is constructed; the graph neural network model includes... The algorithm consists of an edge aggregation message passing layer and a topology adaptive graph convolutional layer. The edge aggregation message passing layer processes the source node features, target node features, and edge features for each edge using a multilayer perceptron, and then normalizes and aggregates them to the target node according to symmetry. A prediction mask is generated according to the bus type, and the prediction mask is encoded and superimposed on the node input features of the graph neural network model. The bus types include balanced nodes, PV nodes, and PQ nodes. A composite loss function is used to train the graph neural network model. The composite loss function includes at least a mask regression loss term, which is used to calculate the mean square error based on the electrical quantities to be predicted for each node. The trained graph neural network model is used for inference to output the prediction results for each node. The prediction results include at least the voltage magnitude and voltage phase angle of each node. Based on the prediction results, the power flow calculation results for each node are determined.
[0195] In one embodiment, when the processor executes the computer program, it further performs the following steps: applying the graph neural network model trained on the first instance to a second instance with a different number of nodes and a different topology than the first instance for inference, and reusing the normalized parameters from the training phase.
[0196] In one embodiment, when the processor executes the computer program, it further performs the following steps: randomly perturbing the topology and electrical parameters of the base network, including at least one of the following methods: randomly adding or deleting lines to change the topology; randomly scaling the line impedance parameters according to a preset proportional range; randomly selecting the generator terminal voltage within a preset voltage range; and randomly perturbing the generator active power, load active power, and load reactive power according to a preset probability distribution, wherein the preset probability distribution includes a normal distribution.
[0197] In one embodiment, when the processor executes the computer program, it further implements the following steps: configuring the electrical quantities to be predicted for the balancing node to include injected active power and injected reactive power, configuring the electrical quantities to be predicted for the PV node to include voltage phase angle and injected reactive power, and configuring the electrical quantities to be predicted for the PQ node to include voltage amplitude and voltage phase angle; marking the mask bits corresponding to the known electrical quantities as 0 and marking the mask bits corresponding to the electrical quantities to be predicted as 1; and after mapping the prediction mask into a continuous vector through a fully connected layer, fusing it with the node input features in an additive manner.
[0198] In one embodiment, when the processor executes the computer program, it further implements the following steps: the composite loss function also includes a known quantity retention loss term, which is used to apply a regularization constraint to the mean square error between the predicted values and the input values of electrical quantities that are known by the prediction mask at each node.
[0199] In one embodiment, when the processor executes the computer program, it further implements the following steps: the composite loss function also includes a power imbalance loss term, which is used to calculate the active and reactive power of each node through the AC power flow equation based on the voltage amplitude and voltage phase angle predicted by the model, and to calculate the mean square error between the node power output by the model or the assembled power and the power calculated by the AC power flow equation; the total loss of the composite loss function is a weighted sum of the mask regression loss term, the known quantity preservation loss term and the power imbalance loss term, wherein the weight of the power imbalance loss term is gradually increased during the training process using a weight scheduling strategy.
[0200] In one embodiment, when the processor executes the computer program, it also performs the following steps: registering multiple graph neural network architectures through a model registry; the model registry is configured with architecture identifiers corresponding to different graph neural network architectures; when it is necessary to switch model architectures, by modifying the architecture identifier in the configuration file or specifying the target architecture identifier through command line parameters, the model registry automatically calls the corresponding graph neural network architecture to build the model according to the target architecture identifier, thereby realizing the switching of multiple graph neural network architectures.
[0201] In one embodiment, when the processor executes the computer program, it further implements the following steps: calculating the mask L1 error and / or mask L2 error based on the prediction results of each node; the mask L1 error and mask L2 error are used to calculate the electrical quantities marked as to be predicted by the prediction mask in each node; the mask L1 error and / or mask L2 error are statistically analyzed by bus type to obtain the electrical quantity errors of the slack bus, PV bus and PQ bus respectively; the computational accuracy of the graph neural network model is compared with the power flow solution method based on the physical model, and / or the computational speed of the graph neural network model is compared with the power flow solution method based on the physical model to obtain the model evaluation result.
[0202] It should be noted that the user information (including but not limited to user device information, user personal information, etc.) and data (including but not limited to data used for analysis, data stored, data displayed, etc.) involved in this application are all information and data authorized by the user or fully authorized by all parties, and the collection, use and processing of the relevant data must comply with relevant regulations.
[0203] Those skilled in the art will understand that all or part of the processes in the methods of the above embodiments can be implemented by a computer program instructing related hardware. The computer program can be stored in a non-volatile computer-readable storage medium, and when executed, it can include the processes of the embodiments of the above methods. Any references to memory, databases, or other media used in the embodiments provided in this application can include at least one of non-volatile memory and volatile memory. Non-volatile memory can include read-only memory (ROM), magnetic tape, floppy disk, flash memory, optical memory, high-density embedded non-volatile memory, resistive random access memory (ReRAM), magnetic random access memory (MRAM), ferroelectric random access memory (FRAM), phase change memory (PCM), graphene memory, etc. Volatile memory can include random access memory (RAM) or external cache memory, etc. By way of illustration and not limitation, RAM can take many forms, such as Static Random Access Memory (SRAM) or Dynamic Random Access Memory (DRAM). The databases involved in the embodiments provided in this application may include at least one type of relational database and non-relational database. Non-relational databases may include, but are not limited to, blockchain-based distributed databases. The processors involved in the embodiments provided in this application may be general-purpose processors, central processing units, graphics processing units, digital signal processors, programmable logic devices, quantum computing-based data processing logic devices, artificial intelligence (AI) processors, etc., and are not limited to these.
[0204] The technical features of the above embodiments can be combined in any way. For the sake of brevity, not all possible combinations of the technical features in the above embodiments are described. However, as long as there is no contradiction in the combination of these technical features, they should be considered to be within the scope of this application.
[0205] The embodiments described above are merely illustrative of several implementation methods of this application, and while the descriptions are specific and detailed, they should not be construed as limiting the scope of this patent application. It should be noted that those skilled in the art can make various modifications and improvements without departing from the concept of this application, and these all fall within the protection scope of this application. Therefore, the protection scope of this application should be determined by the appended claims.
Claims
1. A power system power flow calculation method based on a graph neural network, characterized in that, The method includes: Using the IEEE standard example as the base network, the topology and electrical parameters of the base network are randomly perturbed to simulate multiple operating conditions; The Newton-Raphson method is used to solve the AC power flow for each operating condition, and convergent samples are selected from the multiple operating conditions based on the solved AC power flow. Each convergent sample is exported as graph structure data. The graph structure data includes node features and edge features. The node features include at least the voltage magnitude, voltage phase angle, injected active power, and injected reactive power of each node. The edge features include at least the resistance and reactance of each branch. Based on the graph structure data, a graph neural network model is constructed. The graph neural network model includes an edge aggregation message passing layer and a topology adaptive graph convolutional layer. The edge aggregation message passing layer is used to process the source node features, target node features and edge features of each edge using a multilayer perceptron, and then normalizes and aggregates them to the target node according to the degree of symmetry. A prediction mask is generated according to the bus type, and the prediction mask is encoded and superimposed on the node input features of the graph neural network model; the bus type includes balanced nodes, PV nodes and PQ nodes. The graph neural network model is trained using a composite loss function; the composite loss function includes at least a masked regression loss term, which is used to calculate the mean square error based on the electrical quantity to be predicted at each node; The trained graph neural network model is used for inference, and the prediction results of each node are output; the prediction results include at least the voltage amplitude and voltage phase angle of each node. Based on the prediction results, the power flow calculation results for each node are determined.
2. The method of claim 1, wherein, The method further includes: The graph neural network model trained on the first example is applied to a second example with a different number of nodes and a different topology than the first example for inference, and the normalized parameters from the training phase are reused.
3. The method of claim 1, wherein, The random perturbation of the topology and electrical parameters of the base network includes at least one of the following methods: Randomly add or remove lines to change the topology; The line impedance parameters are randomly scaled according to a preset ratio range; Randomly select a value for the generator terminal voltage within a preset voltage range; The active power of power generation, the active power of load, and the reactive power of load are randomly disturbed according to a preset probability distribution, which includes a normal distribution.
4. The method of claim 1, wherein, The step of generating a prediction mask according to the bus type, and then encoding the prediction mask and superimposing it onto the node input features of the graph neural network model, includes: The electrical quantities to be predicted at the balancing node are configured to include injected active power and injected reactive power, the electrical quantities to be predicted at the PV node are configured to include voltage phase angle and injected reactive power, and the electrical quantities to be predicted at the PQ node are configured to include voltage amplitude and voltage phase angle. Mark the mask bits corresponding to the known electrical quantities as 0, and mark the mask bits corresponding to the electrical quantities to be predicted as 1; The predicted mask is mapped into a continuous vector through a fully connected layer and then fused with the node input features in an additive manner.
5. The method of claim 1, wherein, The composite loss function further includes a known quantity retention loss term, which is used to apply a regularization constraint to the mean square error between the predicted value and the input value of the electrical quantity that is known by the prediction mask at each node.
6. The method of claim 5, wherein, The composite loss function also includes a power imbalance loss term, which is used to calculate the active and reactive power of each node based on the voltage amplitude and voltage phase angle predicted by the model through the AC power flow equation, and to calculate the mean square error between the node power output by the model or the assembled power and the power calculated by the AC power flow equation. The total loss of the composite loss function is the weighted sum of the mask regression loss term, the known quantity preservation loss term, and the power imbalance loss term, wherein the weight of the power imbalance loss term is gradually increased during training using a weight scheduling strategy.
7. The method according to any one of claims 1 to 6, characterized in that, After constructing the graph neural network model based on the graph structure data, the method further includes: Multiple graph neural network architectures are registered through a model registry center; the model registry center is configured with architecture identifiers corresponding to different graph neural network architectures. When it is necessary to switch model architectures, the model registry center can automatically call the corresponding graph neural network architecture to build the model by modifying the architecture identifier in the configuration file or specifying the target architecture identifier through command line parameters, thereby realizing the switching of multiple graph neural network architectures.
8. The method according to any one of claims 1 to 6, characterized in that, After performing inference using the trained graph neural network model and outputting the prediction results for each node, the method further includes: Based on the prediction results of each node, the mask L1 error and / or mask L2 error are calculated; the mask L1 error and mask L2 error are used to calculate the electrical quantities marked as to be predicted by the prediction mask in each node. The mask L1 error and / or mask L2 error are statistically analyzed separately according to the bus type to obtain the electrical quantity errors of the ballast node, PV node and PQ node respectively. The computational accuracy of the graph neural network model is compared with that of the power flow solution method based on the physics model, and / or the computational speed of the graph neural network model is compared with that of the power flow solution method based on the physics model, to obtain the model evaluation results.
9. A power system power flow calculation system based on a graph neural network, characterized in that, The system includes: The data generation module is used to simulate multiple operating conditions by randomly perturbing the topology and electrical parameters of the IEEE standard example network. For each operating condition, the Newton-Raphson method is used to solve the AC power flow, and convergent samples are selected from the multiple operating conditions based on the solved AC power flow. Each convergent sample is exported as graph structure data. The graph structure data includes node features and edge features. The node features include at least the voltage magnitude, voltage phase angle, injected active power, and injected reactive power of each node, and the edge features include at least the resistance and reactance of each branch. The model building module is used to build a graph neural network model based on the graph structure data. The graph neural network model includes an edge aggregation message passing layer and a topology adaptive graph convolutional layer. The edge aggregation message passing layer is used to process the source node features, target node features and edge features of each edge using a multilayer perceptron, and then normalize and aggregate them to the target node according to the symmetry. A mask embedding module is used to generate a prediction mask according to the bus type, and to superimpose the prediction mask onto the node input features of the graph neural network model after encoding; the bus type includes balanced nodes, PV nodes and PQ nodes. The model training module is used to train the graph neural network model using a composite loss function; the composite loss function includes at least a masked regression loss term, which is used to calculate the mean square error based on the electrical quantity to be predicted at each node; The inference evaluation module is used to perform inference using a trained graph neural network model and output the prediction results for each node; the prediction results include at least the voltage magnitude and voltage phase angle of each node; based on the prediction results, the power flow calculation results for each node are determined. 10.A computer device, comprising a memory and a processor, wherein the memory stores a computer program, and the computer device is configured to perform the method according to any one of claims 1-9. When the processor executes the computer program, it implements the steps of the method according to any one of claims 1 to 8.
