Repository: Pyomo/pyomo

Issue:
assert_units_consistent fails when model has reference to unindexed Var
## Summary

Running `assert_units_consistent` on a model with a `Reference` to an unindexed variable results in an error.

### Steps to reproduce the issue

```console
import pyomo.environ as pyo
from pyomo.util.check_units import assert_units_consistent

m = pyo.ConcreteModel()

m.x = pyo.Var(initialize=1, units=pyo.units.m)
m.y = pyo.Var(initialize=1, units=pyo.units.m)
m.z = pyo.Reference(m.x)
m.expr = pyo.Expression(expr=(m.x+m.z[None]))
assert_units_consistent(m)
```

### Error Message

>   Traceback (most recent call last):
> 
>   File ~\Work\assert_units_consistent_fail.py:10 in <module>
>     assert_units_consistent(m)
> 
>   File ~\miniconda3\envs\idaes-new\lib\site-packages\pyomo\util\check_units.py:236 in assert_units_consistent
>     handler(obj)
> 
>   File ~\miniconda3\envs\idaes-new\lib\site-packages\pyomo\util\check_units.py:164 in _assert_units_consistent_block
>     assert_units_consistent(component)
> 
>   File ~\miniconda3\envs\idaes-new\lib\site-packages\pyomo\util\check_units.py:219 in assert_units_consistent
>     raise TypeError("Units checking not supported for object of type {}.".format(obj.ctype))
> 
> TypeError: Units checking not supported for object of type <class 'pyomo.core.base.set.SetOf'>.

### Information on your system

Pyomo version: 6.4.0
Python version: 3.9
Operating system: Windows 11
How Pyomo was installed: Through IDAES install (I think the script uses pip?)



Discussion:

Resolving patch:
diff --git a/pyomo/util/check_units.py b/pyomo/util/check_units.py
--- a/pyomo/util/check_units.py
+++ b/pyomo/util/check_units.py
@@ -15,9 +15,9 @@
 """
 from pyomo.core.base.units_container import units, UnitsError
 from pyomo.core.base import (Objective, Constraint, Var, Param,
-                             Suffix, Set, RangeSet, Block,
+                             Suffix, Set, SetOf, RangeSet, Block,
                              ExternalFunction, Expression,
-                             value, BooleanVar)
+                             value, BooleanVar, BuildAction, BuildCheck)
 from pyomo.dae import ContinuousSet, DerivativeVar
 from pyomo.network import Port, Arc
 from pyomo.mpec import Complementarity
@@ -173,17 +173,24 @@ def _assert_units_consistent_block(obj):
     Expression: _assert_units_consistent_property_expr,
     Suffix: None,
     Param: _assert_units_consistent_expression,
-    Set: None,
-    RangeSet: None,
     Disjunct: _assert_units_consistent_block,
     Disjunction: None,
     BooleanVar: None,
     Block: _assert_units_consistent_block,
     ExternalFunction: None,
-    ContinuousSet: None, # ToDo: change this when continuous sets have units assigned
+    # TODO: change this when Sets / ContinuousSets sets have units:
+    ContinuousSet: None,
+    Set: None,
+    SetOf: None,
+    RangeSet: None,
+    # TODO: Piecewise: _assert_units_consistent_piecewise,
+    # TODO: SOSConstraint: _assert_units_consistent_sos,
+    # TODO: LogicalConstriant: _assert_units_consistent_logical,
+    BuildAction: None,
+    BuildCheck: None,
     # complementarities that are not in normal form are not working yet
     # see comment in test_check_units
-    # Complementarity: _assert_units_complementarity
+    # TODO: Complementarity: _assert_units_complementarity
     }
 
 def assert_units_consistent(obj):


Test patch: