Skip to content
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

Add pyiron based example #73

Merged
merged 9 commits into from
Mar 14, 2024
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
32 changes: 32 additions & 0 deletions .github/workflows/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -301,3 +301,35 @@ jobs:
with:
name: paper
path: exemplary_workflow/gwl/paper.pdf

run-pyiron:
runs-on: ubuntu-latest

steps:
- name: checkout-repository
uses: actions/checkout@v2

- name: install-basic-deps
uses: ./.github/actions/install-basic-deps

- name: setup-conda-environment
uses: conda-incubator/setup-miniconda@v2
with:
miniforge-version: latest
activate-environment: exemplary_workflow
channels: conda-forge
channel-priority: strict

- name: run-workflow
shell: bash -l {0}
run: |
conda install conda_subprocess=0.0.1 pyiron_base=0.7.11
joergfunger marked this conversation as resolved.
Show resolved Hide resolved
cd $GITHUB_WORKSPACE/exemplary_workflow/pyiron
python workflow.py
- name: upload-paper-artifact
uses: actions/upload-artifact@v2
with:
name: paper
path: ./exemplary_workflow/pyiron/workflow/tectonic_hdf5/tectonic/paper.pdf
retention-days: 1
if-no-files-found: error
22 changes: 22 additions & 0 deletions exemplary_workflow/pyiron/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
# pyiron
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.

## Installation
For more detailed information we refer to the official [documentation](https://pyiron-base.readthedocs.io/en/latest/installation.html).
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.

You can then install `pyiron_base` with
```sh
mamba create -c conda-forge -n pyiron_base pyiron_base=0.7.11 conda_subprocess=0.0.1
```

## Running the exemplary workflow
The workflow can be run with
```sh
python workflow.py
```
The final output `paper.pdf` created using the `tectonic` package is then stored in the working direcrtory of last workflow step:
```sh
./workflow/tectonic_hdf5/tectonic/paper.pdf
```
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.
81 changes: 81 additions & 0 deletions exemplary_workflow/pyiron/workflow.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,81 @@
import os
from pyiron_base import Project

# input parameter
domain_size = 2.0

# create pyiron project
pr = Project("workflow")

# create conda environments for the proprocessing, processing and postprocessing stage
for k, v in {
"preprocessing": "../source/envs/preprocessing.yaml",
"processing": "../source/envs/processing.yaml",
"postprocessing": "../source/envs/postprocessing.yaml"
}.items():
pr.conda_environment.create(env_name=k, env_file=v)
pdiercks marked this conversation as resolved.
Show resolved Hide resolved


# Preprocessing
## generate mesh
gmsh = pr.wrap_executable(
job_name="gmsh",
executable_str=f"gmsh -2 -setnumber domain_size {domain_size} unit_square.geo -o square.msh",
conda_environment_path=pr.conda_environment.preprocessing,
pdiercks marked this conversation as resolved.
Show resolved Hide resolved
input_file_lst=["../source/unit_square.geo"],
execute_job=True,
)

## convert mesh to xdmf
meshio = pr.wrap_executable(
job_name="meshio",
executable_str="meshio convert square.msh square.xdmf",
conda_environment_path=pr.conda_environment.preprocessing,
input_file_lst=[gmsh.files.square_msh],
execute_job=True,
)


# Processing
## poisson
def collect_output_poisson(working_directory):
with open(os.path.join(working_directory, "numdofs.txt"), "r") as f:
return {"numdofs": int(f.read())}

poisson = pr.wrap_executable(
job_name="poisson",
executable_str="python poisson.py --mesh square.xdmf --degree 2 --outputfile poisson.pvd --num-dofs numdofs.txt",
pdiercks marked this conversation as resolved.
Show resolved Hide resolved
collect_output_funct=collect_output_poisson,
conda_environment_path=pr.conda_environment.processing,
input_file_lst=["../source/poisson.py", meshio.files.square_xdmf, meshio.files.square_h5],
execute_job=True,
)


# Postprocessing
## plot over line
pvbatch = pr.wrap_executable(
job_name="pvbatch",
executable_str="pvbatch postprocessing.py poisson.pvd plotoverline.csv",
conda_environment_path=pr.conda_environment.postprocessing,
input_file_lst=["../source/postprocessing.py", poisson.files.poisson_pvd, poisson.files.poisson000000_vtu],
execute_job=True,
)

## substitute macros
macros = pr.wrap_executable(
job_name="macros",
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",
conda_environment_path=pr.conda_environment.postprocessing,
input_file_lst=["../source/macros.tex.template", "../source/prepare_paper_macros.py", pvbatch.files.plotoverline_csv],
execute_job=True,
)

## compile paper
tectonic = pr.wrap_executable(
job_name="tectonic",
executable_str="tectonic paper.tex",
conda_environment_path=pr.conda_environment.postprocessing,
input_file_lst=["../source/paper.tex", macros.files.macros_tex, pvbatch.files.plotoverline_csv],
execute_job=True,
)
Loading