Python量子計算qiskit
阿新 • • 發佈:2021-02-01
IBM推出的qiskit是非常棒的Python量子模擬器
# coding=utf-8 import math from qiskit import QuantumRegister, ClassicalRegister, QuantumCircuit # 忽略告警 import warnings warnings.filterwarnings('ignore') # 定義量子傅立葉變換函式qft def qft(circ, q, n): """n-qubit QFT on q in circ.""" for j in range(n): for k in range(j): # 套用傅立葉就換 circ.cu1(math.pi / float(2 ** (j - k)), q[j], q[k]) circ.h(q[j]) # 量子位元數量 n = 3 q = QuantumRegister(n) c = ClassicalRegister(n) # 定義量子電路,後面可以視覺化 qft_n = QuantumCircuit(q, c) qft(qft_n, q, n) for i in range(n): qft_n.measure(q[i], c[i]) print(qft_n.qasm()) # 視覺化 from qiskit.tools.visualization import circuit_drawer # 視覺化 circuit_drawer(qft_n, filename='./qft_circuit')
qft_circuit 用sublime開啟