Skip to content

Conversation

@Iroy30
Copy link
Member

@Iroy30 Iroy30 commented Jul 22, 2025

Description

Issue

Checklist

  • I am familiar with the Contributing Guidelines.
  • Testing
    • New or existing tests cover these changes
    • Added tests
    • Created an issue to follow-up
    • NA
  • Documentation
    • The documentation is up to date with these changes
    • Added new documentation
    • NA

Working on Adding tests and solution extraction

@Iroy30 Iroy30 requested a review from a team as a code owner July 22, 2025 20:52
@Iroy30 Iroy30 requested a review from rgsl888prabhu July 22, 2025 20:52
@copy-pr-bot
Copy link

copy-pr-bot bot commented Jul 22, 2025

This pull request requires additional validation before any workflows can run on NVIDIA's runners.

Pull request vetters can view their responsibilities here.

Contributors can view more details about this message here.

for i in range(nz):
v_idx = expr.vars[i].index
v_coeff = expr.coefficients[i]
self.vindex_coeff_dict[v_idx] = self.vindex_coeff_dict[v_idx] + v_coeff if v_idx in self.vindex_coeff_dict else v_coeff
Copy link
Contributor

@chris-maes chris-maes Jul 23, 2025

Choose a reason for hiding this comment

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

My guess is that the speed of this loop can be improved.

The hash lookup is likely costly. Suppose you have an array of size n (where n is the number of variables) that is all zero. You could store that array in the problem.

workspace = problem.workspace # workspace is all zero and of length variables

# scatter the nonzero coefficients into workspace.
# Any coefficients with the same variable index will get added
self.indices = []
for i in range (nz):
     j = expr.vars[i].index
     x = expr.coefficients[i]
     if workspace[j] == 0.0:
          self.indices.append(j)
     workspace[j] += x

# gather the nonzero coefficients into self.coefficients
final_nz = len(self.indices)
self.coefficients = []
for k in range(final_nz):
    self.coefficients.append(workspace[self.indicies[k]])

# clear workspace
for k in range(final_nz):
    workspace[self.indices[k]] = 0.0

This should be fast in C/C++. But might be slow in Python.

Copy link
Member Author

Choose a reason for hiding this comment

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

We can have this as an evaluation and improvement in the next cycle. It looks promising but not a significant improvement. Needs further perf results.

Copy link
Collaborator

@rgsl888prabhu rgsl888prabhu left a comment

Choose a reason for hiding this comment

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

Awesome work @chris-maes and @Iroy30, I have initial few comments.

Also lets add pytests to cover all the APIs and also scenarios where problem gets modified in a succession so the addition and deletion can be tested to make sure data is getting updated.

@chris-maes
Copy link
Contributor

Awesome work @chris-maes and @Iroy30, I have initial few comments.

Also lets add pytests to cover all the APIs and also scenarios where problem gets modified in a succession so the addition and deletion can be tested to make sure data is getting updated.

@rgsl888prabhu deletion is not supported with this API. You can only add new variables or add new constraints.

@Iroy30 for addition of variables and constraints we might want to reconsider the design a bit. Adding a new variable to a problem should probably invalidate the .Value and .ReducedCost of existing variables, and the .Slack and .DualValue of Constraint, if the previous problem has been solved. Maybe we should store the solution info in the Problem object. Variable and Constraint can store a pointer to the problem. When you try to access these values you go through the problem. When a user adds a new variable or constraint to the problem we can mark the current solution as dirty.

@Iroy30
Copy link
Member Author

Iroy30 commented Jul 30, 2025

/ok to test a27fb80

@Iroy30
Copy link
Member Author

Iroy30 commented Jul 30, 2025

/ok to test 7562bbe

@Iroy30
Copy link
Member Author

Iroy30 commented Jul 30, 2025

/ok to test d71b77e

# Set the incumbent callback
incumbent_callback = IncumbentCallback()
settings.set_mip_callback(incumbent_callback)
settings.set_parameter("time_limit", 30) # Allow enough time to find multiple incumbents
Copy link
Contributor

Choose a reason for hiding this comment

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

Let's not use a bare string here. Let's use CUOPT_TIME_LIMIT instead.

Copy link
Collaborator

Choose a reason for hiding this comment

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

@Iroy30 can you please address this review

Copy link
Collaborator

Choose a reason for hiding this comment

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

And also other places where we use time_limit? And may be also update test case to do same thing.

Copy link
Member Author

Choose a reason for hiding this comment

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

that looks to be the only place in docs

@Iroy30
Copy link
Member Author

Iroy30 commented Jul 31, 2025

/ok to test 8ae3746

@rgsl888prabhu
Copy link
Collaborator

/ok to test e6ade53

Copy link
Contributor

@chris-maes chris-maes left a comment

Choose a reason for hiding this comment

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

LGTM. I think we should merge as is. We can follow up with some doc improvements before the release.

@Iroy30
Copy link
Member Author

Iroy30 commented Jul 31, 2025

/ok to test 2c0a1ab

@Iroy30
Copy link
Member Author

Iroy30 commented Jul 31, 2025

/ok to test f5c127d

@Iroy30
Copy link
Member Author

Iroy30 commented Jul 31, 2025

/ok to test a8a6515

@Iroy30
Copy link
Member Author

Iroy30 commented Jul 31, 2025

/ok to test 1967a3d

@Iroy30
Copy link
Member Author

Iroy30 commented Jul 31, 2025

/merge

@rapids-bot rapids-bot bot merged commit a807755 into NVIDIA:branch-25.08 Jul 31, 2025
73 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

feature request New feature or request non-breaking Introduces a non-breaking change

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants