Add standalone tropical tensor network package#51
Conversation
Includes standalone src, tests, docs, and example assets.
There was a problem hiding this comment.
Pull request overview
This PR introduces a standalone tropical tensor network package for computing Most Probable Explanation (MPE) in probabilistic graphical models. The package includes UAI format parsing, tropical (max-plus) semiring operations, variable elimination ordering heuristics, and a complete MPE inference pipeline.
Changes:
- Added independent
tropical_in_newpackage with complete source implementation, test suite, documentation, and examples - Implemented UAI model parsing utilities and tropical tensor contraction primitives
- Provided runnable Asia network example with model file and execution script
Reviewed changes
Copilot reviewed 17 out of 17 changed files in this pull request and generated 18 comments.
Show a summary per file
| File | Description |
|---|---|
| tropical_in_new/src/init.py | Public API exports for the tropical tensor network package |
| tropical_in_new/src/primitives.py | Core tropical semiring operations including safe_log, tropical_einsum, and argmax tracing |
| tropical_in_new/src/network.py | Tensor network construction from factor graphs |
| tropical_in_new/src/contraction.py | Variable elimination ordering heuristics and contraction tree execution |
| tropical_in_new/src/mpe.py | High-level MPE API and assignment recovery from backpointers |
| tropical_in_new/src/utils.py | UAI format parsing for models and evidence files |
| tropical_in_new/tests/conftest.py | Test configuration with sys.path setup |
| tropical_in_new/tests/test_primitives.py | Unit tests for tropical primitives |
| tropical_in_new/tests/test_contraction.py | Unit tests for contraction ordering and execution |
| tropical_in_new/tests/test_mpe.py | Integration tests comparing MPE results against brute force |
| tropical_in_new/examples/asia_network/main.py | Example script demonstrating MPE computation |
| tropical_in_new/examples/asia_network/model.uai | Example UAI model file |
| tropical_in_new/docs/usage_guide.md | User guide with quick start examples |
| tropical_in_new/docs/mathematical_description.md | Mathematical description of tropical tensor network approach |
| tropical_in_new/docs/api_reference.md | API reference documentation |
| tropical_in_new/README.md | Package overview and structure |
| tropical_in_new/requirements.txt | Package dependencies |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
Update docs/imports and improve validation coverage.
GiggleLiu
left a comment
There was a problem hiding this comment.
I wish the folder name tropical_in_new can be replaced with a better one in this pr, it is hard to change in later revision. You can also leave it to a later refactor (leave an issue if you want to make this change later).
The rest looks good. Well done!
GiggleLiu
left a comment
There was a problem hiding this comment.
For all the remaining comments, please address or make an issue.
|
I will these pr comments. |
- Use einsum with elimination directly in contract_tree instead of separate ReduceNode for multi-node buckets - Generalize _brute_force_mpe with itertools.product for any number of variables - Add assert statements in utils.py for internal consistency checks - Add comprehensive tests for error paths, edge cases, and read_evidence_file/read_model_file (coverage now 98%) Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
Summary
Test plan