Skip to content

Rewrite core.relax_integer_vars transformation #3586

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

Merged
merged 15 commits into from
Jun 17, 2025

Conversation

emma58
Copy link
Contributor

@emma58 emma58 commented Apr 29, 2025

Fixes # .

Summary/Motivation:

This rewrites the core.relax_integer_vars transformation, modernizing it to our more recent transformation conventions. In particular, it:

Changes proposed in this PR:

  • Rewrites core.relax_integer_vars transformation
  • Adds tests!
  • Adds VarCollector enum to distinguish getting Vars from active expressions vs. using component_data_objects(Var). Naming suggestions are welcome here...

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.

@emma58 emma58 requested a review from jsiirola April 29, 2025 23:01
@emma58 emma58 requested a review from mrmundt May 12, 2025 22:38
@emma58
Copy link
Contributor Author

emma58 commented May 12, 2025

This is ready for review again, @mrmundt and @jsiirola

@jsiirola jsiirola merged commit ca33341 into Pyomo:main Jun 17, 2025
35 checks passed
Copy link
Member

@jsiirola jsiirola left a comment

Choose a reason for hiding this comment

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

Accidentally hit merge when I meant to update the branch from main. This is fine, with three small comments (none of which would have prevented merging).

doc="""
This argument should be the reverse transformation token
returned by a previous call to this transformation to transform
fixed disjunctive state in the given model.
Copy link
Member

Choose a reason for hiding this comment

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

copy/paste error: disjunctive -> discrete


def _apply_to(self, model, **kwds):
options = kwds.pop('options', {})
if kwds.get('undo', options.get('undo', False)):
if not model.ctype in (Block, Disjunct):
Copy link
Member

Choose a reason for hiding this comment

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

This test differs slightly from the error message. Do you mean if model.ctype not in SubclassOf(Block):?

Comment on lines +184 to +194
for b in block.component_data_objects(Block, active=None, descend_into=True):
if not b.active:
if config.transform_deactivated_blocks:
deprecation_warning(
"The `transform_deactivated_blocks` arguments is deprecated. "
"Either specify deactivated Blocks as targets to activate them "
"if transforming them is the desired behavior.",
version='6.9.3.dev0',
)
else:
continue
Copy link
Member

Choose a reason for hiding this comment

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

Some questions:

  1. Why descend only over Block when you accept Block and Disjunct as targets? Should this be component_data_objects(SubclassOf(Block), ...?
  2. Why test for active inside the loop? Wouldn't it be easier to active = None if config.transform_deactivated_blocks else True? Is the idea to only issue the deprecation warning if model actually had a deactivated block?

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

Successfully merging this pull request may close these issues.

4 participants