Skip to content

add cuopt direct solver#3620

Merged
blnicho merged 77 commits intoPyomo:mainfrom
Iroy30:add_cuopt_direct_solver_plugin
Feb 11, 2026
Merged

add cuopt direct solver#3620
blnicho merged 77 commits intoPyomo:mainfrom
Iroy30:add_cuopt_direct_solver_plugin

Conversation

@Iroy30
Copy link

@Iroy30 Iroy30 commented Jun 4, 2025

Fixes #3626

Summary/Motivation:

Add cuOpt math optimization (includes LP and MILP) solver backend to Pyomo so users can solve pyomo models with cuOpt

Changes proposed in this PR:

  • Add cuopt_direct solver plugin

Legal Acknowledgement

By contributing to this software project, I have read the contribution guide and agree to the following terms and conditions for my contribution:

  1. I agree my contributions are submitted under the BSD license.
  2. I represent I am authorized to make the contributions and grant the license. If my employer has rights to intellectual property that includes these contributions, I represent that I have received permission to make contributions and grant the required license on behalf of that employer.

@codecov
Copy link

codecov bot commented Jun 17, 2025

Codecov Report

❌ Patch coverage is 88.62069% with 33 lines in your changes missing coverage. Please review.
✅ Project coverage is 89.67%. Comparing base (4e91199) to head (481dca2).
⚠️ Report is 153 commits behind head on main.

Files with missing lines Patch % Lines
pyomo/solvers/plugins/solvers/cuopt_direct.py 88.54% 33 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main    #3620      +/-   ##
==========================================
+ Coverage   89.66%   89.67%   +0.01%     
==========================================
  Files         902      903       +1     
  Lines      105609   105926     +317     
==========================================
+ Hits        94696    94992     +296     
- Misses      10913    10934      +21     
Flag Coverage Δ
builders 29.01% <16.20%> (-0.04%) ⬇️
default 83.79% <88.62%> (?)
expensive 35.46% <16.55%> (?)
linux 86.76% <15.51%> (-2.64%) ⬇️
linux_other 86.76% <15.51%> (-0.21%) ⬇️
oldsolvers 29.85% <72.75%> (+0.17%) ⬆️
osx 82.94% <15.51%> (-0.20%) ⬇️
win 85.01% <15.51%> (-0.20%) ⬇️
win_other 85.01% <15.51%> (-0.20%) ⬇️

Flags with carried forward coverage won't be shown. Click here to find out more.

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

Copy link
Contributor

@mrmundt mrmundt left a comment

Choose a reason for hiding this comment

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

We are working on making cuopt available in our testing infrastructure; can you please add tests to this PR?

@mrmundt
Copy link
Contributor

mrmundt commented Jul 1, 2025

@Iroy30 - We've been able to make cuopt available on our internal testing machines. Can you please add tests to this PR?

@Iroy30 Iroy30 force-pushed the add_cuopt_direct_solver_plugin branch from 5dbf9dd to 6f64094 Compare July 2, 2025 12:33
@Iroy30
Copy link
Contributor Author

Iroy30 commented Jul 2, 2025

@mrmundt Thanks! We have added tests by enabling testing cuopt with LP and MILP capabilities in tests/solvers.py. Let us know if:

  1. There is any other testing that needs to be enabled.
  2. For testing cuOpt backend in CI, it needs a GPU, is that something pyomo team intends to add or will it be disabled in github CI?

The following is the testing output I get relevant to cuOpt

Testing scenario generation
------------------------------
LP_block, cuopt, python
   ok: 
LP_block_kernel, cuopt, python
   ok: 
LP_compiled, cuopt, python
   ok: 
LP_compiled_dense_kernel, cuopt, python
   ok: 
LP_compiled_sparse_kernel, cuopt, python
   ok: 
LP_constant_objective1, cuopt, python
   ok: 
LP_constant_objective1_kernel, cuopt, python
   ok: 
LP_constant_objective2, cuopt, python
   ok: 
LP_constant_objective2_kernel, cuopt, python
   ok: 
LP_duals_maximize, cuopt, python
   ok: 
LP_duals_maximize_kernel, cuopt, python
   ok: 
LP_duals_minimize, cuopt, python
   ok: 
LP_duals_minimize_kernel, cuopt, python
   ok: 
LP_inactive_index, cuopt, python
   ok: 
LP_inactive_index_kernel, cuopt, python
   ok: 
LP_infeasible1, cuopt, python
   ok: 
LP_infeasible1_kernel, cuopt, python
   ok: 
LP_infeasible2, cuopt, python
   ok: 
LP_infeasible2_kernel, cuopt, python
   ok: 
LP_piecewise, cuopt, python
   ok: 
LP_piecewise_nosuffixes, cuopt, python
   ok: 
LP_simple, cuopt, python
   ok: 
LP_simple_kernel, cuopt, python
   ok: 
LP_trivial_constraints, cuopt, python
   ok: 
LP_trivial_constraints_kernel, cuopt, python
   ok: 
LP_unbounded, cuopt, python
   ok: 
LP_unbounded_kernel, cuopt, python
   ok: 
LP_unused_vars, cuopt, python
   ok: 
LP_unused_vars_kernel, cuopt, python
   ok: 
MILP_discrete_var_bounds, cuopt, python
   ok: 
MILP_discrete_var_bounds_kernel, cuopt, python
   ok: 
MILP_infeasible1, cuopt, python
   ok: 
MILP_infeasible1_kernel, cuopt, python
   ok: 
MILP_simple, cuopt, python
   ok: 
MILP_simple_kernel, cuopt, python
   ok: 
MILP_unbounded, cuopt, python
   ok: 
MILP_unbounded_kernel, cuopt, python
   ok: 
MILP_unused_vars, cuopt, python
   ok: 
MILP_unused_vars_kernel, cuopt, python
   ok: 

Comment on lines 60 to 62
t0 = time.time()
self.solution = cuopt.linear_programming.solver.Solve(self._solver_model)
t1 = time.time()
Copy link
Contributor

Choose a reason for hiding this comment

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

This is fine, but just so you're aware, we have this lovely little utility called TicTocTimer that you may want to consider using: https://pyomo.readthedocs.io/en/latest/api/pyomo.common.timing.TicTocTimer.html

@whart222
Copy link
Member

whart222 commented Jul 8, 2025

@mrmundt What do you think about including this solver interface in pyomo.contrib.solvers? Would it make sense to pull-in new solver interfaces there, since that's where the new solver API is evolving?

@mrmundt
Copy link
Contributor

mrmundt commented Jul 8, 2025

@mrmundt What do you think about including this solver interface in pyomo.contrib.solvers? Would it make sense to pull-in new solver interfaces there, since that's where the new solver API is evolving?

@whart222 - I am evenly split. Because we are still messing with what the new solver interfaces are going to actually do / how they will handle input and present output, I don't know if we want to put "new" solvers there or just "well-established" ones that we can robustly test / really know what they are supposed to do and return.

@mrmundt
Copy link
Contributor

mrmundt commented Jul 8, 2025

@Iroy30 - I forgot to post this last week, but all of the failures are of the variety:

self = <pyomo.solvers.tests.checks.test_no_solution_behavior.Test_LP_unbounded_kernel testMethod=test_cuopt_python>

    def return_test(self):
>       return failed_solve_test(self)

/tester/python/python39/pyomo/pyomo/solvers/tests/checks/test_no_solution_behavior.py:92: 
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 
/tester/python/python39/pyomo/pyomo/solvers/tests/checks/test_no_solution_behavior.py:61: in failed_solve_test
    opt, results = model_class.solve(
/tester/python/python39/pyomo/pyomo/solvers/tests/models/base.py:123: in solve
    results = opt.solve(
/tester/python/python39/pyomo/pyomo/opt/base/solvers.py:99: in solve
    self._solver_error('solve')
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 

self = <pyomo.opt.base.solvers.UnknownSolver object at 0x7f86ad9ab040>
method_name = 'solve'

        def _solver_error(self, method_name):
>           raise RuntimeError(
                """Attempting to use an unavailable solver.
    
    The SolverFactory was unable to create the solver "%s"
    and returned an UnknownSolver object.  This error is raised at the point
    where the UnknownSolver object was used as if it were valid (by calling
    method "%s").
    
    The original solver was created with the following parameters:
    \t"""
                % (self.type, method_name)
                + "\n\t".join("%s: %s" % i for i in sorted(self._kwds.items()))
                + "\n\t_args: %s" % (self._args,)
                + "\n\toptions: %s" % (self.options,)
            )
E           RuntimeError: Attempting to use an unavailable solver.
E           
E           The SolverFactory was unable to create the solver "cuopt"
E           and returned an UnknownSolver object.  This error is raised at the point
E           where the UnknownSolver object was used as if it were valid (by calling
E           method "solve").
E           
E           The original solver was created with the following parameters:
E           	executable: cuopt
E           	solver_io: python
E           	type: cuopt
E           	_args: ()
E           	options: {}

/tester/python/python39/pyomo/pyomo/opt/base/solvers.py:116: RuntimeError

@mrmundt
Copy link
Contributor

mrmundt commented Jul 8, 2025

@Iroy30 - Two more things:

  1. Please run black -S -C on your files
  2. Something in our testing environment isn't loading correctly. I'm looking into it.

Iroy30 and others added 2 commits July 9, 2025 13:15
Iroy30 and others added 2 commits February 10, 2026 10:10
Co-authored-by: John Siirola <jsiirola@users.noreply.github.com>
@Iroy30
Copy link
Contributor Author

Iroy30 commented Feb 10, 2026

There are a few tests failing. I'm looking into these new failures with recent changes

Copy link
Contributor

@michaelbynum michaelbynum left a comment

Choose a reason for hiding this comment

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

Once tests pass, I think this is good to go.

@Iroy30
Copy link
Contributor Author

Iroy30 commented Feb 10, 2026

@jsiirola @michaelbynum Is the CI running cuOpt tests? Could you confirm, since I mostly see it SKIPPED on CI unless I'm interpreting it wrong. I still see failures on tests on my local runs

@jsiirola
Copy link
Member

@jsiirola @michaelbynum Is the CI running cuOpt tests? Could you confirm, since I mostly see it SKIPPED on CI unless I'm interpreting it wrong. I still see failures on tests on my local runs

cuOpt is only getting tested through Jenkins - the GHA runners don't have GPUs, so the cuOpt tests should all be getting skipped there. Unfortunately, the Jenkins logs aren't published - only overall pass/fail. If you need any detail from those tests, let us know and we can manually pull it out.

@blnicho blnicho moved this from Review In Progress to Reviewer Approved in Pyomo 6.10 Feb 10, 2026
@Iroy30
Copy link
Contributor Author

Iroy30 commented Feb 10, 2026

cuOpt is only getting tested through Jenkins - the GHA runners don't have GPUs, so the cuOpt tests should all be getting skipped there. Unfortunately, the Jenkins logs aren't published - only overall pass/fail. If you need any detail from those tests, let us know and we can manually pull it out.

@jsiirola Is it possible for you to paste the Jenkins errors

@jsiirola
Copy link
Member

We are seeing 3 errors:

On all versions of Python:

________________ CUOPTTests.test_infeasible_trivial_constraint _________________

self = <pyomo.solvers.tests.checks.test_cuopt_direct.CUOPTTests testMethod=test_infeasible_trivial_constraint>

    @unittest.skipIf(not cuopt_available, "The CuOpt solver is not available")
    def test_infeasible_trivial_constraint(self):
        m = ConcreteModel()
        m.x = Var(domain=NonNegativeReals)
        m.obj = Objective(expr=m.x, sense=minimize)
        # trivial constraint that is infeasible: 5 <= 3
>       m.bad_con = Constraint(expr=5 <= 3)
        ^^^^^^^^^

pyomo/solvers/tests/checks/test_cuopt_direct.py:121: 
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 
pyomo/core/base/block.py:573: in __setattr__
    self.add_component(name, val)
pyomo/core/base/block.py:1088: in add_component
    val.construct(data)
pyomo/core/base/disable_methods.py:119: in construct
    return base.construct(self, data)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^
pyomo/core/base/constraint.py:738: in construct
    self._setitem_when_not_present(index, rule(block, index))
pyomo/core/base/indexed_component.py:1144: in _setitem_when_not_present
    obj.set_value(value)
pyomo/core/base/constraint.py:934: in set_value
    return super().set_value(expr)
           ^^^^^^^^^^^^^^^^^^^^^^^
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 

self = <pyomo.core.base.constraint.ScalarConstraint object at 0x7f0ebeff31b0>
expr = False

    def set_value(self, expr):
        """Set the expression on this constraint."""
        # [ ... ]    
        elif expr.__class__ is bool:
>           raise ValueError(
                "Invalid constraint expression. The constraint "
                "expression resolved to a trivial Boolean (%s) "
                "instead of a Pyomo object. Please modify your "
                "rule to return Constraint.%s instead of %s."
                "\n\nError thrown for Constraint '%s'"
                % (expr, "Feasible" if expr else "Infeasible", expr, self.name)
            )
E           ValueError: Invalid constraint expression. The constraint expression resolved to a trivial Boolean (False) instead of a Pyomo object. Please modify your rule to return Constraint.Infeasible instead of False.
E           
E           Error thrown for Constraint 'bad_con'

pyomo/core/base/constraint.py:466: ValueError
------------------------------ Captured log call -------------------------------
ERROR    pyomo.core:constraint.py:741 Rule failed when generating expression for Constraint bad_con with index None:
ValueError: Invalid constraint expression. The constraint expression resolved to a trivial Boolean (False) instead of a Pyomo object. Please modify your rule to return Constraint.Infeasible instead of False.

Error thrown for Constraint 'bad_con'
ERROR    pyomo.core:block.py:1091 Constructing component 'bad_con' from data=None failed:
    ValueError: Invalid constraint expression. The constraint expression resolved to a trivial Boolean (False) instead of a Pyomo object. Please modify your rule to return Constraint.Infeasible instead of False.

Error thrown for Constraint 'bad_con'

Only on Python 3.13:

____________ Test_LP_piecewise.test_cuopt_python_nonsymbolic_labels ____________

self = <pyomo.solvers.tests.checks.test_writers.Test_LP_piecewise testMethod=test_cuopt_python_nonsymbolic_labels>

    def return_test(self):
>       return writer_test(self)
               ^^^^^^^^^^^^^^^^^

pyomo/solvers/tests/checks/test_writers.py:161: 
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 
pyomo/solvers/tests/checks/test_writers.py:115: in writer_test
    self.fail(
E   AssertionError: Solution mismatch for plugin test_cuopt_python_nonsymbolic_labels, python interface and problem type LP_piecewise
E   Difference in solution for x.value:
E   	Baseline - 0.0
E   	Current - 1.0
E   Gap: None
E   Status: optimal
E   Message: None
E   Objective:
E     obj:
E       Value: 1
E   Variable:
E     x:
E       Rc: 0
E       Value: 1
E     y:
E       Rc: 1
E       Value: 1
E   Constraint: No nonzero values
----------------------------- Captured stdout call -----------------------------
Setting parameter log_file to tmpsi7fbm7i.log
cuOpt version: 25.10.0, git hash: 99e549c, host arch: x86_64, device archs: 70-real,75-real,80-real,86-real,90a-real,100f-real,120a-real,120
CPU: Intel(R) Xeon(R) 
CUDA 12.9, device: NVIDIA T400 4GB
CUDA device UUID: 

Solving a problem with 2 constraints, 2 variables (0 integers), and 4 nonzeros
Problem scaling:
Objective coefficents range:          [1e+00, 1e+00]
Constraint matrix coefficients range: [5e-01, 1e+00]
Constraint rhs / bounds range:        [0e+00, 5e-01]
Variable bounds range:                [0e+00, 0e+00]

Third-party presolve is disabled, skipping
Objective offset 0.000000 scaling_factor 1.000000
Running concurrent

Dual simplex finished in 0.00 seconds, total time 0.00
Barrier finished in 0.01 seconds
   Iter    Primal Obj.      Dual Obj.    Gap        Primal Res.  Dual Res.   Time
      0 +0.00000000e+00 +0.00000000e+00  0.00e+00   7.07e-01     1.00e+00   0.197s
PDLP finished
Concurrent time:  0.198s, total time 0.200s
Solved with dual simplex
Status: Optimal   Objective: 1.00000000e+00  Iterations: 0  Time: 0.200s

and

_____________ Test_LP_piecewise.test_cuopt_python_symbolic_labels ______________

self = <pyomo.solvers.tests.checks.test_writers.Test_LP_piecewise testMethod=test_cuopt_python_symbolic_labels>

    def return_test(self):
>       return writer_test(self)
               ^^^^^^^^^^^^^^^^^

pyomo/solvers/tests/checks/test_writers.py:161: 
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 
pyomo/solvers/tests/checks/test_writers.py:71: in writer_test
    model_class.post_solve_test_validation(self, results)
pyomo/solvers/tests/models/base.py:463: in post_solve_test_validation
    tester.assertEqual(
E   AssertionError: <TerminationCondition.infeasible: 'infeasible'> != <TerminationCondition.optimal: 'optimal'>
----------------------------- Captured stdout call -----------------------------
Setting parameter log_file to tmp5mxrn1ik.log
cuOpt version: 25.10.0, git hash: 99e549c, host arch: x86_64, device archs: 70-real,75-real,80-real,86-real,90a-real,100f-real,120a-real,120
CPU: Intel(R) Xeon(R) 
CUDA 12.9, device: NVIDIA T400 
CUDA device UUID: 

Solving a problem with 2 constraints, 2 variables (0 integers), and 4 nonzeros
Problem scaling:
Objective coefficents range:          [1e+00, 1e+00]
Constraint matrix coefficients range: [5e-01, 1e+00]
Constraint rhs / bounds range:        [0e+00, 5e-01]
Variable bounds range:                [0e+00, 0e+00]

Third-party presolve is disabled, skipping
Objective offset 0.000000 scaling_factor 1.000000
Running concurrent

Dual simplex finished in 0.00 seconds, total time 0.00
Barrier finished in 0.01 seconds
   Iter    Primal Obj.      Dual Obj.    Gap        Primal Res.  Dual Res.   Time
      0 +0.00000000e+00 +0.00000000e+00  0.00e+00   7.07e-01     1.00e+00   0.104s
PDLP finished
Dual Simplex Solve status Primal Infeasible
Concurrent time:  0.104s, total time 0.106s
Solved with dual simplex
Status: Primal Infeasible   Objective: nan  Iterations: 1  Time: 0.106s

@Iroy30
Copy link
Contributor Author

Iroy30 commented Feb 10, 2026

Ive fixed the first error. I am unable to reproduce the other two locally on my python 3.13 environment. Could be that is because I'm using the most recent cuOpt 26.02 version, I see that the CI runs on 25.10. I will have to downgrade the version and re-evaluate the fails

@blnicho blnicho merged commit 02cd662 into Pyomo:main Feb 11, 2026
34 of 35 checks passed
@github-project-automation github-project-automation bot moved this from Reviewer Approved to Done in Pyomo 6.10 Feb 11, 2026
@Iroy30
Copy link
Contributor Author

Iroy30 commented Feb 12, 2026

Thanks everyone! Is this going to be included in 6.10 release of pyomo? If yes, when is the release slated for

@blnicho
Copy link
Member

blnicho commented Feb 12, 2026

@Iroy30 yes, this will be included in the 6.10 release which should be out in the next couple days

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

Labels

None yet

Projects

Status: Done

Development

Successfully merging this pull request may close these issues.

Support NVIDIA cuOpt solver

9 participants