Improve the performance of get_detcost() function.#108
Open
gopinath-vasalamarri wants to merge 3 commits intoquantumlib:mainfrom
Open
Improve the performance of get_detcost() function.#108gopinath-vasalamarri wants to merge 3 commits intoquantumlib:mainfrom
gopinath-vasalamarri wants to merge 3 commits intoquantumlib:mainfrom
Conversation
c6896e4 to
e6bd1d1
Compare
e6bd1d1 to
6e4ebe3
Compare
LalehB
reviewed
Aug 24, 2025
Collaborator
LalehB
left a comment
There was a problem hiding this comment.
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(); |
Collaborator
There was a problem hiding this comment.
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) { |
Collaborator
There was a problem hiding this comment.
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; |
Collaborator
There was a problem hiding this comment.
maybe we can have a more discriptive name for this variable, something like min_cost_det_cnt?
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
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