Skip to content

Commit db7e4b9

Browse files
add cphase gate
1 parent 98f2087 commit db7e4b9

File tree

5 files changed

+23
-3
lines changed

5 files changed

+23
-3
lines changed

CHANGELOG.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010

1111
- Add alias for `sd` and `td` gate
1212

13-
- Add `phase` gate for the circuit
13+
- Add `phase` gate and `cphase` gate for the circuit
1414

1515
- Add U gate and CU gate following OpenQASM 3.0 convention
1616

docs/source/textbook/chap2.ipynb

+1-1
Original file line numberDiff line numberDiff line change
@@ -375,7 +375,7 @@
375375
"$$|{\\rm GHZ}\\rangle = \\frac{1}{\\sqrt{2}}(|000\\rangle + |111\\rangle)\n",
376376
"=(1/\\sqrt{2} , 0 , 0 , 0 , 0 , 0 , 0 , 1/\\sqrt{2})^T。$$\n",
377377
"\n",
378-
"  事实上,与直觉相反,纠缠态无处不在,而可分离态却非常少。纠缠态的性质较为复杂,遗憾的是,对多量子比特系统,哪怕是在$n=2$的情形下,我们也没有像单个量子比特那样清晰的几何图像帮助我们理解。我们在下一节也会看到,一些特殊的纠缠态正是量子算法可以加速完成计算任务的关键。值得注意的是,多量子比特的纠缠态是非常复杂的。**当多个量子比特纠缠在一起时,单个量子比特的量子态信息会在某种意义上变得不确定**,所以我们有时需要消除不需要的纠缠。\n",
378+
"  事实上,与直觉相反,纠缠态无处不在,而可分离态却非常少。纠缠态的性质较为复杂,遗憾的是,对多量子比特系统,哪怕是在 $n=2$ 的情形下,我们也没有像单个量子比特那样清晰的几何图像帮助我们理解。我们在下一节也会看到,一些特殊的纠缠态正是量子算法可以加速完成计算任务的关键。值得注意的是,多量子比特的纠缠态是非常复杂的。**当多个量子比特纠缠在一起时,单个量子比特的量子态信息会在某种意义上变得不确定**,所以我们有时需要消除不需要的纠缠。\n",
379379
"\n",
380380
"\n",
381381
"* > 例子:对纠缠态的测量。如果我们对$|\\Phi_+\\rangle$第一个量子比特进行$Z$的测量。那么我们有$P_0 = |0_0\\rangle\\langle0_0|, P_1 = |1_0\\rangle\\langle 1_0|$, 和$p_0 = 1/2$, $p_1=1/2$。在测量结束后,我们以概率$1/2$得到$0$和$1$,两比特系统相应的最终态为$|00\\rangle$ 和 $|11\\rangle$,量子纠缠不再存在。这里我们注意到,当测量第一个量子比特得到结果0时,第二个量子比特也必须同时塌缩到$|0\\rangle$态。 "

tensorcircuit/abstractcircuit.py

+1
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,7 @@
3939
"rxx",
4040
"ryy",
4141
"rzz",
42+
"cphase",
4243
"crx",
4344
"cry",
4445
"crz",

tensorcircuit/gates.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -963,7 +963,7 @@ def meta_vgate() -> None:
963963
]:
964964
for funcname in [f, f + "gate", f + "_gate"]:
965965
setattr(thismodule, funcname, GateVF(getattr(thismodule, f + "_gate"), f))
966-
for f in ["cu", "crx", "cry", "crz"]:
966+
for f in ["cu", "crx", "cry", "crz", "cphase"]:
967967
for funcname in [f, f + "gate", f + "_gate"]:
968968
setattr(thismodule, funcname, getattr(thismodule, f[1:]).controlled())
969969
for f in ["ox", "oy", "oz", "orx", "ory", "orz"]:

tests/test_gates.py

+19
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,25 @@ def test_ided_gate():
5858
)
5959

6060

61+
def test_fsim_gate():
62+
theta = 0.2
63+
phi = 0.3
64+
c = tc.Circuit(2)
65+
c.iswap(0, 1, theta=-theta)
66+
c.cphase(0, 1, theta=-phi)
67+
m = c.matrix()
68+
ans = np.array(
69+
[
70+
[1.0 + 0.0j, 0.0 + 0.0j, 0.0 + 0.0j, 0.0 + 0.0j],
71+
[0.0 + 0.0j, 0.95105654 + 0.0j, 0.0 - 0.309017j, 0.0 + 0.0j],
72+
[0.0 + 0.0j, 0.0 - 0.309017j, 0.95105654 + 0.0j, 0.0 + 0.0j],
73+
[0.0 + 0.0j, 0.0 + 0.0j, 0.0 + 0.0j, 0.9553365 - 0.29552022j],
74+
]
75+
)
76+
np.testing.assert_allclose(m, ans, atol=1e-5)
77+
print(m)
78+
79+
6180
def test_exp_gate():
6281
c = tc.Circuit(2)
6382
c.exp(

0 commit comments

Comments
 (0)