Skip to content

Commit

Permalink
Merge 6e74edd into a4a0eea
Browse files Browse the repository at this point in the history
  • Loading branch information
DKilkenny committed Aug 20, 2020
2 parents a4a0eea + 6e74edd commit b65a3b9
Show file tree
Hide file tree
Showing 4 changed files with 19 additions and 10 deletions.
21 changes: 15 additions & 6 deletions openmdao/core/group.py
Expand Up @@ -2939,6 +2939,7 @@ def _resolve_ambiguous_input_meta(self):

sval = self.get_val(src, kind='output', get_remote=True, from_src=False)
errs = set()
metadata = set()

prom = abs2prom[tgts[0]]
if prom not in self._group_inputs:
Expand All @@ -2951,29 +2952,37 @@ def _resolve_ambiguous_input_meta(self):

if tgt in all_discrete_ins:
if 'value' not in gmeta and sval != tval:
errs.add('value')
errs.add('val')
metadata.add('value')
else:
tmeta = abs2meta[tgt] if tgt in abs2meta else all_abs2meta[tgt]
tunits = tmeta['units'] if 'units' in tmeta else None
if 'units' not in gmeta and sunits != tunits:
errs.add('units')
metadata.add('units')
if 'value' not in gmeta:
if tval.shape == sval.shape:
if _has_val_mismatch(tunits, tval, sunits, sval):
errs.add('value')
errs.add('val')
metadata.add('value')
else:
if all_abs2meta[tgt]['has_src_indices'] and tgt in abs2meta:
srcpart = sval[abs2meta[tgt]['src_indices']]
if _has_val_mismatch(tunits, tval, sunits, srcpart):
errs.add('value')
errs.add('val')
metadata.add('value')

if errs:
self._show_ambiguity_msg(prom, errs, tgts)
self._show_ambiguity_msg(prom, errs, tgts, metadata)
elif src not in all_discrete_outs:
gmeta['units'] = sunits

def _show_ambiguity_msg(self, prom, metavars, tgts):
def _show_ambiguity_msg(self, prom, metavars, tgts, metadata=None):
errs = sorted(metavars)
if metadata is None:
meta = errs
else:
meta = sorted(metadata)
inputs = sorted(tgts)
gpath = common_subpath(tgts)
if gpath == self.pathname:
Expand Down Expand Up @@ -3001,6 +3010,6 @@ def _show_ambiguity_msg(self, prom, metavars, tgts):
gname = f"Group named '{gpath}'" if gpath else 'model'
args = ', '.join([f'{n}=?' for n in errs])
conditional_error(f"{self.msginfo}: The following inputs, {inputs}, promoted "
f"to '{prom}', are connected but their metadata entries {errs}"
f"to '{prom}', are connected but their metadata entries {meta}"
f" differ. Call <group>.set_input_defaults('{gprom}', {args}), "
f"where <group> is the {gname} to remove the ambiguity.")
2 changes: 1 addition & 1 deletion openmdao/core/tests/test_auto_ivc.py
Expand Up @@ -206,7 +206,7 @@ def test_discrete_fan_out(self):
try:
p.setup()
except Exception as err:
self.assertEqual(str(err), "Group (<model>): The following inputs, ['par.C1.x', 'par.C2.x'], promoted to 'x', are connected but their metadata entries ['value'] differ. Call <group>.set_input_defaults('x', value=?), where <group> is the Group named 'par' to remove the ambiguity.")
self.assertEqual(str(err), "Group (<model>): The following inputs, ['par.C1.x', 'par.C2.x'], promoted to 'x', are connected but their metadata entries ['value'] differ. Call <group>.set_input_defaults('x', val=?), where <group> is the Group named 'par' to remove the ambiguity.")
else:
self.fail("Exception expected.")

Expand Down
4 changes: 2 additions & 2 deletions openmdao/core/tests/test_group.py
Expand Up @@ -2511,7 +2511,7 @@ def test_missing_diff_units(self):
p.setup()

self.assertEqual(cm.exception.args[0],
"Group (<model>): The following inputs, ['par.C1.x', 'par.C2.x'], promoted to 'x', are connected but their metadata entries ['units', 'value'] differ. Call <group>.set_input_defaults('x', units=?, value=?), where <group> is the Group named 'par' to remove the ambiguity.")
"Group (<model>): The following inputs, ['par.C1.x', 'par.C2.x'], promoted to 'x', are connected but their metadata entries ['units', 'value'] differ. Call <group>.set_input_defaults('x', units=?, val=?), where <group> is the Group named 'par' to remove the ambiguity.")

def test_missing_diff_vals(self):
p = om.Problem()
Expand All @@ -2525,7 +2525,7 @@ def test_missing_diff_vals(self):
p.setup()

self.assertEqual(cm.exception.args[0],
"Group (<model>): The following inputs, ['par.C1.x', 'par.C2.x'], promoted to 'x', are connected but their metadata entries ['value'] differ. Call <group>.set_input_defaults('x', value=?), where <group> is the Group named 'par' to remove the ambiguity.")
"Group (<model>): The following inputs, ['par.C1.x', 'par.C2.x'], promoted to 'x', are connected but their metadata entries ['value'] differ. Call <group>.set_input_defaults('x', val=?), where <group> is the Group named 'par' to remove the ambiguity.")

def test_conflicting_units(self):
# multiple Group.set_input_defaults calls at same tree level with conflicting units args
Expand Down
2 changes: 1 addition & 1 deletion openmdao/core/tests/test_problem.py
Expand Up @@ -1068,7 +1068,7 @@ def test_feature_get_set_with_units_diff_err(self):
try:
prob.setup()
except RuntimeError as err:
self.assertEqual(str(err), "Group (<model>): The following inputs, ['C1.x', 'C2.x'], promoted to 'x', are connected but their metadata entries ['units', 'value'] differ. Call <group>.set_input_defaults('x', units=?, value=?), where <group> is the model to remove the ambiguity.")
self.assertEqual(str(err), "Group (<model>): The following inputs, ['C1.x', 'C2.x'], promoted to 'x', are connected but their metadata entries ['units', 'value'] differ. Call <group>.set_input_defaults('x', units=?, val=?), where <group> is the model to remove the ambiguity.")
else:
self.fail("Exception expected.")

Expand Down

0 comments on commit b65a3b9

Please sign in to comment.