Skip to content

NFDI: provide source path as external variable #99

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 6 commits into from
May 14, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
364 changes: 1 addition & 363 deletions example_workflows/nfdi/aiida.ipynb

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion example_workflows/nfdi/jobflow.ipynb

Large diffs are not rendered by default.

313 changes: 1 addition & 312 deletions example_workflows/nfdi/pyiron_base.ipynb

Large diffs are not rendered by default.

10 changes: 8 additions & 2 deletions example_workflows/nfdi/workflow.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,20 +7,26 @@
{"id": 4, "type": "function", "value": "workflow.substitute_macros"},
{"id": 5, "type": "function", "value": "workflow.compile_paper"},
{"id": 6, "type": "input", "value": 2.0, "name": "domain_size"},
{"id": 7, "type": "output", "name": "result"}
{"id": 7, "type": "input", "value": "source", "name": "source_directory"},
{"id": 8, "type": "output", "name": "result"}
],
"edges": [
{"target": 0, "targetPort": "domain_size", "source": 6, "sourcePort": null},
{"target": 0, "targetPort": "source_directory", "source": 7, "sourcePort": null},
{"target": 1, "targetPort": "gmsh_output_file", "source": 0, "sourcePort": null},
{"target": 2, "targetPort": "meshio_output_xdmf", "source": 1, "sourcePort": "xdmf_file"},
{"target": 2, "targetPort": "meshio_output_h5", "source": 1, "sourcePort": "h5_file"},
{"target": 2, "targetPort": "source_directory", "source": 7, "sourcePort": null},
{"target": 3, "targetPort": "poisson_output_pvd_file", "source": 2, "sourcePort": "pvd_file"},
{"target": 3, "targetPort": "poisson_output_vtu_file", "source": 2, "sourcePort": "vtu_file"},
{"target": 3, "targetPort": "source_directory", "source": 7, "sourcePort": null},
{"target": 4, "targetPort": "pvbatch_output_file", "source": 3, "sourcePort": null},
{"target": 4, "targetPort": "ndofs", "source": 2, "sourcePort": "numdofs"},
{"target": 4, "targetPort": "domain_size", "source": 6, "sourcePort": null},
{"target": 4, "targetPort": "source_directory", "source": 7, "sourcePort": null},
{"target": 5, "targetPort": "macros_tex", "source": 4, "sourcePort": null},
{"target": 5, "targetPort": "plot_file", "source": 3, "sourcePort": null},
{"target": 7, "targetPort": null, "source": 5, "sourcePort": null}
{"target": 5, "targetPort": "source_directory", "source": 7, "sourcePort": null},
{"target": 8, "targetPort": null, "source": 5, "sourcePort": null}
]
}
30 changes: 14 additions & 16 deletions example_workflows/nfdi/workflow.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,15 +2,13 @@
from conda_subprocess import check_output
import shutil

source_directory = os.path.join(os.path.dirname(os.path.abspath(__file__)), "source")


def generate_mesh(domain_size: float = 2.0) -> str:
def generate_mesh(domain_size: float, source_directory: str) -> str:
stage_name = "preprocessing"
gmsh_output_file_name = "square.msh"
source_file_name ="unit_square.geo"
os.makedirs(stage_name, exist_ok=True)
_copy_file_from_source(stage_name=stage_name, source_file_name=source_file_name)
_copy_file_from_source(stage_name=stage_name, source_file_name=source_file_name, source_directory=source_directory)
_ = check_output(
[
"gmsh", "-2", "-setnumber", "domain_size", str(domain_size),
Expand Down Expand Up @@ -40,13 +38,13 @@ def convert_to_xdmf(gmsh_output_file : str) -> dict:
}


def poisson(meshio_output_xdmf: str, meshio_output_h5: str) -> dict:
def poisson(meshio_output_xdmf: str, meshio_output_h5: str, source_directory: str) -> dict:
stage_name = "processing"
poisson_output_pvd_file_name = "poisson.pvd"
poisson_output_numdofs_file_name = "numdofs.txt"
source_file_name = "poisson.py"
os.makedirs(stage_name, exist_ok=True)
_copy_file_from_source(stage_name=stage_name, source_file_name=source_file_name)
_copy_file_from_source(stage_name=stage_name, source_file_name=source_file_name, source_directory=source_directory)
_copy_file(stage_name=stage_name, source_file=meshio_output_xdmf)
_copy_file(stage_name=stage_name, source_file=meshio_output_h5)
_ = check_output(
Expand All @@ -65,12 +63,12 @@ def poisson(meshio_output_xdmf: str, meshio_output_h5: str) -> dict:
}


def plot_over_line(poisson_output_pvd_file: str, poisson_output_vtu_file: str) -> str:
def plot_over_line(poisson_output_pvd_file: str, poisson_output_vtu_file: str, source_directory: str) -> str:
stage_name = "postprocessing"
pvbatch_output_file_name = "plotoverline.csv"
source_file_name = "postprocessing.py"
os.makedirs(stage_name, exist_ok=True)
_copy_file_from_source(stage_name=stage_name, source_file_name=source_file_name)
_copy_file_from_source(stage_name=stage_name, source_file_name=source_file_name, source_directory=source_directory)
_copy_file(stage_name=stage_name, source_file=poisson_output_pvd_file)
_copy_file(stage_name=stage_name, source_file=poisson_output_vtu_file)
_ = check_output(
Expand All @@ -82,14 +80,14 @@ def plot_over_line(poisson_output_pvd_file: str, poisson_output_vtu_file: str) -
return os.path.abspath(os.path.join("postprocessing", pvbatch_output_file_name))


def substitute_macros(pvbatch_output_file: str, ndofs: int, domain_size: float = 2.0) -> str:
def substitute_macros(pvbatch_output_file: str, ndofs: int, domain_size: float, source_directory: str) -> str:
stage_name = "postprocessing"
source_file_name = "prepare_paper_macros.py"
template_file_name = "macros.tex.template"
macros_output_file_name = "macros.tex"
os.makedirs(stage_name, exist_ok=True)
_copy_file_from_source(stage_name=stage_name, source_file_name=source_file_name)
_copy_file_from_source(stage_name=stage_name, source_file_name=template_file_name)
_copy_file_from_source(stage_name=stage_name, source_file_name=source_file_name, source_directory=source_directory)
_copy_file_from_source(stage_name=stage_name, source_file_name=template_file_name, source_directory=source_directory)
_copy_file(stage_name=stage_name, source_file=pvbatch_output_file)
_ = check_output(
[
Expand All @@ -104,12 +102,12 @@ def substitute_macros(pvbatch_output_file: str, ndofs: int, domain_size: float =
return os.path.abspath(os.path.join(stage_name, macros_output_file_name))


def compile_paper(macros_tex: str, plot_file: str) -> str:
def compile_paper(macros_tex: str, plot_file: str, source_directory: str) -> str:
stage_name = "postprocessing"
paper_output = "paper.pdf"
source_file_name = "paper.tex"
os.makedirs(stage_name, exist_ok=True)
_copy_file_from_source(stage_name=stage_name, source_file_name=source_file_name)
_copy_file_from_source(stage_name=stage_name, source_file_name=source_file_name, source_directory=source_directory)
_copy_file(stage_name=stage_name, source_file=macros_tex)
_copy_file(stage_name=stage_name, source_file=plot_file)
_ = check_output(
Expand All @@ -126,12 +124,12 @@ def _poisson_collect_output(numdofs_file: str) -> int:
return int(f.read())


def _copy_file(stage_name, source_file):
def _copy_file(stage_name: str, source_file: str):
input_file = os.path.join(os.path.abspath(stage_name), os.path.basename(source_file))
if input_file != source_file:
shutil.copyfile(source_file, input_file)


def _copy_file_from_source(stage_name, source_file_name):
def _copy_file_from_source(stage_name: str, source_file_name: str, source_directory: str):
source_file = os.path.join(source_directory, source_file_name)
shutil.copyfile(source_file, os.path.join(stage_name, source_file_name))
shutil.copyfile(source_file, os.path.join(stage_name, source_file_name))
Loading