Skip to content

Commit c2b616d

Browse files
sbryngelsonclaude
andcommitted
Remove unnecessary __future__ imports, add _is_numeric guards, fix en dash
- Remove `from __future__ import annotations` from all 4 toolchain files (Python 3.10+ is required) - Add `_is_numeric()` guards in physics checks to prevent TypeError when parameters are analytical string expressions - Fix Unicode en dash in Alpha-Rho title Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
1 parent 3dd275f commit c2b616d

5 files changed

Lines changed: 24 additions & 28 deletions

File tree

toolchain/mfc/case_validator.py

Lines changed: 23 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -1638,7 +1638,7 @@ def check_patch_physics(self): # pylint: disable=too-many-locals,too-many-branc
16381638
bubbles_euler = self.get('bubbles_euler', 'F') == 'T'
16391639
num_ibs = self.get('num_ibs', 0) or 0 # IBM (Immersed Boundary Method)
16401640

1641-
if num_patches is None or num_patches <= 0:
1641+
if not self._is_numeric(num_patches) or num_patches <= 0:
16421642
return
16431643

16441644
for i in range(1, num_patches + 1):
@@ -2045,23 +2045,23 @@ def check_domain_bounds(self):
20452045
"""Checks that domain end > domain begin for each active dimension"""
20462046
x_beg = self.get('x_domain%beg')
20472047
x_end = self.get('x_domain%end')
2048-
if x_beg is not None and x_end is not None:
2048+
if self._is_numeric(x_beg) and self._is_numeric(x_end):
20492049
self.prohibit(x_end <= x_beg,
20502050
f"x_domain%end ({x_end}) must be greater than x_domain%beg ({x_beg})")
20512051

20522052
n = self.get('n', 0)
2053-
if n is not None and n > 0:
2053+
if self._is_numeric(n) and n > 0:
20542054
y_beg = self.get('y_domain%beg')
20552055
y_end = self.get('y_domain%end')
2056-
if y_beg is not None and y_end is not None:
2056+
if self._is_numeric(y_beg) and self._is_numeric(y_end):
20572057
self.prohibit(y_end <= y_beg,
20582058
f"y_domain%end ({y_end}) must be greater than y_domain%beg ({y_beg})")
20592059

20602060
p = self.get('p', 0)
2061-
if p is not None and p > 0:
2061+
if self._is_numeric(p) and p > 0:
20622062
z_beg = self.get('z_domain%beg')
20632063
z_end = self.get('z_domain%end')
2064-
if z_beg is not None and z_end is not None:
2064+
if self._is_numeric(z_beg) and self._is_numeric(z_end):
20652065
self.prohibit(z_end <= z_beg,
20662066
f"z_domain%end ({z_end}) must be greater than z_domain%beg ({z_beg})")
20672067

@@ -2099,7 +2099,7 @@ def check_volume_fraction_sum(self): # pylint: disable=too-many-locals
20992099
if num_ibs > 0:
21002100
return
21012101

2102-
if num_patches is None or num_patches <= 0 or num_fluids is None:
2102+
if not self._is_numeric(num_patches) or num_patches <= 0 or not self._is_numeric(num_fluids):
21032103
return
21042104

21052105
for i in range(1, num_patches + 1):
@@ -2146,7 +2146,7 @@ def check_alpha_rho_consistency(self):
21462146
num_patches = self.get('num_patches', 0)
21472147
num_fluids = self.get('num_fluids', 1)
21482148

2149-
if num_patches is None or num_patches <= 0 or num_fluids is None:
2149+
if not self._is_numeric(num_patches) or num_patches <= 0 or not self._is_numeric(num_fluids):
21502150
return
21512151

21522152
for i in range(1, num_patches + 1):
@@ -2188,7 +2188,7 @@ def check_patch_within_domain(self): # pylint: disable=too-many-locals
21882188
extents are transformed and the domain bounds are not directly comparable.
21892189
"""
21902190
num_patches = self.get('num_patches', 0)
2191-
if num_patches is None or num_patches <= 0:
2191+
if not self._is_numeric(num_patches) or num_patches <= 0:
21922192
return
21932193

21942194
# Skip when any grid stretching is active — domain bounds don't map
@@ -2202,10 +2202,10 @@ def check_patch_within_domain(self): # pylint: disable=too-many-locals
22022202
x_end = self.get('x_domain%end')
22032203
n = self.get('n', 0)
22042204
p = self.get('p', 0)
2205-
y_beg = self.get('y_domain%beg') if n and n > 0 else None
2206-
y_end = self.get('y_domain%end') if n and n > 0 else None
2207-
z_beg = self.get('z_domain%beg') if p and p > 0 else None
2208-
z_end = self.get('z_domain%end') if p and p > 0 else None
2205+
y_beg = self.get('y_domain%beg') if self._is_numeric(n) and n > 0 else None
2206+
y_end = self.get('y_domain%end') if self._is_numeric(n) and n > 0 else None
2207+
z_beg = self.get('z_domain%beg') if self._is_numeric(p) and p > 0 else None
2208+
z_end = self.get('z_domain%end') if self._is_numeric(p) and p > 0 else None
22092209

22102210
for i in range(1, num_patches + 1):
22112211
geometry = self.get(f'patch_icpp({i})%geometry')
@@ -2295,28 +2295,31 @@ def check_velocity_components(self):
22952295
num_patches = self.get('num_patches', 0)
22962296
mhd = self.get('mhd', 'F') == 'T'
22972297

2298-
if num_patches is None or num_patches <= 0:
2298+
if not self._is_numeric(num_patches) or num_patches <= 0:
22992299
return
23002300

23012301
# MHD simulations legitimately use transverse velocities in 1D
23022302
if mhd:
23032303
return
23042304

2305+
n_is_1d = self._is_numeric(n) and n == 0
2306+
p_is_2d = self._is_numeric(p) and p == 0
2307+
23052308
for i in range(1, num_patches + 1):
23062309
geometry = self.get(f'patch_icpp({i})%geometry')
23072310
if geometry is None:
23082311
continue
23092312

2310-
if n is not None and n == 0:
2313+
if n_is_1d:
23112314
vel2 = self.get(f'patch_icpp({i})%vel(2)')
2312-
if vel2 is not None and self._is_numeric(vel2) and vel2 != 0:
2313-
self.prohibit(True,
2315+
if vel2 is not None and self._is_numeric(vel2):
2316+
self.prohibit(vel2 != 0,
23142317
f"patch_icpp({i})%vel(2) = {vel2} but n = 0 (1D simulation)")
23152318

2316-
if p is not None and p == 0:
2319+
if p_is_2d:
23172320
vel3 = self.get(f'patch_icpp({i})%vel(3)')
2318-
if vel3 is not None and self._is_numeric(vel3) and vel3 != 0:
2319-
self.prohibit(True,
2321+
if vel3 is not None and self._is_numeric(vel3):
2322+
self.prohibit(vel3 != 0,
23202323
f"patch_icpp({i})%vel(3) = {vel3} but p = 0 (1D/2D simulation)")
23212324

23222325
# ===================================================================

toolchain/mfc/cli/schema.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@
66
for generating argparse parsers, shell completions, and documentation.
77
"""
88

9-
from __future__ import annotations
109
from dataclasses import dataclass, field
1110
from enum import Enum, auto
1211
from typing import List, Optional, Any, Union

toolchain/mfc/gen_case_constraints_docs.py

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,6 @@
88
Also generates case design playbook from curated working examples.
99
""" # pylint: disable=too-many-lines
1010

11-
from __future__ import annotations
12-
1311
import json
1412
import sys
1513
import subprocess
@@ -756,7 +754,7 @@ def _render_cond_parts(trigger_str, cond_dict):
756754
# Method name -> human-readable title
757755
method_titles = {
758756
"check_volume_fraction_sum": "Volume Fraction Sum",
759-
"check_alpha_rho_consistency": "AlphaRho Consistency",
757+
"check_alpha_rho_consistency": "Alpha-Rho Consistency",
760758
"check_eos_parameter_sanity": "EOS Parameter Sanity",
761759
}
762760

toolchain/mfc/gen_physics_docs.py

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,6 @@
66
Produces docs/documentation/physics_constraints.md (Doxygen-compatible).
77
"""
88

9-
from __future__ import annotations
10-
119
import re
1210
import sys
1311
from collections import defaultdict

toolchain/mfc/params/ast_analyzer.py

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,6 @@
77
and case_constraints.md).
88
"""
99

10-
from __future__ import annotations
11-
1210
import ast
1311
import re
1412
from dataclasses import dataclass, field

0 commit comments

Comments
 (0)