internlm/SWE-Fixer-Train-110K huggingface dataset:
Repository: ESMCI/cime

Issue:
testreporter not catching failing NCK tests
The testreporter isn't parsing TestStatus correctly to report failed NCK tests.


Discussion:
Need to add a check for "COMPARE_base_multiinst".  Also need to add "COMPARE_base_test" and "COMPARE_base_single_thread"

Resolving patch:
diff --git a/scripts/Tools/testreporter.py b/scripts/Tools/testreporter.py
--- a/scripts/Tools/testreporter.py
+++ b/scripts/Tools/testreporter.py
@@ -181,13 +181,31 @@ def get_testreporter_xml(testroot, testid, tagname, testtype):
                 if line[0:4] == "FAIL":
                     test_status['COMMENT']+="Hybrid fail! "
                     break
+            if "COMPARE_base_multiinst" in line:
+                test_status['STATUS']=line[0:4]
+                if line[0:4] == "FAIL":
+                    test_status['COMMENT']+="Multi instance fail! "
+                    break
+            if "COMPARE_base_test" in line:
+                test_status['STATUS']=line[0:4]
+                if line[0:4] == "FAIL":
+                    test_status['COMMENT']+="Base test fail! "
+                    break
+            if "COMPARE_base_single_thread" in line:
+                test_status['STATUS']=line[0:4]
+                if line[0:4] == "FAIL":
+                    test_status['COMMENT']+="Thread test fail! "
+                    break
 
             #
             #  Do not include time comments.  Just a preference to have cleaner comments in the test database
             #
             try:
-                if 'time=' not in line:
-                    test_status['COMMENT']+=line.split(' ',3)[3]+' '
+                if 'time=' not in line and 'GENERATE' not in line:
+                    if 'BASELINE' not in line:
+                        test_status['COMMENT']+=line.split(' ',3)[3]+' '
+                    else:
+                        test_status['COMMENT']+=line.split(' ',4)[4]+' '
             except:
                 pass
 


Test patch:
Repository: ESMCI/cime

Issue:
eval statement in env_batch can produce unexpected results
When setting the JOB_QUEUE=long we notice that the eval statement in env_batch.py unexpectedly
evaluates the string long to be ```<type 'long'>```
The solution is to only use the eval statement if the setting includes whitespace.  


Discussion:

Resolving patch:
diff --git a/scripts/lib/CIME/XML/env_batch.py b/scripts/lib/CIME/XML/env_batch.py
--- a/scripts/lib/CIME/XML/env_batch.py
+++ b/scripts/lib/CIME/XML/env_batch.py
@@ -287,10 +287,13 @@ def get_submit_args(self, case, job):
                     val = case.get_resolved_value(name)
 
                 if val is not None and len(str(val)) > 0 and val != "None":
-                    # Try to evaluate val
-                    try:
-                        rval = eval(val)
-                    except:
+                    # Try to evaluate val if it contains any whitespace
+                    if " " in val:
+                        try:
+                            rval = eval(val)
+                        except:
+                            rval = val
+                    else:
                         rval = val
                     # need a correction for tasks per node
                     if flag == "-n" and rval<= 0:


Test patch:
Repository: ESMCI/cime

Issue:
PIO_NUMTASKS is getting reset
Setting env_run.xml's PIO_STRIDE to default -99 and PIO_NUMTASKS to 64 resets both PIO_STRIDE and PIO_NUMTASKS to different default values at run-time.

XML comments:
```
    <entry id="PIO_STRIDE">
      <desc>
     stride in compute comm of io tasks for each component, if this value is -99 it will 
     be computed based on PIO_NUMTASKS and number of compute tasks
    </desc>
```

but instead of 64, PIO_NUMTASKS is getting reset to 8 or 16 depending on the number of component's MPI tasks.

Note that setting PIO_STRIDE to a specific value and leaving PIO_NUMTASKS at default -99 works as expected: PIO_NUMTASKS is set to NTASKS / PIO_STRIDE.


Discussion:
Looks like the issue is in shr_pio_mod.F90:shr_pio_read_component_namelist() where the stride is set to default (if stride = -99) without checking if pio_numiotasks are valid,
```
if(pio_stride== -99) pio_stride = pio_default_stride
```
If pio_numiotasks is valid the code should try to compute stride from it.
A related issue is that shr_pio_read_component_namelist() is doing the job of function shr_pio_namelist_set() that already has logic to reset stride and numiotasks to valid
values.
I think this is the change you need to make:
```
diff --git a/src/share/util/shr_pio_mod.F90 b/src/share/util/shr_pio_mod.F90
index 27894e9..b3ed425 100644
--- a/src/share/util/shr_pio_mod.F90
+++ b/src/share/util/shr_pio_mod.F90
@@ -545,7 +545,13 @@ contains
 
           call shr_pio_getiotypefromname(pio_typename, pio_iotype, pio_default_iotype)
        end if
-       if(pio_stride== -99) pio_stride = pio_default_stride
+       if(pio_stride== -99) then
+          if (pio_numiotasks > 0) then
+             pio_stride = npes/pio_numiotasks
+          else
+             pio_stride = pio_default_stride
+          endif
+       endif
```

Resolving patch:
diff --git a/scripts/lib/CIME/case_run.py b/scripts/lib/CIME/case_run.py
--- a/scripts/lib/CIME/case_run.py
+++ b/scripts/lib/CIME/case_run.py
@@ -269,8 +269,10 @@ def case_run(case, skip_pnl=False):
             lid = new_lid()
 
         if prerun_script:
+            case.flush()
             do_external(prerun_script, case.get_value("CASEROOT"), case.get_value("RUNDIR"),
                         lid, prefix="prerun")
+            case.read_xml()
 
         lid = run_model(case, lid, skip_pnl)
         save_logs(case, lid)       # Copy log files back to caseroot
@@ -278,12 +280,16 @@ def case_run(case, skip_pnl=False):
             get_timing(case, lid)     # Run the getTiming script
 
         if data_assimilation:
+            case.flush()
             do_data_assimilation(data_assimilation_script, case.get_value("CASEROOT"), cycle, lid,
                                  case.get_value("RUNDIR"))
+            case.read_xml()
 
         if postrun_script:
+            case.flush()
             do_external(postrun_script, case.get_value("CASEROOT"), case.get_value("RUNDIR"),
                         lid, prefix="postrun")
+            case.read_xml()
 
         save_postrun_provenance(case)
 


Test patch:
Repository: ESMCI/cime

Issue:
compare_test_results generates error, "Could not find a matching MPI for attributes"
Out of cime master (on yellowstone), I did:

```
./create_test --test-root . --walltime 0:30 ERS_Ld3.f45_g37_rx1.A.yellowstone_intel
```

then when it completed

```
Tools/compare_test_results -b cesm2_0_alpha06m --baseline-root $CESMDATAROOT/ccsm_baselines -r . -t 20170525_094940_daztcr
```

This gave:

```
ERROR: Could not find a matching MPI for attributes: {'mpilib': 'mpich2', 'threaded': False, 'compiler': 'intel'}
```

I just ran into similar errors with somewhat older versions of cime - going back to at least cime5.3.0-alpha.13


Discussion:
I'm unable to duplicate this error on melvin and do not have access to yellowstone. It probably has something to do with CESM configuration, so reassigning to @jedwards4b 

Resolving patch:
diff --git a/scripts/lib/CIME/XML/env_mach_specific.py b/scripts/lib/CIME/XML/env_mach_specific.py
--- a/scripts/lib/CIME/XML/env_mach_specific.py
+++ b/scripts/lib/CIME/XML/env_mach_specific.py
@@ -18,9 +18,8 @@ def __init__(self, caseroot=None, infile="env_mach_specific.xml",
         """
         initialize an object interface to file env_mach_specific.xml in the case directory
         """
-        fullpath = infile if os.path.isabs(infile) else os.path.join(caseroot, infile)
         schema = os.path.join(get_cime_root(), "config", "xml_schemas", "env_mach_specific.xsd")
-        EnvBase.__init__(self, caseroot, fullpath,schema=schema)
+        EnvBase.__init__(self, caseroot, infile, schema=schema)
         self._allowed_mpi_attributes = ("compiler", "mpilib", "threaded", "unit_testing")
         self._unit_testing = unit_testing
 
@@ -236,7 +235,7 @@ def _load_modules_generic(self, modules_to_load):
         # Purpose is for environment management system that does not have
         # a python interface and therefore can only determine what they
         # do by running shell command and looking at the changes
-        # in the environment.  
+        # in the environment.
 
         cmd = "source {}".format(sh_init_cmd)
 
@@ -283,7 +282,7 @@ def _load_modules_generic(self, modules_to_load):
             if key in os.environ and key not in newenv:
                 del(os.environ[key])
             else:
-                os.environ[key] = newenv[key] 
+                os.environ[key] = newenv[key]
 
     def _load_none_modules(self, modules_to_load):
         """


Test patch:
Repository: ESMCI/cime

Issue:
scripts_regression_tests fails on small systems 
In K_TestCimeCase it is assumed that a machine has capability to run a job on P16x8 which causes smaller systems to fail with obscure division by 0 errors.


Discussion:
We have information about how many tasks per node are available but not how many nodes are available, so it's not clear how to tell if a machine is too small for this test.   

Resolving patch:
diff --git a/scripts/lib/CIME/XML/env_mach_pes.py b/scripts/lib/CIME/XML/env_mach_pes.py
--- a/scripts/lib/CIME/XML/env_mach_pes.py
+++ b/scripts/lib/CIME/XML/env_mach_pes.py
@@ -69,7 +69,7 @@ def get_tasks_per_node(self, total_tasks, max_thread_count):
         expect(total_tasks > 0,"totaltasks > 0 expected totaltasks = {}".format(total_tasks))
         tasks_per_node = min(self.get_value("MAX_TASKS_PER_NODE")/ max_thread_count,
                              self.get_value("PES_PER_NODE"), total_tasks)
-        return tasks_per_node
+        return tasks_per_node if tasks_per_node > 0 else 1
 
     def get_total_nodes(self, total_tasks, max_thread_count):
         """


Test patch:
Repository: ESMCI/cime

Issue:
xmlquery does not work for run_exe
jedwards [2:20 PM] 
env_mach_specific.xml isn't listed as an entry-id file in the case and so xmlquery won't search it

[2:20] 
it

jgfouca [2:21 PM] 
ah, ok

[2:21] 
reason being?

jedwards [2:34 PM] 
it's not a conformal entry_id format file

jgfouca [2:35 PM] 
maybe run_exe should be in a conforming file?

jedwards [2:36 PM] 
This has been a problem for a long time and I thought that it would eventually get worked out organically but it hasn't happened.   Same problem with env_batch.xml

[2:40] 
Hmm looking at the code, maybe that's not the case.  We need to trace that error



Discussion:

Resolving patch:
diff --git a/scripts/lib/CIME/case.py b/scripts/lib/CIME/case.py
--- a/scripts/lib/CIME/case.py
+++ b/scripts/lib/CIME/case.py
@@ -381,6 +381,13 @@ def set_value(self, item, value, subgroup=None, ignore_type=False, allow_undefin
                 self._env_files_that_need_rewrite.add(env_file)
                 return result
 
+        for env_file in self._env_generic_files:
+            result = env_file.set_value(item, value, subgroup, ignore_type)
+            if (result is not None):
+                logger.debug("Will rewrite file {} {}".format(env_file.filename, item))
+                self._env_files_that_need_rewrite.add(env_file)
+                return result
+
         expect(allow_undefined or result is not None,
                "No variable {} found in case".format(item))
 


Test patch:
Repository: ESMCI/cime

Issue:
find_circular_dependencies.py broken
find_circular_dependencies.py was broken by commit 801a8f19b255f65639bda91d2544f63e61cbfddd


Discussion:
@erichlf, can you please fix this?
Yeah, sorry it is taking me this long to get to it. I will get on it.
@gold2718 @jgfouca Since it wasn't caught in my initial testing, how should I test if the code is correct?
It's a python script, run it :)
```
<cimeroot>/tools/utils/find_circular_dependency.py <bldroot>/atm/obj/Depends 
```


Resolving patch:
diff --git a/tools/utils/find_circular_dependency.py b/tools/utils/find_circular_dependency.py
--- a/tools/utils/find_circular_dependency.py
+++ b/tools/utils/find_circular_dependency.py
@@ -11,12 +11,12 @@
 
 def Usage ():
   thisFile = os.path.realpath(inspect.getfile(inspect.currentframe()))
-  print(""")
+  print("""
 Usage: {} <Depends file>
 
   Looks for circular dependencies in CESM Depends file
 
-  """.format(os.path.basename(thisFile))
+  """.format(os.path.basename(thisFile)))
 # End Usage
 
 def keylen(key):
@@ -76,7 +76,7 @@ def findCircularDep(filename):
 def main(filename):
   DepFile = os.path.abspath(filename)
   if (not os.path.exists(DepFile)):
-    print("ERROR: File '{}', does not exist".format(filename))
+    print("ERROR: File '{0}', does not exist".format(filename))
     return 1
   # End if
   cleanTree = findCircularDep(DepFile)


Test patch:
Repository: ESMCI/cime

Issue:
drivers and share circular dependency with shr_dmodel
In working on the build system, I've noticed that the drivers/mct/util/seq_*.F90 files depend on several share/utils/shr_*.F90 shared functions, as is the purpose of share/util. However, there is also one dependency that goes the backward direction, where share/util/shr_dmodel_mod.F90 has a dependency back into drivers/mct/shr/seq_flds_mod.F90:
`use seq_flds_mod, only : seq_flds_dom_coord, seq_flds_dom_other`
where the seq_ variables are used just once in this line:
```
  call mct_gGrid_init( GGrid=gGrid, CoordChars=trim(seq_flds_dom_coord), &
     OtherChars=trim(seq_flds_dom_other), lsize=lsize )
```

This is a minor annoyance to the build process, in that the share/util directory has to be broken up into multiple libraries to get the dependencies with drivers/mct/shr correct. I realized that this means that the share directory will not compile when another driver (nuopc) becomes an option, since a new driver presumably won't come with seq_flds_mod.F90. So thought it was worth calling attention to it.

Does anyone understand this code enough to untangle the circular dependency between these two directories, and have motivation to do so? (It isn't as simple as moving shr_dmodel into drivers/mct, since it is in turn used in other share/util files.) Thanks.


Discussion:
Please see #852 regarding the share library.
It seems like the correct location for shr_dmodel_mod.F90 would be a new directory: src/components/data_comps/dshare 

Resolving patch:
diff --git a/scripts/lib/CIME/buildlib.py b/scripts/lib/CIME/buildlib.py
--- a/scripts/lib/CIME/buildlib.py
+++ b/scripts/lib/CIME/buildlib.py
@@ -41,6 +41,7 @@ def build_cime_component_lib(case, compname, libroot, bldroot):
         out.write(os.path.join(case.get_value('CASEROOT'), "SourceMods",
                                "src.{}\n".format(compname)) + "\n")
         if compname.startswith('d'):
+            out.write(os.path.join(cimeroot, "src", "components", "data_comps", compname, "mct") + "\n")
             out.write(os.path.join(cimeroot, "src", "components", "data_comps", compname) + "\n")
         elif compname.startswith('x'):
             out.write(os.path.join(cimeroot, "src", "components", "xcpl_comps", "xshare") + "\n")


Test patch:
Repository: ESMCI/cime

Issue:
NODENAME_REGEX is required - should it be?
Currently some tools such as check_input_data use the Machines object but do not have 
--machine as a command line argument This effectively means that the NODENAME_REGEX is a required field in config_machines.xml. 

An alternative would be to add the --machine argument to the default arguments in standard_script_setup.py so that it is available for all command line scripts.




Discussion:

Resolving patch:
diff --git a/scripts/lib/CIME/XML/env_batch.py b/scripts/lib/CIME/XML/env_batch.py
--- a/scripts/lib/CIME/XML/env_batch.py
+++ b/scripts/lib/CIME/XML/env_batch.py
@@ -572,8 +572,8 @@ def get_status(self, jobid):
 
             cmd += jobid
 
-            stat, out, err = run_cmd(cmd)
-            if stat != 0:
+            status, out, err = run_cmd(cmd)
+            if status != 0:
                 logger.warning("Batch query command '{}' failed with error '{}'".format(cmd, err))
             else:
                 return out.strip()


Test patch:
diff --git a/src/drivers/mct/unit_test/check_fields_test/test_check_fields.pf b/src/drivers/mct/unit_test/check_fields_test/test_check_fields.pf
--- a/src/drivers/mct/unit_test/check_fields_test/test_check_fields.pf
+++ b/src/drivers/mct/unit_test/check_fields_test/test_check_fields.pf
@@ -59,7 +59,7 @@ contains
     call create_gsmap(this%comp%gsmap_cc, lsize)
 
     call check_fields(this%comp, 1)
-    @assertExceptionRaised('ABORTED:  component_mod:check_fields NaN found in pfunittest instance:            1  field foo 1d global index:            3')
+    @assertExceptionRaised('ABORTED: component_mod:check_fields NaN found in pfunittest instance:    1 field foo 1d global index:        3')
 
   end subroutine createAVectWithoutData_1Field_checkField
 
@@ -93,7 +93,7 @@ contains
 
     call check_fields(this%comp, 1)
 
-    @assertExceptionRaised('ABORTED:  component_mod:check_fields NaN found in pfunittest instance:            1  field foo2 1d global index:            3')
+    @assertExceptionRaised('ABORTED: component_mod:check_fields NaN found in pfunittest instance:    1 field foo2 1d global index:        3')
   end subroutine createAVectWithoutData_3Field_checkFields
 
 end module test_check_fields
Repository: ESMCI/cime

Issue:
Hybrid ERP test fails 
As of PR #1795 hybrid tests stage data in case.setup but the ERP test wasn't
changing the value of CONTINUE_RUN for the restart case until after calling case.setup and
so the rpointer files for the restart were getting overwritten by rpointer files for the hybrid start.



Discussion:

Resolving patch:
diff --git a/scripts/lib/CIME/SystemTests/erp.py b/scripts/lib/CIME/SystemTests/erp.py
--- a/scripts/lib/CIME/SystemTests/erp.py
+++ b/scripts/lib/CIME/SystemTests/erp.py
@@ -111,7 +111,6 @@ def run_phase(self):
                 os.remove(exefile)
             shutil.copy(exefile2, exefile)
 
-            case_setup(self._case, test_mode=True, reset=True)
             stop_n      = self._case.get_value("STOP_N")
             stop_option = self._case.get_value("STOP_OPTION")
 
@@ -132,6 +131,9 @@ def run_phase(self):
                 self._case.set_value("CONTINUE_RUN", True)
                 self._case.set_value("REST_OPTION","never")
                 suffix = "rest"
+
+            case_setup(self._case, test_mode=True, reset=True)
+
             self.run_indv(suffix=suffix)
 
         self._component_compare_test("base", "rest")
diff --git a/scripts/lib/CIME/check_input_data.py b/scripts/lib/CIME/check_input_data.py
--- a/scripts/lib/CIME/check_input_data.py
+++ b/scripts/lib/CIME/check_input_data.py
@@ -118,7 +118,7 @@ def stage_refcase(case):
 
         # copy the refcases' rpointer files to the run directory
         for rpointerfile in glob.iglob(os.path.join("{}","*rpointer*").format(refdir)):
-            logger.debug("Copy rpointer {}".format(rpointerfile))
+            logger.info("Copy rpointer {}".format(rpointerfile))
             shutil.copy(rpointerfile, rundir)
 
         # link everything else
@@ -126,7 +126,7 @@ def stage_refcase(case):
         for rcfile in glob.iglob(os.path.join(refdir,"*")):
             rcbaseline = os.path.basename(rcfile)
             if not os.path.exists("{}/{}".format(rundir, rcbaseline)):
-                logger.debug("Staging file {}".format(rcfile))
+                logger.info("Staging file {}".format(rcfile))
                 os.symlink(rcfile, "{}/{}".format(rundir, rcbaseline))
 
         for cam2file in  glob.iglob(os.path.join("{}","*.cam2.*").format(rundir)):


Test patch:
Repository: ESMCI/cime

Issue:
create_newcase warning needs to more prominent
The following important warning message:

This compset and grid combination is not scientifically supported, however it is used in 8 tests

needs to stand out from the rest of information printed out by create_newcase.  A suggestion would be that it be surrounded by *****************************





Discussion:

Resolving patch:
diff --git a/scripts/lib/CIME/case.py b/scripts/lib/CIME/case.py
--- a/scripts/lib/CIME/case.py
+++ b/scripts/lib/CIME/case.py
@@ -1355,7 +1355,9 @@ def _check_testlists(self, compset_alias, grid_name, files):
                 if test["category"] == "prealpha" or test["category"] == "prebeta" or "aux_" in test["category"]:
                     testcnt += 1
         if testcnt > 0:
-            logger.info("\nThis compset and grid combination is not scientifically supported, however it is used in {:d} tests.\n".format(testcnt))
+            logger.warn("\n*********************************************************************************************************************************")
+            logger.warn("This compset and grid combination is not scientifically supported, however it is used in {:d} tests.".format(testcnt))
+            logger.warn("*********************************************************************************************************************************\n")
         else:
             expect(False, "\nThis compset and grid combination is untested in CESM.  "
                    "Override this warning with the --run-unsupported option to create_newcase.",


Test patch:
Repository: ESMCI/cime

Issue:
create_newcase incorrect output 
I noticed that in this case:
 ./create_newcase --machine nomachine --case Fmult --compset F2000_DEV --res f09_f09_mg17

The message is printed:
Leaving broken case dir /Users/jedwards/cesm/cesm2_0_alpha/cime/scripts/Fmult
ERROR: No machine nomachine found

But no directory /Users/jedwards/cesm/cesm2_0_alpha/cime/scripts/Fmult was ever created.


Discussion:

Resolving patch:
diff --git a/scripts/lib/CIME/case.py b/scripts/lib/CIME/case.py
--- a/scripts/lib/CIME/case.py
+++ b/scripts/lib/CIME/case.py
@@ -1472,10 +1472,11 @@ def create(self, casename, srcroot, compset_name, grid_name, user_mods_dir=None,
             # Lock env_case.xml
             lock_file("env_case.xml", self._caseroot)
         except:
-            if os.path.exists(self._caseroot) and not logger.isEnabledFor(logging.DEBUG) and not test:
-                logger.warn("Failed to setup case, removing {}\nUse --debug to force me to keep caseroot".format(self._caseroot))
-                shutil.rmtree(self._caseroot)
-            else:
-                logger.warn("Leaving broken case dir {}".format(self._caseroot))
+            if os.path.exists(self._caseroot):
+                if not logger.isEnabledFor(logging.DEBUG) and not test:
+                    logger.warn("Failed to setup case, removing {}\nUse --debug to force me to keep caseroot".format(self._caseroot))
+                    shutil.rmtree(self._caseroot)
+                else:
+                    logger.warn("Leaving broken case dir {}".format(self._caseroot))
 
             raise


Test patch: