Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add "mixed" standard form representation #3201

Merged
merged 6 commits into from
Apr 2, 2024

Conversation

jsiirola
Copy link
Member

Fixes # .

Summary/Motivation:

This adds a new option to the "Standard Form" compiler that returns a mix of inequality and equality constraints. This representation is particularly useful for solver interfaces. This PR also resolves an error when collapsing unused variables out of the returned matrices. The new implementation is also slightly more performant.

Changes proposed in this PR:

  • add a "mixed" representation to the standard form compiler
  • correct indexing error when removing unused columns from the A matrix and c vector

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.

@@ -372,7 +384,30 @@ def write(self, model):
f"model contains a trivially infeasible constraint, '{con.name}'"
)

if slack_form:
if mixed_form:
Copy link
Contributor

Choose a reason for hiding this comment

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

Is it more likely that a user will want mixed_form over slack_form?

Copy link
Member Author

Choose a reason for hiding this comment

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

Users will probably do the regular form first, and then maybe the slack form. However, I am working on some (more efficient) solver interfaces (a rewrite of gurobi_direct) that will use the mixed_form.

pyomo/repn/tests/test_standard_form.py Outdated Show resolved Hide resolved
Comment on lines 263 to 264
# Note that the solution is a mix of inequality and equality constraints
# self._verify_solution(soln, repn, False)
Copy link
Contributor

Choose a reason for hiding this comment

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

Debugging?

Copy link
Member Author

Choose a reason for hiding this comment

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

Not debugging: a breadcrumb as to why that test is not an exact copy-and-paste of the cases above. I have expanded the comment.

@blnicho blnicho requested a review from emma58 March 26, 2024 18:40
Copy link
Contributor

@emma58 emma58 left a comment

Choose a reason for hiding this comment

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

This looks good--I'm excited about it! :) My only big question is that I had a little argument with myself about multiple objectives... I feel like you're probably right, but the idea of more than one objective in "standard form" seems a little terrifying.

Comment on lines -455 to 489
active_var_idx[-1] = A.indptr[-1]
# active_var_idx[-1] = len(columns)
A = scipy.sparse.csc_array(
Copy link
Contributor

Choose a reason for hiding this comment

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

Did you intend to leave this comment?

)
self.assertTrue(np.all(repn.A == ref))
self.assertTrue(np.all(repn.b == np.array([3, 5, 6, -3, 8])))
self.assertTrue(np.all(repn.c == np.array([[-1, 0, -5, 0], [1, 0, 0, 15]])))
Copy link
Contributor

@emma58 emma58 Apr 2, 2024

Choose a reason for hiding this comment

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

EEEEEK, I didn't notice this before--should we really let a "standard form" have more than one objective? This caused me a moment of terror on the the thought that I would definitely assume c is a vector of the same dimension as the number of columns in A... The matrix c makes sense to me from a writer perspective. From a user/transformation perspective, we're always going to need to be checking that this isn't the case... But I guess we have to do that anyway, so why not here?

@blnicho blnicho merged commit 2a16b19 into Pyomo:main Apr 2, 2024
33 checks passed
@jsiirola jsiirola deleted the mixed-standard-form branch April 4, 2024 04:46
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.

4 participants