Skip to content

BUG: job that returns a numpy array fails #855

Description

@FabiPi3

Consider this example:

import numpy as np
from jobflow import job, run_locally

@job
def return_numpy():
    return np.array([[1, 2], [3, 4]])

run_locally(return_numpy(), ensure_success=True)

While I expect this to work, the output can literally be anything, it actually fails. Error message:

Traceback (most recent call last):
  File "/Users/fabianpeschel/miniconda3/envs/exwoflow313/lib/python3.13/site-packages/jobflow/managers/local.py", line 117, in _run_job
    response = job.run(store=store)
  File "/Users/fabianpeschel/miniconda3/envs/exwoflow313/lib/python3.13/site-packages/jobflow/core/job.py", line 630, in run
    response = Response.from_job_returns(
        response, self.output_schema, job_dir=job_dir
    )
  File "/Users/fabianpeschel/miniconda3/envs/exwoflow313/lib/python3.13/site-packages/jobflow/core/job.py", line 1315, in from_job_returns
    if job_returns and isinstance(job_returns, (list, tuple)):
       ^^^^^^^^^^^
ValueError: The truth value of an array with more than one element is ambiguous. Use a.any() or a.all()

The bug appeared when switching to the newest version 0.3.1. I think the issue was introduced in here: #848
The test if job_returns doesn't work for arrays. One would need a separate handling for this.

Probably @gpetretto and @utf can have a look.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Fields

    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions