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

NLv2 presolver: resolve constant defined vars/external functions #3276

Merged
merged 34 commits into from
May 29, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
34 commits
Select commit Hold shift + click to select a range
4f0c8d8
Simplify constant NL expressions in defined vars due to the presolver
jsiirola Apr 18, 2024
bfd14b1
Merge branch 'main' into nlv2-presolve-defined-vars
jsiirola Apr 19, 2024
afa542f
Improve comments/error messages
jsiirola Apr 19, 2024
1a8ab96
Fix typo in baseline
jsiirola Apr 19, 2024
a5c7931
Remove debugging
jsiirola Apr 22, 2024
8390ce4
Fix the arg count for unary operators
jsiirola Apr 22, 2024
909fd1e
Support deferred final resolution of external function args
jsiirola May 16, 2024
c9ad06a
Merge branch 'main' into nlv2-presolve-defined-vars
jsiirola May 16, 2024
2a2fe4e
Attempt to propagate initial values for presolved variables
jsiirola May 16, 2024
4ebaa66
Merge branch 'main' into nlv2-presolve-defined-vars
jsiirola May 20, 2024
9ded80f
Resolve KeyError with export_nonlinear_variables
jsiirola May 20, 2024
5badeba
Fix error when ressolving constant arguments to external functions
jsiirola May 20, 2024
6c1ced9
Add test for external functions whose arguments presolve to constants
jsiirola May 20, 2024
26c0e4b
NFC: apply black
jsiirola May 20, 2024
f616ade
Remove subexpression_order from AMPLRepnVisitor
jsiirola May 21, 2024
b87325a
Revert some previous changes that were not necessary: because we work…
jsiirola May 21, 2024
254ca04
Avoid error cor constant AMPLRepn objects
jsiirola May 21, 2024
0fecf80
Resolve potential information leak when duplicating AMPLRepn
jsiirola May 21, 2024
7a9a83e
Additional error checking when substituting simple named expressions
jsiirola May 21, 2024
69b7d30
Resolve error when collecting named expressions used in external func…
jsiirola May 21, 2024
0ceedc6
Track changes in AMPLRepnVisitor (handling of external functions)
jsiirola May 21, 2024
6be83b5
NFC: clarify comment wrt string args
jsiirola May 23, 2024
04313dc
fix detection of variables replaces with expressions
jsiirola May 23, 2024
27df1e5
Defer categorizing constraints until after linear presolve
jsiirola May 24, 2024
746737b
Support simplifying/eliminating constant defined variables
jsiirola May 28, 2024
6aa55f2
Simplify handling of NL file newlines around var identifiers
jsiirola May 28, 2024
b7145d9
Add additional testing
jsiirola May 28, 2024
4d10cdf
NFC: fix spelling
jsiirola May 28, 2024
cd62d5b
Improve resolution of constant external function / defined variable s…
jsiirola May 29, 2024
5d4ce08
bugfix: undefined variable
jsiirola May 29, 2024
53f96b3
Merge branch 'main' into nlv2-presolve-defined-vars
jsiirola May 29, 2024
15088de
Updating baseline to reflect improved linear constraint detection
jsiirola May 29, 2024
1bed2c6
NFC: fix typos
jsiirola May 29, 2024
956c201
Merge remote-tracking branch 'refs/remotes/me/nlv2-presolve-defined-v…
jsiirola May 29, 2024
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
2 changes: 0 additions & 2 deletions pyomo/contrib/incidence_analysis/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -130,7 +130,6 @@ def get_config_from_kwds(**kwds):
and kwds.get("_ampl_repn_visitor", None) is None
):
subexpression_cache = {}
subexpression_order = []
external_functions = {}
var_map = {}
used_named_expressions = set()
Expand All @@ -143,7 +142,6 @@ def get_config_from_kwds(**kwds):
amplvisitor = AMPLRepnVisitor(
text_nl_template,
subexpression_cache,
subexpression_order,
external_functions,
var_map,
used_named_expressions,
Expand Down
21 changes: 16 additions & 5 deletions pyomo/contrib/incidence_analysis/incidence.py
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,17 @@ def _get_incident_via_standard_repn(


def _get_incident_via_ampl_repn(expr, linear_only, visitor):
def _nonlinear_var_id_collector(idlist):
for _id in idlist:
if _id in visitor.subexpression_cache:
info = visitor.subexpression_cache[_id][1]
if info.nonlinear:
yield from _nonlinear_var_id_collector(info.nonlinear[1])
if info.linear:
yield from _nonlinear_var_id_collector(info.linear)
else:
yield _id

var_map = visitor.var_map
orig_activevisitor = AMPLRepn.ActiveVisitor
AMPLRepn.ActiveVisitor = visitor
Expand All @@ -91,13 +102,13 @@ def _get_incident_via_ampl_repn(expr, linear_only, visitor):
finally:
AMPLRepn.ActiveVisitor = orig_activevisitor

nonlinear_var_ids = [] if repn.nonlinear is None else repn.nonlinear[1]
nonlinear_var_id_set = set()
unique_nonlinear_var_ids = []
for v_id in nonlinear_var_ids:
if v_id not in nonlinear_var_id_set:
nonlinear_var_id_set.add(v_id)
unique_nonlinear_var_ids.append(v_id)
if repn.nonlinear:
for v_id in _nonlinear_var_id_collector(repn.nonlinear[1]):
if v_id not in nonlinear_var_id_set:
nonlinear_var_id_set.add(v_id)
unique_nonlinear_var_ids.append(v_id)

nonlinear_vars = [var_map[v_id] for v_id in unique_nonlinear_var_ids]
linear_only_vars = [
Expand Down
Loading
Loading