![]() |
QPanda3
Supported by OriginQ
|
In classical computing, the most fundamental unit is the bit, and the most basic control mode is the logic gate. We can achieve our circuit control objectives through the combination of logic gates. Similarly, the way to manipulate quantum bits is through quantum logic gates. pyqpanda3 offers a more concise and lightweight approach to constructing and using quantum logic gates.
Optimize space occupancy
In pyqpanda, quantum logic gates store their own matrix form, which consumes a large amount of memory space for generating ultra large quantum circuits. pyqpanda3, the matrix of quantum circuits is obtained at runtime, effectively reducing memory space occupation
Simplify the construction and initialization process.
In most scenarios, we only need to know the logic gate type and operation bit index to construct quantum logic gates, while in pyqpanda, we need to apply for bits in advance.
In pyqpanda3, The process has been simplified.
Storage and space optimization
Compared with pyqpanda, pyqpanda3 optimizes the information storage of quantum logic gates, reduces memory usage, and can effectively reduce more than 70% of space for the construction of large quantum circuits
pyqpanda has many quantum logic gates that are prone to misleading repetition. In the previous version, we supported the following types of logic gates
pyqpanda3 has completed simplification and optimization
Quantum circuit and program is an important model in the field of quantum computing, used to describe and study the operation process of quantum algorithms and quantum computers. It is a graphical representation method used to demonstrate the operations and interactions between qubits, similar to circuit diagrams in classical computing.
The conversion between quantum programs and originir is more convenient and user-friendly`
In pyqpanda, quantum programs and originir conversions are performed through independent external interfaces
In pyqpanda3, it is directly implemented through the member functions of quantum programs
Example Usage:
In pyqpanda, we use linked lists to store internal quantum operation nodes. In PyQPanda3, we optimized this method by using sequential containers
Characteristics/Scenarios | Quantum Program Sequential Container(std::vector) | Quantum program linked list(std::list, std::forward_list) |
---|---|---|
Memory Layout | Continuous memory allocation improves cache hit rate and access efficiency. | Distributed memory allocation leads to low cache hit rates and slow access speeds. |
Random access efficiency | Support random access of O (1), such as QCircuit[i] | Random access is not supported and needs to be traversed from scratch, with an access complexity of O (n). |
Traverse performance | Supports efficient traversal, with continuous memory allocation resulting in high traversal efficiency and a complexity of O (n). | The traversal efficiency is low, memory allocation is decentralized, and pointer operations increase additional overhead. |
Memory usage | Additional space management capacity is required (such as during dynamic expansion), but the overall memory overhead is relatively small. | Each node requires additional storage of pointers, resulting in high memory overhead. |
Stability (pointer or reference) | The insertion or deletion of elements may cause pointers or references to become invalid (such as ` std::) Vector will reallocate memory. | Element insertion/deletion does not invalidate pointers or references to other elements. |
Overall, quantum programs require traversal and space allocation, so using sequential containers can improve overall system efficiency.
Simulators are used to simulate the evolution process of quantum computing circuits, including quantum systems in perfect states and simulations with noise. In the latest pyqpanda3 version, there are currently six types of virtual machines supported, including full amplitude simulators, single amplitude simulators, density matrix simulators, Clifford circuit simulators, and simulations with noise. Compared to pyqpanda, we have removed multiple redundant interfaces and used them in a more unified manner
Initialization process simplified.
In the quantum simulator code of pyqpanda, the application and release of qubits, the construction of quantum circuits, and the binding of the virtual machine are integrated together. For example:
In pyqpanda3, complete decoupling has been achieved, and the explicit init configuration has been removed.
In the above pyqpanda code, the globally used virtual machine and its initialization method have been deprecated.
The noise model is used to simulate the noise impact of real environments in quantum circuit computing tasks,In pyqpanda, setting noise parameters required a complex noise model, and the noise model and noise errors are not decoupled.
In pyqpanda3, noise errors and noise models are decoupled.
pyqpanda3 has optimized the implementation of quantum program translation. It has replaced the cross-language syntax parser Antlr4, used in pyqpanda, with a line-by-line scanning method for quantum program translation, resulting in a fivefold improvement in overall execution efficiency.
Furthermore, pyqpanda3 supports the parsing of comments in quantum programs.
The intermediate compiler module provides an interface that supports converting an instruction set string in the OriginIR format into a quantum program (QProg).
The intermediate compiler module provides an interface that supports converting a text file containing OriginIR instruction set string into a quantum program (QProg).
The intermediate compiler module provides an interface that supports converting an instruction set string in OpenQASM format into a quantum program (QProg).
The intermediate compiler module provides an interface that supports converting a text file containing OpenQASM instruction set string into a quantum program (QProg).
The intermediate compiler module provides an interface that supports converting a quantum program (QProg) into an instruction set string in the OriginIR format.
As can be seen, in the pyqpanda3 translation QProg interface definition, the parameter list eliminates the QuantumMachine type parameter used for conversion in the old version, and instead only uses the instruction set string or quantum program file path string as parameters to be converted. Additionally, the return value is no longer a list containing the QProg object, quantum bits, and classical bits, but is now solely the QProg object.
As of the latest version, pyqpanda3 supports the use of qpanda2-style and qiskit-style parameter forms or PauliOperator objects to directly construct objects of the Hamiltonian class. Objects of the Hamiltonian class support addition, subtraction, scalar multiplication, multiplication, and tensor products, as well as mixed operations. They also support displaying the main information of the object by omitting the "I" or omitting the string of qubit indexes.
The Hamiltonian supports the direct construction of the Hamiltonian using the parameters of the constructed PauliOperator. When constructing the Hamiltonian, it is no longer necessary to first construct the Pauli operator and then construct the Hamiltonian
The Hamiltonian supports mixed operations of addition, subtraction, scalar multiplication, multiplication, and tensor product
The Hamiltonian supports printing the corresponding string in the omitting "I" mode
Output
The Hamiltonian supports printing the corresponding string by omitting qbit index
Output
As of the latest version, pyqpanda3 supports the direct construction of PauliOperator objects using qpanda2-style and qiskit-style parameter forms. Objects of the PauliOperator class support addition, subtraction, scalar multiplication, multiplication, and tensor products, as well as mixed operations. They also support displaying the main information of the object by omitting the "I" or omitting the string of qubit indexes.
Use the PauliOperator class to provide unified simulation of the first mock examination for basic Pauli operators and Pauli operator combinations
PauliOperator support qsikit-style construction methods
PauliOperator support tensor product operations
PauliOperator support scalar multiplication
PauliOperator supports mixed operations of addition, subtraction, scalar multiplication, multiplication, and tensor product
PauliOperator supports printing the corresponding string by omitting "I"
PauliOperator supports printing corresponding strings by omitting qbit indexes
Output
The profiling module is designed to intuitively present information about quantum programs. It analyzes quantum programs using two methods and displays the results through visualizations for users.
draw_circuit_profile
: This function analyzes quantum programs, outputting the execution time of the quantum program and its subroutine, as well as the calling relationships between various quantum gates. Its inputs include the quantum circuit, names of quantum gates, and their execution times on hardware, with the output being a flowchart of the calling relationships between the quantum gates.draw_circuit_features
: This function visualizes the features of a quantum circuit by generating a radar chart. It computes several metrics related to the circuit's structure and behavior, including connectivity, liveness, parallelism, entanglement, and critical depth, The meaning of specific features can be found in reference [1].In complex quantum circuit simulations, it is necessary to rely on high-performance computer clusters or real quantum computers to replace local computing with cloud computing, which to some extent reduces users' computing costs and provides a better computing experience. The Origin Quantum Cloud Platform submits tasks to quantum computers or computing clusters deployed remotely through the Origin South Service, and queries the processing results,
Origin Quantum Cloud Service Initialization process simplified.
In the quantum cloud service code of pyqpanda, the application and release of qubits, the construction of quantum circuits, and the binding of the virtual machine are integrated together.
For example, This is the usage method of pyqpanda, and the process is quite complicated
In pyqpanda3, complete decoupling has been achieved, and the explicit init configuration has been removed.
In pyqpanda, different computing interfaces are independent.
In pyqpanda3, a unified approach is implemented using overloaded run functions.
At present, we support submission and query methods for cluster tasks such as full amplitude simulation, single amplitude simulation, partial amplitude simulation, and noisy simulation, as well as single and batch task submission and query for real quantum computing chip devices.
In pyqpanda, synchronous and asynchronous methods are provided separately. pyqpanda3 simplifies this process.
Synchronous Process, job.result() will continuously loop through the task results until the task calculation is completed or there is an error
Asynchronous method as above, Job.status() will query the current task status and return the query result
As of the latest version, pyqpanda3 supports the use of StateVector and DensityMatrix to represent two basic quantum state representations, namely state vector and density matrix. It supports the use of five forms of describing quantum channels, including Kraus, Choi, Chi, SuperOp, and PTM, as well as the conversion between these five representations. In addition, it also provides information analysis tools such as Hellinger distance, Hellinger fidelity, and KL divergence, as well as a dedicated class for obtaining the unitary matrix of the quantum circuit QCircuit, and a Matrix class that can obtain the transpose matrix, adjoint matrix, and L2 norm.
Abstract and simulate quantum states, including state vectors and density matrices, and support the application of quantum circuits for evolution operations on quantum systems represented by state vectors and density matrices
The abstraction and simulation of the representation methods Kraus, Choi, PTM, SuperOp, and Chi in quantum channel 5 support the pairwise conversion between these representation methods, and support the use of these quantum channels for evolving quantum states
Information analysis tools, including the calculation of Hellinger distance, Hellinger fidelity, and KL divergence between discrete probability distributions, including KL divergence between discrete probability distributions and KL divergence between continuous probability distributions
Others, including a matrix class and a class for obtaining the unitary matrix of the quantum circuit QCircuit object
This module provides functionalities for compiling quantum circuits, enhancing optimization and mapping to specific hardware topologies.
Transpiler
class has been added, which compiles circuits using the transpile()
interface. This interface has four parameters: QProg
, chip_topology_edges
, init_mapping
, and optimization_level
. The QProg
parameter is the quantum circuit to be compiled, chip_topology_edges
is the target topology for compilation, init_mapping
is the mapping of virtual qubits to physical qubits, and optimization_level
can be set to 0, 1 or 2:0
: No optimization is performed.1
: Basic optimizations are applied, including simple two-qubit gate cancellation and single-qubit gate merging.2
: Advanced optimizations are performed, including matrix optimization, two-qubit gate cancellation, and single-qubit gate merging.X1
, RZ
, CZ
]Example Usage:
As of the latest version, pyqpanda3 uses VQCircuit to support variational quantum circuits. Provide placeholder support for setting variable parameters for logic gates in Ansatz using multidimensional arrays, support for generating QCircuit in batches based on multidimensional arrays, and support for calculating the expected values of Hamiltonians/Pauli operators for the generated QCircuit. In addition, VQCircuit also supports enabling the layer mechanism to better generate QCircuits composed of multiple quantum circuits with the same structure connected in series.
The name of Class was changed from VQC to VQCircuit to avoid conflicts with the abbreviation of the variational quantum circuit classifier. Code example
When constructing Ansatz, the method of adding non-parametric gates and parameter-fixed gates has changed. pyqpanda3 uses the same functions as QCircuit and QProg to add corresponding quantum logic gates. Code example
When constructing Ansatz, the method of adding parameters that require updating quantum logic gates has been changed. pyqpanda3 uses the functions with same names as those which are for generate QCircuit or QProg. These functions can specify which gate parameters of a certain type with parameters need to be updated. Code example
The methods for generating specific QCircuit objects vary. The VQCircuit object generates corresponding QCircuit objects in batches by passing in a multidimensional array. Code example
After generating a QCircuit object, the return form of the result is different. pyqpanda3 uses the VQCResult object to manage the generated QCircuit Code example
Using VQCircuit as the class name can avoid ambiguity between the abbreviations for "Variational Quantum Circuit" and "Variational Quantum Classifier" when referring to VQC.
Using unified functions' names to add quantum logic gates. When constructing Ansatz, the method of adding non-parametric gates and parameter-fixed gates has changed. pyqpanda3 uses the same functions as QCircuit and QProg to add corresponding quantum logic gates
If you want to direct run this example code to try this function. The easiest way is to copy all the code blocks from The first code example to this code into a python script file.
It provides a placeholder mechanism that can be used to add quantum logic gates with variable parameters when constructing the Ansatz of a variational quantum circuit. When constructing Ansatz, the method of adding parameters that require updating quantum logic gates has been changed. pyqpanda3 uses the functions with same names as those which are for generate QCircuit or QProg. These functions can specify which gate parameters of a certain type with parameters need to be updated.
If you want to direct run this example code to try this function. The easiest way is to copy all the code blocks from The first code example to this code into a python script file.
Run the program composed of the sequence introduced in the documentation, from code block The first code example to this code block. The output corresponding to this code block is as follows:
It provides a practical interface that can be used to print information related to the Ansatz.
If you want to direct run this example code to try this function. The easiest way is to copy all the code blocks from The first code example to this code into a python script file.
Run the program composed of the sequence introduced in the documentation, from code block The first code example to this code block. The output corresponding to this code block is as follows:
VQCircuit supports using multi-dimensional arrays to store parameters for batch generating QCircuit objects. The following code is used to prepare a multi-dimensional array data, which will be used in the subsequent example code for batch generating QCircuit objects.
If you want to direct run this example code to try this function. The easiest way is to copy all the code blocks from The first code example to this code into a python script file.
VQCircuit object support disable hierarchical mechanism.
If you want to direct run this example code to try this function. The easiest way is to copy all the code blocks from The first code example to this code into a python script file.
In pyqpanda3, it is so easy to use multi-dimensional arrays to store parameters for batch generating QCircuit objects.
If you want to direct run this example code to try this function. The easiest way is to copy all the code blocks from The first code example to this code into a python script file.
Using VQResult to manage the result of generating QCircuit object by VQCircuit object. This allows users to access each QCircuit object using multi-dimensional array indexing.
If you want to direct run this example code to try this function. The easiest way is to copy all the code blocks from The first code example to this code into a python script file.
If you wish to construct a QCircuit that is composed of substructures (subcircuits) concatenated together, enabling the layer mechanism within VQCircuit will make it more convenient for users to batch construct QCircuit objects using parameters stored in a multi-dimensional array.
If you want to direct run this example code to try this function. The easiest way is to copy all the code blocks from The first code example to this code into a python script file.
The VQResult object provides useful post-processing functionalities for the VQCircuit object. If you only want to obtain the expectation value of the Hamiltonian corresponding to a specific QCircuit in res, the following code is appropriate.
Please to watch Hamiltonian to learn more information about pyqpanda3.hamiltonian.Hamiltonian
If you want to direct run this example code to try this function. The easiest way is to copy all the code blocks from The first code example to this code into a python script file.
Run the program composed of the sequence introduced in the documentation, from code block The first code example to this code block. The output corresponding to this code block is as follows:
If you want to obtain all the expectation values of the Hamiltonian for all QCircuit objects in res in batch, the following code can effectively achieve this goal.
Please to watch Hamiltonian to learn more information about pyqpanda3.hamiltonian.Hamiltonian
If you want to direct run this example code to try this function. The easiest way is to copy all the code blocks from The first code example to this code into a python script file.
Run the program composed of the sequence introduced in the documentation, from code block The first code example to this code block. The output corresponding to this code block is as follows:
If you only want to obtain the expectation value of the PauliOperator corresponding to a specific QCircuit in res, the following code is appropriate.
Please to watch PauliOperator to learn more information about pyqpanda3.hamiltonian.PauliOperator
If you want to direct run this example code to try this function. The easiest way is to copy all the code blocks from The first code example to this code into a python script file.
Run the program composed of the sequence introduced in the documentation, from code block The first code example to this code block. The output corresponding to this code block is as follows:
If you want to obtain all the expectation values of the PauliOperator for all QCircuit objects in res in batch, the following code can effectively achieve this goal.
Please to watch PauliOperator to learn more information about pyqpanda3.hamiltonian.PauliOperator
If you want to direct run this example code to try this function. The easiest way is to copy all the code blocks from The first code example to this code into a python script file.
Run the program composed of the sequence introduced in the documentation, from code block The first code example to this code block. The output corresponding to this code block is as follows: