WO2024066808A1 - Quantum circuit generation method and apparatus, storage medium, and electronic device - Google Patents

Quantum circuit generation method and apparatus, storage medium, and electronic device Download PDF

Info

Publication number
WO2024066808A1
WO2024066808A1 PCT/CN2023/114232 CN2023114232W WO2024066808A1 WO 2024066808 A1 WO2024066808 A1 WO 2024066808A1 CN 2023114232 W CN2023114232 W CN 2023114232W WO 2024066808 A1 WO2024066808 A1 WO 2024066808A1
Authority
WO
WIPO (PCT)
Prior art keywords
quantum
target
bit
logic gate
initial
Prior art date
Application number
PCT/CN2023/114232
Other languages
French (fr)
Chinese (zh)
Inventor
方圆
冷博洋
王奥博
Original Assignee
本源量子计算科技(合肥)股份有限公司
Priority date (The priority date is an assumption and is not a legal conclusion. Google has not performed a legal analysis and makes no representation as to the accuracy of the date listed.)
Filing date
Publication date
Application filed by 本源量子计算科技(合肥)股份有限公司 filed Critical 本源量子计算科技(合肥)股份有限公司
Publication of WO2024066808A1 publication Critical patent/WO2024066808A1/en

Links

Classifications

    • GPHYSICS
    • G06COMPUTING; CALCULATING OR COUNTING
    • G06NCOMPUTING ARRANGEMENTS BASED ON SPECIFIC COMPUTATIONAL MODELS
    • G06N10/00Quantum computing, i.e. information processing based on quantum-mechanical phenomena
    • GPHYSICS
    • G06COMPUTING; CALCULATING OR COUNTING
    • G06NCOMPUTING ARRANGEMENTS BASED ON SPECIFIC COMPUTATIONAL MODELS
    • G06N10/00Quantum computing, i.e. information processing based on quantum-mechanical phenomena
    • G06N10/20Models of quantum computing, e.g. quantum circuits or universal quantum computers
    • GPHYSICS
    • G06COMPUTING; CALCULATING OR COUNTING
    • G06NCOMPUTING ARRANGEMENTS BASED ON SPECIFIC COMPUTATIONAL MODELS
    • G06N10/00Quantum computing, i.e. information processing based on quantum-mechanical phenomena
    • G06N10/40Physical realisations or architectures of quantum processors or components for manipulating qubits, e.g. qubit coupling or qubit control

Definitions

  • the present application belongs to the field of quantum computing technology, and in particular to a quantum circuit generation method, device, storage medium and electronic device.
  • Quantum computing is a new computing model that follows the laws of quantum mechanics to control quantum information units for computing.
  • the most basic principle of quantum computing is the principle of quantum mechanical superposition, which allows the state of quantum information units to be in a superposition state of multiple possibilities, making quantum information processing more efficient than classical information processing.
  • Quantum computing is being applied in more and more fields due to its powerful computing power. For example, it is used to evaluate financial markets and perform financial operations based on the evaluation results.
  • the purpose of the present application is to provide a quantum circuit generation method, device, storage medium and electronic device, which can eliminate the influence of the addition of temporary variables on the calculation results by adding a quantum logic gate in the quantum circuit that makes the final state of the quantum bit corresponding to the temporary variable be the
  • An embodiment of the present application provides a method for generating a quantum circuit, the method comprising:
  • a target quantum circuit is generated.
  • determining a target quantum bit according to the target temporary variable includes:
  • an idle quantum bit is allocated to the target temporary variable as the target quantum bit.
  • 0> state comprises:
  • a target quantum logic gate that makes the final state of the target quantum bit a
  • determining a quantum logic gate acting on the target quantum bit according to the initial quantum program includes:
  • the topological graph containing the target quantum bit, wherein the topological graph is generated using the initial quantum program, the initial node represents the quantum bit, the other nodes represent the quantum logic gates, and the edges represent the association relationship between the nodes;
  • a quantum logic gate acting on the target quantum bit is determined.
  • generating a target quantum circuit based on the initial quantum program and the target quantum logic gate includes:
  • a target quantum circuit is generated.
  • generating a target quantum circuit based on the new topological graph includes:
  • the determined quantum logic gates are sequentially applied to corresponding quantum bits to generate a target quantum circuit.
  • the method further includes:
  • the target quantum bit is released so that the target quantum bit can be reallocated.
  • Another embodiment of the present application provides a quantum circuit generation device, the device comprising:
  • An acquisition module used for obtaining target temporary variables required for executing an initial quantum program
  • a first determination module is used to determine a target quantum bit according to the target temporary variable, wherein the initial state of the target quantum bit is a
  • a second determination module is used to determine a target quantum logic gate that makes the final state of the target quantum bit a
  • a generation module is used to generate a target quantum circuit based on the initial quantum program and the target quantum logic gate.
  • the first determining module is specifically configured to:
  • an idle quantum bit is allocated to the target temporary variable as the target quantum bit.
  • the second determining module includes:
  • a first determining unit configured to determine a quantum logic gate acting on the target quantum bit according to the initial quantum program
  • the second determining unit is used to determine a target quantum logic gate that makes the final state of the target quantum bit a
  • the first determining unit is specifically configured to:
  • the topological graph containing the target quantum bit, wherein the topological graph is generated using the initial quantum program, the initial node represents the quantum bit, the other nodes represent the quantum logic gates, and the edges represent the association relationship between the nodes;
  • a quantum logic gate acting on the target quantum bit is determined.
  • the generating module is specifically used for:
  • a target quantum circuit is generated.
  • the generating module is further specifically used for:
  • the determined quantum logic gates are sequentially applied to corresponding quantum bits to generate a target quantum circuit.
  • the device further comprises:
  • a release module is used to release the target quantum bit when the life cycle of the target temporary variable ends, so that the target quantum bit can be reallocated.
  • An embodiment of the present application provides a storage medium, in which a computer program is stored, wherein the computer program is configured to implement any of the above methods when running.
  • An embodiment of the present application 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 implement any of the above methods.
  • An embodiment of the present application provides a computer program product comprising instructions, which, when executed on a computer, enables the computer to execute any of the above-described methods.
  • the quantum circuit generation method provided by the present application first obtains the target temporary variable required for executing the initial quantum program; determines the target quantum bit according to the target temporary variable; then determines the target quantum logic gate that makes the final state of the target quantum bit
  • 0> state is determined and added to the corresponding position, thereby obtaining the final quantum circuit, eliminating the influence of the addition of the temporary variable on the calculation result, thereby reducing the possibility of errors in the calculation result.
  • FIG1 is a hardware diagram of a computer terminal for a quantum circuit generation method provided in an embodiment of the present application. Structure diagram;
  • FIG2 is a schematic diagram of a flow chart of a quantum circuit generation method provided in an embodiment of the present application.
  • FIG3 is a schematic diagram of a topological map generated based on an initial quantum program provided in an embodiment of the present application
  • FIG4 is a schematic diagram of a node adding order corresponding to a target quantum logic gate provided in an embodiment of the present application
  • FIG5 is a schematic diagram of a topological diagram after adding a node corresponding to a target quantum logic gate provided in an embodiment of the present application;
  • FIG6 is a schematic diagram of another topological map generated based on an initial quantum program provided in an embodiment of the present application.
  • FIG7 is a schematic diagram of another topological diagram after adding a node corresponding to a target quantum logic gate provided in an embodiment of the present application;
  • FIG8 is a schematic diagram of a generated target quantum circuit provided in an embodiment of the present application.
  • FIG9 is a schematic diagram of allocating quantum bits to temporary variables provided by an embodiment of the present application.
  • FIG10 is a schematic diagram of the structure of a quantum circuit generation device provided in an embodiment of the present application.
  • the embodiment of the present application first provides a quantum circuit generation method, which can be applied to electronic devices, such as computer terminals, specifically ordinary computers, quantum computers, etc.
  • Quantum computers are physical devices that follow the laws of quantum mechanics to perform high-speed mathematical and logical operations, store and process quantum information. When a device processes and calculates quantum information and runs quantum algorithms, it is a quantum computer. Quantum computers have become a key technology under research because they have the ability to process mathematical problems more efficiently than ordinary computers. For example, they can speed up the time to crack RSA (Rivest-Adi Shamir-Leonard Adleman) keys from hundreds of years to a few hours.
  • RSA Rastert-Adi Shamir-Leonard Adleman
  • FIG1 is a hardware structure block diagram of a computer terminal of a quantum circuit generation method provided in an embodiment of the present application.
  • the computer terminal may include one or more (only one is shown in FIG1 ) processors 102 (the processor 102 may include but is not limited to a processing device such as a microprocessor (MCU, Micro Controller Unit) or a programmable logic device (FPGA, Field Programmable Gate Array)) and a memory 104 for storing data.
  • the computer terminal may also include a transmission device 106 and an input/output device 108 for communication functions.
  • FIG1 is for illustration only and does not limit the structure of the computer terminal.
  • the computer terminal may also include more or fewer components than those shown in FIG1 , or have a configuration different from that shown in FIG1 .
  • the memory 104 can be used to store software programs and modules of application software, such as program instructions/modules corresponding to the quantum circuit generation method in the embodiment of the present application.
  • the processor 102 executes various functional applications and data processing by running the software programs and modules stored in the memory 104, that is, implementing the above method.
  • the memory 104 may include a high-speed random access memory, and may also include a non-volatile memory, such as one or more magnetic storage devices, flash memory, or other non-volatile solid-state memory.
  • the memory 104 may further include a memory remotely arranged relative to the processor 102, and these remote memories may be connected to the computer terminal via a network. Examples of the above-mentioned network include, but are not limited to, the Internet, an intranet, a local area network, a mobile communication network, and a combination thereof.
  • the transmission device 106 is used to receive or send data via a network.
  • the specific example of the above network may include a wireless network provided by a communication provider of a computer terminal.
  • the transmission device 106 includes a network adapter (Network Interface Controller, NIC), which can be connected to other network devices through a base station so as to communicate with the Internet.
  • the transmission device 106 can be a radio frequency (Radio Frequency, RF) module, which is used to communicate with the Internet wirelessly.
  • RF Radio Frequency
  • the transmission device 106 can also be an ETH (Ethernet) module, which is used to communicate with the Internet via a wired method.
  • a true quantum computer is a hybrid structure, which consists of two parts: one part is a classical computer, which is responsible for performing classical calculations and control; the other part is a quantum device, which is responsible for running quantum programs and thus realizing quantum computing.
  • a quantum program is a sequence of instructions written in a quantum language such as QRunes that can be run on a quantum computer, which supports quantum logic gate operations and ultimately realizes quantum computing.
  • a quantum program is a sequence of instructions that operate quantum logic gates in a certain sequence.
  • Quantum computing is usually required due to the limitations of the development of quantum device hardware. Simulation to verify quantum algorithms, quantum applications, etc.
  • Quantum computing simulation is the process of simulating the operation of quantum programs corresponding to specific problems by using a virtual architecture (i.e., quantum virtual machine) built with the resources of ordinary computers. Usually, it is necessary to build a quantum program corresponding to a specific problem.
  • the quantum program referred to in the embodiment of the present application is a program written in a classical language to characterize quantum bits and their evolution, in which quantum bits, quantum logic gates, etc. related to quantum computing are represented by corresponding classical codes.
  • Quantum circuits as a manifestation of quantum programs, are also called quantum logic circuits. They are the most commonly used general quantum computing model. They represent circuits that operate on quantum bits in an abstract concept. They are composed of quantum bits, circuits (timelines), and various quantum logic gates. Finally, the results often need to be read out through quantum measurement operations.
  • the circuits can be seen as connected by time, that is, the state of the quantum bit evolves naturally over time, following the instructions of the Hamiltonian operator until it encounters a logic gate and is operated.
  • a quantum program as a whole corresponds to a total quantum circuit, and the quantum program described in this application refers to the total quantum circuit, wherein the total number of quantum bits in the total quantum circuit is the same as the total number of quantum bits in the quantum program.
  • a quantum program can be composed of a quantum circuit, a measurement operation on the quantum bits in the quantum circuit, a register for storing the measurement results, and a control flow node (jump instruction).
  • 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 quantum logic gates in a certain sequence. It should be noted that the sequence is the time order in which a single quantum logic gate is executed.
  • Quantum logic gates are the basis of quantum circuits. Quantum logic gates include single-bit quantum logic gates, such as Hadamard gates (H gates, Hadamard gates), Pauli-X gates (X gates), Pauli-Y gates (Y gates), Pauli-Z gates (Z gates), RX gates, RY gates, RZ gates, etc.; two-bit or multi-bit quantum logic gates, such as CNOT gates, CR gates, CZ gates, iSWAP gates, Toffoli gates, etc.
  • H gates Hadamard gates
  • X gates Pauli-X gates
  • Y gates Pauli-Y gates
  • Z gates Pauli-Z gates
  • RX gates RY gates, RZ gates, etc.
  • two-bit or multi-bit quantum logic gates such as CNOT gates, CR gates, CZ gates, iSWAP gates, Toffoli gates, etc.
  • Quantum logic gates are generally represented by unitary matrices, which are not only matrix forms, but also operations and transformations.
  • the effect of general quantum logic gates on quantum states is calculated by multiplying the unitary matrix on the left by the matrix corresponding to the right vector of the quantum state.
  • FIG. 2 is a schematic diagram of a process of a quantum circuit generation method provided in an embodiment of the present application.
  • the diagram may include the following steps:
  • temporary variables are variables that are not declared at the beginning of the program, that is, they are declared only when they are used. Temporary variables are automatically destroyed after the function call to which they belong is completed.
  • temporary variables are variables that are temporarily required when executing a quantum program. Temporary variables may or may not be recorded in the initial quantum program. There may be more than one target temporary variable required to execute the initial quantum program. When the initial quantum program records the target temporary variable, the target temporary variable can be directly obtained from the initial quantum program. Of course, the target temporary variable can also be obtained in other ways, such as obtaining the target temporary variable from pre-recorded temporary variable information. When the target temporary variable is not recorded in the initial quantum program, the initial quantum program is analyzed, and the temporary variable required for the execution of the initial quantum program is used as the target temporary variable, or the target temporary variable is obtained through the information recorded for the initial quantum program.
  • S202 Determine a target quantum bit according to the target temporary variable, wherein an initial state of the target quantum bit is a
  • the target qubit can be determined based on the predetermined mapping relationship between temporary variables and qubits, or a random qubit can be selected from the qubits allocated to the temporary variable as the target qubit.
  • a target qubit is allocated to each target temporary variable. It should be noted that the qubit allocated to the target temporary variable is called the target qubit.
  • determining a target quantum bit according to the target temporary variable includes:
  • an idle quantum bit is allocated to the target temporary variable as the target quantum bit.
  • the pre-set qubits are qubits prepared in advance for temporary variables. These qubits do not overlap with the qubits already defined in the quantum program.
  • the initial quantum program has defined qubits 1-5, a total of five qubits; the pre-set qubits may be qubits 6-8, a total of three qubits.
  • an idle qubit is selected from these qubits (i.e., qubits 6-8) and assigned to the temporary variable.
  • the selected qubit is the target qubit.
  • the pre-set qubits are The sub-bits can be stored in a global pool, which uses a stack structure.
  • a qubit is popped from the top of the stack and allocated to the required temporary variable. For example, a sufficient number of qubits can be set in the global pool in advance based on the temporary variables in the initial quantum program to avoid the situation where qubits need to be allocated for temporary variables and the available bits in the global pool are empty.
  • S203 Based on the initial quantum program, determine a target quantum logic gate that makes the final state of the target quantum bit a
  • the initial state of the quantum bit is prepared, and information can be prepared on the quantum bit by encoding, and the information is the initial state of the quantum bit.
  • the initial state of the quantum bit will change with the operation of the quantum program (i.e., it evolves over time on the quantum circuit), and the final state of the quantum bit is obtained.
  • the quantum state of the target quantum bit will change, because the entanglement of the quantum state will also change the quantum state of other quantum bits.
  • the final state of the target quantum bit can be determined if the influence of the temporary variable is not eliminated.
  • 0> can be determined.
  • the determined quantum logic gate is the target quantum logic gate, and there can be more than one target quantum logic gate.
  • the quantum state of the target quantum bit can be evolved based on the quantum logic gate in the initial quantum program to obtain the final state of the target quantum bit in this case.
  • the final state obtained is also the final state of the target quantum bit without eliminating the influence of the temporary variable.
  • the target quantum logic gate is determined in combination with the final state, so that when the initial state of the target quantum bit is the
  • 0> state includes:
  • a target quantum logic gate that makes the final state of the target quantum bit a
  • the quantum logic gate acting on the target quantum bit can be determined.
  • the quantum logic gate determined here is the quantum logic gate in the initial quantum program. Specifically, it can be determined by The content recorded in the initial quantum program, or the information obtained based on the initial quantum program, such as the syntax tree, is parsed to determine the quantum logic gate acting on the target quantum bit in the initial quantum program. It should be noted that in the initial quantum program, when the target quantum bit is used as the target bit of a two-bit or multi-bit quantum logic gate, the two-bit or multi-bit quantum logic gate is a quantum logic gate acting on the target quantum bit.
  • the target quantum logic gate determined to act on the target quantum bit is a CNOT gate
  • the target quantum logic gate determined is also a CNOT gate.
  • the specific determination method can determine the target quantum logic gate according to the mapping relationship between the pre-established quantum logic gate and its corresponding inverse gate.
  • determining a quantum logic gate acting on the target quantum bit according to the initial quantum program includes:
  • the topological graph containing the target quantum bit, wherein the topological graph is generated using the initial quantum program, the initial node represents the quantum bit, the other nodes represent the quantum logic gates, and the edges represent the association relationship between the nodes;
  • a quantum logic gate acting on the target quantum bit is determined.
  • the topological map is generated by using the initial quantum program.
  • the topological map is generated according to the execution order of the programs in the quantum program, reflecting the structure of the quantum program.
  • the topological map can be a directed acyclic graph or a mathematical model circuit diagram.
  • the topological map contains the target quantum bits.
  • the initial nodes in the topological map represent the quantum bits, that is, the number of initial nodes is the number of quantum bits.
  • the association relationship between the nodes may include the action relationship between the initial node and other nodes, the execution order relationship and constraint relationship between other nodes, and the controlled relationship of the quantum logic gates corresponding to the nodes, etc.
  • the quantum program is:
  • circuit is the representation of quantum circuit
  • is the program symbol
  • H and CNOT are the symbols of quantum logic gates
  • q0, q1 and aux are the symbols of quantum bits.
  • H(q0) means: in the quantum circuit, the H gate acts on q0.
  • circuit ⁇ CNOT(q0,aux) means: in the quantum circuit there is a CNOT gate whose control bit is q0 and target bit is aux.
  • circuit ⁇ CNOT(aux,q1) means: in the quantum circuit there is a CNOT gate whose control bit is aux and target bit is q1.
  • CNOT(q1,q0) means: in the quantum circuit, there is a CNOT gate whose control bit is q1 and target bit is q0.
  • the generated topology graph can be shown in Figure 3, where init is the initial node, representing quantum bits q0, q1, and q2. Specifically, q0 and q1 are initialized quantum bits, q2 is the target quantum bit corresponding to the temporary variable aux, q0 1 represents the first quantum logic gate acting on quantum bit q0 0 , and q0 2 represents the second quantum logic gate acting on quantum bit q0 0.
  • the edges between nodes represent the association between nodes.
  • the symbol between the initial node and the quantum logic gate is Representing the quantum bits acted upon by quantum logic gates, and the symbols between quantum logic gates
  • the execution timing between quantum logic gates can be characterized. For example, for q0, the H gate is executed first, and then the CNOT gate.
  • the quantum logic gate pointed to is the controlled quantum logic gate.
  • the quantum bit pointed to by the arrow is the target bit of the controlled quantum logic gate.
  • the quantum bit corresponding to the dot is the control bit of the controlled quantum logic gate.
  • the control bit of CNOT is q0 and the target bit is q2.
  • the quantum bit pointed to by the arrow means that the quantum logic gate pointed to by the arrow is the quantum bit as the target bit.
  • the quantum bit corresponding to the dot that is, the quantum logic gate at the dot is the quantum bit as the control bit.
  • the quantum logic gate acting on the target quantum bit is a CNOT gate.
  • the gate with the opposite function to the CNOT gate or the inverse gate of the CNOT gate is determined as the target quantum logic gate.
  • the target quantum logic gate can be a CNOT gate.
  • the topological graph can clearly reflect the structure of the quantum program. Based on the topological graph structure, the quantum logic gate acting on the target quantum bit can be found relatively quickly and conveniently.
  • the gates acting on the target quantum bit are traversed step by step in reverse order, that is, traversing upward from the end node determined by the last logic gate related to the target quantum bit in the topological graph to determine the quantum logic gate acting on the target quantum bit.
  • S204 Generate a target quantum circuit based on the initial quantum program and the target quantum logic gate.
  • the target quantum circuit is generated.
  • the position where the target quantum logic gate is added can be determined by the position of the quantum logic gate acting on the target quantum bit in the initial quantum program. Specifically, the position where the target quantum logic gate is added can be adjacent to the quantum logic gate acting on the target quantum bit in the initial quantum program, or the position is relatively close to the quantum logic gate acting on the target quantum bit in the initial quantum program. The principle is that adding the target quantum logic gate cannot change the final state of other quantum bits obtained without adding temporary variables.
  • Quantum computing In quantum computing, temporary variables have an impact on the calculation results, which is determined by the characteristics of quantum computing itself. Quantum computing obtains results based on the entanglement of quantum states, and temporary variables will participate in the calculation because the quantum states of the quantum bits assigned to them will participate in the calculation, thereby changing the entanglement results of the quantum states, and thus affecting the calculation results.
  • the solution provided by the embodiment of the present application includes a target quantum logic gate in the target quantum circuit.
  • the target quantum circuit When the target quantum circuit is run, because the initial state of the target quantum bit obtained is the
  • generating a target quantum circuit based on the initial quantum program and the target quantum logic gate includes:
  • association relationship in the current topology map determine the node that has an association relationship with the newly added node
  • a target quantum circuit is generated.
  • the structure of the topological graph reflects the order in which quantum logic gates are executed.
  • the nodes corresponding to the target quantum logic gates can be added to the topological graph, and the target quantum circuit can be generated based on the topological graph to accurately eliminate Influence of temporary variables.
  • the node corresponding to the target quantum logic gate can be added at the determined position after the node corresponding to the quantum logic gate currently acting on the target quantum bit.
  • the corresponding nodes are added in the reverse order of the corresponding quantum logic gates. For example, as shown in FIG. 4, U1 and U2 are U gates acting on the target quantum bit. They are the target quantum logic gates corresponding to U 1 and U 2 respectively.
  • Corresponding nodes then add It can be seen that after traversing the quantum logic gates acting on the target quantum bits in reverse order in the above embodiment, the corresponding target quantum logic gates can be determined in turn according to the determined order of the quantum logic gates, and the corresponding nodes can be added to the topology graph.
  • the node corresponding to the quantum logic gate acting on the target quantum bit can be determined as the associated node of the newly added node.
  • the nodes corresponding to the quantum bits affected by the temporary variables determine the nodes with an associated relationship with the newly added nodes. Add the edges between the determined nodes (including the nodes with an associated relationship with the newly added nodes determined by the above two methods) and the newly added nodes, and the type of edge is related to the associated relationship.
  • the generated new topological map is shown in Figure 5.
  • the topological map shown in Figure 3 is the current topological map
  • the topological map shown in Figure 5 is a new topological map obtained by adding the nodes corresponding to the target quantum logic gate.
  • the CNOT gate represented by q2 1 and the CNOT gate represented by q0 2 are added between the CNOT gate represented by q2 2 .
  • the quantum logic gates associated with the target quantum bit in the two-bit quantum logic gates and multi-bit quantum logic gates in the initial quantum program can be determined, and correspondingly, the other quantum bits associated with the part of the quantum logic gates can represent the quantum bits affected by the temporary variables.
  • the target bit and the control bit of the controlled quantum logic gate are associated with the controlled quantum logic gate.
  • q1 is the target quantum bit
  • the symbol with a dotted line Indicates that there is a constraint relationship between the nodes, which means that the CNOT gate represented by q1 1 is executed first, and then the H gate represented by q0 2 is executed.
  • generating a target quantum circuit based on the new topological graph includes:
  • the quantum logic gates, execution timing, and action relationships acting on each quantum bit are determined
  • the determined quantum logic gates are sequentially applied to corresponding quantum bits to generate a target quantum circuit.
  • the generated quantum circuit diagram can be shown in FIG8.
  • q[0] represents the quantum bit represented by q0 in FIG5
  • q[1] represents the quantum bit represented by q1 in FIG5
  • q[2] represents the quantum bit represented by q2 in FIG5.
  • the method may further include:
  • the target quantum bit is released so that the target quantum bit can be reallocated.
  • the quantum bits can be reused after the life cycle of the temporary variable ends to achieve the purpose of saving resources.
  • the end of the function where the temporary variable is located can be regarded as the time point when its life cycle ends.
  • the memory management of temporary variables can be implemented through the global pool, which is a stack structure. When a temporary variable needs to allocate a quantum bit, the quantum bit is popped from the top of the stack as the target quantum bit. When the life cycle of the temporary variable ends, the quantum bit is recycled to the global pool. For example, the recycled quantum bit is added to the top of the stack.
  • quantum bits allocated by the global pool for temporary variables are 10 quantum bits q0-q9, aux0-aux2 are all temporary variables, aux0 will call aux1 and aux2, when a variable needs to be allocated with a quantum bit, a quantum bit is popped from the top of the stack, and when the life cycle of the temporary variable ends, the quantum bits occupied by the temporary variable are put back into the stack.
  • the main function is used to apply for bits for the temporary variable aux0.
  • quantum bit q0 is allocated to the temporary variable aux0.
  • function 1 can be called to apply for bits for the temporary variable aux1 through function 1.
  • quantum bit q1 is allocated to the temporary variable aux1.
  • the quantum bit q1 allocated to the temporary variable aux1 is recovered and added to the top of the stack.
  • function 2 can be called to apply for bits for the temporary variable aux2 through function 2.
  • quantum bit q1 is allocated to the temporary variable aux2.
  • the quantum bit q1 allocated to the temporary variable aux2 is recovered and added to the top of the stack. Furthermore, at the end of the main function, the quantum bit q0 allocated to the temporary variable aux0 is recovered and added to the top of the stack.
  • the embodiment of the present application first obtains the target temporary variable required for executing the initial quantum program; determines the target quantum bit according to the target temporary variable; then determines the target quantum logic gate that makes the final state of the target quantum bit
  • 0> state is determined and added to the corresponding position, thereby obtaining the final quantum circuit.
  • the influence of the temporary variable addition on the calculation result is automatically eliminated, thereby reducing the possibility of errors in the calculation result.
  • the quantum generation method provided in the embodiment of the present application is applied to quantum computing scenarios with temporary variables, specifically, password cracking, artificial intelligence, biomedicine, financial engineering, aerospace and transportation, etc.
  • temporary variables specifically, password cracking, artificial intelligence, biomedicine, financial engineering, aerospace and transportation, etc.
  • the method provided in the embodiment of the present application can be used to eliminate the influence of temporary variables, reduce the possibility of errors in the calculation results, and promote the development of various fields.
  • FIG. 10 is a schematic diagram of the structure of a quantum circuit generation device provided in an embodiment of the present application, corresponding to the process shown in FIG. 2 , the device includes:
  • An acquisition module 1001 is used to obtain a target temporary variable required for executing an initial quantum program
  • a first determination module 1002 is used to determine a target quantum bit according to the target temporary variable, wherein the initial state of the target quantum bit is a
  • a second determination module 1003 is used to determine a target quantum logic gate that makes the final state of the target quantum bit a
  • the generating module 1004 is used to generate a target quantum circuit based on the initial quantum program and the target quantum logic gate.
  • the first determining module 1002 may be specifically used to:
  • an idle quantum bit is allocated to the target temporary variable as the target quantum bit.
  • the second determining module 1003 may include:
  • a first determining unit configured to determine a quantum logic gate acting on the target quantum bit according to the initial quantum program
  • the second determining unit is used to determine a target quantum logic gate that makes the final state of the target quantum bit a
  • the first determining unit may be specifically configured to:
  • the topological graph containing the target quantum bit, wherein the topological graph is generated using the initial quantum program, the initial node represents the quantum bit, the other nodes represent the quantum logic gates, and the edges represent the association relationship between the nodes;
  • a quantum logic gate acting on the target quantum bit is determined.
  • the generating module 1004 may be specifically used for:
  • a target quantum circuit is generated.
  • the generating module 1004 may also be specifically used for:
  • the quantum logic gates, execution timing, and action relationships acting on each quantum bit are determined
  • the determined quantum logic gates are sequentially applied to corresponding quantum bits to generate a target quantum circuit.
  • the device may further include:
  • a release module is used to release the target quantum bit when the life cycle of the target temporary variable ends, so that the target quantum bit can be reallocated.
  • the embodiment of the present application first obtains the target temporary variable required for executing the initial quantum program; determines the target quantum bit according to the target temporary variable; and then based on the initial quantum program, Determine the target quantum logic gate that makes the final state of the target quantum bit to be
  • the initial quantum program determine the quantum logic gate that makes the final state of the quantum bit corresponding to the temporary variable to be
  • the influence of the addition of the temporary variable on the calculation result is automatically eliminated, thereby reducing the possibility of errors in the calculation result.
  • An embodiment of the present application further provides a storage medium, in which a computer program is stored, wherein the computer program is configured to execute the steps of any of the above method embodiments when running.
  • the above storage medium may be configured to store a computer program for performing the following steps:
  • S202 Determine a target quantum bit according to the target temporary variable, wherein the initial state of the target quantum bit is a
  • S203 Based on the initial quantum program, determine a target quantum logic gate that makes the final state of the target quantum bit a
  • S204 Generate a target quantum circuit based on the initial quantum program and the target quantum logic gate.
  • An embodiment of the present application further 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 execute the steps in any one of the above method embodiments.
  • the electronic device may further include a transmission device and an input/output device, wherein the transmission device is connected to the processor, and the input/output device is connected to the processor.
  • the processor may be configured to perform the following steps through a computer program:
  • S202 Determine a target quantum bit according to the target temporary variable, wherein the initial state of the target quantum bit is a
  • S203 Based on the initial quantum program, determine a target quantum logic gate that makes the final state of the target quantum bit a
  • the embodiment of the present application also proposes a computer program product comprising instructions, which, when executed on a computer, enables the computer to execute the steps in any of the above method embodiments.

Landscapes

  • Engineering & Computer Science (AREA)
  • General Physics & Mathematics (AREA)
  • Theoretical Computer Science (AREA)
  • Physics & Mathematics (AREA)
  • Mathematical Analysis (AREA)
  • Data Mining & Analysis (AREA)
  • Evolutionary Computation (AREA)
  • Condensed Matter Physics & Semiconductors (AREA)
  • Computational Mathematics (AREA)
  • Mathematical Optimization (AREA)
  • Pure & Applied Mathematics (AREA)
  • Computing Systems (AREA)
  • General Engineering & Computer Science (AREA)
  • Mathematical Physics (AREA)
  • Software Systems (AREA)
  • Artificial Intelligence (AREA)
  • Logic Circuits (AREA)

Abstract

A quantum circuit generation method and apparatus, a storage medium, and an electronic device. The method comprises: obtaining a target temporary variable required for executing an initial quantum program; determining a target quantum bit according to the target temporary variable, wherein an initial state of the target quantum bit is a |0> state; on the basis of the initial quantum program, determining a target quantum logic gate enabling a final state of the target quantum bit to be the |0> state; and generating a target quantum circuit on the basis of the initial quantum program and the target quantum logic gate. According to embodiments of the present application, by adding a quantum logic gate enabling a final state of a quantum bit corresponding to a temporary variable to be a |0> state into a quantum circuit, the effect of addition of the temporary variable on a calculation result can be eliminated, and the possibility of errors of the calculation result is reduced.

Description

量子线路生成方法、装置、存储介质及电子装置Quantum circuit generation method, device, storage medium and electronic device
本申请要求于2022年09月30日提交中国专利局、申请号为202211220055.4发明名称为“量子线路生成方法、装置、存储介质及电子装置”的中国专利申请的优先权,其全部内容通过引用结合在本申请中。This application claims the priority of the Chinese patent application filed with the China Patent Office on September 30, 2022, with application number 202211220055.4 and invention name “Quantum circuit generation method, device, storage medium and electronic device”, all contents of which are incorporated by reference in this application.
技术领域Technical Field
本申请属于量子计算技术领域,特别是一种量子线路生成方法、装置、存储介质及电子装置。The present application belongs to the field of quantum computing technology, and in particular to a quantum circuit generation method, device, storage medium and electronic device.
背景技术Background technique
量子计算是一种遵循量子力学规律调控量子信息单元进行计算的新型计算模式,其中,量子计算基于的最基本的一个原理为量子力学态叠加原理,量子力学态叠加原理使得量子信息单元的状态可以处于多种可能性的叠加状态,从而使得量子信息处理从效率上相比于经典信息处理具有更大潜力。量子计算因其强大的计算能力,正在越来越多的领域应用,例如,利用量子计算对金融市场进行评估,基于评估结果进行金融操作。Quantum computing is a new computing model that follows the laws of quantum mechanics to control quantum information units for computing. The most basic principle of quantum computing is the principle of quantum mechanical superposition, which allows the state of quantum information units to be in a superposition state of multiple possibilities, making quantum information processing more efficient than classical information processing. Quantum computing is being applied in more and more fields due to its powerful computing power. For example, it is used to evaluate financial markets and perform financial operations based on the evaluation results.
在量子计算过程中,为了节省量子比特资源,一般会在量子程序中引入临时变量,在计算过程中为临时变量申请量子比特,从而量子线路中会加入所申请的比特。在经典领域,临时变量的加入不会对计算结果产生影响,而在量子领域,为了临时变量能够在线路中与其他量子比特进行运算,需要为临时变量分配一个量子比特,但是因为量子计算结果是通过对量子线路的末态测量得到的,临时变量的引入会对末态产生影响,从而对测量结果产生影响,可能会出现错误的计算结果,但目前还没有一种较好的方法,能够在量子线路中取消临时变量的计算,减少计算结果出现错误的可能性。In the process of quantum computing, in order to save quantum bit resources, temporary variables are generally introduced into the quantum program, and quantum bits are applied for temporary variables during the calculation process, so that the applied bits will be added to the quantum circuit. In the classical field, the addition of temporary variables will not affect the calculation results, but in the quantum field, in order for the temporary variables to be able to operate with other quantum bits in the circuit, a quantum bit needs to be allocated to the temporary variable. However, because the quantum calculation results are obtained by measuring the final state of the quantum circuit, the introduction of temporary variables will affect the final state, thereby affecting the measurement results, and may result in erroneous calculation results. However, there is currently no better method to cancel the calculation of temporary variables in the quantum circuit and reduce the possibility of errors in the calculation results.
发明内容Summary of the invention
本申请的目的是提供一种量子线路生成方法、装置、存储介质及电子装置,它通过在量子线路中增加使得临时变量对应的量子比特的末态为|0>态的量子逻辑门,能够消除临时变量加入对计算结果的影响,进而减少计算结果出现错误的可能性。The purpose of the present application is to provide a quantum circuit generation method, device, storage medium and electronic device, which can eliminate the influence of the addition of temporary variables on the calculation results by adding a quantum logic gate in the quantum circuit that makes the final state of the quantum bit corresponding to the temporary variable be the |0> state, thereby reducing the possibility of errors in the calculation results.
本申请的一个实施例提供了一种量子线路生成方法,方法包括:An embodiment of the present application provides a method for generating a quantum circuit, the method comprising:
获得为执行初始量子程序所需的目标临时变量; Obtain the target temporary variables required to execute the initial quantum program;
根据所述目标临时变量,确定目标量子比特,其中,所述目标量子比特的初态为|0>态;Determine a target quantum bit according to the target temporary variable, wherein the initial state of the target quantum bit is a |0> state;
基于所述初始量子程序,确定使所述目标量子比特的末态为|0>态的目标量子逻辑门;Based on the initial quantum program, determining a target quantum logic gate that makes the final state of the target quantum bit a |0> state;
基于所述初始量子程序和所述目标量子逻辑门,生成目标量子线路。Based on the initial quantum program and the target quantum logic gate, a target quantum circuit is generated.
可选的,所述根据所述目标临时变量,确定目标量子比特,包括:Optionally, determining a target quantum bit according to the target temporary variable includes:
从预先设置的量子比特中,为所述目标临时变量分配一个空闲量子比特,作为目标量子比特。From the preset quantum bits, an idle quantum bit is allocated to the target temporary variable as the target quantum bit.
可选的,所述基于所述初始量子程序,确定使所述目标量子比特的末态为|0>态的目标量子逻辑门,包括:Optionally, determining, based on the initial quantum program, a target quantum logic gate that makes the final state of the target quantum bit a |0> state comprises:
根据所述初始量子程序,确定作用在所述目标量子比特上的量子逻辑门;Determining a quantum logic gate acting on the target quantum bit according to the initial quantum program;
基于所确定的量子逻辑门,确定使所述目标量子比特的末态为|0>态的目标量子逻辑门。Based on the determined quantum logic gate, a target quantum logic gate that makes the final state of the target quantum bit a |0> state is determined.
可选的,所述根据所述初始量子程序,确定作用在所述目标量子比特上的量子逻辑门,包括:Optionally, determining a quantum logic gate acting on the target quantum bit according to the initial quantum program includes:
获得包含所述目标量子比特的拓扑图,其中,所述拓扑图是利用所述初始量子程序生成的,初始节点表征量子比特,其他节点表征量子逻辑门,边表征节点之间的关联关系;Obtaining a topological graph containing the target quantum bit, wherein the topological graph is generated using the initial quantum program, the initial node represents the quantum bit, the other nodes represent the quantum logic gates, and the edges represent the association relationship between the nodes;
基于所述拓扑图,确定作用在所述目标量子比特上的量子逻辑门。Based on the topological graph, a quantum logic gate acting on the target quantum bit is determined.
可选的,所述基于所述初始量子程序和所述目标量子逻辑门,生成目标量子线路,包括:Optionally, generating a target quantum circuit based on the initial quantum program and the target quantum logic gate includes:
在当前拓扑图中,确定所述目标量子逻辑门的添加位置并添加对应的节点;In the current topology graph, determine the adding position of the target quantum logic gate and add the corresponding node;
根据当前拓扑图中的关联关系,确定与新添加的节点具有关联关系的节点;According to the association relationship in the current topology diagram, determine the node that has an association relationship with the newly added node;
建立所确定的节点与新添加的节点之间的边,以确定新的拓扑图;Establishing edges between the determined nodes and the newly added nodes to determine a new topological graph;
基于所述新的拓扑图,生成目标量子线路。Based on the new topological graph, a target quantum circuit is generated.
可选的,所述基于所述新的拓扑图,生成目标量子线路,包括:Optionally, generating a target quantum circuit based on the new topological graph includes:
根据所述新的拓扑图,确定作用在每一量子比特上的量子逻辑门、执行时序、以及作用关系; Determine the quantum logic gate, execution sequence, and action relationship acting on each quantum bit according to the new topological diagram;
基于所述执行时序和所述作用关系,将所确定的量子逻辑门依次作用在对应的量子比特上,生成目标量子线路。Based on the execution sequence and the action relationship, the determined quantum logic gates are sequentially applied to corresponding quantum bits to generate a target quantum circuit.
可选的,所述方法还包括:Optionally, the method further includes:
当所述目标临时变量生命周期结束,释放所述目标量子比特,以使所述目标量子比特可重新分配。When the life cycle of the target temporary variable ends, the target quantum bit is released so that the target quantum bit can be reallocated.
本申请的又一实施例提供了一种量子线路生成装置,装置包括:Another embodiment of the present application provides a quantum circuit generation device, the device comprising:
获得模块,用于获得为执行初始量子程序所需的目标临时变量;An acquisition module, used for obtaining target temporary variables required for executing an initial quantum program;
第一确定模块,用于根据所述目标临时变量,确定目标量子比特,其中,所述目标量子比特的初态为|0>态;A first determination module is used to determine a target quantum bit according to the target temporary variable, wherein the initial state of the target quantum bit is a |0> state;
第二确定模块,用于基于所述初始量子程序,确定使所述目标量子比特的末态为|0>态的目标量子逻辑门;A second determination module is used to determine a target quantum logic gate that makes the final state of the target quantum bit a |0> state based on the initial quantum program;
生成模块,用于基于所述初始量子程序和所述目标量子逻辑门,生成目标量子线路。A generation module is used to generate a target quantum circuit based on the initial quantum program and the target quantum logic gate.
可选的,所述第一确定模块,具体用于:Optionally, the first determining module is specifically configured to:
从预先设置的量子比特中,为所述目标临时变量分配一个空闲量子比特,作为目标量子比特。From the preset quantum bits, an idle quantum bit is allocated to the target temporary variable as the target quantum bit.
可选的,所述第二确定模块,包括:Optionally, the second determining module includes:
第一确定单元,用于根据所述初始量子程序,确定作用在所述目标量子比特上的量子逻辑门;A first determining unit, configured to determine a quantum logic gate acting on the target quantum bit according to the initial quantum program;
第二确定单元,用于基于所确定的量子逻辑门,确定使所述目标量子比特的末态为|0>态的目标量子逻辑门。The second determining unit is used to determine a target quantum logic gate that makes the final state of the target quantum bit a |0> state based on the determined quantum logic gate.
可选的,所述第一确定单元,具体用于:Optionally, the first determining unit is specifically configured to:
获得包含所述目标量子比特的拓扑图,其中,所述拓扑图是利用所述初始量子程序生成的,初始节点表征量子比特,其他节点表征量子逻辑门,边表征节点之间的关联关系;Obtaining a topological graph containing the target quantum bit, wherein the topological graph is generated using the initial quantum program, the initial node represents the quantum bit, the other nodes represent the quantum logic gates, and the edges represent the association relationship between the nodes;
基于所述拓扑图,确定作用在所述目标量子比特上的量子逻辑门。Based on the topological graph, a quantum logic gate acting on the target quantum bit is determined.
可选的,所述生成模块,具体用于:Optionally, the generating module is specifically used for:
在当前拓扑图中,确定所述目标量子逻辑门的添加位置并添加对应的节点;In the current topology graph, determine the adding position of the target quantum logic gate and add the corresponding node;
根据当前拓扑图中的关联关系,确定与新添加的节点具有关联关系的节 点;According to the association relationship in the current topology map, determine the node that has an association relationship with the newly added node. point;
建立所确定的节点与新添加的节点之间的边,以确定新的拓扑图;Establishing edges between the determined nodes and the newly added nodes to determine a new topological graph;
基于所述新的拓扑图,生成目标量子线路。Based on the new topological graph, a target quantum circuit is generated.
可选的,所述生成模块,还具体用于:Optionally, the generating module is further specifically used for:
根据所述新的拓扑图,确定作用在每一量子比特上的量子逻辑门、执行时序、以及作用关系;Determine the quantum logic gate, execution sequence, and action relationship acting on each quantum bit according to the new topological diagram;
基于所述执行时序和所述作用关系,将所确定的量子逻辑门依次作用在对应的量子比特上,生成目标量子线路。Based on the execution sequence and the action relationship, the determined quantum logic gates are sequentially applied to corresponding quantum bits to generate a target quantum circuit.
可选的,所述装置还包括:Optionally, the device further comprises:
释放模块,用于当所述目标临时变量生命周期结束,释放所述目标量子比特,以使所述目标量子比特可重新分配。A release module is used to release the target quantum bit when the life cycle of the target temporary variable ends, so that the target quantum bit can be reallocated.
本申请的一个实施例提供了一种存储介质,所述存储介质中存储有计算机程序,其中,所述计算机程序被设置为运行时实现上述任一项所述的方法。An embodiment of the present application provides a storage medium, in which a computer program is stored, wherein the computer program is configured to implement any of the above methods when running.
本申请的一个实施例提供了一种电子装置,包括存储器和处理器,所述存储器中存储有计算机程序,所述处理器被设置为运行所述计算机程序以实现上述任一项所述的方法。An embodiment of the present application 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 implement any of the above methods.
本申请的一个实施例提供了一种包含指令的计算机程序产品,当其在计算机上运行时,使得计算机执行上述任一项所述的方法。An embodiment of the present application provides a computer program product comprising instructions, which, when executed on a computer, enables the computer to execute any of the above-described methods.
与现有技术相比,本申请提供的量子线路生成方法,先获得为执行初始量子程序所需的目标临时变量;根据所述目标临时变量,确定目标量子比特;然后基于所述初始量子程序,确定使所述目标量子比特的末态为|0>态的目标量子逻辑门;最后基于所述初始量子程序和所述目标量子逻辑门,生成目标量子线路。通过初始量子程序,确定使得临时变量对应的量子比特的末态为|0>态的量子逻辑门,并加入到对应的位置,从而获得最终量子线路,消除了临时变量加入对计算结果的影响,进而减少计算结果出现错误的可能性。Compared with the prior art, the quantum circuit generation method provided by the present application first obtains the target temporary variable required for executing the initial quantum program; determines the target quantum bit according to the target temporary variable; then determines the target quantum logic gate that makes the final state of the target quantum bit |0> state based on the initial quantum program; finally, generates the target quantum circuit based on the initial quantum program and the target quantum logic gate. Through the initial quantum program, the quantum logic gate that makes the final state of the quantum bit corresponding to the temporary variable |0> state is determined and added to the corresponding position, thereby obtaining the final quantum circuit, eliminating the influence of the addition of the temporary variable on the calculation result, thereby reducing the possibility of errors in the calculation result.
附图说明BRIEF DESCRIPTION OF THE DRAWINGS
此处所说明的附图用来提供对本申请的进一步理解,构成本申请的一部分,本申请的示意性实施例及其说明用于解释本申请,并不构成对本申请的不当限定。The drawings described herein are used to provide further understanding of the present application and constitute a part of the present application. The illustrative embodiments of the present application and their descriptions are used to explain the present application and do not constitute improper limitations on the present application.
图1为本申请实施例提供的一种量子线路生成方法的计算机终端的硬件 结构框图;FIG1 is a hardware diagram of a computer terminal for a quantum circuit generation method provided in an embodiment of the present application. Structure diagram;
图2为本申请实施例提供的一种量子线路生成方法的流程示意图;FIG2 is a schematic diagram of a flow chart of a quantum circuit generation method provided in an embodiment of the present application;
图3为本申请实施例提供的一种基于初始量子程序生成的拓扑图的示意图;FIG3 is a schematic diagram of a topological map generated based on an initial quantum program provided in an embodiment of the present application;
图4为本申请实施例提供的一种目标量子逻辑门对应的节点添加顺序的示意图;FIG4 is a schematic diagram of a node adding order corresponding to a target quantum logic gate provided in an embodiment of the present application;
图5为本申请实施例提供的一种添加目标量子逻辑门对应的节点后的拓扑图的示意图;FIG5 is a schematic diagram of a topological diagram after adding a node corresponding to a target quantum logic gate provided in an embodiment of the present application;
图6为本申请实施例提供的另一种基于初始量子程序生成的拓扑图的示意图;FIG6 is a schematic diagram of another topological map generated based on an initial quantum program provided in an embodiment of the present application;
图7为本申请实施例提供的另一种添加目标量子逻辑门对应的节点后的拓扑图的示意图;FIG7 is a schematic diagram of another topological diagram after adding a node corresponding to a target quantum logic gate provided in an embodiment of the present application;
图8为本申请实施例提供的一种生成的目标量子线路的示意图;FIG8 is a schematic diagram of a generated target quantum circuit provided in an embodiment of the present application;
图9为本申请实施例提供的一种为临时变量分配量子比特的示意图;FIG9 is a schematic diagram of allocating quantum bits to temporary variables provided by an embodiment of the present application;
图10为本申请实施例提供的一种量子线路生成装置的结构示意图。FIG10 is a schematic diagram of the structure of a quantum circuit generation device provided in an embodiment of the present application.
具体实施方式Detailed ways
为使本申请的目的、技术方案、及优点更加清楚明白,以下参照附图并举实施例,对本申请进一步详细说明。显然,所描述的实施例仅仅是本申请一部分实施例,而不是全部的实施例。基于本申请中的实施例,本领域普通技术人员所获得的所有其他实施例,都属于本申请保护的范围。In order to make the purpose, technical solution, and advantages of the present application more clearly understood, the present application is further described in detail with reference to the accompanying drawings and examples. Obviously, the described embodiments are only part of the embodiments of the present application, rather than all of the embodiments. Based on the embodiments in the present application, all other embodiments obtained by ordinary technicians in the field belong to the scope of protection of the present application.
本申请实施例首先提供了一种量子线路生成方法,该方法可以应用于电子设备,如计算机终端,具体如普通电脑、量子计算机等。The embodiment of the present application first provides a quantum circuit generation method, which can be applied to electronic devices, such as computer terminals, specifically ordinary computers, quantum computers, etc.
量子计算机是一类遵循量子力学规律进行高速数学和逻辑运算、存储及处理量子信息的物理装置。当某个装置处理和计算的是量子信息,运行的是量子算法时,它就是量子计算机。量子计算机因其具有相对普通计算机更高效的处理数学问题的能力,例如,能将破解RSA(Rivest-Adi Shamir-Leonard Adleman)密钥的时间从数百年加速到数小时,故成为一种正在研究中的关键技术。Quantum computers are physical devices that follow the laws of quantum mechanics to perform high-speed mathematical and logical operations, store and process quantum information. When a device processes and calculates quantum information and runs quantum algorithms, it is a quantum computer. Quantum computers have become a key technology under research because they have the ability to process mathematical problems more efficiently than ordinary computers. For example, they can speed up the time to crack RSA (Rivest-Adi Shamir-Leonard Adleman) keys from hundreds of years to a few hours.
下面以量子计算运行在计算机终端上为例对其进行详细说明。图1为本申请实施例提供的一种量子线路生成方法的计算机终端的硬件结构框图。如 图1所示,计算机终端可以包括一个或多个(图1中仅示出一个)处理器102(处理器102可以包括但不限于微处理器(MCU,Micro Controller Unit)或可编程逻辑器件(FPGA,Field Programmable Gate Array)等的处理装置)和用于存储数据的存储器104,可选地,上述计算机终端还可以包括用于通信功能的传输装置106以及输入输出设备108。本领域普通技术人员可以理解,图1所示的结构仅为示意,其并不对上述计算机终端的结构造成限定。例如,计算机终端还可包括比图1中所示更多或者更少的组件,或者具有与图1所示不同的配置。The following is a detailed description of quantum computing running on a computer terminal as an example. FIG1 is a hardware structure block diagram of a computer terminal of a quantum circuit generation method provided in an embodiment of the present application. As shown in FIG1 , the computer terminal may include one or more (only one is shown in FIG1 ) processors 102 (the processor 102 may include but is not limited to a processing device such as a microprocessor (MCU, Micro Controller Unit) or a programmable logic device (FPGA, Field Programmable Gate Array)) and a memory 104 for storing data. Optionally, the computer terminal may also include a transmission device 106 and an input/output device 108 for communication functions. It will be appreciated by those skilled in the art that the structure shown in FIG1 is for illustration only and does not limit the structure of the computer terminal. For example, the computer terminal may also include more or fewer components than those shown in FIG1 , or have a configuration different from that shown in FIG1 .
存储器104可用于存储应用软件的软件程序以及模块,如本申请实施例中的量子线路生成方法对应的程序指令/模块,处理器102通过运行存储在存储器104内的软件程序以及模块,从而执行各种功能应用以及数据处理,即实现上述的方法。存储器104可包括高速随机存储器,还可包括非易失性存储器,如一个或者多个磁性存储装置、闪存、或者其他非易失性固态存储器。在一些实例中,存储器104可进一步包括相对于处理器102远程设置的存储器,这些远程存储器可以通过网络连接至计算机终端。上述网络的实例包括但不限于互联网、企业内部网、局域网、移动通信网及其组合。The memory 104 can be used to store software programs and modules of application software, such as program instructions/modules corresponding to the quantum circuit generation method in the embodiment of the present application. The processor 102 executes various functional applications and data processing by running the software programs and modules stored in the memory 104, that is, implementing the above method. The memory 104 may include a high-speed random access memory, and may also include a non-volatile memory, such as one or more magnetic storage devices, flash memory, or other non-volatile solid-state memory. In some examples, the memory 104 may further include a memory remotely arranged relative to the processor 102, and these remote memories may be connected to the computer terminal via a network. Examples of the above-mentioned network include, but are not limited to, the Internet, an intranet, a local area network, a mobile communication network, and a combination thereof.
传输装置106用于经由一个网络接收或者发送数据。上述的网络具体实例可包括计算机终端的通信供应商提供的无线网络。在一个实例中,传输装置106包括一个网络适配器(Network Interface Controller,NIC),其可通过基站与其他网络设备相连从而可与互联网进行通讯。在一个实例中,传输装置106可以为射频(Radio Frequency,RF)模块,其用于通过无线方式与互联网进行通讯。传输装置106也可以为ETH(Ethernet,以太网)模块,其用于通过有线方式与互联网进行通讯。The transmission device 106 is used to receive or send data via a network. The specific example of the above network may include a wireless network provided by a communication provider of a computer terminal. In one example, the transmission device 106 includes a network adapter (Network Interface Controller, NIC), which can be connected to other network devices through a base station so as to communicate with the Internet. In one example, the transmission device 106 can be a radio frequency (Radio Frequency, RF) module, which is used to communicate with the Internet wirelessly. The transmission device 106 can also be an ETH (Ethernet) module, which is used to communicate with the Internet via a wired method.
需要说明的是,真正的量子计算机是混合结构的,它包含两大部分:一部分是经典计算机,负责执行经典计算与控制;另一部分是量子设备,负责运行量子程序进而实现量子计算。而量子程序是由量子语言如QRunes语言编写的一串能够在量子计算机上运行的指令序列,实现了对量子逻辑门操作的支持,并最终实现量子计算。具体的说,量子程序就是一系列按照一定时序操作量子逻辑门的指令序列。It should be noted that a true quantum computer is a hybrid structure, which consists of two parts: one part is a classical computer, which is responsible for performing classical calculations and control; the other part is a quantum device, which is responsible for running quantum programs and thus realizing quantum computing. A quantum program is a sequence of instructions written in a quantum language such as QRunes that can be run on a quantum computer, which supports quantum logic gate operations and ultimately realizes quantum computing. Specifically, a quantum program is a sequence of instructions that operate quantum logic gates in a certain sequence.
在实际应用中,因受限于量子设备硬件的发展,通常需要进行量子计算 模拟以验证量子算法、量子应用等等。量子计算模拟即借助普通计算机的资源搭建的虚拟架构(即量子虚拟机)实现特定问题对应的量子程序的模拟运行的过程。通常,需要构建特定问题对应的量子程序。本申请实施例所指量子程序,即是经典语言编写的表征量子比特及其演化的程序,其中与量子计算相关的量子比特、量子逻辑门等等均有相应的经典代码表示。In practical applications, quantum computing is usually required due to the limitations of the development of quantum device hardware. Simulation to verify quantum algorithms, quantum applications, etc. Quantum computing simulation is the process of simulating the operation of quantum programs corresponding to specific problems by using a virtual architecture (i.e., quantum virtual machine) built with the resources of ordinary computers. Usually, it is necessary to build a quantum program corresponding to a specific problem. The quantum program referred to in the embodiment of the present application is a program written in a classical language to characterize quantum bits and their evolution, in which quantum bits, quantum logic gates, etc. related to quantum computing are represented by corresponding classical codes.
量子线路作为量子程序的一种体现方式,也称量子逻辑电路,是最常用的通用量子计算模型,表示在抽象概念下对于量子比特进行操作的线路,其组成包括量子比特、线路(时间线),以及各种量子逻辑门,最后常需要通过量子测量操作将结果读取出来。Quantum circuits, as a manifestation of quantum programs, are also called quantum logic circuits. They are the most commonly used general quantum computing model. They represent circuits that operate on quantum bits in an abstract concept. They are composed of quantum bits, circuits (timelines), and various quantum logic gates. Finally, the results often need to be read out through quantum measurement operations.
不同于传统电路是用金属线所连接以传递电压信号或电流信号,在量子线路中,线路可看成是由时间所连接,亦即量子比特的状态随着时间自然演化,在这过程中按照哈密顿运算符的指示,一直到遇上逻辑门而被操作。Unlike traditional circuits that are connected by metal wires to transmit voltage or current signals, in quantum circuits, the circuits can be seen as connected by time, that is, the state of the quantum bit evolves naturally over time, following the instructions of the Hamiltonian operator until it encounters a logic gate and is operated.
一个量子程序整体上对应有一条总的量子线路,本申请所述量子程序即指该条总的量子线路,其中,该总的量子线路中的量子比特总数与量子程序的量子比特总数相同。可以理解为:一个量子程序可以由量子线路、针对量子线路中量子比特的测量操作、保存测量结果的寄存器及控制流节点(跳转指令)组成,一条量子线路可以包含几十上百个甚至千上万个量子逻辑门操作。量子程序的执行过程,就是对所有的量子逻辑门按照一定时序执行的过程。需要说明的是,时序即单个量子逻辑门被执行的时间顺序。A quantum program as a whole corresponds to a total quantum circuit, and the quantum program described in this application refers to the total quantum circuit, wherein the total number of quantum bits in the total quantum circuit is the same as the total number of quantum bits in the quantum program. It can be understood that a quantum program can be composed of a quantum circuit, a measurement operation on the quantum bits in the quantum circuit, a register for storing the measurement results, and a control flow node (jump instruction). 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 quantum logic gates in a certain sequence. It should be noted that the sequence is the time order in which a single quantum logic gate is executed.
需要说明的是,经典计算中,最基本的单元是比特,而最基本的控制模式是逻辑门,可以通过逻辑门的组合来达到控制电路的目的。类似地,处理量子比特的方式就是量子逻辑门。使用量子逻辑门,能够使量子态发生演化,量子逻辑门是构成量子线路的基础,量子逻辑门包括单比特量子逻辑门,如Hadamard门(H门,阿达马门)、泡利-X门(X门)、泡利-Y门(Y门)、泡利-Z门(Z门)、RX门、RY门、RZ门等等;两比特或多比特量子逻辑门,如CNOT门、CR门、CZ门、iSWAP门、Toffoli门等等。量子逻辑门一般使用酉矩阵表示,而酉矩阵不仅是矩阵形式,也是一种操作和变换。一般量子逻辑门在量子态上的作用是通过酉矩阵左乘以量子态右矢对应的矩阵进行计算的。It should be noted that in classical computing, the most basic unit is the bit, and the most basic control mode is the logic gate, which can achieve the purpose of controlling the circuit through the combination of logic gates. Similarly, the way to process quantum bits is quantum logic gates. Using quantum logic gates, quantum states can evolve. Quantum logic gates are the basis of quantum circuits. Quantum logic gates include single-bit quantum logic gates, such as Hadamard gates (H gates, Hadamard gates), Pauli-X gates (X gates), Pauli-Y gates (Y gates), Pauli-Z gates (Z gates), RX gates, RY gates, RZ gates, etc.; two-bit or multi-bit quantum logic gates, such as CNOT gates, CR gates, CZ gates, iSWAP gates, Toffoli gates, etc. Quantum logic gates are generally represented by unitary matrices, which are not only matrix forms, but also operations and transformations. The effect of general quantum logic gates on quantum states is calculated by multiplying the unitary matrix on the left by the matrix corresponding to the right vector of the quantum state.
参见图2,图2为本申请实施例提供的一种量子线路生成方法的流程示意 图,可以包括如下步骤:See FIG. 2 , which is a schematic diagram of a process of a quantum circuit generation method provided in an embodiment of the present application. The diagram may include the following steps:
S201:获得为执行初始量子程序所需的目标临时变量。S201: Obtain target temporary variables required for executing the initial quantum program.
与全局变量不同,临时变量表示未在程序开头部分声明,即,在使用到时才进行声明的变量。临时变量在所属函数调用完成后自动销毁。Unlike global variables, temporary variables are variables that are not declared at the beginning of the program, that is, they are declared only when they are used. Temporary variables are automatically destroyed after the function call to which they belong is completed.
需要说明的是,临时变量是执行量子程序时临时需要的变量,临时变量可以记录在初始量子程序中,也可以未记录在初始量子程序中。执行初始量子程序需要的目标临时变量可能不止一个,当初始量子程序记录有目标临时变量,可以从该初始量子程序中直接获取该目标临时变量,当然还可以利用其他方式获得目标临时变量,比如,从预先记录的临时变量信息中获得目标临时变量。当初始量子程序中未记录目标临时变量,则对初始量子程序分析,将初始量子程序执行所需要的临时变量作为目标临时变量,或者通过针对初始量子程序记录的信息,获得目标临时变量。It should be noted that temporary variables are variables that are temporarily required when executing a quantum program. Temporary variables may or may not be recorded in the initial quantum program. There may be more than one target temporary variable required to execute the initial quantum program. When the initial quantum program records the target temporary variable, the target temporary variable can be directly obtained from the initial quantum program. Of course, the target temporary variable can also be obtained in other ways, such as obtaining the target temporary variable from pre-recorded temporary variable information. When the target temporary variable is not recorded in the initial quantum program, the initial quantum program is analyzed, and the temporary variable required for the execution of the initial quantum program is used as the target temporary variable, or the target temporary variable is obtained through the information recorded for the initial quantum program.
S202:根据所述目标临时变量,确定目标量子比特,其中,所述目标量子比特的初态为|0>态。S202: Determine a target quantum bit according to the target temporary variable, wherein an initial state of the target quantum bit is a |0> state.
为了让临时变量能在量子线路中与其他量子比特进行运算,从而实现临时变量对应的功能,需要为临时变量分配量子比特,具体的,可以根据预先确定的临时变量与量子比特的映射关系,确定目标量子比特,也可以从分配给临时变量的量子比特中,随机选择一个作为目标量子比特。当目标临时变量不止一个时,则分别为每一个目标临时变量分配一个目标量子比特。需要说明的是,为目标临时变量分配的量子比特称之为目标量子比特。In order to allow temporary variables to operate with other qubits in the quantum circuit and realize the corresponding functions of temporary variables, it is necessary to allocate qubits to temporary variables. Specifically, the target qubit can be determined based on the predetermined mapping relationship between temporary variables and qubits, or a random qubit can be selected from the qubits allocated to the temporary variable as the target qubit. When there is more than one target temporary variable, a target qubit is allocated to each target temporary variable. It should be noted that the qubit allocated to the target temporary variable is called the target qubit.
在本申请一些可能的实施方式中,所述根据所述目标临时变量,确定目标量子比特,包括:In some possible implementations of the present application, determining a target quantum bit according to the target temporary variable includes:
从预先设置的量子比特中,为所述目标临时变量分配一个空闲量子比特,作为目标量子比特。From the preset quantum bits, an idle quantum bit is allocated to the target temporary variable as the target quantum bit.
预先设置的量子比特是预先为临时变量准备的量子比特,这些量子比特与量子程序中已经定义的量子比特不重复,例如,初始量子程序已经定义了量子比特1-5,共五个量子比特;预先设置的量子比特可以为量子比特6-8,共三个量子比特。当有临时变量需要分配量子比特,从这些量子比特(即量子比特6-8)中选择一个空闲的量子比特,分配给该临时变量,即所选择的量子比特即为目标量子比特。在本申请的一种具体实现方式中,预先设置的量 子比特可以是存放在全局池中,全局池采用堆栈结构,当有临时变量需要分配量子比特且全局池中可用比特不为空,从栈顶弹出一个量子比特分配给需要的临时变量。例如,可以预先基于初始量子程序中的临时变量,在全局池中设置足够数量个量子比特,避免出现需要为临时变量分配量子比特且全局池中可用比特为空的情况。The pre-set qubits are qubits prepared in advance for temporary variables. These qubits do not overlap with the qubits already defined in the quantum program. For example, the initial quantum program has defined qubits 1-5, a total of five qubits; the pre-set qubits may be qubits 6-8, a total of three qubits. When a temporary variable needs to be assigned qubits, an idle qubit is selected from these qubits (i.e., qubits 6-8) and assigned to the temporary variable. The selected qubit is the target qubit. In a specific implementation of the present application, the pre-set qubits are The sub-bits can be stored in a global pool, which uses a stack structure. When a temporary variable needs to be allocated a qubit and the available bits in the global pool are not empty, a qubit is popped from the top of the stack and allocated to the required temporary variable. For example, a sufficient number of qubits can be set in the global pool in advance based on the temporary variables in the initial quantum program to avoid the situation where qubits need to be allocated for temporary variables and the available bits in the global pool are empty.
S203:基于所述初始量子程序,确定使所述目标量子比特的末态为|0>态的目标量子逻辑门。S203: Based on the initial quantum program, determine a target quantum logic gate that makes the final state of the target quantum bit a |0> state.
在本申请实施方式中,量子比特的初态是制备的,可以通过编码的方式将信息制备到量子比特上,该信息就是量子比特的初态。量子比特的初态会随着量子程序的运行(即在量子线路上随时间演化)发生变化,得到量子比特的末态。目标量子比特的量子态会发生变化,因为量子态的纠缠,也会使得其他量子比特的量子态改变,为了消除临时变量产生的影响,需要确定使目标量子比特的末态为|0>的目标量子逻辑门。In the implementation mode of the present application, the initial state of the quantum bit is prepared, and information can be prepared on the quantum bit by encoding, and the information is the initial state of the quantum bit. The initial state of the quantum bit will change with the operation of the quantum program (i.e., it evolves over time on the quantum circuit), and the final state of the quantum bit is obtained. The quantum state of the target quantum bit will change, because the entanglement of the quantum state will also change the quantum state of other quantum bits. In order to eliminate the influence of the temporary variable, it is necessary to determine the target quantum logic gate that makes the final state of the target quantum bit |0>.
基于初始量子程序,可以确定如果不消除临时变量影响的目标量子比特的末态,基于此末态,可以确定使目标量子比特的末态为|0>的量子逻辑门,所确定的量子逻辑门即是目标量子逻辑门,目标量子逻辑门可以不止一个。也就是说,可以先基于初始量子程序中的量子逻辑门对目标量子比特的量子态进行演化,得到该情况下目标量子比特的末态,得到的末态也就是不消除临时变量影响的目标量子比特的末态。进而,结合该末态确定目标量子逻辑门,使得在目标量子比特的初态为|0>态的情况下,经过初始量子程序中的量子逻辑门和目标量子逻辑门的处理,目标量子比特的末态仍为|0>态。即,目标量子逻辑门能够抵消初始量子程序中的量子逻辑门对目标量子比特的量子态的演化。Based on the initial quantum program, the final state of the target quantum bit can be determined if the influence of the temporary variable is not eliminated. Based on this final state, the quantum logic gate that makes the final state of the target quantum bit |0> can be determined. The determined quantum logic gate is the target quantum logic gate, and there can be more than one target quantum logic gate. In other words, the quantum state of the target quantum bit can be evolved based on the quantum logic gate in the initial quantum program to obtain the final state of the target quantum bit in this case. The final state obtained is also the final state of the target quantum bit without eliminating the influence of the temporary variable. Furthermore, the target quantum logic gate is determined in combination with the final state, so that when the initial state of the target quantum bit is the |0> state, after being processed by the quantum logic gate in the initial quantum program and the target quantum logic gate, the final state of the target quantum bit is still the |0> state. That is, the target quantum logic gate can offset the evolution of the quantum state of the target quantum bit by the quantum logic gate in the initial quantum program.
在本申请一些可能实施方式中,所述基于所述初始量子程序,确定使所述目标量子比特末态为|0>态的目标量子逻辑门,包括:In some possible implementations of the present application, determining, based on the initial quantum program, a target quantum logic gate that makes the final state of the target quantum bit a |0> state includes:
根据所述初始量子程序,确定作用在所述目标量子比特上的量子逻辑门;Determining a quantum logic gate acting on the target quantum bit according to the initial quantum program;
基于所确定的量子逻辑门,确定使所述目标量子比特末态为|0>态的目标量子逻辑门。Based on the determined quantum logic gate, a target quantum logic gate that makes the final state of the target quantum bit a |0> state is determined.
基于初始量子程序,可以确定作用在目标量子比特上的量子逻辑门,此处确定出的量子逻辑门是初始量子程序中的量子逻辑门,具体的,可以通过 初始量子程序记载的内容,或者对基于初始量子程序获得的信息,比如语法树等等进行解析,确定初始量子程序中作用在目标量子比特上的量子逻辑门。需要说明的是,在初始量子程序中,当目标量子比特作为一个两比特或多比特量子逻辑门的目标位,则该两比特或多比特量子逻辑门是作用在目标量子比特上的量子逻辑门。Based on the initial quantum program, the quantum logic gate acting on the target quantum bit can be determined. The quantum logic gate determined here is the quantum logic gate in the initial quantum program. Specifically, it can be determined by The content recorded in the initial quantum program, or the information obtained based on the initial quantum program, such as the syntax tree, is parsed to determine the quantum logic gate acting on the target quantum bit in the initial quantum program. It should be noted that in the initial quantum program, when the target quantum bit is used as the target bit of a two-bit or multi-bit quantum logic gate, the two-bit or multi-bit quantum logic gate is a quantum logic gate acting on the target quantum bit.
在本申请实施例中,可以将与所确定的作用在目标量子比特上的量子逻辑门的功能相反的量子逻辑门,作为目标量子逻辑门。具体的,可以是作用在目标量子比特上的量子逻辑门的逆门,作为目标量子逻辑门,其中,任一量子逻辑门的逆门用于实现与该量子逻辑门相逆的演化;或者,也可以根据所确定的作用在目标量子比特上的量子逻辑门的功能,确定多个量子逻辑门,使确定出的多个量子逻辑门可以抵消作用在目标量子比特上的量子逻辑门的功能,确定出的多个量子逻辑门作为目标量子逻辑门。示例性的,当所确定的作用在目标量子比特上的量子逻辑门为CNOT门,基于CNOT门的特性,确定的目标量子逻辑门也为CNOT门。具体的确定方式,可以根据预先建立的量子逻辑门与其对应的逆门之间的映射关系,确定目标量子逻辑门。In an embodiment of the present application, a quantum logic gate having the opposite function to the quantum logic gate determined to act on the target quantum bit can be used as the target quantum logic gate. Specifically, the inverse gate of the quantum logic gate acting on the target quantum bit can be used as the target quantum logic gate, wherein the inverse gate of any quantum logic gate is used to realize the evolution opposite to that of the quantum logic gate; or, multiple quantum logic gates can be determined according to the function of the quantum logic gate determined to act on the target quantum bit, so that the multiple quantum logic gates determined can offset the function of the quantum logic gate acting on the target quantum bit, and the multiple quantum logic gates determined are used as the target quantum logic gate. Exemplarily, when the quantum logic gate determined to act on the target quantum bit is a CNOT gate, based on the characteristics of the CNOT gate, the target quantum logic gate determined is also a CNOT gate. The specific determination method can determine the target quantum logic gate according to the mapping relationship between the pre-established quantum logic gate and its corresponding inverse gate.
在本申请一些可能的实施方式中,根据所述初始量子程序,确定作用在所述目标量子比特上的量子逻辑门,包括:In some possible implementations of the present application, determining a quantum logic gate acting on the target quantum bit according to the initial quantum program includes:
获得包含所述目标量子比特的拓扑图,其中,所述拓扑图是利用所述初始量子程序生成的,初始节点表征量子比特,其他节点表征量子逻辑门,边表征节点之间的关联关系;Obtaining a topological graph containing the target quantum bit, wherein the topological graph is generated using the initial quantum program, the initial node represents the quantum bit, the other nodes represent the quantum logic gates, and the edges represent the association relationship between the nodes;
基于所述拓扑图,确定作用在所述目标量子比特上的量子逻辑门。Based on the topological graph, a quantum logic gate acting on the target quantum bit is determined.
在本申请实施方式中,利用初始量子程序生成拓扑图,具体的,拓扑图是按照量子程序中的程序执行先后顺序生成的,反映量子程序的结构,示例性的,拓扑图可以是有向无环图,也可以是数学模型电路图。拓扑图中包含目标量子比特,拓扑图中初始节点表征量子比特,即初始节点的数量就是量子比特的数量,节点之间的关联关系可以包括初始节点与其他节点的作用关系,其他节点之间执行先后关系、约束关系,以及节点对应的量子逻辑门的受控关系等等。示例性的,量子程序为:In the implementation mode of the present application, the topological map is generated by using the initial quantum program. Specifically, the topological map is generated according to the execution order of the programs in the quantum program, reflecting the structure of the quantum program. Exemplarily, the topological map can be a directed acyclic graph or a mathematical model circuit diagram. The topological map contains the target quantum bits. The initial nodes in the topological map represent the quantum bits, that is, the number of initial nodes is the number of quantum bits. The association relationship between the nodes may include the action relationship between the initial node and other nodes, the execution order relationship and constraint relationship between other nodes, and the controlled relationship of the quantum logic gates corresponding to the nodes, etc. Exemplarily, the quantum program is:
circuit<<H(q0)circuit<<H(q0)
circuit<<CNOT(q0,aux) circuit<<CNOT(q0,aux)
circuit<<CNOT(aux,q1)circuit<<CNOT(aux,q1)
circuit<<CNOT(q1,q0)circuit<<CNOT(q1,q0)
其中,circuit是量子线路的表示,<<是程序符号,H和CNOT是量子逻辑门的符号,q0,q1和aux是量子比特的符号。Among them, circuit is the representation of quantum circuit, << is the program symbol, H and CNOT are the symbols of quantum logic gates, and q0, q1 and aux are the symbols of quantum bits.
circuit<<H(q0)表示:在量子线路中H门作用在q0上。circuit<<H(q0) means: in the quantum circuit, the H gate acts on q0.
circuit<<CNOT(q0,aux)表示:在量子线路中存在一个CNOT门的控制位是q0、目标位是aux。circuit<<CNOT(q0,aux) means: in the quantum circuit there is a CNOT gate whose control bit is q0 and target bit is aux.
circuit<<CNOT(aux,q1)表示:在量子线路中存在一个CNOT门的控制位是aux、目标位是q1。circuit<<CNOT(aux,q1) means: in the quantum circuit there is a CNOT gate whose control bit is aux and target bit is q1.
circuit<<CNOT(q1,q0)表示:在量子线路中,存在一个CNOT门的控制位是q1、目标位是q0。circuit<<CNOT(q1,q0) means: in the quantum circuit, there is a CNOT gate whose control bit is q1 and target bit is q0.
基于该量子程序,生成的拓扑图可以如图3所示,图中init是初始节点,表征量子比特q0、q1和q2,具体的q0和q1是初始化的量子比特,q2为临时变量aux对应的目标量子比特,q01表征作用在量子比特q00的第一个量子逻辑门,q02表征作用在量子比特q00的第二个量子逻辑门。节点之间的边表示节点之间的关联关系,具体的,初始节点与量子逻辑门之间的符号表征量子逻辑门所作用的量子比特,量子逻辑门之间的符号可以表征量子逻辑门之间的执行时序,比如,对于q0,先执行H门,再执行CNOT门。Based on this quantum program, the generated topology graph can be shown in Figure 3, where init is the initial node, representing quantum bits q0, q1, and q2. Specifically, q0 and q1 are initialized quantum bits, q2 is the target quantum bit corresponding to the temporary variable aux, q0 1 represents the first quantum logic gate acting on quantum bit q0 0 , and q0 2 represents the second quantum logic gate acting on quantum bit q0 0. The edges between nodes represent the association between nodes. Specifically, the symbol between the initial node and the quantum logic gate is Representing the quantum bits acted upon by quantum logic gates, and the symbols between quantum logic gates The execution timing between quantum logic gates can be characterized. For example, for q0, the H gate is executed first, and then the CNOT gate.
量子逻辑门之间的符号指向的量子逻辑门是受控量子逻辑门,箭头指向对应的量子比特是该受控量子逻辑门的目标位,圆点对应的量子比特是该受控量子逻辑门的控制位,q21对应的量子逻辑门CNOT为例,H门执行后执行该CNOT门,CNOT的控制位是q0,目标位是q2。箭头指向对应的量子比特,也就是箭头指向的量子逻辑门是作为目标位的量子比特。圆点对应的量子比特,也就是圆点处的量子逻辑门是做为控制位的量子比特。Symbols between quantum logic gates The quantum logic gate pointed to is the controlled quantum logic gate. The quantum bit pointed to by the arrow is the target bit of the controlled quantum logic gate. The quantum bit corresponding to the dot is the control bit of the controlled quantum logic gate. Take the quantum logic gate CNOT corresponding to q2 1 as an example. After the H gate is executed, the CNOT gate is executed. The control bit of CNOT is q0 and the target bit is q2. The quantum bit pointed to by the arrow means that the quantum logic gate pointed to by the arrow is the quantum bit as the target bit. The quantum bit corresponding to the dot, that is, the quantum logic gate at the dot is the quantum bit as the control bit.
以图3为例,基于拓扑图,通过遍历q2相关的逻辑门,可以确定作用在目标量子比特上的量子逻辑门为CNOT门。然后确定与CNOT门的功能相反的门或者CNOT门的逆门为目标量子逻辑门,基于CNOT门的性质可知,当在同一个量子比特上连续作用两个CNOT门,相当于没有作用,因此,目标量子逻辑门可以是CNOT门。拓扑图可以清楚地反映量子程序的结构,基于拓扑图结构,可以比较便捷快速地找到作用在目标量子比特上的量子逻辑门。 当作用在目标量子比特的门不止一个时,逆序逐步遍历作用在目标量子比特上的门,即从拓扑图中与目标量子比特相关的最后一个逻辑门确定的结束节点往上遍历,确定作用在目标量子比特的量子逻辑门。Taking Figure 3 as an example, based on the topological graph, by traversing the logic gates related to q2, it can be determined that the quantum logic gate acting on the target quantum bit is a CNOT gate. Then, the gate with the opposite function to the CNOT gate or the inverse gate of the CNOT gate is determined as the target quantum logic gate. Based on the properties of the CNOT gate, it can be known that when two CNOT gates are continuously applied to the same quantum bit, it is equivalent to having no effect. Therefore, the target quantum logic gate can be a CNOT gate. The topological graph can clearly reflect the structure of the quantum program. Based on the topological graph structure, the quantum logic gate acting on the target quantum bit can be found relatively quickly and conveniently. When there is more than one gate acting on the target quantum bit, the gates acting on the target quantum bit are traversed step by step in reverse order, that is, traversing upward from the end node determined by the last logic gate related to the target quantum bit in the topological graph to determine the quantum logic gate acting on the target quantum bit.
S204:基于所述初始量子程序和所述目标量子逻辑门,生成目标量子线路。S204: Generate a target quantum circuit based on the initial quantum program and the target quantum logic gate.
在初始量子程序中对应的位置加入目标量子逻辑门,就生成了目标量子线路,目标量子逻辑门加入的位置可以由初始量子程序中作用在目标量子比特上的量子逻辑门的位置确定,具体的,目标量子逻辑门加入的位置可以紧邻初始量子程序中作用在目标量子比特上的量子逻辑门,或者位置与初始量子程序中作用在目标量子比特上的量子逻辑门比较接近,原则是加入目标量子逻辑门后不能改变未加入临时变量的情况下得到的其他量子比特的末态。By adding the target quantum logic gate at the corresponding position in the initial quantum program, the target quantum circuit is generated. The position where the target quantum logic gate is added can be determined by the position of the quantum logic gate acting on the target quantum bit in the initial quantum program. Specifically, the position where the target quantum logic gate is added can be adjacent to the quantum logic gate acting on the target quantum bit in the initial quantum program, or the position is relatively close to the quantum logic gate acting on the target quantum bit in the initial quantum program. The principle is that adding the target quantum logic gate cannot change the final state of other quantum bits obtained without adding temporary variables.
在量子计算中,临时变量对计算结果产生影响,是由于量子计算本身的特性决定的,量子计算基于量子态的纠缠得到结果,而临时变量会因为为其分配的量子比特的量子态会参与计算,从而可以改变量子态的纠缠结果,进而对计算结果产生影响。本申请实施例提供的方案,目标量子线路中包含目标量子逻辑门,在运行目标量子线路时,因为得到的目标量子比特的初态为|0>态,在计算过程中,将目标量子比特的末态通过量子逻辑门重新置为|0>态,实现了临时变量的自动取消计算,即,通过新增的目标量子逻辑门,使得整个量子线路对临时变量的处理不会影响其他量子比特,从而消除临时变量对其他量子比特结果的影响,进而减少计算结果出现错误的可能性。In quantum computing, temporary variables have an impact on the calculation results, which is determined by the characteristics of quantum computing itself. Quantum computing obtains results based on the entanglement of quantum states, and temporary variables will participate in the calculation because the quantum states of the quantum bits assigned to them will participate in the calculation, thereby changing the entanglement results of the quantum states, and thus affecting the calculation results. The solution provided by the embodiment of the present application includes a target quantum logic gate in the target quantum circuit. When the target quantum circuit is run, because the initial state of the target quantum bit obtained is the |0> state, during the calculation process, the final state of the target quantum bit is reset to the |0> state through the quantum logic gate, realizing the automatic cancellation of the calculation of the temporary variable, that is, through the newly added target quantum logic gate, the processing of the temporary variable by the entire quantum circuit will not affect other quantum bits, thereby eliminating the influence of the temporary variable on the results of other quantum bits, thereby reducing the possibility of errors in the calculation results.
在本申请一个可能的实施方式中,基于所述初始量子程序和所述目标量子逻辑门,生成目标量子线路,包括:In a possible implementation of the present application, generating a target quantum circuit based on the initial quantum program and the target quantum logic gate includes:
在当前拓扑图中,确定所述目标量子逻辑门的添加位置并添加对应的节点;In the current topology graph, determine the adding position of the target quantum logic gate and add the corresponding node;
根据当前拓扑图中的关联关系,确定与新添加的节点具有关联关系的节点;According to the association relationship in the current topology map, determine the node that has an association relationship with the newly added node;
建立所确定的节点与新添加的节点之间的边,以确定新的拓扑图;Establishing edges between the determined nodes and the newly added nodes to determine a new topological graph;
基于所述新的拓扑图,生成目标量子线路。Based on the new topological graph, a target quantum circuit is generated.
拓扑图的结构反映了量子逻辑门执行的顺序,可以将目标量子逻辑门对应的节点添加到拓扑图中,基于拓扑图生成目标量子线路,可以精准地消除 临时变量的影响。具体的,目标量子逻辑门对应的节点的添加位置可以在当前作用在目标量子比特上的量子逻辑门对应的节点之后,在所确定的位置添加目标量子逻辑门对应的节点,当目标量子逻辑门的不止一个时,按照对应的量子逻辑门的逆序,添加对应的节点,示例性的,可以如图4所示,U1和U2是作用在目标量子比特的U门,分别为U1、U2对应的目标量子逻辑门,在拓扑图中先添加对应的节点,再添加对应的节点。可见,基于上述实施例中按照逆序逐步遍历作用在目标量子比特上的量子逻辑门后,也就能够按照确定出的量子逻辑门的顺序,依次确定各自对应的目标量子逻辑门,并添加相应的节点至拓扑图中。The structure of the topological graph reflects the order in which quantum logic gates are executed. The nodes corresponding to the target quantum logic gates can be added to the topological graph, and the target quantum circuit can be generated based on the topological graph to accurately eliminate Influence of temporary variables. Specifically, the node corresponding to the target quantum logic gate can be added at the determined position after the node corresponding to the quantum logic gate currently acting on the target quantum bit. When there is more than one target quantum logic gate, the corresponding nodes are added in the reverse order of the corresponding quantum logic gates. For example, as shown in FIG. 4, U1 and U2 are U gates acting on the target quantum bit. They are the target quantum logic gates corresponding to U 1 and U 2 respectively. First add Corresponding nodes, then add It can be seen that after traversing the quantum logic gates acting on the target quantum bits in reverse order in the above embodiment, the corresponding target quantum logic gates can be determined in turn according to the determined order of the quantum logic gates, and the corresponding nodes can be added to the topology graph.
基于使目标量子比特的量子态最终为|0>态的原则,基于当前拓扑图,可以确定作用在目标量子比特上的量子逻辑门对应的节点,为新添加节点的关联节点。从受到临时变量影响的量子比特对应的节点中,确定与新添加的节点具有关联关系的节点。添加所确定的节点(包含上述两种方式确定出的与新添加的节点具有关联关系的节点)与新添加节点之间的边,边的类型与关联关系有关。示例性的,在图3的基础上,按照本申请实施例提供的添加方式,生成的新的拓扑图如图5所示,在该示例中,图3所示的拓扑图为当前拓扑图,图5所示拓扑图为添加目标量子逻辑门对应的节点得到的新的拓扑图。从执行时序的角度来说,就是在q21表征的CNOT门和q02表征的CNOT门之间添加了q22表征的CNOT门。例如,可以确定初始量子程序中的两比特量子逻辑门和多比特量子逻辑门中与目标量子比特关联的量子逻辑门,相应的,与该部分量子逻辑门关联的其他量子比特,可以表示受到临时变量影响的量子比特。例如,针对任一受控量子逻辑门,该受控量子逻辑门的目标位和控制位均与该受控量子逻辑门关联。Based on the principle of making the quantum state of the target quantum bit finally | 0 > state, based on the current topological map, the node corresponding to the quantum logic gate acting on the target quantum bit can be determined as the associated node of the newly added node. From the nodes corresponding to the quantum bits affected by the temporary variables, determine the nodes with an associated relationship with the newly added nodes. Add the edges between the determined nodes (including the nodes with an associated relationship with the newly added nodes determined by the above two methods) and the newly added nodes, and the type of edge is related to the associated relationship. Exemplarily, on the basis of Figure 3, according to the adding method provided in the embodiment of the present application, the generated new topological map is shown in Figure 5. In this example, the topological map shown in Figure 3 is the current topological map, and the topological map shown in Figure 5 is a new topological map obtained by adding the nodes corresponding to the target quantum logic gate. From the perspective of execution timing, the CNOT gate represented by q2 1 and the CNOT gate represented by q0 2 are added between the CNOT gate represented by q2 2 . For example, the quantum logic gates associated with the target quantum bit in the two-bit quantum logic gates and multi-bit quantum logic gates in the initial quantum program can be determined, and correspondingly, the other quantum bits associated with the part of the quantum logic gates can represent the quantum bits affected by the temporary variables. For example, for any controlled quantum logic gate, the target bit and the control bit of the controlled quantum logic gate are associated with the controlled quantum logic gate.
当量子程序中,部分量子逻辑门的执行顺序不可调换时,为了保证后续基于拓扑图生成的量子线路中量子逻辑门的执行顺序正确,需要在拓扑图中以边的类型约束量子逻辑门的执行顺序,示例性的,如图6所示,q1是目标量子比特,带虚线的符号表示节点之间存在约束关系,代表先执行q11表征的CNOT门,再执行q02表征的H门。当拓扑图中存在约束关系时,为了实现自动取消计算,需要在CNOT门和第二个H门(即q02表征的H门)间添加CNOT门。添加完CNOT门对应的节点(即q12)后,要添加对于第 二个H门的边符号来确保第二个H门在添加的CNOT门之后执行,新的拓扑图可以如图7所示。When the execution order of some quantum logic gates in a quantum program cannot be changed, in order to ensure the correct execution order of quantum logic gates in the quantum circuit generated based on the topological graph, it is necessary to constrain the execution order of quantum logic gates by edge type in the topological graph. For example, as shown in Figure 6, q1 is the target quantum bit, and the symbol with a dotted line Indicates that there is a constraint relationship between the nodes, which means that the CNOT gate represented by q1 1 is executed first, and then the H gate represented by q0 2 is executed. When there is a constraint relationship in the topology, in order to achieve automatic cancellation of calculation, it is necessary to add a CNOT gate between the CNOT gate and the second H gate (i.e., the H gate represented by q0 2 ). After adding the node corresponding to the CNOT gate (i.e., q1 2 ), add the Side symbols of two H gates To ensure that the second H gate is executed after the added CNOT gate, the new topology can be shown in Figure 7.
在本申请一个可能的实施方式中,所述基于所述新的拓扑图,生成目标量子线路,包括:In a possible implementation of the present application, generating a target quantum circuit based on the new topological graph includes:
根据新的拓扑图,确定作用在每一量子比特上的量子逻辑门、执行时序、以及作用关系;According to the new topological diagram, the quantum logic gates, execution timing, and action relationships acting on each quantum bit are determined;
基于所述执行时序和所述作用关系,将所确定的量子逻辑门依次作用在对应的量子比特上,生成目标量子线路。Based on the execution sequence and the action relationship, the determined quantum logic gates are sequentially applied to corresponding quantum bits to generate a target quantum circuit.
将新的拓扑图编译回量子线路,首先根据初始节点的数量,确定量子比特的数量,对于每一个量子比特,依次遍历拓扑图,确定作用在量子比特的量子逻辑门、量子逻辑门的执行时序以及作用关系,基于执行时序和作用关系,依次在量子比特上作用对应的量子逻辑门,从而获得目标量子线路,示例性的,在对图5进行编译,生成的量子线路图可以如图8所示。图8中,q[0]表示图5中q0表征的量子比特,q[1]表示图5中q1表征的量子比特,q[2]表示图5中q2表征的量子比特。Compile the new topology back to the quantum circuit. First, determine the number of quantum bits based on the number of initial nodes. For each quantum bit, traverse the topology in turn to determine the quantum logic gates acting on the quantum bit, the execution sequence of the quantum logic gates, and the action relationship. Based on the execution sequence and the action relationship, act on the quantum bits in turn with the corresponding quantum logic gates, thereby obtaining the target quantum circuit. For example, after compiling FIG5, the generated quantum circuit diagram can be shown in FIG8. In FIG8, q[0] represents the quantum bit represented by q0 in FIG5, q[1] represents the quantum bit represented by q1 in FIG5, and q[2] represents the quantum bit represented by q2 in FIG5.
在本申请一个可能的实施方式中,方法还可以包括:In a possible implementation of the present application, the method may further include:
当所述目标临时变量生命周期结束,释放所述目标量子比特,以使所述目标量子比特可重新分配。When the life cycle of the target temporary variable ends, the target quantum bit is released so that the target quantum bit can be reallocated.
如果为每一个临时变量都单独分配的一个量子比特会导致量子资源的大量的消耗,而量子资源非常宝贵,因此,可以在临时变量的生命周期结束后,对量子比特进行重新利用,达到节约资源的目的。一般情况下,可以将临时变量所在函数结束时当作其在生命周期结束的时间点。具体的,可以通过全局池实现临时变量的内存管理,全局池是堆栈结构。当临时变量需要分配量子比特时,从栈顶pop(弹)量子比特为目标量子比特,当临时变量生命周期结束,将量子比特回收到全局池中。例如,将回收的量子比特添加至栈顶。If a separate quantum bit is allocated for each temporary variable, it will lead to a large consumption of quantum resources, and quantum resources are very precious. Therefore, the quantum bits can be reused after the life cycle of the temporary variable ends to achieve the purpose of saving resources. In general, the end of the function where the temporary variable is located can be regarded as the time point when its life cycle ends. Specifically, the memory management of temporary variables can be implemented through the global pool, which is a stack structure. When a temporary variable needs to allocate a quantum bit, the quantum bit is popped from the top of the stack as the target quantum bit. When the life cycle of the temporary variable ends, the quantum bit is recycled to the global pool. For example, the recycled quantum bit is added to the top of the stack.
示例性的,通过全局池对量子比特进行内存管理可以如图9所示,全局池为临时变量分配的量子比特为q0-q9这10个量子比特,aux0-aux2都是临时变量,aux0会调用aux1和aux2,当一个变量需要分配量子比特时,从栈顶pop出一个量子比特,当临时变量生命周期结束,将临时变量所占用的量子比特放回到栈中。 Exemplarily, memory management of quantum bits through the global pool can be shown in Figure 9. The quantum bits allocated by the global pool for temporary variables are 10 quantum bits q0-q9, aux0-aux2 are all temporary variables, aux0 will call aux1 and aux2, when a variable needs to be allocated with a quantum bit, a quantum bit is popped from the top of the stack, and when the life cycle of the temporary variable ends, the quantum bits occupied by the temporary variable are put back into the stack.
图9中,通过主函数为临时变量aux0申请比特,此时,由于全局池的最顶端为量子比特q0,则为临时变量aux0分配量子比特q0。然后,可以调用函数1,通过函数1为临时变量aux1申请比特,此时,由于全局池的最顶端为量子比特q1,则为临时变量aux1分配量子比特q1。在函数1结束时,则回收为临时变量aux1分配量子比特q1,并添加至栈顶。然后,可以调用函数2,通过函数2为临时变量aux2申请比特,此时,由于全局池的最顶端为量子比特q1,则为临时变量aux2分配量子比特q1。在函数2结束时,则回收为临时变量aux2分配量子比特q1,并添加至栈顶。进而,在主函数结束时,则回收为临时变量aux0分配量子比特q0,并添加至栈顶。In Figure 9, the main function is used to apply for bits for the temporary variable aux0. At this time, since the top of the global pool is quantum bit q0, quantum bit q0 is allocated to the temporary variable aux0. Then, function 1 can be called to apply for bits for the temporary variable aux1 through function 1. At this time, since the top of the global pool is quantum bit q1, quantum bit q1 is allocated to the temporary variable aux1. At the end of function 1, the quantum bit q1 allocated to the temporary variable aux1 is recovered and added to the top of the stack. Then, function 2 can be called to apply for bits for the temporary variable aux2 through function 2. At this time, since the top of the global pool is quantum bit q1, quantum bit q1 is allocated to the temporary variable aux2. At the end of function 2, the quantum bit q1 allocated to the temporary variable aux2 is recovered and added to the top of the stack. Furthermore, at the end of the main function, the quantum bit q0 allocated to the temporary variable aux0 is recovered and added to the top of the stack.
可见,本申请实施例先获得为执行初始量子程序所需的目标临时变量;根据所述目标临时变量,确定目标量子比特;然后基于所述初始量子程序,确定使所述目标量子比特的末态为|0>态的目标量子逻辑门;最后基于所述初始量子程序和所述目标量子逻辑门,生成目标量子线路。通过初始量子程序,确定使得临时变量对应的量子比特的末态为|0>态的量子逻辑门,并加入到对应的位置,从而获得最终量子线路,在运行量子线路时,自动消除了临时变量加入对计算结果的影响,进而减少计算结果出现错误的可能性。It can be seen that the embodiment of the present application first obtains the target temporary variable required for executing the initial quantum program; determines the target quantum bit according to the target temporary variable; then determines the target quantum logic gate that makes the final state of the target quantum bit |0> state based on the initial quantum program; finally, generates the target quantum circuit based on the initial quantum program and the target quantum logic gate. Through the initial quantum program, the quantum logic gate that makes the final state of the quantum bit corresponding to the temporary variable |0> state is determined and added to the corresponding position, thereby obtaining the final quantum circuit. When running the quantum circuit, the influence of the temporary variable addition on the calculation result is automatically eliminated, thereby reducing the possibility of errors in the calculation result.
本申请实施例提供的量子生成方法应用于有临时变量加入的量子计算场景中,具体的,可以密码破解、人工智能、生物医药、金融工程、航空航天与交通等场景中。在这些场景中,如果有临时变量,可以使用本申请实施例提供的方法,消除临时变量的影响,减少计算结果出现错误的可能性,促进各个领域的发展。The quantum generation method provided in the embodiment of the present application is applied to quantum computing scenarios with temporary variables, specifically, password cracking, artificial intelligence, biomedicine, financial engineering, aerospace and transportation, etc. In these scenarios, if there are temporary variables, the method provided in the embodiment of the present application can be used to eliminate the influence of temporary variables, reduce the possibility of errors in the calculation results, and promote the development of various fields.
参见图10,图10为本申请实施例提供的一种量子线路生成装置的结构示意图,与图2所示的流程相对应,所述装置包括:Referring to FIG. 10 , FIG. 10 is a schematic diagram of the structure of a quantum circuit generation device provided in an embodiment of the present application, corresponding to the process shown in FIG. 2 , the device includes:
获得模块1001,用于获得为执行初始量子程序所需的目标临时变量;An acquisition module 1001 is used to obtain a target temporary variable required for executing an initial quantum program;
第一确定模块1002,用于根据所述目标临时变量,确定目标量子比特,其中,所述目标量子比特的初态为|0>态;A first determination module 1002 is used to determine a target quantum bit according to the target temporary variable, wherein the initial state of the target quantum bit is a |0> state;
第二确定模块1003,用于基于所述初始量子程序,确定使所述目标量子比特的末态为|0>态的目标量子逻辑门;A second determination module 1003 is used to determine a target quantum logic gate that makes the final state of the target quantum bit a |0> state based on the initial quantum program;
生成模块1004,用于基于所述初始量子程序和所述目标量子逻辑门,生成目标量子线路。 The generating module 1004 is used to generate a target quantum circuit based on the initial quantum program and the target quantum logic gate.
在本申请一些可能实施方式中,所述第一确定模块1002,可以具体用于:In some possible implementations of the present application, the first determining module 1002 may be specifically used to:
从预先设置的量子比特中,为所述目标临时变量分配一个空闲量子比特,作为目标量子比特。From the pre-set quantum bits, an idle quantum bit is allocated to the target temporary variable as the target quantum bit.
在本申请一些可能实施方式中,所述第二确定模块1003,可以包括:In some possible implementations of the present application, the second determining module 1003 may include:
第一确定单元,用于根据所述初始量子程序,确定作用在所述目标量子比特上的量子逻辑门;A first determining unit, configured to determine a quantum logic gate acting on the target quantum bit according to the initial quantum program;
第二确定单元,用于基于所确定的量子逻辑门,确定使所述目标量子比特的末态为|0>态的目标量子逻辑门。The second determining unit is used to determine a target quantum logic gate that makes the final state of the target quantum bit a |0> state based on the determined quantum logic gate.
在本申请一些可能实施方式中,所述第一确定单元,可以具体用于:In some possible implementations of the present application, the first determining unit may be specifically configured to:
获得包含所述目标量子比特的拓扑图,其中,所述拓扑图是利用所述初始量子程序生成的,初始节点表征量子比特,其他节点表征量子逻辑门,边表征节点之间的关联关系;Obtaining a topological graph containing the target quantum bit, wherein the topological graph is generated using the initial quantum program, the initial node represents the quantum bit, the other nodes represent the quantum logic gates, and the edges represent the association relationship between the nodes;
基于所述拓扑图,确定作用在所述目标量子比特上的量子逻辑门。Based on the topological graph, a quantum logic gate acting on the target quantum bit is determined.
在本申请一些可能实施方式中,所述生成模块1004,可以具体用于:In some possible implementations of the present application, the generating module 1004 may be specifically used for:
在当前拓扑图中,确定所述目标量子逻辑门的添加位置并添加对应的节点;In the current topology graph, determine the adding position of the target quantum logic gate and add the corresponding node;
根据当前拓扑图中的关联关系,确定与新添加的节点具有关联关系的节点;According to the association relationship in the current topology diagram, determine the node that has an association relationship with the newly added node;
建立所确定的节点与新添加的节点之间的边,以确定新的拓扑图;Establishing edges between the determined nodes and the newly added nodes to determine a new topological graph;
基于所述新的拓扑图,生成目标量子线路。Based on the new topological graph, a target quantum circuit is generated.
在本申请一些可能实施方式中,所述生成模块1004,还可以具体用于:In some possible implementations of the present application, the generating module 1004 may also be specifically used for:
根据新的拓扑图,确定作用在每一量子比特上的量子逻辑门、执行时序、以及作用关系;According to the new topological diagram, the quantum logic gates, execution timing, and action relationships acting on each quantum bit are determined;
基于所述执行时序和所述作用关系,将所确定的量子逻辑门依次作用在对应的量子比特上,生成目标量子线路。Based on the execution sequence and the action relationship, the determined quantum logic gates are sequentially applied to corresponding quantum bits to generate a target quantum circuit.
在本申请一些可能实施方式中,所述装置还可以包括:In some possible implementations of the present application, the device may further include:
释放模块,用于当所述目标临时变量生命周期结束,释放所述目标量子比特,以使所述目标量子比特可重新分配。A release module is used to release the target quantum bit when the life cycle of the target temporary variable ends, so that the target quantum bit can be reallocated.
可见,本申请实施例先获得为执行初始量子程序所需的目标临时变量;根据所述目标临时变量,确定目标量子比特;然后基于所述初始量子程序, 确定使所述目标量子比特的末态为|0>态的目标量子逻辑门;最后基于所述初始量子程序和所述目标量子逻辑门,生成目标量子线路。通过初始量子程序,确定使得临时变量对应的量子比特的末态为|0>态的量子逻辑门,并加入到对应的位置,从而获得最终量子线路,在运行量子线路时,自动消除了临时变量加入对计算结果的影响,进而减少计算结果出现错误的可能性。It can be seen that the embodiment of the present application first obtains the target temporary variable required for executing the initial quantum program; determines the target quantum bit according to the target temporary variable; and then based on the initial quantum program, Determine the target quantum logic gate that makes the final state of the target quantum bit to be |0>state; finally, generate the target quantum circuit based on the initial quantum program and the target quantum logic gate. Through the initial quantum program, determine the quantum logic gate that makes the final state of the quantum bit corresponding to the temporary variable to be |0> state, and add it to the corresponding position, so as to obtain the final quantum circuit. When running the quantum circuit, the influence of the addition of the temporary variable on the calculation result is automatically eliminated, thereby reducing the possibility of errors in the calculation result.
本申请实施例还提供了一种存储介质,所述存储介质中存储有计算机程序,其中,所述计算机程序被设置为运行时执行上述任一项方法实施例中的步骤。An embodiment of the present application further provides a storage medium, in which a computer program is stored, wherein the computer program is configured to execute the steps of any of the above method embodiments when running.
具体的,在本实施例中,上述存储介质可以被设置为存储用于执行以下步骤的计算机程序:Specifically, in this embodiment, the above storage medium may be configured to store a computer program for performing the following steps:
S201:获得为执行初始量子程序所需的目标临时变量;S201: Obtaining target temporary variables required for executing the initial quantum program;
S202:根据所述目标临时变量,确定目标量子比特,其中,所述目标量子比特的初态为|0>态;S202: Determine a target quantum bit according to the target temporary variable, wherein the initial state of the target quantum bit is a |0> state;
S203:基于所述初始量子程序,确定使所述目标量子比特的末态为|0>态的目标量子逻辑门;S203: Based on the initial quantum program, determine a target quantum logic gate that makes the final state of the target quantum bit a |0> state;
S204:基于所述初始量子程序和所述目标量子逻辑门,生成目标量子线路。S204: Generate a target quantum circuit based on the initial quantum program and the target quantum logic gate.
本申请实施例还提供了一种电子装置,包括存储器和处理器,所述存储器中存储有计算机程序,所述处理器被设置为运行所述计算机程序以执行上述任一项方法实施例中的步骤。An embodiment of the present application further 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 execute the steps in any one of the above method embodiments.
具体的,上述电子装置还可以包括传输设备以及输入输出设备,其中,该传输设备和上述处理器连接,该输入输出设备和上述处理器连接。Specifically, the electronic device may further include a transmission device and an input/output device, wherein the transmission device is connected to the processor, and the input/output device is connected to the processor.
具体的,在本实施例中,上述处理器可以被设置为通过计算机程序执行以下步骤:Specifically, in this embodiment, the processor may be configured to perform the following steps through a computer program:
S201:获得为执行初始量子程序所需的目标临时变量;S201: Obtaining target temporary variables required for executing the initial quantum program;
S202:根据所述目标临时变量,确定目标量子比特,其中,所述目标量子比特的初态为|0>态;S202: Determine a target quantum bit according to the target temporary variable, wherein the initial state of the target quantum bit is a |0> state;
S203:基于所述初始量子程序,确定使所述目标量子比特的末态为|0>态的目标量子逻辑门;S203: Based on the initial quantum program, determine a target quantum logic gate that makes the final state of the target quantum bit a |0> state;
S204:基于所述初始量子程序和所述目标量子逻辑门,生成目标量子线 路S204: Generate a target quantum wire based on the initial quantum program and the target quantum logic gate road
本申请实施例还提出一种包含指令的计算机程序产品,当其在计算机上运行时,使得计算机执行上述任一项方法实施例中的步骤。The embodiment of the present application also proposes a computer program product comprising instructions, which, when executed on a computer, enables the computer to execute the steps in any of the above method embodiments.
以上所述仅为本申请的较佳实施例,并不用以限制本申请,凡在本申请的精神和原则之内,所做的任何修改、等同替换、改进等,均应包含在本申请保护的范围之内。 The above description is only a preferred embodiment of the present application and is not intended to limit the present application. Any modifications, equivalent substitutions, improvements, etc. made within the spirit and principles of the present application shall be included in the scope of protection of the present application.

Claims (10)

  1. 一种量子线路生成方法,其特征在于,所述方法包括:A quantum circuit generation method, characterized in that the method comprises:
    获得为执行初始量子程序所需的目标临时变量;Obtain the target temporary variables required to execute the initial quantum program;
    根据所述目标临时变量,确定目标量子比特,其中,所述目标量子比特的初态为|0>态;Determine a target quantum bit according to the target temporary variable, wherein the initial state of the target quantum bit is a |0> state;
    基于所述初始量子程序,确定使所述目标量子比特的末态为|0>态的目标量子逻辑门;Based on the initial quantum program, determining a target quantum logic gate that makes the final state of the target quantum bit a |0> state;
    基于所述初始量子程序和所述目标量子逻辑门,生成目标量子线路。Based on the initial quantum program and the target quantum logic gate, a target quantum circuit is generated.
  2. 根据权利要求1所述的方法,其特征在于,所述根据所述目标临时变量,确定目标量子比特,包括:The method according to claim 1, characterized in that determining the target quantum bit according to the target temporary variable comprises:
    从预先设置的量子比特中,为所述目标临时变量分配一个空闲量子比特,作为目标量子比特。From the preset quantum bits, an idle quantum bit is allocated to the target temporary variable as the target quantum bit.
  3. 根据权利要求1或2所述的方法,其特征在于,所述基于所述初始量子程序,确定使所述目标量子比特的末态为|0>态的目标量子逻辑门,包括:The method according to claim 1 or 2, characterized in that the step of determining, based on the initial quantum program, a target quantum logic gate that makes the final state of the target quantum bit a |0> state comprises:
    根据所述初始量子程序,确定作用在所述目标量子比特上的量子逻辑门;Determining a quantum logic gate acting on the target quantum bit according to the initial quantum program;
    基于所确定的量子逻辑门,确定使所述目标量子比特的末态为|0>态的目标量子逻辑门。Based on the determined quantum logic gate, a target quantum logic gate that makes the final state of the target quantum bit a |0> state is determined.
  4. 根据权利要求3所述的方法,其特征在于,所述根据所述初始量子程序,确定作用在所述目标量子比特上的量子逻辑门,包括:The method according to claim 3, characterized in that the step of determining the quantum logic gate acting on the target quantum bit according to the initial quantum program comprises:
    获得包含所述目标量子比特的拓扑图,其中,所述拓扑图是利用所述初始量子程序生成的,初始节点表征量子比特,其他节点表征量子逻辑门,边表征节点之间的关联关系;Obtaining a topological graph containing the target quantum bit, wherein the topological graph is generated using the initial quantum program, the initial node represents the quantum bit, the other nodes represent the quantum logic gates, and the edges represent the association relationship between the nodes;
    基于所述拓扑图,确定作用在所述目标量子比特上的量子逻辑门。Based on the topological graph, a quantum logic gate acting on the target quantum bit is determined.
  5. 根据权利要求4所述的方法,其特征在于,所述基于所述初始量子程序和所述目标量子逻辑门,生成目标量子线路,包括:The method according to claim 4, characterized in that generating a target quantum circuit based on the initial quantum program and the target quantum logic gate comprises:
    在当前拓扑图中,确定所述目标量子逻辑门的添加位置并添加对应的节点;In the current topology graph, determine the adding position of the target quantum logic gate and add the corresponding node;
    根据当前拓扑图中的关联关系,确定与新添加的节点具有关联关系的节点;According to the association relationship in the current topology diagram, determine the node that has an association relationship with the newly added node;
    建立所确定的节点与新添加的节点之间的边,以确定新的拓扑图; Establishing edges between the determined nodes and the newly added nodes to determine a new topological graph;
    基于所述新的拓扑图,生成目标量子线路。Based on the new topological graph, a target quantum circuit is generated.
  6. 根据权利要求5所述的方法,其特征在于,所述基于所述新的拓扑图,生成目标量子线路,包括:The method according to claim 5, characterized in that generating a target quantum circuit based on the new topological graph comprises:
    根据所述新的拓扑图,确定作用在每一量子比特上的量子逻辑门、执行时序、以及作用关系;Determine the quantum logic gate, execution sequence, and action relationship acting on each quantum bit according to the new topological diagram;
    基于所述执行时序和所述作用关系,将所确定的量子逻辑门依次作用在对应的量子比特上,生成目标量子线路。Based on the execution sequence and the action relationship, the determined quantum logic gates are sequentially applied to corresponding quantum bits to generate a target quantum circuit.
  7. 根据权利要求2所述的方法,其特征在于,所述方法还包括:The method according to claim 2, characterized in that the method further comprises:
    当所述目标临时变量生命周期结束,释放所述目标量子比特,以使所述目标量子比特可重新分配。When the life cycle of the target temporary variable ends, the target quantum bit is released so that the target quantum bit can be reallocated.
  8. 一种量子线路生成装置,其特征在于,所述装置包括:A quantum circuit generation device, characterized in that the device comprises:
    获得模块,用于获得为执行初始量子程序所需的目标临时变量;An acquisition module, used for obtaining target temporary variables required for executing an initial quantum program;
    第一确定模块,用于根据所述目标临时变量,确定目标量子比特,其中,所述目标量子比特的初态为|0>态;A first determination module is used to determine a target quantum bit according to the target temporary variable, wherein the initial state of the target quantum bit is a |0> state;
    第二确定模块,用于基于所述初始量子程序,确定使所述目标量子比特的末态为|0>态的目标量子逻辑门;A second determination module is used to determine a target quantum logic gate that makes the final state of the target quantum bit a |0> state based on the initial quantum program;
    生成模块,用于基于所述初始量子程序和所述目标量子逻辑门,生成目标量子线路。A generation module is used to generate a target quantum circuit based on the initial quantum program and the target quantum logic gate.
  9. 一种存储介质,其特征在于,所述存储介质中存储有计算机程序,其中,所述计算机程序被设置为运行时实现所述权利要求1至7任一项所述的方法。A storage medium, characterized in that a computer program is stored in the storage medium, wherein the computer program is configured to implement the method described in any one of claims 1 to 7 when run.
  10. 一种电子装置,包括存储器和处理器,其特征在于,所述存储器中存储有计算机程序,所述处理器被设置为运行所述计算机程序以实现所述权利要求1至7任一项所述的方法。 An electronic device comprises a memory and a processor, wherein a computer program is stored in the memory, and the processor is configured to run the computer program to implement the method described in any one of claims 1 to 7.
PCT/CN2023/114232 2022-09-30 2023-08-22 Quantum circuit generation method and apparatus, storage medium, and electronic device WO2024066808A1 (en)

Applications Claiming Priority (2)

Application Number Priority Date Filing Date Title
CN202211220055.4 2022-09-30
CN202211220055.4A CN117852659A (en) 2022-09-30 2022-09-30 Quantum circuit generation method and device, storage medium and electronic device

Publications (1)

Publication Number Publication Date
WO2024066808A1 true WO2024066808A1 (en) 2024-04-04

Family

ID=90476021

Family Applications (1)

Application Number Title Priority Date Filing Date
PCT/CN2023/114232 WO2024066808A1 (en) 2022-09-30 2023-08-22 Quantum circuit generation method and apparatus, storage medium, and electronic device

Country Status (2)

Country Link
CN (1) CN117852659A (en)
WO (1) WO2024066808A1 (en)

Citations (9)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN109063844A (en) * 2018-07-13 2018-12-21 合肥本源量子计算科技有限责任公司 A kind of data structure indicating quantum program
CN110825375A (en) * 2019-10-12 2020-02-21 合肥本源量子计算科技有限责任公司 Quantum program conversion method and device, storage medium and electronic device
CN111310928A (en) * 2020-02-28 2020-06-19 东南大学 Implementation method of universal quantum comparison circuit
CN111599414A (en) * 2020-03-25 2020-08-28 清华大学 Quantum computer-based full-quantum molecular simulation method
US20210035008A1 (en) * 2017-09-08 2021-02-04 Google Llc Quantum circuits with reduced t gate count
US20210192114A1 (en) * 2017-10-18 2021-06-24 Google Llc Simulation of quantum circuits
CN113516248A (en) * 2021-07-12 2021-10-19 北京百度网讯科技有限公司 Quantum gate testing method and device and electronic equipment
CN113850389A (en) * 2020-06-28 2021-12-28 合肥本源量子计算科技有限责任公司 Construction method and device of quantum line
CN113988303A (en) * 2021-10-21 2022-01-28 北京量子信息科学研究院 Quantum recommendation method, device and system based on parallel quantum intrinsic solver

Patent Citations (9)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
US20210035008A1 (en) * 2017-09-08 2021-02-04 Google Llc Quantum circuits with reduced t gate count
US20210192114A1 (en) * 2017-10-18 2021-06-24 Google Llc Simulation of quantum circuits
CN109063844A (en) * 2018-07-13 2018-12-21 合肥本源量子计算科技有限责任公司 A kind of data structure indicating quantum program
CN110825375A (en) * 2019-10-12 2020-02-21 合肥本源量子计算科技有限责任公司 Quantum program conversion method and device, storage medium and electronic device
CN111310928A (en) * 2020-02-28 2020-06-19 东南大学 Implementation method of universal quantum comparison circuit
CN111599414A (en) * 2020-03-25 2020-08-28 清华大学 Quantum computer-based full-quantum molecular simulation method
CN113850389A (en) * 2020-06-28 2021-12-28 合肥本源量子计算科技有限责任公司 Construction method and device of quantum line
CN113516248A (en) * 2021-07-12 2021-10-19 北京百度网讯科技有限公司 Quantum gate testing method and device and electronic equipment
CN113988303A (en) * 2021-10-21 2022-01-28 北京量子信息科学研究院 Quantum recommendation method, device and system based on parallel quantum intrinsic solver

Also Published As

Publication number Publication date
CN117852659A (en) 2024-04-09

Similar Documents

Publication Publication Date Title
WO2020151129A1 (en) Quantum machine learning framework construction method and apparatus, and quantum computer and computer storage medium
CN110929873B (en) Quantum program processing method and device, storage medium and electronic device
CN110516810B (en) Quantum program processing method and device, storage medium and electronic device
US20210365253A1 (en) Heterogeneity-agnostic and topology-agnostic data plane programming
CN110889507A (en) Method and device for transferring quantum program into directed acyclic graph, storage medium and electronic device
US20240104417A1 (en) Quantum computing task processing method, system and apparatus, and operating system
WO2022206842A1 (en) Quantum circuit compilation method and device, compilation framework and quantum operating system
CN114358317B (en) Data classification method based on machine learning framework and related equipment
CN115293254A (en) Quantum multilayer perceptron-based classification method and related equipment
CN114912618A (en) Quantum computing task scheduling method and device and quantum computer operating system
WO2024066808A1 (en) Quantum circuit generation method and apparatus, storage medium, and electronic device
CN117291260A (en) Deep learning framework adaptation method, deep learning framework adaptation device, deep learning framework adaptation equipment, deep learning framework adaptation storage medium and deep learning framework adaptation product
CN115829047B (en) Quantum program final mapping determination method and device and quantum computer
CN115879562B (en) Quantum program initial mapping determination method and device and quantum computer
CN114819163B (en) Training method and device for quantum generation countermeasure network, medium and electronic device
WO2023020487A1 (en) Method for mapping quantum program and quantum chip, quantum operating system and computer
CN115983392A (en) Method, device, medium and electronic device for determining quantum program mapping relation
CN116739094A (en) Quantum circuit crosstalk optimization method and device, storage medium and electronic device
CN114511094A (en) Quantum algorithm optimization method and device, storage medium and electronic device
CN114372583B (en) Quantum program optimization method based on machine learning framework and related equipment
CN114970872B (en) Quantum circuit compiling method and device, medium and electronic device
CN116432691A (en) Model training method based on machine learning framework and related equipment
CN116523059A (en) Data processing method, machine learning framework and related equipment
CN115775030A (en) Quantum program rewriting method and device based on pattern matching and electronic device
CN115775028A (en) Quantum line optimization method, quantum line optimization device, quantum line optimization medium, and electronic device

Legal Events

Date Code Title Description
121 Ep: the epo has been informed by wipo that ep was designated in this application

Ref document number: 23870053

Country of ref document: EP

Kind code of ref document: A1