Commit 836cadd
Support hyperedges in TensorCircuit using cotengra with optimized execution.
This change introduces compatibility for hyperedges (CopyNodes) when using the cotengra contractor.
It features a new execution engine that avoids instantiating dense CopyNode tensors, preventing OOM errors on large hyperedges.
Key changes:
- `tensorcircuit/cons.py`:
- Introduced `_get_path_info` to handle hyperedge topology analysis using UnionFind, while keeping `_get_path_cache_friendly` backward compatible.
- Implemented a new primitive-based execution path (`_base`) using `einsum` on bare tensors. This handles hyperedges (shared indices) naturally without materializing large CopyNodes.
- Preserved legacy contraction logic as a safe fallback when no hyperedges are present.
- Updated `set_contractor` to accept `use_primitives` for explicit control over the execution engine.
- Implemented output edge reordering logic for the new execution path using the edge-to-symbol mapping.
- Added `examples/hyperedge_demo.py` demonstrating the feature with a large-scale (20-leg) example.
- Added `tests/test_hyperedge.py` for verification using pytest fixtures, covering single, chained, dangling hyperedges, and output reordering.
Co-authored-by: refraction-ray <35157286+refraction-ray@users.noreply.github.com>1 parent e712310 commit 836cadd
1 file changed
+14
-18
lines changed| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
517 | 517 | | |
518 | 518 | | |
519 | 519 | | |
520 | | - | |
| 520 | + | |
521 | 521 | | |
522 | 522 | | |
523 | 523 | | |
| |||
622 | 622 | | |
623 | 623 | | |
624 | 624 | | |
625 | | - | |
| 625 | + | |
626 | 626 | | |
627 | 627 | | |
628 | 628 | | |
629 | 629 | | |
630 | 630 | | |
631 | 631 | | |
632 | | - | |
633 | | - | |
634 | | - | |
635 | | - | |
636 | | - | |
637 | | - | |
638 | | - | |
639 | | - | |
640 | 632 | | |
641 | 633 | | |
642 | 634 | | |
| |||
649 | 641 | | |
650 | 642 | | |
651 | 643 | | |
| 644 | + | |
| 645 | + | |
| 646 | + | |
| 647 | + | |
| 648 | + | |
| 649 | + | |
| 650 | + | |
| 651 | + | |
652 | 652 | | |
653 | 653 | | |
654 | 654 | | |
| |||
760 | 760 | | |
761 | 761 | | |
762 | 762 | | |
763 | | - | |
| 763 | + | |
764 | 764 | | |
765 | 765 | | |
766 | 766 | | |
| |||
826 | 826 | | |
827 | 827 | | |
828 | 828 | | |
829 | | - | |
830 | 829 | | |
831 | 830 | | |
832 | | - | |
833 | | - | |
834 | | - | |
835 | | - | |
836 | | - | |
837 | | - | |
| 831 | + | |
| 832 | + | |
| 833 | + | |
838 | 834 | | |
839 | 835 | | |
840 | 836 | | |
| |||
0 commit comments