46 std::vector<Eigen::Index> keys;
47 std::unordered_map<Eigen::Index, Eigen::Index> keysKeys;
52 Eigen::Index minId = std::numeric_limits<Eigen::Index>::max();
54 if (contractTheLowestTensorId) {
55 for (
const auto &tensor : tensors) {
56 if (tensor.first < minId) minId = tensor.first;
63 while (tensors.size() > 1) {
64 Eigen::Index tensor1Id;
65 Eigen::Index tensor2Id;
67 if (contractTheLowestTensorId) {
69 auto it = tensors.find(tensor1Id);
71 if (it == tensors.end()) it = tensors.begin();
73 tensor2Id = it->first;
75 auto it = tensors.begin();
76 tensor1Id = it->first;
78 tensor2Id = it->first;
87 const auto &tensor = tensors[tensor1Id];
88 Eigen::Index resultRank = std::numeric_limits<Eigen::Index>::max();
89 for (Eigen::Index ti = 0;
90 ti < static_cast<Eigen::Index>(tensor->connections.size()); ++ti) {
91 const auto nextTensorId = tensor->connections[ti];
93 tensor2Id = nextTensorId;
95 const Eigen::Index newRank =
98 if (newRank <= resultRank) {
99 if (newRank < resultRank) {
100 tensor2Id = nextTensorId;
101 resultRank = newRank;
112 ContractNodes(qubit, tensors, tensor1Id, tensor2Id, resultRank);
114 if (resultRank == 0) {
115 if (tensors.size() == 1 || tensor->contractsTheNeededQubit)
116 return std::real(tensor->tensor->atOffset(0));
120 tensors.erase(tensor1Id);
122 if (contractTheLowestTensorId) {
123 minId = std::numeric_limits<Eigen::Index>::max();
124 for (
const auto &tensor : tensors) {
125 if (tensor.first < minId) minId = tensor.first;
131 return std::real(tensors.begin()->second->tensor->atOffset(0));