Skip to content

Commit 986b294

Browse files
committed
Extend CI
1 parent d35204a commit 986b294

3 files changed

Lines changed: 85 additions & 308 deletions

File tree

.github/workflows/run-benchmark-examples.yml

Lines changed: 58 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ on:
1414

1515
env:
1616
CACHE_NUMBER: 1 # increase to reset cache manually
17+
EXAMPLE_BENCHMARK_FILE: examples/linear-elastic-plate-with-hole/benchmark.json
1718

1819
jobs:
1920
run-examples:
@@ -75,4 +76,61 @@ jobs:
7576
path: |
7677
examples/linear-elastic-plate-with-hole/kratos/results/
7778
79+
process-artifacts:
80+
runs-on: ubuntu-latest
81+
needs: run-examples
82+
strategy:
83+
fail-fast: false
84+
matrix:
85+
include:
86+
- tool_slug: fenics
87+
software_name: Fenics
88+
results_artifact: fenics_results_linear-elastic-plate-with-hole
89+
rocrate_filename: Fenics-RoCrate.zip
90+
plot_filename: fenics-element-size-vs-stress-plot.pdf
91+
92+
steps:
93+
- name: Checkout repo content
94+
uses: actions/checkout@v2
95+
96+
- name: Download ${{ matrix.software_name }} results artifact
97+
uses: actions/download-artifact@v4
98+
with:
99+
name: ${{ matrix.results_artifact }}
100+
path: ./simulation-results/${{ matrix.tool_slug }}
101+
102+
- name: Setup Mambaforge with postprocessing env
103+
uses: conda-incubator/setup-miniconda@v3
104+
with:
105+
miniforge-version: latest
106+
activate-environment: postprocessing
107+
use-mamba: true
108+
environment-file: benchmarks/linear-elastic-plate-with-hole/environment_postprocessing.yml
109+
110+
- name: Create ${{ matrix.software_name }} aggregate RO-Crate
111+
shell: bash -l {0}
112+
run: |
113+
python benchmarks/common/create_rocrate.py \
114+
--benchmark-file "${EXAMPLE_BENCHMARK_FILE}" \
115+
--simulation-result-path "./simulation-results/${{ matrix.tool_slug }}" \
116+
--rocrate-filename "${{ matrix.rocrate_filename }}" \
117+
--software-name "${{ matrix.software_name }}"
118+
119+
- name: Unzip ${{ matrix.software_name }} RO-Crate
120+
run: |
121+
mkdir -p "./processed/${{ matrix.tool_slug }}"
122+
unzip -o "${{ matrix.rocrate_filename }}" -d "./processed/${{ matrix.tool_slug }}"
123+
124+
- name: Run ${{ matrix.software_name }} plotting script
125+
shell: bash -l {0}
126+
run: |
127+
python examples/linear-elastic-plate-with-hole/plot_metrics.py \
128+
--provenance_folderpath "./processed/${{ matrix.tool_slug }}" \
129+
--output_file "${{ matrix.plot_filename }}"
130+
131+
- name: Upload ${{ matrix.software_name }} plot artifact
132+
uses: actions/upload-artifact@v4
133+
with:
134+
name: ${{ matrix.tool_slug }}-element-size-vs-stress-plot
135+
path: ${{ matrix.plot_filename }}
78136

benchmarks/common/create_rocrate.py

Lines changed: 27 additions & 77 deletions
Original file line numberDiff line numberDiff line change
@@ -4,22 +4,21 @@
44
import json
55
import uuid
66
import zipfile
7-
from importlib import resources
87
from pathlib import Path
98
from typing import Any, TypedDict
109

11-
from rdflib import Graph
1210
from rocrate.rocrate import ROCrate
13-
from provenance import ProvenanceAnalyzer
1411
import semantic_benchmark
1512

1613
DEFAULT_BENCHMARK_FILE = (
1714
"/Users/mahdi/Documents/GitHub/NFDI4IngModelValidationPlatform/examples/"
1815
"linear-elastic-plate-with-hole/benchmark.json"
1916
)
2017
DEFAULT_SIMULATION_RESULT_PATH = (
21-
"/Users/mahdi/Downloads/fenics_provenance_linear-elastic-plate-with-hole"
18+
"/Users/mahdi/Downloads/kratos_provenance_linear-elastic-plate-with-hole"
2219
)
20+
DEFAULT_ROCRATE_FILENAME = "RoCrate.zip"
21+
DEFAULT_SOFTWARE_NAME = "FENICS"
2322
M4I_HAS_KIND_OF_QUANTITY = "http://w3id.org/nfdi4ing/metadata4ing#hasKindOfQuantity"
2423
ROCRATE_CONFORMS_TO = [
2524
{"@id": "https://w3id.org/ro/crate/1.1"},
@@ -423,20 +422,11 @@ def _add_profile_creative_works(crate: ROCrate) -> None:
423422
crate.add_jsonld(creative_work)
424423

425424

426-
def unzip_rocrate(ro_zip_path: str = "RO.zip", extract_dir: str = "RO") -> Path:
427-
zip_path = Path(ro_zip_path)
428-
if not zip_path.exists():
429-
raise FileNotFoundError(f"RO-Crate zip not found: {zip_path}")
430-
431-
output_dir = Path(extract_dir)
432-
output_dir.mkdir(parents=True, exist_ok=True)
433-
with zipfile.ZipFile(zip_path, "r") as archive:
434-
archive.extractall(output_dir)
435-
return output_dir
436-
437-
438425
def create_main_ro(
439-
path: str, benchmark_object: semantic_benchmark.SemanticBenchmark
426+
path: str,
427+
benchmark_object: semantic_benchmark.SemanticBenchmark,
428+
rocrate_filename: str = DEFAULT_ROCRATE_FILENAME,
429+
software_name: str = DEFAULT_SOFTWARE_NAME,
440430
) -> None:
441431
crate = ROCrate(version="1.1")
442432
input_path = Path(path)
@@ -475,7 +465,7 @@ def create_main_ro(
475465
_configure_crate_metadata(crate, snakemake_id)
476466

477467
crate.add_jsonld(
478-
{"@id": software_id, "@type": "SoftwareApplication", "name": "FENICS"}
468+
{"@id": software_id, "@type": "SoftwareApplication", "name": software_name}
479469
)
480470
_add_profile_creative_works(crate)
481471

@@ -484,53 +474,12 @@ def create_main_ro(
484474
lang="snakemake",
485475
properties={"hasPart": {"@id": software_id}},
486476
)
487-
crate.write_zip("RoCrate.Zip")
488-
489-
490-
def run_sparql_query(graph: Graph) -> None:
491-
query = """
492-
PREFIX schema: <http://schema.org/>
493-
494-
SELECT ?elementSize ?maxVonMisesStressNodes ?l2ErrorDisplacement
495-
WHERE {
496-
?runAction a schema:CreateAction ;
497-
schema:object ?object ;
498-
schema:result ?metric1 ;
499-
schema:result ?metric2 .
500-
501-
?object a schema:PropertyValue ;
502-
schema:exampleOfWork ?param .
503-
504-
?param a <https://bioschemas.org/FormalParameter> ;
505-
schema:name "element-size" ;
506-
schema:defaultValue ?elementSize .
507-
508-
?metric1 a schema:PropertyValue ;
509-
schema:name "max_von_mises_stress_nodes" ;
510-
schema:defaultValue ?maxVonMisesStressNodes .
511-
512-
?metric2 a schema:PropertyValue ;
513-
schema:name "l2_error_displacement" ;
514-
schema:defaultValue ?l2ErrorDisplacement .
515-
}
516-
ORDER BY ?elementSize
517-
"""
518-
results = graph.query(query)
519-
variables = [str(var) for var in results.vars]
520-
if variables:
521-
print(" | ".join(variables))
522-
print("-" * max(3, len(" | ".join(variables))))
523-
row_count = 0
524-
for row in results:
525-
values = [str(value) if value is not None else "" for value in row]
526-
print(" | ".join(values))
527-
row_count += 1
528-
print(f"\nRows: {row_count}")
477+
crate.write_zip(rocrate_filename)
529478

530479

531-
def main() -> None:
480+
def parse_args() -> argparse.Namespace:
532481
parser = argparse.ArgumentParser(
533-
description="Create RO-Crate and run SPARQL queries on ro-crate-metadata.json"
482+
description="Create a benchmark provenance RO-Crate from simulation results."
534483
)
535484
parser.add_argument(
536485
"--benchmark-file",
@@ -540,30 +489,31 @@ def main() -> None:
540489
parser.add_argument(
541490
"--simulation-result-path",
542491
default=DEFAULT_SIMULATION_RESULT_PATH,
543-
help="Path containing run folders and SubCrate.zip files",
492+
help="Path containing simulation result subfolders with RoCrate zip files",
544493
)
545494
parser.add_argument(
546-
"--ro-zip", default="RoCrate.Zip", help="Path to RO-Crate zip file"
495+
"--rocrate-filename",
496+
default=DEFAULT_ROCRATE_FILENAME,
497+
help="Filename for the generated RO-Crate zip file",
547498
)
548499
parser.add_argument(
549-
"--extract-dir",
550-
default="RO",
551-
help="Directory where RoCrate.Zip should be extracted",
500+
"--software-name",
501+
default=DEFAULT_SOFTWARE_NAME,
502+
help="Name of the software application recorded in the generated RO-Crate",
552503
)
553-
args = parser.parse_args()
554504

555-
benchmark_object = semantic_benchmark.BenchmarkLoader(args.benchmark_file).load()
556-
create_main_ro(args.simulation_result_path, benchmark_object)
505+
return parser.parse_args()
557506

558-
extracted_dir = unzip_rocrate(args.ro_zip, args.extract_dir)
559507

560-
proveance = ProvenanceAnalyzer(provenance_folderpath=extracted_dir)
561-
query = proveance.build_dynamic_rocrate_query(
562-
parameters=["element-size"],
563-
metrics=["max_von_mises_stress_nodes", "max_von_mises_stress_gauss_points"],
508+
def main() -> None:
509+
args = parse_args()
510+
benchmark_object = semantic_benchmark.BenchmarkLoader(args.benchmark_file).load()
511+
create_main_ro(
512+
args.simulation_result_path,
513+
benchmark_object,
514+
rocrate_filename=args.rocrate_filename,
515+
software_name=args.software_name,
564516
)
565-
proveance.plot_provenance_graph()
566-
print(query)
567517

568518

569519
if __name__ == "__main__":

0 commit comments

Comments
 (0)