Skip to content

Commit

Permalink
Merge branch 'main' into benchmark
Browse files Browse the repository at this point in the history
  • Loading branch information
emma58 authored Nov 27, 2023
2 parents 892021f + 90291b0 commit 1f2ab73
Show file tree
Hide file tree
Showing 2 changed files with 71 additions and 0 deletions.
10 changes: 10 additions & 0 deletions pyomo/repn/plugins/nl_writer.py
Original file line number Diff line number Diff line change
Expand Up @@ -470,12 +470,22 @@ def compile(self, column_order, row_order, obj_order, model_id):
"not exported as part of the NL file. "
"Skipping."
)
if logger.isEnabledFor(logging.DEBUG):
logger.debug(
"Skipped component keys:\n\t"
+ "\n\t".join(sorted(map(str, missing_component_data)))
)
if unknown_data:
logger.warning(
f"model contains export suffix '{self.name}' that "
f"contains {len(unknown_data)} keys that are not "
"Var, Constraint, Objective, or the model. Skipping."
)
if logger.isEnabledFor(logging.DEBUG):
logger.debug(
"Skipped component keys:\n\t"
+ "\n\t".join(sorted(map(str, unknown_data)))
)


class CachingNumericSuffixFinder(SuffixFinder):
Expand Down
61 changes: 61 additions & 0 deletions pyomo/repn/tests/ampl/test_nlv2.py
Original file line number Diff line number Diff line change
Expand Up @@ -953,6 +953,14 @@ def d(m, i):
"keys that are not exported as part of the NL file. Skipping.\n",
LOG.getvalue(),
)
with LoggingIntercept(level=logging.DEBUG) as LOG:
nl_writer.NLWriter().write(m, OUT)
self.assertEqual(
"model contains export suffix 'junk' that contains 1 component "
"keys that are not exported as part of the NL file. Skipping.\n"
"Skipped component keys:\n\ty\n",
LOG.getvalue(),
)

m.junk[m.z] = 1
with LoggingIntercept() as LOG:
Expand All @@ -962,6 +970,14 @@ def d(m, i):
"keys that are not exported as part of the NL file. Skipping.\n",
LOG.getvalue(),
)
with LoggingIntercept(level=logging.DEBUG) as LOG:
nl_writer.NLWriter().write(m, OUT)
self.assertEqual(
"model contains export suffix 'junk' that contains 3 component "
"keys that are not exported as part of the NL file. Skipping.\n"
"Skipped component keys:\n\ty\n\tz[1]\n\tz[3]\n",
LOG.getvalue(),
)

m.junk[m.c] = 2
with LoggingIntercept() as LOG:
Expand Down Expand Up @@ -992,6 +1008,51 @@ def d(m, i):
"Skipping.\n",
LOG.getvalue(),
)
with LoggingIntercept(level=logging.DEBUG) as LOG:
nl_writer.NLWriter().write(m, OUT)
self.assertEqual(
"model contains export suffix 'junk' that contains 6 component "
"keys that are not exported as part of the NL file. Skipping.\n"
"Skipped component keys:\n\tc\n\td[1]\n\td[3]\n\ty\n\tz[1]\n\tz[3]\n"
"model contains export suffix 'junk' that contains 1 keys that "
"are not Var, Constraint, Objective, or the model. Skipping.\n"
"Skipped component keys:\n\t5\n",
LOG.getvalue(),
)

def test_log_timing(self):
# This tests an error possibly reported by #2810
m = ConcreteModel()
m.x = Var(range(6))
m.x[0].domain = pyo.Binary
m.x[1].domain = pyo.Integers
m.x[2].domain = pyo.Integers
m.p = Param(initialize=5, mutable=True)
m.o1 = Objective([1, 2], rule=lambda m, i: 1)
m.o2 = Objective(expr=m.x[1] * m.x[2])
m.c1 = Constraint([1, 2], rule=lambda m, i: sum(m.x.values()) == 1)
m.c2 = Constraint(expr=m.p * m.x[1] ** 2 + m.x[2] ** 3 <= 100)

self.maxDiff = None
OUT = io.StringIO()
with capture_output() as LOG:
with report_timing(level=logging.DEBUG):
nl_writer.NLWriter().write(m, OUT)
self.assertEqual(
""" [+ #.##] Initialized column order
[+ #.##] Collected suffixes
[+ #.##] Objective o1
[+ #.##] Objective o2
[+ #.##] Constraint c1
[+ #.##] Constraint c2
[+ #.##] Categorized model variables: 14 nnz
[+ #.##] Set row / column ordering: 6 var [3, 1, 2 R/B/Z], 3 con [2, 1 L/NL]
[+ #.##] Generated row/col labels & comments
[+ #.##] Wrote NL stream
[ #.##] Generated NL representation
""",
re.sub(r'\d\.\d\d\]', '#.##]', LOG.getvalue()),
)

def test_log_timing(self):
# This tests an error possibly reported by #2810
Expand Down

0 comments on commit 1f2ab73

Please sign in to comment.