Install fractal-tasks-tools
¶
Fractal Task Tools is hosted on the PyPI
index, and it can be installed with
pip
via
pip install fractal-task-tools
Use fractal-task-tools
¶
The fractal-task-tools
package mainly includes two main features:
- Tools for building the manifest for a package of Fractal tasks.
- A
run_fractal_task
wrapper that wraps a Python function into a command-line interface, meant to be used from within the Fractal framework.
Build manifest for your Fractal-tasks package¶
fractal-task-tools
includes a set of task models, to be used in the task_list.py
module.
See the following example from the fractal-tasks-core
package:
from fractal_task_tools.task_models import ConverterCompoundTask
TASK_LIST = [
ConverterCompoundTask(
name="Convert Cellvoyager to OME-Zarr",
executable_init="tasks/cellvoyager_to_ome_zarr_init.py",
executable="tasks/cellvoyager_to_ome_zarr_compute.py",
meta_init={"cpus_per_task": 1, "mem": 4000},
meta={"cpus_per_task": 1, "mem": 4000},
category="Conversion",
modality="HCS",
tags=["Yokogawa", "Cellvoyager", "2D", "3D"],
docs_info="file:task_info/convert_cellvoyager_to_ome_zarr.md",
),
]
Once the task_list.py
module is defined, fractal-task-tools
also includes a command-line interface for creating (or checking) a manifest file. This can be used e.g. as in
fractal-manifest --package my-task-package
__FRACTAL_MANIFEST__.json
, in the root folder where the package my-task-package
is installed.
Run tasks through Fractal¶
Within the Fractal framework, tasks are run as executable commands with a given signature, which looks like
python task.py --args-json /path/to/arguments.json --out-json /path/to/output/metadata.json
run_fractal_task
wrapper converts a Python function into such a command-line interface, as in
from fractal_task_tools.task_wrapper import run_fractal_task
if __name__ == "__main__":
run_fractal_task(task_function=some_function)
Migrate from fractal-tasks-core
¶
-
In the
task_list.py
file of your package, import task models fromfractal_task_tools.task_models
(rather thanfractal_tasks_core.dev.task_models
), as infrom fractal_task_tools.task_models import CompoundTask from fractal_task_tools.task_models import NonParallelTask from fractal_task_tools.task_models import ConverterCompoundTask from fractal_task_tools.task_models import ConverterNonParallelTask from fractal_task_tools.task_models import ParallelTask
-
If some of your tasks are converters (that is, they create OME-Zarr images but do not take any OME-Zarr image as an input), you can now use one of the new available task types (
ConverterCompoundTask
andConverterNonParallelTask
). -
In the
task_list.py
file of your package, optionally include variables forAUTHORS
,DOCS_LINK
andINPUT_MODELS
(if applicable), as in this example:AUTHORS = "Fractal Core Team" DOCS_LINK = "https://fractal-analytics-platform.github.io/fractal-tasks-core" INPUT_MODELS = [ ["fractal_tasks_core", "channels.py", "OmeroChannel"], ["fractal_tasks_core", "channels.py", "Window"], ["fractal_tasks_core", "channels.py", "ChannelInputModel"], ... ]
-
In order to create the manifest for your package and write it to disk (within the root directory of the installed package), use
This command replaces the customfractal-manifest create --package my-fractal-tasks-package
create_manifest.py
script, that you can now delete. -
In order to check that the manifest for your package is up to date (e.g. from within the CI), use
This command replaces the custom logic often included in GitHub Actions, which re-creates the manifest and then run afractal-manifest check --package my-fractal-tasks-package
git diff
to see if it changed. -
For each one of your tasks' modules, replace the
import
fromfractal_tasks_core.tasks._utils
withfrom fractal_task_tools.task_wrapper import run_fractal_task