Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Allow stepped integer parameters. #2240

Merged
merged 5 commits into from
May 12, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
1 change: 1 addition & 0 deletions doc/src/cylc-user-guide/cug.tex
Original file line number Diff line number Diff line change
Expand Up @@ -4379,6 +4379,7 @@ \subsubsection{Parameter Expansion}
[[parameters]]
obs = ship, buoy, plane
run = 1..5 # 1, 2, 3, 4, 5
idx = 1..9..2 # 1, 3, 5, 7, 9
\end{lstlisting}
Then angle brackets denote use of these parameters throughout the suite
definition. For the values above, this parameterized name:
Expand Down
6 changes: 3 additions & 3 deletions doc/src/cylc-user-guide/suiterc.tex
Original file line number Diff line number Diff line change
Expand Up @@ -234,13 +234,13 @@ \subsection{[cylc]}
\item {\em default:} False
\end{myitemize}

\subsubsection[parameters]{[cylc] \textrightarrow parameters}
\subsubsection[{[[}parameters{]]}]{[cylc] \textrightarrow [[parameters]]}

Define parameter values here for use in expanding {\em parameterized tasks} -
see Section~\ref{Parameterized Tasks}.
\begin{myitemize}
\item {\em type:} list of strings, or an integer range
\lstinline=LOWER..UPPER= (two dots, inclusive bounds)
\lstinline=LOWER..UPPER..STEP= (two dots, inclusive bounds, STEP optional)
\item {\em default:} (none)
\item {\em examples:}
\begin{myitemize}
Expand All @@ -249,7 +249,7 @@ \subsection{[cylc]}
\end{myitemize}
\end{myitemize}

\subsubsection[parameter templates]{[cylc] \textrightarrow parameter templates}
\subsubsection[{[[}parameter templates{]]}]{[cylc] \textrightarrow [[parameter templates]]}
\label{RefParameterTemplates}

Parameterized task names (see previous item, and Section~\ref{Parameterized
Expand Down
28 changes: 14 additions & 14 deletions lib/cylc/cfgspec/suite.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@
from cylc.network import PRIVILEGE_LEVELS


REC_PARAM_INT_RANGE = re.compile('(\d+)\.\.(\d+)')
REC_PARAM_INT_RANGE = re.compile('(\d+)\.\.(\d+)(?:\.\.(\d+))?')


def _coerce_cycleinterval(value, keys, _):
Expand Down Expand Up @@ -141,19 +141,19 @@ def _coerce_final_cycletime(value, keys, _):
def _coerce_parameter_list(value, keys, _):
"""Coerce parameter list."""
value = _strip_and_unquote_list(keys, value)
if len(value) == 1:
# May be a range e.g. '1..5' (bounds inclusive)
try:
lower, upper = REC_PARAM_INT_RANGE.match(value[0]).groups()
except AttributeError:
if '.' in value[0]:
# Dot is illegal in node names, probably bad range syntax.
raise IllegalValueError("parameter", keys, value)
else:
n_dig = len(upper)
return [
str(i).zfill(n_dig) for i in range(int(lower), int(upper) + 1)]
return value
# May be an integer range with step e.g. '1..6..2' (bounds inclusive).
try:
lower, upper, step = REC_PARAM_INT_RANGE.match(value[0]).groups()
step = step or 1
except AttributeError:
if '.' in value[0]:
# Dot is illegal in node names, probably bad range syntax.
raise IllegalValueError("parameter", keys, value)
return value
else:
n_dig = len(upper)
return [str(i).zfill(n_dig) for i in
range(int(lower), int(upper) + 1, int(step))]

coercers['cycletime'] = _coerce_cycletime
coercers['cycletime_format'] = _coerce_cycletime_format
Expand Down
2 changes: 1 addition & 1 deletion lib/cylc/graph_parser.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#!usr/bin/env python
#!/usr/bin/env python

# THIS FILE IS PART OF THE CYLC SUITE ENGINE.
# Copyright (C) 2008-2017 NIWA
Expand Down
31 changes: 31 additions & 0 deletions tests/param_expand/01-basic.t
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
#!/bin/bash
# THIS FILE IS PART OF THE CYLC SUITE ENGINE.
# Copyright (C) 2008-2017 NIWA
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.
#-------------------------------------------------------------------------------
# check tasks and graph generated by parameter expansion.
. $(dirname $0)/test_header
#-------------------------------------------------------------------------------
set_test_number 2
#-------------------------------------------------------------------------------
install_suite $TEST_NAME_BASE $TEST_NAME_BASE
#-------------------------------------------------------------------------------
TEST_NAME=$TEST_NAME_BASE-validate
run_ok $TEST_NAME cylc validate "${SUITE_NAME}"
#-------------------------------------------------------------------------------
cylc graph --reference $SUITE_NAME > new.graph.ref
cmp_ok new.graph.ref $TEST_SOURCE_DIR/$TEST_NAME_BASE/graph.ref
#-------------------------------------------------------------------------------
purge_suite $SUITE_NAME
48 changes: 48 additions & 0 deletions tests/param_expand/01-basic/graph.ref
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
edge "foo_cat.1" "bar_j1.1" solid
edge "foo_cat.1" "bar_j2.1" solid
edge "foo_cat.1" "bar_j3.1" solid
edge "foo_cat.1" "bar_j4.1" solid
edge "foo_cat.1" "bar_j5.1" solid
edge "foo_dog.1" "bar_j1.1" solid
edge "foo_dog.1" "bar_j2.1" solid
edge "foo_dog.1" "bar_j3.1" solid
edge "foo_dog.1" "bar_j4.1" solid
edge "foo_dog.1" "bar_j5.1" solid
edge "foo_fish.1" "bar_j1.1" solid
edge "foo_fish.1" "bar_j2.1" solid
edge "foo_fish.1" "bar_j3.1" solid
edge "foo_fish.1" "bar_j4.1" solid
edge "foo_fish.1" "bar_j5.1" solid
edge "qux_j1.1" "waz_k01.1" solid
edge "qux_j1.1" "waz_k05.1" solid
edge "qux_j1.1" "waz_k09.1" solid
edge "qux_j2.1" "waz_k01.1" solid
edge "qux_j2.1" "waz_k05.1" solid
edge "qux_j2.1" "waz_k09.1" solid
edge "qux_j3.1" "waz_k01.1" solid
edge "qux_j3.1" "waz_k05.1" solid
edge "qux_j3.1" "waz_k09.1" solid
edge "qux_j4.1" "waz_k01.1" solid
edge "qux_j4.1" "waz_k05.1" solid
edge "qux_j4.1" "waz_k09.1" solid
edge "qux_j5.1" "waz_k01.1" solid
edge "qux_j5.1" "waz_k05.1" solid
edge "qux_j5.1" "waz_k09.1" solid
graph
node "bar_j1.1" "bar_j1\n1" unfilled box black
node "bar_j2.1" "bar_j2\n1" unfilled box black
node "bar_j3.1" "bar_j3\n1" unfilled box black
node "bar_j4.1" "bar_j4\n1" unfilled box black
node "bar_j5.1" "bar_j5\n1" unfilled box black
node "foo_cat.1" "foo_cat\n1" unfilled box black
node "foo_dog.1" "foo_dog\n1" unfilled box black
node "foo_fish.1" "foo_fish\n1" unfilled box black
node "qux_j1.1" "qux_j1\n1" unfilled box black
node "qux_j2.1" "qux_j2\n1" unfilled box black
node "qux_j3.1" "qux_j3\n1" unfilled box black
node "qux_j4.1" "qux_j4\n1" unfilled box black
node "qux_j5.1" "qux_j5\n1" unfilled box black
node "waz_k01.1" "waz_k01\n1" unfilled box black
node "waz_k05.1" "waz_k05\n1" unfilled box black
node "waz_k09.1" "waz_k09\n1" unfilled box black
stop
18 changes: 18 additions & 0 deletions tests/param_expand/01-basic/suite.rc
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
[cylc]
[[parameters]]
i = cat, dog, fish
j = 1..5
k = 1..10..4
[scheduling]
[[dependencies]]
graph = """
foo<i> => bar<j>
qux<j> => waz<k>
"""
[runtime]
[[root]]
script = true
[[foo<i>]]
[[bar<j>]]
[[qux<j>]]
[[waz<k>]]