AI4Finance-Foundation / AI4Finance-Foundation/RLSolver
🐛 contract in some orders on a circuit with ring struction may get incorrect multiplication counts.
- Dominant language
- Python
- Stars
- 169
- Forks
- 36
- PR merge metrics
- No merged PRs in 30d
Description
收缩 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]
```
Contributor guide
No contributing guide indexed for this repository
Research direction
Start with the contraction-counting code shown in the issue and reproduce it on the NodesSycamoreN12M14 circuit using the reported 51 nodes, 99 edges, and contraction-order conditions. Trace the node dimension and boolean arrays around the printed duplicate contraction. Done means cyclic circuits no longer contract an already-combined node or add duplicate multiplication counts.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- python
- Domain
- backend
- Issue type
- Bug
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Stale
- Clarity
- Needs clarification
- Newbie friendliness
- 25/100