-
Notifications
You must be signed in to change notification settings - Fork 222
Add conversion routines for LP/MIP cuOpt JSON dictionaries to/from DataModel and Solution #1800
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
base: main
Are you sure you want to change the base?
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 |
|---|---|---|
|
|
@@ -69,6 +69,36 @@ from the quick start (same constraint matrix and objective). | |
| :class:`~cuopt.linear_programming.problem.Problem`. Always call | ||
| ``delete`` after you are done with the job so the server can release state. | ||
|
|
||
| From a Legacy cuOpt JSON Format Dictionary | ||
| =========================================== | ||
|
|
||
| Two data conversion routines have been added that make it easy to migrate clients from | ||
| use of the cuOpt http server to the gRPC server. LP/MIP datasets in cuOpt JSON | ||
| format can be converted to inputs for the gRPC server, and Solution ojbects | ||
| returned from the gRPC server can be converted into cuOpt JSON response | ||
| dictionaries. | ||
|
|
||
| ``toDataModelAndSettings`` accepts the same input dictionary format that | ||
| that ``CuOptServiceSelfHostClient.get_LP_solve()`` accepts. | ||
| ``toDictFromSolution`` maps a ``Solution`` to the response dictionary | ||
| format that ``CuOptServiceSelfHostClient.get_LP_solve()`` optionally returns. | ||
|
|
||
| .. code-block:: python | ||
|
|
||
| from cuopt.linear_programming import toDataModelAndSettings, toDictFromSolution | ||
| from cuopt.grpc.linear_programming import Client, JobStatus | ||
|
|
||
| dm, settings = toDataModelAndSettings("problem.json") # or a dict | ||
| client = Client("localhost", 5001) | ||
| job_id = client.submit(dm, settings) | ||
| try: | ||
| client.wait(job_id, timeout=120) | ||
| solution = client.result(job_id) | ||
| envelope = toDictFromSolution(solution) | ||
|
Comment on lines
+91
to
+97
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. 🎯 Functional Correctness | 🟡 Minor | ⚡ Quick win Check the job status before calling
As per path instructions, verify that documentation code examples compile and run correctly. 🤖 Prompt for AI AgentsSource: Path instructions |
||
| print(envelope["response"]["solver_response"]["status"]) | ||
| finally: | ||
| client.delete(job_id) | ||
|
|
||
| Variable Names | ||
| ============== | ||
|
|
||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,4 +1,11 @@ | ||
| # SPDX-FileCopyrightText: Copyright (c) 2024-2026 NVIDIA CORPORATION & AFFILIATES. All rights reserved. | ||
| # SPDX-FileCopyrightText: Copyright (c) 2024-2026, NVIDIA CORPORATION & AFFILIATES. All rights reserved. | ||
| # SPDX-License-Identifier: Apache-2.0 | ||
|
|
||
| from cuopt.linear_programming.io.parser import ParseMps, Read, toDict | ||
| from cuopt.linear_programming.io.parser import ( | ||
| ParseMps, | ||
| Read, | ||
| toDataModelAndSettings, | ||
| toDict, | ||
| toDictFromDataModel, | ||
| toDictFromSolution, | ||
| ) |
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.
📐 Maintainability & Code Quality | 🟠 Major | ⚡ Quick win
Document
toDictFromDataModelin this migration section.The package now exports
toDictFromDataModel, but this public conversion API is not documented here. Add its purpose, input, and return behavior. State that it is thetoDictalias for callers that use the paired conversion naming scheme.As per path instructions, “Missing docs: if the PR changes public APIs without updating docs, flag as HIGH.” Based on learnings,
.rstfiles underdocs/cuopt/source/are the canonical published documentation.🤖 Prompt for AI Agents
Sources: Path instructions, Learnings