Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
25 changes: 3 additions & 22 deletions skills/cuopt-numerical-optimization-api-c/SKILL.md
Original file line number Diff line number Diff line change
Expand Up @@ -22,28 +22,9 @@ Confirm problem type and formulation (variables, objective, constraints, variabl

This skill is **C only**.

## Quick Reference: C API

```c
#include <cuopt/linear_programming/cuopt_c.h>

// CSR format for constraints
cuopt_int_t row_offsets[] = {0, 2, 4};
cuopt_int_t col_indices[] = {0, 1, 0, 1};
cuopt_float_t values[] = {2.0, 3.0, 4.0, 2.0};
char var_types[] = {CUOPT_CONTINUOUS, CUOPT_INTEGER};

cuOptCreateRangedProblem(
num_constraints, num_variables, CUOPT_MINIMIZE,
0.0, objective_coefficients,
row_offsets, col_indices, values,
constraint_lower, constraint_upper,
var_lower, var_upper, var_types,
&problem
);
cuOptSolve(problem, settings, &solution);
cuOptGetObjectiveValue(solution, &obj_value);
```
## API Call Sequence

For LP/MILP, the ordered C entry points are: `cuOptCreateRangedProblem` (sense `CUOPT_MINIMIZE` / `CUOPT_MAXIMIZE`, CSR constraint matrix as `row_offsets` / `col_indices` / `values`, `var_types` char array using `CUOPT_CONTINUOUS` / `CUOPT_INTEGER` macros) → `cuOptSolve(problem, settings, &solution)` → `cuOptGetObjectiveValue(solution, &obj_value)` → matching `cuOptDestroy*` calls. Include `<cuopt/linear_programming/cuopt_c.h>`. Full ordered code with build instructions in [references/examples.md](references/examples.md).

## QP via C API (beta)

Expand Down
13 changes: 13 additions & 0 deletions skills/cuopt-numerical-optimization-api-c/evals/evals.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
[
{
"id": "numopt-c-eval-001-milp-api-call-sequence",
"question": "I want to solve a small MILP (some integer variables, linear objective, linear constraints) with the cuOpt C API. List the C functions and structs I need in order — names only, one line each, no full source.",
"expected_skill": "cuopt-numerical-optimization-api-c",
"expected_script": null,
"ground_truth": "The agent produces an ordered list of C API entry points without writing a full source file: include cuopt/linear_programming/cuopt_c.h, then call cuOptCreateRangedProblem with sense CUOPT_MINIMIZE or CUOPT_MAXIMIZE, then cuOptSolve(problem, settings, &solution), then cuOptGetObjectiveValue.",
"expected_behavior": [
"Lists C API call sequence without writing a complete source file",
"Names cuOptCreateRangedProblem, cuOptSolve, cuOptGetObjectiveValue in order"
]
Comment on lines +4 to +11

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

🛠️ Refactor suggestion | 🟠 Major | ⚡ Quick win

Align question, ground_truth, and expected_behavior for completeness.

The question asks for "C functions and structs I need in order" but the ground_truth and expected_behavior only mention functions. The complete answer should include:

Struct types:

  • cuOptOptimizationProblem
  • cuOptSolverSettings
  • cuOptSolution

Functions missing from current ground_truth:

  • cuOptCreateSolverSettings (required before solve, see lp_simple.c:38,98)
  • The three destroy functions: cuOptDestroyProblem, cuOptDestroySolverSettings, cuOptDestroySolution (mentioned in SKILL.md line 27 and used in lp_simple.c:95-97)
📝 Proposed fix to complete the evaluation criteria
     "question": "I want to solve a small MILP (some integer variables, linear objective, linear constraints) with the cuOpt C API. List the C functions and structs I need in order — names only, one line each, no full source.",
     "expected_skill": "cuopt-numerical-optimization-api-c",
     "expected_script": null,
-    "ground_truth": "The agent produces an ordered list of C API entry points without writing a full source file: include cuopt/linear_programming/cuopt_c.h, then call cuOptCreateRangedProblem with sense CUOPT_MINIMIZE or CUOPT_MAXIMIZE, then cuOptSolve(problem, settings, &solution), then cuOptGetObjectiveValue.",
+    "ground_truth": "The agent produces an ordered list of C API types and entry points without writing a full source file: include cuopt/linear_programming/cuopt_c.h, declare cuOptOptimizationProblem/cuOptSolverSettings/cuOptSolution structs, then call cuOptCreateRangedProblem with sense CUOPT_MINIMIZE or CUOPT_MAXIMIZE, cuOptCreateSolverSettings, cuOptSolve(problem, settings, &solution), cuOptGetObjectiveValue, and the three cuOptDestroy* functions.",
     "expected_behavior": [
       "Lists C API call sequence without writing a complete source file",
-      "Names cuOptCreateRangedProblem, cuOptSolve, cuOptGetObjectiveValue in order"
+      "Names the three struct types (cuOptOptimizationProblem, cuOptSolverSettings, cuOptSolution)",
+      "Names cuOptCreateRangedProblem, cuOptCreateSolverSettings, cuOptSolve, cuOptGetObjectiveValue, and destroy functions in order"
     ]
🤖 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 `@skills/cuopt-numerical-optimization-api-c/evals/evals.json` around lines 4 -
11, Update the expected list to include the required struct types and missing
API calls in order: include cuopt/linear_programming/cuopt_c.h, then structs
cuOptOptimizationProblem, cuOptSolverSettings, cuOptSolution, then call
cuOptCreateRangedProblem, cuOptCreateSolverSettings, cuOptSolve(problem,
settings, &solution), cuOptGetObjectiveValue, and finally cleanup with
cuOptDestroyProblem, cuOptDestroySolverSettings, cuOptDestroySolution; reference
these exact symbols (cuOptCreateRangedProblem, cuOptCreateSolverSettings,
cuOptSolve, cuOptGetObjectiveValue, cuOptDestroyProblem,
cuOptDestroySolverSettings, cuOptDestroySolution and the structs) so the eval
expects both functions and structs in the proper sequence.

}
]
60 changes: 40 additions & 20 deletions skills/cuopt-numerical-optimization-api-c/references/examples.md
Original file line number Diff line number Diff line change
Expand Up @@ -46,17 +46,31 @@ int main() {
// Constraint matrix in CSR format
cuopt_int_t row_offsets[] = {0, 2, 4};
cuopt_int_t column_indices[] = {0, 1, 0, 1};
cuopt_float_t values[] = {3.0, 4.0, 2.7, 10.1};
cuopt_float_t values[] = {
3.0,
4.0,
2.7,
10.1
};

// Objective coefficients
cuopt_float_t objective_coefficients[] = {-0.2, 0.1};
cuopt_float_t objective_coefficients[] = {
-0.2,
0.1
};

// Constraint bounds (lower <= Ax <= upper)
cuopt_float_t constraint_upper_bounds[] = {5.4, 4.9};
cuopt_float_t constraint_upper_bounds[] = {
5.4,
4.9
};
cuopt_float_t constraint_lower_bounds[] = {-CUOPT_INFINITY, -CUOPT_INFINITY};

// Variable bounds
cuopt_float_t var_lower_bounds[] = {0.0, 0.0};
cuopt_float_t var_lower_bounds[] = {
0.0,
0.0
};
cuopt_float_t var_upper_bounds[] = {CUOPT_INFINITY, CUOPT_INFINITY};

// Variable types
Expand Down Expand Up @@ -140,12 +154,26 @@ int main() {

cuopt_int_t row_offsets[] = {0, 2, 4};
cuopt_int_t column_indices[] = {0, 1, 0, 1};
cuopt_float_t values[] = {3.0, 4.0, 2.7, 10.1};

cuopt_float_t objective_coefficients[] = {-0.2, 0.1};
cuopt_float_t constraint_upper[] = {5.4, 4.9};
cuopt_float_t values[] = {
3.0,
4.0,
2.7,
10.1
};

cuopt_float_t objective_coefficients[] = {
-0.2,
0.1
};
cuopt_float_t constraint_upper[] = {
5.4,
4.9
};
cuopt_float_t constraint_lower[] = {-CUOPT_INFINITY, -CUOPT_INFINITY};
cuopt_float_t var_lower[] = {0.0, 0.0};
cuopt_float_t var_lower[] = {
0.0,
0.0
};
cuopt_float_t var_upper[] = {CUOPT_INFINITY, CUOPT_INFINITY};

// x1 = INTEGER, x2 = CONTINUOUS
Expand Down Expand Up @@ -202,17 +230,9 @@ cleanup:

## Build & Run

```bash
# Set paths (conda example)
export INCLUDE_PATH="${CONDA_PREFIX}/include"
export LIB_PATH="${CONDA_PREFIX}/lib"

# Compile
gcc -I${INCLUDE_PATH} -L${LIB_PATH} -o lp_example lp_example.c -lcuopt

# Run
LD_LIBRARY_PATH=${LIB_PATH}:$LD_LIBRARY_PATH ./lp_example
```
See [`assets/README.md`](../assets/README.md) for the canonical conda-env
include/library/`LD_LIBRARY_PATH` setup, plus a `gcc` build command. The
same recipe applies here — substitute `lp_example.c` for the file name.

## Constants Reference

Expand Down
Loading