From a88e1848ed3c1437566d65aa9782ad944ab9006a Mon Sep 17 00:00:00 2001 From: Danny Kilkenny Date: Wed, 23 Oct 2019 13:43:26 -0400 Subject: [PATCH 1/2] Added error message if a user tries to promote non existent inputs/outputs --- openmdao/core/system.py | 4 ++++ openmdao/core/tests/test_group.py | 10 ++++++++++ 2 files changed, 14 insertions(+) diff --git a/openmdao/core/system.py b/openmdao/core/system.py index e82902fd72..68eb258425 100644 --- a/openmdao/core/system.py +++ b/openmdao/core/system.py @@ -2020,6 +2020,10 @@ def resolve(to_match, io_types, matches, proms): pmap[name] = gname + name if gname else name not_found = (set(names).union(renames).union(patterns)) - found + if self._var_promotes['any']: + if not self._var_abs2meta and isinstance(self, openmdao.core.group.Group): + raise RuntimeError('No inputs or outputs found. Check %s ' + 'to make sure it is not empty' % (self.msginfo)) if not_found: if len(io_types) == 2: call = 'promotes' diff --git a/openmdao/core/tests/test_group.py b/openmdao/core/tests/test_group.py index 6acb61c5c5..e58fce1517 100644 --- a/openmdao/core/tests/test_group.py +++ b/openmdao/core/tests/test_group.py @@ -687,6 +687,16 @@ def test_promote_not_found3(self): "ExecComp (C2): 'promotes' failed to find any matches for " "the following names or patterns: ['xx'].") + def test_empty_group(self): + p = om.Problem() + g1 = p.model.add_subsystem('G1', om.Group(), promotes=['*']) + + with self.assertRaises(Exception) as context: + p.setup() + self.assertEqual(str(context.exception), + "No inputs or outputs found. Check Group (G1) " + "to make sure it is not empty") + def test_missing_promote_var(self): p = om.Problem() From 7970524e639ffbae982e1b26924cc632d6ba20f1 Mon Sep 17 00:00:00 2001 From: Danny Kilkenny Date: Wed, 23 Oct 2019 15:28:02 -0400 Subject: [PATCH 2/2] Combined new error with existing error --- openmdao/core/system.py | 7 ++----- openmdao/core/tests/test_group.py | 26 +++++++++++++++++--------- 2 files changed, 19 insertions(+), 14 deletions(-) diff --git a/openmdao/core/system.py b/openmdao/core/system.py index 68eb258425..e0e6faed76 100644 --- a/openmdao/core/system.py +++ b/openmdao/core/system.py @@ -2020,17 +2020,14 @@ def resolve(to_match, io_types, matches, proms): pmap[name] = gname + name if gname else name not_found = (set(names).union(renames).union(patterns)) - found - if self._var_promotes['any']: - if not self._var_abs2meta and isinstance(self, openmdao.core.group.Group): - raise RuntimeError('No inputs or outputs found. Check %s ' - 'to make sure it is not empty' % (self.msginfo)) if not_found: + print(not_found) if len(io_types) == 2: call = 'promotes' else: call = 'promotes_%ss' % io_types[0] raise RuntimeError("%s: '%s' failed to find any matches for the following " - "names or patterns: %s." % + "names or patterns: %s. Check to make sure it is not empty" % (self.msginfo, call, sorted(not_found))) maps = {'input': {}, 'output': {}} diff --git a/openmdao/core/tests/test_group.py b/openmdao/core/tests/test_group.py index e58fce1517..302728a1f0 100644 --- a/openmdao/core/tests/test_group.py +++ b/openmdao/core/tests/test_group.py @@ -408,7 +408,8 @@ def test_group_renames_errors_not_found(self): p.setup() self.assertEqual(str(err.exception), "IndepVarComp (comp1): 'promotes_outputs' failed to find any matches for " - "the following names or patterns: ['xx'].") + "the following names or patterns: ['xx']. " + "Check to make sure it is not empty") def test_group_renames_errors_bad_tuple(self): p = om.Problem() @@ -473,7 +474,8 @@ def setup(self): p.setup() self.assertEqual(str(err.exception), "SellarDis2 (d1): 'promotes_outputs' failed to find any matches for " - "the following names or patterns: ['foo'].") + "the following names or patterns: ['foo']. " + "Check to make sure it is not empty") def test_group_nested_conn(self): """Example of adding subsystems and issuing connections with nested groups.""" @@ -659,7 +661,8 @@ def test_promote_not_found1(self): p.setup() self.assertEqual(str(context.exception), "ExecComp (C2): 'promotes_outputs' failed to find any matches for " - "the following names or patterns: ['x*'].") + "the following names or patterns: ['x*']. " + "Check to make sure it is not empty") def test_promote_not_found2(self): p = om.Problem() @@ -672,7 +675,8 @@ def test_promote_not_found2(self): p.setup() self.assertEqual(str(context.exception), "ExecComp (C2): 'promotes_inputs' failed to find any matches for " - "the following names or patterns: ['xx'].") + "the following names or patterns: ['xx']. " + "Check to make sure it is not empty") def test_promote_not_found3(self): p = om.Problem() @@ -685,7 +689,8 @@ def test_promote_not_found3(self): p.setup() self.assertEqual(str(context.exception), "ExecComp (C2): 'promotes' failed to find any matches for " - "the following names or patterns: ['xx'].") + "the following names or patterns: ['xx']. " + "Check to make sure it is not empty") def test_empty_group(self): p = om.Problem() @@ -694,8 +699,9 @@ def test_empty_group(self): with self.assertRaises(Exception) as context: p.setup() self.assertEqual(str(context.exception), - "No inputs or outputs found. Check Group (G1) " - "to make sure it is not empty") + "Group (G1): 'promotes' failed to find any matches for " + "the following names or patterns: ['*']. " + "Check to make sure it is not empty") def test_missing_promote_var(self): p = om.Problem() @@ -710,7 +716,8 @@ def test_missing_promote_var(self): p.setup() self.assertEqual(str(context.exception), "ExecComp (d1): 'promotes_inputs' failed to find any matches for " - "the following names or patterns: ['foo'].") + "the following names or patterns: ['foo']. " + "Check to make sure it is not empty") def test_missing_promote_var2(self): p = om.Problem() @@ -725,7 +732,8 @@ def test_missing_promote_var2(self): p.setup() self.assertEqual(str(context.exception), "ExecComp (d1): 'promotes_outputs' failed to find any matches for " - "the following names or patterns: ['bar', 'blammo'].") + "the following names or patterns: ['bar', 'blammo']. " + "Check to make sure it is not empty") def test_promote_src_indices(self): import numpy as np