Skip to content

Conversation

gausshj
Copy link
Collaborator

@gausshj gausshj commented Sep 12, 2025

Add support for trace

- Add assertion tests for matmul of impure tensors

Signed-off-by: Gausshj <[email protected]>
- Add trace support for tensor
- Add simply test for trace

Signed-off-by: Gausshj <[email protected]>
Copy link

codecov bot commented Sep 12, 2025

Codecov Report

❌ Patch coverage is 77.77778% with 4 lines in your changes missing coverage. Please review.

Files with missing lines Patch % Lines
grassmann_tensor/tensor.py 77.77% 2 Missing and 2 partials ⚠️

📢 Thoughts on this report? Let us know!

if edge_first != edge_end:
raise ValueError(f"Incompatible edges: {edge_first} and {edge_end}.")

if tensor.arrow[trace_pair[0]] != tensor.arrow[trace_pair[1]]:
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

相互trace的两个指标的arrow应该是相反的

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

好的,已在8d23116中提交了修改。

order_first = order.pop(trace_pair[0])
order_end = order.pop(trace_pair[1])
order[trace_pair[0] : trace_pair[0]] = [order_first, order_end]
tensor = tensor.permute(tuple(order))
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

建议你新实现一个只支持对最后两个指标进行trace的版本

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

不然你对符号的处理完全不对,最后两个指标trace的时候,T F的话,不需要加任何符号,F T的话,需要根据最后两个指标的parity加符号(2个相互trace的指标的parity应该是完全一致的)。

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

那能否通过permute来实现,将需要trace的指标移到最后,然后再按照当前的代码逻辑来求trace?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

那能否通过permute来实现,将需要trace的指标移到最后,然后再按照当前的代码逻辑来求trace?

是的,确实是应该这么干的,先实现下最后两个指标的,然后外面套个permute。

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

只要你能把两个指标的trace写对,后面套permute很难写错,所以建议你先把两个指标的版本写对。

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

然后再按照当前的代码逻辑来求trace

你现在的符号没处理对啊

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

不是没处理对符号,是没处理符号=_=、、、你只需要permute成T F的话,符号才可以恰好不用处理。

- Remove unnecessary judge for arrow

Signed-off-by: Gausshj <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants