QPanda3  0.1.0
Supported by OriginQ
Loading...
Searching...
No Matches
Quantum Program

Prev Tutorial: Quantum Circuit
Next Tutorial: Quantum Circuit and Quantum Program


QProg

Quantum programming is used for writing and constructing quantum programs, generally understood as a sequence of operations. Due to the fact that classical computing is also included in quantum algorithms, the industry envisions that the quantum computers that will emerge in the near future will be hybrid structures, consisting of two main parts, one of which is a classical computer responsible for performing classical computing and control; The other part is quantum devices, responsible for performing quantum computing. QPanda3 regards the programming process of quantum programs as a part of classical program execution, and the entire peripheral host program must include the part that creates quantum programs.

Constructors

You can create a QProg instance using several constructors:

  1. Default Constructor
  2. Constructor with Qubits Number
  3. Copy Constructor
  4. Constructor with a Circuit

Member Functions

The following functions can be used to manipulate and query the QProg instance:

  • Append Operations

    You can append gates, circuits, or measurements:

  • Operator Overloading

    You can use the << operator to append nodes:

  • Querying Properties

    Using the qubits_num and cbits_num function to get the number of qubits and classical bits:

  • Get Qubits and Classical Bits

    Using the qubits and cbits function to retrieve the lists of qubits and classical bits:

  • Operations

    Using the operations function to retrieve the operations:

  • Gate Operations

    Using the gate_operations function to get the list of gate operations,The meaning of the parameter is to only obtain two qubit gates:

  • Count Operations

    Using the count_ops function to count the operations in the program,The meaning of the parameter is to only count two qubit gates:

  • Depth of the Program

    Using the depth function to get the depth of the program,The meaning of the parameter is to only count two qubit gates:

  • Flatten and Convert to Circuit

    Using the flatten and to_circuit function to flatten the program or convert it to a circuit:

  • Clearing the Program

    Using the clear function to clear all operations from the program:

Example Usage

Here’s a simple example of how to create a quantum program, run quantum program and measure results:

Run result: