學習和使用QPanda(二)

量子程序轉換爲Quil指令集

上一篇QPanda2組成和簡單的使用,下面利用QPanda2的組件將一個量子程序轉換爲Quil指令集。

具體編程如下:

#include <QPanda.h>
USING_QPANDA


int main(void)
{
    init();
    auto qubits = qAllocMany(4);
    auto cbits = cAllocMany(4);
    QProg prog;

    prog << H(qubits[0]) << RX(qubits[1], PI/6)
         << CNOT(qubits[1], qubits[2])
         << CNOT(qubits[2], qubits[3])
         << Measure(qubits[0], cbits[0]);

    auto quil = qProgToQuil(prog); // 量子程序轉換爲Quil指令集
    std::cout << quil << std::endl;

    return 0;
}

運行結果

 

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章