Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
PaddlePaddle
Quantum
提交
00b1396a
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看板
未验证
提交
00b1396a
编写于
11月 03, 2021
作者:
Q
QuLeaf
提交者:
GitHub
11月 03, 2021
浏览文件
操作
浏览文件
下载
差异文件
Merge pull request #25 from yangguohao/task77
[PaddlePaddle Hackathon]77 为哈密顿量矩阵实现指定量子比特数
上级
77279bd7
3b7f210c
变更
3
隐藏空白更改
内联
并排
Showing
3 changed file
with
17 addition
and
7 deletion
+17
-7
paddle_quantum/circuit.py
paddle_quantum/circuit.py
+2
-2
paddle_quantum/utils.py
paddle_quantum/utils.py
+9
-5
test_documents/test_construct_h_matrix.py
test_documents/test_construct_h_matrix.py
+6
-0
未找到文件。
paddle_quantum/circuit.py
浏览文件 @
00b1396a
...
...
@@ -59,7 +59,7 @@ class UAnsatz:
paddle
.
to_tensor
(
np
.
array
([
math
.
pi
/
4
])),
paddle
.
to_tensor
(
np
.
array
([
-
math
.
pi
/
4
]))]
# Record history of adding gates to the circuit
self
.
__history
=
[]
def
expand
(
self
,
new_n
):
"""
为原来的量子电路进行比特数扩展
...
...
@@ -82,7 +82,7 @@ class UAnsatz:
_state
=
kron
(
self
.
__state
,
_state
)
self
.
__state
=
_state
self
.
n
=
new_n
def
__add__
(
self
,
cir
):
r
"""重载加法 ‘+’ 运算符,用于拼接两个维度相同的电路
...
...
paddle_quantum/utils.py
浏览文件 @
00b1396a
...
...
@@ -914,17 +914,21 @@ class Hamiltonian:
pass
return
self
.
coefficients
,
self
.
__pauli_words
def
construct_h_matrix
(
self
):
def
construct_h_matrix
(
self
,
n_qubit
=
None
):
r
"""构建 Hamiltonian 在 Z 基底下的矩阵。
Returns:
np.ndarray: Z 基底下的哈密顿量矩阵形式
"""
coefs
,
pauli_words
,
sites
=
self
.
decompose_with_sites
()
n_qubit
=
1
for
site
in
sites
:
if
type
(
site
[
0
])
is
int
:
n_qubit
=
max
(
n_qubit
,
max
(
site
)
+
1
)
if
n_qubit
is
None
:
n_qubit
=
1
for
site
in
sites
:
if
type
(
site
[
0
])
is
int
:
print
(
n_qubit
,(
site
))
n_qubit
=
max
(
n_qubit
,
max
(
site
)
+
1
)
else
:
assert
n_qubit
>=
self
.
n_qubits
,
"输入的量子数不小于哈密顿量表达式中所对应的量子比特数"
h_matrix
=
np
.
zeros
([
2
**
n_qubit
,
2
**
n_qubit
],
dtype
=
'complex64'
)
spin_ops
=
SpinOps
(
n_qubit
,
use_sparse
=
True
)
for
idx
in
range
(
len
(
coefs
)):
...
...
test_documents/test_construct_h_matrix.py
0 → 100644
浏览文件 @
00b1396a
from
paddle_quantum.utils
import
Hamiltonian
h
=
Hamiltonian
([(
1
,
'Z0, Z1'
)])
print
(
h
.
construct_h_matrix
())
print
(
h
.
construct_h_matrix
(
4
))
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录