Skip to content

provenance creation for snakemake and nextflow workflows #20

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 23 commits into from
Aug 19, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
23 commits
Select commit Hold shift + click to select a range
6c9025f
provenance creation for snakemake and nextflow workflows
Aug 6, 2025
b64262e
edited run-benchmark.yml
Aug 6, 2025
c48c38e
update snakemake workflow for linear elastic benchmark
joergfunger Aug 14, 2025
99acd43
formating
joergfunger Aug 15, 2025
80cbe47
Merge branch 'main' into creation-of-nextflow-workflow
joergfunger Aug 15, 2025
ac7ad66
updated the ci action file, fix typos there
joergfunger Aug 15, 2025
8c217b8
fix env
joergfunger Aug 15, 2025
2d9cd85
fix bug for file patterns
joergfunger Aug 15, 2025
75f1bf4
first call snakemake and then the reporter afterwards
joergfunger Aug 15, 2025
3f336ac
fix typo
joergfunger Aug 15, 2025
c2e395a
fix typo
joergfunger Aug 15, 2025
736932f
make the output depending on the tool as a wildcard, only the simulat…
joergfunger Aug 15, 2025
1ce8bba
revert hdf5 storage to just store a zipped version of all simulation …
joergfunger Aug 15, 2025
f2fd32f
Update benchmarks/linear-elastic-plate-with-hole/FEniCS/plateWithHole…
joergfunger Aug 18, 2025
c1d9537
Update benchmarks/linear-elastic-plate-with-hole/FEniCS/plateWithHole…
joergfunger Aug 18, 2025
054eb5a
Update benchmarks/linear-elastic-plate-with-hole/FEniCS/plateWithHole…
joergfunger Aug 18, 2025
d1d3fbc
Update benchmarks/linear-elastic-plate-with-hole/FEniCS/plateWithHole…
joergfunger Aug 18, 2025
6fe2c37
move directories
joergfunger Aug 18, 2025
d19fdef
fix typo
joergfunger Aug 18, 2025
3c2b0de
add a check for duplicate configurations in different parameter files
joergfunger Aug 18, 2025
265b452
add some comments
joergfunger Aug 18, 2025
76855fe
upload artefact location
joergfunger Aug 18, 2025
d819202
Update benchmarks/linear-elastic-plate-with-hole/FEniCS/environment_m…
joergfunger Aug 19, 2025
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
44 changes: 26 additions & 18 deletions .github/workflows/run-benchmark.yml
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
name: CI
on:
push:
branches-ignore:

pull_request:
branches: [ main ]
Expand Down Expand Up @@ -35,49 +34,58 @@ jobs:

- name: Update environment
run: mamba env update -n model-validation -f environment_benchmarks.yml
if: steps.cache.outputs.cache-hit != 'true'

- name: run-fenics-benchmarks
shell: bash -l {0}
run: |
cd $GITHUB_WORKSPACE/benchmarks/linear-elastic-plate-with-hole/FEniCS/
snakemake --use-conda --force --cores 'all'
snakemake --use-conda --force --cores 'all' --reporter metadata4ing

- name: run-fenics-nextflow-benchmark
shell: bash -l {0}
run: |
cd $GITHUB_WORKSPACE/benchmarks/linear-elastic-plate-with-hole/FEniCS_nextflow/
nextflow run main.nf
nextflow run main.nf -plugins nf-prov@1.4.0

- name: run-Kratos-benchmarks
shell: bash -l {0}
run: |
cd $GITHUB_WORKSPACE/benchmarks/linear-elastic-plate-with-hole/Kratos/
snakemake --use-conda --force --cores 'all'

#- name: run-optimization-workflow
# shell: bash -l {0}
# run: |
# cd $GITHUB_WORKSPACE/usecases/optimization_paper/optimization_workflow/
# snakemake -c 1

#- name: run-optimization-paper
# shell: bash -l {0}
# run: |
# cd $GITHUB_WORKSPACE/usecases/optimization_paper/
# doit

- name: Archive fenics data
uses: actions/upload-artifact@v4
with:
name: fenics-output
path: |
benchmarks/linear-elastic-plate-with-hole/FEniCS/data

benchmarks/linear-elastic-plate-with-hole/fenics/snakemake_results/

- name: Archive fenics snakemake provenance
uses: actions/upload-artifact@v4
with:
name: fenics-snakemake-provenance
path: |
benchmarks/linear-elastic-plate-with-hole/FEniCS/*.zip

- name: Archive kratos data
uses: actions/upload-artifact@v4
with:
name: kratos-output
path: |
benchmarks/linear-elastic-plate-with-hole/Kratos/data


- name: Archive fenics nextflow data
uses: actions/upload-artifact@v4
with:
name: fenics-nextflow-output
path: |
benchmarks/linear-elastic-plate-with-hole/FEniCS_nextflow/work/**
!benchmarks/linear-elastic-plate-with-hole/FEniCS_nextflow/work/conda/**

- name: Archive fenics nextflow provenance
uses: actions/upload-artifact@v4
with:
name: fenics-nextflow-provenance
path: |
benchmarks/linear-elastic-plate-with-hole/FEniCS_nextflow/provenance.json
140 changes: 92 additions & 48 deletions benchmarks/linear-elastic-plate-with-hole/FEniCS/Snakefile
Original file line number Diff line number Diff line change
@@ -1,67 +1,111 @@
from pathlib import Path
from os.path import join

files = list(Path(".").rglob("parameters_*.json"))
names = [f.stem.split("_")[1] for f in files]
files = list(Path(".").glob("parameters_*.json"))

# extract the configuration from the parameter files
# by reading in the json files and extracting the "configuration" value
# configuration stores the appendix in the output files)"
# in theory, you could make that identical so parameters_1.json with configuration "1"
# would produce summary_1.json
import json
def get_configuration(file):
with open(file, 'r') as f:
data = json.load(f)
# Check if "configuration" key exists, otherwise use the file name
if "configuration" in data:
return data["configuration"]
# Fallback to using the file name if "configuration" is not present
# Assuming the file name is in the format "parameters_<configuration>.json"
if file.stem.startswith("parameters_"):
return file.stem.split("_")[1]
# If no configuration is found, raise an error
raise ValueError(f"Configuration key not found for file: {file}")

# Create a dictionary of configurations (key is the name of the parameter file)
# configurations: {Path("parameters_1.json"): "1", ...}
configurations = {file: get_configuration(file) for file in files if file.is_file()}

# Check for duplicate configuration values (the configurations should be unique)
config_values = list(configurations.values())
duplicates = set([x for x in config_values if config_values.count(x) > 1])
if duplicates:
raise ValueError(f"Duplicate configuration values found in parameter files: {', '.join(duplicates)}")

# Reverse mapping for easy lookup by configuration name
configuration_to_parameter_file = {v: str(k) for k, v in configurations.items()}

tools = ["fenics"]
benchmark = "linear-elastic-plate-with-hole"
# results are stored in snakemake_results/linear-elastic-plate-with-hole/fenics
result_dir = join("snakemake_results", benchmark)

rule all:
input:
expand("summary_{name}.json", name=names),
#expand("output_{name}.h5", name=names)
expand(f"{result_dir}/{{tool}}/summary.json", tool=tools),

rule generate_input_files:
rule create_mesh:
input:
"experiment.json",
"parameters_{name}.json",
script = "create_mesh.py",
# the parameters file for the current configuration, this has to be a lambda function since
# the wildcard (configuration) has to be evaluated (the dictionary)
# otherwise, you could just write configuration_to_parameter_file(configuration)
parameters = lambda wildcards: configuration_to_parameter_file[wildcards.configuration],
output:
"data/input_{name}.json",
"data/mesh_{name}.msh",
conda: "environment.yml"
shell: "python3 create_input_files.py {wildcards.name} {input}"
mesh = f"{result_dir}/mesh/mesh_{{configuration}}.msh",
conda: "environment_mesh.yml"
shell:
"""
python3 {input.script} --input_parameter_file {input.parameters} --output_mesh_file {output.mesh}
"""

rule run_simulation:
input:
"data/input_{name}.json",
"data/mesh_{name}.msh",
script = "{tool}/run_simulation.py",
parameters = lambda wildcards: configuration_to_parameter_file[wildcards.configuration],
mesh = f"{result_dir}/mesh/mesh_{{configuration}}.msh",
output:
"data/output_{name}.vtk",
zip = f"{result_dir}/{{tool}}/solution_field_data_{{configuration}}.zip",
metrics = f"{result_dir}/{{tool}}/solution_metrics_{{configuration}}.json",
conda:
"environment.yml",
shell: "python3 run_simulation.py {wildcards.name} {input}"
"{tool}/environment_simulation.yml",
shell:
"""
python3 {input.script} --input_parameter_file {input.parameters} --input_mesh_file {input.mesh} --output_solution_file_zip {output.zip} --output_metrics_file {output.metrics}
"""

rule summary:
input:
"data/output_{name}.vtk",
"data/input_{name}.json",
"data/mesh_{name}.msh",
"parameters_{name}.json",
# the summary is performed for all configurations saved into a single file
# (snakemake_results/linear-elastic-plate-with-hole/fenics/summary.json)
parameters = expand("{param}", param=[configuration_to_parameter_file[c] for c in configurations.values()]),
mesh = expand(f"{result_dir}/mesh/mesh_{{configuration}}.msh", configuration=configurations.values()),
metrics = lambda wildcards: expand(
f"{result_dir}/{{tool}}/solution_metrics_{{configuration}}.json",
tool=[wildcards.tool], configuration=configurations.values()
),
solution_field_data = lambda wildcards: expand(
f"{result_dir}/{{tool}}/solution_field_data_{{configuration}}.zip",
tool=[wildcards.tool], configuration=configurations.values()
),
output:
"summary_{name}.json",
summary_json = f"{result_dir}/{{tool}}/summary.json",
conda: "environment_postprocessing.yml",
run:
import json
import pyvista
summary = {}
summary["name"] = wildcards.name
summary["parameters"] = input[3]
summary["input"] = input[1]
summary["mesh"] = input[2]
summary["output"] = input[0]
# Load the mesh and output data
max_mises_stress = 42.0
from xml.etree import ElementTree as ET
tree = ET.parse(input[0])
root = tree.getroot()
pvtu_filenames = []
path = Path(input[0]).parent
for dataset in root.findall(".//DataSet"):
pvtu_filenames.append(path / dataset.get("file"))
meshes = [pyvista.read(pvtu_filename) for pvtu_filename in pvtu_filenames]
print(pvtu_filenames)
for mesh in meshes:
# Assuming the mesh has a 'von_mises_stress' array
try:
max_mises_stress = float(mesh["von_mises_stress"].max())
except KeyError:
print("von_mises_stress not found in mesh.")
summary["max_mises_stress"] = max_mises_stress # Replace with actual computation
with open(output[0], "w") as f:
json.dump(summary, f, indent=4)
from pathlib import Path

all_summaries = []
for idx, config in enumerate(configurations.values()):
summary = {}
summary["benchmark"] = benchmark
with open(input.parameters[idx], "r") as param_file:
summary["parameters"] = json.load(param_file)
summary["mesh"] = f"{config}/mesh"
with open(input.metrics[idx], "r") as metrics_file:
summary["metrics"] = json.load(metrics_file)
summary["configuration"] = config
all_summaries.append(summary)

with open(output.summary_json, "w") as f:
json.dump(all_summaries, f, indent=4)

This file was deleted.

Loading
Loading