-
Notifications
You must be signed in to change notification settings - Fork 218
docs: add Python async gRPC client guide under gRPC remote execution #1653
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
Open
tmckayus
wants to merge
7
commits into
NVIDIA:main
Choose a base branch
from
tmckayus:grpcdocs
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
7 commits
Select commit
Hold shift + click to select a range
912a847
docs: add Python async gRPC client guide under gRPC remote execution
tmckayus 3240c02
apply coderabbit feedback on grpc doc changes
tmckayus 1093965
apply feedback on gRPC doc PR (#1653)
tmckayus 1d8c0a3
Merge branch 'main' into grpcdocs
tmckayus 366d2fd
fix doc error introduced in MILP -> MIP normalization
tmckayus 8d56e0e
fix docs build: blank line before section, resolvable xrefs
ramakrishnap-nv 7b0302c
Merge branch 'main' into grpcdocs
ramakrishnap-nv File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,7 @@ | ||
| /* Rubric styled closer to an H2/H3 for in-page subheads that must stay out of the TOC. */ | ||
| p.rubric.large-rubric { | ||
| font-size: 1.4em; | ||
| font-weight: 600; | ||
| margin-top: 1.75rem; | ||
| margin-bottom: 0.75rem; | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
55 changes: 55 additions & 0 deletions
55
docs/cuopt/source/cuopt-grpc/examples/incumbent_stream_demo.py
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,55 @@ | ||
| # SPDX-FileCopyrightText: Copyright (c) 2026, NVIDIA CORPORATION & AFFILIATES. All rights reserved. | ||
| # SPDX-License-Identifier: Apache-2.0 | ||
|
|
||
| """MIP incumbent streaming via the Python async gRPC client. | ||
|
|
||
| Same ``set_mip_callback`` registration as a local solve, plus | ||
| ``start_incumbent_stream`` so those callbacks fire while the remote job runs. | ||
|
|
||
| Start the server first:: | ||
|
|
||
| cuopt_grpc_server --port 5001 --workers 1 | ||
|
|
||
| Then:: | ||
|
|
||
| python incumbent_stream_demo.py | ||
| """ | ||
|
|
||
| from cuopt.grpc.linear_programming import Client, JobStatus | ||
| from cuopt.linear_programming.internals import GetSolutionCallback | ||
| from cuopt.linear_programming.problem import INTEGER, MAXIMIZE, Problem | ||
| from cuopt.linear_programming.solver_settings import SolverSettings | ||
|
|
||
|
|
||
| class IncumbentPrinter(GetSolutionCallback): | ||
| def get_solution(self, solution, solution_cost, solution_bound, user_data): | ||
| print( | ||
| f"incumbent cost={float(solution_cost[0]):.4f} " | ||
| f"values={solution.tolist()}", | ||
| flush=True, | ||
| ) | ||
|
tmckayus marked this conversation as resolved.
|
||
|
|
||
|
|
||
| problem = Problem("incumbent_stream_demo") | ||
| x = problem.addVariable(lb=0, ub=10, vtype=INTEGER, name="x") | ||
| y = problem.addVariable(lb=0, ub=10, vtype=INTEGER, name="y") | ||
| problem.addConstraint(x + y <= 10, name="c1") | ||
| problem.addConstraint(x - y >= 0, name="c2") | ||
| problem.setObjective(x + 2 * y, sense=MAXIMIZE) | ||
|
|
||
| settings = SolverSettings() | ||
| settings.set_mip_callback(IncumbentPrinter(), None) | ||
| settings.set_parameter("time_limit", 30) | ||
|
|
||
| client = Client("localhost", 5001) | ||
| job_id = client.submit(problem, settings) | ||
| try: | ||
| client.start_incumbent_stream(job_id, settings=settings) | ||
| if client.wait(job_id, timeout=120) != JobStatus.COMPLETED: | ||
| raise RuntimeError("job did not complete") | ||
| client.join_incumbent_stream(job_id) | ||
| names = [v.getVariableName() for v in problem.getVariables()] | ||
| solution = client.result(job_id, variable_names=names) | ||
| print(solution.get_termination_reason(), solution.get_primal_objective()) | ||
| finally: | ||
| client.delete(job_id) | ||
|
tmckayus marked this conversation as resolved.
|
||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,13 +1,19 @@ | ||
| NAME good-1 | ||
| NAME good-1 | ||
| OBJSENSE | ||
| MAXIMIZE | ||
| ROWS | ||
| N COST | ||
| L ROW1 | ||
| L ROW2 | ||
| COLUMNS | ||
| VAR1 COST -0.2 | ||
| VAR1 ROW1 3 ROW2 2.7 | ||
| VAR2 COST 0.1 | ||
| VAR2 ROW1 4 ROW2 10.1 | ||
| VAR1 COST 0.2 | ||
| VAR1 ROW1 3.0 ROW2 2.7 | ||
| VAR2 COST 0.1 | ||
| VAR2 ROW1 4.0 ROW2 10.1 | ||
| RHS | ||
| RHS1 ROW1 5.4 ROW2 4.9 | ||
| RHS1 ROW1 5.4 ROW2 4.9 | ||
| BOUNDS | ||
| LO BND1 VAR1 0.0 | ||
| UP BND1 VAR1 2.0 | ||
| LO BND1 VAR2 0.0 | ||
| ENDATA |
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.