Skip to content

Commit 54cda67

Browse files
Improve error reporting for case files. (#437)
* Partially complete typechecking * fix nonsense comment * It appears to work! Only thing I'd maybe change past this point is the error reporting * sate the linter * remove new python syntax -- cluster versions are before 3.10 * Refactor and fix new Python syntax I implemented something halfway between what I currently have and what we discussed last night * Remove redundant check in test runner * sate linter again * refactor, document, and add example * decouple MFCInputFile constructor and validation * remove bad case * Fix macOS CI * regex refactor, remove unnecessary validation * fix trailing whitespace * toolchain: Give context for jsonschema errors --------- Co-authored-by: Henry LE BERRE <[email protected]>
1 parent 0aaeb3b commit 54cda67

File tree

8 files changed

+286
-129
lines changed

8 files changed

+286
-129
lines changed

.github/workflows/test.yml

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -50,10 +50,10 @@ jobs:
5050
- name: Setup MacOS
5151
if: matrix.os == 'macos'
5252
run: |
53-
echo "CC=gcc-13" >> $GITHUB_ENV
54-
echo "CXX=g++-13" >> $GITHUB_ENV
55-
echo "FC=gfortran-13" >> $GITHUB_ENV
56-
brew install wget make python make cmake coreutils gcc@13
53+
brew install wget make python make cmake coreutils gcc@14
54+
echo "CC=gcc-14" >> $GITHUB_ENV
55+
echo "CXX=g++-14" >> $GITHUB_ENV
56+
echo "FC=gfortran-14" >> $GITHUB_ENV
5757
5858
- name: (MacOS) Build OpenMPI
5959
if: matrix.os == 'macos' && matrix.mpi == 'mpi'

docs/documentation/case.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -354,7 +354,7 @@ Details of implementation of viscosity in MFC can be found in [Coralic (2015)](r
354354
| `mpp_lim` | Logical | Mixture physical parameters limits |
355355
| `mixture_err` | Logical | Mixture properties correction |
356356
| `time_stepper` | Integer | Runge--Kutta order [1-3] |
357-
| `adap_dt` | Loginal | Strang splitting scheme with adaptive time stepping |
357+
| `adap_dt` | Logical | Strang splitting scheme with adaptive time stepping |
358358
| `weno_order` | Integer | WENO order [1,3,5] |
359359
| `weno_eps` | Real | WENO perturbation (avoid division by zero) |
360360
| `mapped_weno` | Logical | WENO with mapping of nonlinear weights |

examples/2D_riemann_test/case.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@
3333
'mixture_err' : 'T',
3434
'time_stepper' : 3,
3535
'mp_weno' : 'F',
36-
'recon_type' : 1,
36+
# 'recon_type' : 1,
3737
'weno_order' : 5,
3838
'weno_eps' : 1e-16,
3939
#'muscl_order' : 2,

toolchain/mfc/build.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -287,6 +287,7 @@ def build(targets = None, case: input.MFCInputFile = None, history: typing.Set[s
287287

288288
targets = get_targets(list(REQUIRED_TARGETS) + targets)
289289
case = case or input.load(ARG("input"), ARG("arguments"), {})
290+
case.validate_params()
290291

291292
if len(history) == 0:
292293
cons.print(__generate_header("Build", targets))

toolchain/mfc/case.py

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
1-
import re, json, math, copy, dataclasses
1+
import re, json, math, copy, dataclasses, jsonschema
2+
import jsonschema.exceptions
23

34
from . import common
45
from . import build
@@ -65,6 +66,19 @@ def get_inp(self, _target) -> str:
6566

6667
return f"&user_inputs\n{dict_str}&end/\n"
6768

69+
def validate_params(self, origin_txt: str = None):
70+
'''Typechecks parameters read from case file. If a parameter
71+
is assigned a vlaie of the wrong type, this method throws an exception
72+
highlighting the violating parameter and specifying what it expects.'''
73+
try:
74+
jsonschema.validate(self.params, case_dicts.SCHEMA)
75+
except jsonschema.exceptions.ValidationError as e:
76+
exception_txt = f"Case parameter '{e.path[0]}' is of the wrong type. Expected type: '{e.schema['type']}'. Got value '{e.instance}' of type '{type(e.instance).__name__}'."
77+
if origin_txt:
78+
exception_txt = f"Origin: {origin_txt}. {exception_txt}"
79+
80+
raise common.MFCException(exception_txt)
81+
6882
def __get_ndims(self) -> int:
6983
return 1 + min(int(self.params.get("n", 0)), 1) + min(int(self.params.get("p", 0)), 1)
7084

0 commit comments

Comments
 (0)