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

Update backtrack_path() to use one less lookup in back_map. #888

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
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
7 changes: 4 additions & 3 deletions src/stim/search/graphlike/algo.cc
Original file line number Diff line number Diff line change
Expand Up @@ -27,16 +27,17 @@
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::map<SearchState, SearchState> &back_map, const SearchState &final_state, const SearchState &previous_state) {
DetectorErrorModel out;
auto cur_state = final_state;
auto prev_state = previous_state;
while (true) {
const auto &prev_state = back_map.at(cur_state);
cur_state.append_transition_as_error_instruction_to(prev_state, out);
if (prev_state.is_undetected()) {
break;
}
cur_state = prev_state;
prev_state = back_map.at(cur_state);
}
std::sort(out.instructions.begin(), out.instructions.end());
return out;
Expand Down Expand Up @@ -82,7 +83,7 @@ DetectorErrorModel stim::shortest_graphlike_undetectable_logical_error(
}
if (next.is_undetected()) {
assert(next.obs_mask.not_zero()); // Otherwise, it would have already been in back_map.
return backtrack_path(back_map, next);
return backtrack_path(back_map, next, curr);
} else {
if (next.det_active == NO_NODE_INDEX) {
// Just resolved one out of two excitations. Move on to the second excitation.
Expand Down