Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
30 commits
Select commit Hold shift + click to select a range
78e5ec8
Add visualization library to CMake build
noajshu Aug 11, 2025
482cb81
Merge pull request #36 from noajshu/codex/update-cmakelists-to-includ…
noajshu Aug 11, 2025
106ce02
Merge branch 'main' into main
noajshu Aug 12, 2025
b4c9d08
Merge remote-tracking branch 'quantum/main'
noajshu Aug 12, 2025
5c211bc
Fix CMake Python module placement and add agent instructions
noajshu Aug 13, 2025
d93e31d
Merge pull request #37 from noajshu/codex/add-agents.md-documentation…
noajshu Aug 13, 2025
7c10268
Allow decode_to_errors to accept bitstring
noajshu Aug 20, 2025
8a27808
Merge pull request #38 from noajshu/codex/update-decode_to_errors-to-…
noajshu Aug 20, 2025
1e52d57
Merge branch 'quantumlib:main' into main
noajshu Aug 20, 2025
c34dd80
clang-format
noajshu Aug 20, 2025
24c0d69
Update src/tesseract.pybind.h
noajshu Aug 20, 2025
96849b6
remove stringstream
noajshu Aug 20, 2025
3d486b0
more fixes
noajshu Aug 20, 2025
20e506d
Merge remote-tracking branch 'quantum'
noajshu Aug 29, 2025
61867e2
Handle explicit DetIndex case
noajshu Aug 29, 2025
a3e2663
Merge pull request #39 from noajshu/codex/create-detorder-enum-and-up…
noajshu Aug 29, 2025
7309377
Merge remote-tracking branch 'quantum'
noajshu Aug 29, 2025
454521f
expand det index test
noajshu Aug 29, 2025
18b12cd
Merge pull request #40 from noajshu/codex/refactor-test_build_det_ord…
noajshu Aug 29, 2025
41f7c3e
update beam climbing for when det orders > beam+1
noajshu Aug 29, 2025
e9a0774
Merge remote-tracking branch 'origin'
noajshu Aug 29, 2025
bead3cf
Merge remote-tracking branch 'quantum'
noajshu Aug 30, 2025
8f269f7
Refactor: Remove --at-most-two-errors-per-detector feature
noajshu Aug 31, 2025
a1e86a7
Refactor: Rename num_detectors to num_dets
noajshu Aug 31, 2025
cbf46ef
Merge branch 'main' into refactor/rename-num_detectors-to-num_dets
noajshu Aug 31, 2025
1902a2c
Style: Apply clang-format
noajshu Aug 31, 2025
70be6aa
Merge branch 'main' into refactor/rename-num_detectors-to-num_dets
noajshu Aug 31, 2025
a4ed74a
undo changes to tutorial
noajshu Aug 31, 2025
ffde321
Merge remote-tracking branch 'quantum' into refactor/rename-num_detec…
noajshu Aug 31, 2025
7497652
Merge branch 'refactor/rename-num_detectors-to-num_dets' of https://g…
noajshu Aug 31, 2025
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
41 changes: 20 additions & 21 deletions src/tesseract.cc
Original file line number Diff line number Diff line change
Expand Up @@ -74,12 +74,12 @@ std::string Node::str() {
ss << "Node(";
ss << "errors=" << self.errors << ", ";
ss << "cost=" << self.cost << ", ";
ss << "num_detectors=" << self.num_detectors << ", ";
ss << "num_dets=" << self.num_dets << ", ";
return ss.str();
}

bool Node::operator>(const Node& other) const {
return cost > other.cost || (cost == other.cost && num_detectors < other.num_detectors);
return cost > other.cost || (cost == other.cost && num_dets < other.num_dets);
}

double TesseractDecoder::get_detcost(
Expand Down Expand Up @@ -293,27 +293,27 @@ void TesseractDecoder::decode_to_errors(const std::vector<uint64_t>& detections,
return;
}

size_t min_num_detectors = detections.size();
size_t max_num_detectors = min_num_detectors + detector_beam;
size_t min_num_dets = detections.size();
size_t max_num_dets = min_num_dets + detector_beam;

std::vector<size_t> next_errors;
boost::dynamic_bitset<> next_detectors;
std::vector<DetectorCostTuple> next_detector_cost_tuples;

pq.push({initial_cost, min_num_detectors, std::vector<size_t>()});
pq.push({initial_cost, min_num_dets, std::vector<size_t>()});
size_t num_pq_pushed = 1;

while (!pq.empty()) {
const Node node = pq.top();
pq.pop();

if (node.num_detectors > max_num_detectors) continue;
if (node.num_dets > max_num_dets) continue;

boost::dynamic_bitset<> detectors = initial_detectors;
std::vector<DetectorCostTuple> detector_cost_tuples(num_errors);
flip_detectors_and_block_errors(detector_order, node.errors, detectors, detector_cost_tuples);

if (node.num_detectors == 0) {
if (node.num_dets == 0) {
if (config.create_visualization) {
visualizer.add_activated_errors(node.errors);
visualizer.add_activated_detectors(detectors, num_detectors);
Expand All @@ -339,7 +339,7 @@ void TesseractDecoder::decode_to_errors(const std::vector<uint64_t>& detections,
return;
}

if (config.no_revisit_dets && !visited_detectors[node.num_detectors].insert(detectors).second)
if (config.no_revisit_dets && !visited_detectors[node.num_dets].insert(detectors).second)
continue;

if (config.create_visualization) {
Expand All @@ -349,9 +349,8 @@ void TesseractDecoder::decode_to_errors(const std::vector<uint64_t>& detections,
if (config.verbose) {
std::cout.precision(13);
std::cout << "len(pq) = " << pq.size() << " num_pq_pushed = " << num_pq_pushed << std::endl;
std::cout << "num_detectors = " << node.num_detectors
<< " max_num_detectors = " << max_num_detectors << " cost = " << node.cost
<< std::endl;
std::cout << "num_dets = " << node.num_dets << " max_num_dets = " << max_num_dets
<< " cost = " << node.cost << std::endl;
std::cout << "activated_errors = ";
for (size_t oei : node.errors) {
std::cout << oei << ", ";
Expand All @@ -366,14 +365,14 @@ void TesseractDecoder::decode_to_errors(const std::vector<uint64_t>& detections,
std::cout << std::endl;
}

if (node.num_detectors < min_num_detectors) {
min_num_detectors = node.num_detectors;
if (node.num_dets < min_num_dets) {
min_num_dets = node.num_dets;
if (config.no_revisit_dets) {
for (size_t i = min_num_detectors + detector_beam + 1; i <= max_num_detectors; ++i) {
for (size_t i = min_num_dets + detector_beam + 1; i <= max_num_dets; ++i) {
visited_detectors[i].clear();
}
}
max_num_detectors = std::min(max_num_detectors, min_num_detectors + detector_beam);
max_num_dets = std::min(max_num_dets, min_num_dets + detector_beam);
}

for (size_t d = 0; d < num_detectors; ++d) {
Expand Down Expand Up @@ -415,21 +414,21 @@ void TesseractDecoder::decode_to_errors(const std::vector<uint64_t>& detections,
next_detector_cost_tuples[ei].error_blocked = 1;

double next_cost = node.cost + errors[ei].likelihood_cost;
size_t next_num_detectors = node.num_detectors;
size_t next_num_dets = node.num_dets;

for (int d : edets[ei]) {
next_detectors[d] = !next_detectors[d];
int fired = next_detectors[d] ? 1 : -1;
next_num_detectors += fired;
next_num_dets += fired;
for (int oei : d2e[d]) {
next_detector_cost_tuples[oei].detectors_count += fired;
}
}

if (next_num_detectors > max_num_detectors) continue;
if (next_num_dets > max_num_dets) continue;

if (config.no_revisit_dets && visited_detectors[next_num_detectors].find(next_detectors) !=
visited_detectors[next_num_detectors].end())
if (config.no_revisit_dets && visited_detectors[next_num_dets].find(next_detectors) !=
visited_detectors[next_num_dets].end())
continue;

for (int d : edets[ei]) {
Expand All @@ -454,7 +453,7 @@ void TesseractDecoder::decode_to_errors(const std::vector<uint64_t>& detections,

if (next_cost == INF) continue;

pq.push({next_cost, next_num_detectors, next_errors});
pq.push({next_cost, next_num_dets, next_errors});
++num_pq_pushed;

if (num_pq_pushed > config.pqlimit) {
Expand Down
5 changes: 3 additions & 2 deletions src/tesseract.h
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,8 @@ struct TesseractConfig {
class Node {
public:
double cost;
size_t num_detectors;
// The number of activated detectors (dets for short) at this node
size_t num_dets;
std::vector<size_t> errors;

bool operator>(const Node& other) const;
Expand Down Expand Up @@ -118,4 +119,4 @@ struct TesseractDecoder {
std::vector<DetectorCostTuple>& detector_cost_tuples) const;
};

#endif // TESSERACT_DECODER_H
#endif // TESSERACT_DECODER_H
7 changes: 3 additions & 4 deletions src/tesseract.pybind.h
Original file line number Diff line number Diff line change
Expand Up @@ -205,21 +205,20 @@ void add_tesseract_module(py::module& root) {
This is used internally by the decoder to track decoding progress.
)pbdoc")
.def(py::init<double, size_t, std::vector<size_t>>(), py::arg("cost") = 0.0,
py::arg("num_detectors") = 0, py::arg("errors") = std::vector<size_t>(), R"pbdoc(
py::arg("num_dets") = 0, py::arg("errors") = std::vector<size_t>(), R"pbdoc(
The constructor for the `Node` class.

Parameters
----------
cost : float, default=0.0
The cost of the path to this node.
num_detectors : int, default=0
num_dets : int, default=0
The number of detectors this search node has.
errors : list[int], default=empty
The list of error indices this search node has.
)pbdoc")
.def_readwrite("cost", &Node::cost, "The cost of the node.")
.def_readwrite("num_detectors", &Node::num_detectors,
"The number of detectors this search node has.")
.def_readwrite("num_dets", &Node::num_dets, "The number of detectors this search node has.")
.def_readwrite("errors", &Node::errors, "The list of error indices this search node has.")
.def(py::self > py::self,
"Comparison operator for nodes based on cost. This is necessary to prioritize "
Expand Down
Loading