Fix NaN corruption in displace_t - #312
Conversation
Found a bug where displace_t's rt -> (rt-t) shift could produce a non-positive value with nothing checking for it before log() was called. Resulted in producing NaN and corrupting the KDE fit. Fix computes the shift once, excludes any result <= 0 by relabeling it with the existing filter sentinel, and lets the already-existing downstream filtering pull it out using the same mechanism for omitted trials.
📝 WalkthroughWalkthrough
ChangesDisplaced RT handling
Estimated code review effort: 2 (Simple) | ~10 minutes 🚥 Pre-merge checks | ✅ 5✅ Passed checks (5 passed)
✨ Finishing Touches🧪 Generate unit tests (beta)
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. Comment |
There was a problem hiding this comment.
Actionable comments posted: 1
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
Inline comments:
In `@ssms/support_utils/kde_class.py`:
- Around line 85-91: Normalize model_name by removing the supported trailing
“_deadline” suffix before checking membership in _DISPLACE_T_VALIDATED_MODELS,
while retaining the original name in the warning message. Update the validation
logic around the model_name lookup so both base models and deadline variants
such as ddm_st_deadline use the base-model allowlist entry.
🪄 Autofix (Beta)
Fix all unresolved CodeRabbit comments on this PR:
- Push a commit to this branch (recommended)
- Create a new PR with the fixes
ℹ️ Review info
⚙️ Run configuration
Configuration used: defaults
Review profile: CHILL
Plan: Pro Plus
Run ID: 3b5cbf53-93d4-4c3d-a50a-4d92f1c2c082
📒 Files selected for processing (1)
ssms/support_utils/kde_class.py
| model_name = simulator_data["metadata"].get("model") | ||
| if model_name not in _DISPLACE_T_VALIDATED_MODELS: | ||
| warnings.warn( | ||
| f"displace_t=True untested for model '{model_name}' (validated: {sorted(_DISPLACE_T_VALIDATED_MODELS)}).", | ||
| UserWarning, | ||
| stacklevel=2, | ||
| ) |
There was a problem hiding this comment.
🎯 Functional Correctness | 🟡 Minor | ⚡ Quick win
Normalize deadline-suffixed model names before allowlist lookup.
Line 86 treats a validated deadline variant such as ddm_st_deadline as untested because it cannot match the base-model allowlist entry ddm_st, producing a false warning.
Proposed fix
model_name = simulator_data["metadata"].get("model")
- if model_name not in _DISPLACE_T_VALIDATED_MODELS:
+ base_model_name = (
+ model_name.removesuffix("_deadline") if model_name else model_name
+ )
+ if base_model_name not in _DISPLACE_T_VALIDATED_MODELS:
warnings.warn(As per coding guidelines, support deadline-model naming through the _deadline suffix, such as ddm_deadline, where applicable.
📝 Committable suggestion
‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.
| model_name = simulator_data["metadata"].get("model") | |
| if model_name not in _DISPLACE_T_VALIDATED_MODELS: | |
| warnings.warn( | |
| f"displace_t=True untested for model '{model_name}' (validated: {sorted(_DISPLACE_T_VALIDATED_MODELS)}).", | |
| UserWarning, | |
| stacklevel=2, | |
| ) | |
| model_name = simulator_data["metadata"].get("model") | |
| base_model_name = ( | |
| model_name.removesuffix("_deadline") if model_name else model_name | |
| ) | |
| if base_model_name not in _DISPLACE_T_VALIDATED_MODELS: | |
| warnings.warn( | |
| f"displace_t=True untested for model '{model_name}' (validated: {sorted(_DISPLACE_T_VALIDATED_MODELS)}).", | |
| UserWarning, | |
| stacklevel=2, | |
| ) |
🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
In `@ssms/support_utils/kde_class.py` around lines 85 - 91, Normalize model_name
by removing the supported trailing “_deadline” suffix before checking membership
in _DISPLACE_T_VALIDATED_MODELS, while retaining the original name in the
warning message. Update the validation logic around the model_name lookup so
both base models and deadline variants such as ddm_st_deadline use the
base-model allowlist entry.
Source: Coding guidelines
Found a bug where displace_t's rt -> (rt-t) shift could produce a non-positive value with nothing checking for it before log() was called. Resulted in producing NaN and corrupting the KDE fit. Fix computes the shift once, excludes any result <= 0 by relabeling it with the existing filter sentinel, and lets the already-existing downstream filtering pull it out using the same mechanism for omitted trials.
New Model: [Your Model Name]
Description
Type of Contribution
Model Details
Correctness Validation
Validation details:
Testing
Documentation
Pre-Submission Checklist
pytest tests/)Additional Notes
Summary by CodeRabbit