Skip to content

extend getters on C API#1549

Merged
rapids-bot[bot] merged 6 commits into
NVIDIA:mainfrom
tmckayus:feature/c-api-problem-attributes
Jul 23, 2026
Merged

extend getters on C API#1549
rapids-bot[bot] merged 6 commits into
NVIDIA:mainfrom
tmckayus:feature/c-api-problem-attributes

Conversation

@tmckayus

@tmckayus tmckayus commented Jul 9, 2026

Copy link
Copy Markdown
Contributor

Additonal getters on cuOptOptimizationProblem. Uses generic get routines for different types and constants to identify the attribute, rather than fixed getters for each attribute.

@tmckayus
tmckayus requested review from a team as code owners July 9, 2026 21:48
@tmckayus
tmckayus requested review from Iroy30, aliceb-nv, bdice and mlubin July 9, 2026 21:48
@tmckayus tmckayus added non-breaking Introduces a non-breaking change improvement Improves an existing functionality labels Jul 9, 2026
@tmckayus
tmckayus force-pushed the feature/c-api-problem-attributes branch from 79f2f34 to 8a4ee93 Compare July 9, 2026 21:56
@github-actions

github-actions Bot commented Jul 9, 2026

Copy link
Copy Markdown

CI Test Summary

1 failed · 30 passed · 0 skipped

wheel-tests-cuopt / 13.3.0, 3.14, arm64, ubuntu26.04, l4, latest-driver, latest-deps — 50 failed tests
  • tests/linear_programming/test_incumbent_callbacks.py::test_incumbent_get_set_callback[/mip/swath1.mps]
  • tests/linear_programming/test_incumbent_callbacks.py::test_incumbent_get_set_callback[/mip/neos5-free-bound.mps]
  • tests/linear_programming/test_lp_solver.py::test_unbounded_problem
  • tests/linear_programming/test_python_API.py::test_model
  • tests/linear_programming/test_python_API.py::test_semi_continuous_variable
  • tests/linear_programming/test_python_API.py::test_read_write_mps_and_relaxation
  • tests/linear_programming/test_python_API.py::test_incumbent_get_solutions
  • tests/linear_programming/test_python_API.py::test_incumbent_get_set_solutions
  • tests/linear_programming/test_python_API.py::test_warm_start
  • tests/linear_programming/test_python_API.py::test_mip_start
  • tests/linear_programming/test_python_API.py::test_problem_update
  • tests/linear_programming/test_python_API.py::test_quadratic_objective_1
  • tests/linear_programming/test_python_API.py::test_quadratic_objective_2
  • tests/linear_programming/test_python_API.py::test_quadratic_matrix_1
  • tests/linear_programming/test_python_API.py::test_quadratic_matrix_2
  • tests/quadratic_programming/test_qp.py::test_solver
  • tests/routing/test_batch_solve.py::test_batch_solve_varying_sizes
  • tests/routing/test_data_model.py::test_order_constraints
  • tests/routing/test_data_model.py::test_objective_function
  • tests/routing/test_data_model.py::test_multi_cost_and_transit_matrices_getters
  • tests/routing/test_distance_engine.py::test_compute_cost_matrix
  • tests/routing/test_distance_engine.py::test_compute_waypoint_sequence_set_order_locations
  • tests/routing/test_distance_engine.py::test_compute_waypoint_sequence_no_set_order_locations
  • tests/routing/test_distance_engine.py::test_compute_waypoint_sequence_no_matrix_call
  • tests/routing/test_distance_engine.py::test_compute_shortest_path_costs
  • tests/routing/test_distance_engine.py::test_target_locations_validity
  • tests/routing/test_distance_engine.py::test_locations_validity
  • tests/routing/test_host_arrays.py::test_all_getters_match_cudf[numpy]
  • tests/routing/test_host_arrays.py::test_all_getters_match_cudf[pandas]
  • tests/routing/test_host_arrays.py::test_backend_solves_successfully[cudf]
  • tests/routing/test_host_arrays.py::test_backend_solves_successfully[numpy]
  • tests/routing/test_host_arrays.py::test_backend_solves_successfully[pandas]
  • tests/routing/test_host_arrays.py::test_numpy_matrix_is_c_contiguous_no_transpose
  • tests/routing/test_initial_solutions.py::test_initial_solutions[TestOption.PRIZE]
  • tests/routing/test_initial_solutions.py::test_initial_solutions[TestOption.VRP]
  • tests/routing/test_initial_solutions.py::test_initial_solutions[TestOption.PDP]
  • tests/routing/test_initial_solutions.py::test_initial_solutions[TestOption.SKIP_DEPOTS]
  • tests/routing/test_initial_solutions.py::test_initial_solutions[TestOption.BREAKS]
  • tests/routing/test_re_routing.py::test_re_routing
  • tests/routing/test_serialize.py::test_export_exports_host_and_device_to_host
  • tests/routing/test_serialize.py::test_export_breaks
  • tests/routing/test_solver.py::test_solomon
  • tests/routing/test_solver_settings.py::test_dump_results
  • tests/routing/test_solver_settings.py::test_dump_config
  • tests/routing/test_vehicle_properties.py::test_vehicle_types
  • tests/routing/test_vehicle_properties.py::test_vehicle_fixed_costs
  • tests/routing/test_vehicle_properties.py::test_vehicle_max_costs
  • tests/routing/test_vehicle_properties.py::test_vehicle_max_times_fail
  • tests/routing/test_vehicle_properties.py::test_vehicle_to_order_match
  • tests/routing/test_vehicle_properties.py::test_single_vehicle_with_match

@coderabbitai

coderabbitai Bot commented Jul 9, 2026

Copy link
Copy Markdown

Review Change Stack

Note

Reviews paused

It looks like this branch is under active development. To avoid overwhelming you with review comments due to an influx of new commits, CodeRabbit has automatically paused this review. You can configure this behavior by changing the reviews.auto_review.auto_pause_after_reviewed_commits setting.

Use the following commands to manage reviews:

  • @coderabbitai resume to resume automatic reviews.
  • @coderabbitai review to trigger a single review.

Use the checkboxes below for quick actions:

  • ▶️ Resume reviews
  • 🔍 Trigger review
📝 Walkthrough

Walkthrough

Changes

The C API adds generic problem attribute selectors and getters, explicit CSR and CSC linear constraint-matrix accessors, and deprecates the previous matrix getter. Tests cover scalar, array, name, and matrix data across created, ranged, quadratic, and parsed problems.

Problem accessors

Layer / File(s) Summary
Public attribute and matrix contracts
cpp/include/cuopt/mathematical_optimization/constants.h, cpp/include/cuopt/mathematical_optimization/cuopt_c.h
Defines attribute selectors; declares generic getters and CSR/CSC matrix APIs; documents the deprecated matrix accessor.
Attribute getters and matrix export
cpp/src/pdlp/cuopt_c.cpp
Implements selector validation and copy-out getters, delegates the deprecated matrix API to CSR retrieval, and converts host CSR data to CSC.
Attribute and matrix validation
cpp/tests/linear_programming/c_api_tests/c_api_test.c, cpp/tests/linear_programming/c_api_tests/c_api_tests.cpp, cpp/tests/linear_programming/c_api_tests/c_api_tests.h
Adds C and C++ tests for attributes, matrix equivalence, ranged and quadratic flags, and named problems.

Estimated code review effort: 4 (Complex) | ~60 minutes

Suggested reviewers: aliceb-nv, bdice, chris-maes, mlubin

🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 28.57% 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 is concise and accurately summarizes the main change: adding more getters to the C API.
Description check ✅ Passed The description is related to the changeset and correctly mentions generic getters and attribute constants.
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.
✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests

Comment @coderabbitai help to get the list of available commands.

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

🤖 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 `@cpp/tests/linear_programming/c_api_tests/c_api_tests.cpp`:
- Around line 797-802: The new QP test in c_api_tests::problem_attributes_qp
depends on quadratic_programming/QP_Test_1.qps, but that fixture is not included
in the dataset provisioning flow. Update the dataset download step or related
dataset manifest/script used by cuopt::test::get_rapids_dataset_root_dir() so
QP_Test_1.qps is downloaded with the other test assets, ensuring this test can
locate the file at runtime.
🪄 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: e0acf068-41ea-4d33-aa75-1ab654dc2651

📥 Commits

Reviewing files that changed from the base of the PR and between 24bf137 and 79f2f34.

📒 Files selected for processing (7)
  • cpp/include/cuopt/mathematical_optimization/constants.h
  • cpp/include/cuopt/mathematical_optimization/cuopt_c.h
  • cpp/src/pdlp/CMakeLists.txt
  • cpp/src/pdlp/cuopt_c_attributes.cpp
  • cpp/tests/linear_programming/c_api_tests/c_api_test.c
  • cpp/tests/linear_programming/c_api_tests/c_api_tests.cpp
  • cpp/tests/linear_programming/c_api_tests/c_api_tests.h

Comment thread cpp/tests/linear_programming/c_api_tests/c_api_tests.cpp Outdated

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

🧹 Nitpick comments (1)
cpp/tests/linear_programming/c_api_tests/c_api_test.c (1)

3391-3414: 🎯 Functional Correctness | 🔵 Trivial | ⚡ Quick win

CSC consistency check is structural-only; it won't catch a mis-populated CSC.

The transpose check compares only per-column nnz counts. A CSC exporter that produces correct column-offset gaps but wrong csc_row indices or csc_val values would still pass. Consider (a) range-checking csc_row[k] ∈ [0, nc) like csr_col is checked at Line 3401, and (b) cross-validating the actual nonzero values between the two layouts (e.g. per (row,col) lookup) so the CSC exporter's payload — not just its shape — is verified.

As per path instructions, added/modified C API tests should validate returned values/consistency (not just "success") and cover CSR-to-CSC consistency.

🤖 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 `@cpp/tests/linear_programming/c_api_tests/c_api_test.c` around lines 3391 -
3414, The CSC validation in the C API test only checks offset structure and
transpose counts, so a bad CSC payload could still pass. Update the test around
cuOptGetConstraintMatrix and cuOptGetConstraintMatrixCSC to also range-check
csc_row entries like csr_col is checked, and add a content-level comparison
between CSR and CSC so the actual row/col/value payloads are verified, not just
the offsets.

Source: Path instructions

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

Nitpick comments:
In `@cpp/tests/linear_programming/c_api_tests/c_api_test.c`:
- Around line 3391-3414: The CSC validation in the C API test only checks offset
structure and transpose counts, so a bad CSC payload could still pass. Update
the test around cuOptGetConstraintMatrix and cuOptGetConstraintMatrixCSC to also
range-check csc_row entries like csr_col is checked, and add a content-level
comparison between CSR and CSC so the actual row/col/value payloads are
verified, not just the offsets.

ℹ️ Review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Enterprise

Run ID: 18d59cd8-5a5b-4ae1-9521-6beb92f7c8b0

📥 Commits

Reviewing files that changed from the base of the PR and between 79f2f34 and 8a4ee93.

📒 Files selected for processing (7)
  • cpp/include/cuopt/mathematical_optimization/constants.h
  • cpp/include/cuopt/mathematical_optimization/cuopt_c.h
  • cpp/src/pdlp/CMakeLists.txt
  • cpp/src/pdlp/cuopt_c_attributes.cpp
  • cpp/tests/linear_programming/c_api_tests/c_api_test.c
  • cpp/tests/linear_programming/c_api_tests/c_api_tests.cpp
  • cpp/tests/linear_programming/c_api_tests/c_api_tests.h
✅ Files skipped from review due to trivial changes (1)
  • cpp/src/pdlp/CMakeLists.txt
🚧 Files skipped from review as they are similar to previous changes (5)
  • cpp/tests/linear_programming/c_api_tests/c_api_tests.cpp
  • cpp/tests/linear_programming/c_api_tests/c_api_tests.h
  • cpp/include/cuopt/mathematical_optimization/constants.h
  • cpp/include/cuopt/mathematical_optimization/cuopt_c.h
  • cpp/src/pdlp/cuopt_c_attributes.cpp

@github-actions

Copy link
Copy Markdown

🔔 Hi @anandhkb, this pull request has had no activity for 7 days. Please update or let us know if it can be closed. Thank you!

If this is an "epic" issue, then please add the "epic" label to this issue.
If it is a PR and not ready for review, then please convert this to draft.
If you just want to switch off this notification, then use the "skip inactivity reminder" label.

Comment thread cpp/include/cuopt/mathematical_optimization/constants.h Outdated
Comment thread cpp/include/cuopt/mathematical_optimization/constants.h Outdated
Comment thread cpp/include/cuopt/mathematical_optimization/constants.h Outdated
Comment thread cpp/include/cuopt/mathematical_optimization/cuopt_c.h
Comment thread cpp/include/cuopt/mathematical_optimization/cuopt_c.h Outdated
Comment thread cpp/include/cuopt/mathematical_optimization/cuopt_c.h Outdated
Comment thread cpp/src/pdlp/cuopt_c_attributes.cpp Outdated
Comment thread cpp/src/pdlp/cuopt_c_attributes.cpp Outdated
Comment thread cpp/tests/linear_programming/c_api_tests/c_api_tests.cpp Outdated
@tmckayus
tmckayus force-pushed the feature/c-api-problem-attributes branch from a8746a5 to 7a3447f Compare July 21, 2026 14:57
@copy-pr-bot

copy-pr-bot Bot commented Jul 21, 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.

@copy-pr-bot

copy-pr-bot Bot commented Jul 21, 2026

Copy link
Copy Markdown

/ok to test

@tmckayus, there was an error processing your request: E1

See the following link for more information: https://docs.gha-runners.nvidia.com/cpr/e/1/

@tmckayus

Copy link
Copy Markdown
Contributor Author

/ok to test 7a3447f

@tmckayus tmckayus added this to the 26.08 milestone Jul 21, 2026
@tmckayus tmckayus self-assigned this Jul 21, 2026
@tmckayus

Copy link
Copy Markdown
Contributor Author

/ok to test 93bf501

@tmckayus
tmckayus force-pushed the feature/c-api-problem-attributes branch from 93bf501 to 4e489ad Compare July 21, 2026 17:31
@tmckayus

Copy link
Copy Markdown
Contributor Author

/ok to test 4e489ad

tmckayus added 5 commits July 22, 2026 11:05
* remove cosmetic static casts in new fuctions
* move attribute helpers into cuopt_c.cpp instead of a new file
* add cuOptGetConstraintMatrixCSR and deprecate cuOptGetConstraintMatrix
* revise/remove comments
Use the create functions with direct comparison of values
returned from getters wherever possible. Use mps read
for checking getters of names.
Signed-off-by: Trevor McKay <tmgithub1@gmail.com>
@tmckayus
tmckayus force-pushed the feature/c-api-problem-attributes branch from 4e489ad to 64f505d Compare July 22, 2026 15:06
@tmckayus

Copy link
Copy Markdown
Contributor Author

/ok to test 64f505d

Comment thread cpp/include/cuopt/mathematical_optimization/cuopt_c.h Outdated
Comment thread cpp/src/pdlp/cuopt_c.cpp Outdated
Comment thread cpp/src/pdlp/cuopt_c.cpp Outdated
Comment thread cpp/src/pdlp/cuopt_c.cpp
std::vector<cuopt_float_t> values;
switch (attribute) {
case CUOPT_ARRAY_ATTR_OBJECTIVE_COEFFICIENTS:
values = iface->get_objective_coefficients_host();

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

As a future TODO we can consider changing this interface to pass in a pointer/span to write the coefficients to, avoiding an extra memory allocation and copy.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

do we want to note this formally as a todo in the file?

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Sure, why not

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

actually I'll add an issue for it since this passed CI :)

Comment thread cpp/src/pdlp/cuopt_c.cpp
Comment thread cpp/tests/linear_programming/c_api_tests/c_api_test.c Outdated
Comment thread cpp/tests/linear_programming/c_api_tests/c_api_test.c Outdated
* simplify tests
* move tests to C++
* revise comments
* use existing transpose functions in constraint matrix CSC impl
@tmckayus

Copy link
Copy Markdown
Contributor Author

/ok to test 4fcec52

@tmckayus

Copy link
Copy Markdown
Contributor Author

/merge

@rapids-bot
rapids-bot Bot merged commit 7e22f48 into NVIDIA:main Jul 23, 2026
233 of 242 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

improvement Improves an existing functionality non-breaking Introduces a non-breaking change

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants