学习日志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()
相关推荐
kunge1v51 小时前
学习爬虫第三天:数据提取
前端·爬虫·python·学习
冬夜戏雪1 小时前
[学习日记][springboot 1-7][leetcode 6道]
java·开发语言·学习
趣味编程1111 小时前
go的学习2---》并发编程
学习·golang·perl
zzzsde2 小时前
【Linux】linux基础指令入门(1)
linux·运维·学习
_hermit:2 小时前
【从零开始java学习|第二十二篇】集合进阶之collection
java·学习
_dindong2 小时前
基础算法:滑动窗口
数据结构·学习·算法·leetcode·力扣
今天只学一颗糖3 小时前
Linux学习笔记--查询_唤醒方式读取输入数据
笔记·学习
GIS学姐嘉欣4 小时前
【智慧城市】2025年中国地质大学(武汉)暑期实训优秀作品(5):智慧矿产
学习·gis·智慧城市·webgis
折翼的恶魔4 小时前
前端学习之样式设计
前端·css·学习
光影少年11 小时前
angular生态及学习路线
前端·学习·angular.js