A method and system for generating and verifying Modelica compilation errors based on large models

By extracting the structured semantic feature objects of the Modelica compiler and using a large language model to generate and verify repair solutions, the problem of invalid repair solutions in Modelica compiler diagnostic technology is solved, improving the accuracy and efficiency of the compiler and enhancing the ease of use of the tool.

CN122672778BActive Publication Date: 2026-11-17武汉鼎元同立科技有限公司
View PDF 2 Cites 0 Cited by

Patent Information

Application Number
CN202611165024.1
Authority / Receiving Office
CN · China
Patent Type
Patents(China)
Current Assignee / Owner
Filing Date
2026-08-03
Publication Date
2026-11-17
Estimated Expiration
2046-08-03

AI Technical Summary

Technical Problem

Existing Modelica compiler diagnostic techniques struggle to accurately identify and fix compilation errors, especially since they cannot understand Modelica's unique compilation context and internal semantic processing information, often resulting in ineffective repair solutions.

Method used

By acquiring compilation diagnostic data from the Modelica compiler and source physical model context information, structured semantic feature objects are extracted. Rules are retrieved from the compilation knowledge base using a large language model to generate repair candidate solutions. The model is then checked and verified in an independent verification environment, and finally, the target repair solution that passes the verification is output.

Benefits of technology

It improves the accuracy of error localization in the Modelica compiler, reduces invalid fixes, shortens the model debugging cycle, enhances the ease of use of the tool, and provides a repeatable knowledge accumulation framework.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN122672778B_ABST
    Figure CN122672778B_ABST
Patent Text Reader

Abstract

This invention relates to a method and system for generating and verifying Modelica compiler error repair based on a large model. The method includes: acquiring compilation diagnostic data from the Modelica compiler and corresponding source physical model context information; extracting structured semantic feature objects of the compiler's intermediate states from the compilation diagnostic data and source physical model context information; retrieving associated compilation rules from a compiler knowledge base based on the structured semantic feature objects and generating repair constraints; generating at least one candidate repair scheme using a large language model under the constraints of the repair constraints; and, in an independent verification environment, calling the compiler's verification engine to perform model checking and verification on the candidate repair schemes, and outputting the target repair scheme that passes the verification. This invention improves the automation, adaptability, and reliability of the repair process by combining a large model with compiler checks.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] This invention belongs to the field of large model and compiler technology, specifically relating to a method and system for generating and verifying Modelica compilation errors based on a large model. Background Technology

[0002] Modelica is an equation-based modeling language for multi-domain physical systems. Its compilation process differs from that of ordinary programming languages. The Modelica compiler must handle issues such as component variants, redeclarations, linking mechanisms, model flattening, equation analysis, and state variable selection.

[0003] Translation errors can be triggered by equation balance issues, the propagation of variant redeclarations, and equations generated by join mechanisms. Therefore, while diagnostic messages can accurately describe the error phenomenon, they sometimes fail to directly reveal the root cause perceived by engineers. For example, a connector error might stem from a variant modifying the dimensional information of a nested component, while a redeclaration error might originate from constraint types several levels beyond inheritance. Equation imbalance issues require users to investigate the equation relationships between several equations and variables.

[0004] Existing compiler diagnostics typically output static messages and source code locations. While general large language model code repair techniques can generate suggested repair text, they usually treat the input as plain text code without understanding Modelica's specific semantic structure and compilation context. Such techniques may generate seemingly reasonable but ineffective repair solutions because they fail to access Modelica-specific internal semantic processing information, such as the compiler-generated connection equation system, the propagation path of variants, and the redeclaration replacement process.

[0005] Therefore, a technical mechanism is needed to convert Modelica compilation errors into structured semantic information, retrieve compilation knowledge related to the errors, generate candidate solutions for repair under semantic constraints, verify the candidate solutions through the Modelica checker, and then recommend a repair solution. Summary of the Invention

[0006] To address the problems raised in the background art, a first aspect of this invention provides a method for generating and verifying Modelica compilation error repair based on a large model, comprising: acquiring compilation diagnostic data of the Modelica compiler and corresponding source physical model context information; extracting structured semantic feature objects of the compiler intermediate state from the compilation diagnostic data and source physical model context information; retrieving associated compilation rules from a compilation knowledge base based on the structured semantic feature objects and generating repair constraints; generating at least one candidate repair scheme using a large language model under the constraints of the repair constraints; and, in an independent verification environment, calling the compiler's verification engine to perform model checking and verification on the candidate repair scheme and outputting the target repair scheme that passes the verification.

[0007] In some embodiments of the present invention, the structured semantic feature object includes at least one of the following features: an abstract syntax tree feature representing component and type declaration nodes and equation nodes; a class inheritance graph feature representing derivation relationships, inherited components and equations; a variant propagation chain feature representing parameter variant sources, target components, effective binding and overriding relationships; a redeclaration relationship feature representing original declarations, constraint types, replacement classes and compatibility conditions; a connection graph feature representing potential variables, flow variables, generated association equations and connecting endpoints; and an equation dependency graph feature representing the dependencies between flattened equations and variables and the balance check state.

[0008] In some embodiments of the present invention, generating repair constraints includes: deriving a search key from the structured semantic feature object; querying the compilation knowledge base using the search key to obtain at least one of language rules, library constraints, repair templates, or historical verification cases; and constructing constraints that define the repair scope and limitations based on the search results and the structured semantic feature object.

[0009] Furthermore, the constraint conditions that define the scope and limitations of the repair based on the retrieval results and the structured semantic feature object include: based on the retrieval results, limiting the modifiable model nodes, connection edges, declaration statements, redeclaration statements, parameter bindings or equation contexts, and generating at least one of the following: modified code snippets, root cause explanations, and confidence information.

[0010] In some embodiments of the present invention, the step of calling the compiler's verification engine to perform model checking and verification of the candidate repair scheme in an independent verification environment includes: applying the candidate repair scheme to a temporary copy of the model; performing model checks including syntax checking, semantic checking, and model flattening; if the verification fails, converting the verification error into structured failure feedback information and inputting the failure feedback information into the large language model to drive the large language model to regenerate the candidate repair scheme after adjustment until the verification passes or a preset number of iterations is reached.

[0011] In some embodiments of the present invention, before outputting the verified target repair solution, the method further includes: when there are multiple verified candidate repair solutions, comprehensively ranking the valid candidate repair solutions based on modification scope, semantic safety, historical success rate, and consistency with modeling intent, so as to determine the target repair solution.

[0012] A second aspect of the present invention provides a Modelica compiler error repair generation and verification system based on a large model, comprising: an acquisition module for acquiring compilation diagnostic data of the Modelica compiler and corresponding source physical model context information; an extraction module for extracting structured semantic feature objects of the compiler intermediate state from the compilation diagnostic data and source physical model context information; a retrieval module for retrieving associated compilation rules from a compiler knowledge base based on the structured semantic feature objects and generating repair constraints; a generation module for generating at least one candidate repair scheme using a large language model under the constraints of the repair constraints; and a verification module for calling the compiler's verification engine in an independent verification environment to perform model checking verification on the candidate repair scheme and output the target repair scheme that passes the verification.

[0013] A third aspect of the present invention provides an electronic device comprising: one or more processors; and a storage device for storing one or more programs, wherein when the one or more programs are executed by the one or more processors, the one or more processors implement the Modelica compilation error repair generation and verification method based on a large model provided in the first aspect of the present invention.

[0014] In a fourth aspect, the present invention provides a computer-readable medium having a computer program stored thereon, wherein the computer program, when executed by a processor, implements the Modelica compilation error repair generation and verification method based on a large model provided in the first aspect of the present invention.

[0015] The beneficial effects of this invention are: This invention improves the error localization capabilities of the Modelica compiler by utilizing semantic dependency information rather than relying solely on diagnostic text. By combining large language model generation with compiler knowledge retrieval and automatic verification, it reduces invalid fixes generated by artificial intelligence. Furthermore, by automatically generating and verifying candidate fixes, it shortens the model debugging cycle.

[0016] Modelica improves usability by interpreting errors caused by inheritance, variant, redeclaration, and linking semantics at the compilation semantic level. It reduces repeated compilation failure attempts by sorting fixes based on validation results and historical success patterns. A repeatable knowledge accumulation framework is provided, as validated fixes can be stored as structured knowledge to address similar errors in the future. Attached Figure Description

[0017] Figure 1 This is a schematic diagram of the basic process of Modelica compilation error repair generation and verification method based on a large model in some embodiments of the present invention; Figure 2 This is a schematic diagram of the architecture of the Modelica compilation error repair generation and verification method based on a large model in some embodiments of the present invention; Figure 3 This is a schematic diagram illustrating the specific process of the Modelica compilation error repair generation and verification method based on a large model in some embodiments of the present invention; Figure 4 This is a schematic diagram illustrating the construction principle of specific semantic features of Modelica in some embodiments of the present invention; Figure 5 This is a schematic diagram of a verification-oriented AI repair feedback loop process in some embodiments of the present invention; Figure 6 This is a schematic diagram of the structure of a Modelica compilation error repair generation and verification system based on a large model in some embodiments of the present invention; Figure 7 This is a schematic diagram of the structure of an electronic device in some embodiments of the present invention. Detailed Implementation

[0018] The principles and features of the present invention are described below with reference to the accompanying drawings. The examples given are only for explaining the present invention and are not intended to limit the scope of the present invention.

[0019] Example 1 refer to Figure 1 and Figure 3In a first aspect of the present invention, a method for generating and verifying Modelica compilation error repair based on a large model is provided, comprising: S100. obtaining compilation diagnostic data of the Modelica compiler and corresponding source physical model context information; S200. extracting structured semantic feature objects of the compiler intermediate state from the compilation diagnostic data and source physical model context information; S300. retrieving associated compilation rules from the compilation knowledge base based on the structured semantic feature objects, and generating repair constraints; S400. generating at least one candidate repair scheme under the constraints of the repair constraints using a large language model; S500. in an independent verification environment, calling the compiler's verification engine to perform model checking verification on the candidate repair scheme, and outputting the target repair scheme that passes the verification.

[0020] It should be noted that this disclosure uses the Modelica compiler from MWORKS, and this does not affect the application of the methods disclosed herein to other Modelica compilers. In normal compiler implementations, only textual errors can be obtained, and necessary error information can be provided (designed specifically for manual troubleshooting), requiring manual problem localization. This method constructs a compiler semantic object, which can additionally obtain Modelica compiler-specific intermediate results, including AST records, instance tree records, variant propagation records, redeclaration constraint records, type checking records, join set records, generated join equation records, expanded variable / equation records, balance checking records, and diagnostic records. (Except for the AST, all are Modelica-specific semantic intermediate results and have non-causal, declarative characteristics.) Their format may be tables, graphs, JSON records, or equivalent structured data.

[0021] For Modelica's declarative, non-causal semantics, this improvement is most significant for errors where the compiler error location is not in the original text of the model, such as join set unions, compiler-generated join equations, redeclaration constraints of inheritance, and variants of propagation merge. This method constructs a Modelica compiler semantic object that can provide compiler implementation information that LLM cannot determine from the source text.

[0022] This application does not simply improve the inference ability of LLM, but rather provides more accurate input prompts to large models through semantic objects generated by the compiler, avoiding frequent inference and iteration, reducing overall token consumption, and improving the efficiency and success rate of prompt repair.

[0023] In step S100 of some embodiments of the present invention, the compilation diagnostic data of the Modelica compiler and the corresponding source physical model context information are obtained; Specifically, when the Modelica compiler encounters an error during model checking or compilation, the system collects diagnostic information, source location, compilation stage, and compilation context. It then analyzes the corresponding model fragment and extracts Modelica semantic information related to the error. For linker mismatches, the extracted information may include linker statements, linker class definitions, stream variables, potential variables, inherited linker elements, and type changes caused by variants.

[0024] refer to Figure 4 In step S200 of some embodiments of the present invention, the structured semantic feature object of the compiler intermediate state is extracted from the compilation diagnostic data and the source physical model context information; Specifically, errors are mapped to a structured category. This category may include unresolved names, type mismatches, illegal variants, redeclaration conflicts, violations of replaceable component constraints, connector incompatibility, missing binding equations, over-constrained or under-constrained connection structures, or invalid references to conditional components.

[0025] The structured semantic feature object includes at least one of the following features: an abstract syntax tree feature representing component and type declaration nodes and equation nodes; a class inheritance graph feature representing derivation relationships, inherited components and equations; a variant propagation chain feature representing parameter variant sources, target components, effective binding and overriding relationships; a redeclaration relationship feature representing original declarations, constraint types, replacement classes and compatibility conditions; a connection graph feature representing potential variables, flow variables, generated association equations and connecting endpoints; and an equation dependency graph feature representing the dependencies between flattened equations and variables and the balance check state.

[0026] Specifically, a structured semantic representation is constructed based on Modelica compilation information. This representation may include: 1. Features at the AST (Abstract Syntax Tree) level, including declaration nodes, equation nodes, variant nodes, and import or inheritance clauses.

[0027] 2. Class inheritance diagram, including inherited components, inheritance equations, and valid declarations.

[0028] 3. The variant propagation chain, including the original variant location, target component, effective binding, and overriding relationship.

[0029] 4. Redeclare and substitutability relationships, including constraint types, substitute classes, and compatibility conditions.

[0030] 5. Connectors and connection graphs, including connector classes, flow variables, potential variables, causal correlation attributes, and connection endpoints.

[0031] 6. Equation dependency graph, including error-related variables and equations generated from join clauses.

[0032] The semantic representation described above enables large language models to process compiler data. It also enables the knowledge retrieval module to select precise rules and templates, rather than relying on general text similarity.

[0033] The listed semantic features can be used to form a Modelica semantic representation object. This representation is not limited to the storage format of diagnostic messages. It can be implemented as a table, graph, JSON record, or equivalent structured data. The semantic representation object contains model source text mapping fields and compiler error stage fields, thereby linking the source declarations to compiler stage objects and diagnostic objects of the original model.

[0034] The Abstract Syntax Tree (AST) level features provide component and type declaration nodes, equation nodes, and import or extend clauses, offering structured information about the original model text. The inheritance graph, with nodes representing base classes and derived classes, and edges representing derivation relationships indicated by extend clauses, defines the derivation relationships in the model and helps identify inherited components and equations within instances. This information can be constructed from the Modelica compiler's syntactic and semantic parsing and inheritance analysis. Together, the AST and inheritance graph provide the model context needed for problem localization.

[0035] The variant propagation chain can provide the variant source, target instance, propagation process, and merging coverage process. Its nodes are the various variant AST elements that appear in the model, and the edges are the variant coverage relationships. These fields can be constructed during the application of variants and instantiation, and can be used to determine whether the fix should modify the upper-level variant or the lower-level variant.

[0036] Redeclaration and substitutability relationships provide the original substitutability declaration, constraint type, target type of the replacement, and compatibility check results. These fields are constructed during redeclaration compatibility checks and instantiation, and, in conjunction with the inheritance graph and variant propagation chain, can be used to restrict candidate fixes to compatible replacement classes and components.

[0037] Connectors and connection graphs can be represented as connection set records. A connection set record may include a connection set ID, connector endpoints, connector type, potential variables, flow variables, convection variables, generated potential variable equations, and generated flow variable conservation equations. These fields can be constructed during connection set generation and can be used to detect equation errors caused by the connection mechanism that cannot be directly located in the model source code.

[0038] An equation dependency graph can be represented as the dependencies between flattened equations and variables, and can additionally associate with process records from balance checks. These records may include flattened variables, instantiated equations, variable dependency edges, and the equilibrium state of the system of equations. These fields are derived during flattening and balance checks and can be used to determine the balance relationships when modifying the original model equations.

[0039] The intermediate semantics of these Modelica compilers can establish cross-stage mapping relationships during the compilation process through AST, ensuring bidirectional mapping between the underlying semantics and the model source code.

[0040] The semantic representation object can be further converted into retrieval and repair control information. This object contains retrieval keys, repair scope constraints, and prohibited operations. Retrieval keys are derived from fields from the compilation phase, such as join set ID, constraint type, variant propagation chain, generated equations, and equilibrium states. Repair scope constraints specify which raw text can be modified, such as variant sources, join topologies, and redeclaration types. Prohibited operations exclude changes to only the source code lines where the original error message appeared.

[0041] Understandably, large language models use search keys to query the compiler knowledge base and generate remediation candidates within the constraints of the remediation scope. The retrieved knowledge can include Modelica language rules, compiler rules, component library documentation, remediation templates, and historical remediation cases. Therefore, remediation generation is guided by semantic information derived from the compiler, not just diagnostic text.

[0042] In step S300 of some embodiments of the present invention, based on the structured semantic feature object, associated compilation rules are retrieved from the compilation knowledge base, and repair constraints are generated; Specifically, after classification, the system retrieves relevant knowledge from the compiler knowledge base. The retrieved content may include Modelica language rules, compiler diagnostic explanations, similar verified fixes, model library constraints, and fix templates. This retrieved knowledge is then combined with source code snippets and semantic feature representations to form the constraint input for the large language model.

[0043] The generation of repair constraints includes: deriving a search key from the structured semantic feature object; querying the compilation knowledge base using the search key to obtain at least one of language rules, library constraints, repair templates, or historical verification cases; and constructing constraints that define the repair scope and limitations based on the search results and the structured semantic feature object.

[0044] Furthermore, the constraint conditions that define the scope and limitations of the repair based on the retrieval results and the structured semantic feature object include: based on the retrieval results, limiting the modifiable model nodes, connection edges, declaration statements, redeclaration statements, parameter bindings or equation contexts, and generating at least one of the following: modified code snippets, root cause explanations, and confidence information.

[0045] In step S400 of some embodiments of the present invention, at least one candidate repair scheme is generated using a large language model under the constraints of the repair constraints. The large language model generates multiple fixes. For example, it might correct variant paths, change connector types, add missing redeclaration statements, adjust parameter bindings, replace incompatible components, or move equations to appropriate conditional contexts. Each candidate is applied to a temporary copy of the model for validation.

[0046] In step S500 of some embodiments of the present invention, the step of calling the compiler's verification engine to perform model checking verification on the candidate repair scheme in an independent verification environment includes: S501. Apply the candidate repair scheme to a temporary copy of the model; S502. Perform model checks, including syntax checks, semantic checks, and model flattening; S503. If the verification fails, the verification error is converted into structured failure feedback information, and the failure feedback information is input into the large language model to drive the large language model to regenerate candidate repair solutions after adjustment, until the verification passes or the preset number of iterations is reached.

[0047] Specifically, the Modelica checker is invoked to verify syntax, name resolution, type consistency, connector compatibility, variant validity, redeclaration constraints, and flattening feasibility. If verification fails, the verification error is converted into structured feedback and returned to the large language model for one or more rounds of improvement.

[0048] refer to Figure 5 In some embodiments of the present invention, before outputting the verified target repair solution, the method further includes: when there are multiple verified candidate repair solutions, comprehensively ranking the valid candidate repair solutions based on modification scope, semantic safety, historical success rate, and consistency with modeling intent, so as to determine the target repair solution.

[0049] Specifically, valid candidate solutions are ranked and output. The results may include the recommended fix, alternative fixes, the original root cause explanation, the validation status, and an explanation of why the selected fix conforms to Modelica semantics.

[0050] It's understandable that a verification round might involve editing the model and then re-invoking the compiler's parsing, instantiation, variant merging, redeclaration checks, type checks, linker set generation, flattening, and balance checks. If a round fails, a new round of compilation semantic feature extraction (the specific content depends on the error phenomenon) will begin, thereby generating a new round of repair solutions.

[0051] In one specific embodiment, a compatibility error exists between the non-causal connection set and the balance check connector: Modelica's connection mechanism automatically processes connect-related semantic equations and generates actual connection equations according to the law of conservation of energy. If user-defined connection relationships are unreasonable, the compiler may report an equation balance error for the entire system after the connection set is generated or flattened. The reported erroneous equations cannot be directly found in the original model.

[0052] Example source model: connector Pin Real v; flow Real i; end Pin; model Ground Pin p; equation pv = 0; end Ground model Resistor Pin p; Pin n; parameter Real R = 1; equation pv - nv = R pi; pi + ni = 0; end Resistor; model VoltageSource Pin p; Pin n; parameter Real V = 1; equation pv - nv = V; pi + ni = 0; end VoltageSource; model RedundantGroundCase VoltageSource src(V = 1); Resistor r(R = 1); Ground g1; Ground g2; equation connect(src.p, rp); connect(src.n, rn); connect(src.n, g1.p); connect(rn, g2.p); end RedundantGroundCase; When translating the RedundantGroundCase type of this model, the standard compiler error message is "There is redundancy in the equations of the Real type in the model. There is one redundant equation in the following set:" src.nv=g1.pv; src.nv=g2.pv; g2.pv=0; g1.pv=0;”

[0053] At this point, directly encapsulating the error message into prompts and providing them to the large model may not yield effective modification solutions, because the model does not contain the definitions of these equations. The semantic feature objects constructed during the compiler phase are as follows: Compiler diagnostics: Error code = OVERDETERMINED_SYSTEM; Failure phase = connection equation generation and balance check; Report source = all connect equations associated with the connect set; Affected object = connection set #CS1.

[0054] Example diagnostic text: "Redundancy exists after the connection equations are generated; the affected connection set CS1 is not balanced." This diagnostic requires adjusting the model's connect relationships.

[0055] Semantic objects: connection graph and connection set records.

[0056] Semantic object identifier = join set #2; Connect the nodes in the graph: {src.p, src.n, rp, rn, g1.p, g2.p}; Connect the edges in the graph: {edge#1:connect(src.p,rp),edge#2:connect(src.n,rn),edge#3:connect(src.n,g1.p),edge#4:connect(rn,g2.p)}; Connection graph. Connected components = {connectionSet#1={src.p,rp},connectionSet#2={src.n,rn,g1.p,g2.p}}; Connection Graph. Constraint Equations (connectionSet#2) = {g1.pv = 0 from Ground g1, g2.pv = 0 from Ground g2}; Potential variables = {src.nv,rnv,g1.pv,g2.pv}; Stream variable = {src.ni, rni, g1.pi, g2.pi}; The generated potential variable equation is: {src.nv=rnv,src.nv=g1.pv,src.nv=g2.pv}; The generated flow variable equation is: {src.n.i + rni + g1.p.i + g2.pi = 0}; Grounding equation = {g1.pv=0, g2.pv=0}; Knowledge retrieval fields: connection set, connector endpoint, connector class, flow / potential variable, and equilibrium state.

[0057] The retrieved knowledge includes: Modelica potential / flow connection rules, electrical reference node modeling rules, library documentation for grounding components, and historical repair records of redundant reference constraints in non-causal networks.

[0058] Repairing constraint objects: Allows the removal or disabling of a redundant ground reference, replacement of a ground with a measurement / reference adapter if separate observation is intended, or reconstruction of the topology so that different connections are not merged into a single connection set; prohibits changing resistor / source parameters as an alternative to topology repair; requires generation of connection sets, flattening, and balance checks after repair.

[0059] Candidate Generation and Validation: Upon receiving connection set #2, the large language model will be guided to generate topology-level remediation schemes based on the merged connection graph. The generated candidate schemes may include retaining a single grounding component on the loop path.

[0060] In one specific implementation, regarding redeclaration or replaceable component errors: Modelica models have a redeclaration mechanism that allows a type defined in the base class to be declared as a replaceable type, and then redeclared as a compatible new type in the derived class. However, due to complex derivation relationships and redeclaration definitions, semantic errors in the model may mislead modifications to the larger model. This issue can be resolved through enhanced Modelica semantic representation objects.

[0061] Example source model: Partial package PartialMedium type AbsolutePressure = Real(unit="Pa"); type MassFlowRate = Real(unit="kg / s"); Replaceable function density input AbsolutePressure p; output Real d; end density end PartialMedium; package AirMedium extends PartialMedium; end AirMedium; package InvalidMedium type Temperature = Real(unit="K"); end InvalidMedium; connector FluidPort replaceable package Medium = AirMedium constrained by PartialMedium; Medium.AbsolutePressure p; flow Medium.MassFlowRate m_flow; end FluidPort; model PipeBase replaceable package Medium = AirMedium constrained by PartialMedium; FluidPort port(redeclare package Medium = Medium); end PipeBase model FaultyPipe extends PipeBase(redeclare package Medium = InvalidMedium); end FaultyPipe; When translating the FaultyPipe type of this model, the usual compiler error message is "The component type Medium.AbsolutePressure cannot be found. The full name of the component is port.p."

[0062] At this point, directly encapsulating the error message into a prompt and providing it to the larger model might result in a solution that adds the missing type definition, rather than indicating an underlying type redeclaration error.

[0063] The semantic feature objects constructed during the compiler phase are as follows: Compiler diagnostic information: Error code = INVALID_PACKAGE_REDECLARE; Failure phase = redeclareCompatibilityChecking; Report source = extendsPipeBase(...); Affected object = redeclareRecord#R2.

[0064] Semantic object: A redeclared constraint record.

[0065] Semantic object identifier = redeclareRecord#R2; Original declaration = PipeBase.Medium; Constraint type = PartialMedium; Replacement package = InvalidMedium; Inheritance usage location = FluidPort.port; Valid connector members = {port.p, port.m_flow}; Missing member = {AbsolutePressure, MassFlowRate, density}; Compatibility result = Failed.

[0066] Error Explanation: The failure was due to package incompatibility, not a type lookup error. The semantic object that failed was redeclareRecord#R2, the stage that failed was redeclareCompatibilityChecking, and InvalidMedium was missing a member required by PartialMedium before parameter binding or equation balancing evaluation.

[0067] Knowledge retrieval fields: constraint type, replacement package, inheritance usage location, missing members, and valid connector members.

[0068] The retrieved knowledge includes: redeclaration rules, required PartialMedium interfaces, media compatibility records, component documentation, and adapter templates.

[0069] Fix constraint objects: allow selection of packages that satisfy PartialMedium or improve the InvalidMedium class; Deleting constraint types is prohibited; irrelevant changes to connector members are prohibited.

[0070] Candidate Generation and Validation: Upon receiving the re-declared semantic features, the large language model generates candidate solutions that satisfy the "PartialMedium" condition. The generated candidate solutions may include selecting an existing compatible media package or completing the "InvalidMedium" type definition with missing necessary members. Each candidate solution undergoes a compatibility check again. If multiple candidate solutions pass validation, the large model can provide the user with explanations regarding interface compatibility and possible modifications.

[0071] In one specific implementation, for variant propagation errors: a top-level parameter variant changes a parameter used by a nested component, and when its value is invalid, the resulting error occurs during the instantiation of the lower-level component behavior. This example illustrates a situation where the reported source line is not the target of the fix.

[0072] Example source model: connector Pin Real v; flow Real i; end Pin; model Sensor parameter Integer n = 1; Pin p[n]; end Sensor model SensorBox parameter Integer m = 1; Sensor sensor(n = m); Pin externalPin[1]; equation connect(sensor.p[1], externalPin[1]); end SensorBox. model FaultyModifierCase SensorBox box(m = 0); end FaultyModifierCase; Compiler diagnostics: Error code is ARRAY_INDEX_ERRO; Failure phase: variant merging, expression instantiation; The report source is connect(sensor.p[1], externalPin[1]); Semantic object: A variant propagation merge instance record.

[0073] Semantic object identifier = variant propagation record #M3; Variance source = box(m=0); target instance = box.sensor; Effective binding variant = box.m = 0; The propagation chain is: box(m=0)->sensor(n=m)->sensor.n->sensor.p[n]; Invalid endpoint = sensor.p[1], because the size of the valid connection array is zero; Knowledge retrieval fields: variant source, valid binding, propagation path, variant merge instance, invalid endpoint.

[0074] The retrieved information includes: Modelica language variant mechanism and variant-related fixes.

[0075] Fix constraint objects: allow changes to top-level variant values; prevent sensor.p[1] from being changed to another index; Candidate Generation and Verification: Upon receiving "Variation Propagation Record #M3", the large language model will be guided to generate variant merging-related fixes. The generated candidate solutions may include setting the upper-level variant to a valid positive value consistent with the external pin.

[0076] Example 2 refer to Figure 6 In a second aspect, the present invention provides a Modelica compiler error repair generation and verification system 1 based on a large model, comprising: an acquisition module 11 for acquiring compilation diagnostic data of the Modelica compiler and corresponding source physical model context information; an extraction module 12 for extracting structured semantic feature objects of the compiler intermediate state from the compilation diagnostic data and source physical model context information; a retrieval module 13 for retrieving associated compilation rules from a compilation knowledge base based on the structured semantic feature objects and generating repair constraints; a generation module 14 for generating at least one candidate repair scheme using a large language model under the constraints of the repair constraints; and a verification module 15 for calling the compiler's verification engine in an independent verification environment to perform model checking verification on the candidate repair scheme and output the target repair scheme that passes the verification.

[0077] Furthermore, the generation module 14 includes: a derivation unit, used to derive a retrieval key from the structured semantic feature object; an acquisition unit, used to query the compilation knowledge base using the retrieval key to acquire at least one of language rules, library constraints, repair templates, or historical verification cases; and a construction unit, used to construct constraints that define the repair scope and limitations based on the retrieval results and the structured semantic feature object.

[0078] refer to Figure 2 In one specific embodiment of the present invention, it includes: an error acquisition module: collecting error codes, diagnostic texts, help documents, model error locations, failed compiler stages, involved components, and library version information, etc.

[0079] Modelica semantic feature extraction module: extracts model hierarchy, inherited elements, variant propagation links, redeclaration relationships, connector types, connected image segments, equation dependencies, parameter bindings, and conditional component states.

[0080] The structured error generation module converts raw diagnostic data and compiler semantic features into error categories, affected elements, dependency paths, and possible repair ideas.

[0081] Compilation knowledge base: Stores Modelica syntax rules, semantic rules, compiler diagnostic mappings, linker compatibility rules, repair templates, model library documentation, and verified historical repair cases.

[0082] Knowledge Retrieval Module: Retrieves relevant rules, examples, templates, and explanations based on structured semantic features. Large Language Model Repair Module: Generates candidate repair solutions based on the retrieved semantic constraints, and may output modified code snippets, root cause explanations, and confidence information.

[0083] Validation module: Apply candidate solutions in an independent workspace and perform necessary model checks such as syntax checking, semantic checking, and model flattening.

[0084] The sorting and output module sorts the effective candidate solutions based on the verification results, modification scope, semantic safety, historical success rate, and consistency with the user's modeling intent, and outputs the results.

[0085] Example 3 refer to Figure 7 In a third aspect, the present invention provides an electronic device comprising: one or more processors; and a storage device for storing one or more programs, wherein when the one or more programs are executed by the one or more processors, the one or more processors implement the Modelica compilation error repair generation and verification method based on a large model according to the first aspect of the present invention.

[0086] Electronic device 500 may include a processing unit (e.g., a central processing unit, a graphics processing unit, etc.) 501, which can perform various appropriate actions and processes according to a program stored in read-only memory (ROM) 502 or a program loaded from storage device 508 into random access memory (RAM) 503. The RAM 503 also stores various programs and data required for the operation of electronic device 500. The processing unit 501, ROM 502, and RAM 503 are interconnected via bus 504. An input / output (I / O) interface 505 is also connected to bus 504.

[0087] Typically, the following devices can be connected to I / O interface 505: input devices 506 including, for example, touchscreens, touchpads, keyboards, mice, cameras, microphones, accelerometers, gyroscopes, etc.; output devices 507 including, for example, liquid crystal displays (LCDs), speakers, vibrators, etc.; storage devices 508 including, for example, hard disks; and communication devices 509. Communication device 509 allows electronic device 500 to communicate wirelessly or wiredly with other devices to exchange data. Although Figure 7 An electronic device 500 with various devices is shown; however, it should be understood that it is not required to implement or possess all of the devices shown. More or fewer devices may be implemented or possessed alternatively. Figure 7 Each box shown can represent a device or multiple devices as needed.

[0088] Specifically, according to embodiments of this disclosure, the processes described above with reference to the flowcharts can be implemented as computer software programs. For example, embodiments of this disclosure include a computer program product comprising a computer program carried on a computer-readable medium, the computer program containing program code for performing the methods shown in the flowcharts. In such embodiments, the computer program can be downloaded and installed from a network via a communication device 509, or installed from a storage device 508, or installed from a ROM 502. When the computer program is executed by a processing device 501, it performs the functions defined in the methods of embodiments of this disclosure. It should be noted that the computer-readable medium described in embodiments of this disclosure can be a computer-readable signal medium or a computer-readable storage medium, or any combination thereof. A computer-readable storage medium can be, for example,—but not limited to—an electrical, magnetic, optical, electromagnetic, infrared, or semiconductor system, apparatus, or device, or any combination thereof. More specific examples of computer-readable storage media may include, but are not limited to: electrical connections having one or more wires, portable computer disks, hard disks, random access memory (RAM), read-only memory (ROM), erasable programmable read-only memory (EPROM or flash memory), optical fiber, portable compact disk read-only memory (CD-ROM), optical storage devices, magnetic storage devices, or any suitable combination thereof. In embodiments of this disclosure, a computer-readable storage medium may be any tangible medium containing or storing a program that can be used by or in connection with an instruction execution system, apparatus, or device. In embodiments of this disclosure, a computer-readable signal medium may include a data signal propagated in baseband or as part of a carrier wave, carrying computer-readable program code. Such propagated data signals may take various forms, including but not limited to electromagnetic signals, optical signals, or any suitable combination thereof. A computer-readable signal medium may also be any computer-readable medium other than a computer-readable storage medium, which can send, propagate, or transmit a program for use by or in connection with an instruction execution system, apparatus, or device. Program code contained on a computer-readable medium may be transmitted using any suitable medium, including but not limited to: wires, optical fibers, RF (radio frequency), etc., or any suitable combination thereof.

[0089] The aforementioned computer-readable medium may be included in the aforementioned electronic device; or it may exist independently and not assembled into the electronic device. The aforementioned computer-readable medium carries one or more computer programs, which, when executed by the electronic device, cause the electronic device to: Computer program code for performing the operations of embodiments of this disclosure can be written in one or more programming languages ​​or a combination thereof. Programming languages ​​include object-oriented programming languages—such as Java, Smalltalk, C++, and Python—and conventional procedural programming languages—such as the "C" language or similar programming languages. The program code can be executed entirely on the user's computer, partially on the user's computer, as a standalone software package, partially on the user's computer and partially on a remote computer, or entirely on a remote computer or server. In cases involving remote computers, the remote computer can be connected to the user's computer via any type of network—including a local area network (LAN) or a wide area network (WAN)—or can be connected to an external computer (e.g., via the Internet using an Internet service provider).

[0090] The flowcharts and block diagrams in the accompanying drawings illustrate the architecture, functionality, and operation of possible implementations of systems, methods, and computer program products according to various embodiments of this disclosure. In this regard, each block in a flowchart or block diagram may represent a module, segment, or portion of code containing one or more executable instructions for implementing a specified logical function. It should also be noted that in some alternative implementations, the functions indicated in the blocks may occur in a different order than those indicated in the drawings. For example, two consecutively indicated blocks may actually be executed substantially in parallel, and they may sometimes be executed in reverse order, depending on the functions involved. It should be noted that each block in the block diagrams and / or flowcharts, and combinations of blocks in the block diagrams and / or flowcharts, can be implemented using a dedicated hardware-based system that performs the specified function or operation, or using a combination of dedicated hardware and computer instructions.

[0091] The above description is only a preferred embodiment of the present invention and is not intended to limit the present invention. Any modifications, equivalent substitutions, improvements, etc., made within the spirit and principles of the present invention should be included within the protection scope of the present invention.

Claims

1. A method for generating and verifying Modelica compilation errors based on a large model, characterized in that, include: Obtain compilation diagnostic data from the Modelica compiler and the corresponding source physics model context information; Extract the structured semantic feature objects of the compiler intermediate state from the compilation diagnostic data and the source physical model context information; The structured semantic feature object includes at least one of the following features: an abstract syntax tree feature representing component and type declaration nodes and equation nodes; a class inheritance graph feature representing derivation relationships, inherited components and equations; a variant propagation chain feature representing parameter variant sources, target components, effective binding and overriding relationships; and a redeclaration relationship feature representing original declarations, constraint types, replacement classes and compatibility conditions. Characterize the potential variables, flow variables, generated correlation equations, and connection graph features of the endpoints; characterize the dependencies between the flattening equations and variables, and the equation dependency graph features of the equilibrium check state; Based on the structured semantic feature object, associated compilation rules are retrieved from the compilation knowledge base, and repair constraints are generated. The generation of repair constraints includes: deriving a search key from the structured semantic feature object; querying the compilation knowledge base using the search key to obtain at least one of language rules, library constraints, repair templates, or historical verification cases; and constructing constraints defining the repair scope and limitations based on the search results and the structured semantic feature object. The construction of constraints defining the repair scope and limitations based on the search results and the structured semantic feature object includes: limiting modifiable model nodes, connection edges, declaration statements, redeclaration statements, parameter bindings, or equation contexts based on the search results, and generating at least one of modified code snippets and root cause explanations. Using a large language model, at least one candidate repair scheme is generated under the constraints of the repair conditions; In an independent verification environment, the compiler's verification engine is invoked to perform model checks and verifications on the candidate repair schemes, and the target repair scheme that passes the verification is output. The model checks and verifications include: applying the candidate repair schemes to a temporary copy of the model; performing model checks including syntax checks, semantic checks, and model flattening; if the verification fails, the verification error is converted into structured failure feedback information, and the failure feedback information is input into the large language model to drive the large language model to regenerate the candidate repair schemes after adjustment, until the verification passes or the preset number of iterations is reached.

2. The method for generating and verifying Modelica compilation errors based on a large model according to claim 1, characterized in that, The output, prior to the verified target remediation solution, also includes: When multiple validated candidate repair solutions exist, the valid candidate repair solutions are comprehensively ranked based on modification scope, semantic safety, historical success rate, and consistency with modeling intent to determine the target repair solution.

3. A Modelica compilation error repair generation and verification system based on a large model, characterized in that, include: The acquisition module is used to obtain the compilation diagnostic data of the Modelica compiler and the corresponding source physical model context information; The extraction module is used to extract the structured semantic feature objects of the compiler intermediate state from the compilation diagnostic data and the source physical model context information; The structured semantic feature object includes at least one of the following features: an abstract syntax tree feature representing component and type declaration nodes and equation nodes; a class inheritance graph feature representing derivation relationships, inherited components and equations; a variant propagation chain feature representing parameter variant sources, target components, effective binding and overriding relationships; and a redeclaration relationship feature representing original declarations, constraint types, replacement classes and compatibility conditions. Characterize the potential variables, flow variables, generated correlation equations, and connection graph features of the endpoints; characterize the dependencies between the flattening equations and variables, and the equation dependency graph features of the equilibrium check state; The retrieval module is used to retrieve associated compilation rules from the compilation knowledge base based on the structured semantic feature object, and generate repair constraints. The generation of repair constraints includes: deriving a search key from the structured semantic feature object; querying the compilation knowledge base using the search key to obtain at least one of language rules, library constraints, repair templates, or historical verification cases; and constructing constraints defining the repair scope and limitations based on the search results and the structured semantic feature object. The construction of constraints defining the repair scope and limitations based on the search results and the structured semantic feature object includes: limiting modifiable model nodes, connection edges, declaration statements, redeclaration statements, parameter bindings, or equation contexts based on the search results, and generating at least one of modified code snippets and root cause explanations. A generation module is used to generate at least one candidate repair scheme under the constraints of the repair constraints, using a large language model. The verification module is used to call the compiler's verification engine in an independent verification environment to perform model checking and verification on the candidate repair schemes, and output the target repair scheme that passes the verification. The model checking and verification includes: applying the candidate repair schemes to a temporary copy of the model; performing model checks including syntax checks, semantic checks, and model flattening; if the verification fails, converting the verification error into structured failure feedback information and inputting the failure feedback information into the large language model to drive the large language model to regenerate the candidate repair schemes after adjustment, until the verification passes or a preset number of iterations is reached.

4. An electronic device, comprising: One or more processors; A storage device for storing one or more programs, which, when executed by one or more processors, cause the one or more processors to implement the Modelica compilation error repair generation and verification method based on a large model as described in any one of claims 1 to 2.

5. A computer-readable medium having a computer program stored thereon, wherein, When the computer program is executed by the processor, it implements the Modelica compilation error repair generation and verification method based on a large model as described in any one of claims 1 to 2.

Citation Information

Patent Citations

  • Code repairing method and device based on abstract syntax tree and large model

    CN121807356A

  • Simulation model code automatic repairing method and device based on deep learning and medium

    CN121858144A