From 405181a28436dedc26e795798a132f8863270142 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jan=20Jan=C3=9Fen?= Date: Sun, 6 Apr 2025 11:46:55 +0200 Subject: [PATCH] Use conda_subprocess in NFDI example --- environment.yml | 1 + nfdi_ing_workflow.py | 42 +++++++++++++++++++++++------------------- 2 files changed, 24 insertions(+), 19 deletions(-) diff --git a/environment.yml b/environment.yml index f974f2a..5f7edb0 100644 --- a/environment.yml +++ b/environment.yml @@ -6,3 +6,4 @@ dependencies: - pyiron_base=0.11.8 - pygraphviz=1.14 - aiida-workgraph=0.5.1 +- conda_subprocess =0.0.6 diff --git a/nfdi_ing_workflow.py b/nfdi_ing_workflow.py index 254e73b..3893a38 100644 --- a/nfdi_ing_workflow.py +++ b/nfdi_ing_workflow.py @@ -1,5 +1,5 @@ import os -import subprocess +from conda_subprocess import check_output import shutil source_directory = os.path.join(os.path.dirname(os.path.abspath(__file__)), "source") @@ -11,24 +11,26 @@ def generate_mesh(domain_size: float = 2.0) -> str: 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) - _ = subprocess.check_output( + _ = check_output( [ - "conda", "run", "-n", stage_name, "gmsh", "-2", "-setnumber", - "domain_size", str(domain_size), source_file_name, "-o", gmsh_output_file_name + "gmsh", "-2", "-setnumber", "domain_size", str(domain_size), + source_file_name, "-o", gmsh_output_file_name ], + prefix_name=stage_name, cwd=stage_name, universal_newlines=True, ).split("\n") return os.path.abspath(os.path.join(stage_name, gmsh_output_file_name)) -def convert_to_xdmf(gmsh_output_file : str) -> str: +def convert_to_xdmf(gmsh_output_file : str) -> dict: stage_name = "preprocessing" meshio_output_file_name = "square.xdmf" os.makedirs(stage_name, exist_ok=True) _copy_file(stage_name=stage_name, source_file=gmsh_output_file) - _ = subprocess.check_output( - ["conda", "run", "-n", stage_name, "meshio", "convert", os.path.basename(gmsh_output_file), meshio_output_file_name], + _ = check_output( + ["meshio", "convert", os.path.basename(gmsh_output_file), meshio_output_file_name], + prefix_name=stage_name, cwd=stage_name, universal_newlines=True, ).split("\n") @@ -47,12 +49,12 @@ def poisson(meshio_output_xdmf: str, meshio_output_h5: str) -> dict: _copy_file_from_source(stage_name=stage_name, source_file_name=source_file_name) _copy_file(stage_name=stage_name, source_file=meshio_output_xdmf) _copy_file(stage_name=stage_name, source_file=meshio_output_h5) - _ = subprocess.check_output( + _ = check_output( [ - "conda", "run", "-n", stage_name, "python", "poisson.py", - "--mesh", os.path.basename(meshio_output_xdmf), "--degree", "2", + "python", "poisson.py", "--mesh", os.path.basename(meshio_output_xdmf), "--degree", "2", "--outputfile", poisson_output_pvd_file_name, "--num-dofs", poisson_output_numdofs_file_name ], + prefix_name=stage_name, cwd=stage_name, universal_newlines=True, ).split("\n") @@ -71,8 +73,9 @@ def plot_over_line(poisson_output_pvd_file: str, poisson_output_vtu_file: str) - _copy_file_from_source(stage_name=stage_name, source_file_name=source_file_name) _copy_file(stage_name=stage_name, source_file=poisson_output_pvd_file) _copy_file(stage_name=stage_name, source_file=poisson_output_vtu_file) - _ = subprocess.check_output( - ["conda", "run", "-n", stage_name, "pvbatch", source_file_name, os.path.basename(poisson_output_pvd_file), pvbatch_output_file_name], + _ = check_output( + ["pvbatch", source_file_name, os.path.basename(poisson_output_pvd_file), pvbatch_output_file_name], + prefix_name=stage_name, cwd=stage_name, universal_newlines=True, ).split("\n") @@ -88,13 +91,13 @@ def substitute_macros(pvbatch_output_file: str, ndofs: int, domain_size: float = _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(stage_name=stage_name, source_file=pvbatch_output_file) - _ = subprocess.check_output( + _ = check_output( [ - "conda", "run", "-n", stage_name, "python", "prepare_paper_macros.py", - "--macro-template-file", template_file_name, "--plot-data-path", os.path.basename(pvbatch_output_file), - "--domain-size", str(domain_size), "--num-dofs", str(ndofs), - "--output-macro-file", macros_output_file_name, + "python", "prepare_paper_macros.py", "--macro-template-file", template_file_name, + "--plot-data-path", os.path.basename(pvbatch_output_file), "--domain-size", str(domain_size), + "--num-dofs", str(ndofs), "--output-macro-file", macros_output_file_name, ], + prefix_name=stage_name, cwd=stage_name, universal_newlines=True, ).split("\n") @@ -109,8 +112,9 @@ def compile_paper(macros_tex: str, plot_file: str) -> str: _copy_file_from_source(stage_name=stage_name, source_file_name=source_file_name) _copy_file(stage_name=stage_name, source_file=macros_tex) _copy_file(stage_name=stage_name, source_file=plot_file) - _ = subprocess.check_output( - ["conda", "run", "-n", stage_name, "tectonic", source_file_name], + _ = check_output( + ["tectonic", source_file_name], + prefix_name=stage_name, universal_newlines=True, cwd=stage_name, ).split("\n")