Skip to content

Commit ca9af2d

Browse files
authored
Merge pull request #107 from anshgupta1234/post_tests
2 parents c260b69 + 4e8c88c commit ca9af2d

File tree

7 files changed

+114
-19
lines changed

7 files changed

+114
-19
lines changed

.github/workflows/ci.yml

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@ jobs:
4949
run: /bin/bash mfc.sh build -j $(nproc)
5050

5151
- name: Test Suite
52-
run: /bin/bash mfc.sh test -j $(nproc)
52+
run: /bin/bash mfc.sh test -j $(nproc) -a
5353

5454
self-cpu:
5555
name: (Self) Test Suite - CPU
@@ -69,14 +69,14 @@ jobs:
6969
- name: Build
7070
run: |
7171
module use /opt/nvidia/hpc_sdk/modulefiles/
72-
module load nvhpc/22.11
72+
module load nvhpc
7373
/bin/bash mfc.sh build -j 4
7474
7575
- name: Test Suite
7676
run: |
7777
module use /opt/nvidia/hpc_sdk/modulefiles/
78-
module load nvhpc/22.11
79-
/bin/bash mfc.sh test -j 4
78+
module load nvhpc
79+
/bin/bash mfc.sh test -j 4 -a
8080
8181
self-gpu:
8282
name: (Self) Test Suite - GPU
@@ -96,12 +96,12 @@ jobs:
9696
- name: Build
9797
run: |
9898
module use /opt/nvidia/hpc_sdk/modulefiles/
99-
module load nvhpc/22.11
99+
module load nvhpc
100100
/bin/bash mfc.sh build -j 4 --gpu
101101
102102
- name: Test Suite
103103
run: |
104104
module use /opt/nvidia/hpc_sdk/modulefiles/
105-
module load nvhpc/22.11
106-
/bin/bash mfc.sh test -b mpirun --gpu
105+
module load nvhpc
106+
/bin/bash mfc.sh test -b mpirun --gpu -a
107107

src/common/m_variables_conversion.fpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -681,7 +681,7 @@ contains
681681
! If pre-processing, use non acc mixture subroutines
682682
if (hypoelasticity) then
683683
call s_convert_to_mixture_variables(qK_cons_vf, j, k, l, &
684-
rho_K, gamma_K, pi_inf_K, Re_K, G_K)
684+
rho_K, gamma_K, pi_inf_K, Re_K, G_K, fluid_pp(:)%G)
685685
else
686686
call s_convert_to_mixture_variables(qK_cons_vf, j, k, l, &
687687
rho_K, gamma_K, pi_inf_K)

toolchain/mfc/args.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -69,6 +69,7 @@ def add_common_arguments(p, mask = None):
6969
test.add_argument("-o", "--only", nargs="+", type=str, default=[], metavar="L", help="Only run tests with UUIDs or hashes L.")
7070
test.add_argument("-b", "--binary", choices=binaries, type=str, default=None, help="(Serial) Override MPI execution binary")
7171
test.add_argument("-r", "--relentless", action="store_true", default=False, help="Run all tests, even if multiple fail.")
72+
test.add_argument("-a", "--test-all", action="store_true", default=False, help="Run the Post Process Tests too.")
7273
test.add_argument("--case-optimization", action="store_true", default=False, help="(GPU Optimization) Compile MFC targets with some case parameters hard-coded.")
7374

7475
# === RUN ===

toolchain/mfc/test/case.py

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -101,7 +101,7 @@ def __init__(self, trace: str, mods: dict, ppn: int = None) -> None:
101101
self.ppn = ppn if ppn is not None else 1
102102
super().__init__({**BASE_CFG.copy(), **mods})
103103

104-
def run(self) -> subprocess.CompletedProcess:
104+
def run(self, post_process_toggle) -> subprocess.CompletedProcess:
105105
filepath = f'"{self.get_dirpath()}/case.py"'
106106
tasks = f"-n {self.ppn}"
107107
jobs = f"-j {ARG('jobs')}" if ARG("case_optimization") else ""
@@ -110,10 +110,16 @@ def run(self) -> subprocess.CompletedProcess:
110110

111111
mfc_script = ".\mfc.bat" if os.name == 'nt' else "./mfc.sh"
112112

113-
command: str = f'''\
114-
{mfc_script} run {filepath} {tasks} {binary_option} {case_optimization} \
115-
{jobs} -t pre_process simulation 2>&1\
116-
'''
113+
if post_process_toggle:
114+
command: str = f'''\
115+
{mfc_script} run {filepath} {tasks} {binary_option} {case_optimization} \
116+
{jobs} 2>&1\
117+
'''
118+
else:
119+
command: str = f'''\
120+
{mfc_script} run {filepath} {tasks} {binary_option} {case_optimization} \
121+
{jobs} -t pre_process simulation 2>&1\
122+
'''
117123

118124
return subprocess.run(command, stdout=subprocess.PIPE,
119125
stderr=subprocess.PIPE, universal_newlines=True,

toolchain/mfc/test/cases.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -271,7 +271,6 @@ def alter_bubbles(dimInfo, dimParams):
271271
if len(dimInfo[0]) >= 3:
272272
stack.pop()
273273

274-
275274
def alter_hypoelasticity(dimInfo, dimParams):
276275
# Hypoelasticity checks
277276
for num_fluids in [1,2]:

toolchain/mfc/test/test.py

Lines changed: 93 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,8 @@
1111
from . import pack as packer
1212

1313
import rich, rich.table
14+
import h5py
15+
import numpy as np
1416

1517

1618
CASES = generate_cases()
@@ -81,7 +83,7 @@ def test():
8183
return
8284

8385
if not ARG("case_optimization"):
84-
build_targets(["pre_process", "simulation"])
86+
build_targets(["pre_process", "simulation", "post_process"])
8587

8688
range_str = f"from [bold magenta]{ARG('from')}[/bold magenta] to [bold magenta]{ARG('to')}[/bold magenta]"
8789

@@ -110,17 +112,34 @@ def test():
110112
sched.Task(ppn=case.ppn, func=handle_case, args=[ case ]) for case in CASES
111113
]
112114
sched.sched(tasks, nThreads)
113-
115+
114116
cons.print()
115117
if nFAIL == 0:
116-
cons.print(f"Tested [bold green]✓[/bold green]")
117-
cons.unindent()
118+
cons.print(f"Tested Simulation [bold green]✓[/bold green]")
118119
else:
119120
if nFAIL == 1:
120121
raise MFCException(f"Testing: There was [bold red]1[/bold red] failure.")
121122
else:
122123
raise MFCException(f"Testing: There were [bold red]{nFAIL}[/bold red] failures.")
123124

125+
if ARG("test_all"):
126+
cons.print(f"Now testing post process...")
127+
cons.print()
128+
nFAIL = 0
129+
tasks = [
130+
sched.Task(ppn=case.ppn, func=handle_case_post_process, args=[ case ]) for case in CASES
131+
]
132+
sched.sched(tasks, nThreads)
133+
cons.print()
134+
if nFAIL == 0:
135+
cons.print(f"Tested Post Process [bold green]✓[/bold green]")
136+
else:
137+
if nFAIL == 1:
138+
raise MFCException(f"Testing: There was [bold red]1[/bold red] failure.")
139+
else:
140+
raise MFCException(f"Testing: There were [bold red]{nFAIL}[/bold red] failures.")
141+
cons.unindent()
142+
124143

125144
def handle_case(test: TestCase):
126145
global nFAIL
@@ -137,7 +156,7 @@ def handle_case(test: TestCase):
137156
else:
138157
tol = 1e-12
139158

140-
cmd = test.run()
159+
cmd = test.run(False)
141160

142161
out_filepath = os.path.join(test.get_dirpath(), "out.txt")
143162

@@ -161,6 +180,7 @@ def handle_case(test: TestCase):
161180
packer.check_tolerance(test, pack, packer.load(golden_filepath), tol)
162181

163182
cons.print(f" [bold magenta]{test.get_uuid()}[/bold magenta] {test.trace}")
183+
164184
except Exception as exc:
165185
nFAIL = nFAIL + 1
166186

@@ -169,3 +189,71 @@ def handle_case(test: TestCase):
169189

170190
cons.print(f"[bold red]Failed test {test}.[/bold red]")
171191
cons.print(f"{exc}")
192+
193+
def handle_case_post_process(test: TestCase):
194+
global nFAIL
195+
196+
try:
197+
test.params.update({
198+
'parallel_io' : 'T',
199+
'cons_vars_wrt' : 'T',
200+
'prim_vars_wrt' : 'T',
201+
'alpha_rho_wrt(1)' : 'T',
202+
'rho_wrt' : 'T',
203+
'mom_wrt(1)' : 'T',
204+
'vel_wrt(1)' : 'T',
205+
'E_wrt' : 'T',
206+
'pres_wrt' : 'T',
207+
'alpha_wrt(1)' : 'T',
208+
'gamma_wrt' : 'T',
209+
'heat_ratio_wrt' : 'T',
210+
'pi_inf_wrt' : 'T',
211+
'pres_inf_wrt' : 'T',
212+
'c_wrt' : 'T',
213+
})
214+
215+
if test.params['p'] != 0:
216+
test.params['omega_wrt'] = 'T'
217+
test.params['fd_order'] = 1
218+
219+
test.create_directory()
220+
221+
cmd = test.run(True)
222+
223+
out_filepath = os.path.join(test.get_dirpath(), "out_pp.txt")
224+
225+
common.file_write(out_filepath, cmd.stdout)
226+
227+
if cmd.returncode != 0:
228+
cons.print(cmd.stdout)
229+
raise MFCException(f"""Test {test}: Failed to execute MFC. You can find the run's output in {out_filepath}, and the case dictionary in {os.path.join(test.get_dirpath(), "case.py")}.""")
230+
231+
silo_filepath = os.path.join(test.get_dirpath(), 'silo_hdf5', 'p0', '50.silo')
232+
f = h5py.File(silo_filepath, 'r')
233+
silo = f['.silo']
234+
for key in silo.keys():
235+
dataset = silo[key]
236+
for data in dataset:
237+
check_data(data)
238+
239+
cons.print(f" [bold magenta]{test.get_uuid()}[/bold magenta] {test.trace}")
240+
241+
except Exception as exc:
242+
nFAIL = nFAIL + 1
243+
244+
if not ARG("relentless"):
245+
raise exc
246+
247+
cons.print(f"[bold red]Failed test {test}.[/bold red]")
248+
cons.print(f"{exc}")
249+
250+
def check_data(data):
251+
if isinstance(data, np.ndarray):
252+
for subdata in data:
253+
check_data(subdata)
254+
else:
255+
if np.isnan(data):
256+
raise MFCException(f"""Test {test}: Post Process has detected a NaN. You can find the run's output in {out_filepath}, and the case dictionary in {os.path.join(test.get_dirpath(), "case.py")}.""")
257+
if np.isinf(data):
258+
raise MFCException(f"""Test {test}: Post Process has detected an Infinity. You can find the run's output in {out_filepath}, and the case dictionary in {os.path.join(test.get_dirpath(), "case.py")}.""")
259+

toolchain/requirements.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,3 +5,4 @@ typing
55
PyYAML
66
argparse
77
dataclasses
8+
h5py

0 commit comments

Comments
 (0)