pyiron#

BAMresearch/NFDI4IngScientificWorkflowRequirements

Define workflow with pyiron_base#

import os
from workflow import (
    generate_mesh as _generate_mesh, 
    convert_to_xdmf as _convert_to_xdmf,
    poisson as _poisson,
    plot_over_line as _plot_over_line,
    substitute_macros as _substitute_macros,
    compile_paper as _compile_paper,
)
from pyiron_base import job

from python_workflow_definition.pyiron_base import write_workflow_json
generate_mesh = job(_generate_mesh)
convert_to_xdmf = job(_convert_to_xdmf, output_key_lst=["xdmf_file", "h5_file"])
poisson = job(_poisson, output_key_lst=["numdofs", "pvd_file", "vtu_file"])
plot_over_line = job(_plot_over_line)
substitute_macros = job(_substitute_macros)
compile_paper = job(_compile_paper)
domain_size = 2.0
source_directory = os.path.abspath(os.path.join(os.curdir, "source"))
gmsh_output_file = generate_mesh(
    domain_size=domain_size,
    source_directory=source_directory,
)
meshio_output_dict = convert_to_xdmf(
    gmsh_output_file=gmsh_output_file,
)
poisson_dict = poisson(
    meshio_output_xdmf=meshio_output_dict.output.xdmf_file, 
    meshio_output_h5=meshio_output_dict.output.h5_file,
    source_directory=source_directory,
)
pvbatch_output_file = plot_over_line(
    poisson_output_pvd_file=poisson_dict.output.pvd_file, 
    poisson_output_vtu_file=poisson_dict.output.vtu_file,
    source_directory=source_directory,
)
macros_tex_file = substitute_macros( 
    pvbatch_output_file=pvbatch_output_file, 
    ndofs=poisson_dict.output.numdofs, 
    domain_size=domain_size,
    source_directory=source_directory,
)
paper_output = compile_paper(
    macros_tex=macros_tex_file, 
    plot_file=pvbatch_output_file,
    source_directory=source_directory,
)
workflow_json_filename = "pyiron_base_nfdi.json"
write_workflow_json(delayed_object=paper_output, file_name=workflow_json_filename)

Load Workflow with aiida#

from aiida import load_profile

load_profile()
Profile<uuid='3ce302a995914d2e8a7b6327a10fe381' name='pwd'>
from python_workflow_definition.aiida import load_workflow_json
wg = load_workflow_json(file_name=workflow_json_filename)
wg
wg.run()
05/24/2025 05:45:10 AM <4326> aiida.orm.nodes.process.workflow.workchain.WorkChainNode: [REPORT] [81|WorkGraphEngine|continue_workgraph]: tasks ready to run: generate_mesh6
05/24/2025 05:45:12 AM <4326> aiida.orm.nodes.process.workflow.workchain.WorkChainNode: [REPORT] [81|WorkGraphEngine|update_task_state]: Task: generate_mesh6, type: PyFunction, finished.
05/24/2025 05:45:12 AM <4326> aiida.orm.nodes.process.workflow.workchain.WorkChainNode: [REPORT] [81|WorkGraphEngine|continue_workgraph]: tasks ready to run: convert_to_xdmf5
05/24/2025 05:45:13 AM <4326> aiida.orm.nodes.process.workflow.workchain.WorkChainNode: [REPORT] [81|WorkGraphEngine|update_task_state]: Task: convert_to_xdmf5, type: PyFunction, finished.
05/24/2025 05:45:13 AM <4326> aiida.orm.nodes.process.workflow.workchain.WorkChainNode: [REPORT] [81|WorkGraphEngine|continue_workgraph]: tasks ready to run: poisson4
05/24/2025 05:45:16 AM <4326> aiida.orm.nodes.process.workflow.workchain.WorkChainNode: [REPORT] [81|WorkGraphEngine|update_task_state]: Task: poisson4, type: PyFunction, finished.
05/24/2025 05:45:16 AM <4326> aiida.orm.nodes.process.workflow.workchain.WorkChainNode: [REPORT] [81|WorkGraphEngine|continue_workgraph]: tasks ready to run: plot_over_line3
05/24/2025 05:45:18 AM <4326> aiida.orm.nodes.process.workflow.workchain.WorkChainNode: [REPORT] [81|WorkGraphEngine|update_task_state]: Task: plot_over_line3, type: PyFunction, finished.
05/24/2025 05:45:18 AM <4326> aiida.orm.nodes.process.workflow.workchain.WorkChainNode: [REPORT] [81|WorkGraphEngine|continue_workgraph]: tasks ready to run: substitute_macros2
05/24/2025 05:45:20 AM <4326> aiida.orm.nodes.process.workflow.workchain.WorkChainNode: [REPORT] [81|WorkGraphEngine|update_task_state]: Task: substitute_macros2, type: PyFunction, finished.
05/24/2025 05:45:20 AM <4326> aiida.orm.nodes.process.workflow.workchain.WorkChainNode: [REPORT] [81|WorkGraphEngine|continue_workgraph]: tasks ready to run: compile_paper1
05/24/2025 05:45:22 AM <4326> aiida.orm.nodes.process.workflow.workchain.WorkChainNode: [REPORT] [81|WorkGraphEngine|update_task_state]: Task: compile_paper1, type: PyFunction, finished.
05/24/2025 05:45:22 AM <4326> aiida.orm.nodes.process.workflow.workchain.WorkChainNode: [REPORT] [81|WorkGraphEngine|continue_workgraph]: tasks ready to run: 
05/24/2025 05:45:22 AM <4326> aiida.orm.nodes.process.workflow.workchain.WorkChainNode: [REPORT] [81|WorkGraphEngine|finalize]: Finalize workgraph.

Load Workflow with jobflow#

from python_workflow_definition.jobflow import load_workflow_json
from jobflow.managers.local import run_locally
flow = load_workflow_json(file_name=workflow_json_filename)
result = run_locally(flow)
result
2025-05-24 05:45:23,211 INFO Started executing jobs locally
2025-05-24 05:45:23,487 INFO Starting job - generate_mesh (afd8b83e-2283-40e8-9a75-4553a7ca72d0)
2025-05-24 05:45:24,604 INFO Finished job - generate_mesh (afd8b83e-2283-40e8-9a75-4553a7ca72d0)
2025-05-24 05:45:24,605 INFO Starting job - convert_to_xdmf (6723daca-18b6-4f38-8b3e-a92c2a227dc3)
2025-05-24 05:45:26,001 INFO Finished job - convert_to_xdmf (6723daca-18b6-4f38-8b3e-a92c2a227dc3)
2025-05-24 05:45:26,002 INFO Starting job - poisson (db43f907-45eb-4596-ac6b-ab5978cc5e17)
2025-05-24 05:45:28,507 INFO Finished job - poisson (db43f907-45eb-4596-ac6b-ab5978cc5e17)
2025-05-24 05:45:28,509 INFO Starting job - plot_over_line (b6493a73-f134-4067-ba0d-d6e2cd246afe)
2025-05-24 05:45:29,933 INFO Finished job - plot_over_line (b6493a73-f134-4067-ba0d-d6e2cd246afe)
2025-05-24 05:45:29,934 INFO Starting job - substitute_macros (65c3db44-dcc1-44ca-a1bb-374e8f5c771e)
2025-05-24 05:45:30,774 INFO Finished job - substitute_macros (65c3db44-dcc1-44ca-a1bb-374e8f5c771e)
2025-05-24 05:45:30,775 INFO Starting job - compile_paper (84277487-0e26-444b-92dc-4516ae8a4eba)
2025-05-24 05:45:32,790 INFO Finished job - compile_paper (84277487-0e26-444b-92dc-4516ae8a4eba)
2025-05-24 05:45:32,791 INFO Finished executing jobs locally
{'afd8b83e-2283-40e8-9a75-4553a7ca72d0': {1: Response(output='/home/jovyan/example_workflows/nfdi/preprocessing/square.msh', detour=None, addition=None, replace=None, stored_data=None, stop_children=False, stop_jobflow=False, job_dir=PosixPath('/home/jovyan/example_workflows/nfdi'))},
 '6723daca-18b6-4f38-8b3e-a92c2a227dc3': {1: Response(output={'xdmf_file': '/home/jovyan/example_workflows/nfdi/preprocessing/square.xdmf', 'h5_file': '/home/jovyan/example_workflows/nfdi/preprocessing/square.h5'}, detour=None, addition=None, replace=None, stored_data=None, stop_children=False, stop_jobflow=False, job_dir=PosixPath('/home/jovyan/example_workflows/nfdi'))},
 'db43f907-45eb-4596-ac6b-ab5978cc5e17': {1: Response(output={'numdofs': 357, 'pvd_file': '/home/jovyan/example_workflows/nfdi/processing/poisson.pvd', 'vtu_file': '/home/jovyan/example_workflows/nfdi/processing/poisson000000.vtu'}, detour=None, addition=None, replace=None, stored_data=None, stop_children=False, stop_jobflow=False, job_dir=PosixPath('/home/jovyan/example_workflows/nfdi'))},
 'b6493a73-f134-4067-ba0d-d6e2cd246afe': {1: Response(output='/home/jovyan/example_workflows/nfdi/postprocessing/plotoverline.csv', detour=None, addition=None, replace=None, stored_data=None, stop_children=False, stop_jobflow=False, job_dir=PosixPath('/home/jovyan/example_workflows/nfdi'))},
 '65c3db44-dcc1-44ca-a1bb-374e8f5c771e': {1: Response(output='/home/jovyan/example_workflows/nfdi/postprocessing/macros.tex', detour=None, addition=None, replace=None, stored_data=None, stop_children=False, stop_jobflow=False, job_dir=PosixPath('/home/jovyan/example_workflows/nfdi'))},
 '84277487-0e26-444b-92dc-4516ae8a4eba': {1: Response(output='/home/jovyan/example_workflows/nfdi/postprocessing/paper.pdf', detour=None, addition=None, replace=None, stored_data=None, stop_children=False, stop_jobflow=False, job_dir=PosixPath('/home/jovyan/example_workflows/nfdi'))}}