Heterogeneous model calling method and device oriented to strong language and storage medium

By using JSON format to describe heterogeneous model interface information in strongly typed languages ​​and dynamically call them through the bridge layer, the problem of heterogeneous model call complexity in strongly typed languages ​​is solved, and flexibility and scalability are improved.

CN119473272APending Publication Date: 2025-02-18STATE GRID JIANGSU ELECTRIC POWER CO LTD RESEARCH INSTITUTE +3
View PDF 0 Cites 1 Cited by

Patent Information

Application Number
CN202411580897.X
Authority / Receiving Office
CN · China
Patent Type
Applications(China)
Current Assignee / Owner
Filing Date
2024-11-07
Publication Date
2025-02-18

AI Technical Summary

Technical Problem

In the application environment of strongly typed languages, the prior art is difficult to effectively reduce the complexity and cost of heterogeneous model calls, especially when the model interface changes, it is necessary to explicitly declare the model interface and perform additional model encapsulation interface modification.

Method used

By describing the interface information of heterogeneous models in JSON format, model interface definitions are generated, and deserialized into model interface definition class instances in strongly typed languages, and serialized into JSON format after modifying the attributes. Then, the serialized JSON format model interface definition is passed as parameters to the pre-built bridge layer, and dynamically call it through the conversion function and the activation function to realize unified calls to multiple heterogeneous models.

Benefits of technology

Without explicit declaration of model interfaces or additional model encapsulation interface modification, multiple heterogeneous models can be called in strongly typed languages, reducing the difficulty of calling heterogeneous models and improving the flexibility and scalability of model calls.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN119473272A_ABST
    Figure CN119473272A_ABST
Patent Text Reader

Abstract

The invention discloses a heterogeneous model calling method and device oriented to a strong type language and a storage medium in the technical field of information, and aims at solving the problem that in the prior art, heterogeneous model calling is complex. The method comprises the following steps: describing interface information of a target heterogeneous model in a JSON format, and generating a model interface definition; deserializing the model interface definition corresponding to the target model into an instance of a model interface definition class in a strong type language, modifying the attribute of the instance according to a target demand, and serializing the instance into a model interface definition in a JSON format; and the serialized model interface definition in the JSON format is used as a parameter to be transmitted into a pre-constructed bridging layer so as to execute a conversion function and an activation function, and dynamic calling of a target heterogeneous model interface is carried out. According to the method, the configuration description of the model interface and the dynamic calling capability of the Python weak language are combined, explicit declaration of the model interface or additional model packaging interface transformation is not needed, and the flexibility of the model calling method is improved.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] The invention relates to a strongly typed language-oriented heterogeneous model calling method, device and storage medium, belonging to the field of information technology. Background Art

[0002] With the rapid development of computer technology, model-driven applications are becoming increasingly widespread, especially in professional application fields. In order to solve complex problems, it is usually necessary to call and integrate models built by different languages ​​and development environments. However, due to the diverse physical forms of models (such as .NET assemblies, dynamic link libraries, executable files, and Python script files, etc.), their operation modes and calling methods are different. For strongly typed languages, their strict type checking mechanism brings complexity to cross-language and cross-platform model calls. Developers must declare model interfaces in different ways when coding according to the specific physical form of the model and write corresponding calling codes. Once the interface of the model changes, the model interface must be updated in the code, the calling logic must be adjusted, and the program must be recompiled and deployed. In order to shield the heterogeneity of the model, the usual practice is to encapsulate the model and transform the interface, but for complex models, these tasks are arduous and the cost of encapsulation and transformation cannot be ignored. Therefore, in the application environment of strongly typed languages, there is still a lot of room for improvement to reduce the complexity of heterogeneous model calls. Summary of the invention

[0003] The technical problem to be solved by the present invention is to overcome the defects of the prior art and provide a heterogeneous model calling method, device and storage medium for strongly typed languages. It can realize the calling of multiple heterogeneous models, covering .NET assemblies, dynamic link libraries, executable files and Python script files, without explicitly declaring the model interface or performing additional model encapsulation interface modification, which can effectively reduce the difficulty of calling heterogeneous models and improve the flexibility and scalability of model calling.

[0004] In order to solve the above technical problems, the present invention is implemented by adopting the following technical solutions.

[0005] On the one hand, the present invention discloses a heterogeneous model calling method for strongly typed languages, comprising: Describe the interface information of the target heterogeneous model in JSON format and generate the model interface definition; Deserialize the model interface definition corresponding to the target model into an instance of the model interface definition class in a strongly typed language, modify the attributes of the instance according to target requirements, and then serialize it into a model interface definition in JSON format; The serialized JSON format model interface definition is passed as a parameter to the pre-built bridge layer to execute the conversion function and activation function sequentially to dynamically call the target heterogeneous model interface.

[0006] Furthermore, the interface information of the heterogeneous model includes model name, model type, model path, method name, method parameter set, return value type and method additional information; the method parameter set includes all method parameters required for method calling, and the method parameters are key-value pairs of parameter type and parameter value, and the initial value is empty or a default value; the method additional information is other additional information required for calling the method.

[0007] Furthermore, a serialization and deserialization relationship is set between the model interface definition class and the model interface definition.

[0008] Furthermore, the construction of the bridge layer includes: A bridge layer is built through Python, and the model interface definition is used as an input parameter to bridge strongly typed language programs and heterogeneous models.

[0009] Furthermore, the conversion function is used to convert the input parameters into a unified representation required for calling the underlying model interface; The activation function is used to execute dynamic calls to heterogeneous model interfaces according to a unified representation form, and return the call results to the strongly typed language caller.

[0010] Furthermore, the conversion function uses Python's ctypes library and pythonnet library to convert the parameter type, parameter value and return value type contained in the incoming parameter into corresponding types and values ​​in Python.

[0011] Furthermore, the activation function is used to uniformly call heterogeneous model interfaces including .NET assemblies, dynamic link libraries, executable files and Python script files.

[0012] Furthermore, the unified calling includes: calling .NET assembly functions using the Pythonclr module and getattr() method, calling dynamic link library functions through the Pythonctypes module and getattr() method, calling executable files using the Pythonsubprocess module, and directly calling Python script files using the getattr() method.

[0013] In a second aspect, the present invention discloses a heterogeneous model calling device for strongly typed languages, comprising: A generation module is used to describe the interface information of the target heterogeneous model in JSON format and generate the model interface definition; The serialization module is used to deserialize the model interface definition corresponding to the target model into an instance of the model interface definition class in a strongly typed language, and serialize it into a model interface definition in JSON format after modifying the attributes of the instance according to the target requirements; The calling module is used to pass the serialized JSON format model interface definition as a parameter to the pre-built bridge layer to sequentially execute the conversion function and activation function to dynamically call the target heterogeneous model interface.

[0014] In a third aspect, the present invention discloses a computer-readable storage medium storing one or more programs, wherein the one or more programs include instructions, which, when executed by a computing device, cause the computing device to perform the method of the first aspect.

[0015] The beneficial effects achieved by the present invention are: The present invention combines the configuration description of the model interface with the dynamic calling capability of the Python weak language. It can call multiple heterogeneous models in a strongly typed language without explicitly declaring the model interface or performing additional model encapsulation interface modification, thereby improving the flexibility of the model calling method. BRIEF DESCRIPTION OF THE DRAWINGS

[0016] Figure 1 It is a flow chart of the heterogeneous model calling method of the strongly typed language of the present invention; Figure 2 It is a schematic diagram of the Python bridge layer of the present invention; Figure 3 This is a flow chart of the Python bridge layer activation function method of the present invention. DETAILED DESCRIPTION

[0017] The present invention will be further described below in conjunction with the accompanying drawings. The following embodiments are only used to more clearly illustrate the technical solution of the present invention, and cannot be used to limit the protection scope of the present invention.

[0018] In the description of the present invention, it should be understood that the terms "center", "longitudinal", "lateral", "up", "down", "front", "back", "left", "right", "vertical", "horizontal", "top", "bottom", "inside", "outside" and the like indicate positions or positional relationships based on the positions or positional relationships shown in the accompanying drawings, and are only for the convenience of describing the present invention and simplifying the description, rather than indicating or implying that the device or element referred to must have a specific orientation, be constructed and operated in a specific orientation, and therefore cannot be understood as limiting the present invention. In addition, the terms "first", "second", and the like are only used for descriptive purposes, and cannot be understood as indicating or implying relative importance or implicitly indicating the number of technical features indicated. Thus, features defined as "first", "second", and the like may explicitly or implicitly include one or more of the features. In the description of the present invention, unless otherwise specified, "multiple" means two or more.

[0019] In the description of the present invention, it should be noted that, unless otherwise clearly specified and limited, the terms "installed", "connected", and "connected" should be understood in a broad sense, for example, it can be a fixed connection, a detachable connection, or an integral connection; it can be a mechanical connection or an electrical connection; it can be a direct connection, or it can be indirectly connected through an intermediate medium, or it can be the internal communication of two components. For ordinary technicians in this field, the specific meanings of the above terms in the present invention can be understood by specific circumstances.

[0020] Embodiment 1: This embodiment introduces a heterogeneous model calling method for strongly typed languages, including: Describe the interface information of the target heterogeneous model in JSON format and generate the model interface definition; Deserialize the model interface definition corresponding to the target model into an instance of the model interface definition class in a strongly typed language, modify the attributes of the instance according to target requirements, and then serialize it into a model interface definition in JSON format; The serialized JSON format model interface definition is passed as a parameter to the pre-built bridge layer to execute the conversion function and activation function sequentially to dynamically call the target heterogeneous model interface.

[0021] The interface information of the heterogeneous model includes model name, model type, model path, method name, method parameter set, return value type and method additional information; the method parameter set includes all method parameters required for method calling, and the method parameters are key-value pairs of parameter type and parameter value, and the initial value is empty or a default value; the method additional information is other additional information required for calling the method.

[0022] A serialization and deserialization relationship is set between the model interface definition class and the model interface definition.

[0023] The construction of the bridge layer includes: A bridge layer is built through Python, and the model interface definition is used as an input parameter to bridge strongly typed language programs and heterogeneous models.

[0024] The conversion function is used to convert the input parameters into a unified representation required for calling the underlying model interface; The activation function is used to execute dynamic calls to heterogeneous model interfaces according to a unified representation form, and return the call results to the strongly typed language caller.

[0025] The conversion function uses Python's ctypes library and pythonnet library to convert the parameter type, parameter value and return value type contained in the incoming parameter into the corresponding type and value in Python.

[0026] The activation function is used to uniformly call heterogeneous model interfaces including .NET assemblies, dynamic link libraries, executable files and Python script files.

[0027] The unified calling includes: calling .NET assembly functions using Pythonclr module and getattr() method, calling dynamic link library functions through Pythonctypes module and getattr() method, calling executable files using Pythonsubprocess module, and directly calling Python script files using getattr() method.

[0028] Embodiment 2, this embodiment introduces a heterogeneous model calling method for strongly typed languages. In one example of the present invention, the strongly typed language is Java, and the heterogeneous models are models of various forms of heterogeneity, including .NET assemblies, dynamic link libraries, executable files, and Python script files. The method flow is as follows Figure 1 As shown, the details are as follows: S1. Describe the interface information of the heterogeneous model in JSON format and generate the model interface definition.

[0029] The interface information of heterogeneous models includes model name modelName, model type modelType, model path modelUrl, method name methodName, method parameter set args, return value type returnVal and method additional information addition, where the method parameter set includes all method parameters required for method calls, method parameters are key-value pairs of parameter types and parameter values, and the values ​​are empty or default values, and method additional information is other additional information required for calling methods. Based on this standard, combined with the interface information that heterogeneous models need to disclose, the model interface definition is generated in JSON format. An example of a model interface definition containing 2 parameters generated in JSON format: { "modelName": "model1", / / Model name "modelType": 3, / / Model type "modelUrl": "C:\\Users\\111\\Desktop\\model1.exe", / / Model path "methodName": "method1", / / method name "returnType": "void", / / Return value type "addition": "", / / Method additional information "args": [ / / Method parameter collection { "argType": "String", "argValue": ""}, / / Method parameters { "argType": "String", "argValue": ""} / / Method parameters ] }.

[0030] S2. Define a model interface definition class in a strongly typed language as the entity class of the model interface definition.

[0031] In Java, based on the model interface definition, the model interface definition class ModelInvokeInfo is designed as the entity class defined by the model interface, which is used for serialization and deserialization between the two.

[0032] S3. Use Python to build a bridge layer and pass in the model interface definition parameters to bridge the strongly typed language program with the underlying heterogeneous model.

[0033] like Figure 2As shown in the figure, the bridge layer consists of a conversion function and an activation function. The conversion function converts the incoming model interface definition parameter param into the unified representation required to call the underlying model interface; specifically, since param is a JSON string, for ease of use, param is first deserialized into a Python object pyParam, and then three conversion functions are defined according to the model type: convertPyArgs, convertCArgs, and convertCSArgs. These functions first convert the parameter type, parameter value, and return value type parameters of all parameters in pyParam.args to the corresponding types and values ​​in Python. Furthermore, the convertCArgs and convertCSArgs functions are implemented with the help of the ctypes library and the pythonnet library respectively, solving the cross-language mapping problem of parameter types and values ​​between Python and dynamic link libraries and .NET assemblies.

[0034] The activation function is responsible for calling the specific underlying model and returning the call result, such as Figure 3 As shown, it includes: S301, parameter reception; S302, parameter analysis; S303, parameter type conversion; S304, model dynamic call; S305, call result reception; S306, call result return; The activation function is responsible for calling the specific underlying model and returning the calling result. According to different model types, four specific calling functions are constructed in the experiment: callCSharpDll, callDll, callExe and callPython.

[0035] (1) Construct the callCSDll function. First, load the .NET assembly through the AddReference() method of the clr module in Python. Then, dynamically import the required dynamic link library according to the namespace attribute recorded in pyParam.addition. Next, dynamically obtain the specified class through the getattr() function according to the className attribute recorded in pyParam.addition. After that, determine whether the method to be called is static according to the static attribute recorded in pyParam.addition: if it is a static method, directly obtain the method from the class through getattr() according to pyParam.methodName; if it is a non-static method, you need to instantiate the class first, and access the method through the instantiated object. Finally, call the model method, and receive and return the execution result of the model method.

[0036] (2) Build the callDll function. First, load the specified dynamic link library through the ctypes module in Python according to the pyParam.modelUrl attribute. Then, dynamically obtain the function to be called from the loaded library through the getattr() function in Python according to the pyParam.methodName attribute. Next, use ctypes to define the parameter type and return type of the method to ensure the consistency and correctness of the data type. Finally, dynamically build and call the spliced ​​method, and receive and return the execution result of the model method.

[0037] (3) Construct the callExe function. First, obtain the root directory of the model according to the pyParam.modelUrl information. Then, call the specified executable file type model through the subprocess module in Python. Specifically, call the model through the subprocess.run() method, which has three parameters: the first parameter is the parameter to be passed in, the second parameter indicates whether to use the shell to execute the command, and the third parameter is the working directory where the command is located (that is, the folder where the root directory of the executable file model is located).

[0038] (4) Build the callPthon function. First, set up the running environment and append the root directory of the python script model to the system path. Then, dynamically import the python script and dynamically obtain the specified method through the getattr() function based on the pyParam.methodName attribute. Finally, dynamically build and call the method, and receive and return the execution result of the method.

[0039] S4. Call and pass the model interface definition parameters to the bridge layer in a strongly typed language to implement the call to the underlying heterogeneous model interface.

[0040] Define the execute function in Java, which is responsible for calling and passing the model interface definition param to the S3Python bridge layer. Specifically, in Java, the model interface definition of the required heterogeneous model is deserialized into a model interface definition class instance, and the corresponding instance attributes are modified according to the actual program conditions, and used as the input parameter of the execute function. The execute function serializes the incoming parameters into a model interface definition in JSON format, and then calls the S3 conversion function through the Java Runtime class exec method, and passes the model interface definition as a parameter. When the exec method is executed, the call to the underlying heterogeneous model interface is completed.

[0041] Embodiment 3 is based on the same inventive concept as Embodiment 1. This embodiment introduces a heterogeneous model calling device for strongly typed languages, including: A generation module is used to describe the interface information of the target heterogeneous model in JSON format and generate the model interface definition; The serialization module is used to deserialize the model interface definition corresponding to the target model into an instance of the model interface definition class in a strongly typed language, and serialize it into a model interface definition in JSON format after modifying the attributes of the instance according to the target requirements; The calling module is used to pass the serialized JSON format model interface definition as a parameter to the pre-built bridge layer to sequentially execute the conversion function and activation function to dynamically call the target heterogeneous model interface.

[0042] Embodiment 4 is based on the same inventive concept as Embodiment 1. This embodiment introduces a computer-readable storage medium storing one or more programs, wherein the one or more programs include instructions, and when the instructions are executed by a computing device, the computing device executes the method of Embodiment 1.

[0043] Example 5 is based on the same inventive concept as Example 1. This example introduces a computer device, including one or more processors, a memory, and one or more programs, wherein the one or more programs are stored in the memory and configured to be executed by the one or more processors, and the one or more programs include instructions for executing the method described in Example 2.

[0044] It will be appreciated by those skilled in the art that embodiments of the present invention may be provided as methods, systems, or computer program products. Therefore, the present invention may take the form of a complete hardware embodiment, a complete software embodiment, or an embodiment combining software and hardware. Furthermore, the present invention may take the form of a computer program product implemented on one or more computer-usable storage media (including but not limited to disk storage, CD-ROM, optical storage, etc.) containing computer-usable program code.

[0045] The present invention is described with reference to flowcharts and / or block diagrams of methods, devices (systems), and computer program products according to embodiments of the present invention. It should be understood that each process and / or block in the flowchart and / or block diagram, as well as the combination of processes and / or blocks in the flowchart and / or block diagram, can be implemented by computer program instructions. These computer program instructions can be provided to a processor of a general-purpose computer, a special-purpose computer, an embedded processor, or other programmable data processing device to produce a machine, so that the instructions executed by the processor of the computer or other programmable data processing device generate instructions for implementing the processes in the flowchart and / or block diagram. Figure 1 A process or multiple processes and / or boxes Figure 1A device that provides the functions specified in a block or multiple blocks.

[0046] These computer program instructions may also be stored in a computer-readable memory capable of directing a computer or other programmable data processing device to operate in a specific manner, so that the instructions stored in the computer-readable memory produce an article of manufacture comprising an instruction device, which implements the process Figure 1 A process or multiple processes and / or boxes Figure 1 A function specified in one or more boxes.

[0047] These computer program instructions can also be loaded onto a computer or other programmable data processing device so that a series of operating steps are executed on the computer or other programmable device to produce a computer-implemented process, thereby providing instructions for implementing the process. Figure 1 A process or multiple processes and / or boxes Figure 1 The steps for the functions specified in one or more boxes.

[0048] The above is only a preferred embodiment of the present invention. It should be pointed out that for ordinary technicians in this technical field, several improvements and modifications can be made without departing from the technical principles of the present invention. These improvements and modifications should also be regarded as the scope of protection of the present invention.

Claims

1. A heterogeneous model calling method for strongly typed languages, characterized in that: include: Describe the interface information of the target heterogeneous model in JSON format and generate the model interface definition; Deserialize the model interface definition corresponding to the target model into an instance of the model interface definition class in a strongly typed language, modify the attributes of the instance according to target requirements, and then serialize it into a model interface definition in JSON format; The serialized JSON format model interface definition is passed as a parameter to the pre-built bridge layer to execute the conversion function and activation function sequentially to dynamically call the target heterogeneous model interface.

2. The heterogeneous model calling method for strongly typed languages ​​according to claim 1, characterized in that: The interface information of the heterogeneous model includes model name, model type, model path, method name, method parameter set, return value type and method additional information; the method parameter set includes all method parameters required for method calling, and the method parameters are key-value pairs of parameter type and parameter value, and the initial value is empty or a default value; the method additional information is other additional information required for calling the method.

3. The heterogeneous model calling method for strongly typed languages ​​according to claim 1, characterized in that: A serialization and deserialization relationship is set between the model interface definition class and the model interface definition.

4. The heterogeneous model calling method for strongly typed languages ​​according to claim 1, characterized in that: The construction of the bridge layer includes: A bridge layer is built through Python, and the model interface definition is used as an input parameter to bridge strongly typed language programs and heterogeneous models.

5. The heterogeneous model calling method for strongly typed languages ​​according to claim 3, characterized in that: The conversion function is used to convert the input parameters into a unified representation required for calling the underlying model interface; The activation function is used to execute dynamic calls to heterogeneous model interfaces according to a unified representation form, and return the call results to the strongly typed language caller.

6. The heterogeneous model calling method for strongly typed languages ​​according to claim 5, characterized in that: The conversion function uses Python's ctypes library and pythonnet library to convert the parameter type, parameter value and return value type contained in the incoming parameter into the corresponding type and value in Python.

7. The heterogeneous model calling method for strongly typed languages ​​according to claim 5, characterized in that: The activation function is used to uniformly call heterogeneous model interfaces including .NET assemblies, dynamic link libraries, executable files and Python script files.

8. The heterogeneous model calling method for strongly typed languages ​​according to claim 7, characterized in that: The unified calling includes: calling .NET assembly functions using Pythonclr module and getattr() method, calling dynamic link library functions through Pythonctypes module and getattr() method, calling executable files using Pythonsubprocess module, and directly calling Python script files using getattr() method.

9. A heterogeneous model calling device for strongly typed languages, characterized in that: include: A generation module is used to describe the interface information of the target heterogeneous model in JSON format and generate the model interface definition; The serialization module is used to deserialize the model interface definition corresponding to the target model into an instance of the model interface definition class in a strongly typed language, and serialize it into a model interface definition in JSON format after modifying the attributes of the instance according to the target requirements; The calling module is used to pass the serialized JSON format model interface definition as a parameter to the pre-built bridge layer to sequentially execute the conversion function and activation function to dynamically call the target heterogeneous model interface.

10. A computer-readable storage medium storing one or more programs, characterized in that: The one or more programs include instructions which, when executed by a computing device, cause the computing device to perform the method of any one of claims 1 to 8.

Citation Information

Cited By

  • System platform and heterogeneous model decoupling method and device, computer equipment and medium

    CN119806637A