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

add equivalent unit conversion check and tests #1690

Merged
merged 2 commits into from Sep 18, 2020

Conversation

wright
Copy link
Contributor

@wright wright commented Sep 17, 2020

Summary

Variables promoted with equivalent but different units (such as 'm/s/s' vs. 'm/s**2' will raise an exception without set_input_defaults. Before raising the exception, make sure the units not equivalent.

Related Issues

Backwards incompatibilities

None

New Dependencies

None

@project-bot project-bot bot added this to In progress in OpenMDAO Dev [Read only] Sep 17, 2020
OpenMDAO Dev [Read only] automation moved this from In progress to Reviewer approved Sep 17, 2020
errs.add('units')
metadata.add('units')
try:
test_conv = unit_conversion(sunits, tunits)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Since PhysicalUnit objects understand if they're equivalent or not, we could do this a little more cleanly:

if _find_unit(sunits) != _find_unit(tunits):
   errs.add('units')
   metadata.add('units')

_find_unit is found in openmdao.utils.units

z={'value': 1.0, 'units': 'J/s'}),
promotes_inputs=['x', 'z'])
# trying to convert J/s/s to m/s**2 should cause Incompatible units TypeError exception
with self.assertRaises(TypeError):
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We should check the contents of the error message here as well.

@wright
Copy link
Contributor Author

wright commented Sep 18, 2020

The requested changes have been made.

@swryan swryan merged commit 98de2a5 into OpenMDAO:master Sep 18, 2020
OpenMDAO Dev [Read only] automation moved this from Reviewer approved to Done Sep 18, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
No open projects
Development

Successfully merging this pull request may close these issues.

Promoting variables with different but equivalent units errors due to ambiguity
4 participants