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 finding optimal contraction order (WIP) #532

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

The implementation reuses the original data structure and interface as much as possible.

Currently the code compiles and more integration tests are necessary

- Added comprehensive comments to the `pContract` function in `search_tree.cpp` explaining the XOR operation for tracking tensor contractions.
- Clarified the calculation of new tensor shapes and labels after contraction.
- Improved readability and maintainability of the code by documenting the contraction history.
…rity

- Removed namespace prefix from member function definitions in `search_tree.cpp` for `PseudoUniTensor`.
- Updated the assignment operator and constructor implementations to enhance code readability and maintainability.
- Ensured consistency in member function declarations by streamlining the syntax.
- Renamed `root` to `root_ptr` for better clarity in `search_tree.hpp`.
- Updated `clear()` and `reset_search_order()` methods to use `root_ptr`.
- Changed `get_nodes()` to `get_root()` to reflect the method's purpose more accurately.
- Ensured consistent use of smart pointers in the SearchTree class.
…zation

- Introduced `search_tree_test.cpp` with multiple test cases to validate the SearchTree's behavior, including basic search order, handling of empty trees, single nodes, and disconnected networks.
- Updated `CMakeLists.txt` to include the new test file and added address sanitization options for improved debugging.
- Updated PseudoUniTensor constructor to initialize ID and accumulation string.
- Refactored pContract function to streamline tensor contraction process and set internal node properties.
- Improved error handling in SearchTree::search_order to require at least two base nodes.
- Enhanced code readability with additional comments and consistent use of smart pointers.
… handling

- Added new test cases to validate optimal contraction order for a network of tensors in `search_tree_test.cpp`.
- Updated assertions to check for expected contraction costs and formats.
- Improved error handling in `search_order` method to throw `std::logic_error` instead of `std::runtime_error` for empty and single-node trees.
- Refactored retrieval of result nodes to use `get_root()` for clarity.
…ntation

- Changed adjacency matrix representation from a vector of vectors to a vector of IndexSets for improved performance and memory efficiency.
- Updated DFS function to utilize IndexSet for tracking visited nodes, enhancing clarity and reducing overhead.
- Added a check for empty tensor input in the solve function to prevent unnecessary processing.
- Improved adjacency matrix construction logic to ensure proper sizing and filling based on common tensor labels.
- Enhanced component combination logic to create new nodes with calculated costs and properties, improving the overall structure of the tensor network.
… output

- Removed debug output for accumulated string in BasicSearchOrder test.
- Ensured test cases accurately reflect the intended tensor configurations for better validation.
…on cost and sequence

- Adjusted expected contraction cost from 832 to 1536 to reflect the optimal result.
- Updated the expected contraction sequence string from "(3,(0,(1,2)))" to "((2,3),(0,1))" for accuracy in validation.
@yingjerkao
Copy link
Collaborator Author

I messed up my branch. Will create a new PR from a new branch.

@yingjerkao yingjerkao closed this Dec 12, 2024
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.

1 participant