学习日志32

  • 本源量子计算平台使用
bash 复制代码
from numpy import pi
from pyqpanda import *
from pyqpanda.Visualization import circuit_draw

machine = CPUQVM()
machine.init_qvm()

qlist = machine.qAlloc_many(4)
clist = machine.cAlloc_many(4)

measure_prog = QProg()
measure_prog << hadamard_circuit(qlist) \
<< CZ(qlist[1], qlist[2]) \
<< RX(qlist[2], pi / 4) \
<< RX(qlist[1], pi / 4) \
<< CNOT(qlist[0], qlist[2]) \
<< Measure(qlist[0], clist[0])

print(measure_prog)

创建量子线路及其可视化

bash 复制代码
         ┌─┐                             ┌─┐ 
q_0:  |0>─┤H├ ──── ────────────── ───■── ─┤M├ 
          ├─┤      ┌────────────┐    │    └╥┘ 
q_1:  |0>─┤H├ ──■─ ┤RX(0.785398)├ ───┼── ──╫─ 
          ├─┤ ┌─┴┐ ├────────────┤ ┌──┴─┐   ║  
q_2:  |0>─┤H├ ┤CZ├ ┤RX(0.785398)├ ┤CNOT├ ──╫─ 
          ├─┤ └──┘ └────────────┘ └────┘   ║  
q_3:  |0>─┤H├ ──── ────────────── ────── ──╫─ 
          └─┘                              ║  
 c :   / ══════════════════════════════════╩═
                                            0

打印量子态的分布代码

bash 复制代码
from pyqpanda import *
import numpy as np

machine = CPUQVM()
machine.set_configure(50, 50)
machine.init_qvm()
q = machine.qAlloc_many(4)
c = machine.cAlloc_many(4)
prog = QProg()
prog.insert(X(q[1]))\
    .insert(T(q[0]))\
    .insert(RX(q[1], np.pi/2))\
    .insert(RZ(q[0], np.pi/4))
machine.directly_run(prog)
result = machine.get_qstate()
plot_state_city(result)
machine.finalize()

概率分布代码

bash 复制代码
from pyqpanda import *

machine = CPUQVM()
machine.init_qvm()
qubits = machine.qAlloc_many(3)

prog = QProg()
prog << Z(qubits[0])\
    << X1(qubits[1])\
    << H(qubits[:2])

machine.directly_run(prog)
result_dict = machine.prob_run_dict(prog, qubits, -1)
draw_probability_dict(result_dict)
machine.finalize()
相关推荐
技术小齐16 分钟前
网络运维学习笔记 022 HCIA-Datacom新增知识点03园区网典型组网架构及案例实战
运维·网络·学习
hxung2 小时前
MySQL面试学习
学习·mysql·面试
weixin_502539852 小时前
rust学习笔记5-所有权机制
笔记·学习·rust
PyAIGCMaster2 小时前
50周学习go语言:第四周 函数与错误处理深度解析
开发语言·学习·golang
~kiss~2 小时前
Rust学习~tokio简介
开发语言·学习·rust
StickToForever7 小时前
第4章 信息系统架构(五)
经验分享·笔记·学习·职场和发展
leegong2311110 小时前
学习PostgreSQL专家认证
数据库·学习·postgresql
Moonnnn.11 小时前
51单片机学习——动态数码管显示
笔记·嵌入式硬件·学习·51单片机
南宫生12 小时前
力扣每日一题【算法学习day.132】
java·学习·算法·leetcode
技术小齐12 小时前
网络运维学习笔记 016网工初级(HCIA-Datacom与CCNA-EI)PPP点对点协议和PPPoE以太网上的点对点协议(此处只讲华为)
运维·网络·学习