Skip to content

Commit

Permalink
Merge pull request Pyomo#3043 from jsiirola/nlv2-suffix-debug-log
Browse files Browse the repository at this point in the history
Log which suffix values were skipped at the DEBUG level
  • Loading branch information
blnicho authored Nov 27, 2023
2 parents 05ac00c + 6d04656 commit 4a49039
Show file tree
Hide file tree
Showing 2 changed files with 37 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
27 changes: 27 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,17 @@ 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
Expand Down

0 comments on commit 4a49039

Please sign in to comment.