QPanda3
0.1.0
Supported by OriginQ
|
Prev Tutorial: Quantum Circuit and Quantum Program
Next Tutorial: Quantum Program
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.
You can initialize a QCircuit in three different ways:
Default Constructor:
With a Specified Number of Qubits:
Copy Constructor:
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.
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:
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 Qubits:
Using the control and clear_controlfunction to set and clear control qubits:
Set and Get Circuit Name:
Using the set_name and namefunction to set and get circuit's name:
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.:
Here is a simple example demonstrating the creation of a QCircuit
, appending operations, and retrieving properties:
Run result: