# 作业一：量子态的Bloch表示

AI悦创原创量子态量子计算Python量子计算Python一对一辅导Python一对一教学量子态量子计算Python量子计算Python一对一辅导Python一对一教学大约 3 分钟...约 852 字

## 作业一：量子态的 Bloch 表示

###### -- QUANTA -- #######
# Author: Y. Liu, W. Shi  #
# Data: 2022-09-17        #
###########################
from qutip import *
from scipy.linalg import *
from mpl_toolkits.mplot3d import Axes3D
import numpy as np
import matplotlib.pyplot as plt


## 第一步：量子态的 Bloch 球表示

def getCoordFromPsi(psi):
coord = np.array([0.0000, 0.0000, 1.0000], dtype = float)
#######################################
#todo: complete this function.

#######################################
return coord

def getPsiFromCoord(coord):
psi = np.array([0.0000 + 0.0000j, 1.0000 + 0.0000j], dtype = complex)
#######################################
#todo: complete this function.

#######################################
return psi


## 测试部分

#don't modify the code in this block
n_ck = 10
psi_ck = np.array( [[ -0.4557 + 0.8558j,  0.1531 + 0.1913j],
[  0.0459 + 0.0052j,  0.8862 - 0.4611j],
[ -0.0598 + 0.0307j, -0.9459 - 0.3176j],
[ -0.7077 + 0.1489j, -0.5046 + 0.4716j],
[ -0.1643 + 0.2612j,  0.9362 - 0.1681j],
[ -0.7062 + 0.6726j, -0.2186 + 0.0326j],
[ -0.5454 + 0.5694j, -0.3613 - 0.4978j],
[  0.0438 + 0.1245j, -0.0436 - 0.9903j],
[  0.0000 + 0.0000j,  1.0000 + 0.0000j],
[  0.0546 + 0.0326j,  0.9482 + 0.3113j]], dtype = complex)
coord_ck = np.array([[ 0.1880, -0.4364,  0.8799],
[ 0.0766, -0.0515, -0.9957],
[ 0.0937,  0.0960, -0.9910],
[ 0.8546, -0.5173,  0.0459],
[-0.3955, -0.4339, -0.8095],
[ 0.3527,  0.2480,  0.9023],
[-0.1728,  0.9544,  0.2433],
[-0.2504, -0.0760, -0.9652],
[ 0.0000,  0.0000, -1.0000],
[ 0.1238, -0.0278, -0.9919]], dtype = float)

def checkCoord2Psi():
print('Checking converting coordinate to state vector...')
err = [abs(np.matrix(getPsiFromCoord(coord_ck[c])) * np.matrix(psi_ck[c]).H)[0,0] - 1 for c in range(n_ck)]
if np.sum(err) < 0.01:
print('Pass!')
else:

def checkPsi2Coord():
print('Checking converting state vector to coordinate...')
err = [np.sum(abs(getCoordFromPsi(psi_ck[c]) - coord_ck[c])) for c in range(n_ck)]
if np.sum(err) < 0.05:
print('Pass!')
else:

checkCoord2Psi()
checkPsi2Coord()


## 第二步：Bloch 球的绘制

psi_to_add = np.array([[ 1.0000 + 0.0000j,  0.0000 + 0.0000j],
[ 0.7071 + 0.0000j,  0.5000 + 0.5000j],
[ 0.0000 + 0.0000j,  0.0000 + 1.0000j],
[-0.7071 + 0.0000j, -0.5000 + 0.5000j],
[-1.0000 + 0.0000j, -0.0000 + 0.0000j]])

fig = plt.figure(figsize=(6,6))
sphere = Bloch(axes = axes)

#example:
psi = np.array([1.0000, 0.0000])
coord = getCoordFromPsi(psi)

######################
#todo:
#converting the 5 states in psi_to_add into coordinates, and ploting them onto the Bloch sphere

######################
sphere.make_sphere()

#when using CMD to run this script, the Bloch sphere can be shown in an independent view by the following code.
#fig.show()


AI悦创·编程一对一

AI悦创·推出辅导班啦，包括「Python 语言辅导班、C++ 辅导班、java 辅导班、算法/数据结构辅导班、少儿编程、pygame 游戏开发、Web、Linux」，全部都是一对一教学：一对一辅导 + 一对一答疑 + 布置作业 + 项目实践等。当然，还有线下线上摄影课程、Photoshop、Premiere 一对一教学、QQ、微信在线，随时响应！微信：Jiabcdefh

C++ 信息奥赛题解，长期更新！长期招收一对一中小学信息奥赛集训，莆田、厦门地区有机会线下上门，其他地区线上。微信：Jiabcdefh

• 0
• 0
• 0
• 0
• 0
• 0

• 按正序
• 按倒序
• 按热度