Skip to content

Commit 72760da

Browse files
committed
add script that checks outputs
1 parent 341c52d commit 72760da

2 files changed

Lines changed: 59 additions & 0 deletions

File tree

environment.yaml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ dependencies:
66
- jsonschema
77
- matplotlib
88
- numpy
9+
- pcrunch
910
- pip
1011
- python
1112
- pytest

examples/check_outputs.py

Lines changed: 58 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,58 @@
1+
from pCrunch import read
2+
"""
3+
This script checks the output files of simulation runs in a specified directory and determines whether
4+
each simulation completed successfully or failed prematurely.
5+
6+
Modules:
7+
- pCrunch: Used to read the output binary files (.outb) generated by Fast.Farm.
8+
- os: Used for directory and file path operations.
9+
10+
Constants:
11+
- directory (str): The path to the directory containing the simulation case folders.
12+
- filename (str): The base name of the output file to check.
13+
- Tmax (int): The expected maximum simulation time. Simulations with a last time step less than this
14+
value are considered to have failed prematurely.
15+
16+
Workflow:
17+
1. List all subdirectories in the specified `directory` path.
18+
2. Sort the subdirectories numerically based on the suffix of their names (assumes folder names end
19+
with an underscore followed by a number).
20+
3. For each folder:
21+
- Construct the path to the expected output file.
22+
- Check if the output file exists:
23+
- If not, print a message indicating the folder was not run or the output file is missing.
24+
- If it exists, read the output file and check the last time step:
25+
- If the last time step is greater than `Tmax`, print a message indicating the simulation
26+
completed successfully.
27+
- Otherwise, print a message indicating the simulation failed prematurely and display the
28+
last time step.
29+
30+
Usage:
31+
- Update the `directory` variable to point to the directory containing your simulation case folders.
32+
- Ensure the `filename` variable matches the base name of the output files you want to check.
33+
- Adjust the `Tmax` variable to reflect the expected maximum simulation time for your use case.
34+
"""
35+
import os
36+
37+
# Inputs
38+
directory = "/Users/pbortolo/work/3_projects/30_HolisticSE/FarmCast_runs/cases"
39+
filename = "generated"
40+
Tmax = 900
41+
42+
# Execution
43+
folders = [f for f in os.listdir(directory) if os.path.isdir(os.path.join(directory, f))]
44+
folders.sort(key=lambda x: int(x.split('_')[-1]))
45+
46+
for folder in folders:
47+
folder_path = os.path.join(directory, folder)
48+
outb = os.path.join(folder_path, "fastfarm", filename + ".T1.outb")
49+
if not os.path.exists(outb):
50+
print(f"{folder} not run or output file missing")
51+
else:
52+
data = read(outb)
53+
if data["Time"][-1] > Tmax:
54+
print(f"{folder} completed successfully")
55+
else:
56+
print(f"{folder} failed prematurely, last time step: {data['Time'][-1]}")
57+
58+

0 commit comments

Comments
 (0)