Skip optionally the cost matrix validation check#1217
Conversation
📝 WalkthroughWalkthroughThe ChangesSkip validation parameter for cost matrix
🎯 2 (Simple) | ⏱️ ~8 minutes 🚥 Pre-merge checks | ✅ 4 | ❌ 1❌ Failed checks (1 warning)
✅ Passed checks (4 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing Touches🧪 Generate unit tests (beta)
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 `@python/cuopt/cuopt/routing/vehicle_routing.py`:
- Around line 132-133: When skip_validation is True you still need a lightweight
shape guard to avoid malformed matrices crossing into the wrapper: add a cheap
check before returning that cost_mat is a 2D sequence with outer length == n and
every row length == n (where n = self.get_num_locations()), but do not perform
the heavier NULL/non-negative content scans that validate_matrix does; update
the branch handling skip_validation around the validate_matrix call to run this
simple shape guard (using cost_mat and self.get_num_locations() as identifiers)
and only call validate_matrix when skip_validation is False.
🪄 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: Path: .coderabbit.yaml
Review profile: CHILL
Plan: Enterprise
Run ID: c0284935-6266-45f0-97fc-8eb2c739dc8b
📒 Files selected for processing (1)
python/cuopt/cuopt/routing/vehicle_routing.py
| if not skip_validation: | ||
| validate_matrix(cost_mat, "cost matrix", self.get_num_locations()) |
There was a problem hiding this comment.
Retain minimal boundary validation when skip_validation=True.
Line 132 currently skips all checks, so malformed matrix dimensions can cross the Python boundary and fail deeper in the wrapper with less actionable errors. Keep a cheap shape guard in the skip path and reserve full scans (NULL/non-negative checks) for the non-skip path.
Suggested patch
- if not skip_validation:
- validate_matrix(cost_mat, "cost matrix", self.get_num_locations())
+ n_locations = self.get_num_locations()
+ if skip_validation:
+ if (
+ len(cost_mat) != n_locations
+ or len(cost_mat.columns) != n_locations
+ ):
+ raise ValueError(
+ "cost matrix must be square with size equal to "
+ "number of locations"
+ )
+ else:
+ validate_matrix(cost_mat, "cost matrix", n_locations)As per coding guidelines, "Flag missing input validation at library and server boundaries."
🤖 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 `@python/cuopt/cuopt/routing/vehicle_routing.py` around lines 132 - 133, When
skip_validation is True you still need a lightweight shape guard to avoid
malformed matrices crossing into the wrapper: add a cheap check before returning
that cost_mat is a 2D sequence with outer length == n and every row length == n
(where n = self.get_num_locations()), but do not perform the heavier
NULL/non-negative content scans that validate_matrix does; update the branch
handling skip_validation around the validate_matrix call to run this simple
shape guard (using cost_mat and self.get_num_locations() as identifiers) and
only call validate_matrix when skip_validation is False.
Boosts performance when many problems are scheduled in a loop with large matrices