SMV code automatic generation method and device, equipment and medium

By employing a two-level verification and closed-loop repair mechanism, and utilizing a large language model to generate SMV candidate code and perform structural compliance and formal verification, the problem of high manual burden and error rate in the conversion of natural language requirements to the nuXmv model is solved, thus achieving efficient and reliable SMV code generation.

CN121879736APending Publication Date: 2026-04-17INSPUR ENTERPRISE CLOUD TECHNOLOGY (SHANDONG) CO LTD
View PDF 0 Cites 0 Cited by

Patent Information

Authority / Receiving Office
CN · China
Patent Type
Applications(China)
Current Assignee / Owner
INSPUR ENTERPRISE CLOUD TECHNOLOGY (SHANDONG) CO LTD
Filing Date
2026-01-08
Publication Date
2026-04-17

AI Technical Summary

Technical Problem

In existing technologies, the conversion from natural language requirements to the nuXmv model suffers from heavy manual workload, high error rate, and low iteration efficiency. It lacks an automated error localization and correction loop, making it difficult to form a fast-converging generation-verification process.

Method used

Through a progressive two-level verification and closed-loop repair mechanism, SMV candidate code is generated using a large language model, and first-level structural compliance checks and second-level formal verification are performed. Combined with a low-rank adaptation matrix fine-tuning model, errors are accurately located and repaired, and finally the target SMV code is output.

Benefits of technology

It significantly reduces failures caused by structural omissions and syntax errors, lowers the cost of repeated trial and error and the need for manual intervention, and improves the structural integrity and logical correctness of the generated code.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN121879736A_ABST
    Figure CN121879736A_ABST
Patent Text Reader

Abstract

The invention discloses an SMV code automatic generation method and device, equipment and a medium, and relates to the technical field of software engineering. The method comprises the following steps: receiving a natural language demand text and extracting a standard fragment from the natural language demand text; on the basis of the standard fragments, prompt information used for guiding the large language model to output is constructed, and SMV candidate codes are generated according to the prompt information through the large language model; and sequentially carrying out primary structure compliance check and secondary formal verification on the SMV candidate code, structuring the error information into a repair instruction to carry out iterative repair on the SMV candidate code, and outputting a target SMV code until the SMV candidate code meets a preset stop condition. By means of the technical scheme, the natural language description requirement is converted into the SMV code capable of being recognized by the nuXmv tool, the manual correction cost and the technical threshold of formalized modeling are greatly reduced, and the usability and practicability of an automatic tool in an actual scene are improved.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] This invention relates to the field of software engineering technology, and in particular to an automatic SMV code generation method, apparatus, device, and medium. Background Technology

[0002] With the widespread application of model checking in safety-critical systems, nuXmv, as a mainstream tool supporting sequential logic such as LTL (Linear Temporal Logic) and CTL (Computation Tree Logic), is extensively used for specification modeling and property verification. However, the rapid and accurate conversion of natural language requirements into symbolic model verifier (SMV) code acceptable to nuXmv still relies on manual coding by experts, which presents the following problems: 1. Heavy manual burden: requirement analysis, arrangement of modules / variables / initial conditions / transition relationships and property constraints are time-consuming and labor-intensive; 2. High error rate: incomplete structure, syntax errors, and inconsistencies in properties lead to verification failures and multiple reworks; 3. Low iteration efficiency: lack of automated error location and correction loops makes it difficult to form a fast-converging generation-verification process.

[0003] Therefore, how to provide a solution to the above-mentioned technical problems is a problem that needs to be solved by those skilled in the art. Summary of the Invention

[0004] In view of this, the purpose of this invention is to provide an automatic SMV code generation method, apparatus, device, and medium. Through a progressive two-level verification and closed-loop repair mechanism, the process of converting natural language description requirements into SMV code recognizable by the nuXmv tool significantly reduces failures caused by structural omissions and syntax errors, thereby improving reliability. It greatly reduces the manual correction cost and technical threshold of formal modeling, and enhances the usability and practicality of automation tools in real-world scenarios. The specific solution is as follows:

[0005] Firstly, this application discloses an automatic SMV code generation method, including:

[0006] Receive natural language requirement text and extract the specification fragments that constitute the SMV code framework from the natural language requirement text;

[0007] Based on the specified fragment, prompting information is constructed to guide the output of the large language model, and the large language model is used to generate SMV candidate codes according to the prompting information. The prompting information includes system messages and user messages, wherein the system messages are used to limit the code generation rules of the large language model; the user messages are used to constrain the large language model to complete the missing parts of the SMV candidate codes, including the specified fragment and the remaining natural language descriptions in the natural language requirement text that were not extracted as the specified fragment.

[0008] The SMV candidate code is subjected to a first-level structural compliance check and a second-level formal verification in sequence. When there are error messages in the SMV candidate code, the error messages are structured into repair instructions to iteratively repair the SMV candidate code until the SMV candidate code meets the preset stopping conditions, and then the target SMV code is output.

[0009] Optionally, the specification fragment includes at least one of the following: module definition, variable declaration, initial state setting, state transition relationship definition, and timing logic property definition.

[0010] Optionally, the SMV code automatic generation method further includes:

[0011] A dedicated low-rank adaptation matrix is ​​configured for the module definition, the variable declaration, the initial state setting, and the state transition relationship definition;

[0012] The large language model is fine-tuned based on the low-rank adaptation method, and the low-rank adaptation matrix is ​​injected into the attention projection layer of the large language model to generate the fine-tuned model.

[0013] Accordingly, using the large language model, SMV candidate codes are generated based on the prompt information, including:

[0014] Using the fine-tuned model, SMV candidate codes are generated based on the prompt information.

[0015] Optionally, a first-level structural compliance check is performed on the SMV candidate code, including:

[0016] The SMV candidate code is subjected to template constraint verification using a predefined structure template to check whether the SMV candidate code fully contains the module definition, the variable declaration, the initial state setting and the state transition relationship definition, and whether the SMV candidate code contains at least one of the temporal logic property definitions;

[0017] The SMV candidate code is scanned using regular expressions to check the syntactic integrity of the SMV candidate code.

[0018] If both the template constraint verification and the regular expression matching scan pass, the SMV candidate code is determined to have passed the first-level structural compliance check, and the second-level formal verification is triggered.

[0019] If the template constraint validation and / or the regular expression matching scan fails, the missing item is obtained, and the prompt information is reconstructed based on the missing item. Then, the process jumps to the step of generating SMV candidate code based on the prompt information using the large language model.

[0020] Optionally, the SMV candidate code is subjected to a second-level formal verification, including:

[0021] The nuXmv tool is invoked to perform syntax and model checks on the SMV candidate code that has passed the first-level structure compliance check.

[0022] Accordingly, when the SMV candidate code contains error information, structuring the error information into repair instructions includes:

[0023] If the nuXmv tool outputs the error information, the error information is structured into repair instructions; the repair instructions include the error type, error location, error context, and repair prompts.

[0024] Optionally, when the SMV candidate code contains error information, the error information is structured into repair instructions to iteratively repair the SMV candidate code until the SMV candidate code meets a preset stopping condition, and then the target SMV code is output, including:

[0025] When the SMV candidate code contains error information, the error information is structured into repair instructions, and the prompt information is reconstructed according to the repair instructions. Then, the process jumps to the step of generating SMV candidate code based on the prompt information using the large language model.

[0026] When all properties of the secondary formal verification pass the verification, or when the number of iterations for repair reaches a preset threshold, the target SMV code is output.

[0027] Optionally, generating SMV candidate codes based on the prompt information using the large language model includes:

[0028] By using multi-sample sampling and the large language model, multiple SMV candidate codes are generated at once based on the prompt information;

[0029] Correspondingly, the SMV code automatic generation method further includes:

[0030] The steps of performing first-level structural compliance checks and second-level formal verifications on the multiple SMV candidate codes in parallel are executed, and the SMV candidate code that first meets the preset stopping condition is selected as the target SMV code.

[0031] Secondly, this application discloses an SMV code automatic generation device, comprising:

[0032] The input and extraction module is used to receive natural language requirement text and extract the specification fragments that constitute the SMV code framework from the natural language requirement text.

[0033] A prompting construction module is used to construct prompting information to guide the output of the large language model based on the specified fragment, and to generate SMV candidate code using the large language model according to the prompting information. The prompting information includes system messages and user messages, wherein the system messages are used to limit the code generation rules of the large language model; the user messages are used to constrain the large language model to complete the missing parts of the SMV candidate code, and include the specified fragment and the remaining natural language description in the natural language requirement text that has not been extracted as the specified fragment.

[0034] A two-level verification module is used to perform a first-level structural compliance check and a second-level formal verification on the SMV candidate code in sequence.

[0035] The code generation module is used to structure the error information into repair instructions when there is error information in the SMV candidate code, so as to iteratively repair the SMV candidate code until the SMV candidate code meets the preset stopping conditions, and then output the target SMV code.

[0036] Thirdly, this application discloses an electronic device, which includes a processor and a memory; wherein the memory is used to store a computer program, which is loaded and executed by the processor to implement the SMV code automatic generation method as described above.

[0037] Fourthly, this application discloses a computer-readable storage medium for storing a computer program; wherein the computer program, when executed by a processor, implements the aforementioned SMV code automatic generation method.

[0038] The beneficial effects of this application are as follows: By accurately extracting SMV specification fragments from natural language requirements and constructing targeted prompts, the large language model is guided to prioritize the generation of structured SMV candidate code, reducing the structural missing rate in the initial generation stage. Then, using a two-level verification mechanism, a first-level structural compliance check eliminates basic framework errors, followed by a second-level formal verification to capture deep logical defects, accurately locating the error position and type. Each error message is structured into precise repair instructions to drive model regeneration, ensuring that the final output target SMV code meets compilation requirements and passes all property verifications. This progressive two-level verification and closed-loop repair mechanism not only significantly reduces failures caused by structural missing and syntax errors but also allows most errors in the natural language conversion process to be corrected early in the iteration process. This significantly reduces the cost of repeated trial and error and the need for manual intervention, ultimately achieving a synergistic improvement in the structural integrity and logical correctness of the generated code.

[0039] In addition, the SMV code automatic generation apparatus, device and storage medium provided in this application correspond to the above-mentioned SMV code automatic generation method and have the same effect. Attached Figure Description

[0040] To more clearly illustrate the technical solutions in the embodiments of the present invention or the prior art, the drawings used in the description of the embodiments or the prior art will be briefly introduced below. Obviously, the drawings described below are only embodiments of the present invention. For those skilled in the art, other drawings can be obtained based on the provided drawings without creative effort.

[0041] Figure 1 This application discloses a flowchart of an automatic SMV code generation method.

[0042] Figure 2 This is a schematic diagram of an automatic SMV code generation process disclosed in this application;

[0043] Figure 3 This is a schematic diagram illustrating one application example disclosed in this application;

[0044] Figure 4 This is a flowchart illustrating the error correction process for a bipolar check disclosed in this application.

[0045] Figure 5 This is a schematic diagram of the structure of an SMV code automatic generation device disclosed in this application;

[0046] Figure 6 This is a structural diagram of an electronic device disclosed in this application. Detailed Implementation

[0047] The technical solutions of the embodiments of the present invention will be clearly and completely described below with reference to the accompanying drawings. Obviously, the described embodiments are only some embodiments of the present invention, and not all embodiments. Based on the embodiments of the present invention, all other embodiments obtained by those skilled in the art without creative effort are within the scope of protection of the present invention.

[0048] Currently, traditional SMV code requires manual writing by experts, and manual debugging is necessary after nuXmv verification failures. Therefore, the conversion from natural language to nuXmv models suffers from low conversion efficiency, high error rates, and a lack of automatic verification loops. To address this, this application provides an automatic SMV code generation solution that enables efficient and reliable conversion from natural language requirements to SMV code directly usable for formal verification. This significantly reduces the manual correction costs and technical barriers of formal modeling, and enhances the usability and practicality of automation tools in real-world scenarios.

[0049] This invention discloses an automatic SMV code generation method, see [link to relevant documentation]. Figure 1 As shown, the method includes:

[0050] Step S11: Receive the natural language requirement text and extract the specification fragments that constitute the SMV code framework from the natural language requirement text.

[0051] In the development of safety-critical systems such as industrial control, automotive electronics, and medical devices, engineers need to convert natural language descriptions of requirements (such as "automatically close the valve when the temperature exceeds the threshold") into formal model code (SMV code) that can be recognized by the nuXmv tool. In this embodiment, the system first receives natural language requirement text including system description, signal / variable semantics, initial state, and expected temporal properties. Then, entity / slot recognition (variable name, value range, initial condition), relation extraction (state transition), and property extraction (LTL / CTL formulas) are used to form a standardized fragment constituting the SMV code framework (such as the variable name "valve" and the initial condition "closed").

[0052] It should be noted that the specification fragment includes at least one of the following: module definition (MODULE), variable declaration (VAR), initial state setting (INIT), state transition relation definition (TRANS), and time sequence logic property definition (LTLSPEC, CTLSPEC, INVARSPEC), macro definition (DEFINE), and invariant definition (INVARSPEC).

[0053] Step S12: Based on the specified fragment, construct prompt information to guide the output of the large language model, and use the large language model to generate SMV candidate code according to the prompt information; the prompt information includes system messages and user messages, wherein the system messages are used to limit the code generation rules of the large language model; the user messages are used to constrain the large language model to complete the missing parts of the SMV candidate code, including the specified fragment and the remaining natural language description in the natural language requirement text that was not extracted as the specified fragment.

[0054] In recent years, Large Language Models (LLMs) have made progress in code generation, but their direct application to SMV code generation still suffers from issues such as structural deficiencies, grammatical non-compliance, and property violations. In this embodiment, cue engineering is used to constrain AI behavior and construct cue messages. Specifically, based on extracted canonical fragments, a two-part cue message is constructed to guide the dialogue output of the Large Language Model.

[0055] 1) System Prompt: Used to define the code generation rules for large language models, such as limiting the large language model to act as a "nuXmv / SMV expert", specifying that the output must be complete and compilable SMV code, specifying roles, output formats, and prohibiting interpreted text.

[0056] 2) User Prompt: Carries a known fragment and the remaining natural language description, requiring the model to only complete the missing parts and provide auxiliary macros / definitions when necessary. In one feasible implementation, the prompt can also adopt an imperative single-segment template: "Generate working nuXmv code with these variables and initial conditions: {VARS & INIT}, that represents {Prompt}".

[0057] Furthermore, the large language model is invoked to generate SMV candidate codes based on the prompts. It should be noted that the large language model requires efficient parameter fine-tuning before outputting SMV candidate codes. This fine-tuning employs the Low-Rank Adaptation (LoRA) method, injecting an adaptation matrix of rank r (e.g., r=8) into the attention projection layer (e.g., c_attn) and setting a scaling factor α (e.g., α=16) and dropout=0.1 to improve the model's fitting ability to SMV syntax and patterns. Dedicated low-rank adaptation matrices are designed for SMV MODULE / VAR / INIT / TRANS paragraph patterns to significantly reduce structural omissions and illegal combinations. Finally, the fine-tuned model is used to generate SMV candidate codes based on the prompts.

[0058] Specifically, a dedicated low-rank adaptation matrix is ​​configured for the module definition, variable declaration, initial state setting, and state transition relationship definition; the large language model is fine-tuned based on the low-rank adaptation method, and the low-rank adaptation matrix is ​​injected into the attention projection layer of the large language model to generate the fine-tuned model.

[0059] In this embodiment, a general low-rank matrix (rank r) is first injected into the attention projection layer to fine-tune the model parameters at low cost, allowing the model to initially adapt to the SMV code generation task. At this stage, the model cannot accurately distinguish the differences in grammatical rules between different SMV segments. Therefore, a dedicated low-rank adaptation matrix is ​​configured. Within the basic LoRA framework, independent matrix groups are configured for the four core segments of SMV (MODULE / VAR / INIT / TRANS), which is equivalent to additionally creating branch toolkits for SMV segment characteristics on the general LoRA backbone. Finally, the matrix parameters of the dedicated low-rank adaptation matrix are updated based on SMV training samples to generate the fine-tuned model.

[0060] For example, for this large language model, the SMV training samples during model training can be built based on the official nuXmv documentation / tutorials and open-source repositories, constructing approximately 2500 "description-code" samples, all in JSON format (fields include prompt and code). The training / validation sets are split in a 9:1 ratio, with the validation set used to validate the samples. The training configuration for this large language model is as follows: maximum sequence length of 512 tokens, fp16 training, a certain number of epochs (e.g., 3-5), and batch size adaptively set according to GPU memory.

[0061] It should be noted that LLM generates SMV candidate codes, and multiple samples (e.g., n=3) can be sampled if necessary to improve the success rate on the first attempt.

[0062] Step S13: Perform first-level structural compliance checks and second-level formal verifications on the SMV candidate code in sequence. When there are error messages in the SMV candidate code, structure the error messages into repair instructions to iteratively repair the SMV candidate code until the SMV candidate code meets the preset stopping conditions, and then output the target SMV code.

[0063] In this embodiment of the application, the SMV candidate code is subjected to two-level verification. The core of the first-level structural compliance check is the integrity of the components and the legality of the structural format. It only verifies whether the SMV candidate code contains mandatory or optional components, that is, it verifies the existence of the property specification. The core of the second-level formal verification is the validity verification of the property specification. It verifies the specific property content of the components contained in the first-level verification, that is, it verifies the correctness of the content of the property specification.

[0064] Furthermore, when errors exist in the SMV candidate code, these errors are structured into repair instructions for subsequent regeneration or manual review. Based on these repair instructions, the SMV candidate code is iteratively repaired. It's important to note that the repair during iteration uses differential repair, meaning the model is required to modify only the specified erroneous segments. When the SMV candidate code meets the preset stopping conditions, the final target SMV code is output, along with a verification report. Thus, by prompting engineering constraints for generation and automatically regenerating based on error causes in failure scenarios, a highly reliable end-to-end automated process is achieved.

[0065] The preset stopping condition may include either reaching a preset maximum number of iterations or passing all property verifications of the SMV candidate code. Since multi-sample sampling is possible as described in the preceding steps, in one feasible implementation, multi-sample sampling is performed to obtain multiple candidates. Specifically, through multi-sample sampling, multiple SMV candidate codes are generated at once using the large language model based on the prompt information. Further, the steps of performing first-level structural compliance checks and second-level formal verifications on the multiple SMV candidate codes are executed in parallel, and the SMV candidate code that first meets the preset stopping condition is selected as the target SMV code. For example, the candidate that first passes all checks or first reaches the maximum number of iterations is selected as the final output.

[0066] The beneficial effects of this application are as follows: By accurately extracting SMV specification fragments from natural language requirements and constructing targeted prompts, the large language model is guided to prioritize the generation of structured SMV candidate code, reducing the structural missing rate in the initial generation stage. Then, using a two-level verification mechanism, a first-level structural compliance check eliminates basic framework errors, followed by a second-level formal verification to capture deep logical defects, accurately locating the error position and type. Each error message is structured into precise repair instructions to drive model regeneration, ensuring that the final output target SMV code meets compilation requirements and passes all property verifications. This progressive two-level verification and closed-loop repair mechanism not only significantly reduces failures caused by structural missing and syntax errors but also allows most errors in the natural language conversion process to be corrected early in the iteration process. This significantly reduces the cost of repeated trial and error and the need for manual intervention, ultimately achieving a synergistic improvement in the structural integrity and logical correctness of the generated code.

[0067] like Figure 2 The diagram shows the core process framework implemented based on the above steps, presenting the entire chain of steps from natural language requirement input to target SMV code output, specifically including:

[0068] 1. Input layer: Receives natural language requirement text containing at least one of the following: variable name and value range, initial state description, state transition rules, immutable constraints, and temporal logic properties;

[0069] 2. Preprocessing stage: Extract SMV specification fragments from natural language requirements and unify them into JSON;

[0070] 3. Prompt Construction Stage: Integrate the extracted specification fragments with the remaining unextracted requirements to form a prompt that includes system messages (limiting the generation scope) and user messages (constraining and completing missing parts);

[0071] 4. Code generation stage: The language model, which has been efficiently fine-tuned with parameters, is invoked to generate SMV candidate code based on the prompts;

[0072] 5. Two-level checking and iteration process: First, a first-level structural compliance check is performed to verify whether the required components (MODULE, VAR, INIT, TRANS) are complete and whether at least one of the optional property components (INVARSPEC, etc.) exists. If it fails, a refactoring prompt is given and the code generation process is returned. After passing the first-level check, a second-level formal verification (syntax / model check) is performed to detect syntax errors, dead states, and property satisfiability. If problems are found, repair instructions are generated and the process is iterated.

[0073] 6. Output layer: When the maximum number of iterations is reached or the candidate code passes all checks (first-level structural compliance + second-level formal verification), the target SMV code and verification report are output, and the metadata is persisted.

[0074] like Figure 3 The diagram illustrates a comparison between a natural language requirement and its corresponding SMV model code. The diagram contains two core parts: first, the "input" part, which is the natural language requirement text, explicitly describing "a simple traffic light controller that can alternate between GO and STOP states. The system starts from the STOP state, then switches to the GO state, and this alternation continues in subsequent steps"; second, the "output" part, which is the SMV code matching this natural language requirement. The code includes `MODULE main` (main module), `VAR` (variable declaration, defining the `state` variable with values ​​of `{STOP, GO}`), and `ASSIGN` (assignment section, containing the initial state definition `init(state:=STOP` and the state transition logic based on `next(state)` case statements). This visually demonstrates the specific process and correspondence of how the present invention transforms a traffic light controller-type natural language requirement into structured SMV model code.

[0075] Furthermore, to illustrate the beneficial effects of this invention, a set of representative experimental results are given (using a certain 1B level code model as the baseline): Structural accuracy (structural compliance check pass rate): After processing with the hints and fine-tuning strategies in the method of this invention, it can reach approximately 97.7%; compared with the structural accuracy of the zero-sample large model baseline of approximately 89.7%. This improvement mainly comes from the "structural compliance + differential repair closed-loop" mechanism introduced in this invention, rather than simply an increase in model size or training time, proving the unique contribution of this scheme. Main causes of syntax / property failures: Difficulty in modeling syntax details (such as undeclared variables, missing paragraphs) and temporal properties (LTL / CTL) are common sources of failure; using the "structural compliance + syntax / model check" two-level verification of this invention can significantly reduce the proportion of such errors in the final output. Process metrics: When using the closed loop, the average number of iteration rounds is significantly less than the regeneration without differential repair.

[0076] Based on the above embodiments, this embodiment describes the first-level structural compliance check and the second-level formal verification in the two-level verification process. Specifically, in the first specific implementation, the first-level structural compliance check of the SMV candidate code includes the following steps:

[0077] The SMV candidate code is subjected to template constraint verification using a predefined structure template to check whether the SMV candidate code fully contains the module definition, the variable declaration, the initial state setting and the state transition relationship definition, and whether the SMV candidate code contains at least one of the temporal logic property definitions;

[0078] The SMV candidate code is scanned using regular expressions to check the syntactic integrity of the SMV candidate code.

[0079] If both the template constraint verification and the regular expression matching scan pass, the SMV candidate code is determined to have passed the first-level structural compliance check, and the second-level formal verification is triggered.

[0080] If the template constraint validation and / or the regular expression matching scan fails, the missing item is obtained, and the prompt information is reconstructed based on the missing item. Then, the process jumps to the step of generating SMV candidate code based on the prompt information using the large language model.

[0081] In this embodiment, the first-level structure compliance check adopts a hybrid strategy that combines "template constraints + regular expression matching". Unlike the existing check methods that rely solely on string matching, this approach can accurately locate defects in scenarios such as missing variable declarations and incorrect syntax skeletons in property segments, and transform the defects into subsequent differential repair instructions, thus avoiding missed detections caused by relying solely on string heuristics.

[0082] The template constraint verifies the existence of at least one or more of MODULE, VAR, INIT, TRANS, and LTLSPEC / CTLSPEC / INVARSPEC based on a predefined SMV code skeleton. In one feasible implementation, it can also be verified by parsing the AST to check whether MODULE / VAR / INIT / TRANS and at least one property segment are included. Regular expression matching specifically scans the code string to detect the integrity of variable declaration delimiters, initial condition assignment symbols, and state transition relation keywords, and locates the defect location when missing items are found. If it is unqualified, the suggestion is reconstructed based on the missing items, and the suggestion is rewritten based on the failure reason and then regenerated.

[0083] For example, the following provides an error template definition:

[0084] stage: "structure" (template / syntax), "verification" (properties / semantics);

[0085] location: line number / column number / file segment / property name (e.g., "main.smv:line 23" / "SPEC AG !deadlock");

[0086] message: A summary of the original error message (multiple lines of the original message can be attached);

[0087] fix_hint: The rule-generated hints on "where to fix and how to fix", using reproducible heuristics.

[0088] Example: 1) Structural error: Parser error near 'VAR' → fix_hint: "Check the syntax and semicolons of the VAR section; ensure that each variable declaration ends with ';'";

[0089] 2) Property error: AG p fails (safety) → "Add invariant / restrict transfer to make p always true; or constrain in TRANS / INIT";

[0090] 3) Uninitialized signal: (In Counterexample, the first step is X=undefined) → "Initialize X in INIT / ASSIGN".

[0091] like Figure 4 The diagram shows the compliance check and iterative optimization process for SMV code generation. The process begins with "Constructing Prompt candidates to generate compliance checks" (corresponding to...). Figure 2(See boxes 3-5 in the diagram). First, a "verification pass / fail" check is performed. If verification passes, the output model and report are executed sequentially, and metadata is archived. After this operation, the process ends. If verification fails, an error message and differential repair instruction are executed, followed by incrementing i and checking if the stopping condition has been met. If the stopping condition has not been met, the process returns to the "constructing Prompt candidates to generate compliance checks" stage to continue iterating. If the stopping condition has been met, the best result and error summary are output, and metadata is archived. After this operation, the process ends. This process, through a closed-loop logic of "verification-repair-iteration-stop judgment," achieves compliance assurance and optimized output of SMV candidate code.

[0092] Once the primary structural compliance check passes, the secondary formal verification is triggered. Specifically, the secondary formal verification of the SMV candidate code includes the following steps:

[0093] The nuXmv tool is invoked to perform syntax and model checks on the SMV candidate code that has passed the first-level structure compliance check.

[0094] If the nuXmv tool outputs the error information, the error information is structured into repair instructions; the repair instructions include the error type, error location, error context, and repair prompts.

[0095] nuXmv is a formal verification tool specifically designed to check SMV code, including syntactic correctness (e.g., whether variables are declared, whether semicolons are missing) and logical rationality (e.g., whether deadlocks exist, whether properties are satisfied). In this embodiment, nuXmv is invoked to perform secondary formal verification on SMV candidate code that has passed the structural compliance check. Secondary formal verification is a syntax / model check. If syntax errors or unsatisfied properties are found, the error location (line number / paragraph), error type (e.g., undefined variable, mismatched parentheses), and error context are extracted to form a repair hint containing specific modification actions. The error information is structured into repair instructions expressed in a fixed four-tuple form {stage, location, message, fix_hint} for subsequent regeneration or manual review.

[0096] For example, the mapping from errors to fixes: For instance, `undefined symbol` → a mapping added to the declaration in `VAR / DEFINE`, generating specific rules for generating syntax error fix instructions, clearly defining "where to fix and how to fix"; `propertyviolated` → a mapping added to state invariants or adjustment transitions, generating specific rules for generating property violation fix instructions. As can be seen, these mapping rules provide an operable error-solution correspondence logic for the structured fix instructions, ensuring the effective execution of the differential fix mechanism.

[0097] In this embodiment, a closed-loop execution is optional. Without a closed loop, the first round of verification results and an error report are output. Upon success, the target SMV model and verification report are output, and process metadata (error type, repair instructions, iteration rounds, time consumption, etc.) is archived. With a closed loop, the loop can be executed within a preset maximum number of iterations or a success threshold (e.g., all properties pass verification). During regeneration, error information is structured into repair instructions, and a differential hint mechanism ensures that the large language model undergoes minimal modification only in specified segments.

[0098] Specifically, when the SMV candidate code contains error information, the error information is structured into repair instructions, and the prompt information is reconstructed according to the repair instructions. Then, the process jumps to the step of generating SMV candidate code based on the prompt information using the large language model. When all properties of the secondary formal verification pass the verification, or the number of iterations for repair reaches a preset threshold, the target SMV code is output.

[0099] Iterative repair based on the repair instructions and the prompts can ensure that the large language model is only modified to a minimum in the specified segments, rather than being regenerated entirely, through the differential prompt mechanism. This significantly reduces the repetition error rate and improves the iteration convergence speed.

[0100] It should be noted that, typically, the first step is to determine whether all properties of the second-level formal verification have passed. Once all properties have passed, the target SMV code is output. If generating the target SMV code takes too long, it can also be determined whether the number of iterations has reached a preset threshold. When the number of iterations reaches the preset threshold, the target SMV code is output.

[0101] In summary, this invention utilizes multi-dimensional quality metrics, including structural integrity rate, first-pass yield, average number of iterations, and total duration, to quantitatively assess its reliability and efficiency. Simultaneously, it structurally feeds back error information to the prompts, enabling targeted repair and regeneration based on error type, resulting in faster convergence and controllable iteration. The entire process records prompts, failure types, repair instructions, and verification results, supporting quality measurement and auditing. Furthermore, it is easily integrated, implementable on LLM and nuXmv toolchains without requiring modifications to the nuXmv kernel, facilitating engineering deployment.

[0102] Accordingly, this application also discloses an SMV code automatic generation device, in which each module communicates via a bus or message queue, see [link to relevant documentation]. Figure 5 As shown, the device includes:

[0103] The input and extraction module 11 is used to receive natural language requirement text and extract the specification fragments that constitute the SMV code framework from the natural language requirement text.

[0104] The prompt construction module 12 is used to construct prompt information to guide the output of the large language model based on the specification fragment, and to generate SMV candidate code using the large language model according to the prompt information. The prompt information includes system messages and user messages, wherein the system messages are used to limit the code generation rules of the large language model; the user messages are used to constrain the large language model to complete the missing parts of the SMV candidate code, and include the specification fragment and the remaining natural language description in the natural language requirement text that has not been extracted as the specification fragment.

[0105] The dual-level verification module, 13, is used to perform a first-level structural compliance check and a second-level formal verification on the SMV candidate code in sequence.

[0106] The code generation module 14 is used to structure the error information into repair instructions when there is error information in the SMV candidate code, so as to iteratively repair the SMV candidate code until the SMV candidate code meets the preset stopping conditions, and then output the target SMV code.

[0107] For more detailed information on the working process of each of the above modules, please refer to the relevant content disclosed in the foregoing embodiments, which will not be repeated here.

[0108] Therefore, the above-described scheme in this embodiment, through the precise extraction of SMV specification fragments from natural language requirements and the targeted construction of prompting engineering, guides the large language model to prioritize the generation of structured SMV candidate code, reducing the structural missing rate in the initial generation stage. Then, using a two-level verification mechanism, firstly, a first-level structural compliance check eliminates basic framework errors, and then a second-level formal verification captures deep logical defects, accurately locating the error position and type. Each error message is structured into precise repair instructions to drive model regeneration, and the final output target SMV code not only meets compilation requirements but also passes all property verifications. This progressive two-level verification and closed-loop repair mechanism not only significantly reduces failures caused by structural missing and syntax errors but also allows most errors in the natural language conversion process to be corrected early in the iteration process. This significantly reduces the cost of repeated trial and error and the need for manual intervention, ultimately achieving a synergistic improvement in the structural integrity and logical correctness of the generated code.

[0109] Furthermore, embodiments of this application also disclose an electronic device, Figure 6 This is a structural diagram of an electronic device 20 according to an exemplary embodiment. The content of the diagram should not be construed as limiting the scope of this application.

[0110] Figure 6This is a schematic diagram of the structure of an electronic device 20 provided in an embodiment of this application. Specifically, the electronic device 20 may include: at least one processor 21, at least one memory 22, a power supply 23, a communication interface 24, an input / output interface 25, and a communication bus 26. The memory 22 stores a computer program, which is loaded and executed by the processor 21 to implement the relevant steps in the SMV code automatic generation method disclosed in any of the foregoing embodiments. Alternatively, the electronic device 20 in this embodiment may specifically be a computer.

[0111] In this embodiment, the power supply 23 is used to provide operating voltage for each hardware device on the electronic device 20; the communication interface 24 can create a data transmission channel between the electronic device 20 and external devices, and the communication protocol it follows can be any communication protocol applicable to the technical solution of this application, and is not specifically limited here; the input / output interface 25 is used to acquire external input data or output data to the outside world, and its specific interface type can be selected according to specific application needs, and is not specifically limited here.

[0112] In addition, the memory 22, as a carrier for resource storage, can be a read-only memory, random access memory, disk, or optical disk, etc. The resources stored on it can include an operating system 221, computer programs 222, and data 223, etc. The data 223 can include various types of data. The storage method can be temporary storage or permanent storage.

[0113] The operating system 221 is used to manage and control the various hardware devices on the electronic device 20 and the computer program 222, which may be Windows Server, Netware, Unix, Linux, etc. In addition to including a computer program capable of performing the SMV code automatic generation method executed by the electronic device 20 as disclosed in any of the foregoing embodiments, the computer program 222 may further include a computer program capable of performing other specific tasks.

[0114] Furthermore, this application also discloses a computer-readable storage medium, which includes random access memory (RAM), main memory, read-only memory (ROM), electrically programmable ROM, electrically erasable programmable ROM, registers, hard disks, magnetic disks, optical disks, or any other form of storage medium known in the art. The computer program, when executed by a processor, implements the aforementioned SMV code automatic generation method. Specific steps of this method can be found in the corresponding content disclosed in the foregoing embodiments, and will not be repeated here.

[0115] Furthermore, embodiments of this application also provide a computer program product, including a computer program / instruction, which, when executed by a processor, implements any of the above-described methods for automatically generating SMV code.

[0116] The various embodiments in this specification are described in a progressive manner, with each embodiment focusing on its differences from other embodiments. Similar or identical parts between embodiments can be referred to interchangeably. For the apparatus disclosed in the embodiments, since it corresponds to the method disclosed in the embodiments, the description is relatively simple; relevant parts can be referred to in the method section.

[0117] The steps of the SMV code automatic generation method or algorithm described in conjunction with the embodiments disclosed herein can be implemented directly by hardware, a software module executed by a processor, or a combination of both. The software module can be located in random access memory (RAM), main memory, read-only memory (ROM), electrically programmable ROM, electrically erasable programmable ROM, registers, hard disk, removable disk, CD-ROM, or any other form of storage medium known in the art.

[0118] Finally, it should be noted that in this document, relational terms such as "first" and "second" are used only to distinguish one entity or operation from another, and do not necessarily require or imply any such actual relationship or order between these entities or operations. Furthermore, the terms "comprising," "including," or any other variations thereof are intended to cover non-exclusive inclusion, such that a process, method, article, or apparatus that comprises a list of elements includes not only those elements but also other elements not expressly listed, or elements inherent to such a process, method, article, or apparatus. Without further limitations, an element defined by the phrase "comprising one..." does not exclude the presence of other identical elements in the process, method, article, or apparatus that includes said element.

[0119] The above provides a detailed description of the SMV code automatic generation method, apparatus, device, and medium provided by the present invention. Specific examples have been used to illustrate the principles and implementation methods of the present invention. The descriptions of the above embodiments are only intended to help understand the method and core ideas of the present invention. At the same time, for those skilled in the art, there will be changes in the specific implementation methods and application scope based on the ideas of the present invention. Therefore, the content of this specification should not be construed as a limitation of the present invention.

Claims

1. A method for automatically generating SMV code, characterized in that, include: Receive natural language requirement text and extract the specification fragments that constitute the SMV code framework from the natural language requirement text; Based on the specified fragment, prompting information is constructed to guide the output of the large language model, and the large language model is used to generate SMV candidate codes according to the prompting information. The prompting information includes system messages and user messages, wherein the system messages are used to limit the code generation rules of the large language model; the user messages are used to constrain the large language model to complete the missing parts of the SMV candidate codes, including the specified fragment and the remaining natural language descriptions in the natural language requirement text that were not extracted as the specified fragment. The SMV candidate code is subjected to a first-level structural compliance check and a second-level formal verification in sequence. When there are error messages in the SMV candidate code, the error messages are structured into repair instructions to iteratively repair the SMV candidate code until the SMV candidate code meets the preset stopping conditions, and then the target SMV code is output.

2. The SMV code automatic generation method according to claim 1, characterized in that, The specification fragment includes at least one of the following: module definition, variable declaration, initial state setting, state transition relationship definition, and time sequence logic property definition.

3. The SMV code automatic generation method according to claim 2, characterized in that, Also includes: A dedicated low-rank adaptation matrix is ​​configured for the module definition, the variable declaration, the initial state setting, and the state transition relationship definition; The large language model is fine-tuned based on the low-rank adaptation method, and the low-rank adaptation matrix is ​​injected into the attention projection layer of the large language model to generate the fine-tuned model. Accordingly, using the large language model, SMV candidate codes are generated based on the prompt information, including: Using the fine-tuned model, SMV candidate codes are generated based on the prompt information.

4. The SMV code automatic generation method according to claim 2, characterized in that, Perform a first-level structural compliance check on the SMV candidate code, including: The SMV candidate code is subjected to template constraint verification using a predefined structure template to check whether the SMV candidate code fully contains the module definition, the variable declaration, the initial state setting and the state transition relationship definition, and whether the SMV candidate code contains at least one of the temporal logic property definitions; The SMV candidate code is scanned using regular expressions to check the syntactic integrity of the SMV candidate code. If both the template constraint verification and the regular expression matching scan pass, the SMV candidate code is determined to have passed the first-level structural compliance check, and the second-level formal verification is triggered. If the template constraint validation and / or the regular expression matching scan fails, the missing item is obtained, and the prompt information is reconstructed based on the missing item. Then, the process jumps to the step of generating SMV candidate code based on the prompt information using the large language model.

5. The SMV code automatic generation method according to claim 1, characterized in that, The SMV candidate code is subjected to a second-level formal verification, including: The nuXmv tool is invoked to perform syntax and model checks on the SMV candidate code that has passed the first-level structure compliance check. Accordingly, when the SMV candidate code contains error information, structuring the error information into repair instructions includes: If the nuXmv tool outputs the error information, the error information is structured into repair instructions; the repair instructions include the error type, error location, error context, and repair prompts.

6. The SMV code automatic generation method according to claim 1, characterized in that, When the SMV candidate code contains error information, the error information is structured into repair instructions to iteratively repair the SMV candidate code until the SMV candidate code meets a preset stopping condition, and then the target SMV code is output, including: When the SMV candidate code contains error information, the error information is structured into repair instructions, and the prompt information is reconstructed according to the repair instructions. Then, the process jumps to the step of generating SMV candidate code based on the prompt information using the large language model. When all properties of the secondary formal verification pass the verification, or when the number of iterations for repair reaches a preset threshold, the target SMV code is output.

7. The SMV code automatic generation method according to any one of claims 1 to 6, characterized in that, The step of generating SMV candidate codes based on the prompt information using the large language model includes: By using multi-sample sampling and the large language model, multiple SMV candidate codes are generated at once based on the prompt information; Correspondingly, the SMV code automatic generation method further includes: The steps of performing first-level structural compliance checks and second-level formal verifications on the multiple SMV candidate codes in parallel are executed, and the SMV candidate code that first meets the preset stopping condition is selected as the target SMV code.

8. An SMV code automatic generation device, characterized in that, include: The input and extraction module is used to receive natural language requirement text and extract the specification fragments that constitute the SMV code framework from the natural language requirement text. A prompting construction module is used to construct prompting information to guide the output of the large language model based on the specified fragment, and to generate SMV candidate code using the large language model according to the prompting information. The prompting information includes system messages and user messages, wherein the system messages are used to limit the code generation rules of the large language model; the user messages are used to constrain the large language model to complete the missing parts of the SMV candidate code, and include the specified fragment and the remaining natural language description in the natural language requirement text that has not been extracted as the specified fragment. A two-level verification module is used to perform a first-level structural compliance check and a second-level formal verification on the SMV candidate code in sequence. The code generation module is used to structure the error information into repair instructions when there is error information in the SMV candidate code, so as to iteratively repair the SMV candidate code until the SMV candidate code meets the preset stopping conditions, and then output the target SMV code.

9. An electronic device, characterized in that, The electronic device includes a processor and a memory; wherein the memory is used to store a computer program, which is loaded and executed by the processor to implement the SMV code automatic generation method as described in any one of claims 1 to 7.

10. A computer-readable storage medium, characterized in that, Used to store computer programs; wherein the computer programs, when executed by a processor, implement the SMV code automatic generation method as described in any one of claims 1 to 7.