Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions src/stim/search/graphlike/algo.cc
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
#include "stim/search/graphlike/algo.h"

#include <algorithm>
#include <map>
#include <unordered_map>
#include <queue>
#include <sstream>

Expand All @@ -27,7 +27,7 @@
using namespace stim;
using namespace stim::impl_search_graphlike;

DetectorErrorModel backtrack_path(const std::map<SearchState, SearchState> &back_map, const SearchState &final_state) {
DetectorErrorModel backtrack_path(const std::unordered_map<SearchState, SearchState, SearchStateHash> &back_map, const SearchState &final_state) {
DetectorErrorModel out;
auto cur_state = final_state;
while (true) {
Expand Down Expand Up @@ -55,7 +55,7 @@ DetectorErrorModel stim::shortest_graphlike_undetectable_logical_error(
}

std::queue<SearchState> queue;
std::map<SearchState, SearchState> back_map;
std::unordered_map<SearchState, SearchState, SearchStateHash> back_map;
// Mark the vacuous dead-end state as already seen.
back_map.emplace(empty_search_state, empty_search_state);

Expand Down
18 changes: 18 additions & 0 deletions src/stim/search/graphlike/algo.perf.cc
Original file line number Diff line number Diff line change
Expand Up @@ -36,3 +36,21 @@ BENCHMARK(find_graphlike_logical_error_surface_code_d25) {
std::cout << "bad";
}
}

BENCHMARK(find_graphlike_logical_error_surface_code_d11_r1000) {
CircuitGenParameters params(1000, 11, "rotated_memory_x");
params.after_clifford_depolarization = 0.001;
params.before_measure_flip_probability = 0.001;
params.after_reset_flip_probability = 0.001;
params.before_round_data_depolarization = 0.001;
auto circuit = generate_surface_code_circuit(params).circuit;
auto model = ErrorAnalyzer::circuit_to_detector_error_model(circuit, true, true, false, 0.0, false, true);

size_t total = 0;
benchmark_go([&]() {
total += stim::shortest_graphlike_undetectable_logical_error(model, false).instructions.size();
}).goal_millis(100);
if (total % 11 != 0 || total == 0) {
std::cout << "bad";
}
}
16 changes: 16 additions & 0 deletions src/stim/search/graphlike/search_state.h
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,22 @@ struct SearchState {
};
std::ostream &operator<<(std::ostream &out, const SearchState &v);

inline void hash_combine(size_t &h, uint64_t x) {
h ^= std::hash<uint64_t>{}(x) + 0x9e3779b97f4a7c15ULL + (h << 6) + (h >> 2); // mimic Boost's hash-combine function
}

struct SearchStateHash {
size_t operator()(const SearchState &s) const {
SearchState c = s.canonical();
size_t h = std::hash<uint64_t>{}(c.det_active);
hash_combine(h, c.det_held);
for (size_t i = 0; i < c.obs_mask.num_u64_padded(); i++) {
hash_combine(h, c.obs_mask.u64[i]);
}
return h;
}
};

} // namespace impl_search_graphlike
} // namespace stim

Expand Down
8 changes: 8 additions & 0 deletions src/stim/search/graphlike/search_state.test.cc
Original file line number Diff line number Diff line change
Expand Up @@ -148,3 +148,11 @@ TEST(search_graphlike, DemAdjGraphSearchState_canonical_ordering) {
TEST(search_graphlike, DemAdjGraphSearchState_str) {
ASSERT_EQ(SearchState(1, 2, obs_mask(3)).str(), "D1 D2 L0 L1 ");
}

TEST(search_graphlike, SearchStateHash_operator) {
ASSERT_EQ(SearchStateHash{}(SearchState(1, 2, obs_mask(3))), SearchStateHash{}(SearchState(2, 1, obs_mask(3))));
ASSERT_EQ(SearchStateHash{}(SearchState(1, 2, obs_mask(3))), SearchStateHash{}(SearchState(1, 2, obs_mask(3))));

ASSERT_NE(SearchStateHash{}(SearchState(1, 2, obs_mask(3))), SearchStateHash{}(SearchState(2, 2, obs_mask(3))));
ASSERT_NE(SearchStateHash{}(SearchState(1, 2, obs_mask(3))), SearchStateHash{}(SearchState(1, 2, obs_mask(4))));
}
Loading