You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
32 lines
721 B
32 lines
721 B
#include<QPanda.h>
|
|
#include<iostream>
|
|
#include<cmath>
|
|
using namespace QPanda;
|
|
|
|
QCircuit QuantumFT(QVec qbits)
|
|
{
|
|
QCircuit cir = QCircuit();
|
|
for (size_t i = 0; i < qbits.size(); i++)
|
|
{
|
|
cir << H(qbits[i]);
|
|
for (size_t j = i + 1; j < qbits.size(); j++)
|
|
{
|
|
cir << CR(qbits[j], qbits[i], 2 * PI / pow(2, j - i + 1));//1<<(j-i+1)
|
|
}
|
|
}
|
|
for (size_t i = 0; i < qbits.size() / 2; i++)
|
|
{
|
|
cir << SWAP(qbits[i], qbits[qbits.size() - i - 1]);
|
|
}
|
|
return cir;
|
|
}
|
|
int main()
|
|
{
|
|
auto qvm = initQuantumMachine(QMachineType::CPU);
|
|
auto q = qvm->qAllocMany(3);
|
|
QCircuit cir = QuantumFT(q);
|
|
//QStat mat = getCircuitMatrix(cir);
|
|
//cout << mat << endl;
|
|
cout << convert_qprog_to_originir(cir,qvm) << endl;
|
|
qvm->finalize();
|
|
} |