pythonpython-3.xopenmdao

What is openMDAO's reasoning for returning 'None' for self cancelling units


I've setup an Explicit Component model...

one of my outputs is a ratio:

    self.add_output('diameter_over_thickness', units='mm/mm')

Upon the class being initialized, openMDAO assigns the units to this output as None.

openMDAO .list_outputs() output

Why not unitless ? I feel it would be a more effective representation...

Yes I could just assign it to be unitless but I do not want to do this. It becomes problematic when you're using openMDAO's get_val() function and a dictionary of predefined units you can call from.


Solution

  • As of OpenMDAO V3.20 I would say this is more of a legacy behavior than an active choice. the unitless unit didn't exist early on AND we thought that variables with no unit defined (which defaulted to None) should be compatible with variables that were defined as unitless.

    There is a connection rule that allows variables with units to be connected to other variables that have None. One of the key motivations for this is that often times ExecComp I/O is defined without units and it is very convinent to be able to connect dimensional quantities to them.

    However, that same rule does not apply to unitless variables. In that case, we understand that the user has actively said there are no units and hence a connection to a dimensional quantity should not be allowed.

    So there are some semantic differences between None and unitless. However, I can see the argument that mm/mm should be treated as unitless and not None. A change like this is backwards incompatible though and would require a POEM to be written and approved before an implementation change could be made. I suspect the dev team would welcome a POEM on this subject.