Skip to content

Commit 2efbdf1

Browse files
authored
Use conda_subprocess in NFDI example (#50)
1 parent 299d789 commit 2efbdf1

File tree

2 files changed

+24
-19
lines changed

2 files changed

+24
-19
lines changed

environment.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,3 +6,4 @@ dependencies:
66
- pyiron_base=0.11.8
77
- pygraphviz=1.14
88
- aiida-workgraph=0.5.1
9+
- conda_subprocess =0.0.6

nfdi_ing_workflow.py

Lines changed: 23 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import os
2-
import subprocess
2+
from conda_subprocess import check_output
33
import shutil
44

55
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:
1111
source_file_name ="unit_square.geo"
1212
os.makedirs(stage_name, exist_ok=True)
1313
_copy_file_from_source(stage_name=stage_name, source_file_name=source_file_name)
14-
_ = subprocess.check_output(
14+
_ = check_output(
1515
[
16-
"conda", "run", "-n", stage_name, "gmsh", "-2", "-setnumber",
17-
"domain_size", str(domain_size), source_file_name, "-o", gmsh_output_file_name
16+
"gmsh", "-2", "-setnumber", "domain_size", str(domain_size),
17+
source_file_name, "-o", gmsh_output_file_name
1818
],
19+
prefix_name=stage_name,
1920
cwd=stage_name,
2021
universal_newlines=True,
2122
).split("\n")
2223
return os.path.abspath(os.path.join(stage_name, gmsh_output_file_name))
2324

2425

25-
def convert_to_xdmf(gmsh_output_file : str) -> str:
26+
def convert_to_xdmf(gmsh_output_file : str) -> dict:
2627
stage_name = "preprocessing"
2728
meshio_output_file_name = "square.xdmf"
2829
os.makedirs(stage_name, exist_ok=True)
2930
_copy_file(stage_name=stage_name, source_file=gmsh_output_file)
30-
_ = subprocess.check_output(
31-
["conda", "run", "-n", stage_name, "meshio", "convert", os.path.basename(gmsh_output_file), meshio_output_file_name],
31+
_ = check_output(
32+
["meshio", "convert", os.path.basename(gmsh_output_file), meshio_output_file_name],
33+
prefix_name=stage_name,
3234
cwd=stage_name,
3335
universal_newlines=True,
3436
).split("\n")
@@ -47,12 +49,12 @@ def poisson(meshio_output_xdmf: str, meshio_output_h5: str) -> dict:
4749
_copy_file_from_source(stage_name=stage_name, source_file_name=source_file_name)
4850
_copy_file(stage_name=stage_name, source_file=meshio_output_xdmf)
4951
_copy_file(stage_name=stage_name, source_file=meshio_output_h5)
50-
_ = subprocess.check_output(
52+
_ = check_output(
5153
[
52-
"conda", "run", "-n", stage_name, "python", "poisson.py",
53-
"--mesh", os.path.basename(meshio_output_xdmf), "--degree", "2",
54+
"python", "poisson.py", "--mesh", os.path.basename(meshio_output_xdmf), "--degree", "2",
5455
"--outputfile", poisson_output_pvd_file_name, "--num-dofs", poisson_output_numdofs_file_name
5556
],
57+
prefix_name=stage_name,
5658
cwd=stage_name,
5759
universal_newlines=True,
5860
).split("\n")
@@ -71,8 +73,9 @@ def plot_over_line(poisson_output_pvd_file: str, poisson_output_vtu_file: str) -
7173
_copy_file_from_source(stage_name=stage_name, source_file_name=source_file_name)
7274
_copy_file(stage_name=stage_name, source_file=poisson_output_pvd_file)
7375
_copy_file(stage_name=stage_name, source_file=poisson_output_vtu_file)
74-
_ = subprocess.check_output(
75-
["conda", "run", "-n", stage_name, "pvbatch", source_file_name, os.path.basename(poisson_output_pvd_file), pvbatch_output_file_name],
76+
_ = check_output(
77+
["pvbatch", source_file_name, os.path.basename(poisson_output_pvd_file), pvbatch_output_file_name],
78+
prefix_name=stage_name,
7679
cwd=stage_name,
7780
universal_newlines=True,
7881
).split("\n")
@@ -88,13 +91,13 @@ def substitute_macros(pvbatch_output_file: str, ndofs: int, domain_size: float =
8891
_copy_file_from_source(stage_name=stage_name, source_file_name=source_file_name)
8992
_copy_file_from_source(stage_name=stage_name, source_file_name=template_file_name)
9093
_copy_file(stage_name=stage_name, source_file=pvbatch_output_file)
91-
_ = subprocess.check_output(
94+
_ = check_output(
9295
[
93-
"conda", "run", "-n", stage_name, "python", "prepare_paper_macros.py",
94-
"--macro-template-file", template_file_name, "--plot-data-path", os.path.basename(pvbatch_output_file),
95-
"--domain-size", str(domain_size), "--num-dofs", str(ndofs),
96-
"--output-macro-file", macros_output_file_name,
96+
"python", "prepare_paper_macros.py", "--macro-template-file", template_file_name,
97+
"--plot-data-path", os.path.basename(pvbatch_output_file), "--domain-size", str(domain_size),
98+
"--num-dofs", str(ndofs), "--output-macro-file", macros_output_file_name,
9799
],
100+
prefix_name=stage_name,
98101
cwd=stage_name,
99102
universal_newlines=True,
100103
).split("\n")
@@ -109,8 +112,9 @@ def compile_paper(macros_tex: str, plot_file: str) -> str:
109112
_copy_file_from_source(stage_name=stage_name, source_file_name=source_file_name)
110113
_copy_file(stage_name=stage_name, source_file=macros_tex)
111114
_copy_file(stage_name=stage_name, source_file=plot_file)
112-
_ = subprocess.check_output(
113-
["conda", "run", "-n", stage_name, "tectonic", source_file_name],
115+
_ = check_output(
116+
["tectonic", source_file_name],
117+
prefix_name=stage_name,
114118
universal_newlines=True,
115119
cwd=stage_name,
116120
).split("\n")

0 commit comments

Comments
 (0)