Machine learning model running method, machine learning system, and related device
By specifying the computing devices for both classical and quantum computing layers in the machine learning system and performing data format conversion, the problem of the inability to uniformly call classical-quantum hybrid models is solved, enabling seamless switching and unified use of devices and improving operational efficiency.
Patent Information
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- ORIGIN QUANTUM COMPUTING TECH (HEFEI) CO LTD
- Filing Date
- 2021-12-30
- Publication Date
- 2026-05-19
AI Technical Summary
In existing technologies, classical-quantum hybrid machine learning models cannot achieve unified access to computing devices, resulting in the inability to achieve seamless switching and unified use.
By specifying the first computing device for the classical computing layer and the second computing device for the quantum computing layer, the classical computing layer and the quantum computing layer are created using classical modules and quantum modules respectively, and are called uniformly through an interface, supporting data format conversion to adapt to the needs of different computing devices.
It enables seamless switching and unified access to different computing devices, improves the uniformity of computing device usage, and enhances the running efficiency of machine learning models.
Smart Images

Figure CN116432763B_ABST
Abstract
Description
Technical Field
[0001] This invention belongs to the field of quantum computing technology, and in particular relates to a method for running a machine learning model, a machine learning system, and related equipment. Background Technology
[0002] Classical machine learning, especially deep learning, has revolutionized many subfields of artificial intelligence and achieved significant success. In recent years, with the advent of the information age, deep learning has developed rapidly. The rapid growth in electronic data has led to a massive increase in the training data for deep learning models. Simultaneously, the rapid development of computing power in electronic computers, particularly the emergence of a series of new electronic computing devices represented by graphics processing units (GPUs), has made large-scale training of deep learning models a reality. Therefore, deep learning has far surpassed previous traditional algorithms and has been widely applied in many fields. Deep learning's performance in areas such as digital image classification, handwritten character recognition, and video analysis has reached or surpassed that of human capabilities.
[0003] With the rapid development of quantum computing, quantum machine learning, which combines quantum computing with classical machine learning based on quantum mechanics, has also begun to develop rapidly. Quantum machine learning leverages the far greater efficiency of quantum computers compared to classical computers, combined with the rapidly evolving machine learning algorithms of the big data era, to further improve the processing capabilities of big data.
[0004] Currently, the classical-quantum hybrid machine learning model constructs its classical part through a classical machine learning system and its quantum part through a quantum machine learning system. It requires the combined use of classical and quantum machine learning systems, so this machine learning model cannot achieve unified access to computing devices during runtime. Summary of the Invention
[0005] The purpose of this invention is to provide a method for running machine learning models, a machine learning system, and related equipment, aiming to achieve seamless switching and unified access to different computing devices and improve the uniformity of computing device usage.
[0006] One embodiment of the present invention provides a method for running a machine learning model, applied to an electronic device including a machine learning system, the machine learning system including classical modules and quantum modules, the method comprising:
[0007] Specify the first computing device for the classical computing layer and the second computing device for the quantum computing layer;
[0008] The first computing device is passed as a parameter to the classical computing layer interface, and the second computing device is passed as a parameter to the quantum computing layer interface.
[0009] The classical module is invoked to create a classical computing layer through the classical computing layer interface, and the quantum module is invoked to create a quantum computing layer through the quantum computing layer interface;
[0010] The classic module is invoked to construct a machine learning model including the classic computing layer and the quantum computing layer, and the first computing device and the second computing device are invoked to run the machine learning model.
[0011] Optionally, the step of calling the first computing device and the second computing device to run the machine learning model includes:
[0012] When it is determined that the computing format supported by the second computing device does not include the format of the input data of the quantum computing layer, the classical module is invoked to convert the format of the input data of the quantum computing layer into the computing format supported by the second computing device through the data format conversion interface;
[0013] The second computing device is invoked to run the quantum computing layer to calculate the output data corresponding to the input data.
[0014] Optionally, the computing hardware of the first computing device includes at least one of the following: a central processing unit (CPU), a graphics processing unit (GPU), a tensor processor (TPU), and a field-programmable gate array (FPGA); the computing hardware of the second computing device includes at least one of the following: a CPU, a GPU, and a quantum processor (QPU).
[0015] Optionally, if the computing hardware of the second computing device is a CPU or a GPU, then the second computing device is a quantum virtual machine; before calling the first computing device and the second computing device to run the machine learning model, the method further includes:
[0016] The quantum virtual machine is constructed based on the quantum computing programming library contained in the machine learning system.
[0017] Optionally, constructing the quantum virtual machine based on the quantum computing programming library contained in the machine learning system includes:
[0018] The quantum machine type of the specified computing hardware is passed as a parameter to the initialization function in the quantum computing programming library contained in the machine learning system, and the quantum virtual machine is created through the initialization function.
[0019] Optionally, constructing the quantum virtual machine based on the quantum computing programming library contained in the machine learning system includes:
[0020] The quantum machine type of the specified computing hardware is passed as a parameter to the quantum machine initialization interface in the quantum computing programming library contained in the machine learning system, and the quantum virtual machine is created through the quantum machine initialization interface.
[0021] Optionally, constructing the quantum virtual machine based on the quantum computing programming library contained in the machine learning system includes:
[0022] The quantum virtual machine is created based on the quantum virtual machine class of the specified computing hardware in the quantum computing programming library contained in the machine learning system.
[0023] Another embodiment of the present invention provides a machine learning model running device, applied to an electronic device including a machine learning system, the machine learning system including a classical module and a quantum module, the device comprising:
[0024] A computing device determination unit is used to specify the first computing device of the classical computing layer and the second computing device of the quantum computing layer;
[0025] An interface determination unit is used to pass the first computing device as a parameter to the classical computing layer interface and the second computing device as a parameter to the quantum computing layer interface.
[0026] The computing layer creation unit is used to call the classical module to create a classical computing layer through the classical computing layer interface, and to call the quantum module to create a quantum computing layer through the quantum computing layer interface;
[0027] The model execution unit is used to call the classical module to construct a machine learning model including the classical computing layer and the quantum computing layer, and to call the first computing device and the second computing device to run the machine learning model.
[0028] Optionally, in the aspect of calling the first computing device and the second computing device to run the machine learning model, the model running unit is specifically used for:
[0029] When it is determined that the computing format supported by the second computing device does not include the format of the input data of the quantum computing layer, the classical module is invoked to convert the format of the input data of the quantum computing layer into the computing format supported by the second computing device through the data format conversion interface;
[0030] The second computing device is invoked to run the quantum computing layer to calculate the output data corresponding to the input data.
[0031] Optionally, the computing hardware of the first computing device includes at least one of the following: a central processing unit (CPU), a graphics processing unit (GPU), a tensor processor (TPU), and a field-programmable gate array (FPGA); the computing hardware of the second computing device includes at least one of the following: a CPU, a GPU, and a quantum processor (QPU).
[0032] Optionally, if the computing hardware of the second computing device is a CPU or a GPU, then the second computing device is a quantum virtual machine; before calling the first computing device and the second computing device to run the machine learning model, the computing device determination unit is further configured to:
[0033] The quantum virtual machine is constructed based on the quantum computing programming library contained in the machine learning system.
[0034] Optionally, the quantum virtual machine is constructed based on the quantum computing programming library contained in the machine learning system, and the computing device determination unit is specifically used for:
[0035] The quantum machine type of the specified computing hardware is passed as a parameter to the initialization function in the quantum computing programming library contained in the machine learning system, and the quantum virtual machine is created through the initialization function.
[0036] Optionally, the quantum virtual machine is constructed based on the quantum computing programming library contained in the machine learning system, and the computing device determination unit is specifically used for:
[0037] The quantum machine type of the specified computing hardware is passed as a parameter to the quantum machine initialization interface in the quantum computing programming library contained in the machine learning system, and the quantum virtual machine is created through the quantum machine initialization interface.
[0038] Optionally, the quantum virtual machine is constructed based on the quantum computing programming library contained in the machine learning system, and the computing device determination unit is specifically used for:
[0039] The quantum virtual machine is created based on the quantum virtual machine class of the specified computing hardware in the quantum computing programming library contained in the machine learning system.
[0040] Another embodiment of the present invention provides a machine learning system, the machine learning system comprising:
[0041] The classic module is configured to create a classic computing layer through a classic computing layer interface, the parameters of which include a first computing device of the classic computing layer.
[0042] A quantum module is configured to create a quantum computing layer via a quantum computing layer interface, the parameters of which include a second computing device of the quantum computing layer;
[0043] The classical module is also configured to construct a machine learning model that includes the classical computing layer and the quantum computing layer, and to call the first computing device and the second computing device to run the machine learning model.
[0044] Another embodiment of the present invention provides a storage medium storing a computer program, wherein the computer program is configured to execute the method described in any of the preceding claims when running.
[0045] Another embodiment of the present invention provides an electronic device including a memory and a processor, wherein the memory stores a computer program and the processor is configured to run the computer program to perform the method described in any of the preceding claims.
[0046] Compared with existing technologies, this invention constructs a machine learning model within a machine learning system that includes classical and quantum modules. The classical computing layer of this machine learning model is created by the classical module through a classical computing layer interface, and the quantum computing layer is created by the quantum module through a quantum computing layer interface. At the time of creation, the first computing device of the classical computing layer is specified as a parameter of the classical computing layer interface, and the second computing device of the quantum computing layer is specified as a parameter of the quantum computing layer interface. This enables the classical computing layer to be run through the first computing device and the quantum computing layer to be run through the second computing device during runtime, achieving seamless switching and unified invocation of different computing devices and improving the uniformity of computing device usage. Attached Figure Description
[0047] Figure 1 A hardware structure block diagram of a computer terminal for a machine learning model running method provided in an embodiment of the present invention;
[0048] Figure 2 A flowchart illustrating a machine learning model execution method provided in an embodiment of the present invention;
[0049] Figure 3 This is a schematic diagram of the structure of a machine learning model running device provided in an embodiment of the present invention;
[0050] Figure 4 A schematic diagram of the structure of a machine learning system provided in an embodiment of the present invention;
[0051] Figure 5 This is a schematic diagram of another machine learning system provided in an embodiment of the present invention. Detailed Implementation
[0052] The embodiments described below with reference to the accompanying drawings are exemplary and are only used to explain the present invention, and should not be construed as limiting the present invention.
[0053] This invention first provides a method for running a machine learning model, which can be applied to electronic devices, such as computer terminals, specifically ordinary computers, quantum computers, etc.
[0054] The following detailed explanation uses a computer terminal as an example. Figure 1 This is a hardware structure block diagram of a computer terminal for a machine learning model running method provided in an embodiment of the present invention. Figure 1 As shown, a computer terminal may include one or more ( Figure 1 Only one is shown in the diagram. A processor 102 (which may include, but is not limited to, a microprocessor MCU or a programmable logic device FPGA, etc.) and a memory 104 for storing machine learning model execution methods are also shown. Optionally, the computer terminal may further include a transmission device 106 for communication functions and an input / output device 108. Those skilled in the art will understand that... Figure 1 The structure shown is for illustrative purposes only and does not limit the structure of the computer terminal described above. For example, the computer terminal may also include components that are more complex than those described above. Figure 1 The more or fewer components shown, or having the same Figure 1 The different configurations shown.
[0055] The memory 104 can be used to store software programs and modules of application software, such as the program instructions / modules corresponding to the machine learning model running method in this embodiment of the invention. The processor 102 executes various functional applications and data processing by running the software programs and modules stored in the memory 104, thereby implementing the above-described method. The memory 104 may include high-speed random access memory, and may also include non-volatile memory, such as one or more magnetic storage devices, flash memory, or other non-volatile solid-state memory. In some instances, the memory 104 may further include memory remotely located relative to the processor 102, and these remote memories can be connected to a computer terminal via a network. Examples of such networks include, but are not limited to, the Internet, corporate intranets, local area networks, mobile communication networks, and combinations thereof.
[0056] The transmission device 106 is used to receive or send data via a network. Specific examples of the network described above may include a wireless network provided by a communication provider for the computer terminal. In one example, the transmission device 106 includes a Network Interface Controller (NIC), which can connect to other network devices via a base station to communicate with the Internet. In another example, the transmission device 106 may be a Radio Frequency (RF) module, used for wireless communication with the Internet.
[0057] It's important to note that a true quantum computer has a hybrid structure, comprising two main parts: a classical computer responsible for performing classical computations and control, and a quantum device responsible for running quantum programs to achieve quantum computation. A quantum program is a sequence of instructions written in a quantum language such as QRunes that can run on a quantum computer, supporting operations on quantum logic gates and ultimately enabling quantum computing. Specifically, a quantum program is a sequence of instructions that operates on quantum logic gates according to a specific timing order.
[0058] In practical applications, due to limitations in the development of quantum device hardware, quantum computing simulations are typically required to verify quantum algorithms, quantum applications, and so on. Quantum computing simulation is the process of simulating the execution of a quantum program corresponding to a specific problem using a virtual architecture (i.e., a quantum virtual machine) built with the resources of a conventional computer. Typically, it is necessary to construct a quantum program corresponding to a specific problem. The quantum program referred to in this embodiment of the invention is a program written in a classical language that represents qubits and their evolution, where qubits, quantum logic gates, etc., related to quantum computing all have corresponding classical code representations.
[0059] Quantum circuits, also known as quantum logic circuits, are a manifestation of quantum programming and are the most commonly used general-purpose quantum computing model. They represent circuits that operate on qubits under an abstract concept. They consist of qubits, circuits (timelines), and various quantum logic gates, and the results are often read out through quantum measurement operations.
[0060] Unlike traditional circuits that use metal wires to transmit voltage or current signals, in quantum circuits, the circuits can be seen as being connected by time. That is, the state of a quantum bit evolves naturally over time, following the instructions of the Hamiltonian operator until it encounters a logic gate and is operated on.
[0061] A quantum program corresponds to a total quantum circuit. The quantum program described in this invention refers to this total quantum circuit, where the total number of qubits in the total quantum circuit is the same as the total number of qubits in the quantum program. This can be understood as follows: a quantum program can consist of a quantum circuit, measurement operations on the qubits within the quantum circuit, registers for storing measurement results, and control flow nodes (jump instructions). A quantum circuit can contain dozens, hundreds, or even thousands of quantum logic gate operations. The execution process of a quantum program is the process of executing all the quantum logic gates according to a certain timing order. It should be noted that the timing order refers to the chronological order in which individual quantum logic gates are executed.
[0062] It's important to note that in classical computing, the most basic unit is the bit, and the most fundamental control mode is the logic gate. Circuit control can be achieved through combinations of logic gates. Similarly, the way to process qubits is through quantum logic gates. Quantum logic gates enable the evolution of quantum states and are the foundation of quantum circuits. Quantum logic gates include single-qubit gates, such as Hadamard gates (H-gates), Pauli-X gates (X-gates), Pauli-Y gates (Y-gates), Pauli-Z gates (Z-gates), RX gates, RY gates, RZ gates, etc.; and multi-qubit gates, such as CNOT gates, CR gates, iSWAP gates, Tofoli gates, etc. Quantum logic gates are generally represented using unitary matrices, which are not only matrix forms but also operations and transformations. Generally, the effect of a quantum logic gate on a quantum state is calculated by left-multiplying the unitary matrix by the matrix corresponding to the right vector of the quantum state.
[0063] See Figure 2 , Figure 2 This is a flowchart illustrating a machine learning model operation method provided in an embodiment of the present invention, applied to an electronic device including a machine learning system, wherein the machine learning system includes a classical module and a quantum module, and the method includes:
[0064] Step 201: Specify the first computing device for the classical computing layer and the second computing device for the quantum computing layer;
[0065] Step 202: Pass the first computing device as a parameter to the classical computing layer interface, and pass the second computing device as a parameter to the quantum computing layer interface;
[0066] Step 203: Call the classical module to create a classical computing layer through the classical computing layer interface, and call the quantum module to create a quantum computing layer through the quantum computing layer interface;
[0067] Step 204: Invoke the classical module to construct a machine learning model including the classical computing layer and the quantum computing layer;
[0068] Step 205: Call the first computing device and the second computing device to run the machine learning model.
[0069] Quantum computing is a novel computing paradigm that follows the laws of quantum mechanics to manipulate quantum information units for computation. Utilizing two quantum phenomena—superposition and entanglement—it can simultaneously process multiple states of information. The quantum computing layer is a program module containing quantum circuits, used to implement quantum computations corresponding to those circuits. By encapsulating these quantum circuits according to certain standards, the quantum computing layer is easily used in creating and training machine learning models. The parts of a machine learning model implemented using quantum computing can be understood as the corresponding quantum computing layer.
[0070] Classical computing is a traditional computing paradigm that follows the laws of classical physics to regulate classical information units for computation. It operates through a binary system, where information is stored using 1s or 0s and does not understand anything beyond 0s or 1s. The classical computing layer, in contrast to the quantum computing layer, can be a standardized encapsulation of pre-existing classical computing programs, making it easier to use when creating and training machine learning models.
[0071] An interface is a set of method declarations, a collection of method characteristics. An interface only has method characteristics but no method implementations. Therefore, these methods can be implemented by different classes in different places, and these implementations can have different behaviors. The classical computing layer interface is a set of method declarations corresponding to the classical computing layer, and the quantum computing layer interface is a set of method declarations corresponding to the quantum computing layer. Other interfaces mentioned below can be understood with reference to the explanations here, and will not be elaborated further.
[0072] The classical computation layer includes classical neural network layers and / or activation layers. The classical neural network layer interface corresponding to the classical neural network layer includes at least one of the following: one-dimensional convolutional layer interface Conv1D(), two-dimensional convolutional layer interface Conv2D, two-dimensional transposed convolutional layer interface ConvT2D(), average pooling layer interface AvgPool2D(), max pooling layer interface MaxPool2D(), embedding layer interface Embedding2D(), one-dimensional batch normalization layer interface BatchNorm1D(), two-dimensional batch normalization layer interface BatchNorm2D, fully connected layer interface Linear(), and random dropout layer interface Dropout().
[0073] The activation layer interface includes at least one of the following: Sigmoid(), Softplus(), Softsign(), Softmax(), HardSigmoid(), Relu(), LeakyRelu(), Elu(), and Tanh().
[0074] The activation function corresponding to Sigmoid() is: The activation function corresponding to Softplus() is The activation function corresponding to Softsign() is The activation function corresponding to Softmax() is The activation function corresponding to ReLU() is The activation function corresponding to LeakyRelu() is Leaky. The activation function corresponding to Elu() is The activation function corresponding to Tanh() is The activation function corresponding to HardSigmoid() is .
[0075] The quantum computing layer includes a general quantum computing layer interface (e.g., QuantumLayer(), QuantumLayerV2()), a compatible quantum computing layer interface (e.g., Compatiblelayer()), a noisy quantum computing layer interface (e.g., NoiseQuantumLayer()), a quantum convolutional layer interface (e.g., QConv()), and a quantum fully connected layer interface (e.g., Qlinear()). The general quantum computing layer interface is used to provide quantum programs created based on the quantum computing programming library contained in the machine learning system. The compatible quantum computing layer interface is used to provide quantum programs created based on quantum computing programming libraries not contained in the machine learning system. The noisy quantum computing layer interface is used to provide quantum programs created based on the quantum computing programming library contained in the machine learning system that take noise into account.
[0076] Each classical computing layer interface or quantum computing layer interface includes the parameter machine_type_or_cloud_token, which can be used to specify the first or second computing device.
[0077] The first computing device is a classical computing device, and the second computing device is a quantum computing device. The computing hardware of the first computing device includes at least one of the following: a central processing unit (CPU), a graphics processing unit (GPU), a tensor processing unit (TPU), or a field-programmable gate array (FPGA); the computing hardware of the second computing device includes at least one of the following: a CPU, a GPU, or a quantum processing unit (QPU).
[0078] Specifically, the machine learning system also includes a data structure module, and the step of calling the classical module to construct a machine learning model including the classical computing layer and the quantum computing layer includes:
[0079] The classical module is invoked to construct the classical computing layer, and the data structure module is invoked to construct the forward propagation relationship between the classical computing layer and the quantum computing layer.
[0080] The classical module is invoked to encapsulate the classical computing layer, the quantum computing layer, and the forward propagation relationship between the classical computing layer and the quantum computing layer, thereby obtaining a machine learning model.
[0081] Forward propagation involves using the output of the previous computational layer as the input of the next computational layer and calculating the output of the next computational layer, continuing until there is no next computational layer. The computational layer can be either the classical computational layer or the quantum computational layer mentioned above.
[0082] Furthermore, the classical module also includes an abstract class submodule, which encapsulates the classical computing layer, the quantum computing layer, and the forward propagation relationship between the classical computing layer and the quantum computing layer to obtain a machine learning model, including:
[0083] The abstract class submodule is invoked to initialize and encapsulate the quantum computing layer and the classical computing layer based on the initialization function, resulting in the initialized and encapsulated quantum computing layer and classical computing layer;
[0084] The abstract class submodule is called to encapsulate the forward propagation relationship based on the forward propagation function to obtain the encapsulated forward propagation relationship;
[0085] The abstract class submodule is invoked to encapsulate the initialized and encapsulated quantum computing layer and classical computing layer, as well as the encapsulated forward propagation relationship, based on the module class, to obtain a machine learning model.
[0086] The initialization function is _init_(), and the forward propagation function is forward().
[0087] Based on the initialization function, the quantum computing layer and the classical computing layer are initialized and encapsulated to obtain the initialized and encapsulated quantum computing layer and classical computing layer, which can be described as follows:
[0088] def _init_(self):
[0089] super(Net, self)._init_()
[0090] self.conv1=Conv2D(a)
[0091] self.maxpool = Maxpool2D(b)
[0092] self.conv2=Conv2D(c)
[0093] self.maxpool2 = Maxpool2D(d)
[0094] self.fc1=Linear(e)
[0095] self.fc2 = Linear(f)
[0096] self.hybrid = Qiskitlayer(g)
[0097] self.fc3 = Linear(h)
[0098] The encapsulated forward propagation relation is obtained by encapsulating the forward propagation function, as follows:
[0099] def forward(self, x):
[0100] x = self.conv1(x)
[0101] x = self.maxpool1(x)
[0102] x = self.conv2(x)
[0103] x = maxpool2(x)
[0104] x = self.fc1(x)
[0105] x = self.fc2(x)
[0106] x = self.hybrid(x)
[0107] x = self.fc3(x)
[0108] return x
[0109] Based on the module class, the initialized and encapsulated quantum computing layer and classical computing layer, as well as the encapsulated forward propagation relationship, are encapsulated to obtain a machine learning model, which can be as follows:
[0110] class Net(Module):
[0111] def _init_(self):
[0112] super(Net,self)._init_()
[0113] self.conv1=Conv2D(a)
[0114] self.maxpool=Maxpool2D(b)
[0115] self.conv2=Conv2D(c)
[0116] self.maxpool2=Maxpool2D(d)
[0117] self.fc1=Linear(e)
[0118] self.fc2=Linear(f)
[0119] self.hybrid=Qiskitlayer(g)
[0120] self.fc3=Linear(h)
[0121] def forward(self,x):
[0122] x=self.conv1(x)
[0123] x=self.maxpool1(x)
[0124] x=self.conv2(x)
[0125] x=maxpool2(x)
[0126] x=self.fc1(x)
[0127] x=self.fc2(x)
[0128] x=self.hybrid(x)
[0129] x=self.fc3(x)
[0130] return x
[0131] Compared with existing technologies, this invention constructs a machine learning model within a machine learning system that includes classical and quantum modules. The classical computing layer of this machine learning model is created by the classical module through a classical computing layer interface, and the quantum computing layer is created by the quantum module through a quantum computing layer interface. At the time of creation, the first computing device of the classical computing layer is specified as a parameter of the classical computing layer interface, and the second computing device of the quantum computing layer is specified as a parameter of the quantum computing layer interface. This enables the classical computing layer to be run through the first computing device and the quantum computing layer to be run through the second computing device during runtime, achieving seamless switching and unified invocation of different computing devices and improving the uniformity of computing device usage.
[0132] In one embodiment of the present invention, the step of calling the first computing device and the second computing device to run the machine learning model includes:
[0133] When it is determined that the computing format supported by the second computing device does not include the format of the input data of the quantum computing layer, the classical module is invoked to convert the format of the input data of the quantum computing layer into the computing format supported by the second computing device through the data format conversion interface;
[0134] The second computing device is invoked to run the quantum computing layer to calculate the output data corresponding to the input data.
[0135] The step of calling the first computing device and the second computing device to run the machine learning model further includes:
[0136] When it is determined that the computing formats supported by the first computing device do not include the format of the input data of the classic computing layer, the classic module is invoked to convert the format of the input data of the classic computing layer into the computing format supported by the first computing device through the data format conversion interface.
[0137] The first computing device is invoked to run the classical computing layer to calculate the output data corresponding to the input data.
[0138] Specifically, machine learning models consist of multiple computational layers, including classical and quantum computing layers. Each layer can operate on different computing devices. Therefore, the output data format of a previous layer may not be compatible with the input data format of the next layer, necessitating data format conversion. Data format conversion can be achieved through data format conversion interfaces, such as: `void to CPU(int dev=DEV_CPU)`, `void to GPU(int dev=DEV_GPU)`, `void to TPU(int dev=DEV_TPU)`, `void to FPGA(int dev=DEV_FPGA)`, and `void to QPU(int dev=DEV_QPU)`. `void to CPU(int dev=DEV_CPU)`, `void to GPU(int dev=DEV_GPU)`, `void to TPU(int dev=DEV_TPU)`, `void to FPGA(int dev=DEV_FPGA)`, and `void to QPU(int dev=DEV_QPU)` convert data to CPU, GPU, TPU, FPGA, and QPU formats, respectively.
[0139] In one embodiment of the present invention, if the computing hardware of the second computing device is a CPU or a GPU, then the second computing device is a quantum virtual machine; before calling the first computing device and the second computing device to run the machine learning model, the method further includes:
[0140] The quantum computing programming library contained in the machine learning system can be, for example, Qpanda, Qsikit, Cirq, Forest, Q#, qbsolv, Blackbird, etc., and is not limited here.
[0141] The quantum virtual machine is constructed based on the quantum computing programming library contained in the machine learning system.
[0142] A virtual machine (VM) is a complete computer system simulated by software, possessing full hardware system functionality and running in a completely isolated environment. A quantum virtual machine is a complete computer system that simulates a quantum computer using a classical computer.
[0143] In one embodiment of the present invention, constructing the quantum virtual machine based on the quantum computing programming library contained in the machine learning system includes:
[0144] The quantum machine type of the specified computing hardware is passed as a parameter to the initialization function in the quantum computing programming library contained in the machine learning system, and the quantum virtual machine is created through the initialization function.
[0145] The initialization function is init(), and the specific way to create the virtual machine is init(QMachineType::CPU). This method of creating a quantum virtual machine will generate a global quantum virtual machine qvm in the code.
[0146] In one embodiment of the present invention, constructing the quantum virtual machine based on the quantum computing programming library contained in the machine learning system includes:
[0147] The quantum machine type of the specified computing hardware is passed as a parameter to the quantum machine initialization interface in the quantum computing programming library contained in the machine learning system, and the quantum virtual machine is created through the quantum machine initialization interface.
[0148] The quantum machine initialization interface is initQuantumMachine(), and the specific way to create the virtual machine is Auto qvm = initQuantumMachine(QMachineType::CPU). This virtual machine creation method obtains the quantum virtual machine pointer through the quantum machine initialization interface.
[0149] In one embodiment of the present invention, constructing the quantum virtual machine based on the quantum computing programming library contained in the machine learning system includes:
[0150] The quantum virtual machine is created based on the quantum virtual machine class of the specified computing hardware in the quantum computing programming library contained in the machine learning system.
[0151] The quantum virtual machine class that specifies the computing hardware can be, for example, CPUQVM, GPUQVM, or others. The specific way to create the virtual machine can be, for example, CPUQVM *qvm = new CPUQVM, which directly creates a new qvm class.
[0152] See Figure 3 , Figure 3 This is a schematic diagram of a machine learning model running device provided in an embodiment of the present invention. It is applied to an electronic device including a machine learning system, the machine learning system comprising a classical module and a quantum module. The device 30 includes:
[0153] The computing device determination unit 301 is used to specify the first computing device of the classical computing layer and the second computing device of the quantum computing layer;
[0154] The interface determination unit 302 is used to pass the first computing device as a parameter to the classical computing layer interface and to pass the second computing device as a parameter to the quantum computing layer interface.
[0155] The computing layer creation unit 303 is used to call the classical module to create a classical computing layer through the classical computing layer interface, and to call the quantum module to create a quantum computing layer through the quantum computing layer interface;
[0156] The model execution unit 304 is used to call the classical module to construct a machine learning model including the classical computing layer and the quantum computing layer, and to call the first computing device and the second computing device to run the machine learning model.
[0157] Optionally, in the process of calling the first computing device and the second computing device to run the machine learning model, the model running unit 304 is specifically used for:
[0158] When it is determined that the computing format supported by the second computing device does not include the format of the input data of the quantum computing layer, the classical module is invoked to convert the format of the input data of the quantum computing layer into the computing format supported by the second computing device through the data format conversion interface;
[0159] The second computing device is invoked to run the quantum computing layer to calculate the output data corresponding to the input data.
[0160] Optionally, the computing hardware of the first computing device includes at least one of the following: a central processing unit (CPU), a graphics processing unit (GPU), a tensor processor (TPU), and a field-programmable gate array (FPGA); the computing hardware of the second computing device includes at least one of the following: a CPU, a GPU, and a quantum processor (QPU).
[0161] Optionally, if the computing hardware of the second computing device is a CPU or a GPU, then the second computing device is a quantum virtual machine; before calling the first computing device and the second computing device to run the machine learning model, the computing device determination unit 301 is further configured to:
[0162] The quantum virtual machine is constructed based on the quantum computing programming library contained in the machine learning system.
[0163] Optionally, the quantum virtual machine is constructed based on the quantum computing programming library contained in the machine learning system, and the computing device determination unit 301 is specifically used for:
[0164] The quantum machine type of the specified computing hardware is passed as a parameter to the initialization function in the quantum computing programming library contained in the machine learning system, and the quantum virtual machine is created through the initialization function.
[0165] Optionally, the quantum virtual machine is constructed based on the quantum computing programming library contained in the machine learning system, and the computing device determination unit 301 is specifically used for:
[0166] The quantum machine type of the specified computing hardware is passed as a parameter to the quantum machine initialization interface in the quantum computing programming library contained in the machine learning system, and the quantum virtual machine is created through the quantum machine initialization interface.
[0167] Optionally, the quantum virtual machine is constructed based on the quantum computing programming library contained in the machine learning system, and the computing device determination unit 301 is specifically used for:
[0168] The quantum virtual machine is created based on the quantum virtual machine class of the specified computing hardware in the quantum computing programming library contained in the machine learning system.
[0169] Compared with existing technologies, this invention constructs a machine learning model within a machine learning system that includes classical and quantum modules. The classical computing layer of this machine learning model is created by the classical module through a classical computing layer interface, and the quantum computing layer is created by the quantum module through a quantum computing layer interface. At the time of creation, the first computing device of the classical computing layer is specified as a parameter of the classical computing layer interface, and the second computing device of the quantum computing layer is specified as a parameter of the quantum computing layer interface. This enables the classical computing layer to be run through the first computing device and the quantum computing layer to be run through the second computing device during runtime, achieving seamless switching and unified invocation of different computing devices and improving the uniformity of computing device usage.
[0170] See Figure 4 , Figure 4 This is a schematic diagram of the structure of a machine learning system provided in an embodiment of the present invention. The machine learning system 40 includes:
[0171] Classic module 401 is configured to create a classic computing layer through a classic computing layer interface, wherein the parameters of the classic computing layer interface include a first computing device of the classic computing layer.
[0172] Quantum module 402 is configured to create a quantum computing layer via a quantum computing layer interface, the parameters of which include a second computing device of the quantum computing layer;
[0173] The classical module 401 is also configured to construct a machine learning model including the classical computing layer and the quantum computing layer, and to call the first computing device and the second computing device to run the machine learning model.
[0174] Optionally, the classical module 401 is further configured to convert the format of the input data of the quantum computing layer into a computing format supported by the second computing device through a data format conversion interface when it is determined that the computing format supported by the second computing device does not include the format of the input data of the quantum computing layer.
[0175] Optionally, the computing hardware of the first computing device includes at least one of the following: a central processing unit (CPU), a graphics processing unit (GPU), a tensor processor (TPU), and a field-programmable gate array (FPGA); the computing hardware of the second computing device includes at least one of the following: a CPU, a GPU, and a quantum processor (QPU).
[0176] Optionally, the machine learning system also includes a quantum computing programming library 403, see [link to documentation]. Figure 5 , Figure 5 This is a schematic diagram of another machine learning system provided in an embodiment of the present invention. The quantum computing programming library 403 is configured to construct a quantum virtual machine if the computing hardware of the second computing device is a CPU or a GPU.
[0177] Optionally, the quantum computing programming library 403 is configured to pass the quantum machine type of the specified computing hardware as a parameter to the initialization function in the quantum computing programming library contained in the machine learning system, and to create the quantum virtual machine through the initialization function.
[0178] Optionally, the quantum computing programming library 403 is configured to pass the quantum machine type of the specified computing hardware as a parameter to the quantum machine initialization interface in the quantum computing programming library contained in the machine learning system, and to create the quantum virtual machine through the quantum machine initialization interface.
[0179] Optionally, the quantum computing programming library 403 is configured to create the quantum virtual machine based on the quantum virtual machine class of the specified computing hardware in the quantum computing programming library contained in the machine learning system.
[0180] This invention also provides a storage medium storing a computer program, wherein the computer program is configured to execute the steps in any of the method embodiments described above when running.
[0181] Specifically, in this embodiment, the storage medium can be configured to store a computer program for performing the following steps:
[0182] Specify the first computing device for the classical computing layer and the second computing device for the quantum computing layer;
[0183] The first computing device is passed as a parameter to the classical computing layer interface, and the second computing device is passed as a parameter to the quantum computing layer interface.
[0184] The classical module is invoked to create a classical computing layer through the classical computing layer interface, and the quantum module is invoked to create a quantum computing layer through the quantum computing layer interface;
[0185] The classic module is invoked to construct a machine learning model including the classic computing layer and the quantum computing layer, and the first computing device and the second computing device are invoked to run the machine learning model.
[0186] Specifically, in this embodiment, the storage medium may include, but is not limited to, various media capable of storing computer programs, such as USB flash drives, read-only memory (ROM), random access memory (RAM), portable hard drives, magnetic disks, or optical disks.
[0187] Another embodiment of the present invention provides an electronic device including a memory and a processor, wherein the memory stores a computer program and the processor is configured to run the computer program to perform the steps in any of the method embodiments described above.
[0188] Specifically, the aforementioned electronic device may further include a transmission device and an input / output device, wherein the transmission device is connected to the aforementioned processor, and the input / output device is connected to the aforementioned processor.
[0189] Specifically, in this embodiment, the processor can be configured to perform the following steps via a computer program:
[0190] Specify the first computing device for the classical computing layer and the second computing device for the quantum computing layer;
[0191] The first computing device is passed as a parameter to the classical computing layer interface, and the second computing device is passed as a parameter to the quantum computing layer interface.
[0192] The classical module is invoked to create a classical computing layer through the classical computing layer interface, and the quantum module is invoked to create a quantum computing layer through the quantum computing layer interface;
[0193] The classic module is invoked to construct a machine learning model including the classic computing layer and the quantum computing layer, and the first computing device and the second computing device are invoked to run the machine learning model.
[0194] The above description, based on the embodiments shown in the figures, details the structure, features, and effects of the present invention. The above description is only a preferred embodiment of the present invention, but the present invention is not limited to the scope of implementation shown in the figures. Any changes made in accordance with the concept of the present invention, or equivalent embodiments modified to have equivalent changes, that do not exceed the spirit covered by the specification and figures, should be within the protection scope of the present invention.
Claims
1. A method for running a machine learning model, characterized in that, Applied to an electronic device including a machine learning system, the machine learning system comprising classical and quantum modules, the method includes: Specify the first computing device for the classical computing layer and the second computing device for the quantum computing layer; The first computing device is passed as a parameter to the classical computing layer interface, and the second computing device is passed as a parameter to the quantum computing layer interface. The classical module is invoked to create a classical computing layer through the classical computing layer interface, and the quantum module is invoked to create a quantum computing layer through the quantum computing layer interface; The system calls the classical module to construct a machine learning model that includes the classical computing layer and the quantum computing layer, and calls the first computing device and the second computing device to run the machine learning model. The step of calling the first computing device and the second computing device to run the machine learning model includes: When it is determined that the computing format supported by the second computing device does not include the format of the input data of the quantum computing layer, the classical module is invoked to convert the format of the input data of the quantum computing layer into the computing format supported by the second computing device through the data format conversion interface; The second computing device is invoked to run the quantum computing layer to calculate the output data corresponding to the input data.
2. The method as described in claim 1, characterized in that, The computing hardware of the first computing device includes at least one of the following: a central processing unit (CPU), a graphics processing unit (GPU), a tensor processor (TPU), and a field-programmable gate array (FPGA); the computing hardware of the second computing device includes at least one of the following: a CPU, a GPU, and a quantum processor (QPU).
3. The method as described in claim 2, characterized in that, If the computing hardware of the second computing device is a CPU or a GPU, then the second computing device is a quantum virtual machine; before calling the first computing device and the second computing device to run the machine learning model, the method further includes: The quantum virtual machine is constructed based on the quantum computing programming library contained in the machine learning system.
4. The method as described in claim 3, characterized in that, The construction of the quantum virtual machine based on the quantum computing programming library contained in the machine learning system includes: The quantum machine type of the specified computing hardware is passed as a parameter to the initialization function in the quantum computing programming library contained in the machine learning system, and the quantum virtual machine is created through the initialization function.
5. The method as described in claim 3, characterized in that, The construction of the quantum virtual machine based on the quantum computing programming library contained in the machine learning system includes: The quantum machine type of the specified computing hardware is passed as a parameter to the quantum machine initialization interface in the quantum computing programming library contained in the machine learning system, and the quantum virtual machine is created through the quantum machine initialization interface.
6. The method as described in claim 3, characterized in that, The construction of the quantum virtual machine based on the quantum computing programming library contained in the machine learning system includes: The quantum virtual machine is created based on the quantum virtual machine class of the specified computing hardware in the quantum computing programming library contained in the machine learning system.
7. A machine learning model running device, characterized in that, Applied to an electronic device including a machine learning system, the machine learning system comprising classical and quantum modules, the device comprising: A computing device determination unit is used to specify the first computing device of the classical computing layer and the second computing device of the quantum computing layer; An interface determination unit is used to pass the first computing device as a parameter to the classical computing layer interface and the second computing device as a parameter to the quantum computing layer interface. The computing layer creation unit is used to call the classical module to create a classical computing layer through the classical computing layer interface, and to call the quantum module to create a quantum computing layer through the quantum computing layer interface; The model execution unit is used to call the classical module to construct a machine learning model including the classical computing layer and the quantum computing layer, and to call the first computing device and the second computing device to run the machine learning model, wherein calling the first computing device and the second computing device to run the machine learning model includes: When it is determined that the computing format supported by the second computing device does not include the format of the input data of the quantum computing layer, the classical module is invoked to convert the format of the input data of the quantum computing layer into the computing format supported by the second computing device through the data format conversion interface; The second computing device is invoked to run the quantum computing layer to calculate the output data corresponding to the input data.
8. A machine learning system, characterized in that, The machine learning system includes: The classic module is configured to create a classic computing layer through a classic computing layer interface, the parameters of which include a first computing device of the classic computing layer. A quantum module is configured to create a quantum computing layer via a quantum computing layer interface, the parameters of which include a second computing device of the quantum computing layer; The classical module is further configured to construct a machine learning model including the classical computing layer and the quantum computing layer, and to invoke the first computing device and the second computing device to run the machine learning model, wherein invoking the first computing device and the second computing device to run the machine learning model includes: When it is determined that the computing format supported by the second computing device does not include the format of the input data of the quantum computing layer, the classical module is invoked to convert the format of the input data of the quantum computing layer into the computing format supported by the second computing device through the data format conversion interface; The second computing device is invoked to run the quantum computing layer to calculate the output data corresponding to the input data.
9. A storage medium, characterized in that, The storage medium stores a computer program, wherein the computer program is configured to execute the method described in any one of claims 1 to 6 when it is run.
10. An electronic device comprising a memory and a processor, characterized in that, The memory stores a computer program, and the processor is configured to run the computer program to perform the method as described in any one of claims 1 to 6.