QPanda3
0.1.0
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. QPanda3 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 QPanda3 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 QPanda2, we have removed multiple redundant interfaces and used them in a more unified manner
Initialization process simplified.
In the quantum simulator code of QPanda2, 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.
The noise model is used to simulate the noise impact of real environments in quantum circuit computing tasks,In QPanda2, 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 decoupledfugaile,Covering six commonly used noise models
The interface for running simulator and obtaining results has been simplified. Refer to the code below for details.
in qpanda3, first import modules
QPanda3 has optimized the implementation of quantum program translation. It has replaced the cross-language syntax parser Antlr4, used in QPanda2, with a line-by-line scanning method for quantum program translation, resulting in a fivefold improvement in overall execution efficiency.
Furthermore, QPanda3 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 QPanda3 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, QPanda3 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.
When constructing the Hamiltonian, it is no longer necessary to first construct the Pauli operator and then construct the Hamiltonian
The Hamiltonian supports the direct construction of the Hamiltonian using the parameters of the constructed PauliOperator
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, QPanda3 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 QPanda2, 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 QPanda2, different computing interfaces are independent.
In QPanda3, 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 QPanda2, synchronous and asynchronous methods are provided separately. QPanda3 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, QPanda3 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.
Compared to qpanda2, this module is a brand new module
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, QPanda3 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 1 was changed from VQC to VQCircuit to avoid conflicts with the abbreviation of the variational quantum circuit classifier
When constructing Ansatz, the method of adding non-parametric gates and parameter-fixed gates has changed. QPanda3 uses the same functions as QCircuit and QProg to add corresponding quantum logic gates
When constructing Ansztz, the method of adding parameters that require updating quantum logic gates has been changed. QPanda3 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.
The methods for generating specific QCircuit objects vary. The VQCircuit object generates corresponding QCircuit objects in batches by passing in a multidimensional array.
After generating a QCircuit object, the return form of the result is different. QPanda3 uses the VQCResult object to manage the generated QCircuit
Provides a configurable layer mechanism suitable for constructing quantum circuits formed by concatenating quantum circuits with the same structure but possibly different gate parameters
Support the construction of Ansatz with variable parameters or fixed parameters
Support for displaying detailed information of internal Ansatz
Support the use of multidimensional arrays to update gate parameters and generate quantum circuits in bulk
Provide post-processing of the results of generating circuits in batches, including the calculation of the expected value of the results of quantum program execution in quantum systems with Pauli operators or Hamiltonian actions