Skip to content

Skip optionally the cost matrix validation check#1217

Open
hlinsen wants to merge 1 commit into
NVIDIA:mainfrom
hlinsen:matrix-validation
Open

Skip optionally the cost matrix validation check#1217
hlinsen wants to merge 1 commit into
NVIDIA:mainfrom
hlinsen:matrix-validation

Conversation

@hlinsen
Copy link
Copy Markdown
Contributor

@hlinsen hlinsen commented May 14, 2026

Boosts performance when many problems are scheduled in a loop with large matrices

@hlinsen hlinsen added the non-breaking Introduces a non-breaking change label May 14, 2026
@hlinsen hlinsen requested a review from a team as a code owner May 14, 2026 06:43
@hlinsen hlinsen added the improvement Improves an existing functionality label May 14, 2026
@hlinsen hlinsen requested a review from rgsl888prabhu May 14, 2026 06:43
@coderabbitai
Copy link
Copy Markdown

coderabbitai Bot commented May 14, 2026

Review Change Stack

📝 Walkthrough

Walkthrough

The DataModel.add_cost_matrix method now accepts an optional skip_validation keyword-only parameter (default False). When enabled, validation via validate_matrix is bypassed. The method signature, docstring documentation, and conditional validation logic are updated together.

Changes

Skip validation parameter for cost matrix

Layer / File(s) Summary
Add skip_validation parameter and conditional validation logic
python/cuopt/cuopt/routing/vehicle_routing.py
Method signature adds keyword-only skip_validation parameter; docstring documents parameter behavior and validation responsibilities; conditional logic skips validate_matrix call when skip_validation=True.

🎯 2 (Simple) | ⏱️ ~8 minutes

🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 50.00% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (4 passed)
Check name Status Explanation
Title check ✅ Passed The title accurately describes the main change: adding an optional skip of the cost matrix validation check in the DataModel.add_cost_matrix method.
Description check ✅ Passed The description is directly related to the changeset, explaining the performance benefit motivation for skipping the optional validation check.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.

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

✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests

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

Copy link
Copy Markdown

@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

🤖 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

📥 Commits

Reviewing files that changed from the base of the PR and between 20e15cd and 8cac3fb.

📒 Files selected for processing (1)
  • python/cuopt/cuopt/routing/vehicle_routing.py

Comment on lines +132 to +133
if not skip_validation:
validate_matrix(cost_mat, "cost matrix", self.get_num_locations())
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

⚠️ Potential issue | 🟠 Major | ⚡ Quick win

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.

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

Labels

improvement Improves an existing functionality non-breaking Introduces a non-breaking change

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants