A method and system for homomorphic transformation of functional model units based on a large language model
By adopting a homomorphic transformation method for functional model units based on a large language model, the problem of homomorphic transformation from SysML model to simulation model is solved, realizing semantic consistency between design model and simulation model and automated simulation, supporting multi-platform loading, and improving verification coverage and conclusion credibility.
Patent Information
- Application Number
- CN202611408824.1
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Filing Date
- 2026-09-10
- Publication Date
- 2026-11-17
AI Technical Summary
Homomorphic transformations from SysML models to simulation models suffer from digital discontinuity, making it difficult to verify consistency. Simulation results are hard to quickly pinpoint the cause of errors, and there is a lack of a unified mechanism for cross-platform model interoperability.
A homomorphic transformation method for functional model units based on a large language model is adopted. By constructing a model transformation rule base, homomorphic intermediate representations are generated, and the optimal LoRA expert is automatically matched using the large language model to output simulation source code that conforms to the FMI standard, thereby achieving semantic consistency between the design model and the simulation model.
It achieves seamless integration between design models and simulation models, reduces the risk of human error, improves the automation level and verification coverage of simulation modeling, supports parallel loading and execution on multiple platforms, and ensures the credibility of simulation results.
Smart Images

Figure CN123114628A_ABST
Abstract
Description
Technical Field
[0001] This invention relates to the field of computer modeling and simulation technology, specifically to a method and system for homomorphic transformation of functional model units based on a large language model. Background Technology
[0002] As systems engineering scales up, model-based systems engineering (MBSE) has replaced the traditional document-based development model as the core approach to handling complexity. SysML, as the general modeling language standard for MBSE, is widely used to define system requirements, architecture, function flows, and logical structures, and modeling with SysML has become mainstream. Although SysML dominates top-level design, a serious "digital disconnect" still exists in the crucial transition from a "static design model" to a "dynamic verification model," manifesting in the following three aspects:
[0003] (1) SysML models are essentially descriptive, focusing on architectural topology and logical abstraction, while simulation verification requires precise executable code. Currently, the conversion mainly relies on engineers manually interpreting SysML diagrams and then manually writing code. This method is not only time-consuming and labor-intensive, but also prone to human error due to the ambiguity of natural language or static diagrams, making it impossible to achieve the homomorphic requirement from design model to simulation model.
[0004] (2) Verification of complex systems usually involves multiple physics domains and multiple disciplines. Dynamics may use the Modelica simulation language and the Dymola simulation language, while artificial intelligence models may use the Python simulation language. These simulation platforms use different simulation languages, solver interfaces and data formats, and existing conversion tools often only support point-to-point single mappings. There is a lack of a general and standardized intermediate mechanism to achieve unified generation and interoperability of cross-platform models.
[0005] (3) In the traditional process, whether a simulation passes or fails often depends on the personal experience of the simulation engineer, lacking a digital connection with the original SysML requirements. This makes it difficult to directly map the simulation results back to a specific block or constraint in the SysML model. When a simulation fails, it is difficult to quickly locate whether the error is due to a code implementation error or an architectural design defect. This break in the end-to-end data link makes it impossible to quantify test coverage, which does not meet the strict requirements of functional safety for full lifecycle traceability.
[0006] Therefore, there is an urgent need for a method to realize the homomorphic transformation from SysML model to simulation model, so as to achieve unified interface simulation execution and consistency verification. Here, the simulation platform refers to the platform that runs the functional mock-up unit. Summary of the Invention
[0007] To address the issues of the inability to achieve homomorphism between design models and simulation models, and the inability to quickly locate the cause of simulation faults, this invention proposes a method and system for homomorphic transformation of functional model units based on a large language model.
[0008] The technical solution adopted in this invention is:
[0009] A method for homomorphic transformation of functional model units based on a large language model includes the following steps:
[0010] S1. Construct a model transformation rule library based on the module definition diagram and functional model unit specifications of the SysML model;
[0011] S2. Construct a corresponding SysML model based on the test requirements. The SysML model is represented by a module definition graph. The module definition graph is processed using a model transformation rule library to generate a corresponding homomorphic intermediate representation.
[0012] S3, LoRA experts who configure different simulation languages in large language models;
[0013] S4. Determine the target simulation language according to the test requirements, input the homomorphic intermediate representation and the code generation constraints of the target simulation language into the large language model, and the large language model automatically matches the optimal LoRA expert for the target simulation language through the routing selection mechanism. The large language model outputs the corresponding simulation source code.
[0014] S5. Use the automatic build and packaging engine to encapsulate the simulation source code into functional model units and modelDescription.xml metadata files that conform to the FMI standard.
[0015] A functional model unit homomorphic transformation system based on a large language model, the system comprising a model transformation rule module, a homomorphic intermediate representation generation module, a large language model, and an encapsulation module;
[0016] The model transformation rule module is used to store the mapping relationship between the module definition diagram of the SysML model and the functional model units;
[0017] The homomorphic intermediate representation generation module is used to receive the SysML model of the test requirements to be tested. The SysML model is represented by a module definition graph. Based on the module definition graph, the module calls the model transformation rule module to generate the homomorphic intermediate representation of the test requirements to be tested. The module also sends the homomorphic intermediate representation to the large language model.
[0018] The large language model is used to input the homomorphic intermediate representation of the received test requirements and the code generation constraints of the target simulation language into the large language model. The large language model outputs the simulation source code corresponding to the target simulation language and sends the simulation source code to the encapsulation module.
[0019] The encapsulation module is used to encapsulate the received simulation source code into functional model units and modelDescription.xml metadata files that conform to the FMI standard.
[0020] The beneficial effects of this invention are as follows:
[0021] This invention constructs a model transformation rule base by deterministically parsing the SysML model and its regularized mapping to functional model unit specifications. Based on the SysML model, the model transformation rule base generates corresponding homomorphic intermediate representations, ensuring that interfaces, variables, parameters, and causal relationships remain consistent before and after transformation. The one-to-one mapping of the model transformation rule base enables rapid location of errors and their causes. The homomorphic intermediate representations and code generation constraints of the target simulation language are input into a large language model configured with multiple simulation language LoRA experts. The large language model automatically matches the optimal LoRA expert for the simulation language through a routing mechanism to improve code generation consistency, and finally outputs the simulation source code corresponding to the target simulation language. This invention constrains the large language model with homomorphic intermediate representations. The simulation source code is automatically built and packaged into functional model units conforming to the FMI standard through an automatic construction and packaging engine, and the input interfaces, output interfaces, and initial conditions are automatically configured for the functional model units, generating a modelDescription.xml metadata file. This process achieves the semantic consistency requirements between the design model and the simulation model, eliminates the need for manual rewriting of SysML model logic, reduces the risk of human error, establishes a digital link from system design to simulation implementation, and realizes an integrated model-driven process. Because the generated functional model units conform to the FMI standard, these units can be loaded and executed in parallel on multiple simulation platforms, and result comparison and difference analysis can be performed, thereby improving verification coverage and the credibility of conclusions. This invention achieves seamless integration from design model to simulation verification, improves the automation level of simulation modeling, and forms a new paradigm for efficient, traceable, and high-coverage verification of complex systems engineering. Attached Figure Description
[0022] Figure 1 This is a flowchart of the present invention; Detailed Implementation
[0023] Specific implementation method one: Combining Figure 1 This embodiment describes a method for homomorphic transformation of functional model units based on a large language model, which includes the following steps:
[0024] S1. Construct a model transformation rule base based on the module definition diagram and functional model unit specifications of the SysML model. The model transformation rule base is specifically as follows:
[0025] The module block in the module definition diagram is transformed into a component of the functional model unit. Specifically, the name, type, identifier and model information of the module block in the module definition diagram are extracted, and it is used as a component-level object in the functional model unit. A unique homomorphic intermediate representation (HIR) identifier is assigned to the component.
[0026] The inputs in the module definition diagram are transformed into the inputs of the functional model unit. Specifically, each input variable in the inputs area of the module definition diagram is mapped to the input port of the functional model unit, and direction=input and causality=input are set.
[0027] The outputs in the module definition diagram are converted into the outputs of the functional model unit. Specifically, each output variable in the outputs area of the module definition diagram is mapped to the output port of the functional model unit, and direction=outputs and causality=outputs are set.
[0028] The properties in the module definition diagram are transformed into parameters, states, or local variables of the functional model units. Specifically, the read-write relationships between the property variables in the properties area of the module definition diagram and the do_steps are jointly analyzed. If the properties are only read and not assigned or modified, they are transformed into parameters; if the properties are updated in the execution logic do_steps and need to be maintained across simulation steps, they are transformed into states; if the properties are only calculated and used within the current step, they are transformed into local variables. This transformation converts ordinary properties into variables with simulation semantics, providing a basis for subsequently determining the causality, variability, initial values, and execution order of variables.
[0029] The execution logic `do_steps` in the module definition diagram is transformed into a step prompt specification `stepPromptSpec` and a behavior prompt word `behaviorPrompt` for the functional model unit. This converts the step logic, constraints, control specifications, or natural language descriptions of the execution logic `do_steps` in the module definition diagram into a structured behavior prompt specification in HIR. This specification includes the logical text of the SysML model, the set of usable input variables, the set of usable parameters, the set of output variables that must be updated, target platform generation requirements, and constraints prohibiting the generation of undeclared variables. This eliminates the need for complete syntax parsing of `do_steps`.
[0030] The relationships (combinations of inputs, outputs, properties, and do_steps) in the module definition diagram are transformed into a prompt constraint set promptConstraintSet for the functional model unit. This allows the subsequent large language model to use only declared input, output, and attribute variables when generating code, and to provide generation or update logic for each output variable.
[0031] The source information of the execution logic `do_steps` in the module definition diagram is transformed into a trace map of the functional model unit. This establishes a source element identifier for each `do_steps` segment and records the traceability relationship between that `do_steps` and the generated code logic in the HIR. When problems arise in subsequent generated code or simulation results, the corresponding `do_steps` can be located, rather than simply indicating an overall generation failure. The source information refers to the Block and field to which the execution logic `do_steps` belong.
[0032] S2. Construct a corresponding SysML model based on the test requirements. The SysML model is represented by a module definition graph. The module definition graph is processed using a model transformation rule library to generate a corresponding homomorphic intermediate representation.
[0033] In one implementation, a SysML model of the water heater constant temperature control system is constructed. This SysML model is represented by a block definition diagram. Parsing the block definition diagram reveals that the constant temperature control system comprises a controller, a temperature sensor, a thermostat, and a heater. The port connections are as follows: the controller is connected to the temperature sensor, the thermostat, and the heater. The testing requirement is to maintain the room temperature within ±1.0℃ of the set temperature during the steady-state phase. The inputs are the current temperature and the set temperature; the output is heater on or heater off. The attributes are: hysteresis threshold is 0.5, heating power is 2000W; the constraints are: when... When the heater is turned on, When the heater is turned off, the heater is shut off. The current temperature. To set the temperature.
[0034] Next, the model transformation rule base constructed by S1 is used to perform rule-based transformation, constraint information extraction, and behavior information extraction on the module definition diagram of the SysML model of the constant temperature control system, generating the homomorphic intermediate representation (HIR) corresponding to the constant temperature control system. This homomorphic intermediate representation includes components, port connection relationships, various parameters (current temperature, set temperature, hysteresis threshold, heating power, heater on and heater off) and their units, constraints, and test requirements.
[0035] This invention constructs a homomorphic mapping mechanism from the design space to the simulation space, mapping the structured SysML model representation to a general intermediate representation independent of the SysML model and specific programming languages. This intermediate representation no longer depends on the syntax details of a specific modeling tool, but strictly maintains the causal and connectivity relationships of the original design, thereby supporting the final simulation construction.
[0036] S3. Have engineers write source code in different simulation languages based on the homomorphic intermediate representation. The source code includes positive code samples and negative code samples:
[0037] (1) Sample code Code that compiles successfully and whose simulation results satisfy the homomorphic condition. Under the same initial conditions, input sequence, simulation duration, communication step size, solver, and error tolerance, the FMU corresponding to the candidate code is executed, and the output variables, state variables, and event sequences of the above-mentioned test requirements are collected. The simulation results are compared with the expected results obtained according to the test requirements of the SysML model. When the error of continuous variables does not exceed the first threshold, the number of discrete state inconsistencies does not exceed the second threshold, and the time deviation between the expected event and the actual event does not exceed the third threshold, the simulation results are determined to satisfy the homomorphic condition. Finally, candidate code that passes static syntax checking, code compilation, FMI interface compliance checking, and FMU encapsulation, and whose difference between the simulation output and the expected output obtained from the test requirements of the SysML model does not exceed the threshold, is determined as the positive code sample. .
[0038] (2) Negative code samples Code that fails to compile or exhibits inconsistent simulation behavior. Candidate code that fails static syntax checking, code compilation, FMI interface compliance checks, FMU encapsulation, or whose simulation output differs from the expected output obtained from SysML model testing requirements by more than a threshold is identified as negative code samples. Execution failures caused by missing compilers, abnormal dependency libraries, simulation platform service malfunctions, or insufficient runtime resources are not considered negative code samples. Only errors in syntax, type, interface, encapsulation, or simulation behavior that can be attributed to the candidate code itself are identified as negative code samples.
[0039] For the same homomorphic intermediate representation, positive code samples and negative code samples use the same target language, target platform and version, FMI version, FMU type, initial state, input signal sequence, simulation start and end time, communication step size, solver, error tolerance and dependency library environment.
[0040] Then, in the large language model (Qwen model or LlaMA model), different LoRA experts are configured for different simulation languages, including but not limited to Modelica code generation experts, Python code generation experts, and state transition logic experts. The large language model automatically matches the optimal LoRA expert for each simulation language through a routing mechanism to improve code generation consistency.
[0041] Next, the large language model is trained using the homomorphic intermediate representation and the code generation constraints corresponding to each simulation language (used to constrain the large language model to generate source code of the target simulation language based on the homomorphic intermediate representation). The input is the homomorphic intermediate representation and the code generation constraints corresponding to each simulation language. Then, the large language model automatically matches the LoRA expert for the corresponding simulation language based on the input code generation constraints, freezes the basic parameters of the large language model, and only updates the low-rank parameters of the current LoRA expert. Finally, the executable simulation source code of the simulation language is output.
[0042] Large language models with positive code samples Given the target simulation source code, calculate the code generation loss based on the executable simulation source code and the target simulation source code, and use the code generation loss to independently fine-tune the LoRA expert:
[0043] (1)
[0044] in, To load the first Code generation loss after LoRA experts. The length of the target simulation source code. , To load the first After a LoRA expert, the large language model generates the conditional generation probability of the target simulation source code label. These are the parameters of a large, frozen language model. For the first Trainable low-rank parameters of a LoRA expert. The first in the target simulation source code A tag. For the first The code before each marker. This serves as the input for the large language model.
[0045] To reduce the impact of different code lengths on the generated score, the code... The generated score for (positive code samples and negative code samples) can be expressed as:
[0046] (2)
[0047] in, This indicates the number of tags contained in the code sequence. Indicates loading the first A LoRA expert followed by a large language model for the complete code. The ratings are generated using normalization. A preference loss is used:
[0048] (3)
[0049] in, This represents the Sigmoid function. This represents the scaling factor used to adjust the sensitivity of the score difference between positive and negative code samples. This indicates the score generated for the positive code sample. This represents the generated score for negative code samples.
[0050] The LoRA expert parameters are shown in Table 1. The learning rate is set to 0.0001, the number of training epochs is set to 3, and the weight decay is set to 0.01.
[0051] Table 1
[0052]
[0053] Through the aforementioned fine-tuning, each LoRA expert learns the syntax rules, code structure, and specific modeling logic of the corresponding simulation language. Different LoRA experts are trained independently; while training one LoRA expert, the parameters of the other LoRA experts and the basic large language model remain frozen to reduce mutual interference between different expertise levels. This results in a well-trained large language model. This step achieves semantic consistency between the SysML model and the simulation, improving the consistency and correctness of code generation from Python, Modelica, and other languages.
[0054] In one implementation, positive and negative code samples of the constant temperature control system are obtained by engineers. The homomorphic intermediate representation of the constant temperature control system and the code generation constraints corresponding to each simulation language are then input into the large language model for training. The large language model outputs executable simulation code for each simulation language. The positive code sample is used as the target simulation source code. Equations (1)-(3) are then used to fine-tune the LoRA expert parameters while keeping the basic parameters of the large language model unchanged. This allows the large language model to output executable simulation source code that better matches the target simulation source code, ultimately resulting in a trained large language model and multiple LoRA experts. In practical applications, simulation code, such as Python FMU code or Modelica code, can be directly generated using the trained large language model and multiple LoRA experts, based on the homomorphic intermediate representation of the constant temperature control system and the selected simulation language.
[0055] S4. Using the automatic build and packaging engine, each simulation source code output by S3 is encapsulated into a functional model unit conforming to the FMI standard and a modelDescription.xml metadata file. The specific process is as follows:
[0056] After receiving the executable simulation source code, the automatic build and packaging engine first parses the variable definitions in the executable simulation source code, automatically extracts and defines the input, output, and internal parameters in the description file (modelDescription.xml metadata file) according to the FMI standard specification, and accurately marks the causality and variability of the variables. Then, it uses the packaging tool of the simulation language corresponding to the simulation source code to package it to obtain a package file. It automatically configures the input interface, output interface, and initial conditions for the package file. Finally, it packages the automatically configured package file, simulation source code, resource files, and modelDescription.xml metadata file together to generate a functional model unit file and modelDescription.xml metadata file that conform to the FMI standard.
[0057] In one implementation, an automatic build and packaging engine parses the variable definitions in the Python FMU or Modelica code of the constant temperature control system. Following FMI standards, it automatically extracts and defines the input, output, and internal parameters in the corresponding description file (modelDescription.xml metadata file), accurately labeling the causality and variability of the variables. Next, for the Modelica code, a compiler is invoked to generate an efficient binary dynamic link library, resulting in the corresponding binary file. For the Python code, a lightweight encapsulation of the interpreter environment and dependent libraries is performed, also resulting in a corresponding binary file. Then, the input interfaces, output interfaces, and initial conditions are automatically configured for the binary file. Finally, the automatically configured binary file, simulation source code, resource files, and XML description file are packaged together to generate a functional model unit file and a modelDescription.xml metadata file conforming to FMI standards.
[0058] S5. The functional model units generated in S4 are loaded in parallel on multiple simulation platforms supporting the FMI standard. Output signals, state variables, and event sequences corresponding to the functional model units are collected from the modelDescription.xml metadata file to form verification data. The verification data is compared with the actual results to obtain a difference metric. If the difference metric exceeds a preset threshold, a structured difference report is generated. The structured difference report includes the data, the data processing process, and the data processing results. The simulation source code is then regenerated according to the above process until the difference metric meets the preset threshold or reaches the maximum number of iterations, completing the homomorphic transformation closed loop. Through multi-platform joint simulation verification and comparison of the consistency between simulation behavior and design data, this invention improves verification coverage and the credibility of conclusions.
[0059] In one implementation, to verify the correctness of the generated results, the functional model unit of the constant temperature control system is input into Python FMU, Modelica FMU, and Simulink FMU simulation platforms for simulation, and their behavioral consistency is compared. Simultaneously, three types of core verification indicators are set:
[0060] M1: Final steady-state error abs ;
[0061] M2: Under the same input conditions, the heater switches output by all simulation platforms must be consistent;
[0062] M3: Temperature trajectory deviations between different simulation platforms should be controlled within the allowable threshold.
[0063] The following three test scenarios are simulated in detail, as shown in Table 2.
[0064] Table 2
[0065]
[0066] Table 3
[0067]
[0068] The verification results are shown in Table 3, indicating that test requirement R1 is met and the different simulation platform implementations exhibit high consistency in behavior, thus the homomorphic transformation is considered successful. If the simulation source code generated initially does not meet test requirement R1, the test system will automatically generate a structured difference report, and then re-input the contents of the structured difference report into the large language model for repair, realizing an iterative closed loop of "model-code-simulation-repair".
[0069] S6. In practical applications, S2 is executed to obtain the homomorphic intermediate representation. Then, the simulation language of the target simulation platform is determined according to the test requirements to be tested. The homomorphic intermediate representation and the code generation constraints corresponding to the simulation language are input into the large language model trained in S3. The trained large language model outputs the corresponding executable simulation source code. S4 is executed on the executable simulation source code to generate the corresponding modelDescription.xml metadata file.
[0070] Specific Implementation Method Two: Based on the method for homomorphic transformation of functional model units based on a large language model proposed in Specific Implementation Method One, this implementation method differs from Specific Implementation Method One in that the system for homomorphic transformation of functional model units based on a large language model includes a model transformation rule module, a homomorphic intermediate representation generation module, a large language model, and an encapsulation module.
[0071] The model transformation rule module is used to store the mapping relationship between the module definition graph of the SysML model and the functional model units. The model transformation rule module is as follows:
[0072] The module block in the module definition diagram is transformed into a component of the functional model unit. Specifically, the name, type, identifier and model information of the module block in the module definition diagram are extracted, and it is used as a component-level object in the functional model unit. A unique homomorphic intermediate representation (HIR) identifier is assigned to the component.
[0073] The inputs in the module definition diagram are transformed into the inputs of the functional model unit. Specifically, each input variable in the inputs area of the module definition diagram is mapped to the input port of the functional model unit, and direction=input and causality=input are set.
[0074] The outputs in the module definition diagram are converted into the outputs of the functional model unit. Specifically, each output variable in the outputs area of the module definition diagram is mapped to the output port of the functional model unit, and direction=outputs and causality=outputs are set.
[0075] The properties in the module definition diagram are transformed into parameters, states, or local variables of the functional model units. Specifically, the read-write relationships between the property variables in the properties area of the module definition diagram and the do_steps are jointly analyzed. If the properties are only read and not assigned or modified, they are transformed into parameters; if the properties are updated in the execution logic do_steps and need to be maintained across simulation steps, they are transformed into states; if the properties are only calculated and used within the current step, they are transformed into local variables. This transformation converts ordinary properties into variables with simulation semantics, providing a basis for subsequently determining the causality, variability, initial values, and execution order of variables.
[0076] The execution logic `do_steps` in the module definition diagram is transformed into a step prompt specification `stepPromptSpec` and a behavior prompt word `behaviorPrompt` for the functional model unit. This converts the step logic, constraints, control specifications, or natural language descriptions of the execution logic `do_steps` in the module definition diagram into a structured behavior prompt specification in HIR. This specification includes the logical text of the SysML model, the set of usable input variables, the set of usable parameters, the set of output variables that must be updated, target platform generation requirements, and constraints prohibiting the generation of undeclared variables. Therefore, a complete syntax parsing of `do_steps` is not required.
[0077] The relationships (combinations of inputs, outputs, properties, and do_steps) in the module definition diagram are transformed into a prompt constraint set promptConstraintSet for the functional model unit. This allows the subsequent large language model to use only the declared input, output, and attribute variables when generating code, and to provide generation or update logic for each output variable.
[0078] The source information of the execution logic `do_steps` in the module definition diagram is transformed into a trace map of the functional model unit. This establishes a source element identifier for each `do_steps` segment and records the traceability relationship between that `do_steps` and the generated code logic in the HIR. When problems arise in subsequent generated code or simulation results, the corresponding `do_steps` can be located, rather than simply indicating an overall generation failure. The source information refers to the Block and field to which the execution logic `do_steps` belong.
[0079] The homomorphic intermediate representation generation module is used to receive the SysML model of the test requirements to be tested, which is represented by a module definition graph. Based on the module definition graph, the module calls the model transformation rule module to generate the homomorphic intermediate representation of the test requirements to be tested, and also sends the homomorphic intermediate representation to the large language model.
[0080] In one implementation, a SysML model of the water heater constant temperature control system is constructed. This SysML model is represented by a block definition diagram. Parsing the block definition diagram reveals that the constant temperature control system comprises a controller, a temperature sensor, a thermostat, and a heater. The port connections are as follows: the controller is connected to the temperature sensor, the thermostat, and the heater. The testing requirement is to maintain the room temperature within ±1.0℃ of the set temperature during the steady-state phase. The inputs are the current temperature and the set temperature; the output is heater on or heater off. The attributes are: hysteresis threshold is 0.5, heating power is 2000W; the constraints are: when... When the heater is turned on, When the heater is turned off, the heater is shut off. The current temperature. To set the temperature.
[0081] Next, the model transformation rule base constructed by S1 is used to perform rule-based transformation, constraint information extraction, and behavior information extraction on the module definition diagram of the SysML model of the constant temperature control system, generating the homomorphic intermediate representation (HIR) corresponding to the constant temperature control system. This homomorphic intermediate representation includes components, port connection relationships, various parameters (current temperature, set temperature, hysteresis threshold, heating power, heater on and heater off) and their units, constraints, and test requirements.
[0082] This invention constructs a homomorphic mapping mechanism from the design space to the simulation space, mapping the structured SysML model representation to a general intermediate representation independent of the SysML model and specific programming languages. This intermediate representation no longer depends on the syntax details of a specific modeling tool, but strictly maintains the causal and connectivity relationships of the original design, thereby supporting the final simulation construction.
[0083] The large language model (Qwen model or LlaMA model) is used to input the homomorphic intermediate representation of the received test requirements and the code generation constraints of the target simulation language into the large language model. The large language model outputs the simulation source code corresponding to the target simulation language and sends the simulation source code to the encapsulation module. The large language model is configured with LoRA experts for different simulation languages, including but not limited to Modelica code generation experts, Python code generation experts, and state transition logic experts. The large language model automatically matches the optimal LoRA expert for each simulation language through a routing mechanism to improve code generation consistency.
[0084] In one implementation, the homomorphic intermediate representation of the constant temperature control system and the code generation constraints of the target simulation language are input into a large language model. The large language model automatically matches the optimal LoRA expert for the corresponding simulation language based on the input code generation constraints. After processing by the optimal LoRA expert, the large language model outputs the executable simulation source code of the target simulation language. The simulation source code is Python FMU code or Modelica code.
[0085] The encapsulation module is used to encapsulate the received simulation source code into functional model units conforming to the FMI standard and a modelDescription.xml metadata file. The encapsulation module uses an automatic build and packaging engine.
[0086] After receiving the executable simulation source code, the automatic build and packaging engine first parses the variable definitions in the executable simulation source code, automatically extracts and defines the input, output, and internal parameters in the description file (modelDescription.xml metadata file) according to the FMI standard specification, and accurately marks the causality and variability of the variables. Then, it uses the packaging tool of the simulation language corresponding to the simulation source code to package it to obtain a package file. It automatically configures the input interface, output interface, and initial conditions for the package file. Finally, it packages the automatically configured package file, simulation source code, resource files, and modelDescription.xml metadata file together to generate a functional model unit file and modelDescription.xml metadata file that conform to the FMI standard.
[0087] In one implementation, an automatic build and packaging engine parses the variable definitions in the Python FMU or Modelica code of the constant temperature control system. Following FMI standards, it automatically extracts and defines the input, output, and internal parameters in the corresponding description file (modelDescription.xml metadata file), accurately labeling the causality and variability of the variables. Next, for the Modelica code, a compiler is invoked to generate an efficient binary dynamic link library, resulting in the corresponding binary file. For the Python code, a lightweight encapsulation of the interpreter environment and dependent libraries is performed, also resulting in a corresponding binary file. Then, the input interfaces, output interfaces, and initial conditions are automatically configured for the binary file. Finally, the automatically configured binary file, simulation source code, resource files, and XML description file are packaged together to generate a functional model unit file and a modelDescription.xml metadata file conforming to FMI standards.
[0088] The other steps and parameters are the same as in Specific Implementation Method 1.
[0089] This invention may have other embodiments. Without departing from the spirit and essence of this invention, those skilled in the art can make various corresponding changes and modifications according to this invention, but these corresponding changes and modifications should all fall within the protection scope of the appended claims.
Claims
1. A method for homomorphic transformation of functional model units based on a large language model, characterized in that: It includes the following steps: S1. Construct a model transformation rule library based on the module definition diagram and functional model unit specifications of the SysML model; S2. Construct a corresponding SysML model based on the test requirements. The SysML model is represented by a module definition graph. The module definition graph is processed using a model transformation rule library to generate a corresponding homomorphic intermediate representation. S3, LoRA experts who configure different simulation languages in large language models; S4. Determine the target simulation language according to the test requirements, input the homomorphic intermediate representation and the code generation constraints of the target simulation language into the large language model, and the large language model automatically matches the optimal LoRA expert for the target simulation language through the routing selection mechanism. The large language model outputs the corresponding simulation source code. S5. Use the automatic build and packaging engine to encapsulate the simulation source code into functional model units and modelDescription.xml metadata files that conform to the FMI standard.
2. The method for homomorphic transformation of functional model units based on a large language model according to claim 1, characterized in that: The model transformation rule base is as follows: Transform the Block in the module definition diagram into a Component of the functional model unit; The inputs in the module definition diagram are transformed into the inputs of the functional model units. The outputs in the module definition diagram are converted into the outputs of the functional model units. The properties in the module definition diagram are converted into parameters, states, or local variables of the functional model unit. If the properties are only read and not assigned or modified, they are converted into parameters. If the properties are updated in the execution logic do_steps and need to be maintained across simulation steps, they are converted into states. If the properties are only calculated and used within the current step, they are converted into local variables. The execution logic do_steps in the module definition diagram is transformed into the step prompt specification stepPromptSpec and behavior prompt word behaviorPrompt of the functional model unit; The relationships in the module definition diagram are transformed into a prompt constraint set promptConstraintSet for the functional model unit; The source of the execution logic do_steps in the module definition diagram is transformed into a trace map of the functional model unit.
3. The method for homomorphic transformation of functional model units based on a large language model according to claim 2, characterized in that: The LoRA experts for different simulation languages in S3 include Modelica code generation experts, Python code generation experts, and state transition logic experts.
4. The method for homomorphic transformation of functional model units based on a large language model according to claim 3, characterized in that: The large language model in S3 is either the Qwen model or the LlaMA model.
5. The method for homomorphic transformation of functional model units based on a large language model according to claim 4, characterized in that: The specific process of S5 is as follows: After receiving the simulation source code, the automatic build and packaging engine first parses the variable definitions in the simulation source code, automatically extracts and defines the input, output, and internal parameters in the modelDescription.xml metadata file according to the FMI standard specification, and marks the causality and variability of the variables. Then, it uses the packaging tool of the simulation language corresponding to the simulation source code to package it to obtain a packaged file. It automatically configures the input interface, output interface, and initial conditions for the packaged file. Finally, it packages the automatically configured packaged file, simulation source code, resource files, and modelDescription.xml metadata file together to generate a functional model unit file and modelDescription.xml metadata file that conform to the FMI standard.
6. A homomorphic transformation system for functional model units based on a large language model, characterized in that: The system includes a model transformation rule module, a homomorphic intermediate representation generation module, a large language model, and an encapsulation module. The model transformation rule module is used to store the mapping relationship between the module definition diagram of the SysML model and the functional model units; The homomorphic intermediate representation generation module is used to receive the SysML model of the test requirements to be tested. The SysML model is represented by a module definition graph. Based on the module definition graph, the module calls the model transformation rule module to generate the homomorphic intermediate representation of the test requirements to be tested. The module also sends the homomorphic intermediate representation to the large language model. The large language model is used to input the homomorphic intermediate representation of the received test requirements and the code generation constraints of the target simulation language into the large language model. The large language model outputs the simulation source code corresponding to the target simulation language and sends the simulation source code to the encapsulation module. The encapsulation module is used to encapsulate the received simulation source code into functional model units and modelDescription.xml metadata files that conform to the FMI standard.
7. A homomorphic transformation system for functional model units based on a large language model according to claim 6, characterized in that: The model transformation rule module is as follows: Transform the Block in the module definition diagram into a Component of the functional model unit; The inputs in the module definition diagram are transformed into the inputs of the functional model units. The outputs in the module definition diagram are converted into the outputs of the functional model units. The properties in the module definition diagram are converted into parameters, states, or local variables of the functional model unit. If the properties are only read and not assigned or modified, they are converted into parameters. If the properties are updated in the execution logic do_steps and need to be maintained across simulation steps, they are converted into states. If the properties are only calculated and used within the current step, they are converted into local variables. The execution logic do_steps in the module definition diagram is transformed into the step prompt specification stepPromptSpec and behavior prompt word behaviorPrompt of the functional model unit; The relationships in the module definition diagram are transformed into a prompt constraint set promptConstraintSet for the functional model unit; The source of the execution logic do_steps in the module definition diagram is transformed into a trace map of the functional model unit.
8. A homomorphic transformation system for functional model units based on a large language model according to claim 7, characterized in that: The large language model is configured with LoRA experts for different simulation languages, including Modelica code generation experts, Python code generation experts, and state transition logic experts. The large language model automatically matches the optimal LoRA expert for each simulation language through a routing mechanism.
9. A homomorphic transformation system for functional model units based on a large language model according to claim 8, characterized in that: The large language model is either the Qwen model or the LlaMA model.
10. A homomorphic transformation system for functional model units based on a large language model according to claim 8, characterized in that: The specific process of the encapsulation module is as follows: The encapsulation module employs an automatic build and packaging engine; After receiving the simulation source code, the automatic build and packaging engine first parses the variable definitions in the simulation source code, automatically extracts and defines the input, output, and internal parameters in the modelDescription.xml metadata file according to the FMI standard specification, and marks the causality and variability of the variables. Then, it uses the packaging tool of the simulation language corresponding to the simulation source code to package it to obtain a packaged file. It automatically configures the input interface, output interface, and initial conditions for the packaged file. Finally, it packages the automatically configured packaged file, simulation source code, resource files, and modelDescription.xml metadata file together to generate a functional model unit file and modelDescription.xml metadata file that conform to the FMI standard.
