Skip to content

Commit 652d7c3

Browse files
Add pyiron based example (BAMresearch#73)
* Add pyiron based example * Add conda_subprocess as dependency * remove empty lines * Update source path * Add Readme * rename functions * Update exemplary_workflow/pyiron/README.md Co-authored-by: Philipp Diercks <[email protected]> * Add explanation about storage in the README * Use f-strings to call executables --------- Co-authored-by: Philipp Diercks <[email protected]>
1 parent 3c6ff77 commit 652d7c3

File tree

3 files changed

+135
-0
lines changed

3 files changed

+135
-0
lines changed

.github/workflows/main.yml

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -301,3 +301,35 @@ jobs:
301301
with:
302302
name: paper
303303
path: exemplary_workflow/gwl/paper.pdf
304+
305+
run-pyiron:
306+
runs-on: ubuntu-latest
307+
308+
steps:
309+
- name: checkout-repository
310+
uses: actions/checkout@v2
311+
312+
- name: install-basic-deps
313+
uses: ./.github/actions/install-basic-deps
314+
315+
- name: setup-conda-environment
316+
uses: conda-incubator/setup-miniconda@v2
317+
with:
318+
miniforge-version: latest
319+
activate-environment: exemplary_workflow
320+
channels: conda-forge
321+
channel-priority: strict
322+
323+
- name: run-workflow
324+
shell: bash -l {0}
325+
run: |
326+
conda install conda_subprocess=0.0.1 pyiron_base=0.7.11
327+
cd $GITHUB_WORKSPACE/exemplary_workflow/pyiron
328+
python workflow.py
329+
- name: upload-paper-artifact
330+
uses: actions/upload-artifact@v2
331+
with:
332+
name: paper
333+
path: ./exemplary_workflow/pyiron/workflow/tectonic_hdf5/tectonic/paper.pdf
334+
retention-days: 1
335+
if-no-files-found: error
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
# pyiron
2+
This directory contains an implementation of the exemplary workflow with [pyiron](https://pyiron.org/) or more specifically the [pyiron_base](https://pyiron-base.readthedocs.io) workflow manager.
3+
4+
## Installation
5+
For more detailed information we refer to the official [documentation](https://pyiron-base.readthedocs.io/en/latest/installation.html).
6+
The recommended way of installing `pyiron_base` is via conda, because it also enables `pyiron_base` to handle software dependencies of your workflow using the [conda_subprocess](https://github.com/pyiron/conda_subprocess) package.
7+
8+
You can then install `pyiron_base` with
9+
```sh
10+
mamba create -c conda-forge -n pyiron_base pyiron_base=0.7.11 conda_subprocess=0.0.1
11+
```
12+
13+
## Running the exemplary workflow
14+
The workflow can be run with
15+
```sh
16+
python workflow.py
17+
```
18+
The final output `paper.pdf` created using the `tectonic` package is then stored in the working direcrtory of last workflow step:
19+
```sh
20+
./workflow/tectonic_hdf5/tectonic/paper.pdf
21+
```
22+
This is a general feature of the `pyiron_base` workflow manager, each step of the workflow - called job - is executed in a separate working directory.
Lines changed: 81 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,81 @@
1+
import os
2+
from pyiron_base import Project
3+
4+
# input parameter
5+
domain_size = 2.0
6+
7+
# create pyiron project
8+
pr = Project("workflow")
9+
10+
# create conda environments for the proprocessing, processing and postprocessing stage
11+
for k, v in {
12+
"preprocessing": "../source/envs/preprocessing.yaml",
13+
"processing": "../source/envs/processing.yaml",
14+
"postprocessing": "../source/envs/postprocessing.yaml"
15+
}.items():
16+
pr.conda_environment.create(env_name=k, env_file=v)
17+
18+
19+
# Preprocessing
20+
## generate mesh
21+
gmsh = pr.wrap_executable(
22+
job_name="gmsh",
23+
executable_str=f"gmsh -2 -setnumber domain_size {domain_size} unit_square.geo -o square.msh",
24+
conda_environment_path=pr.conda_environment.preprocessing,
25+
input_file_lst=["../source/unit_square.geo"],
26+
execute_job=True,
27+
)
28+
29+
## convert mesh to xdmf
30+
meshio = pr.wrap_executable(
31+
job_name="meshio",
32+
executable_str="meshio convert square.msh square.xdmf",
33+
conda_environment_path=pr.conda_environment.preprocessing,
34+
input_file_lst=[gmsh.files.square_msh],
35+
execute_job=True,
36+
)
37+
38+
39+
# Processing
40+
## poisson
41+
def collect_output_poisson(working_directory):
42+
with open(os.path.join(working_directory, "numdofs.txt"), "r") as f:
43+
return {"numdofs": int(f.read())}
44+
45+
poisson = pr.wrap_executable(
46+
job_name="poisson",
47+
executable_str="python poisson.py --mesh square.xdmf --degree 2 --outputfile poisson.pvd --num-dofs numdofs.txt",
48+
collect_output_funct=collect_output_poisson,
49+
conda_environment_path=pr.conda_environment.processing,
50+
input_file_lst=["../source/poisson.py", meshio.files.square_xdmf, meshio.files.square_h5],
51+
execute_job=True,
52+
)
53+
54+
55+
# Postprocessing
56+
## plot over line
57+
pvbatch = pr.wrap_executable(
58+
job_name="pvbatch",
59+
executable_str="pvbatch postprocessing.py poisson.pvd plotoverline.csv",
60+
conda_environment_path=pr.conda_environment.postprocessing,
61+
input_file_lst=["../source/postprocessing.py", poisson.files.poisson_pvd, poisson.files.poisson000000_vtu],
62+
execute_job=True,
63+
)
64+
65+
## substitute macros
66+
macros = pr.wrap_executable(
67+
job_name="macros",
68+
executable_str=f"python prepare_paper_macros.py --macro-template-file macros.tex.template --plot-data-path plotoverline.csv --domain-size {domain_size} --num-dofs {poisson.output['numdofs']} --output-macro-file macros.tex",
69+
conda_environment_path=pr.conda_environment.postprocessing,
70+
input_file_lst=["../source/macros.tex.template", "../source/prepare_paper_macros.py", pvbatch.files.plotoverline_csv],
71+
execute_job=True,
72+
)
73+
74+
## compile paper
75+
tectonic = pr.wrap_executable(
76+
job_name="tectonic",
77+
executable_str="tectonic paper.tex",
78+
conda_environment_path=pr.conda_environment.postprocessing,
79+
input_file_lst=["../source/paper.tex", macros.files.macros_tex, pvbatch.files.plotoverline_csv],
80+
execute_job=True,
81+
)

0 commit comments

Comments
 (0)