-
Notifications
You must be signed in to change notification settings - Fork 2
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
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
b64262e
edited run-benchmark.yml
c48c38e
update snakemake workflow for linear elastic benchmark
joergfunger 99acd43
formating
joergfunger 80cbe47
Merge branch 'main' into creation-of-nextflow-workflow
joergfunger ac7ad66
updated the ci action file, fix typos there
joergfunger 8c217b8
fix env
joergfunger 2d9cd85
fix bug for file patterns
joergfunger 75f1bf4
first call snakemake and then the reporter afterwards
joergfunger 3f336ac
fix typo
joergfunger c2e395a
fix typo
joergfunger 736932f
make the output depending on the tool as a wildcard, only the simulat…
joergfunger 1ce8bba
revert hdf5 storage to just store a zipped version of all simulation …
joergfunger f2fd32f
Update benchmarks/linear-elastic-plate-with-hole/FEniCS/plateWithHole…
joergfunger c1d9537
Update benchmarks/linear-elastic-plate-with-hole/FEniCS/plateWithHole…
joergfunger 054eb5a
Update benchmarks/linear-elastic-plate-with-hole/FEniCS/plateWithHole…
joergfunger d1d3fbc
Update benchmarks/linear-elastic-plate-with-hole/FEniCS/plateWithHole…
joergfunger 6fe2c37
move directories
joergfunger d19fdef
fix typo
joergfunger 3c2b0de
add a check for duplicate configurations in different parameter files
joergfunger 265b452
add some comments
joergfunger 76855fe
upload artefact location
joergfunger d819202
Update benchmarks/linear-elastic-plate-with-hole/FEniCS/environment_m…
joergfunger File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
140 changes: 92 additions & 48 deletions
140
benchmarks/linear-elastic-plate-with-hole/FEniCS/Snakefile
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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], | ||
srosenbu marked this conversation as resolved.
Show resolved
Hide resolved
|
||
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) |
95 changes: 0 additions & 95 deletions
95
benchmarks/linear-elastic-plate-with-hole/FEniCS/create_input_files.py
This file was deleted.
Oops, something went wrong.
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.