Skip to content

python: add solve_batch aliases for LP and routing#1260

Closed
Pritiks23 wants to merge 5 commits into
NVIDIA:mainfrom
Pritiks23:feat/python-solve-batch-alias
Closed

python: add solve_batch aliases for LP and routing#1260
Pritiks23 wants to merge 5 commits into
NVIDIA:mainfrom
Pritiks23:feat/python-solve-batch-alias

Conversation

@Pritiks23

Copy link
Copy Markdown

Why this change

Users naturally expect a snake_case batch API in Python (solve_batch([...])) that mirrors common ML serving patterns (single-call batch inference).

cuOpt already has batch solving support through BatchSolve(...), but discoverability is lower and naming is inconsistent with common Python style.

This PR improves API ergonomics without changing solver behavior.

What we changed

  1. Added solve_batch(...) aliases for:
    • Linear programming solver
    • Routing solver
  2. Exported the new alias from public module entry points so users can access it directly.
  3. Kept BatchSolve(...) fully intact for backward compatibility.
  4. Added tests that verify solve_batch(...) returns the same outcomes as BatchSolve(...).
  5. Updated routing API coverage documentation to include the new alias.

What we did NOT change

  • No solver-engine algorithm changes.
  • No status/termination semantics changes.
  • No removal or deprecation of BatchSolve(...).

User impact

Before:

  • Users needed to discover and call BatchSolve(...).

After:

  • Users can call either BatchSolve(...) or the clearer Python-style solve_batch(...).
  • Existing code continues to work unchanged.

Compatibility and risk

  • Additive, low-risk API improvement.
  • Existing integrations remain valid.
  • New tests guard alias parity with existing batch path.

Testing

  • Added targeted unit tests for LP and routing alias parity.
  • In this session, runtime execution of those tests was environment-gated because required runtime deps (cuopt/cudf) were unavailable in the shell; tests are included in the PR for CI validation.

Signed-off-by: Pritika Vipin <65793273+Pritiks23@users.noreply.github.com>
@copy-pr-bot

copy-pr-bot Bot commented May 20, 2026

Copy link
Copy Markdown

This pull request requires additional validation before any workflows can run on NVIDIA's runners.

Pull request vetters can view their responsibilities here.

Contributors can view more details about this message here.

@Pritiks23 Pritiks23 marked this pull request as ready for review May 20, 2026 20:33
@Pritiks23 Pritiks23 requested a review from a team as a code owner May 20, 2026 20:33
@Pritiks23 Pritiks23 requested a review from tmckayus May 20, 2026 20:33
@coderabbitai

coderabbitai Bot commented May 20, 2026

Copy link
Copy Markdown

Review Change Stack

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Enterprise

Run ID: b6b23e78-b2b8-45c5-b183-ad6e22fbb99e

📥 Commits

Reviewing files that changed from the base of the PR and between 1e5ee79 and d96a29a.

📒 Files selected for processing (4)
  • python/cuopt/cuopt/linear_programming/solver/solver.py
  • python/cuopt/cuopt/routing/vehicle_routing.py
  • python/cuopt/cuopt/tests/linear_programming/test_lp_solver.py
  • python/cuopt/cuopt/tests/routing/test_batch_solve.py

📝 Walkthrough

Walkthrough

This PR adds snake_case solve_batch aliases for batch solving in linear programming and routing, re-exports them through each package, and adds tests and API coverage entries validating functional equivalence and input validation.

Changes

Batch solving snake_case aliases

Layer / File(s) Summary
Linear Programming solve_batch alias
python/cuopt/cuopt/linear_programming/solver/solver.py, python/cuopt/cuopt/linear_programming/solver/__init__.py, python/cuopt/cuopt/linear_programming/__init__.py, python/cuopt/cuopt/tests/linear_programming/test_lp_solver.py
Adds solve_batch as a @catch_cuopt_exception wrapper delegating to BatchSolve, re-exports it through solver and top-level LP package, and adds a test asserting list length, solve time, termination status, and objective equality.
Routing solve_batch alias
python/cuopt/cuopt/routing/vehicle_routing.py, python/cuopt/cuopt/routing/__init__.py, python/cuopt/cuopt/tests/routing/test_batch_solve.py, python/cuopt/cuopt/tests/routing/API_COVERAGE.md
Adds solve_batch as a @catch_cuopt_exception wrapper delegating to BatchSolve, re-exports it via routing __init__.py, updates API coverage, and adds tests for result equivalence and input validation (raises ValueError for None).

Estimated code review effort

🎯 2 (Simple) | ⏱️ ~10 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 clearly and concisely summarizes the main change: adding snake_case solve_batch aliases for both LP and routing solvers.
Description check ✅ Passed The description is comprehensive and directly related to the changeset, explaining the rationale, changes made, testing, and impact.
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.

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Actionable comments posted: 2

🧹 Nitpick comments (2)
python/cuopt/cuopt/tests/routing/test_batch_solve.py (1)

86-91: ⚡ Quick win

Add objective/route parity checks in alias test.

Status + vehicle-count parity is good, but it can still miss behavioral drift; include objective (and ideally route) equality checks to verify real output equivalence.

Proposed assertion additions
     for batch_solution, alias_solution in zip(batch_solutions, alias_solutions):
         assert batch_solution.get_status() == alias_solution.get_status()
         assert (
             batch_solution.get_vehicle_count()
             == alias_solution.get_vehicle_count()
         )
+        assert batch_solution.get_total_objective() == pytest.approx(
+            alias_solution.get_total_objective()
+        )
As per coding guidelines, "Flag 'runs without error' tests that don't validate numerical correctness".
🤖 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/tests/routing/test_batch_solve.py` around lines 86 - 91,
Add assertions to verify numerical and route parity between batch_solution and
alias_solution in addition to status and vehicle count: assert equality on the
objective value (e.g., batch_solution.get_objective() ==
alias_solution.get_objective() or get_total_cost()/get_cost() if that API
exists) and assert route-level equality by comparing route lists or per-vehicle
sequences (e.g., batch_solution.get_routes() == alias_solution.get_routes() or
iterate vehicles and compare each vehicle's route sequence). Use the existing
symbols batch_solution and alias_solution and keep checks consistent with the
solution object's API.
python/cuopt/cuopt/tests/linear_programming/test_lp_solver.py (1)

534-538: ⚡ Quick win

Strengthen alias-parity assertions beyond termination status.

This test currently validates mostly control-path parity; add at least objective/value parity checks to enforce numerical equivalence between BatchSolve and solve_batch.

Proposed assertion additions
     for i in range(nb_solves):
         assert (
             batch_solutions[i].get_termination_status()
             == alias_solutions[i].get_termination_status()
         )
+        assert batch_solutions[i].get_primal_objective() == pytest.approx(
+            alias_solutions[i].get_primal_objective()
+        )
+        assert batch_solutions[i].get_dual_objective() == pytest.approx(
+            alias_solutions[i].get_dual_objective()
+        )
As per coding guidelines, "Flag 'runs without error' tests that don't validate numerical correctness".
🤖 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/tests/linear_programming/test_lp_solver.py` around lines
534 - 538, The loop currently only asserts termination parity; expand it to also
assert numerical parity by comparing objective values (e.g., call the solution
objective getter such as get_objective_value() or the concrete API method used
in this test suite) for batch_solutions[i] vs alias_solutions[i] for each i in
range(nb_solves), and additionally assert any available numeric metrics (e.g.,
primal/dual values or gap if the Solution API exposes
get_primal_value()/get_dual_value()/get_gap()) to ensure BatchSolve and
solve_batch produce numerically equivalent results as well as the same
termination status.
🤖 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/linear_programming/solver/solver.py`:
- Around line 192-194: The public function solve_batch currently lacks type
annotations and a full docstring; update the function signature for solve_batch
to include precise type hints for data_model_list (e.g., Sequence[DataModel] or
List[YourDataModelType]) and solver_settings (e.g.,
Optional[SolverSettingsType]) and the return type (e.g., BatchSolveResult or
appropriate type returned by BatchSolve), and add a complete pydocstyle
docstring documenting Parameters (types and meaning), Returns (type and
description), and Raises (exceptions that BatchSolve may propagate); ensure you
reference the existing BatchSolve wrapper behavior in the docstring and
import/forward any type names needed for annotations so the public API is fully
typed and documented.

In `@python/cuopt/cuopt/routing/vehicle_routing.py`:
- Around line 1604-1606: The public alias solve_batch currently lacks type hints
and a complete API docstring; update the signature to include proper type
annotations (e.g., typing.List[YourDataModelType],
Optional[YourSolverSettingsType] -> ReturnType) and expand its docstring to
include params, returns, and raises sections mirroring BatchSolve's contract.
Specifically, modify solve_batch to annotate the parameters and return value,
document the parameters (data_model_list, solver_settings), the return value
(what BatchSolve returns), and any exceptions that can be raised when calling
BatchSolve so callers have full API and type information. Ensure the docstring
style matches project pydocstyle conventions and reference BatchSolve in the
description.

---

Nitpick comments:
In `@python/cuopt/cuopt/tests/linear_programming/test_lp_solver.py`:
- Around line 534-538: The loop currently only asserts termination parity;
expand it to also assert numerical parity by comparing objective values (e.g.,
call the solution objective getter such as get_objective_value() or the concrete
API method used in this test suite) for batch_solutions[i] vs alias_solutions[i]
for each i in range(nb_solves), and additionally assert any available numeric
metrics (e.g., primal/dual values or gap if the Solution API exposes
get_primal_value()/get_dual_value()/get_gap()) to ensure BatchSolve and
solve_batch produce numerically equivalent results as well as the same
termination status.

In `@python/cuopt/cuopt/tests/routing/test_batch_solve.py`:
- Around line 86-91: Add assertions to verify numerical and route parity between
batch_solution and alias_solution in addition to status and vehicle count:
assert equality on the objective value (e.g., batch_solution.get_objective() ==
alias_solution.get_objective() or get_total_cost()/get_cost() if that API
exists) and assert route-level equality by comparing route lists or per-vehicle
sequences (e.g., batch_solution.get_routes() == alias_solution.get_routes() or
iterate vehicles and compare each vehicle's route sequence). Use the existing
symbols batch_solution and alias_solution and keep checks consistent with the
solution object's API.
🪄 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: 8ac3bf12-0774-42b7-aa2a-4a2fcf877822

📥 Commits

Reviewing files that changed from the base of the PR and between 37814ed and 1e5ee79.

📒 Files selected for processing (8)
  • python/cuopt/cuopt/linear_programming/__init__.py
  • python/cuopt/cuopt/linear_programming/solver/__init__.py
  • python/cuopt/cuopt/linear_programming/solver/solver.py
  • python/cuopt/cuopt/routing/__init__.py
  • python/cuopt/cuopt/routing/vehicle_routing.py
  • python/cuopt/cuopt/tests/linear_programming/test_lp_solver.py
  • python/cuopt/cuopt/tests/routing/API_COVERAGE.md
  • python/cuopt/cuopt/tests/routing/test_batch_solve.py

Comment thread python/cuopt/cuopt/linear_programming/solver/solver.py Outdated
Comment thread python/cuopt/cuopt/routing/vehicle_routing.py Outdated
Signed-off-by: Pritika Vipin <65793273+Pritiks23@users.noreply.github.com>
@mlubin

mlubin commented May 20, 2026

Copy link
Copy Markdown
Contributor

The BatchSolve API is deprecated, see #915. We will not be providing new aliases for it.

@Pritiks23 Pritiks23 closed this May 20, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants