Skip to content

Check if either of BayesianSimple / MarkovChainMC#1244

Open
nucleosynthesis wants to merge 1 commit intomainfrom
nckw_add_check_for_Bayesian_discretes
Open

Check if either of BayesianSimple / MarkovChainMC#1244
nucleosynthesis wants to merge 1 commit intomainfrom
nckw_add_check_for_Bayesian_discretes

Conversation

@nucleosynthesis
Copy link
Copy Markdown
Contributor

@nucleosynthesis nucleosynthesis commented Mar 24, 2026

Throw error if either are being used with discrete parameters, as currently this won't make any sense in combine.

Summary by CodeRabbit

Bug Fixes

  • Added validation to prevent incompatible configurations. The system now detects and rejects discrete parameters when using Bayesian algorithms that don't support them, providing clearer error messages.

Throw error if either are being used with discrete parameters, as currently this won't make any sense in combine.
@coderabbitai
Copy link
Copy Markdown
Contributor

coderabbitai bot commented Mar 24, 2026

📝 Walkthrough

Walkthrough

The addDiscreteNuisances method changes from returning void to bool. The implementation now tracks discrete parameter detection via a new flag and returns its state. The caller in Combine::run branches based on this return value to reject Bayesian methods with discrete parameters.

Changes

Cohort / File(s) Summary
Discrete Nuisance Detection Return Value
interface/Combine.h, src/Combine.cc
Method signature and implementation updated: addDiscreteNuisances now returns bool instead of void. Implementation introduces a hasDiscrete flag that tracks whether discrete parameters are found (either directly or via pdfindex fallback), and returns this flag. Caller in Combine::run captures the return value and enforces a new guard: if the algorithm is BayesianSimple or MarkovChainMC and discrete parameters exist, an std::invalid_argument exception is thrown.

Estimated code review effort

🎯 2 (Simple) | ⏱️ ~12 minutes

Poem

🐰 A method once silent now speaks its truth,
Returning a whisper of discrete sleuths,
When Bayes comes calling with parameters in tow,
We kindly reject what we simply can't know! 🌿

🚥 Pre-merge checks | ✅ 1 | ❌ 2

❌ Failed checks (1 warning, 1 inconclusive)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 0.00% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
Title check ❓ Inconclusive The title partially describes the change but is vague and incomplete. It mentions checking for BayesianSimple/MarkovChainMC but omits the key purpose: preventing their use with discrete parameters. Consider a more descriptive title like 'Disallow discrete parameters with BayesianSimple and MarkovChainMC' or 'Add validation to prevent discrete parameters in Bayesian methods'.
✅ Passed checks (1 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
📝 Generate docstrings
  • Create stacked PR
  • Commit on current branch
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch nckw_add_check_for_Bayesian_discretes

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

Copy link
Copy Markdown
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 1

Caution

Some comments are outside the diff and can’t be posted inline due to platform limitations.

⚠️ Outside diff range comments (1)
src/Combine.cc (1)

1203-1256: ⚠️ Potential issue | 🟡 Minor

Fix clang-format issues flagged by CI.

The implementation correctly tracks discrete parameter detection through both the explicit discreteParams path and the pdfindex fallback path. The CI pipeline reports formatting mismatches in this function - please run clang-format to resolve them.

🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@src/Combine.cc` around lines 1203 - 1256, The function
Combine::addDiscreteNuisances has clang-format style mismatches; run
clang-format on this function and fix whitespace/indentation to match project
style (e.g., align braces, spaces around operators, consistent indentation
inside the for/if blocks and around method calls). Reformat occurrences inside
Combine::addDiscreteNuisances where
CascadeMinimizerGlobalConfigs::O().pdfCategories, pdfindex fallback branch, the
loop over clients, and the nested loops that build allRooMultiPdfParams are
defined so the file compiles with CI formatting checks; ensure lines with
CombineLogger::instance().log and Form(...) follow the repository's formatting
rules. After formatting, stage the changes for this file only and re-run CI.
🧹 Nitpick comments (1)
src/Combine.cc (1)

810-812: Consider improving the error message for accuracy.

The error message suggests removing ADD_DISCRETE_FALLBACK, but looking at the logic in addDiscreteNuisances (line 1215), hasDiscrete becomes true if any category is non-constant, regardless of whether ADD_DISCRETE_FALLBACK is set. The suggestion to "remove runtime def option ADD_DISCRETE_FALLBACK" only helps in specific edge cases.

A clearer message might be:

throw std::invalid_argument(
    "Cannot currently use discrete parameters with Bayesian methods. "
    "Either freeze all discrete parameters to constant, or use a different method.");
🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@src/Combine.cc` around lines 810 - 812, The error message thrown in
Combine.cc when (algo->name() == "BayesianSimple" || algo->name() ==
"MarkovChainMC") && wsHasDiscretes is misleading because wsHasDiscretes (set via
addDiscreteNuisances/hasDiscrete) can be true independent of
ADD_DISCRETE_FALLBACK; update the std::invalid_argument text to accurately
reflect the condition (mention freezing discrete parameters or choosing a
different algorithm) and remove the suggestion to "remove runtime def option
ADD_DISCRETE_FALLBACK"; change the message near the check that uses
algo->name(), BayesianSimple, MarkovChainMC, and wsHasDiscretes to the clearer
wording.
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.

Inline comments:
In `@src/Combine.cc`:
- Around line 807-812: The block around addDiscreteNuisances(w) and the Bayesian
check is failing clang-format; reformat the if-statement and surrounding lines
(the call to addDiscreteNuisances, the wsHasDiscretes variable and the if that
checks algo->name() == "BayesianSimple" || algo->name() == "MarkovChainMC") to
match project style—run clang-format on src/Combine.cc or manually adjust
spacing/brace placement so the throw std::invalid_argument line and the if
condition adhere to the codebase's formatting rules.

---

Outside diff comments:
In `@src/Combine.cc`:
- Around line 1203-1256: The function Combine::addDiscreteNuisances has
clang-format style mismatches; run clang-format on this function and fix
whitespace/indentation to match project style (e.g., align braces, spaces around
operators, consistent indentation inside the for/if blocks and around method
calls). Reformat occurrences inside Combine::addDiscreteNuisances where
CascadeMinimizerGlobalConfigs::O().pdfCategories, pdfindex fallback branch, the
loop over clients, and the nested loops that build allRooMultiPdfParams are
defined so the file compiles with CI formatting checks; ensure lines with
CombineLogger::instance().log and Form(...) follow the repository's formatting
rules. After formatting, stage the changes for this file only and re-run CI.

---

Nitpick comments:
In `@src/Combine.cc`:
- Around line 810-812: The error message thrown in Combine.cc when (algo->name()
== "BayesianSimple" || algo->name() == "MarkovChainMC") && wsHasDiscretes is
misleading because wsHasDiscretes (set via addDiscreteNuisances/hasDiscrete) can
be true independent of ADD_DISCRETE_FALLBACK; update the std::invalid_argument
text to accurately reflect the condition (mention freezing discrete parameters
or choosing a different algorithm) and remove the suggestion to "remove runtime
def option ADD_DISCRETE_FALLBACK"; change the message near the check that uses
algo->name(), BayesianSimple, MarkovChainMC, and wsHasDiscretes to the clearer
wording.

ℹ️ Review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro

Run ID: b964854e-e9d6-4ff7-b6ee-3ba8e040248f

📥 Commits

Reviewing files that changed from the base of the PR and between c5c3dc3 and 4c5cb6c.

📒 Files selected for processing (2)
  • interface/Combine.h
  • src/Combine.cc

Comment on lines +807 to +812
bool wsHasDiscretes = addDiscreteNuisances(w);

// Add a check that we're not trying to use discrete profiling with Bayesian methods
if ((algo->name() == "BayesianSimple" || algo->name() == "MarkovChainMC") && wsHasDiscretes){
throw std::invalid_argument("Cannot currently use discrete parameters with Bayesian methods. Either remove discrete parameters or remove runtime def option ADD_DISCRETE_FALLBACK");
}
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.

⚠️ Potential issue | 🟡 Minor

Fix clang-format issues flagged by CI.

The logic correctly prevents Bayesian methods from being used with discrete parameters. However, the CI pipeline reports clang-format failures in this block. Please run clang-format to fix the formatting.

🔧 Suggested formatting fix
   // Setup the CascadeMinimizer with discrete nuisances
-  bool wsHasDiscretes = addDiscreteNuisances(w);
-
-  // Add a check that we're not trying to use discrete profiling with Bayesian methods 
-  if ((algo->name() == "BayesianSimple" || algo->name() == "MarkovChainMC") && wsHasDiscretes){
-      throw std::invalid_argument("Cannot currently use discrete parameters with Bayesian methods. Either remove discrete parameters or remove runtime def option ADD_DISCRETE_FALLBACK");
-  }
+  bool wsHasDiscretes = addDiscreteNuisances(w);

+  // Add a check that we're not trying to use discrete profiling with Bayesian methods
+  if ((algo->name() == "BayesianSimple" || algo->name() == "MarkovChainMC") && wsHasDiscretes) {
+    throw std::invalid_argument(
+        "Cannot currently use discrete parameters with Bayesian methods. Either remove discrete "
+        "parameters or remove runtime def option ADD_DISCRETE_FALLBACK");
+  }
🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@src/Combine.cc` around lines 807 - 812, The block around
addDiscreteNuisances(w) and the Bayesian check is failing clang-format; reformat
the if-statement and surrounding lines (the call to addDiscreteNuisances, the
wsHasDiscretes variable and the if that checks algo->name() == "BayesianSimple"
|| algo->name() == "MarkovChainMC") to match project style—run clang-format on
src/Combine.cc or manually adjust spacing/brace placement so the throw
std::invalid_argument line and the if condition adhere to the codebase's
formatting rules.

@codecov
Copy link
Copy Markdown

codecov bot commented Mar 24, 2026

Codecov Report

❌ Patch coverage is 75.00000% with 2 lines in your changes missing coverage. Please review.
✅ Project coverage is 20.90%. Comparing base (c5c3dc3) to head (4c5cb6c).

Files with missing lines Patch % Lines
src/Combine.cc 75.00% 2 Missing ⚠️

❌ Your patch check has failed because the patch coverage (75.00%) is below the target coverage (98.00%). You can increase the patch coverage or adjust the target coverage.

Additional details and impacted files

Impacted file tree graph

@@            Coverage Diff             @@
##             main    #1244      +/-   ##
==========================================
+ Coverage   20.89%   20.90%   +0.01%     
==========================================
  Files         195      195              
  Lines       26310    26316       +6     
  Branches     3947     3947              
==========================================
+ Hits         5498     5502       +4     
- Misses      20812    20814       +2     
Files with missing lines Coverage Δ
interface/Combine.h 100.00% <ø> (ø)
src/Combine.cc 50.28% <75.00%> (+0.11%) ⬆️
Files with missing lines Coverage Δ
interface/Combine.h 100.00% <ø> (ø)
src/Combine.cc 50.28% <75.00%> (+0.11%) ⬆️
🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

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.

1 participant