Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
PaddlePaddle
Quantum
提交
3b7f210c
Q
Quantum
项目概览
PaddlePaddle
/
Quantum
8 个月 前同步成功
通知
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看板
前往新版Gitcode,体验更适合开发者的 AI 搜索 >>
未验证
提交
3b7f210c
编写于
11月 03, 2021
作者:
Q
QuLeaf
提交者:
GitHub
11月 03, 2021
浏览文件
操作
浏览文件
下载
差异文件
Merge branch 'master' into task77
上级
429f5283
77279bd7
变更
3
隐藏空白更改
内联
并排
Showing
3 changed file
with
59 addition
and
1 deletion
+59
-1
paddle_quantum/circuit.py
paddle_quantum/circuit.py
+24
-1
test_and_documents/readme.md
test_and_documents/readme.md
+1
-0
test_and_documents/test.py
test_and_documents/test.py
+34
-0
未找到文件。
paddle_quantum/circuit.py
浏览文件 @
3b7f210c
...
@@ -26,7 +26,7 @@ from paddle import imag, real, reshape, kron, matmul, trace
...
@@ -26,7 +26,7 @@ from paddle import imag, real, reshape, kron, matmul, trace
from
paddle_quantum.utils
import
partial_trace
,
dagger
,
pauli_str_to_matrix
from
paddle_quantum.utils
import
partial_trace
,
dagger
,
pauli_str_to_matrix
from
paddle_quantum
import
shadow
from
paddle_quantum
import
shadow
from
paddle_quantum.intrinsic
import
*
from
paddle_quantum.intrinsic
import
*
from
paddle_quantum.state
import
density_op
from
paddle_quantum.state
import
density_op
,
vec
__all__
=
[
__all__
=
[
"UAnsatz"
,
"UAnsatz"
,
...
@@ -60,6 +60,29 @@ class UAnsatz:
...
@@ -60,6 +60,29 @@ class UAnsatz:
# Record history of adding gates to the circuit
# Record history of adding gates to the circuit
self
.
__history
=
[]
self
.
__history
=
[]
def
expand
(
self
,
new_n
):
"""
为原来的量子电路进行比特数扩展
Args:
new_n(int):扩展后的量子比特数
"""
assert
new_n
>=
self
.
n
,
'扩展后量子比特数要大于原量子比特数'
diff
=
new_n
-
self
.
n
dim
=
2
**
diff
if
self
.
__state
is
not
None
:
if
self
.
__run_mode
==
'density_matrix'
:
shape
=
(
dim
,
dim
)
_state
=
paddle
.
to_tensor
(
density_op
(
diff
))
elif
self
.
__run_mode
==
'state_vector'
:
shape
=
(
dim
,)
_state
=
paddle
.
to_tensor
(
vec
(
0
,
diff
))
_state
=
paddle
.
reshape
(
_state
,
shape
)
_state
=
kron
(
self
.
__state
,
_state
)
self
.
__state
=
_state
self
.
n
=
new_n
def
__add__
(
self
,
cir
):
def
__add__
(
self
,
cir
):
r
"""重载加法 ‘+’ 运算符,用于拼接两个维度相同的电路
r
"""重载加法 ‘+’ 运算符,用于拼接两个维度相同的电路
...
...
test_and_documents/readme.md
0 → 100644
浏览文件 @
3b7f210c
通过在UAnsatz类中添加新的成员函数expand来实现扩展
test_and_documents/test.py
0 → 100644
浏览文件 @
3b7f210c
from
paddle_quantum.circuit
import
UAnsatz
from
paddle
import
kron
from
paddle_quantum.state
import
vec
,
density_op
import
paddle
#density_matrix
def
test_density_matrix
():
cir
=
UAnsatz
(
1
)
cir
.
ry
(
paddle
.
to_tensor
(
1
,
dtype
=
'float64'
),
0
)
state
=
cir
.
run_density_matrix
()
cir
.
expand
(
3
)
print
(
cir
.
get_state
())
cir2
=
UAnsatz
(
3
)
cir2
.
ry
(
paddle
.
to_tensor
(
1
,
dtype
=
'float64'
),
0
)
cir2
.
run_density_matrix
()
print
(
cir2
.
get_state
())
#state_vector
def
test_state_vector
():
cir
=
UAnsatz
(
1
)
cir
.
ry
(
paddle
.
to_tensor
(
1
,
dtype
=
'float64'
),
0
)
state
=
cir
.
run_state_vector
()
cir
.
expand
(
3
)
print
(
cir
.
get_state
())
cir2
=
UAnsatz
(
3
)
cir2
.
ry
(
paddle
.
to_tensor
(
1
,
dtype
=
'float64'
),
0
)
cir2
.
run_state_vector
()
print
(
cir2
.
get_state
())
test_density_matrix
()
test_state_vector
()
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录