学习日志31

本源量子计算平台体验

from pyqpanda import *
import numpy as np

# 通过QCloud()创建量子云虚拟机
QCM = QCloud()

# 通过传入当前用户的token来初始化
QCM.init_qvm("304102010030130607299538cd7ed/33683")

qlist = QCM.qAlloc_many(6)
clist = QCM.cAlloc_many(6)

measure_prog = QProg()
measure_prog << hadamard_circuit(qlist)\
             << CZ(qlist[1], qlist[5])\
             << Measure(qlist[0], clist[0])\
             << Measure(qlist[1], clist[1])

pmeasure_prog = QProg()
pmeasure_prog << hadamard_circuit(qlist)\
              << CZ(qlist[1], qlist[5])\
              << RX(qlist[2], np.pi / 4)\
              << RX(qlist[1], np.pi / 4)\

result0 = QCM.full_amplitude_measure(measure_prog, 100)
print(result0)
result1 = QCM.full_amplitude_pmeasure(pmeasure_prog, [0, 1, 2])
print(result1)
result3 = QCM.single_amplitude_pmeasure(pmeasure_prog, "0")
print(result3)
QCM.set_noise_model(NoiseModel.BIT_PHASE_FLIP_OPRATOR, [0.01], [0.02])
result4 = QCM.noise_measure(measure_prog, 100)
print(result4)

使用虚拟量子计算服务进行测试目前情形良好,输出正常,但是测量电路的搭建略显抽象。

from pyqpanda import *

# 通过QCloud()创建量子云虚拟机
qm = QCloud()

# 通过传入当前用户的token来初始化,需要确保当前用户有足够算力资源
qm.init_qvm("302e02010001006072a10400104173015020100410634a5b6d0a2a9a2b03b9d7c17c57405f/13082")

qlist = qm.qAlloc_many(6)
clist = qm.cAlloc_many(6)

# 构建量子程序,可以手动输入,也可以来自OriginIR或QASM语法文件等
prog = QProg()
prog << hadamard_circuit(qlist)\
    << CZ(qlist[1], qlist[5])\
    << Measure(qlist[0], clist[0])\
    << Measure(qlist[1], clist[1])

# 调用真实芯片计算接口,至少需要量子程序和测量次数两个参数
result = qm.real_chip_measure(prog, 1000, real_chip_type.origin_72)
print(result)
qm.finalize()

真实量子计算机演示出现问题,暂时没有使用权限,目前需要将原有代码改造为本源量子计算平台代码。

你可能感兴趣的:(学习,量子计算)