Skip to content

[Question] remove_result raises IndexError when no output node is present #180

@Max-ChenFei

Description

@Max-ChenFei

Hi, some processing workflows may not include an output node because they focus on intermediate results rather than a final output or save the output to the disk.
For example:
workflow.json

{
  "version": "0.1.0",
  "nodes": [
    {"id": 0, "type": "function", "value": "workflow.save_image"},
    {"id": 1, "type": "input", "value": "image.png", "name": "x"},
  ],
  "edges": [
    {"target": 0, "targetPort": "x", "source": 1, "sourcePort": null},
  ]
}

workflow.py

def save_image(x):
    imsave(x)

when I use following code to run a workflow

from python_workflow_definition.pyiron_base import load_workflow_json
delayed_object_lst = load_workflow_json(file_name='workflow.json')
delayed_object_lst[-1].pull()

In load_workflow_json function, the remove_result was called

def load_workflow_json(file_name: str, project: Optional[Project] = None):
if project is None:
project = Project(".")
content = remove_result(
workflow_dict=PythonWorkflowDefinitionWorkflow.load_json_file(
file_name=file_name
)
)

If there are zero output nodes, the list comprehension returns [], and [][0] raises IndexError at Line111.

def remove_result(workflow_dict):
node_output_id = [
n["id"] for n in workflow_dict[NODES_LABEL] if n["type"] == "output"
][0]

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions