Download Outputs
Once your Algorithm Job or Invocation is in the 'Succeeded' state you can proceed to download the outputs the algorithm has created.
First things first, we need to get started and initiate the client:
Jobs or invocations¤
Below, we describe how to download the outputs for algorithm jobs. You can use the same steps for algorithm endpoint invocations by replacing the algorithm jobs API client.algorithm_jobs by the invocations API client.algorithm_invocations.
List the jobs¤
If you've submitted all the jobs yourself, you'll likely have an array of jobs still in memory, use that:
Alternatively, you might need to query all the jobs of the algorithm. First get the algorithm object. Then filter the jobs using the algorithm pk.
algorithm = client.algorithm.detail(slug="your-algorithm-slug")
jobs = client.algorithm_jobs.iterate_all(
params={"algorithm_image__algorithm": algorithm.pk},
)
Filtering On Algorithm Image
The algorithm image dictates exactly which algorithm version was used and using it ensures we only get results from this particular version of the algorithm. Use it to filter your jobs:
algorithm_image_pk = "6185b379-e246-4ff3-90cf-2edc76ce0245"
algorithm_image = client.algorithm_images.detail(pk=algorithm_image_pk)
algorithm = client.algorithms.detail(api_url=algorithm_image.algorithm)
jobs = client.algorithm_jobs.iterate_all(
params={"algorithm_image__algorithm": algorithm.pk},
)
filtered_jobs = [job in jobs if job.algorithm_image == algorithm_image.api_url]
Download the outputs¤
With a job list ready, download the outputs of the jobs by handling the socket values via Client.download_socket_value.
The snippet below will download all contents as files and place them under the download/ directory, creating a subdirectory for each job that has ran.
from pathlib import Path
output_path = Path("download/")
for job in jobs:
assert job.status == "Succeeded"
item_path = output_path / job.pk
item_path.mkdir(parents=True, exist_ok=True)
for socket_value in job.outputs:
client.download_socket_value(
socket_value=socket_value,
output_directory=item_path,
)