Skip to content

update doc for usage of incumbent utility function#947

Merged
rapids-bot[bot] merged 7 commits intoNVIDIA:release/26.04from
Iroy30:update_incumbent_doc
Mar 21, 2026
Merged

update doc for usage of incumbent utility function#947
rapids-bot[bot] merged 7 commits intoNVIDIA:release/26.04from
Iroy30:update_incumbent_doc

Conversation

@Iroy30
Copy link
Member

@Iroy30 Iroy30 commented Mar 10, 2026

Description

Issue

Closes #932

Checklist

  • I am familiar with the Contributing Guidelines.
  • Testing
    • New or existing tests cover these changes
    • Added tests
    • Created an issue to follow-up
    • NA
  • Documentation
    • The documentation is up to date with these changes
    • Added new documentation
    • NA

@Iroy30 Iroy30 requested a review from a team as a code owner March 10, 2026 02:05
@Iroy30 Iroy30 requested a review from tmckayus March 10, 2026 02:05
@copy-pr-bot
Copy link

copy-pr-bot bot commented Mar 10, 2026

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.

@coderabbitai
Copy link

coderabbitai bot commented Mar 10, 2026

📝 Walkthrough

Walkthrough

Docstring for Problem.getIncumbentValues was expanded to clarify its role extracting incumbent variable values during Solve incumbent callbacks. Example and tutorial code were updated to pass problem and variable lists into IncumbentCallback and to use Problem.getIncumbentValues for per-variable reporting; example outputs were adjusted accordingly.

Changes

Cohort / File(s) Summary
Core docstring
python/cuopt/cuopt/linear_programming/problem.py
Expanded Problem.getIncumbentValues docstring to document usage during Solve incumbent callbacks and to describe solution (list-like incumbent values) and vars (list of Variable instances). No implementation logic changes.
Examples — docs (incumbent example)
docs/cuopt/source/cuopt-python/lp-qp-milp/examples/incumbent_solutions_example.py
Refactored IncumbentCallback to accept (problem, variables, user_data), store problem/variables, use problem.getIncumbentValues(...) to extract tracked variable values, and change stored/printed incumbent records to named VariableName=value pairs. Updated main() to name variables and pass them into the callback.
Docs — rendered example text
docs/cuopt/source/cuopt-python/lp-qp-milp/lp-qp-milp-examples.rst
Updated the displayed console output for the incumbent example to use named-variable formatting, adjusted solve-time and final-solution formatting/precision, and added a “Total incumbent solutions found” line.
Skills/tutorial example
skills/cuopt-lp-milp-api-python/assets/milp_basic/incumbent_callback.py
Changed IncumbentCallback.__init__ signature to (problem, variables, user_data), switched incumbent extraction from coercing the raw solution to calling problem.getIncumbentValues(solution, self.variables), and updated logging to print comma-separated variable values with cost.

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~20 minutes

🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 42.86% 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 'update doc for usage of incumbent utility function' clearly and concisely describes the main change: documenting usage of the incumbent utility function.
Description check ✅ Passed The PR description is related to the changeset, referencing issue #932 and marking documentation as updated, which aligns with the changes made.
Linked Issues check ✅ Passed The PR directly addresses issue #932 by demonstrating usage of the incumbent utility function through updated documentation and examples showing how to extract solution values via the Problem API.
Out of Scope Changes check ✅ Passed All changes are in-scope: docstring clarifications, example code updates, and documentation output reflecting the improved incumbent utility usage pattern.

✏️ 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

@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.

🧹 Nitpick comments (1)
python/cuopt/cuopt/linear_programming/problem.py (1)

1704-1720: LGTM! Documentation improvement is clear and helpful.

The expanded docstring properly describes the method's purpose and parameters for the incumbent callback use case.

One optional enhancement: consider adding a Returns section to document the return type (List[float]) for completeness.

📝 Optional: Add Returns section
         vars : List[:py:class:`Variable`]
             List of variables to extract corresponding incumbent values.
+
+        Returns
+        -------
+        List[float]
+            List of incumbent values corresponding to the given variables.
         """
🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@python/cuopt/cuopt/linear_programming/problem.py` around lines 1704 - 1720,
Add a Returns section to the getIncumbentValues docstring that documents the
return type and contents (List[float] of incumbent values corresponding to the
input vars). Update the docstring for the function getIncumbentValues to include
a "Returns" heading describing that the function returns a list of floats (one
value per variable in vars) and any brief detail about ordering or length
matching vars.
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.

Nitpick comments:
In `@python/cuopt/cuopt/linear_programming/problem.py`:
- Around line 1704-1720: Add a Returns section to the getIncumbentValues
docstring that documents the return type and contents (List[float] of incumbent
values corresponding to the input vars). Update the docstring for the function
getIncumbentValues to include a "Returns" heading describing that the function
returns a list of floats (one value per variable in vars) and any brief detail
about ordering or length matching vars.

ℹ️ Review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Pro

Run ID: 6486bf37-ef1e-44fb-be8d-0782be892a49

📥 Commits

Reviewing files that changed from the base of the PR and between 2b21118 and 15e43e6.

📒 Files selected for processing (1)
  • python/cuopt/cuopt/linear_programming/problem.py

@anandhkb anandhkb added this to the 26.04 milestone Mar 10, 2026
@anandhkb anandhkb added the doc Improvements or additions to documentation label Mar 10, 2026
@rgsl888prabhu
Copy link
Collaborator

@Iroy30 Also lets add this usage in one of the documentation example to showcase the usage.

@rgsl888prabhu rgsl888prabhu added bug Something isn't working improvement Improves an existing functionality non-breaking Introduces a non-breaking change and removed bug Something isn't working improvement Improves an existing functionality labels Mar 18, 2026
@rgsl888prabhu rgsl888prabhu changed the base branch from main to release/26.04 March 19, 2026 16:32
@rgsl888prabhu
Copy link
Collaborator

/ok to test 38f0a8d

Copy link

@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: 2

🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.

Inline comments:
In
`@docs/cuopt/source/cuopt-python/lp-qp-milp/examples/incumbent_solutions_example.py`:
- Around line 31-37: Update the docstring expected output to match the runtime
prints: replace comma-separated "x=..., y=..." lines in the example output with
the space-separated pairs produced by the callback and final print blocks (e.g.,
align the "Incumbent 1: ..." and "Final solution: ..." lines to use the same
space-separated formatting shown at runtime); locate the output strings in the
example file (incumbent_solutions_example.py) where the docstring contains the
expected output block and make the formatting consistent with the actual prints
emitted by the callback and final print statements.
- Around line 116-119: Remove the unnecessary f-string and the unused enumerate
index in the final-solution print block: change the first print call to a plain
print (no f prefix) and iterate directly over problem.getVariables() instead of
using enumerate so the unused loop variable i is gone; keep using
var.VariableName and var.getValue() to print each variable and keep printing
problem.ObjValue for the final objective value.

ℹ️ Review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Pro

Run ID: a6ae27a6-98c3-4f97-b14d-31b453213279

📥 Commits

Reviewing files that changed from the base of the PR and between 1949267 and 955d253.

📒 Files selected for processing (3)
  • docs/cuopt/source/cuopt-python/lp-qp-milp/examples/incumbent_solutions_example.py
  • docs/cuopt/source/cuopt-python/lp-qp-milp/lp-qp-milp-examples.rst
  • skills/cuopt-lp-milp-api-python/assets/milp_basic/incumbent_callback.py

Comment on lines +31 to 37
Incumbent 1: x=36.0, y=41.0, cost: 303.00

=== Final Results ===
Problem status: Optimal
Solve time: 0.16 seconds
Solve time: 0.27 seconds
Final solution: x=36.0, y=41.0
Final objective value: 303.00
Copy link

Choose a reason for hiding this comment

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

⚠️ Potential issue | 🟡 Minor

Docstring expected output formatting is out of sync with actual prints.

The expected output uses comma-separated formatting (x=..., y=...), but the callback/final print blocks output space-separated pairs. Please align the docstring output with runtime output to avoid confusion.

✏️ Suggested docstring sync
-    Incumbent 1: x=36.0, y=41.0, cost: 303.00
+    Incumbent 1: x=36.0 y=41.0 cost: 303.00
...
-    Final solution: x=36.0, y=41.0
+    Final solution:  x=36.0  y=41.0

As per coding guidelines, docs/**/* changes should prioritize accuracy and consistency between examples and behavior.

🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In
`@docs/cuopt/source/cuopt-python/lp-qp-milp/examples/incumbent_solutions_example.py`
around lines 31 - 37, Update the docstring expected output to match the runtime
prints: replace comma-separated "x=..., y=..." lines in the example output with
the space-separated pairs produced by the callback and final print blocks (e.g.,
align the "Incumbent 1: ..." and "Final solution: ..." lines to use the same
space-separated formatting shown at runtime); locate the output strings in the
example file (incumbent_solutions_example.py) where the docstring contains the
expected output block and make the formatting consistent with the actual prints
emitted by the callback and final print statements.

Comment on lines +116 to +119
print(f"Final solution: ", end=' ')
for i, var in enumerate(problem.getVariables()):
print(f"{var.VariableName}={var.getValue()} ", end=' ')
print(f"\nFinal objective value: {problem.ObjValue:.2f}")
Copy link

Choose a reason for hiding this comment

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

⚠️ Potential issue | 🟠 Major

🧩 Analysis chain

🏁 Script executed:

#!/bin/bash
# Verify Ruff findings on the updated example file.
ruff check docs/cuopt/source/cuopt-python/lp-qp-milp/examples/incumbent_solutions_example.py

Repository: NVIDIA/cuopt

Length of output: 1579


Fix Ruff violations F541 and B007 in final-solution print block.

Line 116 uses an f-string without placeholders, and line 117 introduces an unused loop variable i. Apply the suggested fix to remove the extraneous f prefix and eliminate the unused enumeration index.

Suggested fix
-    print(f"Final solution: ", end=' ')
-    for i, var in enumerate(problem.getVariables()):
-        print(f"{var.VariableName}={var.getValue()} ", end=' ')
+    print("Final solution:", end="")
+    for var in problem.getVariables():
+        print(f" {var.VariableName}={var.getValue()}", end="")
     print(f"\nFinal objective value: {problem.ObjValue:.2f}")
🧰 Tools
🪛 Ruff (0.15.6)

[error] 116-116: f-string without any placeholders

Remove extraneous f prefix

(F541)


[warning] 117-117: Loop control variable i not used within loop body

Rename unused i to _i

(B007)

🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In
`@docs/cuopt/source/cuopt-python/lp-qp-milp/examples/incumbent_solutions_example.py`
around lines 116 - 119, Remove the unnecessary f-string and the unused enumerate
index in the final-solution print block: change the first print call to a plain
print (no f prefix) and iterate directly over problem.getVariables() instead of
using enumerate so the unused loop variable i is gone; keep using
var.VariableName and var.getValue() to print each variable and keep printing
problem.ObjValue for the final objective value.

@Iroy30
Copy link
Member Author

Iroy30 commented Mar 20, 2026

/ok to test b285473

@Iroy30
Copy link
Member Author

Iroy30 commented Mar 20, 2026

/ok to test 176f996

Copy link

@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.

🧹 Nitpick comments (1)
docs/cuopt/source/cuopt-python/lp-qp-milp/examples/incumbent_solutions_example.py (1)

112-115: Remove unused loop variable i.

The enumerate() call introduces an unused index variable i. Since only var is used, iterate directly over getVariables().

✏️ Suggested fix
-    print("Final solution: ", end=" ")
-    for i, var in enumerate(problem.getVariables()):
-        print(f"{var.VariableName}={var.getValue()} ", end=" ")
+    print("Final solution:", end="")
+    for var in problem.getVariables():
+        print(f" {var.VariableName}={var.getValue()}", end="")
     print(f"\nFinal objective value: {problem.ObjValue:.2f}")
🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In
`@docs/cuopt/source/cuopt-python/lp-qp-milp/examples/incumbent_solutions_example.py`
around lines 112 - 115, The loop uses enumerate() but never uses the index
variable `i`; change the iteration to loop directly over problem.getVariables()
(e.g., replace "for i, var in enumerate(problem.getVariables()):" with "for var
in problem.getVariables():") so only the used symbol `var` is bound and the
unused `i` is removed; keep the surrounding prints and the final objective line
unchanged.
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.

Nitpick comments:
In
`@docs/cuopt/source/cuopt-python/lp-qp-milp/examples/incumbent_solutions_example.py`:
- Around line 112-115: The loop uses enumerate() but never uses the index
variable `i`; change the iteration to loop directly over problem.getVariables()
(e.g., replace "for i, var in enumerate(problem.getVariables()):" with "for var
in problem.getVariables():") so only the used symbol `var` is bound and the
unused `i` is removed; keep the surrounding prints and the final objective line
unchanged.

ℹ️ Review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Pro

Run ID: 3b587708-0155-405b-8dca-7f0060b327f2

📥 Commits

Reviewing files that changed from the base of the PR and between 955d253 and 176f996.

📒 Files selected for processing (3)
  • docs/cuopt/source/cuopt-python/lp-qp-milp/examples/incumbent_solutions_example.py
  • docs/cuopt/source/cuopt-python/lp-qp-milp/lp-qp-milp-examples.rst
  • skills/cuopt-lp-milp-api-python/assets/milp_basic/incumbent_callback.py
🚧 Files skipped from review as they are similar to previous changes (2)
  • docs/cuopt/source/cuopt-python/lp-qp-milp/lp-qp-milp-examples.rst
  • skills/cuopt-lp-milp-api-python/assets/milp_basic/incumbent_callback.py

@Iroy30
Copy link
Member Author

Iroy30 commented Mar 21, 2026

/merge

@rapids-bot rapids-bot bot merged commit d7aa673 into NVIDIA:release/26.04 Mar 21, 2026
707 of 724 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

doc Improvements or additions to documentation non-breaking Introduces a non-breaking change

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[QST] How do I get the values of the solution after calling .solve()

3 participants