Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
PaddlePaddle
Quantum
提交
47af6645
Q
Quantum
项目概览
PaddlePaddle
/
Quantum
大约 1 年 前同步成功
通知
20
Star
492
Fork
166
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
5
列表
看板
标记
里程碑
合并请求
0
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
Q
Quantum
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
5
Issue
5
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
提交
Issue看板
未验证
提交
47af6645
编写于
11月 18, 2021
作者:
Y
yangguohao
提交者:
GitHub
11月 18, 2021
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Update trotter.py
上级
1a795946
变更
1
隐藏空白更改
内联
并排
Showing
1 changed file
with
10 addition
and
40 deletion
+10
-40
paddle_quantum/trotter.py
paddle_quantum/trotter.py
+10
-40
未找到文件。
paddle_quantum/trotter.py
浏览文件 @
47af6645
...
...
@@ -260,14 +260,19 @@ def __add_first_order_trotter_block(circuit, tau, grouped_hamiltonian, reverse=F
assert
isinstance
(
hamiltonian
,
Hamiltonian
)
# decompose the Hamiltonian into 3 lists
coeffs
,
pauli_words
,
sites
=
hamiltonian
.
decompose_with_sites
()
if
pauli_words
==
[
'XX'
,
'YY'
,
'ZZ'
]:
optimal_circuit
(
circuit
,[
tau
*
i
for
i
in
coeffs
],
sites
[
0
])
else
:
# apply rotational gate of each term
for
term_index
in
range
(
len
(
coeffs
)):
# apply rotational gate of each term
term_index
=
0
while
term_index
<
len
(
coeffs
):
if
term_index
+
3
<=
len
(
coeffs
)
and
\
len
(
set
(
y
for
x
in
sites
[
term_index
:
term_index
+
3
]
for
y
in
x
))
==
2
and
\
set
(
pauli_words
[
term_index
:
term_index
+
3
])
==
{
'XX'
,
'YY'
,
'ZZ'
}:
optimal_circuit
(
circuit
,[
tau
*
i
for
i
in
coeffs
[
term_index
:
term_index
+
3
]],
sites
[
term_index
])
term_index
+=
3
else
:
# get the sorted pauli_word and site (an array of qubit indices) according to their qubit indices
pauli_word
,
site
=
__sort_pauli_word
(
pauli_words
[
term_index
],
sites
[
term_index
])
add_n_pauli_gate
(
circuit
,
2
*
tau
*
coeffs
[
term_index
],
pauli_word
,
site
)
term_index
+=
1
# in the reverse mode, if the Hamiltonian is a single element list, reverse the order its each term
else
:
if
len
(
grouped_hamiltonian
)
==
1
:
...
...
@@ -390,41 +395,6 @@ def optimal_circuit(circuit,theta,which_qubits):
circuit
.
cnot
([
b
,
a
])
circuit
.
rz
(
paddle
.
to_tensor
(
-
p
,
dtype
=
'float64'
),
a
)
def
__group_hamiltonian_optimal
(
hamiltonian
):
r
""" 将哈密顿量组合成 XXYYZZ 的形式,以及剩余项两个部分,并返回由他们组成的列表
Args:
hamiltonian (Hamiltonian): Paddle Quantum 中的 Hamiltonian 类
Notes:
X0,X1,Y0,Y1,Z0,Z1以及X1,X2,Y1,Y2,Z1,Z2会被分成两组XXYYZZ,且他们的site都要一样。以及其他剩余项
"""
grouped_hamiltonian
=
[]
coeffs
,
pauli_words
,
sites
=
hamiltonian
.
decompose_with_sites
()
grouped_terms_indices
=
[]
left_over_terms_indices
=
[]
d
=
defaultdict
(
list
)
for
term_index
in
range
(
len
(
coeffs
)):
site
=
sites
[
term_index
]
pauli_word
=
pauli_words
[
term_index
]
#print(pauli_word)
for
pauli
in
[
'XX'
,
'YY'
,
'ZZ'
]:
assert
isinstance
(
pauli_word
,
str
),
"Each pauli word should be a string type"
if
(
pauli_word
==
pauli
or
pauli_word
==
pauli
.
lower
()):
d
[
tuple
(
site
)].
append
((
pauli
,
term_index
))
if
len
(
d
[
tuple
(
site
)])
==
3
:
terms_indices_to_be_grouped
=
[
x
[
1
]
for
x
in
d
[
tuple
(
site
)]]
grouped_terms_indices
.
extend
(
terms_indices_to_be_grouped
)
grouped_hamiltonian
.
append
(
hamiltonian
[
terms_indices_to_be_grouped
])
for
term_index
in
range
(
len
(
coeffs
)):
if
term_index
not
in
grouped_terms_indices
:
left_over_terms_indices
.
append
(
term_index
)
if
len
(
left_over_terms_indices
):
for
term_index
in
left_over_terms_indices
:
grouped_hamiltonian
.
append
(
hamiltonian
[
term_index
])
return
grouped_hamiltonian
def
__group_hamiltonian_xyz
(
hamiltonian
):
r
""" 将哈密顿量拆分成 X、Y、Z 以及剩余项四个部分,并返回由他们组成的列表
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录