Classification automatic differentiation method and simulation solver, electronic device, storage medium

CN122818601APending Publication Date: 2026-09-25ZHEJIANG UNIV +1
View PDF 0 Cites 0 Cited by

Patent Information

Application Number
CN202610715276.0
Authority / Receiving Office
CN · China
Patent Type
Applications(China)
Current Assignee / Owner
Filing Date
2026-05-22
Publication Date
2026-09-25

AI Technical Summary

Technical Problem

这种做法未能充分利用DAE系统在预处理阶段(如方程分块及强联通分量分解等)揭示的结构特征,导致在不必要的地方进行微分计算,造成计算图膨胀、内存占用高和计算冗余

Benefits of technology

由上述实施例可知,本申请对不同类型的方程采用使其平衡生成代码量和计算速度的最优微分策略,克服了统一自动微分方法不适用于代数环和差商近似产生过多冗余迭代的问题,达成了内存占用减少和处理器指令数减少的效果,具体地:对显式块构造赋值形式的微分方程,克服了传递计算图的方式生成代码量大的问题,进而达到了减少内存占用和减少计算指令数的效果。对隐式块构造线性方程组,对代数环通过矩阵变换消去显式变量的迭代操作,克服了隐式方程符号展开困难或差商近似精度低的问题,进而达到了仿真精度得以提升的效果。

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN122818601A_ABST
    Figure CN122818601A_ABST
Patent Text Reader

Abstract

The application discloses a kind of classification automatic differentiation method and simulation solver, electronic equipment, storage medium, applied to industrial control system simulation solver preprocessing stage, comprising: the layered block directed acyclic graph formed by the physical model of controlled object is obtained by compiling block;Traverse the layered block directed acyclic graph, according to the type of current traversed equation block, execute corresponding differentiation strategy: if the type of current block is explicit block, execute first differentiation strategy, generate an explicit data object;If the type of current block is implicit block, execute second differentiation strategy, generate an implicit data object;If the type of current block is algebraic ring, execute third differentiation strategy, generate an implicit data object and an explicit data object;All explicit data objects and implicit data objects generated are stored in a uniform order container according to the topological order defined by the layered block directed acyclic graph.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] This application relates to the fields of computer-aided engineering (CAE) and industrial simulation technology, and in particular to a classification automatic differentiation method and simulation solver, electronic equipment, and storage medium. Background Technology

[0002] In the simulation verification of safety-critical systems such as automotive electronic controller hardware-in-the-loop simulation, aircraft servo control system real-time simulation, and industrial robot joint motion control, the physical model of the controlled object is usually compiled into a system of differential algebraic equations (DAE system). The simulation solver needs to calculate the Jacobian matrix of the DAE system in each simulation time step in order to complete the Newton iteration update of the system state.

[0003] Unlike simple ordinary differential equations, DAE systems describe the dynamic characteristics of the system through differential equations and introduce physical constraints or conservation laws through algebraic equations.

[0004] From a mathematical perspective, a DAE system can typically be represented as: Based on whether the equation contains differential terms and the dependencies between variables, it can be classified into different types: Explicit equations: of the form of The equation has variables on the left side that can be directly calculated from the function on the right side without iterative solution.

[0005] Implicit equations: of the form of The equation, where the variables Cannot be directly expressed as Explicit functions usually require numerical solutions using iterative methods such as the Newton-Raphson method.

[0006] In Modelica-based physical system simulations, simulation solvers (such as DASSL and CVODE) typically employ implicit integration methods, such as the BDF method and the implicit Runge-Kutta method, to solve the equations. Within each integration step, the Jacobian matrix needs to be calculated to iteratively solve a system of nonlinear algebraic equations. The accuracy and efficiency of the Jacobian matrix calculation are crucial for ensuring the convergence speed and overall simulation performance of Newton-like iterative methods. Existing simulation solvers typically obtain the Jacobian matrix in two ways: Difference quotient approximation (numerical differentiation): This method approximates the derivative value by perturbing the independent variable. It is simple to implement, but suffers from truncation error, which affects the convergence speed of nonlinear iterations. Furthermore, its computational cost is proportional to the number of system variables, resulting in high computational redundancy and low efficiency for large-scale DAE systems.

[0007] Unified Automatic Differentiation: Automatic differentiation utilizes the chain rule to accurately calculate derivatives, avoiding truncation errors. However, existing automatic differentiation methods typically treat the entire DAE system as a single unit. This approach fails to fully utilize the structural features revealed during the preprocessing phase of the DAE system (such as equation partitioning and strongly connected component decomposition), leading to unnecessary differentiation calculations, resulting in computational graph bloat, high memory consumption, and computational redundancy. The lack of reuse management for partial differential expression nodes leads to repeated storage and computation of partial derivative expressions with the same structure. The absence of inter-block dependency sequential storage of differentiation results necessitates frequent lookups by the processor at runtime, reducing instruction pipeline efficiency. Summary of the Invention

[0008] To address the above issues, embodiments of this application provide a classification automatic differentiation method, a simulation solver, an electronic device, and a storage medium.

[0009] According to a first aspect of the embodiments of this application, a classification automatic differentiation method is provided, characterized in that it is applied to an industrial control system and includes: Step S1: Obtain the hierarchical block directed acyclic graph formed by compiling and dividing the physical model of the controlled object; Step S2: Traverse the hierarchical block-based directed acyclic graph, and execute the corresponding differentiation strategy according to the type of the equation block currently traversed: S21: If the current block is of type explicit block, then execute the first differential strategy to generate an explicit data object; S22: If the current block is of type implicit block, then execute the second differential strategy to generate an implicit data object; S23: If the current block is of type algebraic ring, then execute the third differential strategy to generate an implicit data object and an explicit data object; Step S3: Store all explicit and implicit data objects generated in step S2 in a unified order container according to the topological order defined by the hierarchical block directed acyclic graph.

[0010] Optionally, when executing the first, second, and third differentiation strategies, a selective automatic differentiation tool is invoked to perform differentiation calculations; the selective automatic differentiation tool is configured as follows: The input includes the differential expression E, the independent variable x, and the set of dependent variables. The Boolean flag `include_direct` is taken as input, and the partial differential expression `R` is output; wherein, the set of dependent variables... The elements in the set are the set of dependent variables contained in the equation block that has completed the differential calculation before the current block, and do not contain state variables.

[0011] Optionally, the selective automatic differentiation tool calculates the partial derivative expression R in the following manner: If the boolean flag include_direct is true, then the initialization result is... ,in, This means ignoring other variables in E that are related to x, only taking the partial derivative of x with respect to terms that explicitly contain x, otherwise initializing the result. When the Boolean flag include_direct is false, the result has no physical meaning and is only used as an intermediate mathematical supplement. Traverse the set of dependent variables For each dependent variable d in the equation, calculate... And construct implicit partial derivative nodes. ; Will and Multiplication and accumulation added to ; Return the accumulated result: The expression for the partial differential result is essentially a modification of the formal partial derivative into the actual mathematical partial derivative.

[0012] Optionally, whenever an explicit or implicit block completes the differential calculation and generates the corresponding data object, the dependent variables corresponding to that equation block are added to the dependent variable set. For blocks of algebraic ring type, their implicit and explicit parts are treated as an implicit block and an explicit block, respectively. After the implicit data object corresponding to the implicit part is generated, the dependent variables of the implicit part are added to the dependent variable set. Then, the explicit differential calculation is performed.

[0013] Optionally, the specific construction method of the data object includes: Define a base class to store common information about all types of equation blocks, including explicit / implicit enumeration types and the corresponding number of state variables n; Define a derived data class for the differential results of the explicit part of an explicit equation or an algebraic ring. Store the number of equations r in the original equation block and r*n equations in assignment form. The left side of the equation is the partial differential node as an unknown, and the right side is the symbolic expression of the differential result. Define a derived data class for the differential results of the implicit part in an implicit equation or algebraic ring, storing the coefficient matrix array A, the right-hand matrix array B, and the unknown partial derivative node number vector X; Create a uniformly ordered container to store all created data objects.

[0014] Optionally, the first differential strategy specifically includes: Rewrite the explicit equation into an assignment form, where the independent variable of the equation is a vector of state variables. For each state variable, construct partial differential nodes; The selective automatic differentiation tool is invoked to calculate the partial differential expression of the right-hand side of the assigned form equation, and then combined with the partial differential node to generate the differential equation of the assigned form equation, which is stored in the explicit intermediate representation data object. Add the dependent variable y of the explicit block to the dependent variable array D of the selective automatic differentiation tool.

[0015] Optionally, the second differential strategy specifically includes: The implicit equation is rearranged to obtain the residual expression, where the dependent variable is the dependent variable and the independent variable is the state variable. For each state variable, construct partial differential nodes and store their numbers in a vector; Calculate the coefficient matrix A and the right-hand matrix B based on the residual expression; Based on the coefficient matrix, right-hand side matrix, and vector, construct a system of linear equations, and then... Store the implicit intermediate representation data object; Add the dependency variables of the implicit block to the dependent variable array D of the selective automatic differentiation tool.

[0016] Optionally, the third differential strategy specifically includes: The equations in the algebraic ring are divided into a set of explicit equations and a set of implicit equations. The set of dependent variables for the explicit equations, ys, and the set of dependent variables for the implicit equations, yu, are recorded. This differs from y=f(x) in the first differential strategy. The right-hand side of the equation represents only the result of rearranging terms, while the left-hand side represents terms that explicitly contain dependent variables. Calculate the formal partial derivative matrix Q1 of the explicit equation with respect to the iteration variables, the formal partial derivative matrix Q2 of the implicit equation with respect to the explicit variables, and the formal partial derivative matrix Q3 of the implicit equation with respect to the iteration variables; For each state variable, calculate the partial derivative matrix Q4 of the explicit equation and the partial derivative matrix Q5 of the implicit equation; Based on the set of dependent variables and state variables of the implicit equation, create partial derivative nodes and store their numbers in an ordered vector X; Based on the partial derivative matrix, partial derivative matrix and ordered vector shown, construct an implicit intermediate representation data object, where the coefficient matrix A = Q3 + Q2 Q1, the right-hand matrix B = -Q5 - Q2 Q4, and the unknown partial derivative node numbering vector is the ordered vector X. Add the elements from the set of dependent variables yu of the implicit equation to the dependent variable array of the selective automatic differentiation tool. middle; For each explicit equation in the set of explicit equations, for each state variable, construct a partial differential node, and call the selective automatic differentiation tool with the current state variable as the independent variable, set the dependent variable array to yu, set the Boolean flag include_direct to false, and obtain the supplementary expression R1. For each R1, find the Q4 elements that are the same in the combination of equation and state variables and add them together. Divide by the coefficients of the dependent variables in the original equation. The resulting expression is combined with the partial differential nodes to form a differential equation and generate the corresponding explicit intermediate representation data object. Dependencies in the explicit part Add the dependent variable array to the selective automatic differentiation tool middle.

[0017] Optionally, during the construction of the partial derivative node, a node management module performs content-based hash comparison and number allocation to achieve node reuse for the same partial derivative expression.

[0018] According to a second aspect of the embodiments of this application, a simulation solver for an industrial control system is provided, comprising the classification automatic differentiation device as described in the first aspect.

[0019] According to a third aspect of the embodiments of this application, an electronic device is provided, comprising: One or more processors; Memory, used to store one or more programs; When the one or more programs are executed by the one or more processors, the one or more processors perform the method as described in the first aspect.

[0020] According to a fourth aspect of the embodiments of this application, a computer-readable storage medium is provided having a computer program stored thereon, which, when executed by a processor, implements the method described in the first aspect.

[0021] The technical solutions provided by the embodiments of this application may include the following beneficial effects: As can be seen from the above embodiments, this application employs an optimal differentiation strategy that balances the amount of generated code and computation speed for different types of equations. This overcomes the problem that the unified automatic differentiation method is not suitable for algebraic rings and generates too many redundant iterations in difference quotient approximations, achieving the effect of reducing memory usage and processor instruction count. Specifically: for explicit blocks, constructing assignment-form differential equations overcomes the problem of large code generation by passing computation graphs, thereby reducing memory usage and computation instruction count. For implicit blocks, constructing linear equation systems and eliminating iterative operations of explicit variables through matrix transformations for algebraic rings overcomes the problems of difficult symbolic expansion of implicit equations or low accuracy of difference quotient approximations, thereby improving simulation accuracy.

[0022] All generated explicit and implicit data objects are stored in the same sequential container according to the topological order defined by the hierarchical and block-based directed acyclic graph. This overcomes the performance bottleneck that the runtime cannot obtain all node values ​​at once and requires multiple rounds of assignment calculations. It enables the processor to read sequentially and evaluate directly, achieving a significant improvement in cache hit rate and instruction pipeline efficiency.

[0023] It should be understood that the above general description and the following detailed description are exemplary and explanatory only, and do not limit this application. Attached Figure Description

[0024] The accompanying drawings, which are incorporated in and form part of this specification, illustrate embodiments consistent with this application and, together with the description, serve to explain the principles of this application.

[0025] Figure 1 This is a flowchart illustrating an automatic differentiation method for classification according to an exemplary embodiment. Detailed Implementation

[0026] Exemplary embodiments will now be described in detail, examples of which are illustrated in the accompanying drawings. When the following description relates to the drawings, unless otherwise indicated, the same numbers in different drawings denote the same or similar elements. The embodiments described in the following exemplary embodiments do not represent all embodiments consistent with this application. Rather, they are merely examples of apparatuses and methods consistent with some aspects of this application.

[0027] The terminology used in this application is for the purpose of describing particular embodiments only and is not intended to be limiting of the application. The singular forms “a,” “the,” and “the” used herein are also intended to include the plural forms unless the context clearly indicates otherwise. It should also be understood that the term “and / or” as used herein refers to and includes any and all possible combinations of one or more of the associated listed items.

[0028] In the simulation and verification of safety-critical systems such as automobiles, aerospace, and robotics, the physical model of the controlled object is usually described as a system of differential-algebraic equations (DAE) to achieve high-fidelity hardware-in-the-loop (HIL) or real-time simulation.

[0029] Taking the classic permanent magnet direct current motor (PMDC) model as an example, it serves as a core execution component and is widely used in the design and verification of control systems in the following fields: Automotive electronics: used for simulation of the starting process, load characteristics, and controller response of electric window lift mechanisms, electric seat adjustment, and windshield wiper motors.

[0030] Aerospace: Real-time simulation and verification of high-dynamic, high-precision position servo loops for aircraft servo systems, rocket vector nozzle actuators, and other applications.

[0031] Industrial robots: used for simulating the start-up process of joint servo motors, dynamic performance testing, and calibration of motion controller parameters.

[0032] This embodiment uses a permanent magnet DC motor as an example controlled object to describe the present invention in detail, but it is not limited thereto.

[0033] Figure 1 This is a flowchart illustrating an automatic differentiation method for classification according to an exemplary embodiment, such as... Figure 1 As shown, this method is applied to industrial control systems, specifically in the preprocessing stage of the simulation solver for industrial control systems, and may include the following steps: Step S1: Obtain the hierarchical block directed acyclic graph formed by compiling and dividing the physical model of the controlled object; Specifically, this example uses a permanent magnet DC motor as the controlled object, and its mathematical and physical model is based on the permanent magnet DC motor model Modelica.Electrical.Machines.Examples.DCMachines.DCPM_Start from the official Modelica library. The differential-algebraic system expression generated by compiling the model is as follows: The superscript “·” in the formula refers to the first derivative of the variable with respect to time. The physical meaning and unit description of each parameter in the model are shown in Table 1.

[0034] Table 1: The physical meaning and units of each variable are shown in Table 2.

[0035] Table 2: After automated block processing, the input obtained by this invention is a hierarchical block-based directed acyclic graph related to the integral part, represented as a block list. The structural characteristics of the DAE system, referring to the system's block list, are a directed acyclic graph structure. Each node recursively generates a subgraph until it contains only one equation, arranged in the order of solution, and includes information about the variables each equation depends on. Nodes in the graph are called "blocks," representing a structure containing several equations, including algebraic rings (torn blocks) that must be solved simultaneously, and single implicit or explicit equations that can be directly solved. A brief illustration follows: Among them, rotor angular displacement Armature current Angular velocity of load These are the state variables of the permanent magnet DC motor model. Auxiliary variables include: This is the voltage at the negative terminal of the armature inductor. The armature resistance voltage is This is the potential at the negative terminal of the armature resistor. The armature inductance voltage, For electromagnetic torque, Shaft torque, external load torque , This represents the motor terminal voltage. Model parameters include the torque constant. armature resistance Rotor moment of inertia Load rotational inertia armature inductance .

[0036] Equations (7-8) form an algebraic ring and need to be solved simultaneously. and In the coupling, equation (7) is chosen as the explicit equation, (8) is the implicit equation, and all other equations are explicit equations.

[0037] The input of this invention is a hierarchical block directed acyclic graph formed by compiling and dividing the physical model of the controlled object. It mainly provides a unified classification criterion for the differentiation step, and the topological solution order it indicates transforms the coefficients of the integral part of the equation system into a lower triangular matrix. For each equation being solved, the other variables contained therein have already been obtained, and all variable values ​​can be obtained in one round without repeated calculations. This order also applies to the result after differentiation, achieving the effect of avoiding repeated calculations and reducing the number of processor instructions.

[0038] Step S2: Traverse the hierarchical block-based directed acyclic graph. Based on the type of the equation block currently traversed, execute the corresponding differentiation strategy: if the current block is an explicit block, execute the first differentiation strategy to generate an explicit data object; if the current block is an implicit block, execute the second differentiation strategy to generate an implicit data object; if the current block is an algebraic ring, execute the third differentiation strategy to generate an implicit data object and an explicit data object. Specifically, in the preprocessing stage of permanent magnet DC motor model simulation, the selective automatic differentiation tool of this invention modifies the forward mode automatic differentiation implementation into a selective automatic differentiation method. This solves the technical problem that the forward mode automatic differentiation, which does not record the computation graph, cannot identify the implicit dependent variable, and provides a general method for subsequently calculating expressions for several different purposes. The logic is as follows: (1) Receive the differential expression E and the independent variable Dependent variable set and the boolean flag include_direct; where, The middle element is the set of dependency variables contained in all previous blocks, excluding state variables. After each explicit or implicit block completes the differential calculation and packages the data object, the dependency variables corresponding to the equation must be added. In the case of an algebraic ring, the explicit and implicit parts are treated as an explicit block and an implicit block, respectively, with the implicit block placed first. The implicit data objects are then packaged, and the dependent variables of the implicit part are added to the implicit block. Only then can the explicit partial differential calculations be performed; (2) If the Boolean flag include_direct is true, then the initialization result is... (Formal partial differential symbols) The ergodic equation contains explicit independent variables. The terms are obtained using an abstract syntax tree. right The formal partial derivative expression is given, and the output is a portion of the actual mathematical partial derivative. This means ignoring other variables in E that are related to x, only taking the partial derivative of x with respect to terms that explicitly contain x, otherwise initializing the result. When the Boolean flag include_direct is false, the result has no physical meaning and is only used as an intermediate mathematical supplement. (3) Traversal Each dependent variable in ,calculate Construct implicit partial derivative nodes ,Will and Multiplication and accumulation added to ; (4) Return the accumulated result As a partial differential result expression (here and below, in the form of...) The symbol represents the partial differential expression of expression a with respect to variable b obtained using selective automatic differentiation tools; essentially, it corrects the formal partial derivative to the actual mathematical partial derivative.

[0039] Because equation blocks are interdependent, both the differentiation and evaluation processes must strictly follow the topological solution order, and different types of equations produce different intermediate representations. Unifying these intermediate representations into standardized object pointers and arranging them according to the solution order solves the technical problem of the runtime evaluation module requiring a strict order. The specific construction method of the data object is as follows: A. Define a base class to store common information for all types of equation blocks, mainly including explicit / implicit enumeration types and the corresponding number of state variables n (for runtime space allocation).

[0040] B. Define a derived data class for the differential results of the explicit part of an explicit equation or an algebraic ring. Store the number of equations r in the original equation block, and r*n equations in assignment form. The left side is the partial differential node as the unknown, and the right side is the symbolic expression of the differential result.

[0041] C. Define a derived data class for the differential results of the implicit part of the implicit equation or algebraic ring, storing the coefficient matrix array A, the right-hand matrix array B, and the unknown partial derivative node number vector X.

[0042] D. Create a uniformly ordered container to store all created data objects.

[0043] S21: If the current block is an explicit block (containing a single explicit equation), then execute the first differential strategy to generate an explicit data object; When industrial models contain implicit equations, automatic differentiation is difficult to apply, easily leading to regression to difference quotient approximation. This step avoids the technical problem of using difference quotient approximation to find the derivative of explicit equations in this case, reducing local computational complexity. The first differentiation strategy includes: (1) Rewrite the explicit equation in the form of assignment. ,in A vector of state variables; (2) For each state variable The variable on the left side of the equals sign Construct partial differential nodes in memory, using the differentiable expression and the current state variable as the independent variable. ,in This represents a data structure stored in memory, which acts as a binary symbol node, recording information about the differential expression and its independent variables, and assigning a unique number to it. (3) Call the selective automatic differentiation tool to calculate the partial differential expression of the right-hand side expression with respect to the current state variable. Generate differential equations in assignment form ; (4) Store the differential equation in the assigned form into an explicit intermediate representation data object, and... Store the dependent variable array of the selective differentiation tool middle.

[0044] In the permanent magnet DC motor model of the above embodiment, after block processing, the integral part has a structure of 7 explicit blocks, and this model has 3 state variables, namely rotor angular displacement. Armature current Angular velocity of load Equations (1-6, 9) are explicit equation blocks. For each explicit block, executing the first differential strategy will generate three assignment-form differential equations. Taking equation (2) as an example: The three equations above are stored sequentially in a vector container, which serves as a member of an explicit data object. Other member variables include: type - EXPLICIT, number of original equations - 1, and number of state variables - 3. Following the topological solution order, this object is the second element of the unified order container.

[0045] S22: If the current block is an implicit block (containing a single implicit equation), then execute the second differential strategy to generate an implicit data object; A single implicit equation does not depend on other variables and can theoretically be solved directly. However, its complex form makes it impossible to rewrite the transformation procedure into an assignment form, and it cannot be processed in the same way as explicit equations. Therefore, the difference quotient approximation method is also used to find the numerical differential. This step constructs a system of linear equations as an intermediate form for a single implicit equation, which solves the technical problem that the difference quotient approximation cannot identify explicit partial differential nodes and repeatedly recalculates.

[0046] Input: A pointer to an implicit equation block node, which contains an implicit equation and its corresponding variables.

[0047] Output: An implicit data object containing a coefficient matrix, a right-hand side matrix, and a vector of partial differential node numbers as unknowns.

[0048] The second differential strategy includes: (1) Rearrange the implicit equation to obtain the residual expression. , where y is a dependency variable; (2) For each state variable Construct partial differential nodes And store the node number into a vector. ; (3) Call the selective automatic differentiation function to calculate the coefficient matrix. and the right-hand matrix Construct a system of linear equations ; (4) , , Store the implicit intermediate representation data object, and Store the dependent variable array of the selective automatic differentiation tool middle.

[0049] After obtaining numerical values ​​for A and B in the simulation, functions for solving linear equations from the linear algebra library can be called. A is the coefficient matrix, and B is the right-hand side of the equation. The solution is written to the corresponding position in B, so the updated B matrix contains the required partial differential node values. B and X have equal lengths, and X represents the partial differential node number corresponding to the index expression at the same position in B. Values ​​can be associated with corresponding partial differential nodes using X.

[0050] S23: If the current block is of type algebraic ring (containing multiple equations that need to be solved simultaneously), then execute the third differential strategy to generate an implicit data object and an explicit data object. Algebraic rings, also known as torn blocks, consist of multiple algebraic equations that must be solved simultaneously. A torn block contains both implicit and explicit equations. The process still involves constructing differential equations for the explicit equations and linear equation systems for the implicit equations. However, since iteration variables and explicit variables are program-specified within the torn block, and explicit variables can be expressed by implicit iteration variables within the block, and implicit equation iteration requires substituting information from the explicit equations within the block, more factors influence the implicit equation system. Matrix transformations are needed to represent these influences. This step addresses the technical problem of not being able to use simple implicit and explicit equation differentiation methods for algebraic rings, reducing the probability of approximating the difference quotient by backtracking. It replaces this with a combination of expression assignment and solving linear equation systems, improving computational efficiency and accuracy. The third differentiation strategy includes: (1) Divide the equations in the algebraic ring into sets of explicit equations. ( (a set of numbers) and implicit equations ( (each) records the set of dependent variables of the explicit equation. and the set of iteration variables (i.e., the set of dependent variables of the implicit equation). It is important to note that, unlike y=f(x) in the first differential strategy, here... The right-hand side of the equation represents only the result of rearranging terms, while the left-hand side represents terms that explicitly contain dependent variables. (2) Calculate the formal partial derivative matrix of the explicit equation with respect to the iterative variables. The formal partial derivative matrix of the implicit equation with respect to explicit variables The formal partial derivative matrix of the implicit equation with respect to the iteration variables ; (3) For each state variable Calculate the partial derivative matrix of the explicit equation. The partial derivative matrix of the implicit equation Create partial derivative nodes Store its number in an ordered vector ; (4) Construct an implicit intermediate representation data object, where the coefficient matrix The right-hand matrix (This operation can be viewed as using matrix column transformation to substitute the partial differential expression of the explicit assignment statement within the tear block into the implicit partial linear equation.) for The result after transformation for The transformed result), the unknown partial derivative node number vector (Contains) × (the numbering value of each partial differential node), and... The elements are stored in the dependent variable array of the selective differential tool. middle; (5) For each explicit equation in the set of explicit equations, construct a partial differential node for each state variable, and call the selective automatic differentiation tool with the current state variable as the independent variable, set the dependent variable array to yu, set the Boolean flag include_direct to false, and obtain the supplementary expression R1; (6) For each R1, find the Q4 elements that are the same in the equation and state variable combination and add them together. Divide by the coefficients of the dependent variables in the original equation. Combine the resulting expression with the partial differential nodes to form a differential equation, generate the corresponding explicit intermediate representation data object, and then... The elements are stored in the dependent variable array of the selective differential tool. middle.

[0051] Applying the third differential strategy of the present invention to the algebraic ring 1, for example... , , , , Calculate the intermediate partial derivative matrix: Using the selective automatic differentiation tool, with the second state variable... Using the independent variable as an example, calculate the elements of the intermediate selective partial derivative matrix: The members of the implicit data object can be obtained: the coefficient matrix. The right-hand matrix ,in , , All are 1x3 matrices, with the second element (out of a total of 3 elements) of array X storing the node. Number 25, iteration variable The information can be considered known, and deposit In the middle, the other two state variables also execute as follows: The general operation results in the following implicit data object: type - IMPLICIT, number of state variables - 3, contents of array A, contents of array B, X = [24, 25, 26]. This implicit data object is the 7th element in the Uniform Sequential Container.

[0052] If for a single implicit equation rather than the implicit part in an algebraic ring, the second differential strategy only requires , Other matrices are not calculated.

[0053] With the second state variable Using the independent variable as an example, for explicit equation 7, call the selective automatic differentiation tool and set the dependent variable array as follows: (Right now Setting the boolean flag include_direct to false yields the supplementary expression R1= ,Will +R1 divided by the coefficient have Continuing to process the explicit equation (7) for the other two state variables, we get: After storing the three differential equations into an explicit data object (this explicit data object is the 8th element in a uniformly ordered container), It is also stored as a variable of known information. middle.

[0054] This step clarifies the mutual influence between explicit and implicit equations by differentiating their differentiation strategies and subdividing the explicit and implicit structures within the algebraic ring. It successfully removes the explicit parts from the linear equation system, reducing the number of calculations required to solve the linear equations, and improves the accuracy of the results by increasing the proportion of the analytical part. Explicit equations typically constitute the majority of the integral part of the controlled object model; this step ensures that differential evaluation only requires sequential assignment during runtime, effectively reducing the number of processor instructions. This application employs an optimal differentiation strategy that balances the amount of generated code and computational speed for different types of equations, overcoming the problem that the unified automatic differentiation method is unsuitable for algebraic rings and generates excessive redundant iterations in difference quotient approximation, thus achieving a reduction in memory usage.

[0055] Step S3: Store all explicit and implicit data objects generated in step S2 in a unified order container according to the topological order defined by the hierarchical block directed acyclic graph.

[0056] Specifically, in the preprocessing stage of the permanent magnet DC motor model simulation, the topology solution order is as follows: the explicit data object corresponding to the integral block equation (1-6), an implicit data object and an explicit data object corresponding to the algebraic ring (7-8), and finally the explicit data object corresponding to equation (9). The unified sequential container uses the vector data structure.

[0057] This step sorts the differential results, ensuring consistency with the input topological solution order. This allows the solver to synchronously calculate the values ​​of all partial differential nodes after sequentially calculating the values ​​of all variables at the current time step. This overcomes the problem that the order of explicit and implicit primitive equations in the algebraic ring is reversed with the order of partial differential node calculations, thus reducing redundant calculations.

[0058] In the simulation of the example controlled object, a permanent magnet DC motor model, the numerical Jacobian matrices for the first four time steps obtained using this invention are as follows: The commercial software Dymola uses the difference quotient approximation method to obtain the numerical Jacobian matrix of the same model at the same time: Upon comparison, for all time steps, the present invention is consistent with the difference quotient approximation Jacobian matrix, and the preprocessing of the present invention does not cause errors in the simulation materials.

[0059] This invention, as a key component of the simulation solver used in DAE preprocessing, shows that the simulation results integrated with the CVode integrator have an error within 1e-10 compared to those obtained from the commercial software Dymola. Through the processing of the algebraic loop in this invention, for each state variable at each time step, the Newton-Raphson iteration of the 2×2 matrix equation system using the difference quotient approximation method is changed to the solution of a 1×1 linear equation system. Another equation that would have required iterative solution is transformed into a single assignment, reducing redundant computation.

[0060] As can be seen from the above embodiments, this application employs an optimal differentiation strategy that balances the amount of generated code and computation speed for different types of equations. This overcomes the problem that the unified automatic differentiation method is not suitable for algebraic rings and generates too many redundant iterations in difference quotient approximation, thus achieving the effect of reducing memory usage. Specifically: for explicit blocks, constructing assignment-form differential equations overcomes the problem of large code generation by passing computation graphs, thereby reducing memory usage and the number of computation instructions. For implicit blocks, constructing linear equation systems and eliminating iterative operations of explicit variables through matrix transformations for algebraic rings overcomes the problems of difficult symbolic expansion of implicit equations or low accuracy of difference quotient approximation, thereby improving simulation accuracy.

[0061] All generated explicit and implicit data objects are stored in the same sequential container according to the topological order defined by the hierarchical and block-based directed acyclic graph. This overcomes the performance bottleneck that the runtime cannot obtain all node values ​​at once and requires multiple rounds of assignment calculations. It enables the processor to read sequentially and evaluate directly, achieving a significant improvement in cache hit rate and instruction pipeline efficiency.

[0062] This invention also provides a simulation solver for an industrial control system, comprising the classification automatic differentiation device described above.

[0063] Accordingly, this application also provides an electronic device, comprising: one or more processors; a memory for storing one or more programs; and when the one or more programs are executed by the one or more processors, causing the one or more processors to implement a classification automatic differentiation method as described above.

[0064] Accordingly, this application also provides a computer-readable storage medium having computer instructions stored thereon, which, when executed by a processor, implement the classification automatic differentiation method described above.

[0065] Other embodiments of this application will readily occur to those skilled in the art upon consideration of the specification and practice of the disclosure herein. This application is intended to cover any variations, uses, or adaptations of this application that follow the general principles of this application and include common knowledge or customary techniques in the art not disclosed herein. The specification and embodiments are to be considered exemplary only.

[0066] It should be understood that this application is not limited to the precise structure described above and shown in the accompanying drawings, and various modifications and changes can be made without departing from its scope.

Claims

1. An automatic differentiation method for classification, characterized in that, Applications in industrial control systems, including: Step S1: Obtain the hierarchical block directed acyclic graph formed by compiling and dividing the physical model of the controlled object; Step S2: Traverse the hierarchical block-based directed acyclic graph, and execute the corresponding differentiation strategy according to the type of the equation block currently traversed: S21: If the current block is of type explicit block, then execute the first differential strategy to generate an explicit data object; S22: If the current block is of type implicit block, then execute the second differential strategy to generate an implicit data object; S23: If the current block is of type algebraic ring, then execute the third differential strategy to generate an implicit data object and an explicit data object; Step S3: Store all explicit and implicit data objects generated in step S2 in a unified order container according to the topological order defined by the hierarchical block directed acyclic graph.

2. The method according to claim 1, characterized in that, When executing the first, second, and third differentiation strategies, a selective automatic differentiation tool is invoked to perform differentiation calculations; the selective automatic differentiation tool is configured as follows: The input includes the differential expression E, the independent variable x, and the set of dependent variables. The Boolean flag `include_direct` is taken as input, and the partial differential expression `R` is output; wherein, the set of dependent variables... The elements in the set are the set of dependent variables contained in the equation block that has completed the differential calculation before the current block, and do not contain state variables.

3. The method according to claim 2, characterized in that, The selective automatic differentiation tool calculates the partial derivative expression R in the following way: If the boolean flag include_direct is true, then the initialization result is... ,in, This means ignoring other variables in E that are related to x, only taking the partial derivative of x with respect to terms that explicitly contain x, otherwise initializing the result. When the Boolean flag include_direct is false, the result has no physical meaning and is only used as an intermediate mathematical supplement. Traverse the set of dependent variables For each dependent variable d in the equation, calculate And construct implicit partial derivative nodes. ; Will and Multiplication and accumulation added to ; Return the accumulated result: The expression for the partial differential result is essentially a modification of the formal partial derivative into the actual mathematical partial derivative.

4. The method according to claim 2, characterized in that, Each time an explicit or implicit block completes a differential calculation and generates a corresponding data object, the dependent variables corresponding to that equation block are added to the dependent variable set. For blocks of algebraic ring type, their implicit and explicit parts are treated as an implicit block and an explicit block, respectively. After the implicit data object corresponding to the implicit part is generated, the dependent variables of the implicit part are added to the dependent variable set. Then, the explicit differential calculation is performed.

5. The method according to claim 1, characterized in that, The specific construction methods of the data object include: Define a base class to store common information about all types of equation blocks, including explicit / implicit enumeration types and the corresponding number of state variables n; Define a derived data class for the differential results of the explicit part of an explicit equation or an algebraic ring. Store the number of equations r in the original equation block and r*n equations in assignment form. The left side of the equation is the partial differential node as an unknown, and the right side is the symbolic expression of the differential result. Define a derived data class for the differential results of the implicit part in an implicit equation or algebraic ring, storing the coefficient matrix array A, the right-hand matrix array B, and the unknown partial derivative node number vector X; Create a uniformly ordered container to store all created data objects.

6. The method according to claim 1, characterized in that, The first differential strategy specifically includes: Rewrite the explicit equation into an assignment form, where the independent variable of the equation is a vector of state variables. For each state variable, construct partial differential nodes; The selective automatic differentiation tool is invoked to calculate the partial differential expression of the right-hand side of the assigned form equation, and then combined with the partial differential node to generate the differential equation of the assigned form equation, which is stored in the explicit intermediate representation data object. Add the dependent variable y of the explicit block to the dependent variable array D of the selective automatic differentiation tool.

7. The method according to claim 1, characterized in that, The second differential strategy specifically includes: The implicit equation is rearranged to obtain the residual expression, where the dependent variable is the dependent variable and the independent variable is the state variable. For each state variable, construct partial differential nodes and store their numbers in a vector; Calculate the coefficient matrix A and the right-hand matrix B based on the residual expression; Based on the coefficient matrix, right-hand side matrix, and vector, construct a system of linear equations, and then... Store the implicit intermediate representation data object; Add the dependency variables of the implicit block to the dependent variable array D of the selective automatic differentiation tool.

8. The method according to claim 1, characterized in that, The third differential strategy specifically includes: The equations in the algebraic ring are divided into a set of explicit equations and a set of implicit equations. The set of dependent variables for the explicit equations, ys, and the set of dependent variables for the implicit equations, yu, are recorded. This differs from y=f(x) in the first differential strategy. The right-hand side of the equation represents the result of only moving terms, while the left-hand side represents terms that explicitly contain dependent variables. Calculate the formal partial derivative matrix Q1 of the explicit equation with respect to the iteration variables, the formal partial derivative matrix Q2 of the implicit equation with respect to the explicit variables, and the formal partial derivative matrix Q3 of the implicit equation with respect to the iteration variables; For each state variable, calculate the partial derivative matrix Q4 of the explicit equation and the partial derivative matrix Q5 of the implicit equation; Based on the set of dependent variables and state variables of the implicit equation, create partial derivative nodes and store their numbers in an ordered vector X; Based on the partial derivative matrix, partial derivative matrix and ordered vector shown, construct an implicit intermediate representation data object, where the coefficient matrix A = Q3 + Q2 Q1, the right-hand matrix B = -Q5 - Q2 Q4, and the unknown partial derivative node numbering vector is the ordered vector X. Add the elements from the set of dependent variables yu of the implicit equation to the dependent variable array of the selective automatic differentiation tool. middle; For each explicit equation in the set of explicit equations, for each state variable, construct a partial differential node, and call the selective automatic differentiation tool with the current state variable as the independent variable, set the dependent variable array to yu, set the Boolean flag include_direct to false, and obtain the supplementary expression R1. For each R1, find the Q4 elements that are the same in the combination of equation and state variables and add them together. Divide by the coefficients of the dependent variables in the original equation. The resulting expression is combined with the partial differential nodes to form a differential equation and generate the corresponding explicit intermediate representation data object. Dependencies in the explicit part Add the dependent variable array to the selective automatic differentiation tool middle.

9. The method according to any one of claims 1 to 8, characterized in that, In the process of constructing the partial derivative node, a node management module performs content-based hash comparison and number allocation to achieve node reuse for the same partial derivative expression.

10. A simulation solver for industrial control systems, characterized in that, It includes the automatic differentiation device for classification as described in claim 11.

11. An electronic device, characterized in that, include: One or more processors; Memory, used to store one or more programs; When the one or more programs are executed by the one or more processors, the one or more processors implement the method as described in any one of claims 1-7.

12. A computer-readable storage medium having a computer program stored thereon, characterized in that, When the computer program is executed by a processor, it implements the method as described in any one of claims 1 to 9.