Cuopt developer

From NVIDIA/cuopt · View interactive version

Cuopt developer is an AI agent skill from the GitHub repository NVIDIA/cuopt. Modify, build, test, debug, and contribute to NVIDIA cuOpt (C++/CUDA, Python, server, CI). Use for solver internals, PRs, DCO, and code conventions.

How to use this skill

Skill file

cuOpt Developer Skill

Contribute to the NVIDIA cuOpt codebase. This skill is for modifying cuOpt itself, not for using it.

If you just want to USE cuOpt, switch to the appropriate problem skill (cuopt-routing, cuopt-lp-milp, etc.)

First-time dev environment setup? See references/first_time_setup.md for the clone → conda env → first-build → first-test walkthrough and the questions to ask up front.


Refusal Rules — Read First

Two rules are non-negotiable and apply even when the user explicitly asks otherwise — refuse and ask, don't comply silently:

Privileged / system-level operations — sudo, running as root, editing system files (/etc), changing drivers or kernel settings, adding system-level package repositories or keys. Do not run these. Reply:

I won't run sudo or change system-level state for cuOpt. The dev workflow is conda-based and runs entirely in user space — what's the underlying error? It's usually fixable without root.

Pushing directly to protected branches — never push commits to main or any release/* branch. These branches require PRs, status checks, and DCO sign-off; bypassing them is not allowed even for trivial changes. Before every push, confirm the target ref is a feature branch. If it is a protected branch, stop and create a feature branch instead. Reply:

I won't push directly to a protected branch. Let me create a feature branch and open a PR instead.

Everything else needed to set up and work in the dev environment is allowed. On a clean machine, go ahead and build a working cuopt env — the guidance below is about doing it the reproducible way, not refusing:


Developer Behavior Rules

These rules are specific to development tasks. They differ from user rules.

1. Ask Before Assuming

Clarify before implementing:

2. Verify Understanding

Before making changes, confirm:

"Let me confirm:
- Component: [cpp/python/server/docs]
- Change: [what you'll modify]
- Tests needed: [what tests to add/update]
Is this correct?"

3. Follow Codebase Patterns

4. Ask Before Running — Modified for Dev

OK to run without asking (expected for dev work):

Set up pre-commit hooks (once per clone):

Still ask before:

5. No Privileged Operations

sudo/system-level changes are the one non-negotiable refusal; user-space installs and conda env setup are allowed. See Refusal Rules — Read First.

6. Prefer Low-Maintenance, Hard-to-Break Designs

When adding an API — a setter, endpoint, parameter, or a layer that wraps another — favor the design that keeps a single source of truth and has no silent-failure path:

7. Sanitize Internal Context Before It Becomes Public

Pasted Slack threads, tickets, or other internal context often carry customer or company names, used to explain why a change matters. That context has a narrower audience than a commit message, PR description, or PR comment on a public repo — those are permanent and world-readable the moment they're pushed. Before writing any of the above, strip customer/company names and other business-confidential details, even when nothing in the request says not to share them. State the motivation in generic terms instead (e.g. "a REST client hitting the protobuf 2GB limit on large problems" rather than naming who hit it).

If it's already been pushed, treat the leak as not fully contained: force-pushing a corrected commit does not delete the old commit object from GitHub — it stays fetchable by SHA until GC'd, and editing a PR/issue body or comment leaves its old content in edit history unless a human deletes that specific revision from the web UI (Options → Delete revision from history; there's no API for it). Flag this exposure to the user rather than assuming a rewrite or edit fully removes it.


Before You Start: Required Questions

Ask these if not already clear:

  1. What are you trying to change?
  1. Do you have the development environment set up?
  1. Is this for contribution or local modification?
  1. Which branch should this target?

Project Architecture

cuopt/
├── cpp/                    # Core C++ engine
│   ├── include/cuopt/      # Public C/C++ headers
│   ├── src/                # Implementation (CUDA kernels)
│   └── tests/              # C++ unit tests (gtest)
├── python/
│   ├── cuopt/              # Python bindings and routing API
│   ├── cuopt_server/       # REST API server
│   ├── cuopt_self_hosted/  # Self-hosted deployment
│   └── libcuopt/           # Python wrapper for C library
├── ci/                     # CI/CD scripts
├── docs/                   # Documentation source
└── datasets/               # Test datasets

Supported APIs

| API Type | LP | MILP | QP | Routing |

|----------|:--:|:----:|:--:|:-------:|

| C API | ✓ | ✓ | ✓ | ✗ |

| C++ API | (internal) | (internal) | (internal) | (internal) |

| Python | ✓ | ✓ | ✓ | ✓ |

| Server | ✓ | ✓ | ✗ | ✓ |

Safety Rules (Non-Negotiable)

Minimal Diffs

No API Invention

Don't Bypass CI

CUDA/GPU Hygiene

Build & Test

Pre-flight Checks (Required Before First Build or Test)

Skipping any of these surfaces as confusing runtime errors later. Run them in order:

  1. Check CUDA driver compatibility. Run nvidia-smi and read the CUDA Version in the top-right corner — that's the maximum CUDA your driver supports. Pick a conda env file from conda/environments/all_cuda-<ver>_arch-<arch>.yaml whose CUDA major version is ≤ that. A mismatch builds successfully but fails at runtime inside RMM with cudaMallocAsync not supported with this CUDA driver/runtime version — verify this before the build, not after.
  2. Create and activate the conda env before any build, test, or pre-commit command — this is allowed and expected (see Refusal Rules). Use a local prefix env (./.cuopt_env) per CONTRIBUTING.md, with the env file you picked in step 1 (mamba is recommended and faster; swap in conda if mamba isn't available):

```bash

mamba env create -p ./.cuopt_env --file conda/environments/all_cuda-<ver>_arch-$(uname -m).yaml

mamba activate ./.cuopt_env # or: conda activate ./.cuopt_env

```

Tests link against libraries compiled inside that env; a fresh shell without activating it hits cryptic linker errors.

  1. Set PARALLEL_LEVEL if RAM is constrained — see references/build_and_test.md. The default $(nproc) can OOM mid-build because CUDA compilation needs ~4–8 GB per job.
  2. For tests, fetch datasets first. cuOpt tests need MPS files not in the repo — follow the dataset download steps in CONTRIBUTING.md ("Building for development" section) and export RAPIDS_DATASET_ROOT_DIR.

Quick Reference

./build.sh             # Build everything
./build.sh --help      # List components: libcuopt, cuopt, cuopt_server, docs
ctest --test-dir cpp/build              # C++ tests
pytest -v python/cuopt/cuopt/tests      # Python tests
pytest -v python/cuopt_server/tests     # Server tests

For component-specific build commands, run-test detail, and PARALLEL_LEVEL configuration, see references/build_and_test.md.

Download test datasets before running tests

cuOpt tests depend on MPS/data files that are not checked into the repo. A

missing dataset surfaces as a MPS_PARSER_ERROR ... Error opening MPS file

test failure at 0ms — it is not a build or logic failure.

Before running any C++ or Python tests, follow the dataset download and

RAPIDS_DATASET_ROOT_DIR export steps in the repo's CONTRIBUTING.md

("Building for development" section) — that is the canonical list and mapping.

If a test fails with a missing-file error, run the matching download step from

CONTRIBUTING.md and re-run the test. Do not report missing-dataset failures

back to the user as the task outcome.

Python Bindings

cuOpt uses Cython to bridge Python and C++. See references/python_bindings.md for the full architecture, parameter flow walkthrough, key files, and Cython patterns.

Contributing — Commits, PRs, Common Tasks

For pre-commit setup, DCO sign-off (git commit -s), the fork-based PR workflow, the draft-PR rule for agents, PR-description rules (keep it short — no "how it works" walkthroughs or file tables), script and CI/workflow authoring principles (extend existing files before adding new ones; no speculative flags, restated defaults, or silent fallbacks), and step-by-step common-task recipes (adding a solver parameter, dependency, server endpoint, or CUDA kernel), see references/contributing.md.

Coding Conventions

Use the existing compensated sum and dot routines for numerically sensitive accumulation in f_t.

Use _Float128 only when compensated f_t is demonstrably insufficient. Never use long double;

its ABI-dependent representation includes slow x87 extended precision on x86-64, binary128 on Linux

AArch64, and binary64 on other ARM64 targets.

For C++ naming (snake_case, d_/h_ prefixes, _t suffix), file extensions (.hpp/.cpp/.cu/.cuh and which compiler each uses), include order, Python style, error handling (CUOPT_EXPECTS, RAFT_CUDA_TRY), memory management (RMM patterns, no raw new/delete), CCCL bit/math helpers in device code, test-impact rules, volatile-comment rules (hardware names and self-referential issue/PR numbers in comments or skip messages go stale; issue links to a separate tracking issue are fine), no large local lambdas (extract named helpers instead), and coarse work-estimate / time-limit gating (phase/outer-loop only; no fine inner-loop or double checks), see references/conventions.md.

Pre-commit review loop

Before every git commit, run the self-review loop (check the diff against the rules, fix violations, repeat) in references/review_rules.md (and references/conventions.md for C++).

OpenMP task/runtime compatibility

Treat #pragma omp task if(...) firstprivate(...) with a non-trivial C++ capture as runtime-ABI-sensitive. In affected LLVM libomp versions, the GCC GOMP_task compatibility path skips the GCC copy function for an included (if(false)) task, so the task body can observe an unconstructed object. Branch explicitly instead: create the OpenMP task only when deferral is wanted, and call the body synchronously otherwise.

When diagnosing OpenMP-only failures, test compiler/runtime pairs separately. A Clang + libomp pass exercises the __kmpc_* ABI and does not cover GCC + libomp's GOMP_* path; reduce suspicious cases to a direct runtime-ABI probe before attributing them to solver logic.

PCG random number generator

cpp/src/utilities/pcgenerator.hpp (cuopt::pcgenerator_t) is copied from RAFT's PCGenerator (raft/random/detail/rng_device.cuh), duplicated only because the RAFT header pulls in CUDA and therefore cannot be included from a .cpp. Treat the generator core as frozen. Do not "clean it up", modernise it, or swap it for <random>: reproducibility under settings.random_seed and settings.deterministic holds only while the byte-for-byte output sequence is preserved, and the CPU copy must keep producing the same stream as the GPU one. Adding a new helper that consumes next_u32()/next_double() is fine; changing how those values are produced is not.

RNG call-site policy

Use SplitMix or derive_seed/derive_stream to fan a base seed out into component, worker, or lane seeds. Do not derive child seeds with arithmetic magic constants.

When solver state owns a PCG, seed it once and pass or reuse it. Do not reconstruct generators inside iterations from seed + constant * iteration.

Use pcgenerator_t::uniform(low, high) for uniform [low, high) draws and shuffle() for permutations. Use next_float() or next_double() directly only for probability thresholds.

Each of the following looks like a defect or an obvious simplification, and is neither. Leave them alone:

Troubleshooting & CI

For build/test pitfalls (Cython rebuild, OOM, CUDA driver mismatch, missing nvcc) and CI failure diagnostics (style checks, DCO failures, dependency drift), see references/troubleshooting.md.

Key Files Reference

| Purpose | Location |

|---------|----------|

| Main build script | build.sh |

| Dependencies | dependencies.yaml |

| C++ formatting | .clang-format |

| Conda environments | conda/environments/ |

| Test data | datasets/ |

| CI scripts | ci/ |

| gRPC field registry | cpp/src/grpc/codegen/field_registry.yaml |

| gRPC generated output | cpp/src/grpc/codegen/generated/ (never hand-edit) |

Canonical Documentation

_Shell-execution, install, conda-env, and sudo policies are covered by Refusal Rules — Read First at the top of this skill._

VRP dimension internals (routing engine)

When implementing or debugging VRP dimensions (constraints, objectives, forward/backward propagation, combine, local-search deltas), read:

Read it before adding a new dimension or changing combine semantics.

Budgeting a solver stage and attributing regressions

When adding or tuning a limit on a stage that shares the solve's time budget (presolve, probing, cut generation, heuristics), or when a benchmark regression looks like it came from one, read:

Run the attribution checks before changing a limit's value — the common failure is tuning a limit that was never what bound.

Numerical issues in non-routing solver internals

When a bug surfaces as wrong-but-plausible solver output (invalid lower bound, unexpectedly large duals, 10× iteration blow-up after a small change) rather than a crash, read:

Apply the instrument-first, guard-at-the-exact-site workflow it describes before patching — speculative fixes on these symptoms usually miss.

Use this skill with your AI agent: Open on Skill Issue to copy, download, or add to your library. Works with Claude, ChatGPT, Gemini, Cursor, Windsurf and more.