Conversation
…error handling, importlib usage Co-authored-by: mdoucet <1108748+mdoucet@users.noreply.github.com>
…t structure with comprehensive assertions and edge case testing Co-authored-by: mdoucet <1108748+mdoucet@users.noreply.github.com>
Copilot
AI
changed the title
[WIP] PR review
Address PR review comments: improve configurability, error handling, and testing
Sep 28, 2025
mdoucet
approved these changes
Sep 29, 2025
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.
This PR addresses all 11 comments from the code review to improve code quality, robustness, and testability across the planner module.
Key Changes
Enhanced Configurability
Previously hardcoded values are now configurable with sensible defaults:
perform_mcmc()is now configurable (default: 0.025)add_instrumental_noise()are now configurable (min: 0.01, base: 0.05)Improved Error Handling and Safety
exc_info=Trueand regularized fallback to MVN entropy calculationnp.max(q_values)is zerosys.pathinjection withimportlib.util.spec_from_file_location()for cleaner, safer module importsComprehensive Testing Infrastructure
Converted
test_planner.pyfrom a simple script with print statements to a proper pytest test suite:Code Quality Improvements
Example Usage
The new configurable parameters allow for more flexible experimental setups:
Quality Assurance
This PR makes the codebase more maintainable, testable, and robust while preserving all existing functionality.
Original prompt
This section details on the original issue you should resolve
<issue_title>PR review</issue_title>
<issue_description>Please address the comments from this code review:
Overall Comments
Individual Comments
Comment 1
analyzer_tools/planner/experiment_design.py:204-205<code_context>
</code_context>
<issue_to_address>
suggestion: Hardcoded Q resolution scaling may not generalize to all instruments.
Consider making the Q resolution scaling factor configurable to accommodate different experimental setups.
Suggested implementation:
""" # Prepare FitProblem probe = QProbe(q_values, q_values * q_resolution_scale, R=noisy_reflectivity, dR=errors) expt = Experiment(sample=self.experiment.sample, probe=probe) problem = FitProblem(expt) problem.model_update()your_function_namewith the actual function name in your code.q_resolution_scaleif a value other than the default is needed.</issue_to_address>
Comment 2
analyzer_tools/planner/experiment_design.py:297-306<code_context>
</code_context>
<issue_to_address>
suggestion (bug_risk): KDE fallback to MVN may mask underlying issues.
Consider logging exception details or improving error handling to ensure issues with KDE or sample data are visible.
Suggested implementation:
</issue_to_address>
Comment 3
analyzer_tools/planner/instrument.py:23-24<code_context>
Simple noise model: relative error inversely proportional to sqrt(R * counting_time)
Calculate relative errors - more realistic model
</code_context>
<issue_to_address>
suggestion: Hardcoded error parameters may limit flexibility.
Consider making min_relative_error and base_relative_error configurable via function arguments to support varying instrument requirements.
Suggested implementation: