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

Log which suffix values were skipped at the DEBUG level #3043

Merged
merged 1 commit into from
Nov 27, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
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
28 changes: 28 additions & 0 deletions pyomo/repn/tests/ampl/test_nlv2.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
import pyomo.common.unittest as unittest

import io
import logging
import math
import os

Expand Down Expand Up @@ -949,6 +950,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 @@ -958,6 +967,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 @@ -988,6 +1005,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_linear_constraint_npv_const(self):
# This tests an error possibly reported by #2810
Expand Down