Skip to content

[BUG] Constraint validation reports CSR offset count as the number of rows #2274

Open

Description

@0z5a

Bug

When the length of a constraint vector does not match the CSR matrix, the solver rejects the model, but the validation message reports the length of the CSR offsets array as the number of matrix rows. For a two-row matrix, a three-element RHS can therefore produce the contradictory message:

The right hand side vector has size 3 and the number of rows (constraints) in the matrix is 3.

The actual matrix has two rows (offsets = [0, 1, 2]). The lower/upper-bound representation has the same diagnostic issue. The validation itself rejected the malformed models in the cases checked; this report does not assert an out-of-bounds access.

Reproducer

import numpy as np
from cuopt.linear_programming.data_model import DataModel
from cuopt.linear_programming.solver import Solve
from cuopt.linear_programming.solver_settings import SolverMethod, SolverSettings

model = DataModel()
model.set_csr_constraint_matrix(
    np.array([1.0, 1.0]),
    np.array([0, 0], dtype=np.int32),
    np.array([0, 1, 2], dtype=np.int32),
)
model.set_objective_coefficients(np.array([1.0]))
model.set_variable_lower_bounds(np.array([0.0]))
model.set_variable_upper_bounds(np.array([np.inf]))
model.set_variable_types(np.array(["C"], dtype="S1"))
model.set_constraint_bounds(np.array([1.0, 2.0, 3.0]))
model.set_row_types(np.array(["G", "G", "G"]))

settings = SolverSettings()
settings.set_parameter("method", SolverMethod.PDLP)
settings.set_parameter("time_limit", 10.0)
settings.set_parameter("log_to_console", False)
solution = Solve(model, settings)
print(solution.get_error_status(), solution.get_error_message())

Expected: a validation error reporting 2 matrix rows. Observed with cuOpt 26.12.00a62 (52d14b4c), CUDA 13, B300: a validation error reporting 3 rows. A valid two-element RHS/row-types control solves to Optimal.

At 52d14b4c, the RHS check compares against offsets.size() - 1 but formats offsets.size(); the two bounds checks use the same pattern. Related: #2254.

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions