{% import 'macros.j2' as macros -%}
# %%
%env COLUMNS=150

import kiara
from kiara.interfaces.python_api import Step
from kiara.utils.jupyter import graph_to_image

# %% [markdown]
# # Pipeline description

{{ structure.structure_config.documentation }}

# # Assembling the pipeline <a class="anchor" id="assembly"></a>

The first step in the creation of our pipeline is to create the individual steps from the available *kiara* modules.

A list of available modules and their aliases can be found here: TODO

# ## Creating the steps of the pipeline <a class="anchor" id="creating_steps"></a>

{%  for stage in structure.processing_stages -%}
# %% [markdown]
# ### Execution stage: {{ loop.index }} <a class="anchor" id="execution_stage_{{ loop.index }}"></a>
# %%
{% for step_id in stage -%}
{%  set step = structure.get_step(step_id) -%}
# Creating step: {{ step.step_id }}
{%  if step.module_config -%}
step_{{ step.step_id }}_config = {{ step.module_config }}
step_{{ step.step_id }} = Step(
    "{{ step.module_type }}",
    module_config=step_{{ step.step_id }}_config,
    step_id="{{ step.step_id }}")
{%  else -%}
step_{{ step.step_id }} = Step("{{ step.module_type }}", step_id="{{ step.step_id }}")
{%  endif -%}
{% endfor -%}
{%  endfor -%}

# %% [markdown]

# ## Connecting the pipeline steps <a class="anchor" id="connecting_steps"></a>

After we all steps are created, we need to wire them up to create our pipeline structure. All step inputs that are not
connected to other step outputs are considered user inputs, and, if their values are marked as 'required', must be set
later in order for our pipeline to run successfully.

{% set ns = namespace(last_step_id=None) %}
{%  for stage in structure.processing_stages -%}
{% for step_id in stage -%}
{%  set step = structure.get_step(step_id) -%}
{%  if step.input_links -%}
{%  set ns.last_step_id = step_id -%}
{{  macros.add_links(step, step.input_links) }}
{%  endif -%}
{% endfor -%}
{% endfor -%}

{% include 'pipeline_information.j2' %}
