-
Notifications
You must be signed in to change notification settings - Fork 171
Skip optionally the cost matrix validation check #1217
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -57,7 +57,9 @@ def __init__(self, n_locations, n_fleet, n_orders: int = -1): | |
| super().__init__(n_locations, n_fleet, n_orders=n_orders) | ||
|
|
||
| @catch_cuopt_exception | ||
| def add_cost_matrix(self, cost_mat, vehicle_type=0): | ||
| def add_cost_matrix( | ||
| self, cost_mat, vehicle_type=0, *, skip_validation=False | ||
| ): | ||
| """ | ||
| Add a matrix for all locations (vehicle/technician locations included) | ||
| at once. | ||
|
|
@@ -84,6 +86,10 @@ def add_cost_matrix(self, cost_mat, vehicle_type=0): | |
| num_location rows and columns. | ||
| vehicle_type : uint8 | ||
| Identifier of the vehicle. | ||
| skip_validation : bool | ||
| If True, skips Python validation for matrix shape, NULL values, | ||
| and non-negative values. The caller is responsible for providing | ||
| a valid square matrix matching the number of locations. | ||
|
|
||
| Examples | ||
| -------- | ||
|
|
@@ -125,7 +131,8 @@ def add_cost_matrix(self, cost_mat, vehicle_type=0): | |
| if vehicle_type in self.costs: | ||
| raise ValueError("Vehicle type matrix has already been added") | ||
|
|
||
| validate_matrix(cost_mat, "cost matrix", self.get_num_locations()) | ||
| if not skip_validation: | ||
| validate_matrix(cost_mat, "cost matrix", self.get_num_locations()) | ||
|
|
||
| super().add_cost_matrix(cost_mat, vehicle_type) | ||
|
Comment on lines
+134
to
137
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 🛠️ Refactor suggestion | 🟠 Major | ⚡ Quick win Add pytest coverage for both This change adds a new behavior branch but no tests in this PR context. Please add tests for default validation behavior and explicit skip behavior (while still validating duplicate As per coding guidelines, "python/cuopt/cuopt/**/*.py: Add unit tests for Python code using pytest, referencing examples in 🤖 Prompt for AI Agents |
||
|
|
||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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
As per coding guidelines, "Flag missing input validation at library and server boundaries."
🤖 Prompt for AI Agents