Sewage treatment activated sludge model generation method based on large language model
By generating JSON files of activated sludge models from large language models and fine-tuning them to generate Python code, the problem of complex and time-consuming model construction in existing technologies is solved, enabling the efficient application of activated sludge models in the field of wastewater treatment.
Patent Information
- Application Number
- CN202511815747.7
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Filing Date
- 2025-12-04
- Publication Date
- 2026-03-06
AI Technical Summary
Existing activated sludge modeling software suffers from closed-source characteristics that limit the use of user-defined and data-driven models, resulting in complex, time-consuming, and costly model construction, making it difficult to widely apply in the field of wastewater treatment.
A JSON file of an activated sludge model is generated using a large language model, and executable Python code is generated through fine-tuning. The model information is extracted and the code is generated by combining the open-source large language model, so as to realize the functions of dynamic simulation, steady-state simulation, sensitivity analysis and parameter estimation.
The process of constructing activated sludge models has been simplified, labor costs have been reduced, and the efficiency and compatibility of the models in practical applications have been improved, enabling the widespread application of activated sludge models in the field of wastewater treatment.
Smart Images

Figure CN121617484A_ABST
Abstract
Description
Technical Field
[0001] This invention relates to the field of wastewater treatment technology, and in particular to a method for generating activated sludge models for wastewater treatment based on a large language model. Background Technology
[0002] The Activated Sludge Model (ASM) is a quantitative modeling tool that describes the microbial growth, substrate degradation, and nutrient transformation processes in wastewater treatment bioreactors using mathematical formulas and variable combinations based on prior mechanistic knowledge. Although ASM software offers relatively complete reactor deployment and model parameter optimization processes, its closed-source nature limits users to using pre-designed modules. Users cannot directly develop and validate new microbial metabolic processes in wastewater biological treatment within the software, and it is also difficult to directly integrate current mainstream data-driven modeling methods with the software.
[0003] For research users, writing an ASM from scratch is extremely complex, involving numerous steps. Taking the AQUASIM open-source software as an example, users need to design and manually input all state variables, constant variables, system variables, and other variable parameters; design and manually input all stoichiometric coefficients and kinetic equations; design and manually input reactor configuration, connection details, and input information; and conduct parameter tuning processes such as model sensitivity analysis, uncertainty analysis, and parameter estimation. The more reaction processes and variables involved in an ASM, the more complex the model becomes, making it extremely prone to errors. Model building and calibration often require months of time, resulting in significant labor and time costs. All of these issues limit the practical application of ASM in the field of wastewater treatment. Summary of the Invention
[0004] Purpose of the invention: The purpose of this invention is to provide a method for generating activated sludge models for wastewater treatment based on user natural language using a large language model. This method includes functions such as dynamic simulation, steady-state simulation, sensitivity analysis, uncertainty analysis, and parameter estimation.
[0005] Technical Solution: To achieve the above objectives, the present invention provides a method for generating activated sludge models for wastewater treatment based on a large language model, comprising the following steps:
[0006] S1. Generate an activated sludge model JSON file based on a closed-source large language model;
[0007] S2. Generate executable Python code for the activated sludge model applied to wastewater treatment based on the JSON file and code prompts of the activated sludge model;
[0008] S3. Construct a fine-tuning dataset for an open-source large language model. Each fine-tuning dataset consists of a user input instruction and an executable Python code generated by S2. The user input instruction is a piece of natural language that generates the executable Python code for the wastewater treatment activated sludge model.
[0009] S4. Use the fine-tuning dataset to fine-tune the open-source large language model and obtain the open-source large language model with fine-tuned parameters.
[0010] S5. Based on a finely tuned open-source large language model, Python code for generating activated sludge models for wastewater treatment is generated using user natural language.
[0011] Preferably, the generation method described in S1 is as follows: obtaining literature text and report text containing activated sludge model information, extracting model information from the text using a closed-source large language model and ASM to extract prompt words, and storing it as a JSON format file.
[0012] Preferably, the model information includes model name, simulation objective, key assumptions, variables, process, reactor structure, and reactor connections.
[0013] Preferably, the generation method described in S2 is as follows: using DeepSeek Web Edition to generate executable Python code, the executable Python code is compiled into an executable file (exe) in the Windows system, which has an interactive UI interface after running, and has functions related to wastewater dynamic simulation, steady-state simulation, sensitivity analysis, uncertainty analysis and parameter estimation.
[0014] Preferably, the executable Python code is tested, including: executing the generated Python code in the local PyCharm client to test whether the code can meet the functional requirements. If it can, the Python code is saved for later use; if not, the Python code is uploaded to the DeepSeek web version, and prompts are written based on the code errors or missing functions. The DeepSeek web version automatically corrects the Python code based on the prompt content and generates new corrected Python code until the corresponding executable Python code generated from each JSON file meets the requirements.
[0015] Preferably, the fine-tuning data described in S3 is summarized in a JSON file as the fine-tuning dataset file "data.json".
[0016] Preferably, the fine-tuning method described in S4 is as follows:
[0017] The open-source large language model is fine-tuned using the llama_factory web UI. The open-source large language model to be fine-tuned is selected in the web UI and downloaded.
[0018] Place the fine-tuned dataset file "data.json" in the folder where llama_factory stores local datasets, and modify the dataset_info.json file of llama_factory to add a description of the fine-tuned dataset;
[0019] After selecting the open-source large language model to be fine-tuned and the fine-tuning dataset in the web UI, perform parameter fine-tuning. Once the fine-tuning process is complete and the error converges, save the fine-tuned open-source large language model to your local computer in the web UI.
[0020] Preferably, the fine-tuning dataset is described as follows:
[0021] "dataset_name": {
[0022] "file_name": "data.json",
[0023] "columns": {
[0024] "prompt": "instruction",
[0025] "query": "input",
[0026] "response": "output",
[0027] "system": "system",
[0028] "history": "history
[0029] }
[0030] }
[0031] Preferably, the parameters for fine-tuning include:
[0032] QLoRA quantification level = 4;
[0033] Acceleration method = liger_kernel;
[0034] Learning rate 2e-4;
[0035] Batch size is set to 1, gradient accumulation is 16;
[0036] Validation set ratio 0;
[0037] LoRA drop 0.05, targeting modules q_proj and v_proj.
[0038] Beneficial effects: The present invention has the following advantages: The present invention automatically generates Python executable code for the activated sludge model of wastewater treatment based on the user's natural language through a finely tuned open source large language model. This solves the problems of complex process, cumbersome procedures, time and labor consumption, and poor compatibility with data-driven models written in Python code when remodeling based on the existing activated sludge model. It realizes the practical application of the activated sludge model in the field of wastewater treatment. Attached Figure Description
[0039] Figure 1 This is a schematic diagram of the method flow of the present invention;
[0040] Figure 2 Here are some brief UI screenshots;
[0041] Figure 3 To dynamically simulate the UI interface;
[0042] Figure 4 This is a UI diagram for steady-state simulation.
[0043] Figure 5 UI diagram for sensitivity analysis;
[0044] Figure 6 UI diagram for uncertainty analysis;
[0045] Figure 7 UI diagram for parameter estimation. Detailed Implementation
[0046] The technical solution of the present invention will be described in detail below with reference to the embodiments and accompanying drawings.
[0047] like Figure 1 As shown, the wastewater treatment activated sludge model generation method based on a large language model according to the present invention includes the following:
[0048] S1. Generate an activated sludge model JSON file.
[0049] Obtain literature and report texts containing activated sludge model information (e.g., search for academic papers containing "mechanistic model" and "activated sludge model" on the Web of Science website and download all PDF text files containing this content). Use a closed-source large language model and ASM to extract prompt words to extract model information from the text and store it as a JSON file. The model information includes model name, simulation objective, key assumptions, variables, process, reactor structure, and reactor connections.
[0050] Preferably, DeepSeek Web Edition is used to extract model information from text files. During each extraction process, a PDF text file is uploaded to DeepSeek Web Edition, and ASM extraction prompt words are used as prompts to extract model information from the uploaded file. Each PDF text file will form a JSON format file containing model information after extraction.
[0051] The ASM used in this example to extract part of the prompt words is as follows:
[0052] You are a world-class expert in environmental engineering and computational modeling of wastewater biological treatment processes. Yourexpertise lies in meticulously analyzing scientific literature to deconstruct and understand mechanistic models like the Activated Sludge Models (ASM).
[0053] I will provide you with an academic paper. Your task is to act as aprecise information extraction tool. Carefully read the provided text andextract the key components of the mechanistic model. You must identify andpopulate the following fields. If a piece of information is not present in the text, use `null` as the value.
[0054] You MUST provide your output in a valid JSON format. Do not add anyexplanations before or after the JSON object. The JSON structure is asfollows:
[0055] {
[0056] "model_name": "The official name or abbreviation of the model(e.g., 'ASM2d').",
[0057] "objective": "A concise summary of what the model aims to simulateor predict.",
[0058] "key_assumptions": [
[0059] "A list of key simplifying assumptions the model is built upon(e.g., 'Constant temperature', 'Completely mixed reactor')."
[0060] ],
[0061] "variables": [
[0062] {
[0063] "symbol": "The mathematical symbol used (e.g., 'S_O', ' Y_H,S','μ_PAB'). Don’t use {}.",
[0064] "description": "A clear description of the variable (e.g., 'Dissolved oxygen concentration', 'Maximum specific growth rate ofheterotrophs').",
[0065] "type": "the variable type (e.g., 'state variable, programvariable, constant variable (stoichiometric coefficient and kineticcoefficient were constant variables), real list variable, variable listvariable, formula variable, probe variable.').",
[0066] "value": "the reported numerical value (as a number, not stringfor constant variable, ‘null’ for state variable).",
[0067] "unit": "The unit of measurement (e.g., 'mg / L' or 'gCOD / m^3')."
[0068] }
[0069] ],
[0070] "processes": [
[0071] {
[0072] "process_name": "The name of the biochemical process (e.g., 'Aerobic growth of heterotrophs'). The sequence of the process is listedaccording to the order of the table in the article.",
[0073] "rate_equation": "The kinetic rate equation for this processwith kinetic coefficient, written in LaTeX format (e.g., 'b_H * S_O / (K_O,H+ S_O) * X_H'). Only variables defined in "variables" can be used. Write inthe format defined in the "variables" section. Use * as multiplicationsymbol, use / as division symbol."
[0074] "involved_variables": "List of all state variables involved inthis process (e.g., "S_O")."
[0075] "involved_stoichiometric_coefficient": "List of the wholeequation of the stoichiometric coefficient for every involved state variablein this process (e.g., "-(1 - Y_H,S) / Y_H,S for S_O"). Every involved statevariable has a stoichiometric coefficient equation.",
[0076] }
[0077] ],
[0078] "compartments": [
[0079] {
[0080] "compartment_name": "The name of the compartment (e.g., 'aerobic reactor No.1').",
[0081] "involved_processes": "The involved processes in thiscompartment (e.g., 'Aerobic growth of heterotrophs') ",
[0082] "involved_variables": "The involved variables in thiscompartment (e.g., "S_O") ",
[0083] "initial_conditions": "The initial conditions of thiscompartment including initial microbial concentrations of involved variables,initial pollutant concentrations of involved variables and initial values ofother variables (e.g., the initial X_H=2664 mg / L). Only defined variablescould be used in this section.",
[0084] "input_conditions": "The input of this compartment from waterflow. The input contains involved variables in influent wastewater or theinvolved variables in influent from other compartment (e.g., influent S_S=300mg COD / L). Only defined variables could be used in this section. ",
[0085] "volume": "The volume of this compartment",
[0086] "volume unit": "m3 or L",
[0087] }
[0088] ],
[0089] "links": [
[0090] {
[0091] "link_structure": "The water link among different compartments(eg, "outflow of anaerobic compartment No.1 to the inflow of oxiccompartment No.1"). If there is no link among different compartments, link is"null",
[0092] } ]
[0094] }
[0095] Furthermore, the information in the JSON format file is calibrated and improved. Since DeepSeek may produce errors or omissions during information extraction, the extracted JSON file needs to be verified. The content of the JSON file extracted from each literature PDF text file is compared with the content of the corresponding literature PDF text file to calibrate and improve the JSON file content, ensuring that the JSON file can correctly and completely record the model information in the literature PDF text file.
[0096] S2. Generate executable Python code for the activated sludge model based on the JSON file of the activated sludge model.
[0097] By using a closed-source large language model and ASM-Python code to generate prompt words, combined with the activated sludge model information in the JSON file, executable Python code for the activated sludge model is generated.
[0098] Preferably, DeepSeek Web Edition is used to generate executable Python code. The executable Python code can be compiled into an executable file (exe) for Windows systems. After running, it will have an interactive UI interface and the ability to correctly perform dynamic simulation, steady-state simulation, sensitivity analysis, uncertainty analysis, and parameter estimation.
[0099] This is an example of ASM-Python code generating suggestion words. It is not limited to these suggestion words; the fine-tuned large language model will generate model Python code based on the user's suggestion words.
[0100] "Construct executable Python code for the activated sludge model and UI interface of wastewater treatment in BSM1. It should have functions such as interface introduction of simulation process parameters, dynamic simulation, steady-state simulation, sensitivity analysis, uncertainty analysis, and parameter estimation. It should also be able to display and download simulation result graphs and data in the results interface."
[0101] "Build the executable Python code for the activated sludge model andUI interface of wastewater treatment in BSM1, which should have the functions of interface introduction, dynamic simulation, steady simulation, sensitivity analysis, uncertainty analysis and parameter estimation of the simulation process parameters, and be able to display and download the simulation resultdiagrams and data in the results interface."
[0102] Furthermore, the Python code is tested and refined. The generated Python code is executed in the local PyCharm client to test if it meets the functional requirements. If it does, the Python code is saved for later use; otherwise, it is uploaded to the DeepSeek web version. Based on the code errors or missing functions, prompts are written, and the DeepSeek web version automatically corrects the Python code based on the prompts, generating new, revised Python code. This process continues until the executable Python code generated from each JSON file meets the requirements.
[0103] like Figure 2 As shown, the UI interface and specific functions are described below:
[0104] 1. Introduction: A textual description of the ASM reaction process and the functions of the UI interface.
[0105] 2. Dynamic Simulation: It has the function of loading local influent data files in CSV format, can display the loaded influent data, can modify and apply model parameter values, can perform dynamic simulation of effluent data and microbial data based on the uploaded influent data and applied model parameters, and display the simulation result data graph on the results page.
[0106] like Figure 3 As shown, the dynamic model's operating logic is driven by uploaded CSV format influent data, using linear interpolation to continuously acquire influent concentrations across discrete time points, ensuring a smooth transition of dynamic inputs. Secondly, the model describes the mass balance of the entire system through a system of ordinary differential equations (ODEs). In the bioreactor section, the concentration changes of each component (such as COD, nitrogen compounds, and biomass) are calculated based on biological process rates (e.g., aerobic / anoxic growth of heterotrophic bacteria, growth, decay, ammonification, hydrolysis, etc.) and conversion rates. An oxygen mass transfer term (kLa*(SO_sat-SO)) is introduced for the aerobic reactor to simulate the aeration effect. The sedimentation tank section uses the Vesilind sedimentation model, calculating the sludge concentration distribution in each layer based on solid flux theory, and coupling it with the solid-liquid separation process of the reactor effluent. Numerical solutions are obtained using the SciPy solve_ivp function, employing the BDF (backward differential formula) method to handle rigid systems, ensuring stable integration over long time spans. Furthermore, the model supports real-time parameter adjustment (such as kinetic coefficients and stoichiometric parameters), dynamically updating and resolving through a GUI interface. Multi-threading technology is employed to prevent simulation from blocking the main interface, and a progress bar provides real-time feedback on the calculation status. The simulation results ultimately extract key effluent indicators (such as SNH, SNO, SS, biomass, and OUR) and visualize them. It also supports exporting complete state variables and data as PNG charts and XLSX files for subsequent analysis and validation.
[0107] 3. Steady-state simulation: The simulation duration, model parameter values, and influent parameter values can be modified. Based on the modified results, steady-state simulation of effluent data and microbial data can be performed, and the simulation results data graphs can be displayed on the results page.
[0108] like Figure 4 As shown, the steady-state simulation operation logic is based on the ASM model operating under constant influent conditions. It simulates the process of the wastewater treatment system reaching a steady state under fixed operating conditions by solving the rigid ordinary differential equations (ODEs) describing the transformation and transport of pollutants in the bioreactor and secondary sedimentation tank. Technically, the Python code uses the SciPy solver_ivp and selects the BDF (Backward Difference Formula) method, an implicit multi-step algorithm suitable for rigid systems. Adaptive step size control ensures numerical stability, while approximation of the Jacobian matrix improves computational efficiency.
[0109] 4. Sensitivity Analysis: Sensitivity analysis parameters can be set, and model parameters and output variables in ASM can be customized to perform sensitivity analysis. The analysis results data graphs are displayed on the results page.
[0110] like Figure 5 As shown, the sensitivity analysis operation logic employs the Morris global sensitivity analysis method. It uses a Morris trajectory sampling strategy to systematically perturb the parameters within a user-specified range: after randomly generating initial parameter points, each selected parameter is sequentially changed along a random direction with a fixed step size, forming multiple parameter trajectories to cover the entire uncertainty space. Subsequently, a steady-state simulation model is invoked for each set of sampled parameters, running a simulation for a specified duration. Target variables (SNH, SNO, SS) are extracted from the final effluent water quality data, while the oxygen uptake rate (OUR) is dynamically calculated based on the real-time process rate. Based on the simulation output, the basic effect of each parameter is calculated, and the absolute mean (μ*) measuring the intensity of the parameter's influence, the mean (μ) indicating the direction of influence, and the standard deviation (σ) reflecting nonlinearity or interaction are statistically derived. Finally, the analysis results are visualized through multi-dimensional charts, including parameter sensitivity ranking, Morris scatter plots, and statistical distribution plots. The system supports exporting complete sampling data, sensitivity indicators, and charts into structured reports, thus systematically identifying the most critical model parameters affecting effluent water quality and providing quantitative basis for subsequent model calibration, simplification, and process optimization.
[0111] 5. Uncertainty Analysis: Uncertainty analysis parameters can be set, and model parameters and output variables in ASM can be customized to perform uncertainty analysis. The analysis results data graphs are displayed on the results page.
[0112] like Figure 6 As shown, the uncertainty analysis logic is based on the Monte Carlo method, quantifying the uncertainty of the model output by randomly sampling parameter values. The technical implementation details include four core steps: First, the system generates random samples based on the user-selected parameters and their distribution type (normal or uniform). For normal distributions, a truncated normal distribution is used to ensure the sampled values are within a specified range; for uniform distributions, direct uniform sampling is used. Second, for each parameter sample combination, the model parameters are dynamically updated and a steady-state simulation is run to obtain the key output variables (SNH, SNO, SS, and the calculated OUR) at the final time step. Third, all simulation output results are collected, and statistical indicators (mean, standard deviation, minimum, maximum, median, and 5% and 95th percentiles) are calculated. Finally, the output distribution characteristics are visualized through histograms, box plots, and statistical charts. The entire process runs in an independent thread to avoid interface blocking and is equipped with a progress bar to provide real-time feedback on the simulation progress. Ultimately, the parameter samples, output results, and statistical analysis are integrated into structured data, supporting result download and visualization.
[0113] 6. Parameter estimation: It has the function of loading local experimental data files in CSV format, can set the rounds of parameter estimation, can customize the selection of model parameters and output variables in ASM for parameter estimation, and displays the parameter estimation results data graph on the results page.
[0114] like Figure 7 As shown, the parameter estimation logic employs the Nelder-Mead optimization method (a gradient-free optimization algorithm) to estimate key biokinetic parameters by minimizing the χ² error between the simulated output and the experimental data. First, the system allows the user to select the parameters to be estimated (such as heterotrophic bacterial yield YH, autotrophic bacterial yield YA, maximum specific growth rate μH / μA, etc.) and set reasonable upper and lower bounds for each parameter. Experimental data must be provided in CSV format, including time-series measurements (SNH ammonia nitrogen, SNO nitrate nitrogen, OUR oxygen uptake, SS biodegradable substrate) and their standard deviations.
[0115] The core optimization process is achieved through the χ² objective function: for a given parameter set, the system runs a steady-state simulation and calculates the weighted sum of squared residuals between the simulated values and the experimental measurements, with the weights being the reciprocal of the standard deviation of the measurements. To handle parameter boundary constraints, the system uses an arctangent transform to map the finite interval [min, max] to an unbounded space [-π / 2, π / 2], enabling the Nelder-Mead algorithm to optimize under unconstrained conditions. During the optimization process, each iteration maps the parameters back to the original space through an inverse transform, sets the model parameters, runs the simulation, and calculates the χ² value.
[0116] In implementation, the system utilizes SciPy's `minimize` function to perform Nelder-Mead optimization, avoiding GUI blocking through a separate thread and providing real-time progress feedback. After optimization, the system compares the initial and optimized parameter values, calculates the degree of improvement (χ²), and runs comparative simulations to visualize the fitting effect. Results analysis includes the percentage change in parameters, the reduction in χ², and an assessment of the overlap between the simulated curve and experimental data. All results are visualized using multi-subplots to show the parameter optimization trajectory, the improvement in fitting quality, and the final fitted curve.
[0117] Ultimately, the optimized parameters can be updated to the model and used for subsequent simulations, while providing complete analysis reports and chart export functions, realizing a complete workflow from experimental data to model parameter calibration.
[0118] 7. Results: Once a simulation, analysis, or parameter estimation is completed, the results will be displayed in graphs, and a download button will be provided to download the results graphs and the corresponding data files (xlsx format).
[0119] S3. Construct a fine-tuning dataset for the open-source large language model. Each fine-tuning data point in the dataset consists of a user input instruction and a large language model output. The user input instruction is a piece of natural language that generates executable Python code for the activated sludge model, specifying the reaction processes and code functions within the model. The large language model output is the executable Python code generated in S2. By mapping the natural language code to the executable Python code, the fine-tuning dataset for the large language model is formed.
[0120] Each piece of fine-tuning data in the fine-tuning dataset can be constructed according to the following format: [
[0122] {
[0123] "instruction": "Human instruction (required)",
[0124] "input": "Human input (optional)",
[0125] "output": "Model response (required)",
[0126] "system": "System prompt word (optional)",
[0127] "history": [
[0128] ["First Round Instructions (Optional)", "First Round Response (Optional)"],
[0129] ["Second round instructions (optional)", "Second round responses (optional)"] ]
[0131] } ]
[0133] The user's natural language requirement should be filled in the "instruction" field, the corresponding executable Python code should be filled in the "output" field, and other optional fields can be omitted.
[0134] All fine-tuning data is compiled into a single JSON file as the fine-tuning dataset file "data.json".
[0135] S4. Use the fine-tuning dataset to fine-tune the open-source large language model to obtain the open-source large language model with fine-tuned parameters.
[0136] 1. First, download the open-source large language model to be fine-tuned. If you are using the web UI of llama_factory to fine-tune the large language model, select the open-source large language model to be fine-tuned (Qwen2.5-coder 7B) in the web UI, and the web UI will automatically download the model to your local machine.
[0137] 2. Place the fine-tuned dataset file "data.json" in the folder where llama_factory stores local datasets, and modify the dataset_info.json file of llama_factory to add a description of the fine-tuned dataset:
[0138] "dataset_name": {
[0139] "file_name": "data.json",
[0140] "columns": {
[0141] "prompt": "instruction",
[0142] "query": "input",
[0143] "response": "output",
[0144] "system": "system",
[0145] "history": "history
[0146] }
[0147] }
[0148] Once completed, you can find data.json in the web UI and use it to fine-tune the dataset.
[0149] 3. After selecting the open-source large language model and the dataset to be fine-tuned in the web UI, select the fine-tuning parameters as follows:
[0150] QLoRA quantification level = 4;
[0151] Acceleration method = liger_kernel;
[0152] Learning rate 2e-4;
[0153] Batch size is set to 1, gradient accumulation is 16;
[0154] Validation set ratio 0;
[0155] LoRA drop 0.05, affecting modules q_proj and v_proj;
[0156] After selecting all parameters, the fine-tuning process is executed. The web UI will automatically perform the fine-tuning. Once the fine-tuning process is complete and the error converges, the fine-tuned open-source large language model is saved in the web UI to the local computer.
[0157] 4. Testing the fine-tuned open-source large language model
[0158] Using the web UI of llama_factory to load the finely tuned open-source large language model, in the test interface, the user enters a natural language description of the reaction process and code functions in ASM. The finely tuned open-source large language model can automatically generate executable Python code that meets the requirements and has complete functions based on the natural language.
[0159] S5. Based on a finely tuned open-source large language model, Python code for generating activated sludge models for wastewater treatment is generated using user natural language.
Claims
1. A method for generating an activated sludge model for wastewater treatment based on a large language model, characterized in that, The method comprises the following steps: S1, based on a closed-source large language model, generating an activated sludge model JSON file; S2, generating executable Python code for the activated sludge model applied to sewage treatment according to the activated sludge model JSON file and the code generation prompt; S3, constructing a fine-tuning data set of an open-source large language model, wherein each piece of fine-tuning data is composed of a user input instruction and a piece of executable Python code generated by S2, and the user input instruction is a segment of natural language for generating executable Python code for the activated sludge model for sewage treatment; S4, fine-tuning the open-source large language model using the fine-tuning data set to obtain the open-source large language model after fine-tuning; S5, based on the fine-tuned open-source large language model, using user natural language to generate Python code for the activated sludge model for sewage treatment.
2. The wastewater treatment activated sludge model generation method according to claim 1, characterized by, The generation method of S1 is to obtain literature texts and report texts containing activated sludge model information, extract model information in the texts by using a closed-source large language model and ASM to extract prompts, and store them as JSON format files.
3. The wastewater treatment activated sludge model generation method according to claim 2, characterized by, The model information includes model name, simulation target, key assumption, variable, process, reactor configuration, and reactor connection.
4. The wastewater treatment activated sludge model generating method according to claim 1, characterized by, The generation method of S2 is to use the DeepSeek network version to generate executable Python code, which is compiled into an executable file (exe) in the Windows system, has an interactive UI interface after running, and has functions of dynamic simulation, steady-state simulation, sensitivity analysis, uncertainty analysis, and parameter estimation related to sewage.
5. The wastewater treatment activated sludge model generating method according to claim 1, characterized by, The executable Python code is tested, including: executing the generated Python code in the local Pycharm client, testing whether the code can meet the functional requirements, if so, saving the Python code for later use; if not, uploading the Python code to the DeepSeek network version, and then according to the code error or function missing situation to write the prompt, using the DeepSeek network version to automatically modify the Python code according to the prompt content, and generating new modified Python code, until the corresponding executable Python code generated according to each JSON file meets the requirements.
6. The wastewater treatment activated sludge model generating method according to claim 1, characterized by, The fine-tuning data of S3 is summarized in a JSON file as a fine-tuning data set file "data.json".
7. The wastewater treatment activated sludge model generation method according to claim 6, characterized by, The fine-tuning method of S4 is: The llama_factory webui is used to fine-tune the open-source large language model, and the open-source large language model to be fine-tuned is selected and downloaded in the webui; Place the fine-tuning data set file "data.json" in the folder where llama_factory stores local data sets, and modify the llama_factory dataset_info.json file to add a description of the fine-tuning data set; After selecting the open-source large language model to be fine-tuned and the fine-tuning dataset in the webui, and performing parameter fine-tuning, when the fine-tuning process is completed and the error converges, the fine-tuned open-source large language model is saved to the local computer in the webui.
8. The wastewater treatment activated sludge model generating method according to claim 7, characterized by, The description of the fine-tuning dataset is as follows: "dataset_name": { "file_name": "data.json", "columns": { "prompt": "instruction", "query": "input", "response": "output", "system": "system", "history": "history" } }。 9. The wastewater treatment activated sludge model generating method according to claim 7, characterized by, The fine-tuned parameters include: QLoRA quantization level = 4; Acceleration mode = liger_kernel; Learning rate 2e-4; Batch size is set to 1, and gradient accumulation is 16; Validation set ratio 0; LoRA drop 0.05, action module q_proj, v_proj.