Skip to content

refactor(sapere): simplify execution logic in SAPEREReaction#5317

Open
DanySK wants to merge 3 commits intomasterfrom
refactor/sapere/simplifyexecutionlogicin
Open

refactor(sapere): simplify execution logic in SAPEREReaction#5317
DanySK wants to merge 3 commits intomasterfrom
refactor/sapere/simplifyexecutionlogicin

Conversation

@DanySK
Copy link
Copy Markdown
Member

@DanySK DanySK commented Apr 28, 2026

No description provided.

Copilot AI review requested due to automatic review settings April 28, 2026 16:37
@DanySK DanySK enabled auto-merge (squash) April 28, 2026 16:38
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

Refactors SAPEREReaction.execute() to simplify match selection/execution flow by extracting helper methods, aiming to make the SAPERE reaction execution logic easier to follow and maintain.

Changes:

  • Extracted action execution and molecule removal into dedicated helper methods.
  • Centralized match selection logic into selectMatchIndex() / selectWeightedMatchIndex().
  • Moved the “empty execution” optimization into updateEmptyExecutionStatus(...).

Comment on lines +204 to +212
final double selectedPropensity = rng.nextDouble() * totalPropensity;
double cumulativePropensity = 0;
for (int i = 0; i < propensities.size(); i++) {
cumulativePropensity += propensities.get(i);
if (cumulativePropensity > selectedPropensity) {
return i;
}
}
throw new IllegalStateException("No match selected despite positive total propensity.");
Copy link

Copilot AI Apr 28, 2026

Choose a reason for hiding this comment

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

selectedPropensity = rng.nextDouble() * totalPropensity can round up to exactly totalPropensity for large values (even though nextDouble() is < 1.0), and the strict > comparison can then fail to select any index and throw. Consider clamping selectedPropensity to < totalPropensity (e.g., Math.nextDown(totalPropensity)) and/or ensuring the last bucket is always selected (e.g., return the last index after the loop or use >= on the final iteration).

Copilot uses AI. Check for mistakes.
Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

@copilot apply changes based on this feedback

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Fixed in 39a31ee. The throw is now replaced with return propensities.size() - 1 so the last bucket is always selected when floating-point rounding causes selectedPropensity to equal totalPropensity.

@DanySK DanySK force-pushed the refactor/sapere/simplifyexecutionlogicin branch 2 times, most recently from a689575 to 34b5e9c Compare April 28, 2026 18:50
@codecov
Copy link
Copy Markdown

codecov Bot commented Apr 28, 2026

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 61.53%. Comparing base (59559e5) to head (6f31ac8).
⚠️ Report is 2 commits behind head on master.

Additional details and impacted files
@@            Coverage Diff            @@
##             master    #5317   +/-   ##
=========================================
  Coverage     61.53%   61.53%           
  Complexity       14       14           
=========================================
  Files             2        2           
  Lines            78       78           
  Branches          4        4           
=========================================
  Hits             48       48           
  Misses           24       24           
  Partials          6        6           

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

@DanySK DanySK force-pushed the refactor/sapere/simplifyexecutionlogicin branch 8 times, most recently from 9a5d5b0 to 4571ded Compare April 29, 2026 08:47
auto-merge was automatically disabled April 29, 2026 21:26

Head branch was pushed to by a user without write access

@DanySK DanySK force-pushed the refactor/sapere/simplifyexecutionlogicin branch 2 times, most recently from b85758d to 2365dba Compare April 29, 2026 23:56
DanySK and others added 3 commits April 30, 2026 04:19
@DanySK DanySK force-pushed the refactor/sapere/simplifyexecutionlogicin branch from 2365dba to 6f31ac8 Compare April 30, 2026 02:19
@sonarqubecloud
Copy link
Copy Markdown

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

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants