Edit this page on our live server and create a PR by running command !create-pr in the console panel

Input option pattern and function expand_pattern

  • Difficulty level: easy
  • Time need to lean: 10 minutes or less
  • Key points:
    • Option pattern creates variables from input files

Option pattern

Option pattern uses named wildcards to match pattern to all input files, and creates step variables for these wildcard objects. That is to say, with step_input='a-20.txt', 'b-10.txt' and pattern = '{name}-{par}.txt' as in the following example, SoS creates

  • name=['a', 'b']
  • par=['20', '10']

Then, with the help from another function expand_pattern that creates multiple names from array variables, we can join the arrays to create _output

  • a-processed-20.txt and
  • b-processed-20.txt
In [1]:
a-processed-20.txt b-processed-10.txt

pattern in substeps

A side effect of pattern is that the extracted variables are automatically paired_with input files, which, in addition to variables such as name and par, with create variables _name and _par for each substep.

That is to say, if substeps are defined with option group_by (or for_each), the expand_pattern should use variables _name and _par to create the right _output for each substep:

In [2]:
a-processed-20.txt
b-processed-10.txt