We are currently solving the following issue within our repository. Here is the issue text:
--- BEGIN ISSUE ---
PR #2759 has caused DAE.f19_f19.A to fail during phase RUN
The errors can be reproduced on anlworkstation by running the following cime_developer test:
`./create_test DAE.f19_f19.A --machine=anlworkstation --test-root=****`

Errors were:
```
Exception during run:
ERROR: ERROR: Expected 1 Initial run message(s), 0 found in DAE.f19_f19.A.anlworkstation_gnu.xxxx/run/case2run/da.log.xxxx.gz
Traceback (most recent call last):
  File "scripts/lib/CIME/SystemTests/system_tests_common.py", line 145, in run
    self.run_phase()
  File "scripts/lib/CIME/SystemTests/dae.py", line 155, in run_phase
    "ERROR: Expected {} Initial run message(s), {} found in {}".format(expected_init, found_init, fname))
  File "scripts/lib/CIME/utils.py", line 130, in expect
    raise exc_type(msg)
SystemExit: ERROR: ERROR: Expected 1 Initial run message(s), 0 found in DAE.f19_f19.A.anlworkstation_gnu.xxxx/run/case2run/da.log.xxxx.gz
```
Do we need some settings on anlworkstation to make it work?

--- END ISSUE ---

Below are some code segments, each from a relevant file. One or more of these files may contain bugs.
--- BEGIN FILES ---
Path: `scripts/lib/CIME/SystemTests/dae.py`
Content:
```
1 """
2 Implementation of the CIME data assimilation test:
3 Compares standard run with run broken into two data assimilation cycles.
4 Runs a simple DA script on each cycle which performs checks but does not
5 change any model state (restart files). Compares answers of two runs.
6 
7 """
8 
9 import os.path
10 import logging
11 import glob
12 import gzip
13 
14 import CIME.XML.standard_module_setup as sms
15 from CIME.SystemTests.system_tests_compare_two import SystemTestsCompareTwo
16 from CIME.utils import expect
17 
18 ###############################################################################
19 class DAE(SystemTestsCompareTwo):
20 ###############################################################################
21     """
22     Implementation of the CIME data assimilation test:
23     Compares standard run with a run broken into two data assimilation cycles.
24     Runs a simple DA script on each cycle which performs checks but does not
25     change any model state (restart files). Compares answers of two runs.
26     Refers to a faux data assimilation script in the
27     cime/scripts/data_assimilation directory
28     """
29 
30     ###########################################################################
31     def __init__(self, case):
32     ###########################################################################
33         SystemTestsCompareTwo.__init__(self, case,
34                                        separate_builds=False,
35                                        run_two_suffix='da',
36                                        run_one_description='no data assimilation',
37                                        run_two_description='data assimilation')
38 
39     ###########################################################################
40     def _case_one_setup(self):
41     ###########################################################################
42         # Even though there may be test mods turning on data assimilation,
43         #   case1 is the control so turn it off
44         self._case.set_value("DATA_ASSIMILATION_SCRIPT", "")
45         self._case.set_value("DATA_ASSIMILATION_CYCLES", 1)
46 
47     ###########################################################################
48     def _case_two_setup(self):
49     ###########################################################################
50         # Allow testmods to set an assimilation script
51         if len(self._case.get_value("DATA_ASSIMILATION_SCRIPT")) == 0:
52             # We need to find the scripts/data_assimilation directory
53             # LIB_DIR should be our parent dir
54             da_dir = os.path.join(os.path.dirname(sms.LIB_DIR), "data_assimilation")
55             expect(os.path.isdir(da_dir), "ERROR: da_dir, '{}', does not exist".format(da_dir))
56             da_file = os.path.join(da_dir, "da_no_data_mod.sh")
57             expect(os.path.isfile(da_file), "ERROR: da_file, '{}', does not exist".format(da_file))
58             # Set up two data assimilation cycles each half of the full run
59             self._case.set_value("DATA_ASSIMILATION_SCRIPT", da_file)
60 
61         # We need at least 2 DA cycles
62         da_cycles = self._case.get_value("DATA_ASSIMILATION_CYCLES")
63         if da_cycles < 2:
64             da_cycles = 2
65             self._case.set_value("DATA_ASSIMILATION_CYCLES", da_cycles)
66         stopn = self._case.get_value("STOP_N")
67         expect((stopn % da_cycles) == 0, "ERROR: DAE test with {0} cycles requires that STOP_N be divisible by {0}".format(da_cycles))
68         stopn = int(stopn / da_cycles)
69         self._case.set_value("STOP_N", stopn)
70 
71         self._case.flush()
72 
73     ###########################################################################
74     def run_phase(self): # pylint: disable=arguments-differ
75     ###########################################################################
76         # Clean up any da.log files in case this is a re-run.
77         self._activate_case2()
78         case_root = self._get_caseroot2()
79         rundir2 = self._case.get_value("RUNDIR")
80         da_files = glob.glob(os.path.join(rundir2, 'da.log.*'))
81         for file_ in da_files:
82             os.remove(file_)
83         # End for
84 
85         # CONTINUE_RUN ends up TRUE, set it back in case this is a re-run.
86         self._case.set_value("CONTINUE_RUN", False)
87         # Start normal run here
88         self._activate_case1()
89         SystemTestsCompareTwo.run_phase(self)
90 
91         # Do some checks on the data assimilation 'output' from case2
92         self._activate_case2()
93         da_files = glob.glob(os.path.join(rundir2, 'da.log.*'))
94         if da_files is None:
95             logger = logging.getLogger(__name__)
96             path = os.path.join(case_root, 'da.log.*')
97             logger.warning("No DA files in {}".format(path))
98 
99         da_cycles = self._case.get_value("DATA_ASSIMILATION_CYCLES")
100         expect((da_files is not None) and (len(da_files) == da_cycles),
101                "ERROR: There were {:d} DA cycles in run but {:d} DA files were found".format(da_cycles, len(da_files) if da_files is not None else 0))
102         da_files.sort()
103         cycle_num = 0
104         compset = self._case.get_value("COMPSET")
105         # Special case for DWAV so we can make sure other variables are set
106         is_dwav = '_DWAV' in compset
107         for fname in da_files:
108             found_caseroot = False
109             found_cycle = False
110             found_signal = 0
111             found_init = 0
112             if is_dwav:
113                 expected_init = self._case.get_value("NINST_WAV")
114             else:
115                 # Expect a signal from every instance of every DA component
116                 expected_init = 0
117                 for comp in self._case.get_values("COMP_CLASSES"):
118                     if self._case.get_value("DATA_ASSIMILATION_{}".format(comp)):
119                         expected_init = expected_init + self._case.get_value("NINST_{}".format(comp))
120 
121             # Adjust expected initial run and post-DA numbers
122             if cycle_num == 0:
123                 expected_signal = 0
124             else:
125                 expected_signal = expected_init
126                 expected_init = 0
127 
128             with gzip.open(fname, "r") as dfile:
129                 for bline in dfile:
130                     line = bline.decode("utf-8")
131                     expect(not 'ERROR' in line, "ERROR, error line {} found in {}".format(line, fname))
132                     if 'caseroot' in line[0:8]:
133                         found_caseroot = True
134                     elif 'cycle' in line[0:5]:
135                         found_cycle = True
136                         expect(int(line[7:]) == cycle_num,
137                                "ERROR: Wrong cycle ({:d}) found in {} (expected {:d})".format(int(line[7:]), fname, cycle_num))
138                     elif 'resume signal' in line:
139                         found_signal = found_signal + 1
140                         expect('Post-DA resume signal found' in line[0:27],
141                                "ERROR: bad post-DA message found in {}".format(fname))
142                     elif 'Initial run' in line:
143                         found_init = found_init + 1
144                         expect('Initial run signal found' in line[0:24],
145                                "ERROR: bad Initial run message found in {}".format(fname))
146                     else:
147                         expect(False, "ERROR: Unrecognized line ('{}') found in {}".format(line, fname))
148 
149                 # End of for loop
150                 expect(found_caseroot, "ERROR: No caseroot found in {}".format(fname))
151                 expect(found_cycle, "ERROR: No cycle found in {}".format(fname))
152                 expect(found_signal == expected_signal,
153                        "ERROR: Expected {} post-DA resume signal message(s), {} found in {}".format(expected_signal, found_signal, fname))
154                 expect(found_init == expected_init,
155                        "ERROR: Expected {} Initial run message(s), {} found in {}".format(expected_init, found_init, fname))
156             # End of with
157             cycle_num = cycle_num + 1
158
```
--- END FILES ---

Please first localize the bug based on the issue statement, and then generate a patch according to the `git diff` format fenced by three backticks.

Here is an example:

```diff
diff --git a/examples/server_async.py b/examples/server_async.py
--- a/examples/server_async.py
+++ b/examples/server_async.py
@@ -313,4 +313,4 @@
 
 
 if __name__ == "__main__":
-    asyncio.run(run_async_server("."), debug=True)
+    asyncio.run(run_async_server(), debug=True)
diff --git a/examples/server_sync.py b/examples/server_sync.py
--- a/examples/server_sync.py
+++ b/examples/server_sync.py
@@ -313,5 +313,5 @@
 
 
 if __name__ == "__main__":
-    server = run_sync_server(".")
+    server = run_sync_server()
     server.shutdown()

```

diff --git a/scripts/lib/CIME/SystemTests/dae.py b/scripts/lib/CIME/SystemTests/dae.py
--- a/scripts/lib/CIME/SystemTests/dae.py
+++ b/scripts/lib/CIME/SystemTests/dae.py
@@ -84,6 +84,12 @@
 
         # CONTINUE_RUN ends up TRUE, set it back in case this is a re-run.
         self._case.set_value("CONTINUE_RUN", False)
+        # Turn off post DA in case this is a re-run
+        for comp in self._case.get_values("COMP_CLASSES"):
+            if comp == "ESP":
+                continue
+            else:
+                self._case.set_value("DATA_ASSIMILATION_{}".format(comp), False)
         # Start normal run here
         self._activate_case1()
         SystemTestsCompareTwo.run_phase(self)
@@ -115,7 +121,9 @@
                 # Expect a signal from every instance of every DA component
                 expected_init = 0
                 for comp in self._case.get_values("COMP_CLASSES"):
-                    if self._case.get_value("DATA_ASSIMILATION_{}".format(comp)):
+                    if comp == "ESP":
+                        continue
+                    elif self._case.get_value("DATA_ASSIMILATION_{}".format(comp)):
                         expected_init = expected_init + self._case.get_value("NINST_{}".format(comp))
 
             # Adjust expected initial run and post-DA numbers
@@ -146,12 +154,13 @@
                     else:
                         expect(False, "ERROR: Unrecognized line ('{}') found in {}".format(line, fname))
 
-                # End of for loop
+                # End for
                 expect(found_caseroot, "ERROR: No caseroot found in {}".format(fname))
                 expect(found_cycle, "ERROR: No cycle found in {}".format(fname))
                 expect(found_signal == expected_signal,
                        "ERROR: Expected {} post-DA resume signal message(s), {} found in {}".format(expected_signal, found_signal, fname))
                 expect(found_init == expected_init,
                        "ERROR: Expected {} Initial run message(s), {} found in {}".format(expected_init, found_init, fname))
-            # End of with
+            # End with
             cycle_num = cycle_num + 1
+        # End for

{"golden_diff": "diff --git a/scripts/lib/CIME/SystemTests/dae.py b/scripts/lib/CIME/SystemTests/dae.py\n--- a/scripts/lib/CIME/SystemTests/dae.py\n+++ b/scripts/lib/CIME/SystemTests/dae.py\n@@ -84,6 +84,12 @@\n \n         # CONTINUE_RUN ends up TRUE, set it back in case this is a re-run.\n         self._case.set_value(\"CONTINUE_RUN\", False)\n+        # Turn off post DA in case this is a re-run\n+        for comp in self._case.get_values(\"COMP_CLASSES\"):\n+            if comp == \"ESP\":\n+                continue\n+            else:\n+                self._case.set_value(\"DATA_ASSIMILATION_{}\".format(comp), False)\n         # Start normal run here\n         self._activate_case1()\n         SystemTestsCompareTwo.run_phase(self)\n@@ -115,7 +121,9 @@\n                 # Expect a signal from every instance of every DA component\n                 expected_init = 0\n                 for comp in self._case.get_values(\"COMP_CLASSES\"):\n-                    if self._case.get_value(\"DATA_ASSIMILATION_{}\".format(comp)):\n+                    if comp == \"ESP\":\n+                        continue\n+                    elif self._case.get_value(\"DATA_ASSIMILATION_{}\".format(comp)):\n                         expected_init = expected_init + self._case.get_value(\"NINST_{}\".format(comp))\n \n             # Adjust expected initial run and post-DA numbers\n@@ -146,12 +154,13 @@\n                     else:\n                         expect(False, \"ERROR: Unrecognized line ('{}') found in {}\".format(line, fname))\n \n-                # End of for loop\n+                # End for\n                 expect(found_caseroot, \"ERROR: No caseroot found in {}\".format(fname))\n                 expect(found_cycle, \"ERROR: No cycle found in {}\".format(fname))\n                 expect(found_signal == expected_signal,\n                        \"ERROR: Expected {} post-DA resume signal message(s), {} found in {}\".format(expected_signal, found_signal, fname))\n                 expect(found_init == expected_init,\n                        \"ERROR: Expected {} Initial run message(s), {} found in {}\".format(expected_init, found_init, fname))\n-            # End of with\n+            # End with\n             cycle_num = cycle_num + 1\n+        # End for\n", "issue": "PR #2759 has caused DAE.f19_f19.A to fail during phase RUN\nThe errors can be reproduced on anlworkstation by running the following cime_developer test:\r\n`./create_test DAE.f19_f19.A --machine=anlworkstation --test-root=****`\r\n\r\nErrors were:\r\n```\r\nException during run:\r\nERROR: ERROR: Expected 1 Initial run message(s), 0 found in DAE.f19_f19.A.anlworkstation_gnu.xxxx/run/case2run/da.log.xxxx.gz\r\nTraceback (most recent call last):\r\n  File \"scripts/lib/CIME/SystemTests/system_tests_common.py\", line 145, in run\r\n    self.run_phase()\r\n  File \"scripts/lib/CIME/SystemTests/dae.py\", line 155, in run_phase\r\n    \"ERROR: Expected {} Initial run message(s), {} found in {}\".format(expected_init, found_init, fname))\r\n  File \"scripts/lib/CIME/utils.py\", line 130, in expect\r\n    raise exc_type(msg)\r\nSystemExit: ERROR: ERROR: Expected 1 Initial run message(s), 0 found in DAE.f19_f19.A.anlworkstation_gnu.xxxx/run/case2run/da.log.xxxx.gz\r\n```\r\nDo we need some settings on anlworkstation to make it work?\n", "before_files": [{"content": "\"\"\"\nImplementation of the CIME data assimilation test:\nCompares standard run with run broken into two data assimilation cycles.\nRuns a simple DA script on each cycle which performs checks but does not\nchange any model state (restart files). Compares answers of two runs.\n\n\"\"\"\n\nimport os.path\nimport logging\nimport glob\nimport gzip\n\nimport CIME.XML.standard_module_setup as sms\nfrom CIME.SystemTests.system_tests_compare_two import SystemTestsCompareTwo\nfrom CIME.utils import expect\n\n###############################################################################\nclass DAE(SystemTestsCompareTwo):\n###############################################################################\n    \"\"\"\n    Implementation of the CIME data assimilation test:\n    Compares standard run with a run broken into two data assimilation cycles.\n    Runs a simple DA script on each cycle which performs checks but does not\n    change any model state (restart files). Compares answers of two runs.\n    Refers to a faux data assimilation script in the\n    cime/scripts/data_assimilation directory\n    \"\"\"\n\n    ###########################################################################\n    def __init__(self, case):\n    ###########################################################################\n        SystemTestsCompareTwo.__init__(self, case,\n                                       separate_builds=False,\n                                       run_two_suffix='da',\n                                       run_one_description='no data assimilation',\n                                       run_two_description='data assimilation')\n\n    ###########################################################################\n    def _case_one_setup(self):\n    ###########################################################################\n        # Even though there may be test mods turning on data assimilation,\n        #   case1 is the control so turn it off\n        self._case.set_value(\"DATA_ASSIMILATION_SCRIPT\", \"\")\n        self._case.set_value(\"DATA_ASSIMILATION_CYCLES\", 1)\n\n    ###########################################################################\n    def _case_two_setup(self):\n    ###########################################################################\n        # Allow testmods to set an assimilation script\n        if len(self._case.get_value(\"DATA_ASSIMILATION_SCRIPT\")) == 0:\n            # We need to find the scripts/data_assimilation directory\n            # LIB_DIR should be our parent dir\n            da_dir = os.path.join(os.path.dirname(sms.LIB_DIR), \"data_assimilation\")\n            expect(os.path.isdir(da_dir), \"ERROR: da_dir, '{}', does not exist\".format(da_dir))\n            da_file = os.path.join(da_dir, \"da_no_data_mod.sh\")\n            expect(os.path.isfile(da_file), \"ERROR: da_file, '{}', does not exist\".format(da_file))\n            # Set up two data assimilation cycles each half of the full run\n            self._case.set_value(\"DATA_ASSIMILATION_SCRIPT\", da_file)\n\n        # We need at least 2 DA cycles\n        da_cycles = self._case.get_value(\"DATA_ASSIMILATION_CYCLES\")\n        if da_cycles < 2:\n            da_cycles = 2\n            self._case.set_value(\"DATA_ASSIMILATION_CYCLES\", da_cycles)\n        stopn = self._case.get_value(\"STOP_N\")\n        expect((stopn % da_cycles) == 0, \"ERROR: DAE test with {0} cycles requires that STOP_N be divisible by {0}\".format(da_cycles))\n        stopn = int(stopn / da_cycles)\n        self._case.set_value(\"STOP_N\", stopn)\n\n        self._case.flush()\n\n    ###########################################################################\n    def run_phase(self): # pylint: disable=arguments-differ\n    ###########################################################################\n        # Clean up any da.log files in case this is a re-run.\n        self._activate_case2()\n        case_root = self._get_caseroot2()\n        rundir2 = self._case.get_value(\"RUNDIR\")\n        da_files = glob.glob(os.path.join(rundir2, 'da.log.*'))\n        for file_ in da_files:\n            os.remove(file_)\n        # End for\n\n        # CONTINUE_RUN ends up TRUE, set it back in case this is a re-run.\n        self._case.set_value(\"CONTINUE_RUN\", False)\n        # Start normal run here\n        self._activate_case1()\n        SystemTestsCompareTwo.run_phase(self)\n\n        # Do some checks on the data assimilation 'output' from case2\n        self._activate_case2()\n        da_files = glob.glob(os.path.join(rundir2, 'da.log.*'))\n        if da_files is None:\n            logger = logging.getLogger(__name__)\n            path = os.path.join(case_root, 'da.log.*')\n            logger.warning(\"No DA files in {}\".format(path))\n\n        da_cycles = self._case.get_value(\"DATA_ASSIMILATION_CYCLES\")\n        expect((da_files is not None) and (len(da_files) == da_cycles),\n               \"ERROR: There were {:d} DA cycles in run but {:d} DA files were found\".format(da_cycles, len(da_files) if da_files is not None else 0))\n        da_files.sort()\n        cycle_num = 0\n        compset = self._case.get_value(\"COMPSET\")\n        # Special case for DWAV so we can make sure other variables are set\n        is_dwav = '_DWAV' in compset\n        for fname in da_files:\n            found_caseroot = False\n            found_cycle = False\n            found_signal = 0\n            found_init = 0\n            if is_dwav:\n                expected_init = self._case.get_value(\"NINST_WAV\")\n            else:\n                # Expect a signal from every instance of every DA component\n                expected_init = 0\n                for comp in self._case.get_values(\"COMP_CLASSES\"):\n                    if self._case.get_value(\"DATA_ASSIMILATION_{}\".format(comp)):\n                        expected_init = expected_init + self._case.get_value(\"NINST_{}\".format(comp))\n\n            # Adjust expected initial run and post-DA numbers\n            if cycle_num == 0:\n                expected_signal = 0\n            else:\n                expected_signal = expected_init\n                expected_init = 0\n\n            with gzip.open(fname, \"r\") as dfile:\n                for bline in dfile:\n                    line = bline.decode(\"utf-8\")\n                    expect(not 'ERROR' in line, \"ERROR, error line {} found in {}\".format(line, fname))\n                    if 'caseroot' in line[0:8]:\n                        found_caseroot = True\n                    elif 'cycle' in line[0:5]:\n                        found_cycle = True\n                        expect(int(line[7:]) == cycle_num,\n                               \"ERROR: Wrong cycle ({:d}) found in {} (expected {:d})\".format(int(line[7:]), fname, cycle_num))\n                    elif 'resume signal' in line:\n                        found_signal = found_signal + 1\n                        expect('Post-DA resume signal found' in line[0:27],\n                               \"ERROR: bad post-DA message found in {}\".format(fname))\n                    elif 'Initial run' in line:\n                        found_init = found_init + 1\n                        expect('Initial run signal found' in line[0:24],\n                               \"ERROR: bad Initial run message found in {}\".format(fname))\n                    else:\n                        expect(False, \"ERROR: Unrecognized line ('{}') found in {}\".format(line, fname))\n\n                # End of for loop\n                expect(found_caseroot, \"ERROR: No caseroot found in {}\".format(fname))\n                expect(found_cycle, \"ERROR: No cycle found in {}\".format(fname))\n                expect(found_signal == expected_signal,\n                       \"ERROR: Expected {} post-DA resume signal message(s), {} found in {}\".format(expected_signal, found_signal, fname))\n                expect(found_init == expected_init,\n                       \"ERROR: Expected {} Initial run message(s), {} found in {}\".format(expected_init, found_init, fname))\n            # End of with\n            cycle_num = cycle_num + 1\n", "path": "scripts/lib/CIME/SystemTests/dae.py"}], "after_files": [{"content": "\"\"\"\nImplementation of the CIME data assimilation test:\nCompares standard run with run broken into two data assimilation cycles.\nRuns a simple DA script on each cycle which performs checks but does not\nchange any model state (restart files). Compares answers of two runs.\n\n\"\"\"\n\nimport os.path\nimport logging\nimport glob\nimport gzip\n\nimport CIME.XML.standard_module_setup as sms\nfrom CIME.SystemTests.system_tests_compare_two import SystemTestsCompareTwo\nfrom CIME.utils import expect\n\n###############################################################################\nclass DAE(SystemTestsCompareTwo):\n###############################################################################\n    \"\"\"\n    Implementation of the CIME data assimilation test:\n    Compares standard run with a run broken into two data assimilation cycles.\n    Runs a simple DA script on each cycle which performs checks but does not\n    change any model state (restart files). Compares answers of two runs.\n    Refers to a faux data assimilation script in the\n    cime/scripts/data_assimilation directory\n    \"\"\"\n\n    ###########################################################################\n    def __init__(self, case):\n    ###########################################################################\n        SystemTestsCompareTwo.__init__(self, case,\n                                       separate_builds=False,\n                                       run_two_suffix='da',\n                                       run_one_description='no data assimilation',\n                                       run_two_description='data assimilation')\n\n    ###########################################################################\n    def _case_one_setup(self):\n    ###########################################################################\n        # Even though there may be test mods turning on data assimilation,\n        #   case1 is the control so turn it off\n        self._case.set_value(\"DATA_ASSIMILATION_SCRIPT\", \"\")\n        self._case.set_value(\"DATA_ASSIMILATION_CYCLES\", 1)\n\n    ###########################################################################\n    def _case_two_setup(self):\n    ###########################################################################\n        # Allow testmods to set an assimilation script\n        if len(self._case.get_value(\"DATA_ASSIMILATION_SCRIPT\")) == 0:\n            # We need to find the scripts/data_assimilation directory\n            # LIB_DIR should be our parent dir\n            da_dir = os.path.join(os.path.dirname(sms.LIB_DIR), \"data_assimilation\")\n            expect(os.path.isdir(da_dir), \"ERROR: da_dir, '{}', does not exist\".format(da_dir))\n            da_file = os.path.join(da_dir, \"da_no_data_mod.sh\")\n            expect(os.path.isfile(da_file), \"ERROR: da_file, '{}', does not exist\".format(da_file))\n            # Set up two data assimilation cycles each half of the full run\n            self._case.set_value(\"DATA_ASSIMILATION_SCRIPT\", da_file)\n\n        # We need at least 2 DA cycles\n        da_cycles = self._case.get_value(\"DATA_ASSIMILATION_CYCLES\")\n        if da_cycles < 2:\n            da_cycles = 2\n            self._case.set_value(\"DATA_ASSIMILATION_CYCLES\", da_cycles)\n        stopn = self._case.get_value(\"STOP_N\")\n        expect((stopn % da_cycles) == 0, \"ERROR: DAE test with {0} cycles requires that STOP_N be divisible by {0}\".format(da_cycles))\n        stopn = int(stopn / da_cycles)\n        self._case.set_value(\"STOP_N\", stopn)\n\n        self._case.flush()\n\n    ###########################################################################\n    def run_phase(self): # pylint: disable=arguments-differ\n    ###########################################################################\n        # Clean up any da.log files in case this is a re-run.\n        self._activate_case2()\n        case_root = self._get_caseroot2()\n        rundir2 = self._case.get_value(\"RUNDIR\")\n        da_files = glob.glob(os.path.join(rundir2, 'da.log.*'))\n        for file_ in da_files:\n            os.remove(file_)\n        # End for\n\n        # CONTINUE_RUN ends up TRUE, set it back in case this is a re-run.\n        self._case.set_value(\"CONTINUE_RUN\", False)\n        # Turn off post DA in case this is a re-run\n        for comp in self._case.get_values(\"COMP_CLASSES\"):\n            if comp == \"ESP\":\n                continue\n            else:\n                self._case.set_value(\"DATA_ASSIMILATION_{}\".format(comp), False)\n        # Start normal run here\n        self._activate_case1()\n        SystemTestsCompareTwo.run_phase(self)\n\n        # Do some checks on the data assimilation 'output' from case2\n        self._activate_case2()\n        da_files = glob.glob(os.path.join(rundir2, 'da.log.*'))\n        if da_files is None:\n            logger = logging.getLogger(__name__)\n            path = os.path.join(case_root, 'da.log.*')\n            logger.warning(\"No DA files in {}\".format(path))\n\n        da_cycles = self._case.get_value(\"DATA_ASSIMILATION_CYCLES\")\n        expect((da_files is not None) and (len(da_files) == da_cycles),\n               \"ERROR: There were {:d} DA cycles in run but {:d} DA files were found\".format(da_cycles, len(da_files) if da_files is not None else 0))\n        da_files.sort()\n        cycle_num = 0\n        compset = self._case.get_value(\"COMPSET\")\n        # Special case for DWAV so we can make sure other variables are set\n        is_dwav = '_DWAV' in compset\n        for fname in da_files:\n            found_caseroot = False\n            found_cycle = False\n            found_signal = 0\n            found_init = 0\n            if is_dwav:\n                expected_init = self._case.get_value(\"NINST_WAV\")\n            else:\n                # Expect a signal from every instance of every DA component\n                expected_init = 0\n                for comp in self._case.get_values(\"COMP_CLASSES\"):\n                    if comp == \"ESP\":\n                        continue\n                    elif self._case.get_value(\"DATA_ASSIMILATION_{}\".format(comp)):\n                        expected_init = expected_init + self._case.get_value(\"NINST_{}\".format(comp))\n\n            # Adjust expected initial run and post-DA numbers\n            if cycle_num == 0:\n                expected_signal = 0\n            else:\n                expected_signal = expected_init\n                expected_init = 0\n\n            with gzip.open(fname, \"r\") as dfile:\n                for bline in dfile:\n                    line = bline.decode(\"utf-8\")\n                    expect(not 'ERROR' in line, \"ERROR, error line {} found in {}\".format(line, fname))\n                    if 'caseroot' in line[0:8]:\n                        found_caseroot = True\n                    elif 'cycle' in line[0:5]:\n                        found_cycle = True\n                        expect(int(line[7:]) == cycle_num,\n                               \"ERROR: Wrong cycle ({:d}) found in {} (expected {:d})\".format(int(line[7:]), fname, cycle_num))\n                    elif 'resume signal' in line:\n                        found_signal = found_signal + 1\n                        expect('Post-DA resume signal found' in line[0:27],\n                               \"ERROR: bad post-DA message found in {}\".format(fname))\n                    elif 'Initial run' in line:\n                        found_init = found_init + 1\n                        expect('Initial run signal found' in line[0:24],\n                               \"ERROR: bad Initial run message found in {}\".format(fname))\n                    else:\n                        expect(False, \"ERROR: Unrecognized line ('{}') found in {}\".format(line, fname))\n\n                # End for\n                expect(found_caseroot, \"ERROR: No caseroot found in {}\".format(fname))\n                expect(found_cycle, \"ERROR: No cycle found in {}\".format(fname))\n                expect(found_signal == expected_signal,\n                       \"ERROR: Expected {} post-DA resume signal message(s), {} found in {}\".format(expected_signal, found_signal, fname))\n                expect(found_init == expected_init,\n                       \"ERROR: Expected {} Initial run message(s), {} found in {}\".format(expected_init, found_init, fname))\n            # End with\n            cycle_num = cycle_num + 1\n        # End for\n", "path": "scripts/lib/CIME/SystemTests/dae.py"}]}