Skip to content

Conversation

@gopinath-vasalamarri
Copy link

@gopinath-vasalamarri gopinath-vasalamarri commented Aug 15, 2025

At the core of the change -- we are essentially swapping double_divs <-> double_muls in the for loop which, are more efficient CPU Cycle wise.

More information on comparison of before and after performance --
https://docs.google.com/spreadsheets/d/17fL_NVWe7XjwGmdBIts75YFuzUmokUyfd_YMEU9ISXY/edit?gid=0#gid=0

@gopinath-vasalamarri gopinath-vasalamarri force-pushed the main branch 2 times, most recently from c6896e4 to e6bd1d1 Compare August 17, 2025 05:35
Copy link
Collaborator

@LalehB LalehB left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks so much, @gopinath-vasalamarri
This optimization is super cool 💯
If you get a chance, could you please also share performance results for larger numbers of shots (10K or 1M) and on other codes (surface code, color code, bivariate bicycle codes)?

double TesseractDecoder::get_detcost(
size_t d, const std::vector<DetectorCostTuple>& detector_cost_tuples) const {
double min_cost = INF;
uint32_t min_det_cost = std::numeric_limits<uint32_t>::infinity();
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Does the std::numeric_limits<T>::infinity() applies for uint32_t? if it is only for floating-point types then this could become zero and later we might face division by zero issues!

error_cost = ec.likelihood_cost / dct.detectors_count;
if (error_cost < min_cost) {
error_cost = ec.likelihood_cost;
if (error_cost < min_cost * dct.detectors_count) {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I like that you are replacing the div with mul 👏🏻

error_cost = ec.likelihood_cost;
if (error_cost < min_cost * dct.detectors_count) {
min_cost = error_cost;
min_det_cost = dct.detectors_count;
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

maybe we can have a more discriptive name for this variable, something like min_cost_det_cnt?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants