Quantum gate implementation method, device, electronic device and storage medium
By analyzing the quantum gate programming code and creating quantum operation data structures, the problems of insufficient flexibility and programming complexity in the prior art are solved, and more efficient and concise quantum programming is achieved.
Patent Information
- Application Number
- CN202410814668.3
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- Filing Date
- 2024-06-24
- Publication Date
- 2024-11-12
- Estimated Expiration
- 2044-06-24
AI Technical Summary
The existing quantum programming frameworks have problems such as insufficient flexibility and high programming complexity when implementing quantum gates, which limits developers' programming efficiency and program readability.
By analyzing the quantum gate programming code, extracting and saving quantum gate data and qubit data, creating corresponding quantum operation data structures, and applying these data in quantum circuits to realize the calculation of quantum gates, supporting general quantum gate structures and matrix structures. And conduct legality checks and matching checks during programming.
It improves the computing flexibility of the quantum gate, reduces the difficulty of quantum programming, and simplifies the quantum program, making it more concise and readable.
Smart Images

Figure CN118378712B_ABST
Abstract
Description
Technical Field
[0001] The present invention relates to the field of quantum computing, and in particular to a method, device, electronic device and storage medium for implementing a quantum gate. Background Art
[0002] With the development of quantum computers, quantum programs have emerged in the field of quantum computing. In order to efficiently provide quantum programs that run on quantum computers, quantum simulation computing systems or quantum simulators, developers use programming frameworks to program quantum programs, similar to traditional program development. However, due to the difference between quantum computing and traditional computing, the existing traditional programming frameworks are not suitable for quantum programming. Therefore, some programming frameworks suitable for quantum programming have emerged in the industry, such as Qiskit created and developed by IBM Research, Cirq released by the Google Quantum AI team, and Quipper jointly developed by Dalhousie University in Canada and Princeton Institute for Advanced Study in the United States. The aforementioned quantum programming frameworks provide some tools and libraries for quantum programming, but these programming frameworks have certain limitations in different aspects, which limits programming efficiency. For example, the quantum gates and quantum operations provided are limited, and developers can only apply the quantum gates provided by the programming framework, and the calculations of these quantum gates are fixed. Although it provides programming convenience to a certain extent, it also rigidifies the calculation flexibility of quantum gates. In order to use the quantum gate programming provided by the programming framework, developers need to split the quantum calculations to be performed into computational logic that can be executed by one or more quantum gates, which increases the difficulty of quantum programming and makes quantum programs cumbersome and difficult to read. Summary of the invention
[0003] In view of this, embodiments of the present invention provide a method, device, electronic device and storage medium for implementing a quantum gate to improve the flexibility of quantum programming and simplify quantum programs.
[0004] According to one aspect of the present invention, the present invention provides a method for implementing a quantum gate, comprising:
[0005] Parsing the quantum gate programming code to obtain corresponding quantum gate data and qubit data, wherein the quantum gate data includes one or more of a gate structure, a gate parameter value, and a gate operation, and the qubit data includes at least a target bit;
[0006] Creating a quantum operation, wherein the data structure corresponding to the quantum operation includes a qubit parameter and a command data structure;
[0007] The quantum gate data obtained by parsing is saved in the command data structure, and the quantum bit data obtained by parsing is saved in the quantum bit parameter;
[0008] When the quantum operation is applied to a quantum circuit, calculation of the quantum gate is implemented based on the quantum gate data and the quantum bit data stored in the data structure corresponding to the quantum operation.
[0009] Optionally, before creating the quantum operation, the method for implementing the quantum gate further includes:
[0010] Verifying whether the qubit data structure in the qubit data is legal based on a preset qubit data structure;
[0011] Checking whether the type and quantity of qubits are legal based on preset qubit legal conditions, wherein the types of qubits include target bits and control bits;
[0012] Check whether the gate parameter value matches the qubit;
[0013] Check whether the gate parameter values match the gate operation;
[0014] In response to a qubit data structure in the qubit data conforming to a preset qubit data structure, and the type and quantity of the qubits conforming to qubit legality conditions, and the gate parameter values match the qubits, and the gate parameter values match the gate operations, determining that the inspection is passed;
[0015] Correspondingly, a quantum operation is created after the verification passes.
[0016] Optionally, the gate structure is a universal quantum gate structure or a matrix structure.
[0017] Optionally, when the gate structure is a matrix structure, the corresponding gate parameters are matrix parameters, and the corresponding gate parameter values are matrix data.
[0018] Optionally, the matrix parameters include matrix elements and matrix orders, and the matrix elements and the matrix orders are numerical values or variables or functional expressions.
[0019] Optionally, the step of checking whether the gate parameter value matches the quantum bit includes: checking whether the matrix order in the matrix parameter is equal to an exponential calculation value with 2 as the base and the target number of bits as the exponent; and determining that the check is passed in response to the matrix order being equal to the exponential calculation value with 2 as the base and the target number of bits as the exponent.
[0020] Optionally, when the gate operation is a matrix transposition operation, the step of checking whether the gate parameter value matches the gate operation includes: checking whether matrix elements in the matrix parameters constitute a unitary matrix, and determining that the check passes in response to the matrix elements constituting a unitary matrix.
[0021] Optionally, the command data structure includes at least a matrix real part parameter, a matrix imaginary part parameter and a unitary matrix description parameter.
[0022] Optionally, when the gate operation obtained by parsing includes a control bit setting operation of a qubit, a control bit is specified in the parsed qubit data, and the specified control bit is saved to a control bit parameter in a qubit parameter, and the remaining qubits in the qubit data are saved to a target bit parameter in a qubit parameter.
[0023] Optionally, the definition instructions and programming codes of the composite quantum gate included in the quantum gate programming code include:
[0024] Creating a composite gate function, wherein the composite gate function includes a plurality of quantum gate data structures;
[0025] Identify the separation identifiers from the quantum programming code, and store the programming code corresponding to each separation identifier into the corresponding quantum gate data structure;
[0026] Correspondingly, the programming code in each quantum gate data structure is parsed to obtain the corresponding quantum gate data and quantum bit data;
[0027] Correspondingly, a respective quantum operation is created for each quantum gate data structure, and quantum gate data and qubit data parsed from the programming code in each quantum gate data structure are saved into corresponding parameters of the corresponding data structure of the corresponding quantum operation;
[0028] When the composite quantum gate is applied to a quantum circuit, the quantum operations in each quantum gate data structure are provided to the quantum circuit one by one, and the calculation of the corresponding quantum gate is implemented based on the quantum gate data and quantum bit data stored in the data structure corresponding to the quantum operation.
[0029] According to another aspect of the present invention, the present invention further provides a device for implementing a quantum gate, comprising an interface unit, a structure unit, a parameter unit, a parsing unit and an operation creation unit, wherein the interface unit is configured to at least provide a programming code input interface; the structure unit is configured to provide one or more gate structures constituting a quantum gate; the parameter unit is configured to provide one or more gate parameters and / or gate operations for each gate structure; the parsing unit is configured to parse the quantum gate programming code to obtain corresponding quantum gate data and qubit data, wherein the quantum gate data includes one or more of a gate structure, a gate parameter value and a gate operation, and the qubit data includes at least a target bit; the operation creation unit is configured to create a quantum operation, the data structure corresponding to the quantum operation includes a qubit parameter and a command data structure, the parsed quantum gate data is stored in the command data structure, and the parsed qubit data is stored in the qubit parameter; when the quantum operation is applied to a quantum circuit, the calculation of the quantum gate is implemented based on the quantum gate data and the qubit data stored in the data structure corresponding to the quantum operation.
[0030] Optionally, when the parsing unit parses the quantum gate programming code, when the quantum gate programming code contains the definition instruction and programming code of the composite quantum gate, the operation creation unit creates a composite gate function, and the composite gate function includes multiple quantum gate data structures; when the parsing unit identifies the separation identifier in the programming code, the programming code corresponding to each separation identifier is stored in the corresponding quantum gate data structure; correspondingly, the parsing unit parses the programming code in each quantum gate data structure to obtain the corresponding quantum gate data and qubit data; correspondingly, the operation creation unit creates a respective quantum operation for each quantum gate data structure, and saves the quantum gate data and qubit data parsed from the programming code in each quantum gate data structure to the corresponding parameters of the corresponding data structure of the corresponding quantum operation; when the composite quantum gate is applied to the quantum circuit, the quantum operations in each quantum gate data structure are provided to the quantum circuit one by one, and the calculation of the corresponding quantum gate is realized based on the quantum gate data and qubit data stored in the corresponding data structure of the quantum operation.
[0031] According to another aspect of the present invention, the present invention further provides an electronic device, comprising a processor and a memory storing computer program instructions; the processor implements the aforementioned quantum gate implementation method when executing the computer program instructions.
[0032] According to another aspect of the present invention, the present invention further provides a computer-readable storage medium, on which computer program instructions are stored, and when the computer program instructions are executed by a processor, the aforementioned method for realizing a quantum gate is implemented.
[0033] The embodiments of the present invention can effectively improve the computational flexibility of quantum gates, reduce the difficulty of quantum programming, improve the efficiency of quantum programming, and make the obtained quantum program concise and readable. BRIEF DESCRIPTION OF THE DRAWINGS
[0034] In order to more clearly illustrate the technical solution of the embodiment of the present invention, the drawings in the embodiment of the present invention are briefly introduced below.
[0035] Figure 1 is a flow chart of a method for implementing a quantum gate according to an embodiment of the present invention;
[0036] Figure 2 is a detailed flow chart of a method for implementing a quantum gate according to an embodiment of the present invention;
[0037] Figure 3 is a flow chart of a method for implementing a composite quantum gate according to an embodiment of the present invention;
[0038] Figure 4is a principle block diagram of a device for implementing a quantum gate according to an embodiment of the present invention;
[0039] Figure 5 It is a structural principle block diagram of an electronic device according to an embodiment of the present invention. DETAILED DESCRIPTION
[0040] The principles and spirit of the present invention will be described below with reference to several exemplary embodiments. It should be understood that the purpose of providing these embodiments is to make the principles and spirit of the present invention clearer and more thorough, so that those skilled in the art can better understand and implement the principles and spirit of the present invention. The exemplary embodiments provided herein are only part of the embodiments of the present invention, not all of the embodiments. Based on the embodiments herein, all other embodiments obtained by ordinary technicians in this field without creative work are within the scope of protection of the present invention.
[0041] In the present invention, terms such as first, second, third, etc. are only used to distinguish one entity (or operation) from another entity (or operation), but are not intended to require or imply any order or relationship between these entities (or operations).
[0042] Figure 1 This is a flow chart of a method for implementing a quantum gate according to an embodiment of the present invention. The method is applied in a quantum programming framework system. When a developer applies the quantum programming framework system to perform quantum programming, the developer inputs a programming code for defining a quantum gate through a programming code input interface as needed. When the quantum programming framework system parses the quantum programming code and parses the quantum gate programming code, the quantum gate defined by the developer is implemented according to the programming code. The method includes the following steps:
[0043] Step S1, parsing the quantum gate programming code, and obtaining quantum gate data and qubit data therefrom, wherein the quantum gate data includes one or more of gate structure, gate parameter value and gate operation, and the qubit data includes at least a target bit.
[0044] Step S2: creating a quantum operation, wherein the data structure corresponding to the quantum operation includes multiple parameters.
[0045] Step S3, saving the parsed quantum gate data and quantum bit data into corresponding parameters of the data structure corresponding to the quantum operation.
[0046] The following examples and Figure 2 right Figure 1 The method steps shown are described in detail. Figure 2 , Figure 2Detailed flowchart of a method for implementing a quantum gate according to an embodiment of the present invention. The method comprises the following steps:
[0047] Step S11, the quantum gate programming code is parsed to obtain quantum gate data and qubit data, wherein the quantum gate data includes one or more of a gate structure, a gate parameter value, and a gate operation, and the qubit data includes at least a target bit. For example, when the quantum gate programming code is as shown in Table 1 below, the gate structure used by the quantum gate is determined to be a matrix structure based on "Matric()", wherein one gate parameter is a matrix parameter, and the gate parameter value is specific matrix data. In this embodiment, the corresponding matrix data is [[0.5, 0.5], [0.5, -0.5]], and the other gate parameter is a quantum gate name. In this embodiment, the quantum gate name is "custom-a", and the qubit data is a qubit "qr[0]".
[0048] Table 1
[0049] Programming Code Serial number Matrix([[0.5,0.5],[0.5,-0.5]],"custom-a")*qr[0] 1-1
[0050] For another example, when the quantum gate programming code is as shown in the following Table 2, the gate structure used by the quantum gate is determined to be a matrix structure based on "Matric()", one of the gate parameters is a matrix parameter, and the gate parameter value is matrix data. In this embodiment, the matrix data is [[-0.5, 0.5], [0.5, -0.5]], and the other gate parameter is the quantum gate name. In this embodiment, the quantum gate name is "custom-b", the gate operation is the control bit setting operation "ctrl(1)", and the quantum bit data includes two quantum bits "qr[0]" and "qr[1]".
[0051] Among them, when the gate structure is a matrix structure, the corresponding gate parameters are matrix parameters, and the matrix parameters include matrix elements and matrix orders, and the matrix elements and the matrix orders are numerical values or variables or functional relationships. The matrix element parameter values and matrix order parameter values in this embodiment are numerical values, thereby determining a specific matrix data. Developers can also set matrix elements as variables according to the needs of calculations, and set different numerical values for the variables during the programming process according to actual needs, thereby obtaining a parameterized quantum gate; when the matrix elements are functional relationships, by setting the functional relationship and its independent variables, the matrix of the quantum gate can realize various possible calculations during programming.
[0052] Table 2
[0053]
[0054] Step S12, calling the _init_ method of Matrix to save the parsed data.
[0055] Step S13, based on the preset qubit data structure, check whether the qubit data structure of the qubit is legal. The qubit data structure is, for example: the qubit after the symbol "*" should be a QuBit object, and the QuBit object is represented by "qr[]", where "[]" is a positive integer starting from 0; when there are multiple QuBit objects, the multiple QuBit objects should be placed in brackets and separated by commas. After the symbol "*" is obtained, check whether the qubit after the symbol "*" is a QuBit object. If the qubit obtained by parsing is a QuBit object, and the expression method conforms to the aforementioned qubit data structure, it means that the qubit data structure meets the requirements and is legal, otherwise it is illegal. For the example shown in Table 1, there is a qubit "qr[0]" after the symbol "*", and its expression method conforms to the expression method of the QuBit object, so the qubit data structure in Table 1 is legal. For the example shown in Table 2, there are two qubits "qr[0], qr[1]" after the symbol "*", and the expression of each qubit conforms to the expression of the QuBit object, and the two QuBit objects are placed in brackets and separated by commas, so the qubit data structure in Table 2 is legal. After inspection, if the qubit data structure of the qubit is legal, step S14 is executed. If it is illegal, step S20 is executed.
[0056] Step S14, calculate the number of control bits and target bits, and specify the control bits and target bits from the identified quantum bits. For example, when there is a control bit setting operation in the gate operation, the number of control bits is determined according to the parameter value in the control bit setting operation, the number of target bits is obtained by subtracting the number of control bits from the total number of quantum bits, and the control bits and target bits are respectively specified from the total quantum bits according to the specified strategy. For example, for the quantum gate programming code in Table 2, which includes the quantum bit control bit setting operation "ctrl(1)", since its parameter value is 1, it is determined that there is one control bit. In this embodiment, the first quantum bit "qr[0]" is specified as the control bit, and the remaining quantum bits "qr[1]" are specified as target bits. This embodiment specifies in order from front to back, of course, the specified order can also be from back to front, or according to certain strategies, which will not be repeated here. If there is no control bit setting operation, all current quantum bits are specified as target bits, as shown in the example in Table 1, and the quantum bit "qr[0]" in Table 1 is specified as the target bit.
[0057] Step S15, check whether the type and quantity of qubits are legal. If legal, execute step S16; if illegal, execute step S20. Among them, the types of qubits include target bits and control bits. The qubit legality condition is, for example: when there is only one qubit after the symbol "*", there cannot be a control bit; the number of control bits cannot be greater than or equal to the total number of qubits. During the inspection, it is determined whether the condition is met based on the determined control bits, target bits and their respective quantities. If they are met, the current type and quantity of qubits are legal, that is, the setting of the control bits and target bits of the qubits is reasonable. In the example shown in Table 1, since there is only one qubit and it is designated as the target bit, it meets the qubit legality condition. For the example shown in Table 2, there are two qubits, one qubit is a control bit and the other qubit is a target bit, which meets the condition that the number of control bits cannot be greater than or equal to the total number of qubits, and thus also meets the qubit legality condition.
[0058] Step S16, check whether the matrix order in the matrix parameters matches the target number of bits. The format of the matrix structure must satisfy N=2 n Condition, where N is the matrix order and n is the target number of bits. In the above two embodiments, the target bit is one, that is, n = 1, and the matrix [[0.5, 0.5], [0.5, -0.5]] and the matrix [[-0.5, 0.5], [0.5, -0.5]] are 2*2 matrices, that is, the matrix order N = 2 = 2 1 , thus satisfying the format requirements of the matrix structure, then executing step S17. When the matrix order in the matrix parameter does not match the target bit number, it indicates that there is an error in the current programming code, thus executing step S20. In this embodiment, the matrix parameter is a gate parameter, that is, in this embodiment, what is checked is whether the gate parameter value matches the qubit.
[0059] Step S17, determining whether there is a matrix transposition operation in the gate operation, if yes, executing step S18. If not, executing step S19.
[0060] Step S18, checking whether the matrix elements in the matrix parameters constitute a unitary matrix. If the matrix elements constitute a unitary matrix, it means that the gate parameter value matches the gate operation, and then executing step S19; if the matrix elements do not constitute a unitary matrix, executing step S20.
[0061] Step S19, confirm that the inspection is passed.
[0062] Step S20, generating error prompt information and displaying it to the developer through the interface.
[0063] Step S21, creating a quantum operation. For example, a command operation is created, which has a corresponding data structure, and the data structure includes multiple parameters, for example, the data structure includes a quantum bit parameter and a command data structure; the quantum bit parameter includes a control bit parameter and / or a target bit parameter, and the command data structure includes parameters for storing matrix data corresponding to the gate structure, such as a matrix real part parameter, a matrix imaginary part parameter, and a unitary matrix description parameter. Optionally, the data structure of the quantum operation also includes a quantum gate identification parameter.
[0064] Step S22, the identified gate structure, gate parameter value, qubit or gate operation is saved in the corresponding parameters in the quantum operation data structure. For example, the matrix data in the quantum gate data is saved in the matrix real part parameter and the matrix imaginary part parameter, and the unitary matrix description parameter is set to indicate whether the current matrix is a unitary matrix or not, and the determined target bit or control bit is saved in the corresponding target bit parameter and control bit parameter in the qubit parameter.
[0065] A quantum gate is implemented by the above method. When the developer uses the quantum gate, based on specific instructions, the command operation created above is submitted to the quantum circuit, and the corresponding calculation of the quantum gate can be implemented in the quantum circuit based on the quantum gate data and quantum bit data stored in the quantum operation data structure.
[0066] The present invention also provides a method for implementing a composite quantum gate. When developers use a quantum programming framework system to perform quantum programming, they can define a composite quantum gate that combines multiple gate operations together, and use a separation identifier in the programming code to separate the programming codes of multiple quantum gates. In the process of parsing the quantum programming code, the quantum programming framework system can implement the composite quantum gate based on the programming code input by the developer. Figure 3 , Figure 3 is a flow chart of a method for implementing a composite quantum gate according to an embodiment of the present invention. In this embodiment, when a definition instruction of a composite quantum gate is parsed from the quantum gate programming code, the method specifically includes the following steps:
[0067] Step S31, creating a composite gate function. Take the case where a developer inputs the programming code shown in Table 3 below as an example:
[0068] Table 3
[0069]
[0070] According to the instructions "def my_gate(a,b,c,d)" and "return Gate()" in the coding code, the content of the subsequent programming code is determined to implement a composite quantum gate. Based on the programming code "my_gate()", a composite gate function is created, and the composite gate function includes multiple quantum gate data structures.
[0071] Step S32, identifying the separation mark in the programming code, and storing the programming code corresponding to each separation mark in the quantum gate data structure. In this embodiment, the symbol "<<()" is used as the separation mark of different quantum gates, and the programming code in each symbol "<<()" is used as a quantum gate programming code. In one embodiment, each quantum gate data structure in the composite gate function includes quantum gate parameters and quantum bit parameters. When the programming code corresponding to each separation mark is stored in the quantum gate data structure, a transfer (_Ishift_) function is created and called, and the data in the separation mark is transferred to the corresponding parameter through the _Ishift_ function. For example, for the data in the first separation mark, the _Ishift_ function saves the "Matrix([[-0.5,0.5],[0.5,0.5]]).ctrl(2)" before the comma in the quantum gate parameter, and saves the "(a,b,c)" after the comma in the quantum bit parameter. By analogy, the programming codes corresponding to the other four separation marks are stored in the corresponding quantum gate data structure.
[0072] Step S33: using the programming code in the first quantum gate data structure as the quantum gate programming code to be parsed.
[0073] Step S34, parse and obtain quantum gate data and qubit data from the quantum gate programming code to be parsed, wherein the quantum gate data includes one or more of a gate structure, a gate parameter value, and a gate operation, and the qubit data includes at least a target bit. The gate structure is, for example, a universal quantum gate structure, and the corresponding gate parameter value is, for example, matrix data corresponding to the universal quantum gate structure. The gate operation is, for example, a control bit setting operation or a matrix transposition operation. Taking the aforementioned programming code as an example, when parsing the first three quantum gate programming codes, a matrix structure is obtained, and when parsing the last two quantum gate programming codes, an H gate and an X gate are obtained respectively.
[0074] Step S35: creating a quantum operation, wherein the data structure corresponding to the quantum operation includes multiple parameters.
[0075] Step S36, saving the parsed quantum gate data and quantum bit data into corresponding parameters of the data structure corresponding to the quantum operation.
[0076] The processing of step S35 and step S36 is described in detail above. Figure 2The description of the process shown will not be repeated here.
[0077] Step S37, determine whether there is any unprocessed quantum gate programming code to be parsed, if yes, return to step S34, if no, end.
[0078] After the above processing flow, multiple quantum gates can be merged and bound together to form a computing unit of a composite quantum gate. In the embodiment shown in Table 3, the composite quantum gate is composed of three quantum gates defined by developers, an H gate and an X gate, wherein the first quantum gate is a three-bit quantum gate, qubit a and qubit b are control bits, qubit c is the target bit, and the matrix [[-0.5, 0.5], [0.5, 0.5]] is applied to the target bit. The second quantum gate is a two-bit quantum gate, qubit a is the control bit, qubit c is the target bit, and the matrix [[0.5, -0.5], [0.5, 0.5]] is applied to the target bit. The third quantum gate is a single-bit quantum gate, and the matrix [[0.5, 0.5], [-0.5, 0.5]] is applied to qubit b. The fourth quantum gate is an H gate, which acts on qubit d. The fifth quantum gate is an X gate, which acts on qubit d. The above five quantum gates constitute a 4-bit composite quantum gate.
[0079] Table 4 is an application example of the composite quantum gate in Table 3.
[0080]
[0081] A composite gate is obtained based on the programming code of sequence number 1-3, which corresponds to a composite gate function and stores the data of each quantum gate.
[0082] A quantum circuit is defined according to the programming code of sequence number 1-4, and 4 quantum bits are allocated to the quantum circuit according to the programming code of sequence number 1-5.
[0083] Based on the programming code of sequence number 1-6, the _mul_ method of the quantum gate is first called, and the composite gate function is called through the _mul_ method to obtain the data structure corresponding to the quantum operation in each quantum gate data structure in the composite gate function, and then based on each quantum gate data structure, the _mul_ method of the quantum gate is called one by one, and the aforementioned quantum bits are respectively passed into the data structure of the quantum operation as parameters, that is, q1[3] corresponds to quantum bit a, q1[1] corresponds to quantum bit b, q1[0] corresponds to quantum bit c, and q1[2] corresponds to quantum bit d, and submitted to the aforementioned defined quantum circuit, based on the quantum gate data and quantum bit data stored in the data structure of each quantum operation, the calculation of the corresponding quantum gate is realized in turn, thereby realizing all quantum gate calculations of a composite quantum gate. As shown in Table 4, when the programming code 1-6 is executed, the five quantum gates in the composite quantum gate in the programming code 1-3 are sequentially acted on the corresponding quantum bits in the quantum circuit from front to back to realize the corresponding quantum gate operation.
[0084] Based on the programming codes of sequence numbers 1-6, it can be seen that the application method of the composite quantum gate is the same as that of a simple quantum gate, which conforms to the application habits of developers. Since developers can combine multiple quantum gates to form a computing unit according to the needs of the computing logic, the programming code is simplified and the readability of the programming code is increased. Developers can not only build more complex and flexible quantum circuits by using composite quantum gates, but also achieve a wider range of quantum transformations by combining different simple quantum gate operations, thereby improving the expressive power of quantum circuits. Developers can flexibly define composite quantum gates by adjusting and combining different quantum gate operations, and can find more effective circuit structures and reduce the total number of quantum gates, thereby effectively optimizing quantum circuits and improving computing efficiency. In addition, in quantum computing, both quantum bits and quantum gate operations are susceptible to noise and errors. By cleverly designing composite quantum gates, the sensitivity to noise and errors can be reduced, the stability of computing can be improved, and the error rate can be reduced. Furthermore, composite quantum gates facilitate the construction of quantum algorithms, and complex quantum algorithms can be implemented through appropriate composite quantum gates.
[0085] In another aspect, the present invention also provides a device for implementing a quantum gate. Figure 4 , Figure 4It is a principle block diagram of a quantum gate implementation device according to an embodiment of the present invention. In this embodiment, the quantum gate implementation device includes an interface unit 11, a structure unit 12, a parameter unit 13, a parsing unit 14 and an operation creation unit 15. Among them, the interface unit 11 is used to provide a programming code input interface. The structure unit 12 is used to provide one or more gate structures constituting a quantum gate. The parameter unit 13 is used to provide one or more gate parameters and / or gate operations for each gate structure; the parsing unit 14 parses the quantum gate data and qubit data from the quantum gate programming code, wherein the quantum gate data includes one or more of the gate structure, the gate parameter value and the gate operation, and the qubit data includes at least the target bit. The operation creation unit 15 creates a quantum operation, and the data structure corresponding to the quantum operation includes multiple parameters, and the parsed quantum gate data and qubit data are saved in the corresponding parameters of the quantum operation data structure; when the quantum operation is applied to the quantum circuit, the quantum gate calculation is implemented based on the quantum gate data and qubit data saved in the data structure of the quantum operation.
[0086] The interface unit 11 is used to interact with developers. When developers use the quantum programming framework system to perform quantum programming, when they need to define a quantum gate, they can input programming codes through the programming code input interface provided by the interface unit 11, which includes quantum gate programming codes. The structure unit 12 provides a gate structure constituting a quantum gate, such as a universal quantum gate structure. The universal quantum gates are, for example, CR, H, I, ISwap, Measure, CNOT, Toffoli, P, R, Rx, Ry, Rz, S, Sdg, T, Tdg, X, Y, Z, X1, Y1, Z1, NOT, Swap, SqrtSwap, SqrtX, Rxx, Ryy, Rzz, U1, U2, U3, etc. The above quantum gates are some universal quantum gates that have been standardized and defined. Correspondingly, the gate parameters provided by the parameter unit 13 include matrix data corresponding to each universal quantum gate structure. The gate structure of the quantum gate provided by the structural unit 12 is also a matrix structure, and correspondingly, the gate parameters provided by the parameter unit 13 include matrix parameters, such as matrix element parameters and matrix order parameters. The matrix element parameter values and matrix order parameter values are numerical values, variables or function relationships. Developers can set the matrix order and elements according to the needs of calculation, for example, the matrix order is 2, 4, 8, etc. When the matrix element is a specific numerical value, a fixed matrix is formed; when the matrix element is a variable, different numerical values can be set for the variable during the programming process according to actual needs, so as to obtain a parameterized quantum gate; when the matrix element is a function relationship, by setting the function relationship and its independent variables, the matrix of the quantum gate can realize various possible calculations during programming. The gate parameters provided by the parameter unit 13 are also parameters such as quantum gate names. The parameter unit 13 also provides some gate operations, such as some functional functions that implement quantum operations, such as the ctrl function for setting control bits, the inv function for matrix transposition operations, etc. When programming, developers select the parameters to be used according to needs and assign values to them.
[0087] The developer uses the programming code input interface provided by the interface unit 11 to write the quantum gate programming code according to the matrix structure provided by the structure unit 11 and the parameters provided by the parameter unit 13. For example, the developer can define a quantum gate programming code according to the matrix structure provided by the structure unit 11 and the parameters provided by the parameter unit 13 as shown in Table 5:
[0088] Table 5
[0089]
[0090] Among them, Matrix() represents a matrix structure; [[1,0], [1,0]] is the specific matrix data; 'a' represents the name of the quantum gate of the Matrix structure; ctrl(3) represents setting 3 control bits, and (qc[0], qc[1], qc[2], qc[3]) represents four quantum bits.
[0091] When parsing the aforementioned programming code, the parsing unit 14 parses the developer's programming code to obtain quantum gate data and qubit data, such as the matrix structure and specific matrix data "[[1,0],[1,0]]", the quantum gate name 'a', the control bit setting operation "ctrl(3)", and the qubit data "(qc[0],qc[1],qc[2],qc[3])". In one embodiment, the parsing unit 14 calls the _init_ method of Matrix to save the above parsed data. Moreover, in a further embodiment, the parsing unit 14 also performs various checks during the data parsing process, such as checking whether the qubit data structure of the qubit is legal; calculating the number of control bits and target bits, and specifying the control bits and target bits from the parsed qubits; checking whether the setting of the control bits is reasonable; checking whether the matrix order in the matrix parameters matches the number of target bits; checking whether there is a matrix transposition operation in the gate operation and whether the matrix elements in the matrix parameters constitute a unitary matrix when there is a matrix transposition operation, etc. When performing the above-mentioned various checks, a prompt message is generated when any of the checks fails, and is displayed to the developer through the interface. When all the checks meet the corresponding requirements or conditions, it is determined that the check of the segment of programming code has passed, and the data is saved at this time.
[0092] The operation creation unit 15 creates a quantum operation, such as a command operation, and the data structure corresponding to the quantum operation includes multiple parameters, and the quantum gate data and quantum bit data obtained by parsing are saved to the corresponding parameters in the quantum operation data structure. Therefore, when the quantum operation is submitted to the quantum circuit, the calculation of the quantum gate is realized when the quantum operation is executed.
[0093] This embodiment provides a definition instruction of a composite quantum gate used in programming and a separation identifier for separating multiple quantum gate programming codes. Therefore, when the parsing unit 14 parses the programming code to obtain the definition instruction and separation identifier of the composite quantum gate, the operation creation unit 15 creates a composite gate function, and the composite gate function includes multiple quantum gate data structures. When the parsing unit 14 parses the separation identifier, the operation creation unit 15 saves the programming code corresponding to the separation identifier to a quantum gate data structure in the composite gate function, which includes quantum gate parameters and quantum bit parameters. In one embodiment, the operation creation unit 15 calls the transfer (_Ishift_) function to save a part of the programming code corresponding to the separation identifier to the quantum gate parameters, and another part to the quantum bit parameters. Then, as described above, the parsing unit 14 parses the programming code corresponding to each separation identifier to obtain the gate structure, gate parameter value, quantum bit and gate operation of the quantum gate, etc. The operation creation unit 15 creates a quantum operation and saves the parsed data to the corresponding parameters in the quantum operation data structure, thereby binding multiple quantum gates together to form a composite quantum gate calculation unit.
[0094] As can be seen from the above description, this embodiment provides a composite gate that can be defined by developers, which can merge multiple quantum gates together, thereby simplifying the development work of developers. Composite gates can realize specific functions and can be applied to any quantum circuit. The implementation device of the quantum gate enables developers to define quantum gates in the programming process according to the functions to be realized and the requirements of calculations, so as to implement some specific quantum operations or calculations. It can be used in quantum programming like a general quantum gate, making the implementation of quantum calculation more flexible, and at the same time, some operations and calculations can be integrated together to simplify the programming code and improve programming efficiency.
[0095] In another aspect, the present invention further provides an electronic device, see Figure 5 , Figure 5 1 is a block diagram of the structure principle of an electronic device according to an embodiment of the present invention. Figure 5 As shown, the electronic device includes a processor 601 and a memory 602 storing computer program instructions; when the processor 601 executes the computer program instructions, the implementation method of the quantum gate in the above-mentioned embodiment is implemented.
[0096] Specifically, the processor 601 may include a central processing unit (CPU) or a graphics processing unit (GPU), or an application specific integrated circuit (ASIC), or may be configured to implement one or more integrated circuits of an embodiment of the present invention. The memory 602 may include a memory for data or instructions. For example, the memory 602 may be at least one of the following: a hard disk drive (HDD), a read-only memory (ROM), a random access memory (RAM), a floppy disk drive, a flash memory, an optical disk, a magneto-optical disk, a magnetic tape, a universal serial bus (USB) drive or other physical / tangible memory storage device. For another example, the memory 602 includes a removable or non-removable (or fixed) medium. For another example, the memory 602 may be inside or outside the integrated gateway disaster recovery device. The memory 602 may be a non-volatile solid-state memory. In other words, typically the memory 602 includes a tangible (non-transitory) computer-readable storage medium (such as a memory device) encoded with executable instructions, wherein when the stored executable instructions are executed by the processor 601 (such as executed by one or more processors), the method for implementing the quantum gate in the embodiment of the present invention can be implemented.
[0097] In one example, Figure 5 The electronic device shown may also include a communication interface 603 and a bus 610. The processor 601, the memory 602, and the communication interface 603 are connected and communicate with each other via the bus 610. The communication interface 603 is mainly used to implement communication between modules, devices, units, and / or devices in the electronic device.
[0098] The bus 610 includes hardware, software, or both, and can couple the components of the online data traffic metering device to each other. For example, the bus may include at least one of the following: an accelerated graphics port (AGP) or other graphics bus, an enhanced industrial standard architecture (EISA) bus, a front-side bus (FSB), a hypertransport (HT) interconnect, an industrial standard architecture (ISA) bus, an infinite bandwidth interconnect, a low pin count (LPC) bus, a memory bus, a microchannel architecture (MCA) bus, a peripheral component interconnect (PCI) bus, a PCI-Express (PCI-X) bus, a serial advanced technology attachment (SATA) bus, a video electronics standard association local (VLB) bus, or other suitable buses. The bus 610 may include one or more buses. Although the embodiments of the present invention describe or illustrate a specific bus, the embodiments of the present invention may consider any suitable bus or interconnection method.
[0099] On the other hand, an embodiment of the present invention further provides a computer-readable storage medium, on which computer program instructions are stored, and when the computer program instructions are executed by a processor, the aforementioned method for implementing a quantum gate is implemented.
[0100] The flowcharts and / or block diagrams of the methods, devices, systems, and computer program products of the embodiments of the present invention are described above by way of example, and various aspects of the related aspects are described. It should be understood that each box or combination thereof in the flowchart and / or block diagram may be implemented by computer program instructions, or may be implemented by dedicated hardware that performs a specified function or action, or may be implemented by a combination of dedicated hardware and computer instructions. For example, these computer program instructions may be provided to a processor of a general-purpose computer, a special-purpose computer, or other programmable data processing device to form a machine that enables these instructions executed by such a processor to enable the implementation of the functions / actions specified in each box or combination thereof in the flowchart and / or block diagram. Such a processor may be a general-purpose processor, a special-purpose processor, a special application processor, or a field programmable logic circuit.
[0101] The functional blocks shown in the structural block diagram of the embodiment of the present invention can be implemented as hardware, software, firmware or a combination thereof. When implemented in hardware, it can be, for example, an electronic circuit, an application-specific integrated circuit (ASIC), appropriate firmware, a plug-in, a function card, etc.; when implemented in software, it is a program or code segment used to perform the required task. The program or code segment can be stored in a memory, or transmitted on a transmission medium or a communication link via a data signal carried in a carrier. The code segment can be downloaded via a computer network such as the Internet, an intranet, etc.
[0102] It should be noted that the present invention is not limited to the specific configurations and processes described above or shown in the figures. The above is only a specific implementation mode of the present invention. Those skilled in the art can clearly understand that for the convenience and brevity of description, the specific working process of the described system, device, module or unit can refer to the corresponding process in the method embodiment without further description. It should be understood that the protection scope of the present invention is not limited to this. Any technician familiar with the technical field can think of various equivalent modifications or substitutions within the technical scope disclosed by the present invention, and these modifications or substitutions should be covered within the protection scope of the present invention.
Claims
1. A method for realizing a quantum gate, characterized in that: include: Parsing the quantum gate programming code to obtain corresponding quantum gate data and qubit data, wherein the quantum gate data includes one or more of a gate structure, a gate parameter value, and a gate operation, and the qubit data includes at least a target bit; Creating a quantum operation, wherein the data structure corresponding to the quantum operation includes a qubit parameter and a command data structure; The quantum gate data obtained by parsing is saved in the command data structure, and the quantum bit data obtained by parsing is saved in the quantum bit parameter; When the quantum operation is applied to a quantum circuit, calculation of the quantum gate is implemented based on the quantum gate data and the quantum bit data stored in the data structure corresponding to the quantum operation.
2. The method for realizing a quantum gate according to claim 1, characterized in that: Before creating the quantum operation, the method for implementing the quantum gate further includes: Verifying whether the qubit data structure in the qubit data is legal based on a preset qubit data structure; Checking whether the type and quantity of qubits are legal based on preset qubit legal conditions, wherein the types of qubits include target bits and control bits; Check whether the gate parameter value matches the qubit; Check whether the gate parameter values match the gate operation; In response to a qubit data structure in the qubit data conforming to a preset qubit data structure, and the type and quantity of the qubits conforming to qubit legality conditions, and the gate parameter values match the qubits, and the gate parameter values match the gate operations, determining that the inspection is passed; Correspondingly, a quantum operation is created after the verification passes.
3. The method for realizing a quantum gate according to claim 2, characterized in that: The gate structure is a universal quantum gate structure or a matrix structure.
4. The method for realizing a quantum gate according to claim 3, characterized in that: When the gate structure is a matrix structure, the corresponding gate parameters are matrix parameters, and the corresponding gate parameter values are matrix data.
5. The method for realizing a quantum gate according to claim 4, characterized in that: The matrix parameters include matrix elements and matrix orders, and the matrix elements and the matrix orders are numerical values or variables or functional expressions.
6. The method for realizing a quantum gate according to claim 5, characterized in that: The step of checking whether the gate parameter value matches the quantum bit includes: checking whether the matrix order in the matrix parameter is equal to the exponential calculation value with 2 as the base and the target number of bits as the exponent; in response to the matrix order being equal to the exponential calculation value with 2 as the base and the target number of bits as the exponent, determining that the check is passed.
7. The method for realizing a quantum gate according to claim 5, characterized in that: When the gate operation is a matrix transposition operation, the step of checking whether the gate parameter value matches the gate operation includes: checking whether the matrix elements in the matrix parameters form a unitary matrix, and determining that the check is passed in response to the matrix elements forming a unitary matrix.
8. The method for realizing a quantum gate according to claim 1, characterized in that: The command data structure includes at least a matrix real part parameter, a matrix imaginary part parameter and a unitary matrix description parameter.
9. The method for realizing a quantum gate according to claim 1, characterized in that: When the gate operation obtained by parsing includes a control bit setting operation of a qubit, a control bit is specified in the parsed qubit data, and the specified control bit is saved to a control bit parameter in a qubit parameter, and the remaining qubits in the qubit data are saved to a target bit parameter in a qubit parameter.
10. The method for realizing a quantum gate according to claim 1, characterized in that: The definition instructions and programming codes of the composite quantum gates included in the quantum gate programming code include: Creating a composite gate function, wherein the composite gate function includes a plurality of quantum gate data structures; Identify the separation identifier from the quantum gate programming code, and store the programming code corresponding to each separation identifier into the corresponding quantum gate data structure; Correspondingly, the programming code in each quantum gate data structure is parsed to obtain the corresponding quantum gate data and quantum bit data; Correspondingly, a respective quantum operation is created for each quantum gate data structure, and quantum gate data and qubit data parsed from the programming code in each quantum gate data structure are saved into corresponding parameters of the corresponding data structure of the corresponding quantum operation; When the composite quantum gate is applied to a quantum circuit, the quantum operations in each quantum gate data structure are provided to the quantum circuit one by one, and the calculation of the corresponding quantum gate is implemented based on the quantum gate data and quantum bit data stored in the data structure corresponding to the quantum operation.
11. A device for implementing a quantum gate, characterized in that: include: an interface unit configured to provide at least a programming code input interface; A structural unit configured to provide one or more gate structures constituting a quantum gate; a parameter unit configured to provide one or more gate parameters and / or gate operations for each gate structure; a parsing unit configured to parse the quantum gate programming code to obtain corresponding quantum gate data and qubit data, wherein the quantum gate data includes one or more of a gate structure, a gate parameter value, and a gate operation, and the qubit data includes at least a target bit; An operation creation unit is configured to create a quantum operation, wherein the data structure corresponding to the quantum operation includes a qubit parameter and a command data structure, the quantum gate data obtained by parsing is stored in the command data structure, and the qubit data obtained by parsing is stored in the qubit parameter; when the quantum operation is applied to a quantum circuit, the calculation of the quantum gate is implemented based on the quantum gate data and the qubit data stored in the data structure corresponding to the quantum operation.
12. An electronic device, characterized in that: The invention comprises a processor and a memory storing computer program instructions; when the processor executes the computer program instructions, the method for realizing a quantum gate as claimed in any one of claims 1 to 10 is implemented.
13. A computer-readable storage medium, characterized in that: The computer-readable storage medium stores computer program instructions, and when the computer program instructions are executed by a processor, the method for realizing a quantum gate according to any one of claims 1 to 10 is implemented.
