Skip to content

Conversation

@ChrisRackauckas
Copy link
Member

Summary

Fixes #528 - This PR adds Float64 conversion for bounds in MOI.GreaterThan and MOI.LessThan constraints to handle integer constraint vectors properly.

Problem

When users pass integer vectors for lb and ub parameters, OptimizationMOI throws a confusing error:

MathOptInterface.UnsupportedConstraint{MathOptInterface.VariableIndex, 
MathOptInterface.GreaterThan{Int64}}

This happens because MOI expects Float64 types for constraints, but the code in nlp.jl wasn't converting integer bounds.

Solution

Added Float64() conversion when creating the constraints:

  • MOI.GreaterThan(evaluator.lb[i])MOI.GreaterThan(Float64(evaluator.lb[i]))
  • MOI.LessThan(evaluator.ub[i])MOI.LessThan(Float64(evaluator.ub[i]))

This matches the implementation in moi.jl which already had this conversion.

Example

Before this fix:

using Optimization, OptimizationMOI, Ipopt
prob = OptimizationProblem(fopt, params;
    lb = fill(-10, length(params)),  # Integer vector - causes error
    ub = fill(10, length(params))
)
solve(prob, Ipopt.Optimizer())  # ERROR: UnsupportedConstraint

After this fix:

# Same code now works without error
solve(prob, Ipopt.Optimizer())  # ✓ Works\!

Testing

  • Verified the Float64 conversion is in place
  • Consistent with the implementation in moi.jl
  • Maintains backward compatibility (Float64 bounds still work)

🤖 Generated with Claude Code

Fixes #528 - Added Float64 conversion for bounds in MOI.GreaterThan and
MOI.LessThan constraints to handle integer constraint vectors properly.

Previously, passing integer vectors for lb/ub parameters would cause:
```
MathOptInterface.UnsupportedConstraint{MathOptInterface.VariableIndex,
MathOptInterface.GreaterThan{Int64}}
```

Now integer bounds are automatically converted to Float64, matching the
behavior in moi.jl and preventing confusing errors.

Changes:
- Convert evaluator.lb[i] to Float64 in MOI.GreaterThan constraint
- Convert evaluator.ub[i] to Float64 in MOI.LessThan constraint

🤖 Generated with [Claude Code](https://claude.ai/code)

Co-Authored-By: Claude <[email protected]>
@ChrisRackauckas ChrisRackauckas merged commit 9a063c5 into master Jul 23, 2025
24 of 29 checks passed
@ChrisRackauckas ChrisRackauckas deleted the fix-integer-bounds branch July 23, 2025 11:27
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Error messages with integer constraint vectors

2 participants