Skip to content

Commit

Permalink
restore validate --run-mode
Browse files Browse the repository at this point in the history
  • Loading branch information
wxtim committed Oct 31, 2024
1 parent 2ec57e9 commit aeca3e4
Show file tree
Hide file tree
Showing 5 changed files with 59 additions and 5 deletions.
6 changes: 6 additions & 0 deletions cylc/flow/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,7 @@
)
from cylc.flow.print_tree import print_tree
from cylc.flow.task_qualifiers import ALT_QUALIFIERS
from cylc.flow.run_modes.simulation import configure_sim_mode
from cylc.flow.run_modes.skip import skip_mode_validate
from cylc.flow.subprocctx import SubFuncContext
from cylc.flow.task_events_mgr import (
Expand Down Expand Up @@ -513,6 +514,11 @@ def __init__(

self.process_runahead_limit()

run_mode = RunMode.get(self.options)
if run_mode in {RunMode.SIMULATION, RunMode.DUMMY}:
for taskdef in self.taskdefs.values():
configure_sim_mode(taskdef.rtconfig, None, False)

self.configure_workflow_state_polling_tasks()

self._check_task_event_handlers()
Expand Down
4 changes: 3 additions & 1 deletion cylc/flow/run_modes/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,11 +14,13 @@
# You should have received a copy of the GNU General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.

from copy import deepcopy
from enum import Enum
from typing import TYPE_CHECKING, Callable, Optional, Tuple
from typing import TYPE_CHECKING, Callable, Dict, Optional, Tuple

if TYPE_CHECKING:
from optparse import Values
from cylc.flow.taskdef import TaskDef
from cylc.flow.task_job_mgr import TaskJobManager
from cylc.flow.task_proxy import TaskProxy

Expand Down
20 changes: 16 additions & 4 deletions cylc/flow/run_modes/simulation.py
Original file line number Diff line number Diff line change
Expand Up @@ -189,7 +189,7 @@ def __init__(
self.timeout = started_time + self.simulated_run_length


def configure_sim_mode(rtc, fallback):
def configure_sim_mode(rtc, fallback, warnonly: bool = True):
"""Adjust task defs for simulation mode.
Example:
Expand All @@ -209,6 +209,13 @@ def configure_sim_mode(rtc, fallback):
>>> rtc['platform']
'localhost'
"""
if not warnonly:
parse_fail_cycle_points(
rtc["simulation"]["fail cycle points"],
fallback,
warnonly
)
return
rtc['submission retry delays'] = [1]

disable_platforms(rtc)
Expand All @@ -220,7 +227,8 @@ def configure_sim_mode(rtc, fallback):
"fail cycle points"
] = parse_fail_cycle_points(
rtc["simulation"]["fail cycle points"],
fallback
fallback,
warnonly
)


Expand Down Expand Up @@ -265,6 +273,7 @@ def disable_platforms(
def parse_fail_cycle_points(
fail_at_points_updated: List[str],
fail_at_points_config,
warnonly: bool = True
) -> 'Union[None, List[PointBase]]':
"""Parse `[simulation][fail cycle points]`.
Expand Down Expand Up @@ -302,8 +311,11 @@ def parse_fail_cycle_points(
try:
fail_at_points.append(get_point(point_str).standardise())
except PointParsingError as exc:
LOG.warning(exc.args[0])
return fail_at_points_config
if warnonly:
LOG.warning(exc.args[0])
return fail_at_points_config
else:
raise exc
return fail_at_points


Expand Down
5 changes: 5 additions & 0 deletions cylc/flow/scripts/validate.py
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@
ICP_OPTION,
)
from cylc.flow.profiler import Profiler
from cylc.flow.scheduler_cli import RUN_MODE
from cylc.flow.task_proxy import TaskProxy
from cylc.flow.templatevars import get_template_vars
from cylc.flow.terminal import cli_function
Expand All @@ -60,6 +61,8 @@
from cylc.flow.option_parsers import Values


VALIDATE_RUN_MODE = deepcopy(RUN_MODE)
VALIDATE_RUN_MODE.sources = {'validate'}
VALIDATE_ICP_OPTION = deepcopy(ICP_OPTION)
VALIDATE_ICP_OPTION.sources = {'validate'}
VALIDATE_AGAINST_SOURCE_OPTION = deepcopy(AGAINST_SOURCE_OPTION)
Expand Down Expand Up @@ -95,6 +98,7 @@
dest="profile_mode",
sources={'validate'}
),
VALIDATE_RUN_MODE,
VALIDATE_ICP_OPTION,
]

Expand Down Expand Up @@ -149,6 +153,7 @@ async def run(
src=True,
constraint='workflows',
)

cfg = WorkflowConfig(
workflow_id,
flow_file,
Expand Down
29 changes: 29 additions & 0 deletions tests/integration/test_config.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
from cylc.flow.cfgspec.glbl_cfg import glbl_cfg
from cylc.flow.cfgspec.globalcfg import GlobalConfig
from cylc.flow.exceptions import (
PointParsingError,
ServiceFileError,
WorkflowConfigError,
XtriggerConfigError,
Expand Down Expand Up @@ -628,3 +629,31 @@ def test_skip_forbidden_as_output(flow, validate):
})
with pytest.raises(WorkflowConfigError, match='message for skip'):
validate(wid)


def test_validate_workflow_run_mode(flow: Fixture, validate: Fixture, caplog: Fixture):
"""Test that Cylc validate will only check simulation mode settings
if validate --mode simulation or dummy.
Discovered in:
https://github.com/cylc/cylc-flow/pull/6213#issuecomment-2225365825
"""
wid = flow(
{
'scheduling': {'graph': {'R1': 'mytask'}},
'runtime': {
'mytask': {
'simulation': {'fail cycle points': 'invalid'},
}
},
}
)

validate(wid)

# It fails with run mode simulation:
with pytest.raises(PointParsingError, match='Incompatible value'):
validate(wid, run_mode='simulation')

# It fails with run mode dummy:
with pytest.raises(PointParsingError, match='Incompatible value'):
validate(wid, run_mode='dummy')

0 comments on commit aeca3e4

Please sign in to comment.