Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions conda/environments/all_cuda-129_arch-aarch64.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,7 @@ dependencies:
- requests
- rmm==26.2.*,>=0.0.0a0
- scikit-build-core>=0.11.0
- scipy>=1.14.1
- sphinx
- sphinx-copybutton
- sphinx-design
Expand Down
1 change: 1 addition & 0 deletions conda/environments/all_cuda-129_arch-x86_64.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,7 @@ dependencies:
- requests
- rmm==26.2.*,>=0.0.0a0
- scikit-build-core>=0.11.0
- scipy>=1.14.1
- sphinx
- sphinx-copybutton
- sphinx-design
Expand Down
1 change: 1 addition & 0 deletions conda/environments/all_cuda-131_arch-aarch64.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,7 @@ dependencies:
- requests
- rmm==26.2.*,>=0.0.0a0
- scikit-build-core>=0.11.0
- scipy>=1.14.1
- sphinx
- sphinx-copybutton
- sphinx-design
Expand Down
1 change: 1 addition & 0 deletions conda/environments/all_cuda-131_arch-x86_64.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,7 @@ dependencies:
- requests
- rmm==26.2.*,>=0.0.0a0
- scikit-build-core>=0.11.0
- scipy>=1.14.1
- sphinx
- sphinx-copybutton
- sphinx-design
Expand Down
1 change: 1 addition & 0 deletions conda/recipes/cuopt/recipe.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,7 @@ requirements:
- pylibraft =${{ minor_version }}
- python
- rmm =${{ minor_version }}
- scipy >=1.14.1
# Needed by Numba for CUDA support
- cuda-nvcc-impl
# TODO: Add nvjitlink here
Expand Down
1 change: 1 addition & 0 deletions dependencies.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -350,6 +350,7 @@ dependencies:
- numba>=0.60.0
- &pandas pandas>=2.0
- &pyyaml pyyaml>=6.0.0
- scipy>=1.14.1
- output_types: requirements
packages:
# pip recognizes the index as a global option for the requirements.txt file
Expand Down
Original file line number Diff line number Diff line change
@@ -1,19 +1,6 @@
# SPDX-FileCopyrightText: Copyright (c) 2025 NVIDIA CORPORATION &
# SPDX-FileCopyrightText: Copyright (c) 2025-2026, NVIDIA CORPORATION & AFFILIATES. All rights reserved.
# SPDX-License-Identifier: Apache-2.0
# AFFILIATES. All rights reserved.
# SPDX-License-Identifier: Apache-2.0
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.

"""
Working with Expressions and Constraints Example
Expand Down
Original file line number Diff line number Diff line change
@@ -1,19 +1,6 @@
# SPDX-FileCopyrightText: Copyright (c) 2025 NVIDIA CORPORATION &
# SPDX-FileCopyrightText: Copyright (c) 2025-2026, NVIDIA CORPORATION & AFFILIATES. All rights reserved.
# SPDX-License-Identifier: Apache-2.0
# AFFILIATES. All rights reserved.
# SPDX-License-Identifier: Apache-2.0
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.

"""
Working with Incumbent Solutions Example
Expand Down
Original file line number Diff line number Diff line change
@@ -1,19 +1,6 @@
# SPDX-FileCopyrightText: Copyright (c) 2025 NVIDIA CORPORATION &
# SPDX-FileCopyrightText: Copyright (c) 2025-2026, NVIDIA CORPORATION & AFFILIATES. All rights reserved.
# SPDX-License-Identifier: Apache-2.0
# AFFILIATES. All rights reserved.
# SPDX-License-Identifier: Apache-2.0
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.

"""
Working with PDLP Warmstart Data Example
Expand Down Expand Up @@ -90,7 +77,7 @@ def main():
print(f"Objective value = {problem.ObjValue}")

# Get the warmstart data
warmstart_data = problem.get_pdlp_warm_start_data()
warmstart_data = problem.getWarmstartData()
print(
f"\nWarmstart data extracted (primal solution size: "
f"{len(warmstart_data.current_primal_solution)})"
Expand Down
Original file line number Diff line number Diff line change
@@ -1,19 +1,6 @@
# SPDX-FileCopyrightText: Copyright (c) 2025 NVIDIA CORPORATION &
# SPDX-FileCopyrightText: Copyright (c) 2025-2026, NVIDIA CORPORATION & AFFILIATES. All rights reserved.
# SPDX-License-Identifier: Apache-2.0
# AFFILIATES. All rights reserved.
# SPDX-License-Identifier: Apache-2.0
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.

"""
Production Planning Example
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
# SPDX-FileCopyrightText: Copyright (c) 2026, NVIDIA CORPORATION & AFFILIATES.
# SPDX-License-Identifier: Apache-2.0

"""
Quadratic Programming Matrix Example
====================================
.. note::
The QP solver is currently in beta.
This example demonstrates how to formulate and solve a
Quadratic Programming (QP) problem represented in a matrix format
using the cuOpt Python API.
Problem:
minimize 0.01 * p1^2 + 0.02 * p2^2 + 0.015 * p3^2 + 8 * p1 + 6 * p2 + 7 * p3
subject to p1 + p2 + p3 = 150
10 <= p1 <= 100
10 <= p2 <= 80
10 <= p3 <= 90
This is a convex QP that minimizes the cost of power generation and dispatch
while satisfying capacity and demand.
"""

from cuopt.linear_programming.problem import (
MINIMIZE,
Problem,
QuadraticExpression,
)


def main():
# Create a new optimization problem
prob = Problem("QP Power Dispatch")

# Add variables with lower and upper bounds
p1 = prob.addVariable(lb=10, ub=100)
p2 = prob.addVariable(lb=10, ub=80)
p3 = prob.addVariable(lb=10, ub=90)

# Add demand constraint: p1 + p2 + p3 = 150
prob.addConstraint(p1 + p2 + p3 == 150, name="demand")

# Create matrix for quadratic terms: 0.01 p1^2 + 0.02 p2^2 + 0.015 p3^2
matrix = [[0.01, 0.0, 0.0], [0.0, 0.02, 0.0], [0.0, 0.0, 0.015]]
quad_matrix = QuadraticExpression(matrix, prob.getVariables())

# Set objective using matrix representation
quad_obj = quad_matrix + 8 * p1 + 6 * p2 + 7 * p3
prob.setObjective(quad_obj, sense=MINIMIZE)

# Solve the problem
prob.solve()

# Print results
print(f"Optimal solution found in {prob.SolveTime:.2f} seconds")
print(f"p1 = {p1.Value}")
print(f"p2 = {p2.Value}")
print(f"p3 = {p3.Value}")
print(f"Minimized cost = {prob.ObjValue}")


if __name__ == "__main__":
main()
Original file line number Diff line number Diff line change
@@ -1,19 +1,6 @@
# SPDX-FileCopyrightText: Copyright (c) 2025 NVIDIA CORPORATION &
# SPDX-FileCopyrightText: Copyright (c) 2025-2026, NVIDIA CORPORATION & AFFILIATES. All rights reserved.
# SPDX-License-Identifier: Apache-2.0
# AFFILIATES. All rights reserved.
# SPDX-License-Identifier: Apache-2.0
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.

"""
Simple Linear Programming Example
Expand Down
Original file line number Diff line number Diff line change
@@ -1,19 +1,6 @@
# SPDX-FileCopyrightText: Copyright (c) 2025 NVIDIA CORPORATION &
# SPDX-FileCopyrightText: Copyright (c) 2025-2026, NVIDIA CORPORATION & AFFILIATES. All rights reserved.
# SPDX-License-Identifier: Apache-2.0
# AFFILIATES. All rights reserved.
# SPDX-License-Identifier: Apache-2.0
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.

"""
Mixed Integer Linear Programming Example
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# SPDX-FileCopyrightText: Copyright (c) 2025-2026, NVIDIA CORPORATION & AFFILIATES.
# SPDX-FileCopyrightText: Copyright (c) 2025-2026, NVIDIA CORPORATION & AFFILIATES. All rights reserved.
# SPDX-License-Identifier: Apache-2.0

"""
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
# SPDX-FileCopyrightText: Copyright (c) 2026, NVIDIA CORPORATION & AFFILIATES. All rights reserved.
# SPDX-License-Identifier: Apache-2.0
Copy link
Collaborator

Choose a reason for hiding this comment

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

Suggested change
# SPDX-License-Identifier: Apache-2.0

Copy link
Member Author

Choose a reason for hiding this comment

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

Updated all examples copyright


"""
Linear Programming Solution Example

This example demonstrates how to:
- Create a linear programming problem
- Solve the problem and retrieve result details

Problem:
Minimize: 3x + 2y + 5z
Subject to:
x + y + z = 4
2x + y + z = 5
x, y, z >= 0

Expected Output:
Optimal solution found in 0.02 seconds
Objective: 9.0
x = 1.0, ReducedCost = 0.0
y = 3.0, ReducedCost = 0.0
z = 0.0, ReducedCost = 2.999999858578644
c1 DualValue = 1.0000000592359144
c2 DualValue = 1.0000000821854418
"""

from cuopt.linear_programming.problem import Problem, MINIMIZE


def main():
"""Run the simple LP example."""
problem = Problem("min_dual_rc")

# Add Variables
x = problem.addVariable(lb=0.0, name="x")
y = problem.addVariable(lb=0.0, name="y")
z = problem.addVariable(lb=0.0, name="z")

# Add Constraints (equalities)
problem.addConstraint(x + y + z == 4.0, name="c1")
problem.addConstraint(2.0 * x + y + z == 5.0, name="c2")

# Set Objective (minimize)
problem.setObjective(3.0 * x + 2.0 * y + 5.0 * z, sense=MINIMIZE)

# Solve
problem.solve()

# Check solution status
if problem.Status.name == "Optimal":
print(f"Optimal solution found in {problem.SolveTime:.2f} seconds")
# Get Primal
print("Objective:", problem.ObjValue)
for v in problem.getVariables():
print(
f"{v.VariableName} = {v.Value}, ReducedCost = {v.ReducedCost}"
)
# Get Duals
for c in problem.getConstraints():
print(f"{c.ConstraintName} DualValue = {c.DualValue}")
else:
print(f"Problem status: {problem.Status.name}")


if __name__ == "__main__":
main()
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ LP, QP and MILP API Reference
.. autoclass:: cuopt.linear_programming.problem.Problem
:members:
:undoc-members:
:exclude-members: reset_solved_values, populate_solution, dict_to_object, NumNZs, NumVariables, NumConstraints, IsMIP
:exclude-members: reset_solved_values, populate_solution, dict_to_object, NumNZs, NumVariables, NumConstraints, IsMIP, get_incumbent_values, get_pdlp_warm_start_data, getQcsr

.. autoclass:: cuopt.linear_programming.problem.Variable
:members:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -111,6 +111,46 @@ The response is as follows:
z = 99.99999999999999
Objective value = 399.99999999999994

Working with Quadratic objective matrix
---------------------------------------

:download:`qp_matrix_example.py <examples/qp_matrix_example.py>`

.. literalinclude:: examples/qp_matrix_example.py
:language: python
:linenos:

The response is as follows:

.. code-block:: text

Optimal solution found in 0.16 seconds
p1 = 30.770728122083014
p2 = 65.38350784293876
p3 = 53.84576403497824
Minimized cost = 1153.8461538953868

Inspecting the Problem Solution
-------------------------------

:download:`solution_example.py <examples/solution_example.py>`

.. literalinclude:: examples/solution_example.py
:language: python
:linenos:

The response is as follows:

.. code-block:: text

Optimal solution found in 0.02 seconds
Objective: 9.0
x = 1.0, ReducedCost = 0.0
y = 3.0, ReducedCost = 0.0
z = 0.0, ReducedCost = 2.999999858578644
c1 DualValue = 1.0000000592359144
c2 DualValue = 1.0000000821854418

Working with Incumbent Solutions
--------------------------------

Expand Down
Loading