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

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


QCircuit

Quantum circuits, also known as quantum logic circuits, are the most commonly used general quantum computing models. They represent circuits that operate on quantum bits in abstract concepts and are a collection of various logic gates. Finally, quantum measurements are often required to read out the results. Unlike traditional circuits that use metal wires to transmit voltage or current signals, in quantum circuits, the wires are connected by time, meaning that the state of quantum bits naturally evolves over time, following the instructions of the Hamiltonian operator, until they encounter a logic gate and are operated upon. Since each quantum logic gate that makes up a quantum circuit is a 'unitary matrix', the entire quantum circuit is also a large unitary matrix.

Class Initialization

You can initialize a QCircuit in three different ways:

  1. Default Constructor:

  2. With a Specified Number of Qubits:

  3. Copy Constructor:

Basic Methods

  • Get the Size of the Circuit:

    Using the size function to get circuit size. Example:

  • Append Operations:

    You can append both gates and other circuits using the append method or the << operator.

Circuit Management

  • Clear the Circuit:

    Using the clear function to clear circuit. Example:

  • Get Qubits:

    Using the qubits function to retrieve qubits involved in the circuit: Example:

  • Target and Control Qubits:

    Using the target_qubits function to get target qubits. Using the control_qubits function to get control qubits. Example:

Circuit Properties

  • Check if the Circuit is a Dagger:

    Using the is_dagger function to check if the Circuit is a Dagger.

  • Set Dagger Property:

    Using the dagger function to set circuit dagger. If the current circuit is dagger, the dagger will be cancelled.Example:

Control Operations

  • Control Qubits:

    Using the control and clear_controlfunction to set and clear control qubits:

Circuit Name

  • Set and Get Circuit Name:

    Using the set_name and namefunction to set and get circuit's name:

Operations and Layers

  • List Operations:

    Using the operations function to get circuit's operations:

  • Count Operations:

    Using the count_ops function to count the number of gates in the circuit:

  • Get Circuit Depth:

    Using the depth function to get circuit's depth:

  • Expand Circuit:

    Using the expand function to get a copy of the expanded circuit.:

Example Usage

Here is a simple example demonstrating the creation of a QCircuit, appending operations, and retrieving properties:

Run result:

Circuit Size: 2
Qubits: [0, 1]
Operations: {'CNOT': 1, 'H': 1}
Circuit Depth: 2