Skip to content

Commit

Permalink
enh: added better error handling and reporting
Browse files Browse the repository at this point in the history
  • Loading branch information
satra committed Apr 10, 2024
1 parent e915513 commit 4f54d56
Showing 1 changed file with 19 additions and 8 deletions.
27 changes: 19 additions & 8 deletions src/b2aiprep/cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -161,21 +161,32 @@ def batchconvert(
)

cwd = os.getcwd()
with pydra.Submitter(plugin=plugin[0], **plugin_args) as sub:
sub(runnable=featurize_task)
try:
with pydra.Submitter(plugin=plugin[0], **plugin_args) as sub:
sub(runnable=featurize_task)
except Exception:
print("Run finished with errors")
else:
print("Run finished successfully")
os.chdir(cwd)
results = featurize_task.result()
results = featurize_task.result(return_inputs=True)
Path(outdir).mkdir(exist_ok=True, parents=True)
for val in results:
shutil.copy(val.output.features[1], Path(outdir))
stored_results = []
for input_params, result in results:
if result.errored:
print(f"File: {input_params['to_features.filename']} errored")
continue
shutil.copy(result.output.features[1], Path(outdir))
if save_figures:
shutil.copy(val.output.features[2], Path(outdir))
shutil.copy(result.output.features[2], Path(outdir))
stored_results.append(Path(outdir) / Path(result.output.features[1]).name)
if dataset:

def gen():
for val in results:
yield torch.load(val.output.features[1])
for val in stored_results:
yield torch.load(val)

print(f"Input: {len(results)} files. Processed: {len(stored_results)}")
to_hf_dataset(gen, Path(outdir) / "hf_dataset")


Expand Down

0 comments on commit 4f54d56

Please sign in to comment.