Repository: ESMCI/cime

Issue:
Load Balancing Tool Error: 'Pes' object has no attribute 'get_nodes'
The load balancing tool gives the below error when you run load_balancing_submit.py.  The same error shows up when running cime/tools/load_balancing_tool/tests/load_balancing_test.py. I'm using cime version cime5.6.0, not sure when this broke.

Full traceback:
Traceback (most recent call last):
  File "./load_balancing_submit.py", line 320, in <module>
    _main_func(__doc__)
  File "./load_balancing_submit.py", line 315, in _main_func
    force_purge, test_root))
  File "./load_balancing_submit.py", line 219, in load_balancing_submit
    for node in pesobj.get_nodes('pes'):
AttributeError: 'Pes' object has no attribute 'get_nodes'


Discussion:

Resolving patch:
diff --git a/tools/load_balancing_tool/load_balancing_submit.py b/tools/load_balancing_tool/load_balancing_submit.py
--- a/tools/load_balancing_tool/load_balancing_submit.py
+++ b/tools/load_balancing_tool/load_balancing_submit.py
@@ -216,13 +216,18 @@ def load_balancing_submit(compset, res, pesfile, mpilib, compiler, project, mach
         raise SystemExit(1)
 
     pesize_list = []
-    for node in pesobj.get_nodes('pes'):
-        pesize = node.get('pesize')
-        if not pesize:
-            logger.critical('No pesize for pes node in file %s', pesfile)
-        if pesize in pesize_list:
-            logger.critical('pesize %s duplicated in file %s', pesize, pesfile)
-        pesize_list.append(pesize)
+    grid_nodes = pesobj.get_children("grid")
+    for gnode in grid_nodes:
+        mach_nodes = pesobj.get_children("mach", root=gnode)
+        for mnode in mach_nodes:
+            pes_nodes = pesobj.get_children("pes", root=mnode)
+            for pnode in pes_nodes:
+                pesize = pesobj.get(pnode, 'pesize')
+                if not pesize:
+                    logger.critical('No pesize for pes node in file %s', pesfile)
+                if pesize in pesize_list:
+                    logger.critical('pesize %s duplicated in file %s', pesize, pesfile)
+                pesize_list.append(pesize)
 
     if not pesize_list:
         logger.critical('ERROR: No grid entries found in pes file %s', pesfile)
@@ -269,7 +274,7 @@ def load_balancing_submit(compset, res, pesfile, mpilib, compiler, project, mach
         testnames.append( testname)
         logger.info("test is {}".format(testname))
         with Case(testname) as case:
-            pes_ntasks, pes_nthrds, pes_rootpe, _ = \
+            pes_ntasks, pes_nthrds, pes_rootpe, _, _, _ = \
                                                     pesobj.find_pes_layout('any', 'any', 'any', pesize_opts=pesize_list.pop(0))
             for key in pes_ntasks:
                 case.set_value(key, pes_ntasks[key])


Test patch:
diff --git a/tools/load_balancing_tool/tests/load_balancing_test.py b/tools/load_balancing_tool/tests/load_balancing_test.py
--- a/tools/load_balancing_tool/tests/load_balancing_test.py
+++ b/tools/load_balancing_tool/tests/load_balancing_test.py
@@ -210,10 +210,11 @@ def test_write_pes(self):
 
             self.assertTrue(os.access(pes_file.name, os.R_OK), "pesfile %s not written" % pes_file.name)
             pesobj = CIME.XML.pes.Pes(pes_file.name)
-        for node in pesobj.get_nodes('pes'):
-            pesize = node.get('pesize')
-            pes_ntasks, pes_nthrds, pes_rootpe, _ = \
-               pesobj.find_pes_layout('any', 'any', 'any', pesize_opts=pesize)
+
+        pes_ntasks, pes_nthrds, pes_rootpe, _, _, _ = \
+               pesobj.find_pes_layout('any', 'any', 'any', '')
+        self.assertTrue(pes_ntasks['NTASKS_ATM']==992)
+        
 
     def test_set_blocksize_atm(self):
         cmd = "./load_balancing_solve.py --timing-dir %s --total-tasks 64 --blocksize 2 --blocksize-atm 4 --layout IceLndAtmOcn" % os.path.join(TEST_DIR, "timing")