simpleaf workflow run
=====================
The ``simpleaf workflow run`` command is designed to run potentially complex single-cell data processing workflows using an instantiated simpleaf workflow template. Please check our tutorial on `running an workflow from an published template `_ and `developing custom template from scratch `_
``simpleaf workflow run`` exposes one required parameter group (though the options are mutually exclusive):
* ``--template`` takes the path to a ``simpleaf`` workflow *template* (i.e. an un-evaluated JSONNET file). One can develop their own templates or grab published templates from the `protocol estuary `_ GitHub repository using the API we provide via the the ``simpleaf workflow get`` command, and fill in required information.
* ``--manifest`` takes the path to a ``simpleaf`` workflow *manifest* (i.e. a fully-instantiated JSON file that describes and enumrates all of the commands to be executed, with all relevant parameters fully specified). This manifest could e.g. be the result of a prior execution, or the result of applying the ``simpleaf workflow patch`` command to a template to produce one or more manifests with desired parameters replaced.
Additionally, the user may pass an ``--output`` parameter to the ``run`` invokation, but **only if a template is being instantiated and run**, as the ``--output`` flag does not
make sense in the context of a fully-instantiated manifest.
* ``--output`` takes the path to the output directory for writing the log files and the results generated by invoking workflow commands. Note that paramater will only have an effect if the
corresponding template allows passing ``output`` as an external variable (all of the templates in the protocol estuary do). Further, if the output directory has already been manually
overridden in the template, then ``--output`` will have no effect and will not be used; in this case a warning to this effect will be printed.
When calling ``simpleaf workflow run`` using a workflow template, ``simpleaf`` will first instantiate the template, which is a `Jsonnet `_ program, into a workflow manifest in JSON format. Whereas the workflow template provides a "template" for the workflow and functions to handle features like basic logic, the resulting workflow manifest is a simple imperative description of the commands to be executed. To provide the greatest flexibility, the only requirement we set for a ``simpleaf`` workflow template is that in the workflow manifest its results, the fields representing a command record, either a ``simpleaf`` command or an external shell command, follow the format described in section `Valid simpleaf workflow manifest format`_.
Then, ``simpleaf workflow run`` will traverse the workflow manifest to collect the ``simpleaf`` and external shell command records and place them into an execution queue, ordered by their ``step`` number.
``simpleaf workflow run`` also exposes multiple flags for controlling the execution flow when invoking the commands. If none of the flags is set, ``simpleaf`` will invoke all commands in the execution queue.
* If setting the ``--no-execution`` flag, ``simpleaf`` will parse the file passed to the ``--template`` option, write the manifest and log files, and return without invoking any command.
* If setting the ``--start-at`` flag with a ``step`` number, ``simpleaf`` will ignore all previous steps (commands) and begin the invocation from the commands in the execution queue whose `step` is equal or next to that specific starting ``step``.
* If setting the ``--resume`` flag, ``simpleaf`` will try to find the log file from a previous run in the provided output folder to decide which ``step`` to begin with.
* If setting the ``--skip-step`` flag with a set of comma-separated ``step`` numbers, ``simpleaf`` will ignore the commands whose ``step`` is in those numbers.
Workflow Output
^^^^^^^^^^^^^^^
``simpleaf workflow run`` writes two log files to the output directory passed to ``--output``:
* ``simpleaf_workflow_log.json``: This file records the meta and logging information of the workflow execution. For example, the runtime of each executed command and the ``step`` of the start and terminating command. If ``--resume`` is set, ``simpleaf`` will try to find this file in the provided output directory to decide which step(command) to start.
* ``workflow_execution_log.json``: This file is a modified version of the workflow manifest JSON discussed above. The only modification is that in this file, the ``active`` field of the successfully invoked commands (return code 0) becomes `false`.
workflow run: Full Usage
^^^^^^^^^^^^^^^^^^^^^^^^
The relevant options (which you can obtain by running ``simpleaf workflow run -h``) are:
.. code-block:: console
Parse and instantiate a workflow template and invoke the workflow commands, or run an instantiated manifest directly
Usage: simpleaf workflow run [OPTIONS] <--manifest |--template >
Options:
-t, --template path to an instantiated simpleaf workflow template
-o, --output