NVIDIA / NVIDIA/cuopt

[Bug/Robustness] Inefficient type handling in is_mip() and strict parsing of CUOPT_EXTRA_TIMESTAMPS

Open
#868 10 comments 0 reactions 1 assignee View on GitHub

@ramakrishnap-nv is already working on this.

Since Feb 14, 2026.

awaiting response bug
Dominant language
Cuda
Stars
1k
Forks
233
Avg merge
4d 4h
Merged PRs (30d)
95

Description

While reviewing python/cuopt/linear_programming/solver.py, I identified two robustness issues in the Solve() helper function:

  1. The local is_mip() function uses inefficient iteration and fragile type checking, which may fail or perform poorly with cudf.Series or numpy scalar types.
  2. The CUOPT_EXTRA_TIMESTAMPS environment variable parsing ignores common truthy values like "1" or "yes".

1. is_mip(): Inefficient iteration and fragile type checking

Description:
The current implementation of is_mip iterates over var_types using map(type, ...) and set(...).

# Current Code
if len(set(map(type, var_types))) == 1:
    # ...

Issues:

  1. Performance on GPU Containers: If var_types is a cudf.Series (which resides on GPU), iterating over it element-wise in Python (map) causes significant overhead due to scalar access and memory transfer.
  2. Type Mismatch: cudf or numpy arrays often return scalar types (e.g., numpy.bytes_, numpy.str_) instead of standard Python bytes or str. The current isinstance(..., bytes) check may fail for these scalar types, leading to incorrect MIP detection (returning False for an actual MIP problem).

Suggested Fix:
Avoid explicit Python-side iteration for type checking if possible, or normalize types robustly.

def is_mip(var_types):
    # Handle cudf/numpy vectorization if available, otherwise fallback to robust loop
    for vt in var_types:
        # Normalize numpy/cudf scalars to python types
        try:
            if isinstance(vt, (bytes, bytearray)):
                if vt == b"I": return True
            elif hasattr(vt, "tobytes"): # numpy/cudf scalar handling
                 if vt.tobytes() == b"I": return True
            elif vt == "I":
                 return True
        except Exception:
            pass
            
    return False


2. Strict parsing of CUOPT_EXTRA_TIMESTAMPS

Description:
The current parsing logic only accepts Python booleans or specific string casings:

# Current Code
emit_stamps = os.environ.get("CUOPT_EXTRA_TIMESTAMPS", False) in (
    True, "True", "true",
)

Issue:
In standard shell or container environments (e.g., Kubernetes, Docker), boolean flags are often set as "1", "yes", or "on". The current logic ignores these values, making it difficult to enable debug logging in certain deployment scenarios.

Suggested Fix:
Normalize the input string to handle standard truthy values.

val = str(os.environ.get("CUOPT_EXTRA_TIMESTAMPS", "False")).strip().lower()
emit_stamps = val in {"1", "true", "yes", "on", "y"}


Impact
  • Reliability: Correctly detects MIP models even when input data types vary (e.g., numpy.bytes_ vs bytes).
  • Performance: Reduces overhead when var_types is a large cudf.Series.
  • Usability: Allows standard environment variable configuration for debugging.

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.