Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix contraction tree #536

Merged
merged 13 commits into from
Dec 23, 2024
Merged

Fix contraction tree #536

merged 13 commits into from
Dec 23, 2024

Conversation

yingjerkao
Copy link
Collaborator

This PR implements the algorithm described in Faster identification of optimal contraction sequences for tensor networks by Robert N. C. Pfeifer, Jutho Haegeman, Frank Verstraete to fix #506

Raw pointers are replaced with smart pointers for to improve the memory management in SearchTree, ContractionTree, Node, and PseudoUniTensor classes. Ranged for loop is used when possible.

Need to further tests on edge cases.

…anagement and functionality

- Renamed PsudoUniTensor to PseudoUniTensor for consistency.
- Replaced raw pointers with smart pointers (std::unique_ptr) in PseudoUniTensor to enhance memory safety.
- Updated constructors and assignment operators to support move semantics.
- Introduced helper functions for optimal tree solving and connected components detection.
- Enhanced SearchTree class to utilize the new PseudoUniTensor structure and improved error handling.
- Added unit tests for SearchTree functionality, covering various scenarios including basic contraction orders and error cases.

This refactor aims to streamline tensor contraction processes and improve overall code maintainability.
…mproved memory management

- Updated Node class to inherit from std::enable_shared_from_this for better shared pointer management.
- Replaced raw pointers with std::shared_ptr and std::weak_ptr in Node to prevent memory leaks and circular references.
- Modified constructors and assignment operators in Node and ContractionTree to support smart pointer usage.
- Adjusted methods in ContractionTree to work with shared pointers, enhancing safety and clarity.
- Updated related code in RegularGncon and RegularNetwork to accommodate changes in Node handling.

This refactor aims to enhance memory safety and maintainability in tensor contraction processes.
…anagement and debugging output

- Added debug output for setting root pointers in Node class to aid in tracing.
- Introduced a new method `set_root_ptrs()` to streamline root pointer assignment.
- Updated constructors to set node names based on children for better identification.
- Refactored `reset_nodes()` and `reset_contraction_order()` methods for clearer logic and safety.
- Enhanced error handling in `set_root_ptrs()` to manage potential weak pointer issues.
- Updated tests to include debug information during network creation.

These changes aim to improve the clarity and maintainability of the contraction tree structure, facilitating easier debugging and understanding of tensor relationships.
…ity and functionality

- Clear previous base nodes before creating new ones to ensure a fresh state.
- Implemented a loop to properly create and assign names to base nodes using smart pointers.
- Enhanced the structure of the FromString method for better readability.

These changes aim to streamline the initialization of base nodes in the contraction tree, improving maintainability and clarity in the network setup process.
Copy link

codecov bot commented Dec 12, 2024

Codecov Report

Attention: Patch coverage is 77.94118% with 60 lines in your changes missing coverage. Please review.

Project coverage is 23.64%. Comparing base (bebe393) to head (4a1fccb).
Report is 15 commits behind head on dev-master.

Files with missing lines Patch % Lines
src/search_tree.cpp 77.16% 25 Missing and 12 partials ⚠️
include/contraction_tree.hpp 71.42% 6 Missing and 6 partials ⚠️
src/contraction_tree.cpp 68.00% 6 Missing and 2 partials ⚠️
src/RegularNetwork.cpp 90.62% 0 Missing and 3 partials ⚠️
Additional details and impacted files
@@              Coverage Diff               @@
##           dev-master     #536      +/-   ##
==============================================
+ Coverage       17.85%   23.64%   +5.79%     
==============================================
  Files             211      211              
  Lines           44766    44911     +145     
  Branches        14956    15039      +83     
==============================================
+ Hits             7992    10620    +2628     
- Misses          32636    32641       +5     
+ Partials         4138     1650    -2488     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

@kaihsin
Copy link
Member

kaihsin commented Dec 13, 2024

I saw a few commit with clang format. Are you using pre-commit tool? It will auto format for you

@yingjerkao
Copy link
Collaborator Author

I moved from vscode to cursor so my extension setup are messed up. Will fix it.

Copy link
Collaborator

@hunghaoti hunghaoti left a comment

Choose a reason for hiding this comment

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

All tests have passed, and additional tests have been added for this change

@yingjerkao yingjerkao merged commit bb1dc21 into dev-master Dec 23, 2024
1 of 2 checks passed
@yingjerkao yingjerkao deleted the fix-contraction-tree branch December 23, 2024 13:47
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.

3 participants