Using solutions in data workflows

Every Album solution is a command-line step: album run runs it in its own environment. Workflow engines such as Snakemake or Nextflow - and plain scripts - call it like any other command. The engine handles the pipeline, Album provides the environment of each step, so steps with conflicting dependencies can be part of the same workflow.

Concern

Handled by

Order of steps, parallelism, retries, caching

Workflow engine

Software environment of a step, install-time setup (models, binaries)

Album (album install)

Running a step in its environment

Album (album run)

Inputs and outputs of a step

File and folder paths passed as solution arguments

Set up once

  1. Add the catalogs that contain your steps:

    album add-catalog https://gitlab.com/my-lab/my-catalog
    
  2. Install the steps:

    album install my-catalog:my-group:segment:0.1.0
    album install my-catalog:my-group:measure:0.2.0
    
  3. Look up their arguments (--json prints them as JSON):

    album info my-catalog:my-group:segment:0.1.0
    
  4. Use the full coordinates catalog:group:name:version in your workflow, so it always runs the versions you tested.

A solution as a workflow step

Each step is one album run call:

album run my-catalog:my-group:segment:0.1.0 --input raw/a.tif --output seg/a_seg.tif > logs/a.log 2>&1

Use this command in a Snakemake rule or a Nextflow process - the documentation of your workflow engine describes how to define them. Several steps can run at the same time.

How album run behaves in scripts

Topic

Behavior

Arguments

--name value or --name=value; use the = form if the value starts with -.

Boolean arguments

Always pass a value: --flag true or --flag false (also yes/no, on/off, 1/0).

Exit code

0 if the solution finished, the exit code of the solution if it failed, 1 for an Album error (for example a solution that is not installed), 2 for an invalid Album command line.

Outputs

Pass every output file or folder as an argument.

Logs

Album and the solution log to stdout. Redirect both streams, for example > step.log 2>&1.

Working directory

Relative paths are resolved against the directory you call album run from.

Interaction

Use solutions that do not open a GUI or wait for input.

Many inputs of one solution

A shell loop runs the solution once per file:

mkdir -p seg
for f in raw/*.tif; do
    name=$(basename "$f" .tif)
    album run my-catalog:my-group:segment:0.1.0 --input "$f" --output "seg/${name}_seg.tif" \
        > "seg/${name}.log" 2>&1 || echo "failed: $f"
done

album-distributed does this with one command - for example as a single step of a workflow or as one cluster job. It generates one task per file that matches a pattern and runs the tasks one after another or in parallel threads:

album run-distributed my-catalog:my-group:segment:0.1.0 --input "raw/*.tif" --output "seg/*_seg.tif" --mode queue --threads 4

Freezing a step with album-docker

When a step is stable, freeze it in a container image with album-docker. The image contains the solution environment and everything the solution’s install fetched at build time. The workflow then calls docker run <image> --input ... --output ... instead of album run.

Case study: a Snakemake workflow as one solution (ari3d)

ari3d (analysis of mineral particles in 3D X-ray CT images, case study C) ships its Snakemake workflow as one Album solution, de.mdc:ari3d:0.1.6:

  • The solution environment contains Snakemake and Album itself.

  • Its install installs the workflow steps, which are Album solutions of the ari3d catalog, into a base path of its own and downloads the default segmentation model.

  • Its run starts Snakemake with the solution arguments. Each analysis rule (segment, extract, quantify) runs one step solution through the Album Python API.

Install it from the cloned repository - with --allow-recursive, because its environment contains Album - and run it:

git clone --branch v0.1.6 https://gitlab.com/ida-mdc/ari3d.git
album install --allow-recursive ari3d
album run de.mdc:ari3d:0.1.6 --input_dir /data/ct-scans --project_dir /data/ari3d-project --parameters_file /data/ct-scans/parameters.json

The whole workflow is also available as one container image, built with album-docker. The image archives (22 to 27 GB) are published on DESY Sync&Share. Load the archive and run the workflow with a GPU:

docker load -i de.mdc_ari3d_0.1.6_image.tar
docker run --rm --gpus all -v /path/to/your/input:/input -v /path/to/your/output:/output de.mdc_ari3d_0.1.6 --input_dir /input --project_dir /output --parameters_file /input/parameters.json

If docker load prints only an image ID, name the image first: docker tag <image id> de.mdc_ari3d_0.1.6.

Environment variables

Album reads these variables when it starts. In Python, Album.Builder().base_cache_path(...) takes precedence over ALBUM_BASE_CACHE_PATH.

Variable

Effect

Default

ALBUM_BASE_CACHE_PATH

Folder for Album’s data: catalogs, collection, solution environments and installations, downloads, Album’s micromamba. Use an absolute path.

~/.album

ALBUM_DEFAULT_CATALOG

Source (URL or path) of the catalog default, which Album adds when it creates a new collection.

https://gitlab.com/album-app/catalogs/default

ALBUM_DEFAULT_CATALOG_BRANCH

Branch of that catalog.

main

ENVIRONMENT_DEBUGGING_MICROMAMBA_PATH

Path to a micromamba executable that Album uses instead of downloading its own, see Using a different micromamba.

not set

ENVIRONMENT_CONDA_LOCK_PATH

Path to a conda-lock executable, used by album deploy and to install a solution from its solution.conda-lock.yml.

not set