Repository: ESMCI/cime

Issue:
Python2 Strings to Python3 Strings PR causing CESM tests to fail
PR #1608 has been causing several CESM tests to fail.
    FAIL ERP_Ln9.f09_f09_mg17.F2000_DEV.yellowstone_intel.cam-outfrq9s_clm5 RUN time=179
    FAIL ERP_Ln9.f09_f09_mg17.FC55CLUBB.yellowstone_intel.cam-outfrq9s RUN time=128
    FAIL ERP_Ln9.f09_f09_mg17.FHIST_DEV.yellowstone_intel.cam-outfrq9s_clm5 RUN time=191
    FAIL SMS_D_Ln9.f19_f19_mg17.FX2000climo.yellowstone_intel.cam-outfrq9s RUN time=318
    FAIL ERP_Ln9.f09_f09_mg17.F2000_DEV.cheyenne_intel.cam-outfrq9s_clm5 RUN time=152
    FAIL ERP_Ln9.f09_f09_mg17.FHIST_DEV.cheyenne_intel.cam-outfrq9s_clm5 RUN time=188
    FAIL SMS_D_Ln9.f19_f19_mg17.FX2000climo.cheyenne_intel.cam-outfrq9s RUN time=184
    FAIL SMS_Ld5.T31_g37_gl20.B1850C5L45BGCRG.cheyenne_intel.allactive-defaultio RUN time=136

Can we revert this PR, we cannot be changing this at this moment.  And the Python2 strings were working fine.

@mvertens 



Discussion:
We need to investigate this a bit more to clarify what the problem is - but
the short summary is that the CICE decomposition seems to be set
incorrectly with CIME master - but was working fine prior to this PR. More
details will follow.

On Sat, Jun 3, 2017 at 9:49 AM, fischer-ncar <notifications@github.com>
wrote:

> PR #1608 <https://github.com/ESMCI/cime/pull/1608> has been causing
> several CESM tests to fail.
> FAIL ERP_Ln9.f09_f09_mg17.F2000_DEV.yellowstone_intel.cam-outfrq9s_clm5
> RUN time=179
> FAIL ERP_Ln9.f09_f09_mg17.FC55CLUBB.yellowstone_intel.cam-outfrq9s RUN
> time=128
> FAIL ERP_Ln9.f09_f09_mg17.FHIST_DEV.yellowstone_intel.cam-outfrq9s_clm5
> RUN time=191
> FAIL SMS_D_Ln9.f19_f19_mg17.FX2000climo.yellowstone_intel.cam-outfrq9s
> RUN time=318
> FAIL ERP_Ln9.f09_f09_mg17.F2000_DEV.cheyenne_intel.cam-outfrq9s_clm5 RUN
> time=152
> FAIL ERP_Ln9.f09_f09_mg17.FHIST_DEV.cheyenne_intel.cam-outfrq9s_clm5 RUN
> time=188
> FAIL SMS_D_Ln9.f19_f19_mg17.FX2000climo.cheyenne_intel.cam-outfrq9s RUN
> time=184
> FAIL SMS_Ld5.T31_g37_gl20.B1850C5L45BGCRG.cheyenne_intel.allactive-defaultio
> RUN time=136
>
> Can we revert this PR, we cannot be changing this at this moment. And the
> Python2 strings were working fine.
>
> @mvertens <https://github.com/mvertens>
>
> —
> You are receiving this because you were mentioned.
> Reply to this email directly, view it on GitHub
> <https://github.com/ESMCI/cime/issues/1638>, or mute the thread
> <https://github.com/notifications/unsubscribe-auth/AHlxEwK_nfOJjkR3mrI7Ja4PXJE2QD5Kks5sAYCdgaJpZM4NvHun>
> .
>

Closing this issue until we do more investigation. 
I have found the problem and have a fix. 

In the erp.py test the following is incorrect:

           restore("env_mach_pes.ERP{:d}.xml".format(run, newname="env_mach_pes.xml"))
           restore("env_build.ERP{:d}.xml".format(run, newname="env_build.xml"))

and needs to be changed to: 

           restore("env_mach_pes.ERP{:d}.xml".format(run), newname="env_mach_pes.xml")
           restore("env_build.ERP{:d}.xml".format(run), newname="env_build.xml")

I have verified that with this fix to CIME master, ERP_Ln9.f09_f09_mg17.FC55CLUBB.yellowstone_intel.cam-outfrq9s passes.

This new call to restore came in with #1608. All ERP tests since then are not being done correctly and are really not testing a change in tasks and threads. 

I'm surprised that this was not picked up by pylint - or showed up as a failure. In our case, cice was triggering this failure when the domain changed recently.


It looks like there are a few other problems with a similar pattern: From `git grep -n 'format([^)]*='` and just listing the ones that look problematic to me:

```
scripts/Tools/normalize_cases:79:            files_needing_rename = run_cmd_no_fail('find -depth -name "*.{}"'.format(case1_lid, from_dir=case1).splitlines())
scripts/lib/CIME/SystemTests/homme.py:39:            run_cmd_no_fail("{} -j8".format(gmake, arg_stdout="homme.bldlog", combine_output=True), from_dir=exeroot)
scripts/lib/CIME/SystemTests/homme.py:59:            stat = run_cmd("{} -j 4 baseline".format(gmake, arg_stdout=log, combine_output=True), from_dir=exeroot)[0]
```

I also thought that pylint should pick these up. But what I have found is that pylint flags this as a problem if you're using named conversion specifiers, as in:

```python
mystr = "hello {num}".format(num=1, newname='foo')
```

```
W:  5, 8: Unused format argument 'newname' (unused-format-string-argument)
```

but apparently not if you're using positional conversion specifiers: pylint raises no warnings about this:

```
mystr = "hello {}".format(1, newname='foo')
```
@billsacks - thanks! We really need these fixes in as soon as possible for CESM - so I'm going to try to put i a PR today with the relevant fixes.

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
@@ -96,8 +96,8 @@ def run_phase(self):
                    "ERROR: LockedFiles/env_mach_pes.ERP{:d}.xml does not exist, run case.build".format(run ))
 
             # Use the second env_mach_pes.xml and env_build.xml files
-            restore("env_mach_pes.ERP{:d}.xml".format(run, newname="env_mach_pes.xml"))
-            restore("env_build.ERP{:d}.xml".format(run, newname="env_build.xml"))
+            restore("env_mach_pes.ERP{:d}.xml".format(run), newname="env_mach_pes.xml")
+            restore("env_build.ERP{:d}.xml".format(run), newname="env_build.xml")
 
             # update the case to use the new values
             self._case.read_xml()
diff --git a/scripts/lib/CIME/SystemTests/homme.py b/scripts/lib/CIME/SystemTests/homme.py
--- a/scripts/lib/CIME/SystemTests/homme.py
+++ b/scripts/lib/CIME/SystemTests/homme.py
@@ -36,7 +36,7 @@ def build_phase(self, sharedlib_only=False, model_only=False):
             cmake_cmd = "cmake -C {}/components/homme/cmake/machineFiles/{}.cmake -DUSE_NUM_PROCS={} {}/components/homme -DHOMME_BASELINE_DIR={}/{}".format(srcroot, mach, procs, srcroot, baseline, basename)
 
             run_cmd_no_fail(cmake_cmd, arg_stdout="homme.bldlog", combine_output=True, from_dir=exeroot)
-            run_cmd_no_fail("{} -j8".format(gmake, arg_stdout="homme.bldlog", combine_output=True), from_dir=exeroot)
+            run_cmd_no_fail("{} -j8".format(gmake), arg_stdout="homme.bldlog", combine_output=True, from_dir=exeroot)
 
             post_build(self._case, [os.path.join(exeroot, "homme.bldlog")])
 
@@ -56,7 +56,7 @@ def run_phase(self):
 
         if generate:
             full_baseline_dir = os.path.join(baseline, basegen, "tests", "baseline")
-            stat = run_cmd("{} -j 4 baseline".format(gmake, arg_stdout=log, combine_output=True), from_dir=exeroot)[0]
+            stat = run_cmd("{} -j 4 baseline".format(gmake), arg_stdout=log, combine_output=True, from_dir=exeroot)[0]
             if stat == 0:
                 if os.path.isdir(full_baseline_dir):
                     shutil.rmtree(full_baseline_dir)
diff --git a/scripts/lib/CIME/SystemTests/ncr.py b/scripts/lib/CIME/SystemTests/ncr.py
--- a/scripts/lib/CIME/SystemTests/ncr.py
+++ b/scripts/lib/CIME/SystemTests/ncr.py
@@ -102,7 +102,7 @@ def run_phase(self):
         os.remove("{}/{}.exe".format(exeroot, cime_model))
         shutil.copy("{}/{}.exe.NCR2".format(exeroot, cime_model),
                     "{}/{}.exe".format(exeroot, cime_model))
-        restore("env_build.NCR2.xml", "env_build.xml")
+        restore("env_build.NCR2.xml", newname="env_build.xml")
 
         logger.info("default: doing a {} {} with NINST2".format(stop_n, stop_option))
         self.run_indv(suffix="multiinst")


Test patch: