Skip to content

🐛 contract in some orders on a circuit with ring struction may get incorrect multiplication counts. #99

Description

@Yonv1943

收缩 sycamore 以及 tensor grid ,tensor ring 这种有环状结构的电路,会有bug,导致乘法次数计算错误
(刚好我们测试的 tensor train,tensor tree 没有环状结构)

需要有环状结构,且按某个顺序收缩张量节点,才会触发

下面的代码,在一个小规模的 sycamore 电路 NodesSycamoreN12M14 上得到,然后逐行检查发现了这个bug

num_nodes             51
num_edges             99
ban_edges              0

先粗略记录一下。

这是print代码

'''calculate the multiple and avoid repeat'''
contract_dims = node_dims_arys[node_i0] + node_dims_arys[node_i1]  # 计算收缩后的node 的邻接张量的维度 以及来源
contract_bool = node_bool_arys[node_i0] | node_bool_arys[node_i1]  # 计算收缩后的node 由哪些原初node 合成
# assert contract_dims.shape == (num_nodes, )
# assert contract_bool.shape == (num_nodes, )

print(';;;', i, node_i0, node_i1)
print(node_dims_arys[node_i0].numpy().astype(int))
print(node_dims_arys[node_i1].numpy().astype(int))
print(contract_dims.numpy().astype(int))
print(contract_bool.numpy().astype(int))

这是print内容。可以看到,对已经收缩的节点竟然进行了不可能的收缩,并且产生了多余的乘法次数。

;;; 52 tensor(3) tensor(9)
[  0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0 352   0   0   0   0  96   0   0   0 128   0   0   0   0 320   0 128   0   0   0  64   0  64  64   0   0   0   0 192   0  64  64   0]
[  0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0 352   0   0   0   0  96   0   0   0 128   0   0   0   0 320   0 128   0   0   0  64   0  64  64   0   0   0   0 192   0  64  64   0]
[  0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0 704   0   0   0   0 192   0   0   0 256   0   0   0   0 640   0 256   0   0   0 128   0 128 128   0   0   0   0 384   0 128 128   0]
[1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 0 1 1 1 1 0 1 1 1 0 1 1 1 1 0 1 0 1 0 1 0 1 0 0 1 1 0 0 0 1 0 0 1]

Metadata

Metadata

Assignees

No one assigned

    Labels

    discussioncode understandinghelp wantedExtra attention is needed

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions