From 6d046563719982d6de2e2884c7e5dfeaff4a7aa8 Mon Sep 17 00:00:00 2001 From: John Siirola Date: Fri, 17 Nov 2023 22:26:43 -0700 Subject: [PATCH] Log which suffix values were skipped at the DEBUG level --- pyomo/repn/plugins/nl_writer.py | 10 ++++++++++ pyomo/repn/tests/ampl/test_nlv2.py | 28 ++++++++++++++++++++++++++++ 2 files changed, 38 insertions(+) diff --git a/pyomo/repn/plugins/nl_writer.py b/pyomo/repn/plugins/nl_writer.py index 32cec880320..ab1ec88a499 100644 --- a/pyomo/repn/plugins/nl_writer.py +++ b/pyomo/repn/plugins/nl_writer.py @@ -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): diff --git a/pyomo/repn/tests/ampl/test_nlv2.py b/pyomo/repn/tests/ampl/test_nlv2.py index a4fbaee77ed..ef4be290708 100644 --- a/pyomo/repn/tests/ampl/test_nlv2.py +++ b/pyomo/repn/tests/ampl/test_nlv2.py @@ -13,6 +13,7 @@ import pyomo.common.unittest as unittest import io +import logging import math import os @@ -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: @@ -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: @@ -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