49 std::vector<Eigen::Index> keys;
50 std::unordered_map<Eigen::Index, Eigen::Index> keysKeys;
54 Eigen::Index minId = std::numeric_limits<Eigen::Index>::max();
56 if (contractTheLowestTensorId)
58 for (
const auto &tensor : tensors)
60 if (tensor.first < minId)
68 while (tensors.size() > 1)
70 Eigen::Index tensor1Id;
71 Eigen::Index tensor2Id;
73 if (contractTheLowestTensorId)
76 auto it = tensors.find(tensor1Id);
78 if (it == tensors.end())
81 tensor2Id = it->first;
85 auto it = tensors.begin();
86 tensor1Id = it->first;
88 tensor2Id = it->first;
97 const auto &tensor = tensors[tensor1Id];
98 Eigen::Index resultRank = std::numeric_limits<Eigen::Index>::max();
99 for (Eigen::Index ti = 0; ti < static_cast<Eigen::Index>(tensor->connections.size()); ++ti)
101 const auto nextTensorId = tensor->connections[ti];
104 tensor2Id = nextTensorId;
106 const Eigen::Index newRank =
GetResultRank(tensor, tensors[nextTensorId]);
108 if (newRank <= resultRank)
110 if (newRank < resultRank)
112 tensor2Id = nextTensorId;
113 resultRank = newRank;
124 ContractNodes(qubit, tensors, tensor1Id, tensor2Id, resultRank);
128 if (tensors.size() == 1 || tensor->contractsTheNeededQubit)
129 return std::real(tensor->tensor->atOffset(0));
133 tensors.erase(tensor1Id);
135 if (contractTheLowestTensorId)
137 minId = std::numeric_limits<Eigen::Index>::max();
138 for (
const auto &tensor : tensors)
140 if (tensor.first < minId)
141 minId = tensor.first;
147 return std::real(tensors.begin()->second->tensor->atOffset(0));