Skip to content

Commit b085dc8

Browse files
authored
Merge pull request #7048 from MetRonnie/icp-nonsense
Fix icp = now changing on reload
1 parent d8fcfdd commit b085dc8

File tree

15 files changed

+125
-73
lines changed

15 files changed

+125
-73
lines changed

changes.d/7048.fix.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
Stopped the evaluated value of `initial cycle point = now` changing on reload/restart.

cylc/flow/commands.py

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -568,6 +568,10 @@ async def reload_workflow(schd: 'Scheduler', reload_global: bool = False):
568568
schd.reload_pending = 'loading the workflow definition'
569569
schd.update_data_store() # update workflow status msg
570570
schd._update_workflow_state()
571+
# Things that can't change on workflow reload:
572+
schd._set_workflow_params(
573+
schd.workflow_db_mgr.pri_dao.select_workflow_params()
574+
)
571575
LOG.info("Reloading the workflow definition.")
572576
config = schd.load_flow_file(is_reload=True)
573577
except (ParsecError, CylcConfigError) as exc:
@@ -589,10 +593,7 @@ async def reload_workflow(schd: 'Scheduler', reload_global: bool = False):
589593
else:
590594
schd.reload_pending = 'applying the new config'
591595
old_tasks = set(schd.config.get_task_name_list())
592-
# Things that can't change on workflow reload:
593-
schd._set_workflow_params(
594-
schd.workflow_db_mgr.pri_dao.select_workflow_params()
595-
)
596+
596597
schd.apply_new_config(config, is_reload=True)
597598
schd.broadcast_mgr.linearized_ancestors = (
598599
schd.config.get_linearized_ancestors()

cylc/flow/config.py

Lines changed: 7 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -379,7 +379,8 @@ def __init__(
379379
raise WorkflowConfigError("missing [scheduling][[graph]] section.")
380380
# (The check that 'graph' is defined is below).
381381

382-
# Override the workflow defn with an initial point from the CLI.
382+
# Override the workflow defn with an initial point from the CLI
383+
# or from reload/restart:
383384
icp_str = getattr(self.options, 'icp', None)
384385
if icp_str is not None:
385386
self.cfg['scheduling']['initial cycle point'] = icp_str
@@ -564,7 +565,7 @@ def __init__(
564565
self._upg_wflow_event_names()
565566

566567
self.mem_log("config.py: before load_graph()")
567-
self.load_graph()
568+
self._load_graph()
568569
self.mem_log("config.py: after load_graph()")
569570

570571
self._set_completion_expressions()
@@ -684,10 +685,10 @@ def prelim_process_graph(self) -> None:
684685
all(item in ['graph', '1', 'R1'] for item in graphdict)
685686
):
686687
# Pure acyclic graph, assume integer cycling mode with '1' cycle
687-
self.cfg['scheduling']['cycling mode'] = INTEGER_CYCLING_TYPE
688688
for key in ('initial cycle point', 'final cycle point'):
689689
if key not in self.cfg['scheduling']:
690690
self.cfg['scheduling'][key] = '1'
691+
self.cfg['scheduling']['cycling mode'] = INTEGER_CYCLING_TYPE
691692

692693
def process_utc_mode(self):
693694
"""Set UTC mode from config or from stored value on restart.
@@ -761,7 +762,6 @@ def process_initial_cycle_point(self) -> None:
761762
Sets:
762763
self.initial_point
763764
self.cfg['scheduling']['initial cycle point']
764-
self.evaluated_icp
765765
Raises:
766766
WorkflowConfigError - if it fails to validate
767767
"""
@@ -775,11 +775,6 @@ def process_initial_cycle_point(self) -> None:
775775
raise WorkflowConfigError(
776776
"This workflow requires an initial cycle point.")
777777
icp = _parse_iso_cycle_point(orig_icp)
778-
self.evaluated_icp = None
779-
if icp != orig_icp:
780-
# now/next()/previous() was used, need to store
781-
# evaluated point in DB
782-
self.evaluated_icp = icp
783778
self.initial_point = get_point(icp).standardise()
784779
self.cfg['scheduling']['initial cycle point'] = str(self.initial_point)
785780

@@ -2312,7 +2307,7 @@ def _close_families(l_id, r_id, clf_map):
23122307

23132308
return lret, rret
23142309

2315-
def load_graph(self):
2310+
def _load_graph(self):
23162311
"""Parse and load dependency graph."""
23172312
LOG.debug("Parsing the dependency graph")
23182313

@@ -2336,18 +2331,14 @@ def load_graph(self):
23362331
section = get_sequence_cls().get_async_expr()
23372332
graphdict[section] = graphdict.pop('graph')
23382333

2339-
icp = self.cfg['scheduling']['initial cycle point']
2334+
icp = str(self.initial_point)
23402335
fcp = self.cfg['scheduling']['final cycle point']
23412336

23422337
# Make a stack of sections and graphs [(sec1, graph1), ...]
23432338
sections = []
23442339
for section, value in self.cfg['scheduling']['graph'].items():
23452340
# Substitute initial and final cycle points.
2346-
if icp:
2347-
section = section.replace("^", icp)
2348-
elif "^" in section:
2349-
raise WorkflowConfigError("Initial cycle point referenced"
2350-
" (^) but not defined.")
2341+
section = section.replace("^", icp)
23512342
if fcp:
23522343
section = section.replace("$", fcp)
23532344
elif "$" in section:

cylc/flow/cycling/integer.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -594,7 +594,7 @@ def init_from_cfg(_):
594594
pass
595595

596596

597-
def get_dump_format(cycling_type=None):
597+
def get_dump_format() -> None:
598598
"""Return cycle point string dump format."""
599599
# Not used for integer cycling.
600600
return None

cylc/flow/cycling/iso8601.py

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -649,6 +649,9 @@ def __lt__(self, other):
649649
def __str__(self):
650650
return self.value
651651

652+
def __repr__(self) -> str:
653+
return f"<{type(self).__name__} {self.value}>"
654+
652655
def __hash__(self) -> int:
653656
return hash(self.value)
654657

@@ -902,7 +905,7 @@ def init(num_expanded_year_digits=0, custom_dump_format=None, time_zone=None,
902905
return WorkflowSpecifics
903906

904907

905-
def get_dump_format():
908+
def get_dump_format() -> str:
906909
"""Return cycle point string dump format."""
907910
return WorkflowSpecifics.DUMP_FORMAT
908911

cylc/flow/cycling/loader.py

Lines changed: 24 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -19,11 +19,21 @@
1919
Each task may have multiple sequences, e.g. 12-hourly and 6-hourly.
2020
"""
2121

22-
from typing import Optional, Type, overload
22+
from typing import (
23+
Literal,
24+
Optional,
25+
Type,
26+
overload,
27+
)
2328

24-
from cylc.flow.cycling import PointBase, integer, iso8601
2529
from metomi.isodatetime.data import Calendar
2630

31+
from cylc.flow.cycling import (
32+
PointBase,
33+
integer,
34+
iso8601,
35+
)
36+
2737

2838
ISO8601_CYCLING_TYPE = iso8601.CYCLER_TYPE_ISO8601
2939
INTEGER_CYCLING_TYPE = integer.CYCLER_TYPE_INTEGER
@@ -88,8 +98,18 @@ def get_point_cls(cycling_type: Optional[str] = None) -> Type[PointBase]:
8898
return POINTS[cycling_type]
8999

90100

91-
def get_dump_format(cycling_type=None):
92-
"""Return cycle point dump format, or None."""
101+
@overload
102+
def get_dump_format(cycling_type: Literal["integer"]) -> None:
103+
...
104+
105+
106+
@overload
107+
def get_dump_format(cycling_type: Literal["iso8601"]) -> str:
108+
...
109+
110+
111+
def get_dump_format(cycling_type: Literal["integer", "iso8601"]) -> str | None:
112+
"""Return cycle point dump format (None for integer mode)."""
93113
return DUMP_FORMAT_GETTERS[cycling_type]()
94114

95115

cylc/flow/scheduler.py

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1228,7 +1228,7 @@ def apply_new_config(self, config, is_reload=False):
12281228
})
12291229

12301230
def _set_workflow_params(
1231-
self, params: Iterable[Tuple[str, Optional[str]]]
1231+
self, params: Iterable[tuple[str, str | None]]
12321232
) -> None:
12331233
"""Set workflow params on restart/reload.
12341234
@@ -1240,20 +1240,20 @@ def _set_workflow_params(
12401240
* A flag to indicate if the workflow should be paused or not.
12411241
* Original workflow run time zone.
12421242
"""
1243-
LOG.info('LOADING workflow parameters')
1243+
LOG.info("LOADING saved workflow parameters")
12441244
for key, value in params:
12451245
if key == self.workflow_db_mgr.KEY_RUN_MODE:
12461246
self.options.run_mode = value or RunMode.LIVE.value
12471247
LOG.info(f"+ run mode = {value}")
12481248
if value is None:
12491249
continue
1250-
if key in self.workflow_db_mgr.KEY_INITIAL_CYCLE_POINT_COMPATS:
1250+
if key == self.workflow_db_mgr.KEY_INITIAL_CYCLE_POINT:
12511251
self.options.icp = value
12521252
LOG.info(f"+ initial point = {value}")
1253-
elif key in self.workflow_db_mgr.KEY_START_CYCLE_POINT_COMPATS:
1253+
elif key == self.workflow_db_mgr.KEY_START_CYCLE_POINT:
12541254
self.options.startcp = value
12551255
LOG.info(f"+ start point = {value}")
1256-
elif key in self.workflow_db_mgr.KEY_FINAL_CYCLE_POINT_COMPATS:
1256+
elif key == self.workflow_db_mgr.KEY_FINAL_CYCLE_POINT:
12571257
if self.is_restart and self.options.fcp == 'reload':
12581258
LOG.debug(f"- final point = {value} (ignored)")
12591259
elif self.options.fcp is None:

cylc/flow/workflow_db_mgr.py

Lines changed: 2 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -95,13 +95,8 @@ class WorkflowDatabaseManager:
9595
"""Manage the workflow runtime private and public databases."""
9696

9797
KEY_INITIAL_CYCLE_POINT = 'icp'
98-
KEY_INITIAL_CYCLE_POINT_COMPATS = (
99-
KEY_INITIAL_CYCLE_POINT, 'initial_point')
10098
KEY_START_CYCLE_POINT = 'startcp'
101-
KEY_START_CYCLE_POINT_COMPATS = (
102-
KEY_START_CYCLE_POINT, 'start_point')
10399
KEY_FINAL_CYCLE_POINT = 'fcp'
104-
KEY_FINAL_CYCLE_POINT_COMPATS = (KEY_FINAL_CYCLE_POINT, 'final_point')
105100
KEY_STOP_CYCLE_POINT = 'stopcp'
106101
KEY_UUID_STR = 'uuid_str'
107102
KEY_CYLC_VERSION = 'cylc_version'
@@ -337,7 +332,7 @@ def put_workflow_params(self, schd: 'Scheduler') -> None:
337332
This method queues the relevant insert statements.
338333
339334
Arguments:
340-
schd (cylc.flow.scheduler.Scheduler): scheduler object.
335+
schd: scheduler object.
341336
"""
342337
self.db_deletes_map[self.TABLE_WORKFLOW_PARAMS].append({})
343338
self.db_inserts_map[self.TABLE_WORKFLOW_PARAMS].extend([
@@ -353,11 +348,8 @@ def put_workflow_params(self, schd: 'Scheduler') -> None:
353348
])
354349

355350
# Store raw initial cycle point in the DB.
356-
value = schd.config.evaluated_icp
357-
value = None if value == 'reload' else value
358351
self.put_workflow_params_1(
359-
self.KEY_INITIAL_CYCLE_POINT,
360-
value or str(schd.config.initial_point)
352+
self.KEY_INITIAL_CYCLE_POINT, str(schd.config.initial_point)
361353
)
362354

363355
for key in (

tests/functional/cylc-combination-scripts/09-vr-icp-now.t

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,8 @@
1616
# along with this program. If not, see <http://www.gnu.org/licenses/>.
1717

1818
#------------------------------------------------------------------------------
19-
# Ensure that validate step of Cylc VR cannot change the options object.
19+
# Ensure that validate step of `cylc vr` does not set the --icp option for the
20+
# restart step, as this would cause an InputError.
2021
# See https://github.com/cylc/cylc-flow/issues/6262
2122

2223
. "$(dirname "$0")/test_header"
@@ -26,14 +27,13 @@ WORKFLOW_ID=$(workflow_id)
2627

2728
cp -r "${TEST_SOURCE_DIR}/${TEST_NAME_BASE}/flow.cylc" .
2829

29-
run_ok "${TEST_NAME_BASE}-vip" \
30-
cylc vip . \
31-
--workflow-name "${WORKFLOW_ID}" \
32-
--no-detach \
33-
--no-run-name
30+
run_ok "${TEST_NAME_BASE}-vip" cylc vip . \
31+
--workflow-name "${WORKFLOW_ID}" \
32+
--no-detach \
33+
--no-run-name \
34+
--mode simulation
3435

3536
echo "# Some Comment" >> flow.cylc
3637

3738
run_ok "${TEST_NAME_BASE}-vr" \
38-
cylc vr "${WORKFLOW_ID}" \
39-
--stop-cycle-point 2020-01-01T00:02Z
39+
cylc vr "${WORKFLOW_ID}" --no-detach --mode simulation

tests/functional/cylc-combination-scripts/09-vr-icp-now/flow.cylc

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,11 @@
1+
[scheduler]
2+
[[events]]
3+
restart timeout = PT0S
14
[scheduling]
25
initial cycle point = 2020
3-
stop after cycle point = 2020-01-01T00:01Z
6+
final cycle point = 2020
47
[[graph]]
5-
PT1M = foo
8+
P1Y = foo
69
[runtime]
710
[[foo]]
811
[[[simulation]]]

0 commit comments

Comments
 (0)