# Step Execution and Structure

A **step** represents a stage or function within the pipeline. Each step is defined by a function that runs with the parameters and inputs configured in the pipeline. Steps are added sequentially and executed in the same order they were defined.

When a step is executed, a new folder is automatically created inside the previously configured output directory (see the *Output Directory* section).\
Each folder follows this naming format:

```
{branch_name} - Step {step_number} - {function_name}
```

For example, if you are on the `main` branch and execute the first step with the function `sum`, a folder will be created with the name:

```
main - Step 1 - sum
```

Inside that folder, all the output files generated by that step will be stored — whether it produces one or multiple outputs.\
As more steps are added and executed, the pipeline will automatically create new folders following this same convention.

***

#### Example: running steps

Once the pipeline is created, you can add and chain steps like this:

```python
(
    pipeline
    .isx.preprocess_videos()
    .isx.bandpass_filter_videos()
    .isx.motion_correction_videos()
    .isx.normalize_dff_videos()
    .isx.extract_neurons_pca_ica()
    .isx.detect_events_in_cells()
    .isx.auto_accept_reject_cells()
)
```

In this example, several functions from the **isx** module are executed one after another.\
Each of them corresponds to a different step, and each step generates its own output folder within the configured directory.

You can also run a single function if you want to execute a specific step, or chain multiple steps together to run the full sequence of the pipeline.

***

#### Creating a Branch

The `branch(branch_name)` function allows you to generate a new pipeline from an existing one. The new branch **inherits all previously defined steps and defaults** from the original pipeline but can add new steps without modifying the original.

Example usage:

```python
pipeline = CIPipe(pipeline_input, file_system=self._file_system)
pipeline.step("Add one", add_one)

# Create a secondary branch
new_pipeline_branch = pipeline.branch("Secondary Branch")
new_pipeline_branch.step("Add one", add_one)

# Continue working on the original pipeline
pipeline.step("Multiply by 2", multiply_by_2)
```

In this example:

* The `"Secondary Branch"` starts with the same steps as the original pipeline but then adds its own step.
* The original pipeline can continue adding independent steps.
* Each branch generates its own output folders. For example:

```
main - Step 1 - Add one
main - Step 2 - Multiply by 2
Secondary Branch - Step 2 - Add one
```

This allows you to **execute new steps in the branch without affecting the original pipeline**, keeping the results of each branch separate and enabling you to continue working with either pipeline.


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://cipipe.gitbook.io/cipipe-docs/creating-a-pipeline/step-execution-and-structure.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
