量子比特和通常的数字形式的门直接来自维基百科
pyqbit的Python项目详细描述
皮卡比特 量子比特和通常的数字形式的门直接来自维基百科。 ##应用 将门应用于状态
例如,此链的计算结果为零:
>>> from functools import reduce >>> s = reduce( apply, [Zero(), H(), PauliZ(), H(), PauliX()]) >>> Measure.one(s) 0
交换一下位置
>>> one = Combine(Zero(), One()) >>> Measure.one(one) 1 >>> one array([[0], [1], [0], [0]]) >>> two = apply(one, SWAP()) >>> Measure.one(two) 2 >>> two array([[0], [0], [1], [0]])
量子比特定义
零 每次计算为零的量子位
>>> Zero |0> >>> Zero() array([[1], [0]]) >>> Measure.one(Zero()) 0
一个 每次计算为1的量子位
>>> One |1> >>> One() array([[0], [1]]) >>> Measure.one(One()) 1
加上 平均计算为1和0的量子位
>>> Plus |+> >>> Plus() array([[0.70710678], [0.70710678]])
减 平均计算为1和0的量子位
>>> Minus |-> >>> Minus() array([[ 0.70710678], [-0.70710678]])
测量 模拟量子位的测量过程
>>> Measure.one(One()) 1
联合收割机 使用两个数组的Kronecker积来组合量子比特。在
>>> Combine(Zero(),Zero()) array([[1], [0], [0], [0]])>>> from functools import reduce >>> reduce(Combine, [One(), Zero(), Zero()]) array([[0], [0], [0], [0], [1], [0], [0], [0]])
每一行表示作为结果获得其索引值的概率
>>> Measure.one(Combine(Zero(),Zero())) 0>>> Measure.one( Combine(One(), Combine(Zero(),Zero())) ) 4
相等 如果两个量子位状态相同,则相等是一个测试
>>> equal(One(), One()) True >>> equal(One(), Zero()) False
量子门
身份 身份门
>>> Identity Identity >>> Identity() array([[1, 0], [0, 1]])
################H 哈达玛门
>>> H H >>> H() array([[ 0.70710678, 0.70710678], [ 0.70710678, -0.70710678]])
泡利克斯 保利X门
>>> PauliX X >>> PauliX() array([[0, 1], [1, 0]])
保利 保利Y门
>>> PauliY Y >>> PauliY() array([[ 0.+0.j, -0.-1.j], [ 0.+1.j, 0.+0.j]])
泡利兹 保利Z门
>>> PauliZ Z >>> PauliZ() array([[ 1, 0], [ 0, -1]])
相位 相位(S,P)门
>>> Phase P >>> Phase() array([[1.+0.j, 0.+0.j], [0.+0.j, 0.+1.j]])
################R R是自定义相移门
>>> from math import pi >>> R(pi/4) R(0.7853981633974483) >>> R(pi/4)() array([[1. +0.j , 0. +0.j ], [0. +0.j , 0.70710678+0.70710678j]])
####不 CNOT是受控非门(CX)
>>> CNOT CX >>> CNOT() array([[1, 0, 0, 0], [0, 1, 0, 0], [0, 0, 0, 1], [0, 0, 1, 0]])
卡普利兹 CPauliZ是受控的pauliz门(CZ)
>>> CPauliZ CZ >>> CPauliZ() array([[ 1, 0, 0, 0], [ 0, 1, 0, 0], [ 0, 0, 1, 0], [ 0, 0, 0, -1]])
交换 交换是qbit交换门
>>> SWAP SWAP >>> SWAP() array([[1, 0, 0, 0], [0, 0, 1, 0], [0, 1, 0, 0], [0, 0, 0, 1]])
保利集团
####P1 P1是第一个由 [-1,1,-1j,1j]和[Identity(),PauliX(),pauly(),PauliZ()]
>>> P1 P1 >>> p1 = list(P1()) >>> len(p1) 16 >>> equal(p1[0], -1*Identity()) True >>> equal(p1[1], 1*Identity()) True >>> equal(p1[2], -1j*Identity()) True >>> equal(p1[3], 1j*Identity()) True >>> equal(p1[15], 1j*PauliZ()) True
p1是一个组,因此适用于:
关联性:
>>> all([ any([equal(apply(a,b), c) for c in P1()]) for a in P1() for b in P1()]) True
身份:
>>> equal( Identity(), p1[1]) True>>> all([ equal(apply(a, Identity()), a) for a in P1()]) True
反向元素:
>>> all([ any([equal(apply(a, b), Identity()) for b in P1()]) for a in P1() ]) True
- 项目
标签: