Paths and output files#
To assure that the dependency between different tasks is handled correctly it is essential that all outputs from tasks are provided as an explicit output from the Python function that represents the task. However, there are cases where the result has to be written to output files and cannot be encoded as a single output variable
(see e.g. the ground state task in the section Basic concepts).
In such a case the path to the file can be returned as a pathlib.Path object. The system then automatically assures that the path resolves to the correct directory. Below we provide a simple example of tasks that read/write output files.
First create a taskblaster repository
$ tb init
Created repository using module "taskblaster.repository" in "/home/me/repo".
An example of tasks that read/write output files as paths is given by the following workflow
import taskblaster as tb
@tb.workflow
class Workflow:
greeting = tb.var()
@tb.task
def hello(self):
return tb.node('write_greeting', greeting=self.greeting)
@tb.task
def read_hello(self):
return tb.node('read_and_return_greeting', greeting_path=self.hello)
def workflow(runner):
runner.run_workflow(Workflow(greeting='hello world'))
with the tasks defined in tasks.py
from pathlib import Path
def write_greeting(greeting):
with open('output.txt', 'w') as fd:
fd.write(greeting)
return Path('output.txt')
def read_and_return_greeting(greeting_path):
with open(greeting_path, 'r') as fd:
lines = fd.readlines()
return lines
If you run the workflow
$ tb workflow workflow.py entry: add new 0/0 tree/hello add new 0/1 tree/read_hello add: 2
$ tb run tree
Starting worker rank=000 size=001
[rank=000 2026-04-17 12:58:41 N/A-0/1] Worker class: —
[rank=000 2026-04-17 12:58:41 N/A-0/1] Required tags: —
[rank=000 2026-04-17 12:58:41 N/A-0/1] Supported tags: —
[rank=000 2026-04-17 12:58:41 N/A-0/1] name: None
tags: —
required_tags: —
resources: None
max_tasks: None
subworker_size: None
subworker_count: None
wall_time: None
no_mpi: None
workflow: None
[rank=000 2026-04-17 12:58:41 N/A-0/1] Main loop
[rank=000 2026-04-17 12:58:41 N/A-0/1] Running hello ...
[rank=000 2026-04-17 12:58:41 N/A-0/1] Task hello finished in 0:00:00.001079
[rank=000 2026-04-17 12:58:41 N/A-0/1] Running read_hello ...
[rank=000 2026-04-17 12:58:41 N/A-0/1] Task read_hello finished in 0:00:00.000670
[rank=000 2026-04-17 12:58:41 N/A-0/1] No available tasks, end worker main loop
you can view how the output is encoded using the tb view command:
$ tb view tree
name: hello
location: /home/me/repo/tree/hello
state: done
target: write_greeting(…)
wait for: 0 dependencies
depth: 0
source workflow: <root workflow>
frozen by: (not frozen)
latest handled inputs:
None
handlers:
[]
handler data:
<None>
parents:
<task has no dependencies>
input:
["write_greeting", {"greeting": "hello world"}]
output:
PosixPath('/home/me/repo/tree/hello/output.txt')
Run information:
Worker name: N/A-0/1
Start time: 2026-04-17 12:58:41
End time: 2026-04-17 12:58:41
Duration: 0:00:00
Error: None
No custom actions defined for this task.
name: read_hello
location: /home/me/repo/tree/read_hello
state: done
target: read_and_return_greeting(…)
wait for: 0 dependencies
depth: 1
source workflow: <root workflow>
frozen by: (not frozen)
latest handled inputs:
None
handlers:
[]
handler data:
<None>
parents:
hello
input:
["read_and_return_greeting", {"greeting_path": {"__tb_type__": "ref", "index": [], "name": "hello"}}]
output:
['hello world']
Run information:
Worker name: N/A-0/1
Start time: 2026-04-17 12:58:41
End time: 2026-04-17 12:58:41
Duration: 0:00:00
Error: None
No custom actions defined for this task.