Skip to content

Commit b0d9461

Browse files
committed
Add visualization & case utility libraries
1 parent ecdf5b1 commit b0d9461

File tree

13 files changed

+242
-185
lines changed

13 files changed

+242
-185
lines changed

.github/file-filter.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ fortran_src: &fortran_src
77

88
python_src: &python_src
99
- '**/*.py'
10-
- 'toolchain/requirements.txt'
10+
- 'toolchain/pyproject.toml'
1111

1212
cmakelist: &cmakelist
1313
- 'CMakeLists.txt'

docs/documentation/case.md

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -41,17 +41,18 @@ parser = argparse.ArgumentParser(
4141
description="Weak- and strong-scaling benchmark case.",
4242
formatter_class=argparse.ArgumentDefaultsHelpFormatter)
4343

44-
parser.add_argument("dict", type=str, metavar="DICT")
45-
parser.add_argument("-s", "--scaling", type=str, metavar="SCALING", choices=["weak", "strong"], help="Whether weak- or strong-scaling is being exercised.")
44+
parser.add_argument("--mfc", type=str, metavar="DICT", default='{}')
45+
parser.add_argument("-s", "--scaling", type=str, metavar="SCALING", choices=["weak", "strong"],
46+
help="Whether weak- or strong-scaling is being exercised.")
4647

4748
# Your parsed arguments are here
4849
args = parser.parse_args()
4950
```
5051

51-
The first argument is always a JSON string representing `mfc.sh run`'s internal
52-
state.
52+
The `--mfc` argument is a JSON string representing `mfc.sh run`'s internal
53+
state, passed in when MFC runs your input file.
5354
It contains all the runtime information you might want from the build/run system.
54-
You can add as many additional arguments as you may need.
55+
You can add as many additional arguments and options as you may need.
5556

5657
To run such a case, use the following format:
5758

examples/scaling/case.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
description="Weak- and strong-scaling benchmark case.",
88
formatter_class=argparse.ArgumentDefaultsHelpFormatter)
99

10-
parser.add_argument("dict", type=str, metavar="DICT")
10+
parser.add_argument("--mfc", type=str, metavar="MFC")
1111
parser.add_argument("-s", "--scaling", type=str, metavar="SCALING", choices=["weak", "strong"], help="Whether weak- or strong-scaling is being exercised.")
1212
parser.add_argument("-m", "--memory", type=int, metavar="MEMORY", help="Weak scaling: memory per rank in GB. Strong scaling: global memory in GB. Used to determine cell count.")
1313
parser.add_argument("-f", "--fidelity", type=str, metavar="FIDELITY", choices=["ideal", "exact"], default="ideal")
@@ -20,7 +20,7 @@
2020
parser.print_help()
2121
sys.exit(1)
2222

23-
DICT = json.loads(args.dict)
23+
DICT = json.loads(args.mfc)
2424

2525
# \approx The number of cells per GB of memory. The exact value is not important.
2626
cpg = 8000000 / 16.0

mfc.bat

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -31,11 +31,11 @@ if %errorlevel% neq 0 (
3131
exit /b 1
3232
)
3333

34-
fc /b "%cd%\build\requirements.txt" "%cd%\toolchain\requirements.txt" 2> NUL
34+
fc /b "%cd%\build\pyproject.toml" "%cd%\toolchain\pyproject.toml" 2> NUL
3535
if %errorlevel% neq 0 (
36-
pip3 install -r toolchain/requirements.txt
36+
pip3 install -e toolchain
3737

38-
copy "%cd%\toolchain\requirements.txt" "%cd%\build" 2> NUL
38+
copy "%cd%\toolchain\pyproject.toml" "%cd%\build" 2> NUL
3939
)
4040

4141
python "%cd%\toolchain\main.py" %*

misc/viz.py

Lines changed: 0 additions & 135 deletions
This file was deleted.

toolchain/bootstrap/lint.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,6 @@
22

33
log "(venv) Running$MAGENTA pylint$COLOR_RESET on$MAGENTA MFC$COLOR_RESET's $MAGENTA""toolchain$COLOR_RESET."
44

5-
pylint -d R1722,W0718,C0301,C0116,C0115,C0114,C0410,W0622,W0640,C0103,W1309,C0411,W1514,R0401,W0511 "$(pwd)/toolchain/"
5+
pylint -d R1722,W0718,C0301,C0116,C0115,C0114,C0410,W0622,W0640,C0103,W1309,C0411,W1514,R0401,W0511,C0321,C3001 "$(pwd)/toolchain/"
66

77
exit $?

toolchain/bootstrap/python.sh

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -74,7 +74,7 @@ if [ ! -f "$(pwd)/build/venv/bin/activate" ]; then
7474

7575
ok "Created a$MAGENTA Python$COLOR_RESET virtual environment (venv)."
7676

77-
rm "$(pwd)/build/requirements.txt" > /dev/null 2>&1 || true
77+
rm "$(pwd)/build/pyproject.toml" > /dev/null 2>&1 || true
7878
fi
7979

8080

@@ -111,8 +111,8 @@ ok "(venv) Entered the $MAGENTA$(python3 --version)$COLOR_RESET virtual environm
111111
# Install Python dependencies if, either:
112112
# - This script is running for the first time
113113
# (or)
114-
# - The requirements.txt file has changed
115-
if ! cmp "$(pwd)/toolchain/requirements.txt" "$(pwd)/build/requirements.txt" > /dev/null 2>&1; then
114+
# - The pyproject.toml file has changed
115+
if ! cmp "$(pwd)/toolchain/pyproject.toml" "$(pwd)/build/pyproject.toml" > /dev/null 2>&1; then
116116
log "(venv) (Re)Installing mfc.sh's Python dependencies (via Pip)."
117117

118118
next_arg=0
@@ -129,7 +129,7 @@ if ! cmp "$(pwd)/toolchain/requirements.txt" "$(pwd)/build/requirements.txt" > /
129129
fi
130130
done
131131

132-
if ! PIP_DISABLE_PIP_VERSION_CHECK=1 MAKEFLAGS=$nthreads pip3 install -r "$(pwd)/toolchain/requirements.txt"; then
132+
if ! PIP_DISABLE_PIP_VERSION_CHECK=1 MAKEFLAGS=$nthreads pip3 install -e "$(pwd)/toolchain"; then
133133
error "(venv) Installation failed."
134134

135135
log "(venv) Exiting the$MAGENTA Python$COLOR_RESET virtual environment."
@@ -140,6 +140,6 @@ if ! cmp "$(pwd)/toolchain/requirements.txt" "$(pwd)/build/requirements.txt" > /
140140

141141
ok "(venv) Installation succeeded."
142142

143-
# Save the new/current requirements.txt
144-
cp "$(pwd)/toolchain/requirements.txt" "$(pwd)/build/"
143+
# Save the new/current pyproject.toml
144+
cp "$(pwd)/toolchain/pyproject.toml" "$(pwd)/build/"
145145
fi

toolchain/mfc/case_utils.py

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
import re
2+
3+
def remove_higher_dimensional_keys(case: dict, ndims: int) -> dict:
4+
assert 1 <= ndims <= 3
5+
6+
rm_dims = [set(), set(['y', 'z']), set(['z'])][ndims]
7+
dim_ids = {dim: i + 1 for i, dim in enumerate(['x', 'y', 'z'])}
8+
dim_mnp = {'x': 'm', 'y': 'n', 'z': 'p'}
9+
10+
rm_keys = set()
11+
for key in case.keys():
12+
for dim in rm_dims:
13+
if any([
14+
re.match(f'.+_{dim}', key), re.match(f'{dim}_.+', key),
15+
re.match(f'%{dim}', key), f'%vel({dim_ids[dim]})' in key
16+
]):
17+
rm_keys.add(key)
18+
break
19+
20+
new_case = {k: v for k, v in case.items() if k not in rm_keys}
21+
22+
for dim in rm_dims:
23+
new_case[dim_mnp[dim]] = 0
24+
25+
return new_case

toolchain/mfc/run/input.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -144,7 +144,7 @@ def load(filepath: str = None, args: typing.List[str] = None, empty_data: dict =
144144
raise common.MFCException(f"Input file '{filename}' does not exist. Please check the path is valid.")
145145

146146
if filename.endswith(".py"):
147-
(json_str, err) = common.get_py_program_output(filename, [json.dumps(ARGS())] + (args or []))
147+
(json_str, err) = common.get_py_program_output(filename, ["--mfc", json.dumps(ARGS())] + (args or []))
148148

149149
if err != 0:
150150
raise common.MFCException(f"Input file {filename} terminated with a non-zero exit code. Please make sure running the file doesn't produce any errors.")

toolchain/mfc/test/case.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -179,16 +179,16 @@ def create_directory(self):
179179
description="{self.get_filepath()}: {self.trace}",
180180
formatter_class=argparse.ArgumentDefaultsHelpFormatter)
181181
182-
parser.add_argument("dict", type=str, metavar="DICT", help=argparse.SUPPRESS)
182+
parser.add_argument("--mfc", type=str, metavar="MFC", help=argparse.SUPPRESS)
183183
184184
ARGS = vars(parser.parse_args())
185185
186-
ARGS["dict"] = json.loads(ARGS["dict"])
186+
ARGS["mfc"] = json.loads(ARGS["mfc"])
187187
188188
case = {self.gen_json_dict_str()}
189189
mods = {{}}
190190
191-
if "post_process" in ARGS["dict"]["targets"]:
191+
if "post_process" in ARGS["mfc"]["targets"]:
192192
mods = {{
193193
'parallel_io' : 'T', 'cons_vars_wrt' : 'T',
194194
'prim_vars_wrt': 'T', 'alpha_rho_wrt(1)': 'T',

0 commit comments

Comments
 (0)